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.

145 lines
4.3KB

  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. int main()
  120. {
  121. testControlEventDump();
  122. return 0;
  123. }