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.

129 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. // FIXME for v3.0, use const for the input buffer
  39. static void midithrough_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. for (uint32_t i=0; i < midiEventCount; ++i)
  45. host->write_midi_event(host->handle, &midiEvents[i]);
  46. return;
  47. // unused
  48. (void)inBuffer;
  49. (void)outBuffer;
  50. (void)frames;
  51. }
  52. #undef handlePtr
  53. // -----------------------------------------------------------------------
  54. static const NativePluginDescriptor midithroughDesc = {
  55. .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
  56. .hints = NATIVE_PLUGIN_IS_RTSAFE,
  57. .supports = NATIVE_PLUGIN_SUPPORTS_EVERYTHING,
  58. .audioIns = 0,
  59. .audioOuts = 0,
  60. .cvIns = 0,
  61. .cvOuts = 0,
  62. .midiIns = 1,
  63. .midiOuts = 1,
  64. .paramIns = 0,
  65. .paramOuts = 0,
  66. .name = "MIDI Through",
  67. .label = "midithrough",
  68. .maker = "falkTX",
  69. .copyright = "GNU GPL v2+",
  70. .instantiate = midithrough_instantiate,
  71. .cleanup = midithrough_cleanup,
  72. .get_parameter_count = NULL,
  73. .get_parameter_info = NULL,
  74. .get_parameter_value = NULL,
  75. .get_midi_program_count = NULL,
  76. .get_midi_program_info = NULL,
  77. .set_parameter_value = NULL,
  78. .set_midi_program = NULL,
  79. .set_custom_data = NULL,
  80. .ui_show = NULL,
  81. .ui_idle = NULL,
  82. .ui_set_parameter_value = NULL,
  83. .ui_set_midi_program = NULL,
  84. .ui_set_custom_data = NULL,
  85. .activate = NULL,
  86. .deactivate = NULL,
  87. .process = midithrough_process,
  88. .get_state = NULL,
  89. .set_state = NULL,
  90. .dispatcher = NULL
  91. };
  92. // -----------------------------------------------------------------------
  93. void carla_register_native_plugin_midithrough(void);
  94. void carla_register_native_plugin_midithrough(void)
  95. {
  96. carla_register_native_plugin(&midithroughDesc);
  97. }
  98. // -----------------------------------------------------------------------