Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
7.4KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  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.
  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. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaEngine.hpp"
  18. #include "CarlaMIDI.h"
  19. #include "CarlaUtils.hpp"
  20. CARLA_BACKEND_USE_NAMESPACE
  21. void testControlEventDump()
  22. {
  23. uint8_t size;
  24. uint8_t data[3];
  25. EngineControlEvent e;
  26. // test null event
  27. e.type = kEngineControlEventTypeNull;
  28. e.dumpToMidiData(0, size, data);
  29. assert(size == 0);
  30. // test regular param event (half value)
  31. e.type = kEngineControlEventTypeParameter;
  32. e.param = MIDI_CONTROL_MODULATION_WHEEL;
  33. e.value = 0.5f;
  34. e.dumpToMidiData(0, size, data);
  35. assert(size == 3);
  36. assert(data[0] == MIDI_STATUS_CONTROL_CHANGE);
  37. assert(data[1] == MIDI_CONTROL_MODULATION_WHEEL);
  38. assert(data[2] == (MAX_MIDI_VALUE-1)/2);
  39. // test regular param event (out of bounds positive)
  40. e.value = 9.0f;
  41. e.dumpToMidiData(0, size, data);
  42. assert(data[2] == MAX_MIDI_VALUE-1);
  43. // test regular param event (out of bounds negative)
  44. e.value = -11.0f;
  45. e.dumpToMidiData(0, size, data);
  46. assert(data[2] == 0);
  47. // test bad param as bank select
  48. e.param = MIDI_CONTROL_BANK_SELECT;
  49. e.value = 100;
  50. e.dumpToMidiData(0, size, data);
  51. assert(size == 3);
  52. assert(data[1] == MIDI_CONTROL_BANK_SELECT);
  53. assert(data[2] == 100);
  54. // test bad param as bank select (out of bounds index positive)
  55. e.value = 9999;
  56. e.dumpToMidiData(0, size, data);
  57. assert(data[2] == MAX_MIDI_VALUE-1);
  58. // test bad param as bank select (out of bounds index negative)
  59. e.value = -9999;
  60. e.dumpToMidiData(0, size, data);
  61. assert(data[2] == 0);
  62. // test bad param (out of bounds index)
  63. e.param = 999;
  64. e.dumpToMidiData(0, size, data);
  65. assert(size == 0);
  66. // test regular midi-bank event
  67. e.type = kEngineControlEventTypeMidiBank;
  68. e.param = 11;
  69. e.dumpToMidiData(0, size, data);
  70. assert(size == 3);
  71. assert(data[0] == MIDI_STATUS_CONTROL_CHANGE);
  72. assert(data[1] == MIDI_CONTROL_BANK_SELECT);
  73. assert(data[2] == 11);
  74. // test bad midi-bank event (out of bounds)
  75. e.param = 300;
  76. e.dumpToMidiData(0, size, data);
  77. assert(data[2] == MAX_MIDI_VALUE-1);
  78. // test bad midi-bank event (out of bounds #2)
  79. e.param = 32867;
  80. e.dumpToMidiData(0, size, data);
  81. assert(data[2] == MAX_MIDI_VALUE-1);
  82. // test regular midi-program event
  83. e.type = kEngineControlEventTypeMidiProgram;
  84. e.param = 15;
  85. e.dumpToMidiData(0, size, data);
  86. assert(size == 2);
  87. assert(data[0] == MIDI_STATUS_PROGRAM_CHANGE);
  88. assert(data[1] == 15);
  89. // test bad midi-program event (out of bounds)
  90. e.param = 299;
  91. e.dumpToMidiData(0, size, data);
  92. assert(data[1] == MAX_MIDI_VALUE-1);
  93. // test regular all-sound-off event
  94. e.type = kEngineControlEventTypeAllSoundOff;
  95. e.dumpToMidiData(0, size, data);
  96. assert(size == 2);
  97. assert(data[0] == MIDI_STATUS_CONTROL_CHANGE);
  98. assert(data[1] == MIDI_CONTROL_ALL_SOUND_OFF);
  99. // test regular all-notes-off event
  100. e.type = kEngineControlEventTypeAllNotesOff;
  101. e.dumpToMidiData(0, size, data);
  102. assert(size == 2);
  103. assert(data[0] == MIDI_STATUS_CONTROL_CHANGE);
  104. assert(data[1] == MIDI_CONTROL_ALL_NOTES_OFF);
  105. // test channel bit
  106. e.dumpToMidiData(0, size, data);
  107. assert(MIDI_GET_CHANNEL_FROM_DATA(data) == 0);
  108. e.dumpToMidiData(1, size, data);
  109. assert(MIDI_GET_CHANNEL_FROM_DATA(data) == 1);
  110. e.dumpToMidiData(15, size, data);
  111. assert(MIDI_GET_CHANNEL_FROM_DATA(data) == 15);
  112. e.dumpToMidiData(16, size, data);
  113. assert(MIDI_GET_CHANNEL_FROM_DATA(data) == 0);
  114. e.dumpToMidiData(17, size, data);
  115. assert(MIDI_GET_CHANNEL_FROM_DATA(data) == 1);
  116. e.dumpToMidiData(31, size, data);
  117. assert(MIDI_GET_CHANNEL_FROM_DATA(data) == 15);
  118. }
  119. void testEventMidiFill()
  120. {
  121. uint8_t size;
  122. uint8_t data[25];
  123. //EngineControlEvent c;
  124. EngineEvent e;
  125. e.time = 0;
  126. // test safety first
  127. e.fillFromMidiData(0, data);
  128. assert(e.type == kEngineEventTypeNull);
  129. assert(e.channel == 0);
  130. e.fillFromMidiData(50, nullptr);
  131. assert(e.type == kEngineEventTypeNull);
  132. assert(e.channel == 0);
  133. // test bad midi event
  134. size = 3;
  135. data[0] = 0x45;
  136. data[1] = 100;
  137. data[2] = 100;
  138. e.fillFromMidiData(size, data);
  139. assert(e.type == kEngineEventTypeNull);
  140. assert(e.channel == 0);
  141. // test simple midi event
  142. size = 3;
  143. data[0] = 0x82; // MIDI_STATUS_NOTE_OFF + 2
  144. data[1] = 127;
  145. data[2] = 127;
  146. e.fillFromMidiData(size, data);
  147. assert(e.type == kEngineEventTypeMidi);
  148. assert(e.channel == 2);
  149. assert(e.midi.size == size);
  150. assert(e.midi.dataExt == nullptr);
  151. assert(e.midi.data[0] == 0x80); // without channel bit
  152. assert(e.midi.data[1] == data[1]);
  153. assert(e.midi.data[2] == data[2]);
  154. // test sysex midi event
  155. size = 11;
  156. data[ 0] = 0xF0;
  157. data[ 1] = 0x41;
  158. data[ 2] = 0x10;
  159. data[ 3] = 0x42;
  160. data[ 4] = 0x12;
  161. data[ 5] = 0x40;
  162. data[ 6] = 0x00;
  163. data[ 7] = 0x7F;
  164. data[ 8] = 0x00;
  165. data[ 9] = 0x41;
  166. data[10] = 0xF7;
  167. e.fillFromMidiData(size, data);
  168. assert(e.type == kEngineEventTypeMidi);
  169. assert(e.channel == 0);
  170. assert(e.midi.size == size);
  171. assert(e.midi.dataExt == data);
  172. assert(e.midi.data[0] == 0);
  173. assert(e.midi.data[1] == 0);
  174. assert(e.midi.data[2] == 0);
  175. assert(e.midi.data[3] == 0);
  176. // test all-sound-off event
  177. size = 2;
  178. data[0] = 0xB5; // MIDI_STATUS_CONTROL_CHANGE + 5
  179. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  180. e.fillFromMidiData(size, data);
  181. assert(e.type == kEngineEventTypeControl);
  182. assert(e.channel == 5);
  183. assert(e.ctrl.type == kEngineControlEventTypeAllSoundOff);
  184. assert(e.ctrl.param == 0);
  185. assert(e.ctrl.value == 0.0f);
  186. // test all-notes-off event
  187. size = 2;
  188. data[0] = 0xBF; // MIDI_STATUS_CONTROL_CHANGE + 15
  189. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  190. e.fillFromMidiData(size, data);
  191. assert(e.type == kEngineEventTypeControl);
  192. assert(e.channel == 15);
  193. assert(e.ctrl.type == kEngineControlEventTypeAllNotesOff);
  194. assert(e.ctrl.param == 0);
  195. assert(e.ctrl.value == 0.0f);
  196. // test midi-bank event
  197. size = 3;
  198. data[0] = 0xB1; // MIDI_STATUS_CONTROL_CHANGE + 1
  199. data[1] = MIDI_CONTROL_BANK_SELECT;
  200. data[2] = 123;
  201. e.fillFromMidiData(size, data);
  202. assert(e.type == kEngineEventTypeControl);
  203. assert(e.channel == 1);
  204. assert(e.ctrl.type == kEngineControlEventTypeMidiBank);
  205. assert(e.ctrl.param == 123);
  206. assert(e.ctrl.value == 0.0f);
  207. // test midi-program event
  208. size = 2;
  209. data[0] = MIDI_STATUS_PROGRAM_CHANGE;
  210. data[1] = 77;
  211. e.fillFromMidiData(size, data);
  212. assert(e.type == kEngineEventTypeControl);
  213. assert(e.channel == 0);
  214. assert(e.ctrl.type == kEngineControlEventTypeMidiProgram);
  215. assert(e.ctrl.param == 77);
  216. assert(e.ctrl.value == 0.0f);
  217. }
  218. int main()
  219. {
  220. testControlEventDump();
  221. testEventMidiFill();
  222. return 0;
  223. }