MuseScore  3.4
Music composition and notation
event.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 __EVENT_H__
14 #define __EVENT_H__
15 
16 #include <map>
17 
18 namespace Ms {
19 
20 class Note;
21 class XmlWriter;
22 
23 enum class BeatType : char;
24 
25 //---------------------------------------------------------
26 // Event types
27 //---------------------------------------------------------
28 
29 enum {
30  ME_INVALID = 0,
31  ME_NOTEOFF = 0x80,
32  ME_NOTEON = 0x90,
33  ME_POLYAFTER = 0xa0,
34  ME_CONTROLLER = 0xb0,
35  ME_PROGRAM = 0xc0,
36  ME_AFTERTOUCH = 0xd0,
37  ME_PITCHBEND = 0xe0,
38  ME_SYSEX = 0xf0,
39  ME_META = 0xff,
40  ME_SONGPOS = 0xf2,
41  ME_ENDSYSEX = 0xf7,
42  ME_CLOCK = 0xf8,
43  ME_START = 0xfa,
44  ME_CONTINUE = 0xfb,
45  ME_STOP = 0xfc,
46  ME_SENSE = 0xfe, // active sense (used by yamaha)
47 
48  ME_NOTE = 0x1,
49  ME_CHORD = 0x2,
50  ME_TICK1 = 0x3, // metronome tick akzent
51  ME_TICK2 = 0x4, // metronome tick
52  };
53 
54 //---------------------------------------------------------
55 // Midi Meta Events
56 //---------------------------------------------------------
57 
58 enum {
60  META_TEXT = 1,
67  META_PROGRAM_NAME = 8, // MIDI Meta Events 8 and 9 were defined as above by the MMA in 1998
68  META_DEVICE_NAME = 9, // It is therefore necessary to redefine MuseScore's private meta events
69  META_TRACK_COMMENT = 0xf, // Using the block starting 0x10 seems sensible as that is currently clear
70  META_TITLE = 0x10, // mscore extension
71  META_SUBTITLE = 0x11, // mscore extension
72  META_COMPOSER = 0x12, // mscore extension
73  META_TRANSLATOR = 0x13, // mscore extension
74  META_POET = 0x14, // mscore extension
77  META_EOT = 0x2f, // end of track
78  META_TEMPO = 0x51,
81  META_SPECIFIC = 0x7F // sequencer specific
82  };
83 
84 //---------------------------------------------------------
85 // Midi Controller
86 //---------------------------------------------------------
87 
88 enum {
89  CTRL_HBANK = 0x00,
90  CTRL_LBANK = 0x20,
91 
92  CTRL_HDATA = 0x06,
93  CTRL_LDATA = 0x26,
94 
95  CTRL_HNRPN = 0x63,
96  CTRL_LNRPN = 0x62,
97 
98  CTRL_HRPN = 0x65,
99  CTRL_LRPN = 0x64,
100 
102  CTRL_BREATH = 0x02,
103  CTRL_FOOT = 0x04,
105  CTRL_VOLUME = 0x07,
106  CTRL_PANPOT = 0x0a,
108  CTRL_SUSTAIN = 0x40,
115 
121 
122  CTRL_ALL_SOUNDS_OFF = 0x78, // 120
123  CTRL_RESET_ALL_CTRL = 0x79, // 121
124  CTRL_LOCAL_OFF = 0x7a, // 122
125  CTRL_ALL_NOTES_OFF = 0x7b, // 123
126 
127  // special midi events are mapped to internal
128  // controller
129  //
130  CTRL_PROGRAM = 0x81,
131  /* = 0x82,*/
132  CTRL_PRESS = 0x83,
134  };
135 
136 //---------------------------------------------------------
137 // MidiCoreEvent
138 //---------------------------------------------------------
139 
141  protected:
142  uchar _type = 0;
143  uchar _channel = 0;
144  uchar _a = 0;
145  uchar _b = 0;
146 
147  public:
149  MidiCoreEvent(uchar t, uchar c, uchar a, uchar b)
150  : _type(t), _channel(c), _a(a), _b(b) {}
151 
152  void set(uchar t, uchar c, uchar a, uchar b) {
153  _type = t;
154  _channel = c;
155  _a = a;
156  _b = b;
157  }
158 
159  uchar type() const { return _type; }
160  void setType(uchar t) { _type = t; }
161  uchar channel() const { return _channel; }
162  void setChannel(uchar c) { _channel = c; }
163 
164  int dataA() const { return _a; }
165  int pitch() const { return _a; }
166  int controller() const { return _a; }
167 
168  void setDataA(int v) { _a = v; }
169  void setPitch(int v) { _a = v; }
170  void setController(int v) { _a = v; }
171 
172  int dataB() const { return _b; }
173  int velo() const { return _b; }
174  int value() const { return _b; }
175 
176  void setDataB(int v) { _b = v; }
177  void setVelo(int v) { _b = v; }
178  void setValue(int v) { _b = v; }
179 
180  void setData(int a, int b) { _a = a; _b = b; }
181  void setData(int t, int a, int b) { _type = t; _a = a; _b = b; }
182 
183  bool isChannelEvent() const;
184  void write(XmlWriter&) const;
185  bool operator==(const MidiCoreEvent& e) const {
186  return e._type == _type && e._channel == _channel && e._a == _a && e._b == _b;
187  }
188  };
189 
190 //---------------------------------------------------------
191 // MidiEvent
192 //---------------------------------------------------------
193 
194 class MidiEvent : public MidiCoreEvent {
195 
196  protected:
197  uchar* _edata; // always zero terminated (_data[_len] == 0; )
198  int _len;
200 
201  public:
203  MidiEvent(uchar t, uchar c, uchar a, uchar b)
204  : MidiCoreEvent(t, c, a, b), _edata(0), _len(0) {}
205 
206  const uchar* edata() const { return _edata; }
207  void setEData(uchar* d) { _edata = d; }
208  int len() const { return _len; }
209  void setLen(int l) { _len = l; }
210  int metaType() const { return _metaType; }
211  void setMetaType(int v) { _metaType = v; }
212  };
213 
214 //---------------------------------------------------------
215 // PlayEvent
216 // interface to Synthesizer
217 //---------------------------------------------------------
218 
219 class PlayEvent : public MidiCoreEvent {
220 
221  protected:
222  float _tuning = .0f;
223 
224  public:
227  PlayEvent(uchar t, uchar c, uchar a, uchar b)
228  : MidiCoreEvent(t, c, a, b) {}
229  float tuning() const { return _tuning; }
230  void setTuning(float v) { _tuning = v; }
231  };
232 
233 //---------------------------------------------------------
234 // NPlayEvent
235 // used for Sequencer interface
236 //---------------------------------------------------------
237 
238 class NPlayEvent : public PlayEvent {
239  const Note* _note = 0;
240  int _origin = -1;
241  int _discard = 0;
242 
243  public:
245  NPlayEvent(uchar t, uchar c, uchar a, uchar b)
246  : PlayEvent(t, c, a, b) {}
248  NPlayEvent(BeatType beatType);
249 
250  const Note* note() const { return _note; }
251  void setNote(const Note* v) { _note = v; }
252 
253  int getOriginatingStaff() const { return _origin; }
254  void setOriginatingStaff(int i) { _origin = i; }
255  void setDiscard(int d) { _discard = d; }
256  int discard() const { return _discard; }
257  bool isMuted() const;
258  };
259 
260 //---------------------------------------------------------
261 // Event
262 //---------------------------------------------------------
263 
264 class Event : public PlayEvent {
265  int _ontime;
269  int _tpc; // tonal pitch class
270  int _voice;
271  QList<Event> _notes;
272  uchar* _edata; // always zero terminated (_data[_len] == 0; )
273  int _len;
275  const Note* _note;
276 
277  public:
278  Event();
279  Event(const Event&);
280  Event(int t);
281  ~Event();
282  bool operator==(const Event&) const;
283 
284  void write(XmlWriter&) const;
285  void dump() const;
286 
287 
288  int noquantOntime() const { return _noquantOntime; }
289  void setNoquantOntime(int v) { _noquantOntime = v; }
290  int noquantDuration() const { return _noquantDuration; }
291  void setNoquantDuration(int v) { _noquantDuration = v; }
292 
293  int ontime() const { return _ontime; }
294  void setOntime(int v) { _ontime = v; }
295 
296  int duration() const { return _duration; }
297  void setDuration(int v) { _duration = v; }
298  int voice() const { return _voice; }
299  void setVoice(int val) { _voice = val; }
300  int offtime() const { return _ontime + _duration; }
301  QList<Event>& notes() { return _notes; }
302  const uchar* edata() const { return _edata; }
303  void setEData(uchar* d) { _edata = d; }
304  int len() const { return _len; }
305  void setLen(int l) { _len = l; }
306  int metaType() const { return _metaType; }
307  void setMetaType(int v) { _metaType = v; }
308  int tpc() const { return _tpc; }
309  void setTpc(int v) { _tpc = v; }
310  const Note* note() const { return _note; }
311  void setNote(const Note* v) { _note = v; }
312  };
313 
314 //---------------------------------------------------------
315 // EventList
316 // EventMap
317 //---------------------------------------------------------
318 
319 class EventList : public QList<Event> {
320  public:
321  void insert(const Event&);
322  void insertNote(int channel, Note*);
323  };
324 
325 class EventMap : public std::multimap<int, NPlayEvent> {
326  int _highestChannel = 15;
327  public:
328  void fixupMIDI();
329  void registerChannel(int c) { if (c > _highestChannel) _highestChannel = c; }
330  };
331 
332 typedef EventList::iterator iEvent;
333 typedef EventList::const_iterator ciEvent;
334 
335 extern QString midiMetaName(int meta);
336 
337 }
338 #endif
339 
Definition: event.h:65
const uchar * edata() const
Definition: event.h:206
Definition: event.h:90
Definition: event.h:96
uchar * _edata
Definition: event.h:197
int _noquantDuration
Definition: event.h:267
int noquantDuration() const
Definition: event.h:290
Definition: event.h:140
int _ontime
Definition: event.h:265
Definition: event.h:99
void setValue(int v)
Definition: event.h:178
int _len
Definition: event.h:198
Definition: event.h:61
Definition: event.h:116
void setData(int a, int b)
Definition: event.h:180
void setNoquantOntime(int v)
Definition: event.h:289
Definition: event.h:68
Definition: event.h:107
PlayEvent(uchar t, uchar c, uchar a, uchar b)
Definition: event.h:227
void setNote(const Note *v)
Definition: event.h:311
int tpc() const
Definition: event.h:308
int metaType() const
Definition: event.h:210
Definition: event.h:59
Definition: event.h:81
uchar _b
Definition: event.h:145
void setMetaType(int v)
Definition: event.h:211
Definition: event.h:111
Definition: event.h:106
int _len
Definition: event.h:273
void setType(uchar t)
Definition: event.h:160
Definition: event.h:117
void setNote(const Note *v)
Definition: event.h:251
void setEData(uchar *d)
Definition: event.h:303
Definition: event.h:103
void setData(int t, int a, int b)
Definition: event.h:181
const uchar * edata() const
Definition: event.h:302
int _noquantOntime
Definition: event.h:266
void setChannel(uchar c)
Definition: event.h:162
Definition: event.h:101
Definition: event.h:118
Definition: event.h:75
EventList::const_iterator ciEvent
Definition: event.h:333
Definition: event.h:67
int discard() const
Definition: event.h:256
Definition: event.h:71
const Note * note() const
Definition: event.h:250
int noquantOntime() const
Definition: event.h:288
PlayEvent()
Definition: event.h:225
Definition: event.h:93
Definition: event.h:110
int getOriginatingStaff() const
Definition: event.h:253
void setDataA(int v)
Definition: event.h:168
void setOriginatingStaff(int i)
Definition: event.h:254
Definition: event.h:76
uchar _type
Definition: event.h:142
MidiCoreEvent(uchar t, uchar c, uchar a, uchar b)
Definition: event.h:149
uchar type() const
Definition: event.h:159
NPlayEvent(uchar t, uchar c, uchar a, uchar b)
Definition: event.h:245
bool operator==(const MidiCoreEvent &e) const
Definition: event.h:185
const Note * _note
Definition: event.h:275
Definition: event.h:79
Definition: event.h:130
Definition: event.h:95
int controller() const
Definition: event.h:166
void setLen(int l)
Definition: event.h:209
int dataB() const
Definition: event.h:172
void setPitch(int v)
Definition: event.h:169
MidiCoreEvent()
Definition: event.h:148
QString midiMetaName(int meta)
Definition: event.cpp:342
Definition: event.h:120
int _metaType
Definition: event.h:274
void setNoquantDuration(int v)
Definition: event.h:291
Definition: event.h:105
Definition: event.h:66
Definition: event.h:72
int voice() const
Definition: event.h:298
void setMetaType(int v)
Definition: event.h:307
Definition: event.h:319
int _voice
Definition: event.h:270
int _duration
Definition: event.h:268
uchar channel() const
Definition: event.h:161
Definition: event.h:102
Definition: event.h:119
Definition: event.h:125
int len() const
Definition: event.h:208
void setTuning(float v)
Definition: event.h:230
Definition: event.h:109
int duration() const
Definition: event.h:296
Definition: event.h:74
void setLen(int l)
Definition: event.h:305
Definition: event.h:78
Definition: event.h:122
Definition: event.h:132
Definition: aeolus.cpp:26
Definition: event.h:124
Definition: event.h:264
Definition: event.h:123
Definition: event.h:77
int velo() const
Definition: event.h:173
Definition: event.h:98
void setDiscard(int d)
Definition: event.h:255
Definition: xml.h:218
Definition: event.h:238
QList< Event > _notes
Definition: event.h:271
void setVelo(int v)
Definition: event.h:177
float tuning() const
Definition: event.h:229
void setTpc(int v)
Definition: event.h:309
Definition: xmlwriter.h:26
Definition: event.h:133
Definition: event.h:73
int len() const
Definition: event.h:304
Definition: event.h:89
BeatType
Definition: sig.h:29
Definition: event.h:104
MidiEvent(uchar t, uchar c, uchar a, uchar b)
Definition: event.h:203
int pitch() const
Definition: event.h:165
void setDuration(int v)
Definition: event.h:297
NPlayEvent(const MidiCoreEvent &e)
Definition: event.h:247
int value() const
Definition: event.h:174
Definition: event.h:113
uchar * _edata
Definition: event.h:272
void setController(int v)
Definition: event.h:170
void setVoice(int val)
Definition: event.h:299
Definition: event.h:63
void setEData(uchar *d)
Definition: event.h:207
Definition: event.h:62
int _tpc
Definition: event.h:269
Graphic representation of a note.
Definition: note.h:212
uchar _a
Definition: event.h:144
Definition: event.h:194
Definition: event.h:92
void setDataB(int v)
Definition: event.h:176
Definition: event.h:325
Definition: event.h:70
int metaType() const
Definition: event.h:306
int offtime() const
Definition: event.h:300
Definition: event.h:80
Definition: event.h:69
Definition: event.h:114
void setOntime(int v)
Definition: event.h:294
Definition: event.h:112
uchar _channel
Definition: event.h:143
Definition: event.h:108
MidiEvent()
Definition: event.h:202
int dataA() const
Definition: event.h:164
Definition: event.h:219
int ontime() const
Definition: event.h:293
NPlayEvent()
Definition: event.h:244
PlayEvent(const MidiCoreEvent &e)
Definition: event.h:226
EventList::iterator iEvent
Definition: event.h:332
int _metaType
Definition: event.h:199
Definition: event.h:64
void registerChannel(int c)
Definition: event.h:329
Definition: event.h:60
const Note * note() const
Definition: event.h:310
QList< Event > & notes()
Definition: event.h:301