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.

188 lines
6.2KB

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