Remove juce completely, cleanup
[carla.git] / source / tests / carla-engine-sdl.c
blob95674a5be5cebf8c625c95b2e7d9e7a5ce193e69
1 /*
2 * Carla Host Plugin SDL test
3 * Copyright (C) 2022-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 "CarlaHost.h"
19 #include "CarlaUtils.h"
21 #include <emscripten.h>
23 #include <stdio.h>
24 #include <string.h>
26 static void engine_idle_loop(void* const arg)
28 const CarlaHostHandle handle = arg;
29 carla_engine_idle(handle);
32 static int counter = 0;
33 if (++counter == 100)
35 counter = 0;
36 const uint64_t frame = carla_get_current_transport_frame(handle);
37 printf("engine_idle_loop | play frame %llu | audio peaks %f %f\n",
38 frame,
39 carla_get_output_peak_value(handle, 0, true),
40 carla_get_output_peak_value(handle, 0, false));
45 int main(void)
47 printf("carla_get_complete_license_text: %s\n", carla_get_complete_license_text());
48 // printf("carla_get_supported_file_extensions: %s\n", carla_get_supported_file_extensions());
49 // printf("carla_get_supported_features: %s\n", carla_get_supported_features());
50 printf("carla_get_library_filename: %s\n", carla_get_library_filename());
51 printf("carla_get_library_folder: %s\n", carla_get_library_folder());
54 const uint32_t plugins_count = carla_get_cached_plugin_count(PLUGIN_INTERNAL, NULL);
55 printf("carla_get_cached_plugin_count: %u\n", plugins_count);
57 for (uint32_t i=0; i<plugins_count; ++i)
59 const CarlaCachedPluginInfo* const plugin_info = carla_get_cached_plugin_info(PLUGIN_INTERNAL, i);
60 printf("Loading carla_get_cached_plugin_info #%u '%s'\n", i+1, plugin_info->label);
64 const CarlaHostHandle handle = carla_standalone_host_init();
65 printf("carla_standalone_host_init: %p\n", handle);
67 carla_set_engine_option(handle, ENGINE_OPTION_PROCESS_MODE, ENGINE_PROCESS_MODE_CONTINUOUS_RACK, NULL);
69 const bool engine_init = carla_engine_init(handle, "SDL", "Engine Test");
70 printf("carla_engine_init: %d\n", engine_init);
72 if (!engine_init)
73 return 1;
75 const bool plugin_added = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Music", "audiofile", 0, NULL, 0x0);
76 printf("carla_add_plugin: %d\n", plugin_added);
78 if (!plugin_added)
79 goto close;
81 const bool plugin_added2 = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Gain", "audiogain_s", 0, NULL, 0x0);
82 printf("carla_add_plugin2: %d\n", plugin_added2);
84 if (!plugin_added2)
85 goto close;
87 const uint32_t current_plugins_count = carla_get_current_plugin_count(handle);
88 printf("carla_get_current_plugin_count: %u\n", current_plugins_count);
90 if (current_plugins_count != 2)
91 goto close;
93 carla_set_parameter_value(handle, 1, 0, 1.0f); // gain
95 carla_patchbay_connect(handle, false, 1, 3, 3, 1);
96 carla_patchbay_connect(handle, false, 1, 4, 3, 2);
98 carla_set_custom_data(handle, 0, CUSTOM_DATA_TYPE_PATH, "file", "/foolme.mp3");
99 carla_transport_play(handle);
101 emscripten_set_main_loop_arg(engine_idle_loop, handle, 0, false);
103 return 0;
105 close:
106 printf("carla_engine_close: %d\n", carla_engine_close(handle));
107 return 1;