3 * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaEngine.hpp"
19 #include "CarlaMIDI.h"
20 #include "CarlaUtils.hpp"
22 CARLA_BACKEND_USE_NAMESPACE
24 void testControlEventDump()
32 e
.type
= kEngineControlEventTypeNull
;
33 e
.dumpToMidiData(0, size
, data
);
36 // test regular param event (half value)
37 e
.type
= kEngineControlEventTypeParameter
;
38 e
.param
= MIDI_CONTROL_MODULATION_WHEEL
;
40 e
.dumpToMidiData(0, size
, data
);
42 assert(data
[0] == MIDI_STATUS_CONTROL_CHANGE
);
43 assert(data
[1] == MIDI_CONTROL_MODULATION_WHEEL
);
44 assert(data
[2] == (MAX_MIDI_VALUE
-1)/2);
46 // test regular param event (out of bounds positive)
48 e
.dumpToMidiData(0, size
, data
);
49 assert(data
[2] == MAX_MIDI_VALUE
-1);
51 // test regular param event (out of bounds negative)
53 e
.dumpToMidiData(0, size
, data
);
56 // test bad param as bank select
57 e
.param
= MIDI_CONTROL_BANK_SELECT
;
59 e
.dumpToMidiData(0, size
, data
);
61 assert(data
[1] == MIDI_CONTROL_BANK_SELECT
);
62 assert(data
[2] == 100);
64 // test bad param as bank select (out of bounds index positive)
66 e
.dumpToMidiData(0, size
, data
);
67 assert(data
[2] == MAX_MIDI_VALUE
-1);
69 // test bad param as bank select (out of bounds index negative)
71 e
.dumpToMidiData(0, size
, data
);
74 // test bad param (out of bounds index)
76 e
.dumpToMidiData(0, size
, data
);
79 // test regular midi-bank event
80 e
.type
= kEngineControlEventTypeMidiBank
;
82 e
.dumpToMidiData(0, size
, data
);
84 assert(data
[0] == MIDI_STATUS_CONTROL_CHANGE
);
85 assert(data
[1] == MIDI_CONTROL_BANK_SELECT
);
86 assert(data
[2] == 11);
88 // test bad midi-bank event (out of bounds)
90 e
.dumpToMidiData(0, size
, data
);
91 assert(data
[2] == MAX_MIDI_VALUE
-1);
93 // test bad midi-bank event (out of bounds #2)
95 e
.dumpToMidiData(0, size
, data
);
96 assert(data
[2] == MAX_MIDI_VALUE
-1);
98 // test regular midi-program event
99 e
.type
= kEngineControlEventTypeMidiProgram
;
101 e
.dumpToMidiData(0, size
, data
);
103 assert(data
[0] == MIDI_STATUS_PROGRAM_CHANGE
);
104 assert(data
[1] == 15);
106 // test bad midi-program event (out of bounds)
108 e
.dumpToMidiData(0, size
, data
);
109 assert(data
[1] == MAX_MIDI_VALUE
-1);
111 // test regular all-sound-off event
112 e
.type
= kEngineControlEventTypeAllSoundOff
;
113 e
.dumpToMidiData(0, size
, data
);
115 assert(data
[0] == MIDI_STATUS_CONTROL_CHANGE
);
116 assert(data
[1] == MIDI_CONTROL_ALL_SOUND_OFF
);
118 // test regular all-notes-off event
119 e
.type
= kEngineControlEventTypeAllNotesOff
;
120 e
.dumpToMidiData(0, size
, data
);
122 assert(data
[0] == MIDI_STATUS_CONTROL_CHANGE
);
123 assert(data
[1] == MIDI_CONTROL_ALL_NOTES_OFF
);
126 e
.dumpToMidiData(0, size
, data
);
127 assert(MIDI_GET_CHANNEL_FROM_DATA(data
) == 0);
128 e
.dumpToMidiData(1, size
, data
);
129 assert(MIDI_GET_CHANNEL_FROM_DATA(data
) == 1);
130 e
.dumpToMidiData(15, size
, data
);
131 assert(MIDI_GET_CHANNEL_FROM_DATA(data
) == 15);
132 e
.dumpToMidiData(16, size
, data
);
133 assert(MIDI_GET_CHANNEL_FROM_DATA(data
) == 0);
134 e
.dumpToMidiData(17, size
, data
);
135 assert(MIDI_GET_CHANNEL_FROM_DATA(data
) == 1);
136 e
.dumpToMidiData(31, size
, data
);
137 assert(MIDI_GET_CHANNEL_FROM_DATA(data
) == 15);
140 void testEventMidiFill()
145 //EngineControlEvent c;
150 e
.fillFromMidiData(0, data
);
151 assert(e
.type
== kEngineEventTypeNull
);
152 assert(e
.channel
== 0);
153 e
.fillFromMidiData(50, nullptr);
154 assert(e
.type
== kEngineEventTypeNull
);
155 assert(e
.channel
== 0);
157 // test bad midi event
162 e
.fillFromMidiData(size
, data
);
163 assert(e
.type
== kEngineEventTypeNull
);
164 assert(e
.channel
== 0);
166 // test simple midi event
168 data
[0] = 0x82; // MIDI_STATUS_NOTE_OFF + 2
171 e
.fillFromMidiData(size
, data
);
172 assert(e
.type
== kEngineEventTypeMidi
);
173 assert(e
.channel
== 2);
174 assert(e
.midi
.size
== size
);
175 assert(e
.midi
.dataExt
== nullptr);
176 assert(e
.midi
.data
[0] == 0x80); // without channel bit
177 assert(e
.midi
.data
[1] == data
[1]);
178 assert(e
.midi
.data
[2] == data
[2]);
180 // test sysex midi event
193 e
.fillFromMidiData(size
, data
);
194 assert(e
.type
== kEngineEventTypeMidi
);
195 assert(e
.channel
== 0);
196 assert(e
.midi
.size
== size
);
197 assert(e
.midi
.dataExt
== data
);
198 assert(e
.midi
.data
[0] == 0);
199 assert(e
.midi
.data
[1] == 0);
200 assert(e
.midi
.data
[2] == 0);
201 assert(e
.midi
.data
[3] == 0);
203 // test all-sound-off event
205 data
[0] = 0xB5; // MIDI_STATUS_CONTROL_CHANGE + 5
206 data
[1] = MIDI_CONTROL_ALL_SOUND_OFF
;
207 e
.fillFromMidiData(size
, data
);
208 assert(e
.type
== kEngineEventTypeControl
);
209 assert(e
.channel
== 5);
210 assert(e
.ctrl
.type
== kEngineControlEventTypeAllSoundOff
);
211 assert(e
.ctrl
.param
== 0);
212 assert(e
.ctrl
.value
== 0.0f
);
214 // test all-notes-off event
216 data
[0] = 0xBF; // MIDI_STATUS_CONTROL_CHANGE + 15
217 data
[1] = MIDI_CONTROL_ALL_NOTES_OFF
;
218 e
.fillFromMidiData(size
, data
);
219 assert(e
.type
== kEngineEventTypeControl
);
220 assert(e
.channel
== 15);
221 assert(e
.ctrl
.type
== kEngineControlEventTypeAllNotesOff
);
222 assert(e
.ctrl
.param
== 0);
223 assert(e
.ctrl
.value
== 0.0f
);
225 // test midi-bank event
227 data
[0] = 0xB1; // MIDI_STATUS_CONTROL_CHANGE + 1
228 data
[1] = MIDI_CONTROL_BANK_SELECT
;
230 e
.fillFromMidiData(size
, data
);
231 assert(e
.type
== kEngineEventTypeControl
);
232 assert(e
.channel
== 1);
233 assert(e
.ctrl
.type
== kEngineControlEventTypeMidiBank
);
234 assert(e
.ctrl
.param
== 123);
235 assert(e
.ctrl
.value
== 0.0f
);
237 // test midi-program event
239 data
[0] = MIDI_STATUS_PROGRAM_CHANGE
;
241 e
.fillFromMidiData(size
, data
);
242 assert(e
.type
== kEngineEventTypeControl
);
243 assert(e
.channel
== 0);
244 assert(e
.ctrl
.type
== kEngineControlEventTypeMidiProgram
);
245 assert(e
.ctrl
.param
== 77);
246 assert(e
.ctrl
.value
== 0.0f
);
251 testControlEventDump();