2 * Carla Host Plugin test
3 * Copyright (C) 2020 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"
24 static uint32_t get_buffer_size(NativeHostHandle h
)
32 static double get_sample_rate(NativeHostHandle h
)
40 static bool is_offline(NativeHostHandle h
)
48 static intptr_t dispatcher(NativeHostHandle h
, NativeHostDispatcherOpcode c
, int32_t i
, intptr_t v
, void* p
, float o
)
61 static const NativeHostDescriptor host_descriptor
= {
64 .get_buffer_size
= get_buffer_size
,
65 .get_sample_rate
= get_sample_rate
,
66 .is_offline
= is_offline
,
67 .dispatcher
= dispatcher
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');
80 const NativePluginDescriptor
* const rack
= carla_get_native_rack_plugin();
83 const NativePluginDescriptor
* const patchbay
= carla_get_native_patchbay_plugin();
84 assert(patchbay
!= NULL
);
86 const NativePluginHandle rack_handle
= rack
->instantiate(&host_descriptor
);
87 assert(rack_handle
!= NULL
);
89 const NativePluginHandle patchbay_handle
= patchbay
->instantiate(&host_descriptor
);
90 assert(patchbay_handle
!= NULL
);
92 const CarlaHostHandle rack_host_handle
= carla_create_native_plugin_host_handle(rack
, rack_handle
);
93 assert(rack_host_handle
);
95 const CarlaHostHandle patchbay_host_handle
= carla_create_native_plugin_host_handle(patchbay
, patchbay_handle
);
96 assert(patchbay_host_handle
);
98 carla_set_engine_option(rack_host_handle
, ENGINE_OPTION_PLUGIN_PATH
, PLUGIN_LV2
, lib_folder
);
99 carla_set_engine_option(patchbay_host_handle
, ENGINE_OPTION_PLUGIN_PATH
, PLUGIN_LV2
, lib_folder
);
101 uint32_t plugins_count
= 0;
102 const NativePluginDescriptor
* const plugin_descriptors
= carla_get_native_plugins_data(&plugins_count
);
103 assert(plugins_count
!= 0);
104 assert(plugin_descriptors
!= NULL
);
107 for (uint32_t i
=0; i
<plugins_count
; ++i
)
109 const NativePluginDescriptor
* const plugin_descriptor
= &plugin_descriptors
[i
];
110 assert(plugin_descriptor
->label
!= NULL
);
112 printf("Loading plugin #%u '%s'\n", i
+1, plugin_descriptor
->label
);
114 if ((plugin_descriptor
->hints
& NATIVE_PLUGIN_USES_CONTROL_VOLTAGE
) == 0x0) {
115 assert(carla_add_plugin(rack_host_handle
, BINARY_NATIVE
, PLUGIN_INTERNAL
, "", "", plugin_descriptor
->label
, 0, NULL
, 0x0));
118 if (plugin_descriptor
->midiIns
<= 1 && plugin_descriptor
->midiOuts
<= 1) {
119 assert(carla_add_plugin(patchbay_host_handle
, BINARY_NATIVE
, PLUGIN_INTERNAL
, "", "", plugin_descriptor
->label
, 0, NULL
, 0x0));
124 plugins_count
= carla_get_cached_plugin_count(PLUGIN_LV2
, lib_folder
);
125 assert(plugins_count
!= 0);
127 for (uint32_t i
=0; i
<plugins_count
; ++i
)
129 const CarlaCachedPluginInfo
* const plugin_info
= carla_get_cached_plugin_info(PLUGIN_LV2
, i
);
130 assert(plugin_info
!= NULL
);
132 printf("Loading plugin #%u '%s'\n", i
+1, plugin_info
->label
);
134 const char* plugin_uri
= strchr(plugin_info
->label
, '/');
135 assert(plugin_uri
!= NULL
&& plugin_uri
[0] != '\0' && plugin_uri
[1] != '\0');
138 if (plugin_info
->cvIns
+ plugin_info
->cvOuts
== 0) {
139 assert(carla_add_plugin(rack_host_handle
, BINARY_NATIVE
, PLUGIN_LV2
, "", "", plugin_uri
, 0, NULL
, 0x0));
142 if (plugin_info
->midiIns
<= 1 && plugin_info
->midiOuts
<= 1) {
143 assert(carla_add_plugin(patchbay_host_handle
, BINARY_NATIVE
, PLUGIN_LV2
, "", "", plugin_uri
, 0, NULL
, 0x0));
148 assert(carla_add_plugin(rack_host_handle
, BINARY_NATIVE
, PLUGIN_VST2
, "../../bin/CarlaRack.so", "", "", 0, NULL
, 0x0));
149 assert(carla_add_plugin(rack_host_handle
, BINARY_NATIVE
, PLUGIN_VST2
, "../../bin/CarlaPatchbay.so", "", "", 0, NULL
, 0x0));
151 assert(carla_add_plugin(patchbay_host_handle
, BINARY_NATIVE
, PLUGIN_VST2
, "../../bin/CarlaRack.so", "", "", 0, NULL
, 0x0));
152 assert(carla_add_plugin(patchbay_host_handle
, BINARY_NATIVE
, PLUGIN_VST2
, "../../bin/CarlaPatchbay.so", "", "", 0, NULL
, 0x0));
156 plugins_count
= carla_get_current_plugin_count(rack_host_handle
);
158 for (uint32_t i
=0; i
<plugins_count
; ++i
)
160 carla_get_plugin_info(rack_host_handle
, i
);
161 carla_get_audio_port_count_info(rack_host_handle
, i
);
162 carla_get_midi_port_count_info(rack_host_handle
, i
);
163 carla_get_parameter_count_info(rack_host_handle
, i
);
166 plugins_count
= carla_get_current_plugin_count(patchbay_host_handle
);
168 for (uint32_t i
=0; i
<plugins_count
; ++i
)
170 carla_get_plugin_info(patchbay_host_handle
, i
);
171 carla_get_audio_port_count_info(patchbay_host_handle
, i
);
172 carla_get_midi_port_count_info(patchbay_host_handle
, i
);
173 carla_get_parameter_count_info(patchbay_host_handle
, i
);
180 carla_set_engine_about_to_close(rack_host_handle
);
181 carla_remove_all_plugins(rack_host_handle
);
183 carla_set_engine_about_to_close(patchbay_host_handle
);
184 carla_remove_all_plugins(patchbay_host_handle
);
187 rack
->cleanup(rack_handle
);
188 rack
->cleanup(patchbay_handle
);
190 carla_host_handle_free(rack_host_handle
);
191 carla_host_handle_free(patchbay_host_handle
);
193 carla_juce_cleanup();