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.

midi-split.c 3.6KB

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