From 135c828b66b9629737bb6469a6fc73b2d0fffc90 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 3 Jul 2022 01:03:37 +0100 Subject: [PATCH] Add SDL/wasm test code Signed-off-by: falkTX --- source/tests/Makefile | 36 ++++++++++-- source/tests/carla-engine-sdl.c | 98 +++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 source/tests/carla-engine-sdl.c diff --git a/source/tests/Makefile b/source/tests/Makefile index 43fdc6d79..af01535e2 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -21,14 +21,14 @@ endif # --------------------------------------------------------------------------------------------------------------------- -BUILD_C_FLAGS += -I.. -BUILD_CXX_FLAGS += -I.. -I$(CWD)/modules +BASE_FLAGS += -DBUILDING_CARLA -DREAL_BUILD +BASE_FLAGS += -I. -I.. -I../backend -I../includes -I../modules -I../utils +BUILD_CXX_FLAGS += -I$(CWD)/modules # --------------------------------------------------------------------------------------------------------------------- PEDANTIC_FLAGS = -pedantic -pedantic-errors -PEDANTIC_FLAGS += -Wall -Wextra -Werror -pipe -DBUILDING_CARLA -DREAL_BUILD -PEDANTIC_FLAGS += -I. -I../backend -I../includes -I../modules -I../utils +PEDANTIC_FLAGS += -Wall -Wextra -Werror -pipe PEDANTIC_FLAGS += -Wabi=98 -Wcast-qual -Wclobbered -Wconversion -Wdisabled-optimization PEDANTIC_FLAGS += -Wcast-align -Wcast-qual -Wclobbered -Wconversion -Wdisabled-optimization @@ -75,7 +75,12 @@ TARGETS = \ ansi-pedantic-test_cxx98_run \ ansi-pedantic-test_cxx03_run \ ansi-pedantic-test_cxx11_run \ - carla-host-plugin_run + carla-host-plugin_run \ + carla-engine-sdl + +ifeq ($(WASM),true) +TARGETS = carla-engine-sdl$(APP_EXT) +endif # --------------------------------------------------------------------------------------------------------------------- @@ -125,6 +130,27 @@ $(BINDIR)/carla-host-plugin: carla-host-plugin.c # --------------------------------------------------------------------------------------------------------------------- +# $(CWD)/../build/plugin/Release/carla-host-plugin.cpp.o \ + +.PHONY: carla-engine-sdl$(APP_EXT) +carla-engine-sdl$(APP_EXT): $(OBJDIR)/carla-engine-sdl.c.o + $(CC) $< \ + $(CWD)/../build/backend/Release/CarlaStandalone.cpp.o \ + $(MODULEDIR)/carla_engine.a \ + $(MODULEDIR)/carla_plugin.a \ + $(MODULEDIR)/lilv.a \ + $(MODULEDIR)/native-plugins.a \ + $(MODULEDIR)/sfzero.a \ + $(MODULEDIR)/audio_decoder.a \ + $(MODULEDIR)/rtmempool.a \ + $(MODULEDIR)/water.a \ + $(MODULEDIR)/ysfx.a \ + $(MODULEDIR)/zita-resampler.a \ + -lSDL --preload-file foolme.mp3 -sALLOW_MEMORY_GROWTH \ + -o $@ + +# --------------------------------------------------------------------------------------------------------------------- + clean: rm -f $(BINDIR)/ansi-pedantic-test_* $(BINDIR)/carla-host-plugin diff --git a/source/tests/carla-engine-sdl.c b/source/tests/carla-engine-sdl.c new file mode 100644 index 000000000..ad69227d5 --- /dev/null +++ b/source/tests/carla-engine-sdl.c @@ -0,0 +1,98 @@ +/* + * Carla Host Plugin SDL test + * Copyright (C) 2022 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#include "CarlaHost.h" +#include "CarlaUtils.h" + +#include + +#include +#include + +static void engine_idle_loop(void* const arg) +{ + const CarlaHostHandle handle = arg; + static int counter = 0; + if (++counter == 100) + { + carla_engine_idle(handle); + counter = 0; + const uint64_t frame = carla_get_current_transport_frame(handle); + printf("engine_idle_loop | play frame %llu | audio peaks %f %f\n", + frame, + carla_get_output_peak_value(handle, 0, true), + carla_get_output_peak_value(handle, 0, false)); + } +} + +int main(void) +{ + printf("carla_get_complete_license_text: %s\n", carla_get_complete_license_text()); +// printf("carla_get_juce_version: %s\n", carla_get_juce_version()); +// printf("carla_get_supported_file_extensions: %s\n", carla_get_supported_file_extensions()); +// printf("carla_get_supported_features: %s\n", carla_get_supported_features()); + printf("carla_get_library_filename: %s\n", carla_get_library_filename()); + printf("carla_get_library_folder: %s\n", carla_get_library_folder()); + + /* + const uint32_t plugins_count = carla_get_cached_plugin_count(PLUGIN_INTERNAL, NULL); + printf("carla_get_cached_plugin_count: %u\n", plugins_count); + + for (uint32_t i=0; ilabel); + } + */ + + const CarlaHostHandle handle = carla_standalone_host_init(); + printf("carla_standalone_host_init: %p\n", handle); + + carla_set_engine_option(handle, ENGINE_OPTION_PROCESS_MODE, ENGINE_PROCESS_MODE_CONTINUOUS_RACK, NULL); + + const bool engine_init = carla_engine_init(handle, "SDL", "Engine Test"); + printf("carla_engine_init: %d\n", engine_init); + + if (!engine_init) + return 1; + + const bool plugin_added = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Music", "audiofile", 0, NULL, PLUGIN_OPTIONS_NULL); + printf("carla_add_plugin: %d\n", plugin_added); + + if (!plugin_added) + goto close; + + const uint32_t current_plugins_count = carla_get_current_plugin_count(handle); + printf("carla_get_current_plugin_count: %u\n", current_plugins_count); + + if (current_plugins_count != 1) + goto close; + + carla_patchbay_connect(handle, false, 1, 3, 3, 1); + carla_patchbay_connect(handle, false, 1, 4, 3, 2); + + carla_set_custom_data(handle, 0, CUSTOM_DATA_TYPE_PATH, "file", "/foolme.mp3"); + carla_transport_play(handle); + + emscripten_set_main_loop_arg(engine_idle_loop, handle, 0, false); + + return 0; + +close: + printf("carla_engine_close: %d\n", carla_engine_close(handle)); + return 1; +}