-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathevents.cpp
265 lines (229 loc) · 6.03 KB
/
events.cpp
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
Drumstick MIDI File Player Multiplatform Program
Copyright (C) 2006-2024, Pedro Lopez-Cabanillas <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QString>
#include <QByteArray>
#include <drumstick/rtmidioutput.h>
#include "events.h"
using namespace drumstick::rt;
/**
* Default constructor.
*/
MIDIEvent::MIDIEvent() : QEvent(MIDIEventType),
m_delta(0), m_tick(0), m_tag(0), m_status(0)
{ }
/**
* Sets the event to be scheduled in delta musical time (ticks) units.
* @param delta The delta time in ticks.
*/
void MIDIEvent::setDelta(const long delta)
{
m_delta = delta;
}
/**
* Sets the event to be scheduled in musical time (ticks) units.
* @param tick The time in ticks.
*/
void MIDIEvent::setTick(const long tick)
{
m_tick = tick;
}
/**
* Sets the event's tag. This attribute is any arbitrary integer number.
* @param aTag A tag number.
*/
void MIDIEvent::setTag(const int aTag)
{
m_tag = aTag;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param key MIDI note.
* @param vel Note velocity.
*/
NoteOnEvent::NoteOnEvent(int ch, int key, int vel) : KeyEvent(ch, key, vel)
{
m_status = MIDI_STATUS_NOTEON;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param key MIDI note.
* @param vel Note velocity.
*/
NoteOffEvent::NoteOffEvent(int ch, int key, int vel) : KeyEvent(ch, key, vel)
{
m_status = MIDI_STATUS_NOTEOFF;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param key MIDI note.
* @param vel Note velocity.
*/
KeyPressEvent::KeyPressEvent(int ch, int key, int vel) : KeyEvent(ch, key, vel)
{
m_status = MIDI_STATUS_KEYPRESURE;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param cc MIDI Controller number.
* @param val Controller value.
*/
ControllerEvent::ControllerEvent(int ch, int cc, int val) : ChannelEvent(ch),
m_param(cc), m_value(val)
{
m_status = MIDI_STATUS_CONTROLCHANGE;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param val MIDI Program number.
*/
ProgramChangeEvent::ProgramChangeEvent(int ch, int val) : ChannelEvent(ch),
m_program(val)
{
m_status = MIDI_STATUS_PROGRAMCHANGE;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param val Pitch Bend value. Zero centered from -8192 to 8191.
*/
PitchBendEvent::PitchBendEvent(int ch, int val) : ChannelEvent(ch),
m_value(val)
{
m_status = MIDI_STATUS_PITCHBEND;
}
/**
* Constructor using proper attribute values.
* @param ch MIDI Channel.
* @param val Aftertouch value.
*/
ChanPressEvent::ChanPressEvent(int ch, int val) : ChannelEvent(ch),
m_value(val)
{
m_status = MIDI_STATUS_CHANNELPRESSURE;
}
/**
* Default constructor.
*/
VariableEvent::VariableEvent() : MIDIEvent()
{
m_data.clear();
}
/**
* Constructor from an arbitrary data array.
* @param data A data byte array.
*/
VariableEvent::VariableEvent(const QByteArray& data): MIDIEvent()
{
m_data = data;
}
/**
* Constructor from a data pointer.
* @param datalen Length of the data.
* @param dataptr Pointer the data.
*/
VariableEvent::VariableEvent(const unsigned int datalen, char* dataptr)
: MIDIEvent()
{
m_data = QByteArray(dataptr, datalen);
}
/**
* Default constructor.
*/
SysExEvent::SysExEvent()
: VariableEvent()
{
m_status = MIDI_STATUS_SYSEX;
}
/**
* Constructor from a data array.
* @param data A data byte array.
*/
SysExEvent::SysExEvent(const QByteArray& data)
: VariableEvent(data)
{
m_status = MIDI_STATUS_SYSEX;
}
/**
* Constructor taking a data pointer and length
* @param datalen Data length
* @param dataptr Data pointer
*/
SysExEvent::SysExEvent(const unsigned int datalen, char* dataptr)
: VariableEvent( datalen, dataptr )
{
m_status = MIDI_STATUS_SYSEX;
}
SystemEvent::SystemEvent(const int message)
: MIDIEvent()
{
m_status = message;
}
/**
* Default constructor
*/
TextEvent::TextEvent()
: VariableEvent(), m_textType(1)
{ }
/**
* Constructor from a given string
* @param text The event's text
* @param textType The SMF text type
*/
TextEvent::TextEvent(const QByteArray &text, const int textType)
: VariableEvent(text), m_textType(textType)
{ }
/**
* Constructor from a data pointer and length
* @param datalen Data length
* @param dataptr Data pointer
*/
TextEvent::TextEvent(const unsigned int datalen, char* dataptr)
: VariableEvent(datalen, dataptr), m_textType(1)
{ }
/**
* Gets the event's SMF text type.
* @return The SMF text type.
*/
int TextEvent::textType() const
{
return m_textType;
}
TempoEvent::TempoEvent() : MIDIEvent(), m_tempo(0)
{ }
TempoEvent::TempoEvent(const qreal tempo): MIDIEvent(), m_tempo(tempo)
{ }
TimeSignatureEvent::TimeSignatureEvent()
: MIDIEvent(), m_numerator(0), m_denominator(0)
{ }
TimeSignatureEvent::TimeSignatureEvent(const int numerator, const int denominator)
: MIDIEvent(), m_numerator(numerator), m_denominator(denominator)
{ }
KeySignatureEvent::KeySignatureEvent()
: MIDIEvent(), m_alterations(0), m_minorMode(false)
{ }
KeySignatureEvent::KeySignatureEvent(const int alterations, const bool minorMode)
: MIDIEvent(), m_alterations(alterations), m_minorMode(minorMode)
{ }
BeatEvent::BeatEvent()
: MIDIEvent(), m_bar(0), m_beat(0), m_max(0)
{ }
BeatEvent::BeatEvent(const int bar, const int beat, const int max)
: MIDIEvent(), m_bar(bar), m_beat(beat), m_max(max)
{ }