MuseScore Plugins  3.5
Plugins API for MuseScore
instrument.h
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2020 MuseScore BVBA
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 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __PLUGIN_API_INSTRUMENT_H__
21 #define __PLUGIN_API_INSTRUMENT_H__
22 
23 #include "scoreelement.h"
24 #include "libmscore/instrument.h"
25 
26 namespace Ms {
27 
28 class Instrument;
29 
30 namespace PluginAPI {
31 
32 class Instrument;
33 
34 //---------------------------------------------------------
35 // Channel
63 //---------------------------------------------------------
64 
65 class Channel : public QObject {
66  Q_OBJECT
67 
68  Ms::Channel* _channel;
69  Ms::Part* _part;
70 
72  Q_PROPERTY(QString name READ name)
73 
74 
80  Q_PROPERTY(int volume READ volume WRITE setVolume)
87  Q_PROPERTY(int pan READ pan WRITE setPan)
94  Q_PROPERTY(int chorus READ chorus WRITE setChorus)
101  Q_PROPERTY(int reverb READ reverb WRITE setReverb)
108  Q_PROPERTY(bool mute READ mute WRITE setMute)
109 
115  Q_PROPERTY(int midiProgram READ midiProgram WRITE setMidiProgram)
121  Q_PROPERTY(int midiBank READ midiBank WRITE setMidiBank)
122 
123  Ms::Channel* activeChannel();
124 
125  void setMidiBankAndProgram(int bank, int program, bool setUserBankController);
126 
127  public:
129  Channel(Ms::Channel* ch, Ms::Part* p, QObject* parent = nullptr)
130  : QObject(parent), _channel(ch), _part(p) {}
131 
132  QString name() const { return _channel->name(); }
133 
134  int volume() const { return _channel->volume(); }
135  void setVolume(int val) { activeChannel()->setVolume(qBound(0, val, 127)); }
136  int pan() const { return _channel->pan(); }
137  void setPan(int val) { activeChannel()->setPan(qBound(0, val, 127)); }
138  int chorus() const { return _channel->chorus(); }
139  void setChorus(int val) { activeChannel()->setChorus(qBound(0, val, 127)); }
140  int reverb() const { return _channel->reverb(); }
141  void setReverb(int val) { activeChannel()->setReverb(qBound(0, val, 127)); }
142 
143  bool mute() const { return _channel->mute(); }
144  void setMute(bool val) { activeChannel()->setMute(val); }
145 
146  int midiProgram() const { return _channel->program(); }
147  void setMidiProgram(int prog);
148  int midiBank() const { return _channel->bank(); }
149  void setMidiBank(int bank);
151  };
152 
153 //---------------------------------------------------------
154 // StringData
156 //---------------------------------------------------------
157 
158 class StringData : public QObject {
159  Q_OBJECT
160 
172  Q_PROPERTY(QVariantList strings READ stringList)
173 
174 
175  Q_PROPERTY(int frets READ frets)
176 
177  Ms::StringData _data;
178 
179  public:
181  StringData(const Ms::StringData* d, QObject* parent = nullptr)
182  : QObject(parent), _data(*d) {}
183 
184  QVariantList stringList() const;
185  int frets() const { return _data.frets(); }
187  };
188 
189 //---------------------------------------------------------
190 // ChannelListProperty
192 //---------------------------------------------------------
193 
194 class ChannelListProperty : public QQmlListProperty<Channel> {
195 public:
196  ChannelListProperty(Instrument* i);
197 
198  static int count(QQmlListProperty<Channel>* l);
199  static Channel* at(QQmlListProperty<Channel>* l, int i);
200  };
201 
202 //---------------------------------------------------------
203 // Instrument
205 //---------------------------------------------------------
206 
207 class Instrument : public QObject {
208  Q_OBJECT
209 
216  Q_PROPERTY(QString instrumentId READ instrumentId)
217  // Ms::Instrument supports multiple short/long names (for aeolus instruments?)
218  // but in practice only one is actually used. If this gets changed this API could
219  // be expanded.
221  Q_PROPERTY(QString longName READ longName)
223  Q_PROPERTY(QString shortName READ shortName)
224 
229  Q_PROPERTY(Ms::PluginAPI::StringData* stringData READ stringData)
230 
231  // TODO: a property for drumset?
232 
233  Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Channel> channels READ channels)
234 
235  Ms::Instrument* _instrument;
236  Ms::Part* _part;
237 
238  public:
240  Instrument(Ms::Instrument* i, Ms::Part* p)
241  : QObject(), _instrument(i), _part(p) {}
242 
243  Ms::Instrument* instrument() { return _instrument; };
244  const Ms::Instrument* instrument() const { return _instrument; };
245 
246  Ms::Part* part() { return _part; }
247 
248  QString instrumentId() const { return instrument()->instrumentId(); }
249  QString longName() const;
250  QString shortName() const;
251 
252  StringData* stringData() { return customWrap<StringData>(instrument()->stringData()); }
253 
254  ChannelListProperty channels();
256 
258  Q_INVOKABLE bool is(Ms::PluginAPI::Instrument* other) { return other && instrument() == other->instrument(); }
259  };
260 
261 } // namespace PluginAPI
262 } // namespace Ms
263 
264 #endif
Provides an access to channel properties.
Definition: instrument.h:65
int midiProgram
MIDI program number, from 0 to 127.
Definition: instrument.h:115
int midiBank
MIDI patch bank number.
Definition: instrument.h:121
Definition: part.h:42
Q_INVOKABLE bool is(Ms::PluginAPI::Instrument *other)
Checks whether two variables represent the same object.
Definition: instrument.h:258
QString instrumentId
The string identifier (MusicXML Sound ID) for this instrument.
Definition: instrument.h:216
Definition: instrument.h:158
QString name
Name of this channel.
Definition: instrument.h:72
int pan
Channel pan, from 0 to 127.
Definition: instrument.h:87
int chorus
Channel chorus, from 0 to 127.
Definition: instrument.h:94
int volume
Channel volume, from 0 to 127.
Definition: instrument.h:80
Definition: cursor.cpp:30
bool mute
Whether this channel is muted.
Definition: instrument.h:108
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:62
Definition: instrument.h:207
int reverb
Channel reverb, from 0 to 127.
Definition: instrument.h:101