Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an small example and test of clap-first in-linked wrapper #256

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 62 additions & 7 deletions .github/workflows/pullreq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Linux External SDK
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive

Expand Down Expand Up @@ -73,11 +73,11 @@ jobs:
run_aptget: false
name: Windows gcc/minGW

- os: windows-latest
cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
install_ninja: true
run_aptget: false
name: Windows clang
#- os: windows-latest
# cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
# install_ninja: true
# run_aptget: false
# name: Windows clang

- os: ubuntu-latest
cmakeargs: -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -156,3 +156,58 @@ jobs:
find build -name downloadplug.vst3 -print
find build -name downloadplug.component -print


build_feature_clapfirst-test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
cmakeargs: -A x64
install_ninja: false
run_aptget: false
name: ClapFirst Windows 64bit MSVC

- os: ubuntu-latest
cmakeargs: -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11
install_ninja: false
run_aptget: true
name: ClapFirst Linux gcc11

- os: macos-latest
cmakeargs: -G"Xcode"
install_ninja: false
run_aptget: false
name: ClapFirst MacOS Xcode


steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Apt Update
if: ${{ matrix.run_aptget }}
run: sudo apt-get update

- name: Get Deps
if: ${{ matrix.run_aptget }}
run: sudo apt-get install -y alsa alsa-tools libasound2-dev libjack-dev libgtk-3-dev

- name: Install Ninja
if: ${{ matrix.install_ninja }}
uses: seanmiddleditch/gha-setup-ninja@master

- name: Build project
run: |
cmake -S . -B ./build ${{ matrix.cmakeargs }} -DCMAKE_BUILD_TYPE=Debug -DCLAP_WRAPPER_DOWNLOAD_DEPENDENCIES=TRUE -DCLAP_WRAPPER_BUILD_TESTS=TRUE
cmake --build ./build --config Debug --target clap-first-distortion_all_plugins

- name: Show Build Results
shell: bash
run: |
find build -name "ClapFirst*" -print


4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(CMAKE_COLOR_DIAGNOSTICS ON)
# can just build with this turned on and it will forward all note expressions to your CLAP
option(CLAP_SUPPORTS_ALL_NOTE_EXPRESSIONS "Does the underlying CLAP support note expressions" OFF)
option(CLAP_WRAPPER_WINDOWS_SINGLE_FILE "Build a single fine (rather than folder) on windows" ON)
option(CLAP_WRAPPER_BUILD_TESTS "Build test CLAP wrappers" OFF)

project(clap-wrapper
LANGUAGES C CXX
Expand Down Expand Up @@ -131,3 +132,6 @@ else()

endif()

if (${CLAP_WRAPPER_BUILD_TESTS})
add_subdirectory(tests)
endif()
5 changes: 5 additions & 0 deletions cmake/base_sdks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ function(guarantee_rtaudio)
set(BUILD_TESTING OFF CACHE BOOL "don't eject test targets")


if (APPLE)
# If you brew install jack, rtaudio will find it but not link it properly
set(RTAUDIO_API_JACK FALSE CACHE STRING "No jack by default on macos")
endif()

if (NOT "${RTAUDIO_SDK_ROOT}" STREQUAL "")
# Use the provided root
elseif (${CLAP_WRAPPER_DOWNLOAD_DEPENDENCIES})
Expand Down
3 changes: 2 additions & 1 deletion cmake/wrap_vst3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function(target_add_vst3_wrapper)
target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PUBLIC clap base-sdk-vst3)

# clap-wrapper-extensions are PUBLIC, so a clap linking the library can access the clap-wrapper-extensions
target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PUBLIC clap-wrapper-extensions clap-wrapper-compile-options clap-wrapper-shared-detail)
target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PUBLIC clap-wrapper-extensions clap-wrapper-shared-detail)
target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PRIVATE clap-wrapper-compile-options)

