MuseScore/libmscore/measure.h

334 lines
12 KiB
C
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __MEASURE_H__
#define __MEASURE_H__
/**
\file
2014-07-27 12:38:45 +02:00
Definition of classes MStaff, Measure.
2012-05-26 14:26:10 +02:00
*/
#include "measurebase.h"
#include "fraction.h"
#include "segmentlist.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:26:10 +02:00
class Xml;
class Beam;
class Tuplet;
class Staff;
class Chord;
class Text;
class ChordRest;
class Score;
class MuseScoreView;
class System;
class Note;
class Spacer;
class TieMap;
class AccidentalState;
class Spanner;
class Part;
class RepeatMeasure;
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// MStaff
2012-08-02 18:33:43 +02:00
/// Per staff values of measure.
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
struct MStaff {
qreal distanceUp;
qreal distanceDown;
Text* _noText; ///< Measure number text object
2012-05-26 14:26:10 +02:00
StaffLines* lines;
Spacer* _vspacerUp;
Spacer* _vspacerDown;
bool hasVoices; ///< indicates that MStaff contains more than one voice,
///< this changes some layout rules
bool _visible;
bool _slashStyle;
MStaff();
~MStaff();
MStaff(const MStaff&);
2012-05-26 14:26:10 +02:00
bool visible() const { return _visible; }
void setVisible(bool val) { _visible = val; }
bool slashStyle() const { return _slashStyle; }
void setSlashStyle(bool val) { _slashStyle = val; }
void setScore(Score*);
void setTrack(int);
Text* noText() const { return _noText; }
void setNoText(Text* t) { _noText = t; }
2012-05-26 14:26:10 +02:00
};
2014-07-17 09:32:30 +02:00
//---------------------------------------------------------
// Repeat
//---------------------------------------------------------
enum class Repeat : char {
NONE = 0,
END = 1,
START = 2,
MEASURE = 4,
JUMP = 8
2012-05-26 14:26:10 +02:00
};
2014-07-17 09:32:30 +02:00
constexpr Repeat operator| (Repeat t1, Repeat t2) {
return static_cast<Repeat>(static_cast<int>(t1) | static_cast<int>(t2));
}
constexpr bool operator& (Repeat t1, Repeat t2) {
return static_cast<int>(t1) & static_cast<int>(t2);
}
//---------------------------------------------------------
// MeasureNumberMode
//---------------------------------------------------------
enum class MeasureNumberMode : char {
AUTO, // show measure number depending on style
SHOW, // always show measure number
HIDE // dont show measure number
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2012-07-11 21:29:42 +02:00
// @@ Measure
2012-07-25 11:49:34 +02:00
/// one measure in a system
Fixes the following Q_INVOKABLE methods returning a QObject* by turning them into a property: - Measure: -- firstSegment -- lastSegment - MeasureBase: -- nextMeasure -- nextMeasureMM (new) -- prevMeasure -- prevMeasureMM (new) - Score: -- firstMeasure -- firstMeasureMM (new) -- (for firstSegment(), see special cases below) -- lastMeasure -- lastMeasureMM (new) -- lastSegment - Segment: -- next (renamed from `next1`) -- nextInMeasure (renamed from `next`) -- prev (renamed from `prev1`) -- prevInMeasure (renamed from prev) Special cases: - Cursor: The prototype of the `Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)` was wrong: corrected in `Q_INVOKABLE void Cursor::addNote(int pitch)`. - QmlPlugin: `Q_INVOKABLE Score* QmlPlugin::readScore()` and `Q_INVOKABLE Score* QmlPlugin::newScore()` has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object. - Score: `Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)` is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*. - Segment: `Ms::Element* Segment::element(int track)` has been made NOT Q_INVOKABLE; a variant `Q_INVOKABLE Ms::Element* elementAt(int track)` has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in). - FiguredBass: `Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()` has been removed; plugin interface for FiguredBass needs to be redesigned anyway. The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.
2014-07-06 01:56:30 +02:00
//
// @P firstSegment Ms::Segment the first segment of the measure (read-only)
// @P lastSegment Ms::Segment the last segment of the measure (read-only)
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Measure : public MeasureBase {
Q_OBJECT
Q_PROPERTY(Ms::Segment* firstSegment READ last)
Fixes the following Q_INVOKABLE methods returning a QObject* by turning them into a property: - Measure: -- firstSegment -- lastSegment - MeasureBase: -- nextMeasure -- nextMeasureMM (new) -- prevMeasure -- prevMeasureMM (new) - Score: -- firstMeasure -- firstMeasureMM (new) -- (for firstSegment(), see special cases below) -- lastMeasure -- lastMeasureMM (new) -- lastSegment - Segment: -- next (renamed from `next1`) -- nextInMeasure (renamed from `next`) -- prev (renamed from `prev1`) -- prevInMeasure (renamed from prev) Special cases: - Cursor: The prototype of the `Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)` was wrong: corrected in `Q_INVOKABLE void Cursor::addNote(int pitch)`. - QmlPlugin: `Q_INVOKABLE Score* QmlPlugin::readScore()` and `Q_INVOKABLE Score* QmlPlugin::newScore()` has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object. - Score: `Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)` is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*. - Segment: `Ms::Element* Segment::element(int track)` has been made NOT Q_INVOKABLE; a variant `Q_INVOKABLE Ms::Element* elementAt(int track)` has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in). - FiguredBass: `Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()` has been removed; plugin interface for FiguredBass needs to be redesigned anyway. The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.
2014-07-06 01:56:30 +02:00
Q_PROPERTY(Ms::Segment* lastSegment READ first)
2012-05-26 14:26:10 +02:00
SegmentList _segments;
Fraction _timesig;
Fraction _len; ///< actual length of measure
int _repeatCount; ///< end repeat marker und repeat count
2014-07-17 09:32:30 +02:00
Repeat _repeatFlags; ///< or'd Repeat's
2012-05-26 14:26:10 +02:00
QList<MStaff*> staves;
int _no; ///< Measure number, counting from zero
int _noOffset; ///< Offset to measure number
MeasureNumberMode _noMode;
2012-05-26 14:26:10 +02:00
qreal _userStretch;
2014-10-21 18:57:43 +02:00
mutable qreal _minWidth1; ///< minimal measure width, cached value
mutable qreal _minWidth2; ///< minimal measure width, cached value
2012-05-26 14:26:10 +02:00
bool _irregular; ///< Irregular measure, do not count
bool _breakMultiMeasureRest; ///< set by user
bool _breakMMRest; ///< set by layout
BarLineType _endBarLineType;
bool _endBarLineGenerated;
bool _endBarLineVisible;
QColor _endBarLineColor;
BarLineType _systemInitialBarLineType; ///< type used for system bar line, when measure is initial
2012-05-26 14:26:10 +02:00
int _playbackCount; // temp. value used in RepeatList
// counts how many times this measure was already played
Measure* _mmRest; // multi measure rest which replaces a measure range
int _mmRestCount; // > 0 if this is a multi measure rest
2013-09-27 18:43:25 +02:00
// 0 if this is the start of a mm rest (_mmRest != 0)
// < 0 if this measure is covered by a mm rest
2012-05-26 14:26:10 +02:00
void push_back(Segment* e);
void push_front(Segment* e);
2015-02-19 10:28:25 +01:00
void layoutCR0(ChordRest* cr, qreal m, AccidentalState*);
2012-05-26 14:26:10 +02:00
public:
Measure(Score* = 0);
2012-05-26 14:26:10 +02:00
Measure(const Measure&);
~Measure();
virtual Measure* clone() const override { return new Measure(*this); }
virtual Element::Type type() const override { return Element::Type::MEASURE; }
virtual void setScore(Score* s) override;
2013-07-05 11:23:52 +02:00
Measure* cloneMeasure(Score*, TieMap*);
2012-05-26 14:26:10 +02:00
2013-01-17 12:56:14 +01:00
void read(XmlReader&, int idx);
2013-01-11 18:10:18 +01:00
void read(XmlReader& d) { read(d, 0); }
2015-05-05 19:53:52 +02:00
virtual void write(Xml& xml) const override { Element::write(xml); }
2013-01-17 12:56:14 +01:00
void write(Xml&, int, bool writeSystemElements) const;
2012-05-26 14:26:10 +02:00
void writeBox(Xml&) const;
2013-01-11 18:10:18 +01:00
void readBox(XmlReader&);
virtual bool isEditable() const override { return false; }
2012-05-26 14:26:10 +02:00
virtual void add(Element*) override;
virtual void remove(Element*) override;
virtual void change(Element* o, Element* n) override;
virtual void spatiumChanged(qreal oldValue, qreal newValue) override;
2012-05-26 14:26:10 +02:00
System* system() const { return (System*)parent(); }
QList<MStaff*>* staffList() { return &staves; }
MStaff* mstaff(int staffIdx) { return staves[staffIdx]; }
bool hasVoices(int staffIdx) const { return staves[staffIdx]->hasVoices; }
StaffLines* staffLines(int staffIdx) { return staves[staffIdx]->lines; }
int no() const { return _no; }
bool irregular() const { return _irregular; }
void setIrregular(bool val) { _irregular = val; }
int noOffset() const { return _noOffset; }
MeasureNumberMode measureNumberMode() const { return _noMode; }
void setMeasureNumberMode(MeasureNumberMode v) { _noMode = v; }
2012-05-26 14:26:10 +02:00
void setNo(int n) { _no = n; }
void setNoOffset(int n) { _noOffset = n; }
virtual qreal distanceUp(int i) const;
virtual qreal distanceDown(int i) const;
2012-05-26 14:26:10 +02:00
qreal minWidth1() const;
qreal minWidth2() const;
2014-10-21 18:57:43 +02:00
bool systemHeader() const;
void setDirty();
2012-05-26 14:26:10 +02:00
Fraction timesig() const { return _timesig; }
void setTimesig(const Fraction& f) { _timesig = f; }
Fraction len() const { return _len; }
Fraction stretchedLen(Staff*) const;
void setLen(const Fraction& f) { _len = f; }
// actual length of measure in ticks
2014-02-26 19:06:42 +01:00
virtual int ticks() const override;
2012-05-26 14:26:10 +02:00
Fixes the following Q_INVOKABLE methods returning a QObject* by turning them into a property: - Measure: -- firstSegment -- lastSegment - MeasureBase: -- nextMeasure -- nextMeasureMM (new) -- prevMeasure -- prevMeasureMM (new) - Score: -- firstMeasure -- firstMeasureMM (new) -- (for firstSegment(), see special cases below) -- lastMeasure -- lastMeasureMM (new) -- lastSegment - Segment: -- next (renamed from `next1`) -- nextInMeasure (renamed from `next`) -- prev (renamed from `prev1`) -- prevInMeasure (renamed from prev) Special cases: - Cursor: The prototype of the `Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)` was wrong: corrected in `Q_INVOKABLE void Cursor::addNote(int pitch)`. - QmlPlugin: `Q_INVOKABLE Score* QmlPlugin::readScore()` and `Q_INVOKABLE Score* QmlPlugin::newScore()` has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object. - Score: `Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)` is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*. - Segment: `Ms::Element* Segment::element(int track)` has been made NOT Q_INVOKABLE; a variant `Q_INVOKABLE Ms::Element* elementAt(int track)` has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in). - FiguredBass: `Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()` has been removed; plugin interface for FiguredBass needs to be redesigned anyway. The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.
2014-07-06 01:56:30 +02:00
int size() const { return _segments.size(); }
Ms::Segment* first() const { return _segments.first(); }
Segment* first(Segment::Type t) const { return _segments.first(t); }
2012-05-26 14:26:10 +02:00
Fixes the following Q_INVOKABLE methods returning a QObject* by turning them into a property: - Measure: -- firstSegment -- lastSegment - MeasureBase: -- nextMeasure -- nextMeasureMM (new) -- prevMeasure -- prevMeasureMM (new) - Score: -- firstMeasure -- firstMeasureMM (new) -- (for firstSegment(), see special cases below) -- lastMeasure -- lastMeasureMM (new) -- lastSegment - Segment: -- next (renamed from `next1`) -- nextInMeasure (renamed from `next`) -- prev (renamed from `prev1`) -- prevInMeasure (renamed from prev) Special cases: - Cursor: The prototype of the `Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)` was wrong: corrected in `Q_INVOKABLE void Cursor::addNote(int pitch)`. - QmlPlugin: `Q_INVOKABLE Score* QmlPlugin::readScore()` and `Q_INVOKABLE Score* QmlPlugin::newScore()` has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object. - Score: `Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)` is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*. - Segment: `Ms::Element* Segment::element(int track)` has been made NOT Q_INVOKABLE; a variant `Q_INVOKABLE Ms::Element* elementAt(int track)` has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in). - FiguredBass: `Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()` has been removed; plugin interface for FiguredBass needs to be redesigned anyway. The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.
2014-07-06 01:56:30 +02:00
Ms::Segment* last() const { return _segments.last(); }
2012-05-26 14:26:10 +02:00
void remove(Segment* s);
Fixes the following Q_INVOKABLE methods returning a QObject* by turning them into a property: - Measure: -- firstSegment -- lastSegment - MeasureBase: -- nextMeasure -- nextMeasureMM (new) -- prevMeasure -- prevMeasureMM (new) - Score: -- firstMeasure -- firstMeasureMM (new) -- (for firstSegment(), see special cases below) -- lastMeasure -- lastMeasureMM (new) -- lastSegment - Segment: -- next (renamed from `next1`) -- nextInMeasure (renamed from `next`) -- prev (renamed from `prev1`) -- prevInMeasure (renamed from prev) Special cases: - Cursor: The prototype of the `Q_INVOKABLE Ms::Note* Cursor::addNote(int pitch)` was wrong: corrected in `Q_INVOKABLE void Cursor::addNote(int pitch)`. - QmlPlugin: `Q_INVOKABLE Score* QmlPlugin::readScore()` and `Q_INVOKABLE Score* QmlPlugin::newScore()` has been kept, as they are intended to be called from QML; code has been added to ensure the C++ ownership of the returned object. - Score: `Q_INVOKABLE Segment* Score::firstSegment(Segment::Type segType)` is kept (as it needs a parameters), but code is added to ensure C++ ownership of the returned Segment*. - Segment: `Ms::Element* Segment::element(int track)` has been made NOT Q_INVOKABLE; a variant `Q_INVOKABLE Ms::Element* elementAt(int track)` has been added specifically for QML with code to ensure the C++ ownership of the returned Element* (this was the cause for the crash of the Walk plug-in). - FiguredBass: `Q_INVOKABLE Ms::FiguredBassItem* FiguredBass::addItem()` has been removed; plugin interface for FiguredBass needs to be redesigned anyway. The few occurrences in the supplied plug-ins of the methods whose names did change have been updated.
2014-07-06 01:56:30 +02:00
SegmentList* segments() { return &_segments; }
2012-05-26 14:26:10 +02:00
2014-05-17 18:40:05 +02:00
qreal userStretch() const;
void setUserStretch(qreal v) { _userStretch = (v < 0 ? 0 : v); }
2012-05-26 14:26:10 +02:00
void layoutX(qreal stretch);
void layoutWidth(qreal width);
2012-05-26 14:26:10 +02:00
void layout2();
2013-06-24 13:46:21 +02:00
Chord* findChord(int tick, int track);
2012-05-26 14:26:10 +02:00
ChordRest* findChordRest(int tick, int track);
int snap(int tick, const QPointF p) const;
int snapNote(int tick, const QPointF p, int staff) const;
void insertStaff(Staff*, int staff);
void insertMStaff(MStaff* staff, int idx);
void removeMStaff(MStaff* staff, int idx);
virtual void moveTicks(int diff);
void cmdRemoveStaves(int s, int e);
void cmdAddStaves(int s, int e, bool createRest);
void removeStaves(int s, int e);
void insertStaves(int s, int e);
qreal tick2pos(int) const;
Segment* tick2segment(int tick, Segment::Type st = Segment::Type::ChordRest) const;
2012-05-26 14:26:10 +02:00
void sortStaves(QList<int>& dst);
void dump() const;
2014-08-13 21:01:21 +02:00
virtual bool acceptDrop(const DropData&) const override;
virtual Element* drop(const DropData&) override;
2012-05-26 14:26:10 +02:00
int repeatCount() const { return _repeatCount; }
void setRepeatCount(int val) { _repeatCount = val; }
Segment* undoGetSegment(Segment::Type st, int tick);
2012-05-26 14:26:10 +02:00
Segment* getSegment(Element* el, int tick);
Segment* getSegment(Segment::Type st, int tick);
Segment* findSegment(Segment::Type st, int t);
2012-05-26 14:26:10 +02:00
bool createEndBarLines();
void setEndBarLineType(BarLineType val, bool g, bool visible = true, QColor color = QColor());
2012-05-26 14:26:10 +02:00
BarLineType endBarLineType() const { return _endBarLineType; }
2012-05-26 14:26:10 +02:00
bool setStartRepeatBarLine(bool);
bool endBarLineGenerated() const { return _endBarLineGenerated; }
void setEndBarLineGenerated(bool v) { _endBarLineGenerated = v; }
bool endBarLineVisible() const { return _endBarLineVisible; }
QColor endBarLineColor() const { return _endBarLineColor; }
void setSystemInitialBarLineType(BarLineType v) { _systemInitialBarLineType = v; }
BarLineType systemInitialBarLineType() const { return _systemInitialBarLineType; }
2012-05-26 14:26:10 +02:00
RepeatMeasure* cmdInsertRepeatMeasure(int staffIdx);
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
2012-05-26 14:26:10 +02:00
void createVoice(int track);
void adjustToLen(Fraction);
2014-07-17 09:32:30 +02:00
Repeat repeatFlags() const { return _repeatFlags; }
void setRepeatFlags(Repeat val) { _repeatFlags = val; }
void setRepeatFlag(Repeat val) { _repeatFlags = _repeatFlags | val; }
void resetRepeatFlag(Repeat val) { _repeatFlags = Repeat(int(_repeatFlags) & ~int(val)); }
2012-08-08 20:46:29 +02:00
AccidentalVal findAccidental(Note*) const;
AccidentalVal findAccidental(Segment* s, int staffIdx, int line) const;
2014-08-29 10:35:17 +02:00
void exchangeVoice(int voice1, int voice2, int staffIdx);
2012-05-26 14:26:10 +02:00
void checkMultiVoices(int staffIdx);
bool hasVoice(int track) const;
bool isMeasureRest(int staffIdx);
bool isFullMeasureRest();
bool isRepeatMeasure(Staff* staff);
2012-05-26 14:26:10 +02:00
bool visible(int staffIdx) const;
bool slashStyle(int staffIdx) const;
bool breakMultiMeasureRest() const { return _breakMultiMeasureRest | _breakMMRest; }
bool breakMMRest() const { return _breakMMRest; }
void setBreakMMRest(bool v) { _breakMMRest = v; }
bool getBreakMultiMeasureRest() const { return _breakMultiMeasureRest; }
void setBreakMultiMeasureRest(bool val) { _breakMultiMeasureRest = val; }
bool isEmpty() const;
bool isOnlyRests(int track) const;
2012-05-26 14:26:10 +02:00
2014-04-22 17:02:03 +02:00
2012-05-26 14:26:10 +02:00
void layoutStage1();
int playbackCount() const { return _playbackCount; }
void setPlaybackCount(int val) { _playbackCount = val; }
QRectF staffabbox(int staffIdx) const;
virtual QVariant getProperty(P_ID propertyId) const override;
virtual bool setProperty(P_ID propertyId, const QVariant&) override;
virtual QVariant propertyDefault(P_ID) const override;
2012-05-26 14:26:10 +02:00
bool hasMMRest() const { return _mmRest != 0; }
2013-09-27 18:43:25 +02:00
bool isMMRest() const { return _mmRestCount > 0; }
Measure* mmRest() const { return _mmRest; }
const Measure* mmRest1() const;
void setMMRest(Measure* m) { _mmRest = m; }
int mmRestCount() const { return _mmRestCount; } // number of measures _mmRest spans
void setMMRestCount(int n) { _mmRestCount = n; }
2013-10-30 14:21:08 +01:00
Measure* mmRestFirst() const;
Measure* mmRestLast() const;
Element* nextElementStaff(int staff);
Element* prevElementStaff(int staff);
virtual QString accessibleInfo() override;
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif