Cleanup
[carla.git] / source / tests / carla-host-plugin.c
blob64ea996e1571874264b0cfd9320e0ea17fd03835
1 /*
2 * Carla Host Plugin test
3 * Copyright (C) 2020-2024 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaNativePlugin.h"
20 #include <assert.h>
21 #include <stdio.h>
22 #include <string.h>
24 static uint32_t get_buffer_size(NativeHostHandle h)
26 return 128;
28 /* unused */
29 (void)h;
32 static double get_sample_rate(NativeHostHandle h)
34 return 44100.0;
36 /* unused */
37 (void)h;
40 static bool is_offline(NativeHostHandle h)
42 return false;
44 /* unused */
45 (void)h;
48 static intptr_t dispatcher(NativeHostHandle h, NativeHostDispatcherOpcode c, int32_t i, intptr_t v, void* p, float o)
50 return 0;
52 /* unused */
53 (void)h;
54 (void)c;
55 (void)i;
56 (void)v;
57 (void)p;
58 (void)o;
61 static const NativeHostDescriptor host_descriptor = {
62 .resourceDir = "",
63 .uiName = "",
64 .get_buffer_size = get_buffer_size,
65 .get_sample_rate = get_sample_rate,
66 .is_offline = is_offline,
67 .dispatcher = dispatcher
70 int main(void)
72 const char* const lib_filename = carla_get_library_filename();
73 assert(lib_filename != NULL && lib_filename[0] != '\0');
75 const char* const lib_folder = carla_get_library_folder();
76 assert(lib_folder != NULL && lib_folder[0] != '\0');
78 const NativePluginDescriptor* const rack = carla_get_native_rack_plugin();
79 assert(rack != NULL);
81 const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin();
82 assert(patchbay != NULL);
84 const NativePluginHandle rack_handle = rack->instantiate(&host_descriptor);
85 assert(rack_handle != NULL);
87 const NativePluginHandle patchbay_handle = patchbay->instantiate(&host_descriptor);
88 assert(patchbay_handle != NULL);
90 const CarlaHostHandle rack_host_handle = carla_create_native_plugin_host_handle(rack, rack_handle);
91 assert(rack_host_handle);
93 const CarlaHostHandle patchbay_host_handle = carla_create_native_plugin_host_handle(patchbay, patchbay_handle);
94 assert(patchbay_host_handle);
96 carla_set_engine_option(rack_host_handle, ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, lib_folder);
97 carla_set_engine_option(patchbay_host_handle, ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, lib_folder);
99 uint32_t plugins_count = 0;
100 const NativePluginDescriptor* const plugin_descriptors = carla_get_native_plugins_data(&plugins_count);
101 assert(plugins_count != 0);
102 assert(plugin_descriptors != NULL);
104 #if 1
105 for (uint32_t i=0; i<plugins_count; ++i)
107 const NativePluginDescriptor* const plugin_descriptor = &plugin_descriptors[i];
108 assert(plugin_descriptor->label != NULL);
110 printf("Loading plugin #%u '%s'\n", i+1, plugin_descriptor->label);
112 if ((plugin_descriptor->hints & NATIVE_PLUGIN_USES_CONTROL_VOLTAGE) == 0x0) {
113 assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_INTERNAL, "", "", plugin_descriptor->label, 0, NULL, 0x0));
116 if (plugin_descriptor->midiIns <= 1 && plugin_descriptor->midiOuts <= 1) {
117 assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_INTERNAL, "", "", plugin_descriptor->label, 0, NULL, 0x0));
120 #endif
122 plugins_count = carla_get_cached_plugin_count(PLUGIN_LV2, lib_folder);
123 assert(plugins_count != 0);
125 for (uint32_t i=0; i<plugins_count; ++i)
127 const CarlaCachedPluginInfo* const plugin_info = carla_get_cached_plugin_info(PLUGIN_LV2, i);
128 assert(plugin_info != NULL);
130 printf("Loading plugin #%u '%s'\n", i+1, plugin_info->label);
132 const char* plugin_uri = strchr(plugin_info->label, '/');
133 assert(plugin_uri != NULL && plugin_uri[0] != '\0' && plugin_uri[1] != '\0');
134 ++plugin_uri;
136 if (plugin_info->cvIns + plugin_info->cvOuts == 0) {
137 assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_LV2, "", "", plugin_uri, 0, NULL, 0x0));
140 if (plugin_info->midiIns <= 1 && plugin_info->midiOuts <= 1) {
141 assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_LV2, "", "", plugin_uri, 0, NULL, 0x0));
145 #if 1
146 assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaRack.so", "", "", 0, NULL, 0x0));
147 assert(carla_add_plugin(rack_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaPatchbay.so", "", "", 0, NULL, 0x0));
149 assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaRack.so", "", "", 0, NULL, 0x0));
150 assert(carla_add_plugin(patchbay_host_handle, BINARY_NATIVE, PLUGIN_VST2, "../../bin/CarlaPatchbay.so", "", "", 0, NULL, 0x0));
152 plugins_count = carla_get_current_plugin_count(rack_host_handle);
154 for (uint32_t i=0; i<plugins_count; ++i)
156 carla_get_plugin_info(rack_host_handle, i);
157 carla_get_audio_port_count_info(rack_host_handle, i);
158 carla_get_midi_port_count_info(rack_host_handle, i);
159 carla_get_parameter_count_info(rack_host_handle, i);
162 plugins_count = carla_get_current_plugin_count(patchbay_host_handle);
164 for (uint32_t i=0; i<plugins_count; ++i)
166 carla_get_plugin_info(patchbay_host_handle, i);
167 carla_get_audio_port_count_info(patchbay_host_handle, i);
168 carla_get_midi_port_count_info(patchbay_host_handle, i);
169 carla_get_parameter_count_info(patchbay_host_handle, i);
171 #endif
173 #if 0
174 carla_set_engine_about_to_close(rack_host_handle);
175 carla_remove_all_plugins(rack_host_handle);
177 carla_set_engine_about_to_close(patchbay_host_handle);
178 carla_remove_all_plugins(patchbay_host_handle);
179 #endif
181 rack->cleanup(rack_handle);
182 rack->cleanup(patchbay_handle);
184 carla_host_handle_free(rack_host_handle);
185 carla_host_handle_free(patchbay_host_handle);
186 return 0;