target_compile_options(${V3_TARGET}-clap-wrapper-vst3-lib PRIVATE
-DCLAP_SUPPORTS_ALL_NOTE_EXPRESSIONS=$<IF:$<BOOL:${V3_SUPPORTS_ALL_NOTE_EXPRESSIONS}>,1,0>
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(clap-first-example)
103 changes: 103 additions & 0 deletions tests/clap-first-example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
project(clap-first-distortion)

# By A "Clap First" plugin, we mean a plugin which is *just* implmented as
# CLAP and uses this wrapper to project into the various other platforms.
#
# One special form of clap first plugin does that by creating a
# the platform plugins with the entire clap library built in. While there's
# a few ways to do this the pattern which eemse to work best is
#
# 1. Write the etnire DSP, handling, etc... of your clap as a library without
# the clap entry
# 2. Have a minimal clap entry c++ file which just exposes the entry points from
# that static library
# 3. Make each of the clap, vst3, auv2 etc... link the static library from 1 but
# recomile the entry from 2, so the resulting plugin has the entry point exposed.
#
# We show an example of that here with a slightly modified version of the
# basic c99 distortion plugin, here re-coded using a C++ compiler.

# So first make the actual plugin as a static library
add_library(${PROJECT_NAME}_base STATIC distortion_clap.cpp)
target_link_libraries(${PROJECT_NAME}_base PUBLIC clap)


# Now build and configure the CLAP.
add_library(${PROJECT_NAME}_clap MODULE
distortion_clap_entry.cpp
)
target_link_libraries(${PROJECT_NAME}_clap ${PROJECT_NAME}_base)

if(APPLE)
set_target_properties(${PROJECT_NAME}_clap PROPERTIES
BUNDLE True
BUNDLE_EXTENSION clap
LIBRARY_OUTPUT_NAME ClapFirstDistortion
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_GUI_IDENTIFIER org.free-audio.clapfirst
MACOSX_BUNDLE_BUNDLE_NAME ClapFirstDistortion
MACOSX_BUNDLE_BUNDLE_VERSION "1"
MACOSX_BUNDLE_SHORT_VERSION_STRING "1"
XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE "YES"
)
elseif(UNIX)
set_target_properties(${PROJECT_NAME}_clap PROPERTIES OUTPUT_NAME ClapFirstDistortion SUFFIX ".clap" PREFIX "")

else()
set_target_properties(${PROJECT_NAME}_clap
PROPERTIES
OUTPUT_NAME ClapFirstDistortion
SUFFIX ".clap" PREFIX ""
LIBRARY_OUTPUT_DIRECTORY CLAP
)
endif()

# Building a VST3 is now easy. Make a MODULE library which compiles the entry code
# and links the base library, then use the wraper cmake code to expose it as a VST3
set(VST3_TARGET ${PROJECT_NAME}_vst3)
add_library(${VST3_TARGET} MODULE)
target_sources(${VST3_TARGET} PRIVATE distortion_clap_entry.cpp)
target_add_vst3_wrapper(TARGET ${VST3_TARGET}
OUTPUT_NAME "ClapFirstDistortion"
)
target_link_libraries(${VST3_TARGET} PRIVATE ${PROJECT_NAME}_base)


# And the same for the standalone
set(SA_TARGET ${PROJECT_NAME}_standalone)
add_executable(${SA_TARGET})
target_sources(${SA_TARGET} PRIVATE distortion_clap_entry.cpp)
target_link_libraries(${SA_TARGET} PRIVATE ${PROJECT_NAME}_base)
target_add_standalone_wrapper(TARGET ${SA_TARGET}
OUTPUT_NAME "ClapFirstDistortion"
STATICALLY_LINKED_CLAP_ENTRY True
PLUGIN_ID "org.free-audio.clap-first-bad-distortion")

if (APPLE)
# And the same for the AUV2
set(AUV2_TARGET ${PROJECT_NAME}_auv2)
add_library(${AUV2_TARGET} MODULE)
target_sources(${AUV2_TARGET} PRIVATE distortion_clap_entry.cpp)
target_link_libraries(${AUV2_TARGET} PRIVATE ${PROJECT_NAME}_base)
target_add_auv2_wrapper(
TARGET ${AUV2_TARGET}
OUTPUT_NAME "ClapFirstDistortion"
BUNDLE_IDENTIFIER "org.freeaudio.bad-clap-first"
BUNDLE_VERSION "1"

MANUFACTURER_NAME "FreeAudio Team"
MANUFACTURER_CODE "FrAU"
SUBTYPE_CODE "clDi"
INSTRUMENT_TYPE "aufx"

CLAP_TARGET_FOR_CONFIG ${PROJECT_NAME}_clap
)
endif()


# FInally collect those all in a utility target
add_custom_target(${PROJECT_NAME}_all_plugins)
add_dependencies(${PROJECT_NAME}_all_plugins ${PROJECT_NAME}_clap ${PROJECT_NAME}_vst3 ${PROJECT_NAME}_standalone)
if (APPLE)
add_dependencies(${PROJECT_NAME}_all_plugins ${PROJECT_NAME}_auv2)
endif()
Loading
Loading