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

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