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.

125 lines
3.3KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2013 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 PluginHostDescriptor* host;
  23. MappedValue map_midi;
  24. } MidiThroughHandle;
  25. // -----------------------------------------------------------------------
  26. static PluginHandle midiThrough_instantiate(const PluginHostDescriptor* host)
  27. {
  28. MidiThroughHandle* const handle = (MidiThroughHandle*)malloc(sizeof(MidiThroughHandle));
  29. if (handle == NULL)
  30. return NULL;
  31. handle->host = host;
  32. handle->map_midi = host->map_value(host->handle, EVENT_TYPE_MIDI);
  33. return handle;
  34. }
  35. #define handlePtr ((MidiThroughHandle*)handle)
  36. static void midiThrough_cleanup(PluginHandle handle)
  37. {
  38. free(handlePtr);
  39. }
  40. static void midiThrough_process(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, const Event* events, uint32_t eventCount)
  41. {
  42. const PluginHostDescriptor* const host = handlePtr->host;
  43. const MappedValue map_midi = handlePtr->map_midi;
  44. for (uint32_t i=0; i < eventCount; ++i)
  45. {
  46. if (events[i].type == map_midi)
  47. host->write_event(host->handle, &events[i]);
  48. }
  49. return;
  50. // unused
  51. (void)inBuffer;
  52. (void)outBuffer;
  53. (void)frames;
  54. }
  55. #undef handlePtr
  56. // -----------------------------------------------------------------------
  57. static const PluginDescriptor midiThroughDesc = {
  58. .api = CARLA_NATIVE_API_VERSION,
  59. .categories = PLUGIN_CATEGORY_UTILITY ":midi",
  60. .features = "rtsafe",
  61. .supports = PLUGIN_SUPPORTS_EVERYTHING,
  62. .metadata = NULL,
  63. .audioIns = 0,
  64. .audioOuts = 0,
  65. .midiIns = 1,
  66. .midiOuts = 1,
  67. .paramIns = 0,
  68. .paramOuts = 0,
  69. .author = "falkTX",
  70. .name = "MIDI Through",
  71. .label = "midiThrough",
  72. .copyright = "GNU GPL v2+",
  73. .version = 0x1000,
  74. .instantiate = midiThrough_instantiate,
  75. .cleanup = midiThrough_cleanup,
  76. .get_parameter_count = NULL,
  77. .get_parameter_info = NULL,
  78. .get_parameter_value = NULL,
  79. .get_parameter_text = NULL,
  80. .set_parameter_value = NULL,
  81. .get_midi_program_count = NULL,
  82. .get_midi_program_info = NULL,
  83. .set_midi_program = NULL,
  84. .idle = NULL,
  85. .get_state = NULL,
  86. .set_state = NULL,
  87. .activate = NULL,
  88. .deactivate = NULL,
  89. .process = midiThrough_process,
  90. .dispatcher = NULL
  91. };
  92. // -----------------------------------------------------------------------
  93. void carla_register_native_plugin_midiThrough()
  94. {
  95. carla_register_native_plugin(&midiThroughDesc);
  96. }
  97. // -----------------------------------------------------------------------