MuseScore  3.4
Music composition and notation
qmlpluginapi.h
Go to the documentation of this file.
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/mscore.h"
20 #include "libmscore/utils.h"
21 
22 namespace Ms {
23 
24 class Element;
25 class MScore;
26 
32 namespace PluginAPI {
33 
34 class Element;
35 class FractionWrapper;
36 class MsProcess;
37 class Score;
38 
39 #define DECLARE_API_ENUM(qmlName, cppName) \
40  Q_PROPERTY(Ms::PluginAPI::Enum* qmlName READ get_##cppName CONSTANT) \
41  static Enum* cppName; \
42  static Enum* get_##cppName() { return cppName; }
43 
44 //---------------------------------------------------------
51 // @P scores array[Ms::Score] all currently open scores (read only)
52 //---------------------------------------------------------
53 
54 class PluginAPI : public Ms::QmlPlugin {
55  Q_OBJECT
57  Q_PROPERTY(QString menuPath READ menuPath WRITE setMenuPath)
59  Q_PROPERTY(QString filePath READ filePath)
61  Q_PROPERTY(QString version READ version WRITE setVersion)
63  Q_PROPERTY(QString description READ description WRITE setDescription)
65  Q_PROPERTY(QString pluginType READ pluginType WRITE setPluginType)
67  Q_PROPERTY(QString dockArea READ dockArea WRITE setDockArea)
69  Q_PROPERTY(bool requiresScore READ requiresScore WRITE setRequiresScore)
74  Q_PROPERTY(int division READ division)
76  Q_PROPERTY(int mscoreVersion READ mscoreVersion CONSTANT)
78  Q_PROPERTY(int mscoreMajorVersion READ mscoreMajorVersion CONSTANT)
80  Q_PROPERTY(int mscoreMinorVersion READ mscoreMinorVersion CONSTANT)
82  Q_PROPERTY(int mscoreUpdateVersion READ mscoreUpdateVersion CONSTANT)
84  Q_PROPERTY(qreal mscoreDPI READ mscoreDPI)
86  Q_PROPERTY(Ms::PluginAPI::Score* curScore READ curScore)
88  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Score> scores READ scores)
89 
90  // Should be initialized in qmlpluginapi.cpp
102  DECLARE_API_ENUM( Glissando, glissandoTypeEnum ) // was probably absent in 2.X
151  DECLARE_API_ENUM( Spanner, spannerAnchorEnum ) // probably unavailable in 2.X
152 
153  QFile logFile;
154 
155  static void initEnums();
156 
157  signals:
160  void run();
161 
215  void scoreStateChanged(const QMap<QString, QVariant>& state);
216 
217  public:
219  PluginAPI(QQuickItem* parent = 0);
220 
221  static void registerQmlTypes();
222 
223  void runPlugin() override { emit run(); }
224  void endCmd(const QMap<QString, QVariant>& stateInfo) override { emit scoreStateChanged(stateInfo); }
225 
226  Score* curScore() const;
227  QQmlListProperty<Score> scores();
229 
230  Q_INVOKABLE Ms::PluginAPI::Score* newScore(const QString& name, const QString& part, int measures);
231  Q_INVOKABLE Ms::PluginAPI::Element* newElement(int);
232  Q_INVOKABLE void removeElement(Ms::PluginAPI::Element* wrapped);
233  Q_INVOKABLE void cmd(const QString&);
235  Q_INVOKABLE Ms::PluginAPI::MsProcess* newQProcess();
236  Q_INVOKABLE bool writeScore(Ms::PluginAPI::Score*, const QString& name, const QString& ext);
237  Q_INVOKABLE Ms::PluginAPI::Score* readScore(const QString& name, bool noninteractive = false);
238  Q_INVOKABLE void closeScore(Ms::PluginAPI::Score*);
239 
240  Q_INVOKABLE void log(const QString&);
241  Q_INVOKABLE void logn(const QString&);
242  Q_INVOKABLE void log2(const QString&, const QString&);
243  Q_INVOKABLE void openLog(const QString&);
244  Q_INVOKABLE void closeLog();
245 
246  Q_INVOKABLE Ms::PluginAPI::FractionWrapper* fraction(int numerator, int denominator) const;
247  };
248 
249 #undef DECLARE_API_ENUM
250 } // namespace PluginAPI
251 } // namespace Ms
252 #endif
static Enum * accidentalTypeEnum
Definition: qmlpluginapi.h:94
int mscoreUpdateVersion() const
Definition: qmlplugin.h:92
static Enum * directionHEnum
Definition: qmlpluginapi.h:114
static Enum * lyricsSyllabicEnum
Definition: qmlpluginapi.h:106
Definition: qmlplugin.h:49
Q_INVOKABLE Ms::PluginAPI::Element * newElement(int)
Creates a new element with the given type.
Definition: qmlpluginapi.cpp:172
static Enum * tidEnum
Definition: qmlpluginapi.h:127
#define DECLARE_API_ENUM(qmlName, cppName)
Definition: qmlpluginapi.h:39
symbols for line break, page break etc.
Definition: layoutbreak.h:27
QString dockArea() const
Definition: qmlplugin.h:82
Definition: beam.h:37
static Enum * beamModeEnum
Definition: qmlpluginapi.h:96
Definition: elements.h:565
Virtual base class for slurs, ties, lines etc.
Definition: spanner.h:136
static Enum * alignEnum
Definition: qmlpluginapi.h:130
Ms::PluginAPI::Enum NoteHeadGroup
Contains Ms::NoteHead::Group enumeration values.
Definition: qmlpluginapi.h:144
int mscoreVersion() const
Definition: qmlplugin.h:89
static Enum * directionEnum
Definition: qmlpluginapi.h:110
Definition: elements.h:75
QFile logFile
Definition: qmlpluginapi.h:153
Ms::PluginAPI::Enum DirectionH
Contains Ms::MScore::DirectionH enumeration values.
Definition: qmlpluginapi.h:114
static Enum * layoutBreakTypeEnum
Definition: qmlpluginapi.h:104
QQmlListProperty< Score > scores()
Q_INVOKABLE Ms::PluginAPI::FractionWrapper * fraction(int numerator, int denominator) const
Creates a new fraction with the given numerator and denominator.
Definition: qmlpluginapi.cpp:304
Q_INVOKABLE void log2(const QString &, const QString &)
Definition: qmlpluginapi.cpp:281
Q_INVOKABLE void closeLog()
Definition: qmlpluginapi.cpp:250
Definition: accidental.h:65
Q_INVOKABLE void removeElement(Ms::PluginAPI::Element *wrapped)
Disposes of an Element and its children.
Definition: qmlpluginapi.cpp:193
void endCmd(const QMap< QString, QVariant > &stateInfo) override
Definition: qmlpluginapi.h:224
PlayEventType
Determines whether oranaments are automatically generated when playing a score and whether the PlayEv...
Definition: types.h:489
void runPlugin() override
Definition: qmlpluginapi.h:223
QString pluginType() const
Definition: qmlplugin.h:80
static void registerQmlTypes()
Definition: qmlpluginapi.cpp:313
Q_INVOKABLE Ms::PluginAPI::Score * newScore(const QString &name, const QString &part, int measures)
Definition: qmlpluginapi.cpp:203
static Enum * ornamentStyleEnum
Definition: qmlpluginapi.h:118
Placement
Definition: types.h:312
static Enum * placementEnum
Definition: qmlpluginapi.h:100
void setRequiresScore(bool b)
Definition: qmlplugin.h:83
Definition: glissando.h:49
Q_INVOKABLE void openLog(const QString &)
Definition: qmlpluginapi.cpp:237
Definition: score.h:36
QString description() const
Definition: qmlplugin.h:75
Tid
Enumerates the list of built-in text substyles.
Definition: types.h:371
void scoreStateChanged(const QMap< QString, QVariant > &state)
Notifies plugin about changes in score state.
static Enum * noteTypeEnum
Definition: qmlpluginapi.h:133
Q_INVOKABLE Ms::PluginAPI::MsProcess * newQProcess()
Not enabled currently (so excluded from plugin docs)
Definition: qmlpluginapi.cpp:293
Q_INVOKABLE void logn(const QString &)
Definition: qmlpluginapi.cpp:270
Ms::PluginAPI::Enum OrnamentStyle
Contains Ms::MScore::OrnamentStyle enumeration values.
Definition: qmlpluginapi.h:118
QString filePath() const
Definition: qmlplugin.h:77
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:145
Definition: aeolus.cpp:26
Score * curScore() const
int mscoreMinorVersion() const
Definition: qmlplugin.h:91
void setPluginType(const QString &s)
Definition: qmlplugin.h:79
static Enum * playEventTypeEnum
Definition: qmlpluginapi.h:136
void setVersion(const QString &s)
Definition: qmlplugin.h:72
Q_INVOKABLE void cmd(const QString &)
Definition: qmlpluginapi.cpp:224
NoteType
Definition: types.h:255
static Enum * noteValueTypeEnum
Definition: qmlpluginapi.h:148
static Enum * glissandoTypeEnum
Definition: qmlpluginapi.h:102
void setDockArea(const QString &s)
Definition: qmlplugin.h:81
int division() const
Definition: qmlplugin.h:88
Ms::PluginAPI::Enum NoteValueType
Contains Ms::Note::ValueType enumeration values.
Definition: qmlpluginapi.h:148
bool requiresScore() const
Definition: qmlplugin.h:84
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:54
Direction
Definition: types.h:282
GlissandoStyle
Definition: types.h:302
Q_INVOKABLE bool writeScore(Ms::PluginAPI::Score *, const QString &name, const QString &ext)
Writes a score to a file.
Definition: qmlpluginapi.cpp:128
QString version() const
Definition: qmlplugin.h:73
static Enum * noteHeadGroupEnum
Definition: qmlpluginapi.h:144
static Enum * spannerAnchorEnum
Definition: qmlpluginapi.h:151
Q_INVOKABLE void closeScore(Ms::PluginAPI::Score *)
Definition: qmlpluginapi.cpp:159
void setDescription(const QString &s)
Definition: qmlplugin.h:74
qreal mscoreDPI() const
Definition: qmlplugin.h:93
static Enum * segmentTypeEnum
Definition: qmlpluginapi.h:150
void setMenuPath(const QString &s)
Definition: qmlplugin.h:70
static Enum * elementTypeEnum
Definition: qmlpluginapi.h:92
QString menuPath() const
Definition: qmlplugin.h:71
int mscoreMajorVersion() const
Definition: qmlplugin.h:90
Definition: lyrics.h:27
Align
Definition: types.h:439
Fraction object available to QML plugins.
Definition: fraction.h:32
static void initEnums()
Definition: qmlpluginapi.cpp:58
static Enum * noteHeadTypeEnum
Definition: qmlpluginapi.h:140
Q_INVOKABLE void log(const QString &)
Definition: qmlpluginapi.cpp:260
static Enum * glissandoStyleEnum
Definition: qmlpluginapi.h:123
void run()
Indicates that the plugin was launched.
Ms::PluginAPI::Enum NoteHeadType
Contains Ms::NoteHead::Type enumeration values.
Definition: qmlpluginapi.h:140