Collection of tools useful for audio production
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.

207 lines
4.7KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_nativemm.h"
  18. #include <cstring>
  19. class MidiSplitPlugin : public PluginDescriptorClass
  20. {
  21. public:
  22. MidiSplitPlugin(const PluginDescriptorClass* master)
  23. : PluginDescriptorClass(master)
  24. {
  25. if (! master)
  26. return;
  27. }
  28. ~MidiSplitPlugin()
  29. {
  30. }
  31. // -------------------------------------------------------------------
  32. protected:
  33. PluginDescriptorClass* createMe()
  34. {
  35. return new MidiSplitPlugin(this);
  36. }
  37. void deleteMe()
  38. {
  39. delete this;
  40. }
  41. // -------------------------------------------------------------------
  42. PluginCategory getCategory()
  43. {
  44. return PLUGIN_CATEGORY_UTILITY;
  45. }
  46. uint32_t getHints()
  47. {
  48. return 0;
  49. }
  50. const char* getName()
  51. {
  52. return "MIDI Split";
  53. }
  54. const char* getLabel()
  55. {
  56. return "midiSplit";
  57. }
  58. const char* getMaker()
  59. {
  60. return "falkTX";
  61. }
  62. const char* getCopyright()
  63. {
  64. return "GNU GPL v2+";
  65. }
  66. // -------------------------------------------------------------------
  67. uint32_t getPortCount()
  68. {
  69. return PORT_MAX;
  70. }
  71. PortType getPortType(uint32_t)
  72. {
  73. return PORT_TYPE_MIDI;
  74. }
  75. uint32_t getPortHints(uint32_t index)
  76. {
  77. return (index == 0) ? 0 : PORT_HINT_IS_OUTPUT;
  78. }
  79. const char* getPortName(const uint32_t index)
  80. {
  81. switch (index)
  82. {
  83. case PORT_INPUT:
  84. return "input";
  85. case PORT_OUTPUT_1:
  86. return "output-01";
  87. case PORT_OUTPUT_2:
  88. return "output-02";
  89. case PORT_OUTPUT_3:
  90. return "output-03";
  91. case PORT_OUTPUT_4:
  92. return "output-04";
  93. case PORT_OUTPUT_5:
  94. return "output-05";
  95. case PORT_OUTPUT_6:
  96. return "output-06";
  97. case PORT_OUTPUT_7:
  98. return "output-07";
  99. case PORT_OUTPUT_8:
  100. return "output-08";
  101. case PORT_OUTPUT_9:
  102. return "output-09";
  103. case PORT_OUTPUT_10:
  104. return "output-10";
  105. case PORT_OUTPUT_11:
  106. return "output-11";
  107. case PORT_OUTPUT_12:
  108. return "output-12";
  109. case PORT_OUTPUT_13:
  110. return "output-13";
  111. case PORT_OUTPUT_14:
  112. return "output-14";
  113. case PORT_OUTPUT_15:
  114. return "output-15";
  115. case PORT_OUTPUT_16:
  116. return "output-16";
  117. default:
  118. return "";
  119. }
  120. }
  121. // -------------------------------------------------------------------
  122. void activate()
  123. {
  124. memset(events, 0, sizeof(MidiEvent) * MAX_MIDI_EVENTS);
  125. }
  126. // -------------------------------------------------------------------
  127. void process(float**, float**, uint32_t, uint32_t midiEventCount, MidiEvent* midiEvents)
  128. {
  129. MidiEvent midiEvent;
  130. for (uint32_t i=0; i < midiEventCount; i++)
  131. {
  132. memcpy(&midiEvent, &midiEvents[i], sizeof(MidiEvent));
  133. uint8_t status = midiEvent.data[0];
  134. uint8_t channel = status & 0x0F;
  135. CARLA_ASSERT(channel < 16);
  136. if (channel >= 16)
  137. continue;
  138. status -= channel;
  139. midiEvent.portOffset = channel;
  140. midiEvent.data[0] = status;
  141. writeMidiEvent(&midiEvent);
  142. }
  143. }
  144. // -------------------------------------------------------------------
  145. private:
  146. enum Ports {
  147. PORT_INPUT = 0,
  148. PORT_OUTPUT_1,
  149. PORT_OUTPUT_2,
  150. PORT_OUTPUT_3,
  151. PORT_OUTPUT_4,
  152. PORT_OUTPUT_5,
  153. PORT_OUTPUT_6,
  154. PORT_OUTPUT_7,
  155. PORT_OUTPUT_8,
  156. PORT_OUTPUT_9,
  157. PORT_OUTPUT_10,
  158. PORT_OUTPUT_11,
  159. PORT_OUTPUT_12,
  160. PORT_OUTPUT_13,
  161. PORT_OUTPUT_14,
  162. PORT_OUTPUT_15,
  163. PORT_OUTPUT_16,
  164. PORT_MAX
  165. };
  166. static const unsigned short MAX_MIDI_EVENTS = 512;
  167. MidiEvent events[MAX_MIDI_EVENTS];
  168. };
  169. static MidiSplitPlugin midiSplitPlugin(nullptr);
  170. CARLA_REGISTER_NATIVE_PLUGIN_MM(midiSplit, midiSplitPlugin)