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.

150 lines
4.0KB

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