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.

147 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. .midiIns = 1,
  75. .midiOuts = MAX_MIDI_CHANNELS,
  76. .paramIns = 0,
  77. .paramOuts = 0,
  78. .name = "MIDI Split",
  79. .label = "midisplit",
  80. .maker = "falkTX",
  81. .copyright = "GNU GPL v2+",
  82. .instantiate = midisplit_instantiate,
  83. .cleanup = midisplit_cleanup,
  84. .get_parameter_count = NULL,
  85. .get_parameter_info = NULL,
  86. .get_parameter_value = NULL,
  87. .get_midi_program_count = NULL,
  88. .get_midi_program_info = NULL,
  89. .set_parameter_value = NULL,
  90. .set_midi_program = NULL,
  91. .set_custom_data = NULL,
  92. .ui_show = NULL,
  93. .ui_idle = NULL,
  94. .ui_set_parameter_value = NULL,
  95. .ui_set_midi_program = NULL,
  96. .ui_set_custom_data = NULL,
  97. .activate = NULL,
  98. .deactivate = NULL,
  99. .process = midisplit_process,
  100. .get_state = NULL,
  101. .set_state = NULL,
  102. .dispatcher = NULL,
  103. .render_inline_display = NULL
  104. };
  105. // -----------------------------------------------------------------------
  106. void carla_register_native_plugin_midisplit(void);
  107. void carla_register_native_plugin_midisplit(void)
  108. {
  109. carla_register_native_plugin(&midisplitDesc);
  110. }
  111. // -----------------------------------------------------------------------