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.

131 lines
3.4KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #include "CarlaNative.h"
  18. #include "CarlaMIDI.h"
  19. #include <stdlib.h>
  20. typedef struct _MidiSplitHandle {
  21. HostDescriptor* host;
  22. } MidiSplitHandle;
  23. static PluginHandle midiSplit_instantiate(const PluginDescriptor* _this_, HostDescriptor* host)
  24. {
  25. MidiSplitHandle* const handle = (MidiSplitHandle*)malloc(sizeof(MidiSplitHandle));
  26. if (handle)
  27. {
  28. handle->host = host;
  29. return handle;
  30. }
  31. return NULL;
  32. // unused
  33. (void)_this_;
  34. }
  35. static void midiSplit_cleanup(PluginHandle handle)
  36. {
  37. free((MidiSplitHandle*)handle);
  38. }
  39. static void midiSplit_process(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents)
  40. {
  41. HostDescriptor* const host = ((MidiSplitHandle*)handle)->host;
  42. MidiEvent tmpEvent;
  43. for (uint32_t i=0; i < midiEventCount; i++)
  44. {
  45. const MidiEvent* const midiEvent = &midiEvents[i];
  46. const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
  47. const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);
  48. if (channel >= MAX_MIDI_CHANNELS)
  49. continue;
  50. tmpEvent.port = channel;
  51. tmpEvent.time = midiEvent->time;
  52. tmpEvent.data[0] = status;
  53. tmpEvent.data[1] = midiEvent->data[1];
  54. tmpEvent.data[2] = midiEvent->data[2];
  55. host->write_midi_event(host, &tmpEvent);
  56. }
  57. return;
  58. // unused
  59. (void)inBuffer;
  60. (void)outBuffer;
  61. (void)frames;
  62. }
  63. // -----------------------------------------------------------------------
  64. static const PluginDescriptor midiSplitDesc = {
  65. .category = PLUGIN_CATEGORY_UTILITY,
  66. .hints = PLUGIN_IS_RTSAFE,
  67. .audioIns = 0,
  68. .audioOuts = 0,
  69. .midiIns = 1,
  70. .midiOuts = 16,
  71. .parameterIns = 0,
  72. .parameterOuts = 0,
  73. .name = "MIDI Split",
  74. .label = "midiSplit",
  75. .maker = "falkTX",
  76. .copyright = "GNU GPL v2+",
  77. .instantiate = midiSplit_instantiate,
  78. .cleanup = midiSplit_cleanup,
  79. .get_parameter_count = NULL,
  80. .get_parameter_info = NULL,
  81. .get_parameter_value = NULL,
  82. .get_parameter_text = NULL,
  83. .get_midi_program_count = NULL,
  84. .get_midi_program_info = NULL,
  85. .set_parameter_value = NULL,
  86. .set_midi_program = NULL,
  87. .set_custom_data = NULL,
  88. .ui_show = NULL,
  89. .ui_idle = NULL,
  90. .ui_set_parameter_value = NULL,
  91. .ui_set_midi_program = NULL,
  92. .ui_set_custom_data = NULL,
  93. .activate = NULL,
  94. .deactivate = NULL,
  95. .process = midiSplit_process
  96. };
  97. // -----------------------------------------------------------------------
  98. void carla_register_native_plugin_midiSplit()
  99. {
  100. carla_register_native_plugin(&midiSplitDesc);
  101. }
  102. // -----------------------------------------------------------------------