From 1d0466941053973923776df88a8f45d1b44c1843 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 20 Oct 2021 20:11:21 +0100 Subject: [PATCH] LV2: Add turtle-writer program --- CMakeLists.txt | 2 + modules/CMakeLists.txt | 2 + .../juce_audio_plugin_client/CMakeLists.txt | 22 ++++++ .../LV2/juce_LV2TurtleDumpProgram.cpp | 71 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 modules/juce_audio_plugin_client/CMakeLists.txt create mode 100644 modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bf3cf3c5c3..e35658db19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,3 +148,5 @@ install(FILES "${JUCE_BINARY_DIR}/JUCEConfigVersion.cmake" "${JUCE_CMAKE_UTILS_DIR}/copyDir.cmake" "${JUCE_CMAKE_UTILS_DIR}/juce_runtime_arch_detection.cpp" DESTINATION "${JUCE_INSTALL_DESTINATION}") + +install(EXPORT LV2_HELPER NAMESPACE juce:: DESTINATION "${JUCE_INSTALL_DESTINATION}") diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 55aa6c373a..41e8ff6e86 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -37,3 +37,5 @@ juce_add_modules( juce_osc juce_product_unlocking juce_video) + +add_subdirectory(juce_audio_plugin_client) diff --git a/modules/juce_audio_plugin_client/CMakeLists.txt b/modules/juce_audio_plugin_client/CMakeLists.txt new file mode 100644 index 0000000000..7febe507ec --- /dev/null +++ b/modules/juce_audio_plugin_client/CMakeLists.txt @@ -0,0 +1,22 @@ +# ============================================================================== +# +# This file is part of the JUCE 7 technical preview. +# Copyright (c) 2022 - Raw Material Software Limited +# +# You may use this code under the terms of the GPL v3 +# (see www.gnu.org/licenses). +# +# For the technical preview this file cannot be licensed commercially. +# +# JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER +# EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE +# DISCLAIMED. +# +# ============================================================================== + +add_executable(juce_lv2_helper LV2/juce_LV2TurtleDumpProgram.cpp) +add_executable(juce::juce_lv2_helper ALIAS juce_lv2_helper) +target_compile_features(juce_lv2_helper PRIVATE cxx_std_14) +set_target_properties(juce_lv2_helper PROPERTIES BUILD_WITH_INSTALL_RPATH ON) +target_link_libraries(juce_lv2_helper PRIVATE ${CMAKE_DL_LIBS}) +install(TARGETS juce_lv2_helper EXPORT LV2_HELPER DESTINATION "bin/JUCE-${JUCE_VERSION}") diff --git a/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp b/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp new file mode 100644 index 0000000000..e0603a9844 --- /dev/null +++ b/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp @@ -0,0 +1,71 @@ +/* + ============================================================================== + + This file is part of the JUCE 7 technical preview. + Copyright (c) 2022 - Raw Material Software Limited + + You may use this code under the terms of the GPL v3 + (see www.gnu.org/licenses). + + For the technical preview this file cannot be licensed commercially. + + JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER + EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE + DISCLAIMED. + + ============================================================================== +*/ + +#ifdef _WIN32 + #include + HMODULE dlopen (const char* filename, int) { return LoadLibrary (filename); } + FARPROC dlsym (HMODULE handle, const char* name) { return GetProcAddress (handle, name); } + enum { RTLD_LAZY = 0 }; +#else + #include +#endif + +#include + +// Replicating some of the LV2 header here so that we don't have to set up any +// custom include paths for this file. +// Normally this would be a bad idea, but the LV2 API has to keep these definitions +// in order to remain backwards-compatible. + +extern "C" +{ + typedef struct LV2_Descriptor + { + const void* a; + const void* b; + const void* c; + const void* d; + const void* e; + const void* f; + const void* g; + const void* (*extension_data)(const char* uri); + } LV2_Descriptor; +} + +int main (int argc, const char** argv) +{ + if (argc != 2) + return 1; + + const auto* libraryPath = argv[1]; + + struct RecallFeature + { + int (*doRecall) (const char*); + }; + + if (auto* handle = dlopen (libraryPath, RTLD_LAZY)) + if (auto* getDescriptor = reinterpret_cast (dlsym (handle, "lv2_descriptor"))) + if (auto* descriptor = getDescriptor (0)) + if (auto* extensionData = descriptor->extension_data) + if (auto* recallFeature = reinterpret_cast (extensionData ("https://lv2-extensions.juce.com/turtle_recall"))) + if (auto* doRecall = recallFeature->doRecall) + return doRecall (libraryPath); + + return 1; +}