File: qmlpluginapi.h

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 218,192 kB
  • sloc: cpp: 291,369; xml: 200,226; sh: 3,779; ansic: 1,447; python: 393; makefile: 249; perl: 82; pascal: 79
file content (188 lines) | stat: -rw-r--r-- 8,579 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2012 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 __QMLPLUGINAPI_H__
#define __QMLPLUGINAPI_H__

#include "config.h"

#include "../qmlplugin.h"
#include "enums.h"
#include "libmscore/mscore.h"
#include "libmscore/utils.h"

namespace Ms {

class Element;
class MScore;

/**
 * \namespace Ms::PluginAPI
 * Contains items exposed to the QML plugins framework.
 */

namespace PluginAPI {

class Element;
class FractionWrapper;
class MsProcess;
class Score;

#define DECLARE_API_ENUM(qmlName, cppName) \
      Q_PROPERTY(Ms::PluginAPI::Enum* qmlName READ get_##cppName CONSTANT) \
      static Enum* cppName; \
      static Enum* get_##cppName() { return cppName; }

//---------------------------------------------------------
///   \class PluginAPI
///   \brief Main class of the plugins framework.\ Named
///   as \p MuseScore in QML.
///   \details This class is exposed to QML plugins
///   framework under \p MuseScore name and is the root
///   component of each MuseScore plugin.
//   @P scores               array[Ms::Score]  all currently open scores (read only)
//---------------------------------------------------------

class PluginAPI : public Ms::QmlPlugin {
      Q_OBJECT
      /** Path where the plugin is placed in menu */
      Q_PROPERTY(QString menuPath        READ menuPath WRITE setMenuPath)
      /** Source file path, without the file name (read only) */
      Q_PROPERTY(QString filePath        READ filePath)
      /** Version of this plugin */
      Q_PROPERTY(QString version         READ version WRITE setVersion)
      /** Human-readable plugin description, displayed in Plugin Manager */
      Q_PROPERTY(QString description     READ description WRITE setDescription)
      /** Type may be dialog, dock, or not defined */
      Q_PROPERTY(QString pluginType      READ pluginType WRITE setPluginType)
      /** Where to dock on main screen. Possible values: left, top, bottom, right */
      Q_PROPERTY(QString dockArea        READ dockArea WRITE setDockArea)
      /** Whether the plugin requires an existing score to run, default is `true` */
      Q_PROPERTY(bool requiresScore      READ requiresScore WRITE setRequiresScore)
      /** Number of MIDI ticks for 1/4 note (read only) */
      Q_PROPERTY(int division            READ division)
      /** Complete version number of MuseScore in the form: MMmmuu (read only) */
      Q_PROPERTY(int mscoreVersion       READ mscoreVersion       CONSTANT)
      /** 1st part of the MuseScore version (read only) */
      Q_PROPERTY(int mscoreMajorVersion  READ mscoreMajorVersion  CONSTANT)
      /** 2nd part of the MuseScore version (read only)*/
      Q_PROPERTY(int mscoreMinorVersion  READ mscoreMinorVersion  CONSTANT)
      /** 3rd part of the MuseScore version (read only) */
      Q_PROPERTY(int mscoreUpdateVersion READ mscoreUpdateVersion CONSTANT)
      /** (read-only) */
      Q_PROPERTY(qreal mscoreDPI         READ mscoreDPI)
      /** Current score, if any (read only) */
      Q_PROPERTY(Ms::PluginAPI::Score* curScore     READ curScore)
      /** List of currently open scores (read only).\n \since MuseScore 3.2 */
      Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Score> scores READ scores)

      // Should be initialized in qmlpluginapi.cpp
      /// Contains Ms::ElementType enumeration values
      DECLARE_API_ENUM( Element,          elementTypeEnum         )
      /// Contains Ms::AccidentalType enumeration values
      DECLARE_API_ENUM( Accidental,       accidentalTypeEnum      )
      /// Contains Ms::Beam::Mode enumeration values
      DECLARE_API_ENUM( Beam,             beamModeEnum            )
      /// Contains Ms::Placement enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// Element.ABOVE and Element.BELOW.
      DECLARE_API_ENUM( Placement,        placementEnum           )
      /// Contains Ms::GlissandoType enumeration values
      DECLARE_API_ENUM( Glissando,        glissandoTypeEnum       ) // was probably absent in 2.X
      /// Contains Ms::LayoutBreak::Type enumeration values
      DECLARE_API_ENUM( LayoutBreak,      layoutBreakTypeEnum     )
      /// Contains Ms::Lyrics::Syllabic enumeration values
      DECLARE_API_ENUM( Lyrics,           lyricsSyllabicEnum      )
      /// Contains Ms::Direction enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// MScore.UP, MScore.DOWN, MScore.AUTO.
      DECLARE_API_ENUM( Direction,        directionEnum           )
      /// Contains Ms::MScore::DirectionH enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// MScore.LEFT, MScore.RIGHT, MScore.AUTO.
      DECLARE_API_ENUM( DirectionH,       directionHEnum          )
      /// Contains Ms::MScore::OrnamentStyle enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// MScore.DEFAULT, MScore.BAROQUE.
      DECLARE_API_ENUM( OrnamentStyle,    ornamentStyleEnum       )
      /// Contains Ms::GlissandoStyle enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// MScore.CHROMATIC, MScore.WHITE_KEYS, MScore.BLACK_KEYS,
      /// MScore.DIATONIC.
      DECLARE_API_ENUM( GlissandoStyle,   glissandoStyleEnum      )
      /// Contains Ms::Tid enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// TextStyleType (TextStyleType.TITLE etc.)
      DECLARE_API_ENUM( Tid,              tidEnum                 )
      /// Contains Ms::NoteType enumeration values 
      /// \since MuseScore 3.2.1
      DECLARE_API_ENUM( NoteType,         noteTypeEnum            )
      /// Contains Ms::NoteHead::Type enumeration values
      /// \note In MuseScore 2.X this enumeration was available in
      /// NoteHead class (e.g. NoteHead.HEAD_QUARTER).
      DECLARE_API_ENUM( NoteHeadType,     noteHeadTypeEnum        )
      /// Contains Ms::NoteHead::Group enumeration values
      /// \note In MuseScore 2.X this enumeration was available in
      /// NoteHead class (e.g. NoteHead.HEAD_TRIANGLE).
      DECLARE_API_ENUM( NoteHeadGroup,    noteHeadGroupEnum       )
      /// Contains Ms::Note::ValueType enumeration values
      /// \note In MuseScore 2.X this enumeration was available as
      /// Note.OFFSET_VAL, Note.USER_VAL
      DECLARE_API_ENUM( NoteValueType,    noteValueTypeEnum       )
      /// Contains Ms::SegmentType enumeration values
      DECLARE_API_ENUM( Segment,          segmentTypeEnum         )
      DECLARE_API_ENUM( Spanner,          spannerAnchorEnum       ) // probably unavailable in 2.X

      QFile logFile;

      static void initEnums();

   signals:
      /// Indicates that the plugin was launched.
      /// Implement \p onRun() function in your plugin to handle this signal.
      void run();

   public:
      /// \cond MS_INTERNAL
      PluginAPI(QQuickItem* parent = 0);

      static void registerQmlTypes();

      void runPlugin() override            { emit run();       }

      Score* curScore() const;
      QQmlListProperty<Score> scores();
      /// \endcond

      Q_INVOKABLE Ms::PluginAPI::Score* newScore(const QString& name, const QString& part, int measures);
      Q_INVOKABLE Ms::PluginAPI::Element* newElement(int);
      Q_INVOKABLE void removeElement(Ms::PluginAPI::Element* wrapped);
      Q_INVOKABLE void cmd(const QString&);
      /** \cond PLUGIN_API \private \endcond */
      Q_INVOKABLE Ms::PluginAPI::MsProcess* newQProcess();
      Q_INVOKABLE bool writeScore(Ms::PluginAPI::Score*, const QString& name, const QString& ext);
      Q_INVOKABLE Ms::PluginAPI::Score* readScore(const QString& name, bool noninteractive = false);
      Q_INVOKABLE void closeScore(Ms::PluginAPI::Score*);

      Q_INVOKABLE void log(const QString&);
      Q_INVOKABLE void logn(const QString&);
      Q_INVOKABLE void log2(const QString&, const QString&);
      Q_INVOKABLE void openLog(const QString&);
      Q_INVOKABLE void closeLog();

      Q_INVOKABLE Ms::PluginAPI::FractionWrapper* fraction(int numerator, int denominator) const;
      };

#undef DECLARE_API_ENUM
} // namespace PluginAPI
} // namespace Ms
#endif