MuseScore  3.4
Music composition and notation
instrument.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 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 __INSTRUMENT_H__
14 #define __INSTRUMENT_H__
15 
16 #include "stringdata.h"
17 #include "mscore.h"
18 #include "notifier.hpp"
19 #include "synthesizer/event.h"
20 #include "interval.h"
21 #include "clef.h"
22 #include <QtGlobal>
23 #include <QString>
24 
25 namespace Ms {
26 
27 class InstrumentTemplate;
28 class MasterScore;
29 class XmlWriter;
30 class XmlReader;
31 class Drumset;
32 class StringData;
33 class ChannelListener;
34 class Synthesizer;
35 
36 //---------------------------------------------------------
37 // StaffName
38 //---------------------------------------------------------
39 
40 class StaffName {
41  QString _name; // html string
42  int _pos; // even number -> between staves
43 
44  public:
45  StaffName() {}
46  StaffName(const QString& s, int p=0);
47 
48  bool operator==(const StaffName&) const;
49  void read(XmlReader&);
50  void write(XmlWriter& xml, const char* name) const;
51  int pos() const { return _pos; }
52  QString name() const { return _name; }
53  };
54 
55 //---------------------------------------------------------
56 // StaffNameList
57 //---------------------------------------------------------
58 
59 class StaffNameList : public QList<StaffName> {
60 
61  public:
62  void write(XmlWriter& xml, const char* name) const;
63  };
64 
65 //---------------------------------------------------------
66 // NamedEventList
67 //---------------------------------------------------------
68 
70  QString name;
71  QString descr;
72  std::vector<MidiCoreEvent> events;
73 
74  void write(XmlWriter&, const QString& name) const;
75  void read(XmlReader&);
76  bool operator==(const NamedEventList& i) const { return i.name == name && i.events == events; }
77  };
78 
79 //---------------------------------------------------------
80 // MidiArticulation
81 //---------------------------------------------------------
82 
84  QString name;
85  QString descr;
86  int velocity; // velocity change: -100% - +100%
87  int gateTime; // gate time change: -100% - +100%
88  void write(XmlWriter&) const;
89  void read(XmlReader&);
90 
92  MidiArticulation(const QString& n, const QString& d, int v, int g) : name(n), descr(d), velocity(v), gateTime(g) {}
93  bool operator==(const MidiArticulation& i) const;
94  };
95 
96 //---------------------------------------------------------
97 // Channel
98 //---------------------------------------------------------
99 
100 class Channel {
101  // this are the indexes of controllers which are always present in
102  // Channel init EventList (maybe zero)
103  QString _name;
104  QString _descr;
105 
106  static const int DEFAULT_COLOR = 0x3399ff;
107  int _color; //rgb
108 
109  QString _synti;
110 
111  char _volume;
112  char _pan;
113 
114  char _chorus;
115  char _reverb;
116 
117  int _program; // current values as shown in mixer
118  int _bank; // initialized from "init"
119  int _channel { 0 }; // mscore channel number, mapped to midi port/channel
120 
121  bool _soloMute;
122  bool _mute;
123  bool _solo;
124 
125  // MuseScore General-specific SND flags:
126  bool _userBankController = false; // if the user has changed the bank controller as opposed to switchExpressive
127  bool _switchedToExpressive = false; // if the patch has been automatically switched to and expr variant
128 
129  mutable std::vector<MidiCoreEvent> _init;
130  mutable bool _mustUpdateInit = true;
131 
132 public:
133  static const char* DEFAULT_NAME;
134  static constexpr char defaultVolume = 100;
135 
136  enum class A : char {
137  HBANK, LBANK, PROGRAM, VOLUME, PAN, CHORUS, REVERB,
138  INIT_COUNT
139  };
140 
141  enum class Prop : char {
142  VOLUME, PAN, CHORUS, REVERB, NAME, DESCR, PROGRAM, BANK, COLOR,
143  SOLOMUTE, SOLO, MUTE, SYNTI, CHANNEL, USER_BANK_CONTROL
144  };
145 
146 private:
148  void firePropertyChanged(Channel::Prop prop) { _notifier.notify(prop); }
149 
150 public:
151  std::vector<MidiCoreEvent>& initList() const;
152 
153  QString name() const { return _name; }
154  void setName(const QString& value);
155  QString descr() const { return _descr; }
156  void setDescr(const QString& value);
157  QString synti() const { return _synti; }
158  void setSynti(const QString& value);
159  int color() const { return _color; }
160  void setColor(int value);
161 
162  char volume() const { return _volume; }
163  void setVolume(char value);
164  char pan() const { return _pan; }
165  void setPan(char value);
166  char chorus() const { return _chorus; }
167  void setChorus(char value);
168  char reverb() const { return _reverb; }
169  void setReverb(char value);
170 
171  int program() const { return _program; }
172  void setProgram(int value);
173  int bank() const { return _bank; }
174  void setBank(int value);
175  int channel() const { return _channel; }
176  void setChannel(int value);
177 
178  bool soloMute() const { return _soloMute; }
179  void setSoloMute(bool value);
180  bool mute() const { return _mute; }
181  void setMute(bool value);
182  bool solo() const { return _solo; }
183  void setSolo(bool value);
184 
185  // If the bank controller is set by the user or not
186  bool userBankController() const { return _userBankController; }
187  void setUserBankController(bool val);
188 
189  QList<NamedEventList> midiActions;
190  QList<MidiArticulation> articulation;
191 
192  Channel();
193  void write(XmlWriter&, const Part* part) const;
194  void read(XmlReader&, Part *part);
195  void updateInitList() const;
196  bool operator==(const Channel& c) { return (_name == c._name) && (_channel == c._channel); }
197 
198  void addListener(ChannelListener* l);
199  void removeListener(ChannelListener* l);
200 
201  void switchExpressive(Synthesizer* synth, bool expressive, bool force = false);
202  };
203 
204 //---------------------------------------------------------
205 // ChannelListener
206 //---------------------------------------------------------
207 
208 class ChannelListener : public Listener<Channel::Prop> {
209  public:
210  virtual void propertyChanged(Channel::Prop property) = 0;
211  void setNotifier(Channel* ch) { Listener::setNotifier(nullptr); if (ch) ch->addListener(this); }
212 
213  private:
214  void receive(Channel::Prop prop) override { propertyChanged(prop); }
215  };
216 
217 //---------------------------------------------------------
218 // PartChannelSettingsLink
219 //---------------------------------------------------------
220 
222  // A list of properties which may vary for different excerpts.
223  static const std::initializer_list<Channel::Prop> excerptProperties;
224 
225  private:
228  bool _excerpt;
229 
230  static bool isExcerptProperty(Channel::Prop p) { return std::find(excerptProperties.begin(), excerptProperties.end(), p) != excerptProperties.end(); }
231  static void applyProperty(Channel::Prop p, const Channel* from, Channel* to);
232  void propertyChanged(Channel::Prop p) override;
233 
234  public:
235  PartChannelSettingsLink() : _main(nullptr), _bound(nullptr), _excerpt(false) {}
236  PartChannelSettingsLink(Channel* main, Channel* bound, bool excerpt);
239  PartChannelSettingsLink& operator=(const PartChannelSettingsLink&) = delete;
242 
244  };
245 
246 //---------------------------------------------------------
247 // Instrument
248 //---------------------------------------------------------
249 
250 class Instrument {
253  QString _trackName;
254 
255  char _minPitchA, _maxPitchA, _minPitchP, _maxPitchP;
257  QString _instrumentId;
258 
262 
263  QList<NamedEventList> _midiActions;
264  QList<MidiArticulation> _articulation;
265  QList<Channel*> _channel; // at least one entry
266  QList<ClefTypeList> _clefType;
267 
269 
270  public:
271  Instrument();
272  Instrument(const Instrument&);
273  void operator=(const Instrument&);
274  ~Instrument();
275 
276  void read(XmlReader&, Part *part);
277  bool readProperties(XmlReader&, Part* , bool* customDrumset);
278  void write(XmlWriter& xml, const Part* part) const;
279  NamedEventList* midiAction(const QString& s, int channel) const;
280  int channelIdx(const QString& s) const;
281  void updateVelocity(int* velocity, int channel, const QString& name);
282  void updateGateTime(int* gateTime, int channelIdx, const QString& name);
283 
284  bool operator==(const Instrument&) const;
285 
286  void setMinPitchP(int v) { _minPitchP = v; }
287  void setMaxPitchP(int v) { _maxPitchP = v; }
288  void setMinPitchA(int v) { _minPitchA = v; }
289  void setMaxPitchA(int v) { _maxPitchA = v; }
290  Interval transpose() const { return _transpose; }
291  void setTranspose(const Interval& v) { _transpose = v; }
292  QString instrumentId() { return _instrumentId; }
293  void setInstrumentId(const QString& instrumentId) { _instrumentId = instrumentId; }
294 
295  void setDrumset(const Drumset* ds);
296  const Drumset* drumset() const { return _drumset; }
297  Drumset* drumset() { return _drumset; }
298  bool useDrumset() const { return _useDrumset; }
299  void setUseDrumset(bool val);
300  void setAmateurPitchRange(int a, int b) { _minPitchA = a; _maxPitchA = b; }
301  void setProfessionalPitchRange(int a, int b) { _minPitchP = a; _maxPitchP = b; }
302  Channel* channel(int idx) { return _channel[idx]; }
303  const Channel* channel(int idx) const { return _channel[idx]; }
304  Channel* playbackChannel(int idx, MasterScore*);
305  const Channel* playbackChannel(int idx, const MasterScore*) const;
306  ClefTypeList clefType(int staffIdx) const;
307  void setClefType(int staffIdx, const ClefTypeList& c);
308 
309  const QList<NamedEventList>& midiActions() const { return _midiActions; }
310  const QList<MidiArticulation>& articulation() const { return _articulation; }
311 
312  const QList<Channel*>& channel() const { return _channel; }
313  void appendChannel(Channel* c) { _channel.append(c); }
314  void clearChannels() { _channel.clear(); }
315 
316  void setMidiActions(const QList<NamedEventList>& l) { _midiActions = l; }
317  void setArticulation(const QList<MidiArticulation>& l) { _articulation = l; }
318  const StringData* stringData() const { return &_stringData; }
319  void setStringData(const StringData& d) { _stringData = d; }
320 
321  void setLongName(const QString& f);
322  void setShortName(const QString& f);
323 
324  void addLongName(const StaffName& f);
325  void addShortName(const StaffName& f);
326 
327  int minPitchP() const;
328  int maxPitchP() const;
329  int minPitchA() const;
330  int maxPitchA() const;
331  QString instrumentId() const;
332 
333  const QList<StaffName>& longNames() const;
334  const QList<StaffName>& shortNames() const;
335  QList<StaffName>& longNames();
336 
337  QList<StaffName>& shortNames();
338  QString trackName() const;
339  void setTrackName(const QString& s);
340  static Instrument fromTemplate(const InstrumentTemplate* t);
341 
342  bool singleNoteDynamics() const { return _singleNoteDynamics; }
343  void setSingleNoteDynamics(bool val) { _singleNoteDynamics = val; }
344  void setSingleNoteDynamicsFromTemplate();
345  bool getSingleNoteDynamicsFromTemplate() const;
346  void switchExpressive(MasterScore* score, Synthesizer* synth, bool expressive, bool force = false);
347  };
348 
349 //---------------------------------------------------------
350 // InstrumentList
351 //---------------------------------------------------------
352 
353 class InstrumentList : public std::map<const int, Instrument*> {
355 
356  public:
358  const Instrument* instrument(int tick) const;
359  Instrument* instrument(int tick);
360  void setInstrument(Instrument*, int tick);
361  };
362 
363 } // namespace Ms
364 #endif
365 
void setTranspose(const Interval &v)
Definition: instrument.h:291
std::vector< MidiCoreEvent > _init
Definition: instrument.h:129
QString descr
Definition: instrument.h:71
QString name
Definition: instrument.h:84
char volume() const
Definition: instrument.h:162
bool singleNoteDynamics() const
Definition: instrument.h:342
bool _singleNoteDynamics
Definition: instrument.h:268
QString _synti
Definition: instrument.h:109
void setMaxPitchA(int v)
Definition: instrument.h:289
char chorus() const
Definition: instrument.h:166
int pos() const
Definition: instrument.h:51
Definition: xml.h:67
bool solo() const
Definition: instrument.h:182
static Instrument defaultInstrument
Definition: instrument.h:354
QString _name
Definition: instrument.h:41
const StringData * stringData() const
Definition: instrument.h:318
int gateTime
Definition: instrument.h:87
Definition: synthesizer.h:41
void setNotifier(Notifier< Data > *n)
Definition: notifier.hpp:127
Definition: score.h:1227
Definition: instrument.h:83
QString name() const
Definition: instrument.h:52
char _pan
Definition: instrument.h:112
void setMinPitchA(int v)
Definition: instrument.h:288
MidiArticulation(const QString &n, const QString &d, int v, int g)
Definition: instrument.h:92
Interval _transpose
Definition: instrument.h:256
int program() const
Definition: instrument.h:171
Definition: notifier.hpp:25
int _channel
Definition: instrument.h:119
char _volume
Definition: instrument.h:111
bool mute() const
Definition: instrument.h:180
Prop
Definition: instrument.h:141
QString _name
Definition: instrument.h:103
Definition: instrument.h:250
Definition: instrument.h:69
int channel() const
Definition: instrument.h:175
int color() const
Definition: instrument.h:159
QString name() const
Definition: instrument.h:153
Definition: clef.h:81
QString descr() const
Definition: instrument.h:155
QString _descr
Definition: instrument.h:104
QList< MidiArticulation > _articulation
Definition: instrument.h:264
Channel * channel(int idx)
Definition: instrument.h:302
Definition of classes Clef.
const Channel * channel(int idx) const
Definition: instrument.h:303
bool _mute
Definition: instrument.h:122
Definition: instrument.h:40
void notify(Data d) const
Definition: notifier.hpp:92
int _bank
Definition: instrument.h:118
char _chorus
Definition: instrument.h:114
Definition: editdrumset.cpp:32
int main(int, char *[])
Definition: ltest.cpp:27
Definition: stringdata.h:35
void read(XmlReader &)
Definition: instrument.cpp:195
bool soloMute() const
Definition: instrument.h:178
Drumset * _drumset
Definition: instrument.h:260
int _color
Definition: instrument.h:107
QList< NamedEventList > midiActions
Definition: instrument.h:189
char _reverb
Definition: instrument.h:115
StaffNameList _shortNames
Definition: instrument.h:252
bool operator==(const StaffName &) const
Definition: instrument.cpp:1194
A
Definition: instrument.h:136
void setMaxPitchP(int v)
Definition: instrument.h:287
QString descr
Definition: instrument.h:85
Definition: drumset.h:68
QString _instrumentId
Definition: instrument.h:257
void swap(PartChannelSettingsLink &l1, PartChannelSettingsLink &l2)
Definition: instrument.cpp:966
const QList< Channel * > & channel() const
Definition: instrument.h:312
void clearChannels()
Definition: instrument.h:314
bool userBankController() const
Definition: instrument.h:186
char reverb() const
Definition: instrument.h:168
bool useDrumset() const
Definition: instrument.h:298
bool _soloMute
Definition: instrument.h:121
void setSingleNoteDynamics(bool val)
Definition: instrument.h:343
int _pos
Definition: instrument.h:42
Notifier< Channel::Prop > _notifier
Definition: instrument.h:147
void setMidiActions(const QList< NamedEventList > &l)
Definition: instrument.h:316
StaffName()
Definition: instrument.h:45
char pan() const
Definition: instrument.h:164
int velocity
Definition: instrument.h:86
bool _solo
Definition: instrument.h:123
QList< NamedEventList > _midiActions
Definition: instrument.h:263
std::vector< MidiCoreEvent > events
Definition: instrument.h:72
Interval transpose() const
Definition: instrument.h:290
const QList< NamedEventList > & midiActions() const
Definition: instrument.h:309
void addListener(ChannelListener *l)
Definition: instrument.cpp:907
Definition: interval.h:22
void setAmateurPitchRange(int a, int b)
Definition: instrument.h:300
Definition: aeolus.cpp:26
QString instrumentId()
Definition: instrument.h:292
QString _trackName
Definition: instrument.h:253
void firePropertyChanged(Channel::Prop prop)
Definition: instrument.h:148
Definition: xml.h:218
QList< ClefTypeList > _clefType
Definition: instrument.h:266
void write(XmlWriter &xml, const char *name) const
Definition: instrument.cpp:181
const QList< MidiArticulation > & articulation() const
Definition: instrument.h:310
static const char * DEFAULT_NAME
Definition: instrument.h:133
Definition: inspectorAmbitus.cpp:21
Definition: xmlwriter.h:26
void receive(Channel::Prop prop) override
Definition: instrument.h:214
bool _useDrumset
Definition: instrument.h:259
InstrumentList()
Definition: instrument.h:357
int _program
Definition: instrument.h:117
QString name
Definition: instrument.h:70
Definition: instrument.h:100
QList< Channel * > _channel
Definition: instrument.h:265
void setNotifier(Channel *ch)
Definition: instrument.h:211
Definition: xmlreader.h:28
char _minPitchP
Definition: instrument.h:255
StaffNameList _longNames
Definition: instrument.h:251
Definition: instrument.h:208
void setMinPitchP(int v)
Definition: instrument.h:286
bool operator==(const Channel &c)
Definition: instrument.h:196
Definition: instrtemplate.h:48
Definition: instrument.h:353
void setArticulation(const QList< MidiArticulation > &l)
Definition: instrument.h:317
int bank() const
Definition: instrument.h:173
void appendChannel(Channel *c)
Definition: instrument.h:313
StringData _stringData
Definition: instrument.h:261
void setInstrumentId(const QString &instrumentId)
Definition: instrument.h:293
Definition: part.h:47
QList< MidiArticulation > articulation
Definition: instrument.h:190
QString synti() const
Definition: instrument.h:157
bool operator==(const NamedEventList &i) const
Definition: instrument.h:76
Drumset * drumset()
Definition: instrument.h:297
Definition: instrument.h:59
void setProfessionalPitchRange(int a, int b)
Definition: instrument.h:301
void setStringData(const StringData &d)
Definition: instrument.h:319
MidiArticulation()
Definition: instrument.h:91
const Drumset * drumset() const
Definition: instrument.h:296