MuseScore Plugins  3.2.2
Plugins API for MuseScore
score.h
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 //=============================================================================
12 
13 #ifndef __PLUGIN_API_SCORE_H__
14 #define __PLUGIN_API_SCORE_H__
15 
16 #include "scoreelement.h"
17 #include "part.h"
18 #include "excerpt.h"
19 #include "libmscore/score.h"
20 
21 namespace Ms {
22 namespace PluginAPI {
23 
24 class Cursor;
25 class Segment;
26 class Measure;
27 
28 //---------------------------------------------------------
29 // Score
30 //---------------------------------------------------------
31 
33  Q_OBJECT
35  Q_PROPERTY(QString composer READ composer)
37  Q_PROPERTY(int duration READ duration)
39  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Excerpt> excerpts READ excerpts)
45  Q_PROPERTY(int harmonyCount READ harmonyCount)
47  Q_PROPERTY(bool hasHarmonies READ hasHarmonies)
49  Q_PROPERTY(bool hasLyrics READ hasLyrics)
52  Q_PROPERTY(int keysig READ keysig)
58  Q_PROPERTY(Ms::PluginAPI::Segment* lastSegment READ lastSegment) // TODO: make it function? Was property in 2.X, but firstSegment is a function...
60  Q_PROPERTY(int lyricCount READ lyricCount)
62  Q_PROPERTY(QString scoreName READ name WRITE setName)
64  Q_PROPERTY(int nmeasures READ nmeasures)
66  Q_PROPERTY(int npages READ npages)
68  Q_PROPERTY(int nstaves READ nstaves)
70  Q_PROPERTY(int ntracks READ ntracks)
71 // Q_PROPERTY(Ms::PageFormat* pageFormat READ pageFormat WRITE undoChangePageFormat)
73  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Part> parts READ parts)
75  Q_PROPERTY(QString lyricist READ lyricist)
76 // Q_PROPERTY(QString subtitle READ subtitle)
78  Q_PROPERTY(QString title READ title)
80  Q_PROPERTY(QString mscoreVersion READ mscoreVersion)
82  Q_PROPERTY(QString mscoreRevision READ mscoreRevision)
83 
84  public:
86  Score(Ms::Score* s = nullptr, Ownership o = Ownership::SCORE)
87  : ScoreElement(s, o) {}
88 
89  Ms::Score* score() { return toScore(e); }
90  const Ms::Score* score() const { return toScore(e); }
91 
92  QString composer() { return score()->metaTag("composer"); }
93  int duration() { return score()->duration(); }
94  int harmonyCount() { return score()->harmonyCount(); }
95  bool hasHarmonies() { return score()->hasHarmonies(); }
96  bool hasLyrics() { return score()->hasLyrics(); }
97  int keysig() { return score()->keysig(); }
98  int lyricCount() { return score()->lyricCount(); }
99  QString lyricist() { return score()->metaTag("lyricist"); } // not the meanwhile obsolete "poet"
100  QString title() { return score()->metaTag("workTitle"); }
102 
104  Q_INVOKABLE QString metaTag(const QString& tag) const { return score()->metaTag(tag); }
106  Q_INVOKABLE void setMetaTag(const QString& tag, const QString& val) { score()->setMetaTag(tag, val); }
107 
108 // //@ appends to the score a named part as last part
109 // Q_INVOKABLE void appendPart(const QString&);
111  Q_INVOKABLE void appendMeasures(int n) { score()->appendMeasures(n); }
112  Q_INVOKABLE void addText(const QString& type, const QString& text);
114  Q_INVOKABLE Ms::PluginAPI::Cursor* newCursor();
115 
116  Q_INVOKABLE Ms::PluginAPI::Segment* firstSegment(); // TODO: segment type
118  Segment* lastSegment();
119 
122  Measure* lastMeasure();
124 
125  QString name() const { return score()->masterScore()->title(); }
126  void setName(const QString& name) { score()->masterScore()->setName(name); }
128 
129  Q_INVOKABLE QString extractLyrics() { return score()->extractLyrics(); }
130 
131 // //@ ??
132 // Q_INVOKABLE void updateRepeatList(bool expandRepeats) { score()->updateRepeatList(); } // TODO: needed?
133 
135  int nmeasures() const { return score()->nmeasures(); }
136  int npages() const { return score()->npages(); }
137  int nstaves() const { return score()->nstaves(); }
138  int ntracks() const { return score()->ntracks(); }
140 
149  Q_INVOKABLE void startCmd() { score()->startCmd(); }
159  Q_INVOKABLE void endCmd(bool rollback = false) { score()->endCmd(rollback); }
160 
162  QString mscoreVersion() { return score()->mscoreVersion(); }
163  QString mscoreRevision() { return QString::number(score()->mscoreRevision(), /* base */ 16); }
164 
165  QQmlListProperty<Part> parts() { return wrapContainerProperty<Part>(this, score()->parts()); }
166  QQmlListProperty<Excerpt> excerpts() { return wrapExcerptsContainerProperty<Excerpt>(this, score()->excerpts()); }
168  };
169 } // namespace PluginAPI
170 } // namespace Ms
171 #endif
Definition: elements.h:519
QString title
Title of score, as taken from the score properties&#39; workTitle (read only).
Definition: score.h:78
Base class for most of object wrappers exposed to QML.
Definition: scoreelement.h:42
Definition: elements.h:459
int npages
Number of pages (read only)
Definition: score.h:66
QQmlListProperty< Ms::PluginAPI::Part > parts
The list of parts.
Definition: score.h:73
Definition: part.h:26
Q_INVOKABLE QString metaTag(const QString &tag) const
Returns as a string the metatag named tag.
Definition: score.h:104
Q_INVOKABLE void setMetaTag(const QString &tag, const QString &val)
Sets the metatag named tag to val.
Definition: score.h:106
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:159
int lyricCount
Number of lyrics items (syllables) in the score (read only).
Definition: score.h:60
Ms::PluginAPI::Measure firstMeasureMM
First multimeasure rest measure of the score (read only).
Definition: score.h:43
Q_INVOKABLE Ms::PluginAPI::Cursor * newCursor()
Creates and returns a cursor to be used to navigate in the score.
Definition: score.cpp:28
Cursor can be used by plugins to manipulate the score.
Definition: cursor.h:43
Definition: score.h:32
Q_INVOKABLE void startCmd()
For "dock" type plugins: to be used before score modifications to make them undoable.
Definition: score.h:149
bool hasHarmonies
Whether score has harmonies (chord symbols) (read only).
Definition: score.h:47
int nstaves
Number of staves (read only)
Definition: score.h:68
Ms::PluginAPI::Measure lastMeasure
Last measure of the score (read only)
Definition: score.h:54
Ms::PluginAPI::Segment lastSegment
Last score segment (read only)
Definition: score.h:58
Definition: cursor.cpp:29
int duration
Duration of score in seconds (read only).
Definition: score.h:37
QString composer
Composer of the score, as taken from the score properties (read only).
Definition: score.h:35
Q_INVOKABLE void appendMeasures(int n)
Appends a number of measures to this score.
Definition: score.h:111
Ms::PluginAPI::Measure firstMeasure
First measure of the score (read only)
Definition: score.h:41
QString lyricist
Lyricist of score, as taken from the score properties.
Definition: score.h:75
QQmlListProperty< Ms::PluginAPI::Excerpt > excerpts
List of the excerpts (linked parts) (read only)
Definition: score.h:39
Ms::PluginAPI::Measure lastMeasureMM
Last multimeasure rest measure of the score (read only).
Definition: score.h:56
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:55
QString scoreName
Name of the score, without path leading to it and extension.
Definition: score.h:62
Q_INVOKABLE void addText(const QString &type, const QString &text)
Adds a header text to the score.
Definition: score.cpp:45
int nmeasures
Number of measures (read only)
Definition: score.h:64
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:52
QString mscoreVersion
MuseScore version the score has been last saved with (includes autosave) (read only) ...
Definition: score.h:80
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:82
int ntracks
Number of tracks (nstaves * 4) (read only)
Definition: score.h:70
bool hasLyrics
Whether score has lyrics (read only).
Definition: score.h:49
int harmonyCount
Number of harmony items (chord symbols) in the score (read only).
Definition: score.h:45