MuseScore/libmscore/measure.h

306 lines
11 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
Definition of classes MStaff, Measure and MeasureList.
*/
#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
};
enum Repeat : char {
END = 1,
START = 2,
MEASUREFLAG = 4,
JUMP = 8
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
// 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
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Measure : public MeasureBase {
Q_OBJECT
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
int _repeatFlags; ///< or'd RepeatType's
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;
mutable qreal _minWidth1; ///< minimal measure width without system header
mutable qreal _minWidth2; ///< minimal measure width with system header
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;
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);
2013-06-20 10:19:04 +02:00
void layoutCR0(ChordRest* cr, qreal m);
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 ElementType type() const override { return ElementType::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); }
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;
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;
void setMinWidth1(qreal w) { _minWidth1 = w; }
void setMinWidth2(qreal w) { _minWidth2 = w; }
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
int size() const { return _segments.size(); }
Q_INVOKABLE Ms::Segment* first() const { return _segments.first(); }
Segment* first(Segment::SegmentTypes t) const { return _segments.first(t); }
2012-05-26 14:26:10 +02:00
Q_INVOKABLE Ms::Segment* last() const { return _segments.last(); }
2012-05-26 14:26:10 +02:00
void remove(Segment* s);
SegmentList* segments() { return &_segments; }
2014-05-17 18:40:05 +02:00
qreal userStretch() const;
void setUserStretch(qreal v) { _userStretch = v; }
2012-05-26 14:26:10 +02:00
void layoutX(qreal stretch);
2012-05-26 14:26:10 +02:00
void layout(qreal width);
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;
2013-06-16 23:33:37 +02:00
Segment* tick2segment(int) const;
2012-05-26 14:26:10 +02:00
void sortStaves(QList<int>& dst);
void dump() const;
virtual bool acceptDrop(MuseScoreView*, const QPointF&, Element*) 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::SegmentType st, int tick);
2012-05-26 14:26:10 +02:00
Segment* getSegment(Element* el, int tick);
Segment* getSegment(Segment::SegmentType st, int tick);
Segment* findSegment(Segment::SegmentType 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; }
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);
int repeatFlags() const { return _repeatFlags; }
void setRepeatFlags(int val) { _repeatFlags = val; }
2012-08-08 20:46:29 +02:00
AccidentalVal findAccidental(Note*) const;
AccidentalVal findAccidental(Segment* s, int staffIdx, int line) const;
2012-05-26 14:26:10 +02:00
void exchangeVoice(int, int, int, int);
void checkMultiVoices(int staffIdx);
bool hasVoice(int track) const;
bool isMeasureRest(int staffIdx);
bool isFullMeasureRest();
bool isRepeatMeasure(Part* part);
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
void updateNotes(int staffIdx);
void cmdUpdateNotes(int staffIdx);
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; }
2014-04-24 10:42:42 +02:00
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;
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif