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.

149 lines
4.0KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2019 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 NativeHostDescriptor* host;
  23. } MidiSplitHandle;
  24. // -----------------------------------------------------------------------
  25. static NativePluginHandle midisplit_instantiate(const NativeHostDescriptor* host)
  26. {
  27. MidiSplitHandle* const handle = (MidiSplitHandle*)malloc(sizeof(MidiSplitHandle));
  28. if (handle == NULL)
  29. return NULL;
  30. handle->host = host;
  31. return handle;
  32. }
  33. #define handlePtr ((MidiSplitHandle*)handle)
  34. static void midisplit_cleanup(NativePluginHandle handle)
  35. {
  36. free(handlePtr);
  37. }
  38. static void midisplit_process(NativePluginHandle handle,
  39. const float** inBuffer, float** outBuffer, uint32_t frames,
  40. const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
  41. {
  42. const NativeHostDescriptor* const host = handlePtr->host;
  43. NativeMidiEvent tmpEvent;
  44. for (uint32_t i=0; i < midiEventCount; ++i)
  45. {
  46. const NativeMidiEvent* const midiEvent = &midiEvents[i];
  47. const uint8_t status = (uint8_t)MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
  48. const uint8_t channel = (uint8_t)MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);
  49. if (channel >= MAX_MIDI_CHANNELS)
  50. continue;
  51. tmpEvent.port = channel;
  52. tmpEvent.time = midiEvent->time;
  53. tmpEvent.data[0] = status;
  54. tmpEvent.data[1] = midiEvent->data[1];
  55. tmpEvent.data[2] = midiEvent->data[2];
  56. tmpEvent.data[3] = midiEvent->data[3];
  57. tmpEvent.size = midiEvent->size;
  58. host->write_midi_event(host->handle, &tmpEvent);
  59. }
  60. return;
  61. // unused
  62. (void)inBuffer;
  63. (void)outBuffer;
  64. (void)frames;
  65. }
  66. #undef handlePtr
  67. // -----------------------------------------------------------------------
  68. static const NativePluginDescriptor midisplitDesc = {
  69. .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
  70. .hints = NATIVE_PLUGIN_IS_RTSAFE,
  71. .supports = NATIVE_PLUGIN_SUPPORTS_EVERYTHING,
  72. .audioIns = 0,
  73. .audioOuts = 0,
  74. .cvIns = 0,
  75. .cvOuts = 0,
  76. .midiIns = 1,
  77. .midiOuts = MAX_MIDI_CHANNELS,
  78. .paramIns = 0,
  79. .paramOuts = 0,
  80. .name = "MIDI Split",
  81. .label = "midisplit",
  82. .maker = "falkTX",
  83. .copyright = "GNU GPL v2+",
  84. .instantiate = midisplit_instantiate,
  85. .cleanup = midisplit_cleanup,
  86. .get_parameter_count = NULL,
  87. .get_parameter_info = NULL,
  88. .get_parameter_value = NULL,
  89. .get_midi_program_count = NULL,
  90. .get_midi_program_info = NULL,
  91. .set_parameter_value = NULL,
  92. .set_midi_program = NULL,
  93. .set_custom_data = NULL,
  94. .ui_show = NULL,
  95. .ui_idle = NULL,
  96. .ui_set_parameter_value = NULL,
  97. .ui_set_midi_program = NULL,
  98. .ui_set_custom_data = NULL,
  99. .activate = NULL,
  100. .deactivate = NULL,
  101. .process = midisplit_process,
  102. .get_state = NULL,
  103. .set_state = NULL,
  104. .dispatcher = NULL,
  105. .render_inline_display = NULL
  106. };
  107. // -----------------------------------------------------------------------
  108. void carla_register_native_plugin_midisplit(void);
  109. void carla_register_native_plugin_midisplit(void)
  110. {
  111. carla_register_native_plugin(&midisplitDesc);
  112. }
  113. // -----------------------------------------------------------------------