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.

196 lines
6.3KB

  1. /*
  2. * Carla Host Plugin test
  3. * Copyright (C) 2020 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 "CarlaNativePlugin.h"
  18. #include <assert.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. static uint32_t get_buffer_size(NativeHostHandle h)
  22. {
  23. return 128;
  24. /* unused */
  25. (void)h;
  26. }
  27. static double get_sample_rate(NativeHostHandle h)
  28. {
  29. return 44100.0;
  30. /* unused */
  31. (void)h;
  32. }
  33. static bool is_offline(NativeHostHandle h)
  34. {
  35. return false;
  36. /* unused */
  37. (void)h;
  38. }
  39. static intptr_t dispatcher(NativeHostHandle h, NativeHostDispatcherOpcode c, int32_t i, intptr_t v, void* p, float o)
  40. {
  41. return 0;
  42. /* unused */
  43. (void)h;
  44. (void)c;
  45. (void)i;
  46. (void)v;
  47. (void)p;
  48. (void)o;
  49. }
  50. static const NativeHostDescriptor host_descriptor = {
  51. .resourceDir = "",
  52. .uiName = "",
  53. .get_buffer_size = get_buffer_size,
  54. .get_sample_rate = get_sample_rate,
  55. .is_offline = is_offline,
  56. .dispatcher = dispatcher
  57. };
  58. int main(void)
  59. {
  60. const char* const lib_filename = carla_get_library_filename();
  61. assert(lib_filename != NULL && lib_filename[0] != '\0');
  62. const char* const lib_folder = carla_get_library_folder();
  63. assert(lib_folder != NULL && lib_folder[0] != '\0');
  64. carla_juce_init();
  65. const NativePluginDescriptor* const rack = carla_get_native_rack_plugin();
  66. assert(rack != NULL);
  67. const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin();
  68. assert(patchbay != NULL);
  69. const NativePluginHandle rack_handle = rack->instantiate(&host_descriptor);
  70. assert(rack_handle != NULL);
  71. const NativePluginHandle patchbay_handle = patchbay->instantiate(&host_descriptor);
  72. assert(patchbay_handle != NULL);
  73. const CarlaHostHandle rack_host_handle = carla_create_native_plugin_host_handle(rack, rack_handle);
  74. assert(rack_host_handle);
  75. const CarlaHostHandle patchbay_host_handle = carla_create_native_plugin_host_handle(patchbay, patchbay_handle);
  76. assert(patchbay_host_handle);
  77. carla_set_engine_option(rack_host_handle, ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, lib_folder);
  78. carla_set_engine_option(patchbay_host_handle, ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, lib_folder);
  79. uint32_t plugins_count = 0;
  80. const NativePluginDescriptor* const plugin_descriptors = carla_get_native_plugins_data(&plugins_count);
  81. assert(plugins_count != 0);
  82. assert(plugin_descriptors != NULL);
  83. #if 1
  84. for (uint32_t i=0; i<plugins_count; ++i)
  85. {
  86. const NativePluginDescriptor* const plugin_descriptor = &plugin_descriptors[i];
  87. assert(plugin_descriptor->label != NULL);
  88. printf("Loading plugin #%u '%s'\n", i+1, plugin_descriptor->label);
  89. if ((plugin_descriptor->hints & NATIVE_PLUGIN_USES_CONTROL_VOLTAGE) == 0x0) {
  90. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_INTERNAL, "", "", plugin_descriptor->label, 0, NULL, 0x0));
  91. }
  92. if (plugin_descriptor->midiIns <= 1 && plugin_descriptor->midiOuts <= 1) {
  93. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_INTERNAL, "", "", plugin_descriptor->label, 0, NULL, 0x0));
  94. }
  95. }
  96. #endif
  97. plugins_count = carla_get_cached_plugin_count(PLUGIN_LV2, lib_folder);
  98. assert(plugins_count != 0);
  99. for (uint32_t i=0; i<plugins_count; ++i)
  100. {
  101. const CarlaCachedPluginInfo* const plugin_info = carla_get_cached_plugin_info(PLUGIN_LV2, i);
  102. assert(plugin_info != NULL);
  103. printf("Loading plugin #%u '%s'\n", i+1, plugin_info->label);
  104. const char* plugin_uri = strchr(plugin_info->label, '/');
  105. assert(plugin_uri != NULL && plugin_uri[0] != '\0' && plugin_uri[1] != '\0');
  106. ++plugin_uri;
  107. if (plugin_info->cvIns + plugin_info->cvOuts == 0) {
  108. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_LV2, "", "", plugin_uri, 0, NULL, 0x0));
  109. }
  110. if (plugin_info->midiIns <= 1 && plugin_info->midiOuts <= 1) {
  111. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_LV2, "", "", plugin_uri, 0, NULL, 0x0));
  112. }
  113. }
  114. #if 1
  115. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaRack.so", "", "", 0, NULL, 0x0));
  116. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaPatchbay.so", "", "", 0, NULL, 0x0));
  117. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaRack.so", "", "", 0, NULL, 0x0));
  118. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaPatchbay.so", "", "", 0, NULL, 0x0));
  119. carla_juce_idle();
  120. plugins_count = carla_get_current_plugin_count(rack_host_handle);
  121. for (uint32_t i=0; i<plugins_count; ++i)
  122. {
  123. carla_get_plugin_info(rack_host_handle, i);
  124. carla_get_audio_port_count_info(rack_host_handle, i);
  125. carla_get_midi_port_count_info(rack_host_handle, i);
  126. carla_get_parameter_count_info(rack_host_handle, i);
  127. }
  128. plugins_count = carla_get_current_plugin_count(patchbay_host_handle);
  129. for (uint32_t i=0; i<plugins_count; ++i)
  130. {
  131. carla_get_plugin_info(patchbay_host_handle, i);
  132. carla_get_audio_port_count_info(patchbay_host_handle, i);
  133. carla_get_midi_port_count_info(patchbay_host_handle, i);
  134. carla_get_parameter_count_info(patchbay_host_handle, i);
  135. }
  136. carla_juce_idle();
  137. #endif
  138. #if 0
  139. carla_set_engine_about_to_close(rack_host_handle);
  140. carla_remove_all_plugins(rack_host_handle);
  141. carla_set_engine_about_to_close(patchbay_host_handle);
  142. carla_remove_all_plugins(patchbay_host_handle);
  143. #endif
  144. rack->cleanup(rack_handle);
  145. rack->cleanup(patchbay_handle);
  146. carla_host_handle_free(rack_host_handle);
  147. carla_host_handle_free(patchbay_host_handle);
  148. carla_juce_cleanup();
  149. return 0;
  150. }