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.

202 lines
6.6KB

  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 standalone_filename = carla_standalone_get_library_filename();
  61. assert(standalone_filename != NULL && standalone_filename[0] != '\0');
  62. const char* const utils_filename = carla_utils_get_library_filename();
  63. assert(utils_filename != NULL && utils_filename[0] != '\0');
  64. const char* const standalone_folder = carla_standalone_get_library_folder();
  65. assert(standalone_folder != NULL && standalone_folder[0] != '\0');
  66. const char* const utils_folder = carla_utils_get_library_folder();
  67. assert(utils_folder != NULL && utils_folder[0] != '\0');
  68. carla_juce_init();
  69. const NativePluginDescriptor* const rack = carla_get_native_rack_plugin();
  70. assert(rack != NULL);
  71. const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin();
  72. assert(patchbay != NULL);
  73. const NativePluginHandle rack_handle = rack->instantiate(&host_descriptor);
  74. assert(rack_handle != NULL);
  75. const NativePluginHandle patchbay_handle = patchbay->instantiate(&host_descriptor);
  76. assert(patchbay_handle != NULL);
  77. const CarlaHostHandle rack_host_handle = carla_create_native_plugin_host_handle(rack, rack_handle);
  78. assert(rack_host_handle);
  79. const CarlaHostHandle patchbay_host_handle = carla_create_native_plugin_host_handle(patchbay, patchbay_handle);
  80. assert(patchbay_host_handle);
  81. carla_set_engine_option(rack_host_handle, ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, utils_folder);
  82. carla_set_engine_option(patchbay_host_handle, ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, utils_folder);
  83. uint32_t plugins_count = 0;
  84. const NativePluginDescriptor* const plugin_descriptors = carla_get_native_plugins_data(&plugins_count);
  85. assert(plugins_count != 0);
  86. assert(plugin_descriptors != NULL);
  87. #if 1
  88. for (uint32_t i=0; i<plugins_count; ++i)
  89. {
  90. const NativePluginDescriptor* const plugin_descriptor = &plugin_descriptors[i];
  91. assert(plugin_descriptor->label != NULL);
  92. printf("Loading plugin #%u '%s'\n", i+1, plugin_descriptor->label);
  93. if ((plugin_descriptor->hints & NATIVE_PLUGIN_USES_CONTROL_VOLTAGE) == 0x0) {
  94. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_INTERNAL, "", "", plugin_descriptor->label, 0, NULL, 0x0));
  95. }
  96. if (plugin_descriptor->midiIns <= 1 && plugin_descriptor->midiOuts <= 1) {
  97. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_INTERNAL, "", "", plugin_descriptor->label, 0, NULL, 0x0));
  98. }
  99. }
  100. #endif
  101. plugins_count = carla_get_cached_plugin_count(PLUGIN_LV2, utils_folder);
  102. assert(plugins_count != 0);
  103. for (uint32_t i=0; i<plugins_count; ++i)
  104. {
  105. const CarlaCachedPluginInfo* const plugin_info = carla_get_cached_plugin_info(PLUGIN_LV2, i);
  106. assert(plugin_info != NULL);
  107. printf("Loading plugin #%u '%s'\n", i+1, plugin_info->label);
  108. const char* plugin_uri = strchr(plugin_info->label, '/');
  109. assert(plugin_uri != NULL && plugin_uri[0] != '\0' && plugin_uri[1] != '\0');
  110. ++plugin_uri;
  111. if (plugin_info->cvIns + plugin_info->cvOuts == 0) {
  112. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_LV2, "", "", plugin_uri, 0, NULL, 0x0));
  113. }
  114. if (plugin_info->midiIns <= 1 && plugin_info->midiOuts <= 1) {
  115. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_LV2, "", "", plugin_uri, 0, NULL, 0x0));
  116. }
  117. }
  118. #if 1
  119. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaRack.so", "", "", 0, NULL, 0x0));
  120. assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaPatchbay.so", "", "", 0, NULL, 0x0));
  121. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaRack.so", "", "", 0, NULL, 0x0));
  122. assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaPatchbay.so", "", "", 0, NULL, 0x0));
  123. carla_juce_idle();
  124. plugins_count = carla_get_current_plugin_count(rack_host_handle);
  125. for (uint32_t i=0; i<plugins_count; ++i)
  126. {
  127. carla_get_plugin_info(rack_host_handle, i);
  128. carla_get_audio_port_count_info(rack_host_handle, i);
  129. carla_get_midi_port_count_info(rack_host_handle, i);
  130. carla_get_parameter_count_info(rack_host_handle, i);
  131. }
  132. plugins_count = carla_get_current_plugin_count(patchbay_host_handle);
  133. for (uint32_t i=0; i<plugins_count; ++i)
  134. {
  135. carla_get_plugin_info(patchbay_host_handle, i);
  136. carla_get_audio_port_count_info(patchbay_host_handle, i);
  137. carla_get_midi_port_count_info(patchbay_host_handle, i);
  138. carla_get_parameter_count_info(patchbay_host_handle, i);
  139. }
  140. carla_juce_idle();
  141. #endif
  142. #if 0
  143. carla_set_engine_about_to_close(rack_host_handle);
  144. carla_remove_all_plugins(rack_host_handle);
  145. carla_set_engine_about_to_close(patchbay_host_handle);
  146. carla_remove_all_plugins(patchbay_host_handle);
  147. #endif
  148. rack->cleanup(rack_handle);
  149. rack->cleanup(patchbay_handle);
  150. carla_host_handle_free(rack_host_handle);
  151. carla_host_handle_free(patchbay_host_handle);
  152. carla_juce_cleanup();
  153. return 0;
  154. }