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.

128 lines
3.4KB

  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. } MidiThroughHandle;
  24. // -----------------------------------------------------------------------
  25. static NativePluginHandle midithrough_instantiate(const NativeHostDescriptor* host)
  26. {
  27. MidiThroughHandle* const handle = (MidiThroughHandle*)malloc(sizeof(MidiThroughHandle));
  28. if (handle == NULL)
  29. return NULL;
  30. handle->host = host;
  31. return handle;
  32. }
  33. #define handlePtr ((MidiThroughHandle*)handle)
  34. static void midithrough_cleanup(NativePluginHandle handle)
  35. {
  36. free(handlePtr);
  37. }
  38. static void midithrough_process(NativePluginHandle handle,
  39. const float** inBuffer, float** outBuffer, uint32_t frames,
  40. const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
  41. {
  42. const NativeHostDescriptor* const host = handlePtr->host;
  43. for (uint32_t i=0; i < midiEventCount; ++i)
  44. host->write_midi_event(host->handle, &midiEvents[i]);
  45. return;
  46. // unused
  47. (void)inBuffer;
  48. (void)outBuffer;
  49. (void)frames;
  50. }
  51. #undef handlePtr
  52. // -----------------------------------------------------------------------
  53. static const NativePluginDescriptor midithroughDesc = {
  54. .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
  55. .hints = NATIVE_PLUGIN_IS_RTSAFE,
  56. .supports = NATIVE_PLUGIN_SUPPORTS_EVERYTHING,
  57. .audioIns = 0,
  58. .audioOuts = 0,
  59. .midiIns = 1,
  60. .midiOuts = 1,
  61. .paramIns = 0,
  62. .paramOuts = 0,
  63. .name = "MIDI Through",
  64. .label = "midithrough",
  65. .maker = "falkTX",
  66. .copyright = "GNU GPL v2+",
  67. .instantiate = midithrough_instantiate,
  68. .cleanup = midithrough_cleanup,
  69. .get_parameter_count = NULL,
  70. .get_parameter_info = NULL,
  71. .get_parameter_value = NULL,
  72. .get_midi_program_count = NULL,
  73. .get_midi_program_info = NULL,
  74. .set_parameter_value = NULL,
  75. .set_midi_program = NULL,
  76. .set_custom_data = NULL,
  77. .ui_show = NULL,
  78. .ui_idle = NULL,
  79. .ui_set_parameter_value = NULL,
  80. .ui_set_midi_program = NULL,
  81. .ui_set_custom_data = NULL,
  82. .activate = NULL,
  83. .deactivate = NULL,
  84. .process = midithrough_process,
  85. .get_state = NULL,
  86. .set_state = NULL,
  87. .dispatcher = NULL,
  88. .render_inline_display = NULL
  89. };
  90. // -----------------------------------------------------------------------
  91. void carla_register_native_plugin_midithrough(void);
  92. void carla_register_native_plugin_midithrough(void)
  93. {
  94. carla_register_native_plugin(&midithroughDesc);
  95. }
  96. // -----------------------------------------------------------------------