MuseScore Plugins  3.5
Plugins API for MuseScore
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2019 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
13 #ifndef __PLUGIN_API_SCORE_H__
14 #define __PLUGIN_API_SCORE_H__
16 #include "scoreelement.h"
17 #include "part.h"
18 #include "style.h"
19 #include "excerpt.h"
20 #include "libmscore/score.h"
22 namespace Ms {
24 class InstrumentTemplate;
26 namespace PluginAPI {
28 class Cursor;
29 class Segment;
30 class Measure;
31 class Selection;
32 class Score;
33 class Staff;
35 extern Selection* selectionWrap(Ms::Selection* select);
37 //---------------------------------------------------------
38 // Score
39 //---------------------------------------------------------
44  Q_PROPERTY(QString composer READ composer)
46  Q_PROPERTY(int duration READ duration)
48  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Excerpt> excerpts READ excerpts)
58  Q_PROPERTY(int harmonyCount READ harmonyCount)
60  Q_PROPERTY(bool hasHarmonies READ hasHarmonies)
62  Q_PROPERTY(bool hasLyrics READ hasLyrics)
65  Q_PROPERTY(int keysig READ keysig)
75  Q_PROPERTY(Ms::PluginAPI::Segment* lastSegment READ lastSegment) // TODO: make it function? Was property in 2.X, but firstSegment is a function...
77  Q_PROPERTY(int lyricCount READ lyricCount)
79  Q_PROPERTY(QString scoreName READ name WRITE setName)
81  Q_PROPERTY(int nmeasures READ nmeasures)
83  Q_PROPERTY(int npages READ npages)
85  Q_PROPERTY(int nstaves READ nstaves)
87  Q_PROPERTY(int ntracks READ ntracks)
88 // Q_PROPERTY(Ms::PageFormat* pageFormat READ pageFormat WRITE undoChangePageFormat)
90  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Part> parts READ parts)
92  Q_PROPERTY(QString lyricist READ lyricist)
93 // Q_PROPERTY(QString subtitle READ subtitle)
95  Q_PROPERTY(QString title READ title)
97  Q_PROPERTY(QString mscoreVersion READ mscoreVersion)
99  Q_PROPERTY(QString mscoreRevision READ mscoreRevision)
103  Q_PROPERTY(Ms::PluginAPI::MStyle* style READ style)
112  Q_PROPERTY(int pageNumberOffset READ pageNumberOffset WRITE setPageNumberOffset)
118  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Staff> staves READ staves)
120  public:
122  Score(Ms::Score* s = nullptr, Ownership o = Ownership::SCORE)
123  : ScoreElement(s, o) {}
125  Ms::Score* score() { return toScore(e); }
126  const Ms::Score* score() const { return toScore(e); }
128  QString composer() { return score()->metaTag("composer"); }
129  int duration() { return score()->duration(); }
130  int harmonyCount() { return score()->harmonyCount(); }
131  bool hasHarmonies() { return score()->hasHarmonies(); }
132  bool hasLyrics() { return score()->hasLyrics(); }
133  int keysig() { return score()->keysig(); }
134  int lyricCount() { return score()->lyricCount(); }
135  QString lyricist() { return score()->metaTag("lyricist"); } // not the meanwhile obsolete "poet"
136  QString title() { return score()->metaTag("workTitle"); }
137  Ms::PluginAPI::Selection* selection() { return selectionWrap(&score()->selection()); }
138  MStyle* style() { return wrap(&score()->style(), score()); }
140  int pageNumberOffset() const { return score()->pageNumberOffset(); }
141  void setPageNumberOffset(int offset) { score()->undoChangePageNumberOffset(offset); }
146  Q_INVOKABLE QString metaTag(const QString& tag) const { return score()->metaTag(tag); }
148  Q_INVOKABLE void setMetaTag(const QString& tag, const QString& val) { score()->setMetaTag(tag, val); }
158  Q_INVOKABLE void appendPart(const QString& instrumentId);
168  Q_INVOKABLE void appendPartByMusicXmlId(const QString& instrumentMusicXmlId);
171  Q_INVOKABLE void appendMeasures(int n) { score()->appendMeasures(n); }
172  Q_INVOKABLE void addText(const QString& type, const QString& text);
174  Q_INVOKABLE Ms::PluginAPI::Cursor* newCursor();
176  Q_INVOKABLE Ms::PluginAPI::Segment* firstSegment(); // TODO: segment type
178  Segment* lastSegment();
182  Measure* lastMeasure();
185  QString name() const { return score()->masterScore()->title(); }
186  void setName(const QString& name) { score()->masterScore()->setName(name); }
189  Q_INVOKABLE QString extractLyrics() { return score()->extractLyrics(); }
191 // //@ ??
192 // Q_INVOKABLE void updateRepeatList(bool expandRepeats) { score()->updateRepeatList(); } // TODO: needed?
195  int nmeasures() const { return score()->nmeasures(); }
196  int npages() const { return score()->npages(); }
197  int nstaves() const { return score()->nstaves(); }
198  int ntracks() const { return score()->ntracks(); }
209  Q_INVOKABLE void startCmd();
219  Q_INVOKABLE void endCmd(bool rollback = false) { score()->endCmd(rollback); }
228  Q_INVOKABLE void createPlayEvents() { score()->createPlayEvents(); }
231  QString mscoreVersion() { return score()->mscoreVersion(); }
232  QString mscoreRevision() { return QString::number(score()->mscoreRevision(), /* base */ 16); }
234  QQmlListProperty<Part> parts() { return wrapContainerProperty<Part>(this, score()->parts()); }
235  QQmlListProperty<Excerpt> excerpts() { return wrapExcerptsContainerProperty<Excerpt>(this, score()->excerpts()); }
236  QQmlListProperty<Staff> staves();
238  static const Ms::InstrumentTemplate* instrTemplateFromName(const QString& name); // used by PluginAPI::newScore()
240  };
241 } // namespace PluginAPI
242 } // namespace Ms
243 #endif
Definition: elements.h:775
QString title
Title of score, as taken from the score properties&#39; workTitle (read only).
Definition: score.h:95
Base class for most of object wrappers exposed to QML.
Definition: scoreelement.h:42
Q_INVOKABLE void startCmd()
For "dock" type plugins: to be used before score modifications to make them undoable.
Definition: score.cpp:204
Definition: selection.h:28
Definition: elements.h:709
int npages
Number of pages (read only)
Definition: score.h:83
Q_INVOKABLE void appendPartByMusicXmlId(const QString &instrumentMusicXmlId)
Appends a part with the instrument defined by the given MusicXML ID to this score.
Definition: score.cpp:126
Q_INVOKABLE void appendPart(const QString &instrumentId)
Appends a part with the instrument defined by instrumentId to this score.
Definition: score.cpp:110
QQmlListProperty< Ms::PluginAPI::Part > parts
The list of parts.
Definition: score.h:90
Definition: part.h:42
Q_INVOKABLE QString metaTag(const QString &tag) const
Returns as a string the metatag named tag.
Definition: score.h:146
Q_INVOKABLE void setMetaTag(const QString &tag, const QString &val)
Sets the metatag named tag to val.
Definition: score.h:148
Definition: excerpt.h:35
Q_INVOKABLE void endCmd(bool rollback=false)
For "dock" type plugins: to be used after score modifications to make them undoable.
Definition: score.h:219
int lyricCount
Number of lyrics items (syllables) in the score (read only).
Definition: score.h:77
Ms::PluginAPI::Measure firstMeasureMM
First multimeasure rest measure of the score (read only).
Definition: score.h:56
int pageNumberOffset
Page numbering offset.
Definition: score.h:112
Ms::PluginAPI::Selection selection
Current selections for the score.
Definition: score.h:101
Q_INVOKABLE Ms::PluginAPI::Cursor * newCursor()
Creates and returns a cursor to be used to navigate in the score.
Definition: score.cpp:32
Cursor can be used by plugins to manipulate the score.
Definition: cursor.h:53
Definition: score.h:41
bool hasHarmonies
Whether score has harmonies (chord symbols) (read only).
Definition: score.h:60
int nstaves
Number of staves (read only)
Definition: score.h:85
Ms::PluginAPI::Measure lastMeasure
Last measure of the score (read only)
Definition: score.h:67
Ms::PluginAPI::Segment lastSegment
Last score segment (read only)
Definition: score.h:75
Definition: cursor.cpp:30
int duration
Duration of score in seconds (read only).
Definition: score.h:46
Definition: elements.h:867
QString composer
Composer of the score, as taken from the score properties (read only).
Definition: score.h:44
Q_INVOKABLE void appendMeasures(int n)
Appends a number of measures to this score.
Definition: score.h:171
Ms::PluginAPI::Measure firstMeasure
First measure of the score (read only)
Definition: score.h:50
QString lyricist
Lyricist of score, as taken from the score properties.
Definition: score.h:92
QQmlListProperty< Ms::PluginAPI::Excerpt > excerpts
List of the excerpts (linked parts) (read only)
Definition: score.h:48
Ms::PluginAPI::MStyle style
Style settings for this score.
Definition: score.h:103
Provides an access to score style settings.
Definition: style.h:47
Ms::PluginAPI::Measure lastMeasureMM
Last multimeasure rest measure of the score (read only).
Definition: score.h:73
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:62
QString scoreName
Name of the score, without path leading to it and extension.
Definition: score.h:79
QQmlListProperty< Ms::PluginAPI::Staff > staves
List of staves in this score.
Definition: score.h:118
Q_INVOKABLE void createPlayEvents()
Create PlayEvents for all notes based on ornamentation.
Definition: score.h:228
Q_INVOKABLE void addText(const QString &type, const QString &text)
Adds a header text to the score.
Definition: score.cpp:49
int nmeasures
Number of measures (read only)
Definition: score.h:81
QString name
Name of this element&#39;s type, not localized.
Definition: scoreelement.h:54
int keysig
Key signature at the start of the score, in number of accidentals, negative for flats, postitive for sharps (read only).
Definition: score.h:65
QString mscoreVersion
MuseScore version the score has been last saved with (includes autosave) (read only) ...
Definition: score.h:97
int type
Type of this element.
Definition: scoreelement.h:48
QString mscoreRevision
MuseScore revision the score has been last saved with (includes autosave) (read only) ...
Definition: score.h:99
int ntracks
Number of tracks (nstaves * 4) (read only)
Definition: score.h:87
bool hasLyrics
Whether score has lyrics (read only).
Definition: score.h:62
int harmonyCount
Number of harmony items (chord symbols) in the score (read only).
Definition: score.h:58