MuseScore/libmscore/measurebase.h

180 lines
6.9 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 __MEASUREBASE_H__
#define __MEASUREBASE_H__
/**
\file
Definition of MeasureBase class.
*/
#include "element.h"
#include "layoutbreak.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:26:10 +02:00
class Score;
class System;
class Measure;
2016-01-04 14:48:58 +01:00
//---------------------------------------------------------
// Repeat
//---------------------------------------------------------
enum class Repeat : char {
NONE = 0,
END = 1,
START = 2,
MEASURE = 4,
JUMP = 8
};
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);
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2012-07-11 21:29:42 +02:00
// @@ MeasureBase
/// Virtual base class for Measure, HBox and VBox
//
// @P lineBreak bool true if a system break is positioned on this measure
// @P nextMeasure Measure the next Measure (read-only)
// @P nextMeasureMM Measure the next multi-measure rest Measure (read-only)
// @P pageBreak bool true if a page break is positioned on this measure
// @P prevMeasure Measure the previous Measure (read-only)
// @P prevMeasureMM Measure the previous multi-measure rest Measure (read-only)
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class MeasureBase : public Element {
2016-01-04 14:48:58 +01:00
MeasureBase* _next { 0 };
MeasureBase* _prev { 0 };
ElementList _el; ///< Measure(/tick) relative -elements: with defined start time
///< but outside the staff
2016-06-06 10:33:09 +02:00
int _tick { 0 };
int _no { 0 }; ///< Measure number, counting from zero
int _noOffset { 0 }; ///< Offset to measure number
2012-05-26 14:26:10 +02:00
2016-01-04 14:48:58 +01:00
protected:
2016-10-13 14:28:00 +02:00
void cleanupLayoutBreaks(bool undo);
2012-05-26 14:26:10 +02:00
public:
MeasureBase(Score* score = 0);
2012-05-26 14:26:10 +02:00
~MeasureBase();
MeasureBase(const MeasureBase&);
2012-05-26 14:26:10 +02:00
virtual MeasureBase* clone() const = 0;
2017-01-18 14:16:33 +01:00
virtual ElementType type() const = 0;
virtual void setScore(Score* s) override;
2012-05-26 14:26:10 +02:00
MeasureBase* next() const { return _next; }
MeasureBase* nextMM() const;
2012-05-26 14:26:10 +02:00
void setNext(MeasureBase* e) { _next = e; }
MeasureBase* prev() const { return _prev; }
void setPrev(MeasureBase* e) { _prev = e; }
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::Measure* nextMeasure() const;
Ms::Measure* prevMeasure() const;
Ms::Measure* nextMeasureMM() const;
2013-09-27 18:43:25 +02:00
Ms::Measure* prevMeasureMM() const;
2012-05-26 14:26:10 +02:00
2016-11-19 11:51:21 +01:00
virtual void write(XmlWriter&) const override = 0;
virtual void write(XmlWriter&, int, bool, bool) const = 0;
2012-05-26 14:26:10 +02:00
virtual void layout();
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
2016-01-04 14:48:58 +01:00
ElementList& el() { return _el; }
const ElementList& el() const { return _el; }
2012-05-26 14:26:10 +02:00
System* system() const { return (System*)parent(); }
void setSystem(System* s) { setParent((Element*)s); }
2016-10-13 14:28:00 +02:00
LayoutBreak* sectionBreakElement() const;
void undoSetBreak(bool v, LayoutBreak::Type type);
void undoSetLineBreak(bool v) { undoSetBreak(v, LayoutBreak::LINE);}
void undoSetPageBreak(bool v) { undoSetBreak(v, LayoutBreak::PAGE);}
void undoSetSectionBreak(bool v) { undoSetBreak(v, LayoutBreak::SECTION);}
void undoSetNoBreak(bool v) { undoSetBreak(v, LayoutBreak::NOBREAK);}
2012-05-26 14:26:10 +02:00
virtual void moveTicks(int diff) { setTick(tick() + diff); }
virtual void add(Element*) override;
virtual void remove(Element*) override;
2016-11-19 11:51:21 +01:00
virtual void writeProperties(XmlWriter&) const override;
2016-01-04 14:48:58 +01:00
virtual bool readProperties(XmlReader&) override;
virtual bool readProperties300(XmlReader&) override;
2016-01-04 14:48:58 +01:00
2016-03-08 09:46:33 +01:00
virtual int tick() const override { return _tick; }
virtual int ticks() const { return 0; }
2012-05-26 14:26:10 +02:00
int endTick() const { return tick() + ticks(); }
void setTick(int t) { _tick = t; }
Fraction rfrac() const override { return 0; }
Fraction afrac() const override;
2012-05-26 14:26:10 +02:00
qreal pause() const;
2012-08-02 18:33:43 +02:00
2018-03-27 15:36:00 +02:00
virtual QVariant getProperty(Pid) const override;
virtual bool setProperty(Pid, const QVariant&) override;
virtual QVariant propertyDefault(Pid) const override;
void clearElements();
ElementList takeElements();
2016-01-04 14:48:58 +01:00
2016-10-20 11:32:07 +02:00
int no() const { return _no; }
void setNo(int n) { _no = n; }
int noOffset() const { return _noOffset; }
void setNoOffset(int n) { _noOffset = n; }
bool repeatEnd() const { return flag(ElementFlag::REPEAT_END); }
void setRepeatEnd(bool v) { setFlag(ElementFlag::REPEAT_END, v); }
bool repeatStart() const { return flag(ElementFlag::REPEAT_START); }
void setRepeatStart(bool v) { setFlag(ElementFlag::REPEAT_START, v); }
bool repeatJump() const { return flag(ElementFlag::REPEAT_JUMP); }
void setRepeatJump(bool v) { setFlag(ElementFlag::REPEAT_JUMP, v); }
bool irregular() const { return flag(ElementFlag::IRREGULAR); }
void setIrregular(bool v) { setFlag(ElementFlag::IRREGULAR, v); }
bool lineBreak() const { return flag(ElementFlag::LINE_BREAK); }
void setLineBreak(bool v) { setFlag(ElementFlag::LINE_BREAK, v); }
bool pageBreak() const { return flag(ElementFlag::PAGE_BREAK); }
void setPageBreak(bool v) { setFlag(ElementFlag::PAGE_BREAK, v); }
bool sectionBreak() const { return flag(ElementFlag::SECTION_BREAK); }
void setSectionBreak(bool v) { setFlag(ElementFlag::SECTION_BREAK, v); }
2016-01-04 14:48:58 +01:00
2016-10-20 11:32:07 +02:00
bool noBreak() const { return flag(ElementFlag::NO_BREAK); }
void setNoBreak(bool v) { setFlag(ElementFlag::NO_BREAK, v); }
2016-02-04 11:27:47 +01:00
2016-10-20 11:32:07 +02:00
bool hasCourtesyKeySig() const { return flag(ElementFlag::KEYSIG); }
void setHasCourtesyKeySig(int v) { setFlag(ElementFlag::KEYSIG, v); }
2016-02-12 19:14:24 +01:00
virtual void computeMinWidth() { };
2016-02-12 19:14:24 +01:00
2016-01-04 14:48:58 +01:00
int index() const;
2012-05-26 14:26:10 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif