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-join.c 4.2KB

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