MuseScore Plugins  3.5
Plugins API for MuseScore
qmlpluginapi.h
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2012 Werner Schweer
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 __QMLPLUGINAPI_H__
14 #define __QMLPLUGINAPI_H__
15 
16 #include "config.h"
17 #include "../qmlplugin.h"
18 #include "enums.h"
19 #include "libmscore/harmony.h"
20 #include "libmscore/lyrics.h"
21 #include "libmscore/mscore.h"
22 #include "libmscore/utils.h"
23 #include "libmscore/score.h"
24 #include "libmscore/spanner.h"
25 
26 namespace Ms {
27 
28 class Element;
29 class MScore;
30 
36 namespace PluginAPI {
37 
38 class Element;
39 class FractionWrapper;
40 class MsProcess;
41 class Score;
42 
43 #define DECLARE_API_ENUM(qmlName, cppName, enumName) \
44  Q_PROPERTY(Ms::PluginAPI::Enum* qmlName READ get_##cppName CONSTANT) \
45  static Enum* cppName; \
46  static Enum* get_##cppName() { \
47  if (!cppName) \
48  cppName = wrapEnum<enumName>(); \
49  return cppName; \
50  }
51 
52 //---------------------------------------------------------
59 // @P scores array[Ms::Score] all currently open scores (read only)
60 //---------------------------------------------------------
61 
62 class PluginAPI : public Ms::QmlPlugin {
63  Q_OBJECT
65  Q_PROPERTY(QString menuPath READ menuPath WRITE setMenuPath)
67  Q_PROPERTY(QString filePath READ filePath)
69  Q_PROPERTY(QString version READ version WRITE setVersion)
71  Q_PROPERTY(QString description READ description WRITE setDescription)
73  Q_PROPERTY(QString pluginType READ pluginType WRITE setPluginType)
75  Q_PROPERTY(QString dockArea READ dockArea WRITE setDockArea)
77  Q_PROPERTY(bool requiresScore READ requiresScore WRITE setRequiresScore)
82  Q_PROPERTY(int division READ division)
84  Q_PROPERTY(int mscoreVersion READ mscoreVersion CONSTANT)
86  Q_PROPERTY(int mscoreMajorVersion READ mscoreMajorVersion CONSTANT)
88  Q_PROPERTY(int mscoreMinorVersion READ mscoreMinorVersion CONSTANT)
90  Q_PROPERTY(int mscoreUpdateVersion READ mscoreUpdateVersion CONSTANT)
92  Q_PROPERTY(qreal mscoreDPI READ mscoreDPI)
94  Q_PROPERTY(Ms::PluginAPI::Score* curScore READ curScore)
96  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Score> scores READ scores)
97 
98  // Should be initialized in qmlpluginapi.cpp
100  DECLARE_API_ENUM( Element, elementTypeEnum, Ms::ElementType )
102  DECLARE_API_ENUM( Accidental, accidentalTypeEnum, Ms::AccidentalType )
104  DECLARE_API_ENUM( Beam, beamModeEnum, Ms::Beam::Mode )
108  DECLARE_API_ENUM( Placement, placementEnum, Ms::Placement )
110  DECLARE_API_ENUM( Glissando, glissandoTypeEnum, Ms::GlissandoType ) // was probably absent in 2.X
112  DECLARE_API_ENUM( LayoutBreak, layoutBreakTypeEnum, Ms::LayoutBreak::Type )
114  DECLARE_API_ENUM( Lyrics, lyricsSyllabicEnum, Ms::Lyrics::Syllabic )
118  DECLARE_API_ENUM( Direction, directionEnum, Ms::Direction )
122  DECLARE_API_ENUM( DirectionH, directionHEnum, Ms::MScore::DirectionH )
126  DECLARE_API_ENUM( OrnamentStyle, ornamentStyleEnum, Ms::MScore::OrnamentStyle )
131  DECLARE_API_ENUM( GlissandoStyle, glissandoStyleEnum, Ms::GlissandoStyle )
135  DECLARE_API_ENUM( Tid, tidEnum, Ms::Tid )
138  DECLARE_API_ENUM( Align, alignEnum, Ms::Align )
141  DECLARE_API_ENUM( NoteType, noteTypeEnum, Ms::NoteType )
144  DECLARE_API_ENUM( PlayEventType, playEventTypeEnum, Ms::PlayEventType )
148  DECLARE_API_ENUM( NoteHeadType, noteHeadTypeEnum, Ms::NoteHead::Type )
151  DECLARE_API_ENUM( NoteHeadScheme, noteHeadSchemeEnum, Ms::NoteHead::Scheme )
155  DECLARE_API_ENUM( NoteHeadGroup, noteHeadGroupEnum, Ms::NoteHead::Group )
159  DECLARE_API_ENUM( NoteValueType, noteValueTypeEnum, Ms::Note::ValueType )
161  DECLARE_API_ENUM( Segment, segmentTypeEnum, Ms::SegmentType )
162  DECLARE_API_ENUM( Spanner, spannerAnchorEnum, Ms::Spanner::Anchor ) // probably unavailable in 2.X
165  DECLARE_API_ENUM( SymId, symIdEnum, Ms::SymId )
168  DECLARE_API_ENUM( HarmonyType, harmonyTypeEnum, Ms::HarmonyType )
169 
170  QFile logFile;
171 
172  signals:
175  void run();
176 
233  void scoreStateChanged(const QMap<QString, QVariant>& state);
234 
235  public:
237  PluginAPI(QQuickItem* parent = 0);
238 
239  static void registerQmlTypes();
240 
241  void runPlugin() override { emit run(); }
242  void endCmd(const QMap<QString, QVariant>& stateInfo) override { emit scoreStateChanged(stateInfo); }
243 
244  Score* curScore() const;
245  QQmlListProperty<Score> scores();
247 
248  Q_INVOKABLE Ms::PluginAPI::Score* newScore(const QString& name, const QString& part, int measures);
249  Q_INVOKABLE Ms::PluginAPI::Element* newElement(int);
250  Q_INVOKABLE void removeElement(Ms::PluginAPI::Element* wrapped);
251  Q_INVOKABLE void cmd(const QString&);
253  Q_INVOKABLE Ms::PluginAPI::MsProcess* newQProcess();
254  Q_INVOKABLE bool writeScore(Ms::PluginAPI::Score*, const QString& name, const QString& ext);
255  Q_INVOKABLE Ms::PluginAPI::Score* readScore(const QString& name, bool noninteractive = false);
256  Q_INVOKABLE void closeScore(Ms::PluginAPI::Score*);
257 
258  Q_INVOKABLE void log(const QString&);
259  Q_INVOKABLE void logn(const QString&);
260  Q_INVOKABLE void log2(const QString&, const QString&);
261  Q_INVOKABLE void openLog(const QString&);
262  Q_INVOKABLE void closeLog();
263 
264  Q_INVOKABLE Ms::PluginAPI::FractionWrapper* fraction(int numerator, int denominator) const;
265  };
266 
267 #undef DECLARE_API_ENUM
268 } // namespace PluginAPI
269 } // namespace Ms
270 #endif
QString description
Human-readable plugin description, displayed in Plugin Manager.
Definition: qmlpluginapi.h:71
bool requiresScore
Whether the plugin requires an existing score to run, default is true
Definition: qmlpluginapi.h:77
QString filePath
Source file path, without the file name (read only)
Definition: qmlpluginapi.h:67
SymId
Definition: sym.h:45
Ms::PluginAPI::Enum NoteHeadGroup
Contains Ms::NoteHead::Group enumeration values.
Definition: qmlpluginapi.h:155
symbols for line break, page break etc.
Definition: layoutbreak.h:27
Definition: beam.h:37
Placement
Definition: types.h:393
Tid
Enumerates the list of built-in text substyles.
Definition: types.h:462
void run()
Indicates that the plugin was launched.
QString dockArea
Where to dock on main screen.
Definition: qmlpluginapi.h:75
Ms::PluginAPI::Enum NoteHeadType
Contains Ms::NoteHead::Type enumeration values.
Definition: qmlpluginapi.h:148
Definition: elements.h:709
Q_INVOKABLE bool writeScore(Ms::PluginAPI::Score *, const QString &name, const QString &ext)
Writes a score to a file.
Definition: qmlpluginapi.cpp:97
QQmlListProperty< Ms::PluginAPI::Score > scores
List of currently open scores (read only).
Definition: qmlpluginapi.h:96
int mscoreMajorVersion
1st part of the MuseScore version (read only)
Definition: qmlpluginapi.h:86
ElementType
Definition: types.h:34
Q_INVOKABLE Ms::PluginAPI::Score * readScore(const QString &name, bool noninteractive=false)
Reads the score from a file and opens it in a new tab.
Definition: qmlpluginapi.cpp:114
void scoreStateChanged(const QMap< QString, QVariant > &state)
Notifies plugin about changes in score state.
Definition: elements.h:85
Direction
Definition: types.h:351
Align
Align Because the Align enum has Top = 0 and Left = 0, align() & Align::Top will always return false...
Definition: types.h:537
Ms::PluginAPI::Enum Glissando
Contains Ms::GlissandoType enumeration values.
Definition: qmlpluginapi.h:110
PlayEventType
Determines whether oranaments are automatically generated when playing a score and whether the PlayEv...
Definition: types.h:587
Ms::PluginAPI::Enum Accidental
Contains Ms::AccidentalType enumeration values.
Definition: qmlpluginapi.h:102
Ms::PluginAPI::Score curScore
Current score, if any (read only)
Definition: qmlpluginapi.h:94
Ms::PluginAPI::Enum DirectionH
Contains Ms::MScore::DirectionH enumeration values.
Definition: qmlpluginapi.h:122
QString menuPath
Path where the plugin is placed in menu.
Definition: qmlpluginapi.h:65
NoteType
Definition: types.h:324
Ms::PluginAPI::Enum NoteHeadScheme
Contains Ms::NoteHead::Scheme enumeration values.
Definition: qmlpluginapi.h:151
GlissandoStyle
Definition: types.h:371
HarmonyType
Definition: types.h:381
Definition: score.h:41
Ms::PluginAPI::Enum OrnamentStyle
Contains Ms::MScore::OrnamentStyle enumeration values.
Definition: qmlpluginapi.h:126
qreal mscoreDPI
(read-only)
Definition: qmlpluginapi.h:92
AccidentalType
Definition: types.h:152
Definition: cursor.cpp:30
Definition: note.h:53
SegmentType
Definition: types.h:424
int mscoreUpdateVersion
3rd part of the MuseScore version (read only)
Definition: qmlpluginapi.h:90
Q_INVOKABLE Ms::PluginAPI::FractionWrapper * fraction(int numerator, int denominator) const
Creates a new fraction with the given numerator and denominator.
Definition: qmlpluginapi.cpp:273
Definition: mscore.h:288
Start an external program. Available in QML as QProcess.
Definition: util.h:116
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:62
int mscoreMinorVersion
2nd part of the MuseScore version (read only)
Definition: qmlpluginapi.h:88
QString pluginType
Type may be dialog, dock, or not defined.
Definition: qmlpluginapi.h:73
int division
Number of MIDI ticks for 1/4 note (read only)
Definition: qmlpluginapi.h:82
int mscoreVersion
Complete version number of MuseScore in the form: MMmmuu (read only)
Definition: qmlpluginapi.h:84
QString version
Version of this plugin.
Definition: qmlpluginapi.h:69
Q_INVOKABLE void removeElement(Ms::PluginAPI::Element *wrapped)
Disposes of an Element and its children.
Definition: qmlpluginapi.cpp:162
Ms::PluginAPI::Enum NoteValueType
Contains Ms::Note::ValueType enumeration values.
Definition: qmlpluginapi.h:159
Definition: lyrics.h:27
Fraction object available to QML plugins.
Definition: fraction.h:32
Q_INVOKABLE Ms::PluginAPI::Element * newElement(int)
Creates a new element with the given type.
Definition: qmlpluginapi.cpp:141
GlissandoType
Definition: types.h:361
Definition: elements.h:423