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.

154 lines
4.1KB

  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. #include <stdio.h>
  21. // -----------------------------------------------------------------------
  22. typedef struct {
  23. const NativeHostDescriptor* host;
  24. } MidiSplitHandle;
  25. // -----------------------------------------------------------------------
  26. static NativePluginHandle midijoin_instantiate(const NativeHostDescriptor* host)
  27. {
  28. MidiSplitHandle* const handle = (MidiSplitHandle*)malloc(sizeof(MidiSplitHandle));
  29. if (handle == NULL)
  30. return NULL;
  31. handle->host = host;
  32. return handle;
  33. }
  34. #define handlePtr ((MidiSplitHandle*)handle)
  35. static void midijoin_cleanup(NativePluginHandle handle)
  36. {
  37. free(handlePtr);
  38. }
  39. static void midijoin_process(NativePluginHandle handle,
  40. const 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. if (midiEvent->port >= MAX_MIDI_CHANNELS)
  49. {
  50. printf("Assertion error: midiEvent->port:%u >= MAX_MIDI_CHANNELS\n", midiEvent->port);
  51. continue;
  52. }
  53. const uint8_t statusByte = midiEvent->data[0];
  54. if (MIDI_IS_CHANNEL_MESSAGE(statusByte))
  55. tmpEvent.data[0] = (uint8_t)((statusByte & MIDI_STATUS_BIT) | (midiEvent->port & MIDI_CHANNEL_BIT));
  56. else
  57. tmpEvent.data[0] = statusByte;
  58. tmpEvent.port = 0;
  59. tmpEvent.time = midiEvent->time;
  60. tmpEvent.data[1] = midiEvent->data[1];
  61. tmpEvent.data[2] = midiEvent->data[2];
  62. tmpEvent.data[3] = midiEvent->data[3];
  63. tmpEvent.size = midiEvent->size;
  64. host->write_midi_event(host->handle, &tmpEvent);
  65. }
  66. return;
  67. // unused
  68. (void)inBuffer;
  69. (void)outBuffer;
  70. (void)frames;
  71. }
  72. #undef handlePtr
  73. // -----------------------------------------------------------------------
  74. static const NativePluginDescriptor midijoinDesc = {
  75. .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
  76. .hints = NATIVE_PLUGIN_IS_RTSAFE,
  77. .supports = NATIVE_PLUGIN_SUPPORTS_EVERYTHING,
  78. .audioIns = 0,
  79. .audioOuts = 0,
  80. .midiIns = MAX_MIDI_CHANNELS,
  81. .midiOuts = 1,
  82. .paramIns = 0,
  83. .paramOuts = 0,
  84. .name = "MIDI Join",
  85. .label = "midijoin",
  86. .maker = "falkTX",
  87. .copyright = "GNU GPL v2+",
  88. .instantiate = midijoin_instantiate,
  89. .cleanup = midijoin_cleanup,
  90. .get_parameter_count = NULL,
  91. .get_parameter_info = NULL,
  92. .get_parameter_value = NULL,
  93. .get_midi_program_count = NULL,
  94. .get_midi_program_info = NULL,
  95. .set_parameter_value = NULL,
  96. .set_midi_program = NULL,
  97. .set_custom_data = NULL,
  98. .ui_show = NULL,
  99. .ui_idle = NULL,
  100. .ui_set_parameter_value = NULL,
  101. .ui_set_midi_program = NULL,
  102. .ui_set_custom_data = NULL,
  103. .activate = NULL,
  104. .deactivate = NULL,
  105. .process = midijoin_process,
  106. .get_state = NULL,
  107. .set_state = NULL,
  108. .dispatcher = NULL,
  109. .render_inline_display = NULL
  110. };
  111. // -----------------------------------------------------------------------
  112. void carla_register_native_plugin_midijoin(void);
  113. void carla_register_native_plugin_midijoin(void)
  114. {
  115. carla_register_native_plugin(&midijoinDesc);
  116. }
  117. // -----------------------------------------------------------------------