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.

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