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.

144 lines
3.9KB

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