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
3.9KB

  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 doc/GPL.txt file.
  16. */
  17. #include "CarlaNative.h"
  18. #include "CarlaMIDI.h"
  19. #include <stdlib.h>
  20. // -----------------------------------------------------------------------
  21. typedef struct {
  22. const PluginHostDescriptor* host;
  23. MappedValue map_midi;
  24. } MidiSplitHandle;
  25. // -----------------------------------------------------------------------
  26. static PluginHandle midiSplit_instantiate(const PluginHostDescriptor* host)
  27. {
  28. MidiSplitHandle* const handle = (MidiSplitHandle*)malloc(sizeof(MidiSplitHandle));
  29. if (handle == NULL)
  30. return NULL;
  31. handle->host = host;
  32. handle->map_midi = host->map_value(host->handle, EVENT_TYPE_MIDI);
  33. return handle;
  34. }
  35. #define handlePtr ((MidiSplitHandle*)handle)
  36. static void midiSplit_cleanup(PluginHandle handle)
  37. {
  38. free(handlePtr);
  39. }
  40. static void midiSplit_process(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const Event* events, uint32_t eventCount)
  41. {
  42. const PluginHostDescriptor* const host = handlePtr->host;
  43. const MappedValue map_midi = handlePtr->map_midi;
  44. MidiEvent tmpEvent;
  45. tmpEvent.e.type = map_midi;
  46. for (uint32_t i=0; i < eventCount; ++i)
  47. {
  48. if (events[i].type != map_midi)
  49. continue;
  50. const MidiEvent* const midiEvent = (const MidiEvent*)&events[i];
  51. const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
  52. const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);
  53. if (channel >= MAX_MIDI_CHANNELS)
  54. continue;
  55. tmpEvent.e.frame = midiEvent->e.frame;
  56. tmpEvent.port = channel;
  57. tmpEvent.data[0] = status;
  58. tmpEvent.data[1] = midiEvent->data[1];
  59. tmpEvent.data[2] = midiEvent->data[2];
  60. tmpEvent.data[3] = midiEvent->data[3];
  61. tmpEvent.size = midiEvent->size;
  62. host->write_event(host->handle, (const Event*)&tmpEvent);
  63. }
  64. return;
  65. // unused
  66. (void)inBuffer;
  67. (void)outBuffer;
  68. (void)frames;
  69. }
  70. #undef handlePtr
  71. // -----------------------------------------------------------------------
  72. static const PluginDescriptor midiSplitDesc = {
  73. .api = CARLA_NATIVE_API_VERSION,
  74. .categories = PLUGIN_CATEGORY_UTILITY ":midi",
  75. .features = "rtsafe",
  76. .supports = PLUGIN_SUPPORTS_EVERYTHING,
  77. .metadata = NULL,
  78. .audioIns = 0,
  79. .audioOuts = 0,
  80. .midiIns = 1,
  81. .midiOuts = 16,
  82. .paramIns = 0,
  83. .paramOuts = 0,
  84. .author = "falkTX",
  85. .name = "MIDI Split",
  86. .label = "midiSplit",
  87. .copyright = "GNU GPL v2+",
  88. .instantiate = midiSplit_instantiate,
  89. .cleanup = midiSplit_cleanup,
  90. .get_parameter_count = NULL,
  91. .get_parameter_info = NULL,
  92. .get_parameter_value = NULL,
  93. .get_parameter_text = NULL,
  94. .set_parameter_value = NULL,
  95. .get_midi_program_count = NULL,
  96. .get_midi_program_info = NULL,
  97. .set_midi_program = NULL,
  98. .idle = NULL,
  99. .get_state = NULL,
  100. .set_state = NULL,
  101. .activate = NULL,
  102. .deactivate = NULL,
  103. .process = midiSplit_process,
  104. .dispatcher = NULL
  105. };
  106. // -----------------------------------------------------------------------
  107. void carla_register_native_plugin_midiSplit()
  108. {
  109. carla_register_native_plugin(&midiSplitDesc);
  110. }
  111. // -----------------------------------------------------------------------