From a0646abd077ee602b3620c181b9f9412a24c94ec Mon Sep 17 00:00:00 2001 From: jorshi Date: Mon, 18 Mar 2024 22:56:10 +0000 Subject: [PATCH 1/2] scripts to support building and releasing plugins --- .gitignore | 1 - .vscode/settings.json | 4 +++ CMakeLists.txt | 4 +-- scripts/ableton_debugging_osx.sh | 2 ++ scripts/add_debug_entitlements.sh | 36 +++++++++++++++++++++++ scripts/prepare_plugin_release.sh | 49 +++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100755 scripts/ableton_debugging_osx.sh create mode 100755 scripts/add_debug_entitlements.sh create mode 100755 scripts/prepare_plugin_release.sh diff --git a/.gitignore b/.gitignore index 26af4e5..8e39ccf 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,5 @@ modules/libtorch/ # Files related to release packaging Presets/ -prepare_plugin_release.sh remove_library_presets.sh SignedPlugins/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6d3e577 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "cmake.configureOnOpen": true, + "cmake.cmakePath": "/opt/homebrew/bin/cmake" +} diff --git a/CMakeLists.txt b/CMakeLists.txt index c943bfc..e4405ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) -set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment target") +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment target") set(CMAKE_CXX_STANDARD 17) -project(TorchDrum VERSION 0.0.4) +project(TorchDrum VERSION 0.0.5) # Adding submodules add_subdirectory(modules) diff --git a/scripts/ableton_debugging_osx.sh b/scripts/ableton_debugging_osx.sh new file mode 100755 index 0000000..76dab74 --- /dev/null +++ b/scripts/ableton_debugging_osx.sh @@ -0,0 +1,2 @@ +xattr -rc "/Applications/Ableton Live 11 Suite.app" +./scripts/add_debug_entitlements.sh "/Applications/Ableton Live 11 Suite.app" diff --git a/scripts/add_debug_entitlements.sh b/scripts/add_debug_entitlements.sh new file mode 100755 index 0000000..64c69a9 --- /dev/null +++ b/scripts/add_debug_entitlements.sh @@ -0,0 +1,36 @@ +#! /bin/bash +# Simple Utility Script for allowing debug of hardened macOS apps. +# This is useful mostly for plug-in developer that would like keep developing without turning SIP off. +# Credit for idea goes to (McMartin): https://forum.juce.com/t/apple-gatekeeper-notarised-distributables/29952/57?u=ttg +# Update 2022-03-10: Based on Fabian's feedback, add capability to inject DYLD for sanitizers. +# +# Please note: +# - Modern Logic (on M1s) uses `AUHostingService` which resides within the system thus not patchable and REQUIRES to turn-off SIP. +# - Some hosts uses separate plug-in scanning or sandboxing. +# if that's the case, it's required to patch those (if needed) and attach debugger to them instead. +# +# If you see `operation not permitted`, make sure the calling process has Full Disk Access. +# For example Terminal.app is showing and has Full Disk Access under System Preferences -> Privacy & Security +# +app_path=$1 + +if [ -z "$app_path" ]; +then + echo "You need to specify app to re-codesign!" + exit 0 +fi + +# This uses local codesign. so it'll be valid ONLY on the machine you've re-signed with. +entitlements_plist=/tmp/debug_entitlements.plist +echo "Grabbing entitlements from app..." +codesign -d --entitlements - "$app_path" --xml >> $entitlements_plist || { exit 1; } +echo "Patch entitlements (if missing)..." +/usr/libexec/PlistBuddy -c "Add :com.apple.security.cs.disable-library-validation bool true" $entitlements_plist +/usr/libexec/PlistBuddy -c "Add :com.apple.security.cs.allow-unsigned-executable-memory bool true" $entitlements_plist +/usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" $entitlements_plist +# allow custom dyld for sanitizers... +/usr/libexec/PlistBuddy -c "Add :com.apple.security.cs.allow-dyld-environment-variables bool true" $entitlements_plist +echo "Re-applying entitlements (if missing)..." +codesign --force --options runtime --sign - --entitlements $entitlements_plist "$app_path" || { echo "codesign failed!"; } +echo "Removing temporary plist..." +rm $entitlements_plist diff --git a/scripts/prepare_plugin_release.sh b/scripts/prepare_plugin_release.sh new file mode 100755 index 0000000..7865a7b --- /dev/null +++ b/scripts/prepare_plugin_release.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# exit on failure +set -e + +rm -rf build + +# Build plugin +cmake -Bbuild -GXcode -DMACOS_RELEASE=ON \ + -DCMAKE_PREFIX_PATH=/Users/jordanm/anaconda3/envs/torchdrum/lib/python3.10/site-packages/torch/share/cmake \ + -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE="Manual" \ + -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO \ + -DCMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS="--timestamp" + +cmake --build build --config Release -j12 + +# Copy the release plugin and create a signature +rm -rf SignedPlugins +cp -r build/TorchDrum_artefacts/Release/VST3/ SignedPlugins/ + +# Copy libtorch +mkdir -p SignedPlugins/TorchDrum.vst3/Contents/Frameworks +cp /Users/jordanm/anaconda3/envs/torchdrum/lib/python3.10/site-packages/torch/lib/libtorch.dylib SignedPlugins/TorchDrum.vst3/Contents/Frameworks/ +cp /Users/jordanm/anaconda3/envs/torchdrum/lib/python3.10/site-packages/torch/lib/libtorch_cpu.dylib SignedPlugins/TorchDrum.vst3/Contents/Frameworks/ +cp /Users/jordanm/anaconda3/envs/torchdrum/lib/python3.10/site-packages/torch/lib/libc10.dylib SignedPlugins/TorchDrum.vst3/Contents/Frameworks/ +cp /Users/jordanm/anaconda3/envs/torchdrum/lib/python3.10/site-packages/torch/lib/libtorch_global_deps.dylib SignedPlugins/TorchDrum.vst3/Contents/Frameworks/ + +# Update the links to libtorch +install_name_tool -change @rpath/libtorch.dylib @loader_path/../Frameworks/libtorch.dylib SignedPlugins/TorchDrum.vst3/Contents/MacOS/TorchDrum +install_name_tool -change @rpath/libtorch_cpu.dylib @loader_path/../Frameworks/libtorch_cpu.dylib SignedPlugins/TorchDrum.vst3/Contents/MacOS/TorchDrum +install_name_tool -change @rpath/libc10.dylib @loader_path/../Frameworks/libc10.dylib SignedPlugins/TorchDrum.vst3/Contents/MacOS/TorchDrum +install_name_tool -change @rpath/libtorch_global_deps.dylib @loader_path/../Frameworks/libtorch_global_deps.dylib SignedPlugins/TorchDrum.vst3/Contents/MacOS/TorchDrum + +cd SignedPlugins +codesign --deep --force --options runtime --timestamp -s $APPLE_DEVELOPER_ID -v TorchDrum.vst3 + +codesign --display --verbose TorchDrum.vst3 +codesign -vvv --deep --strict TorchDrum.vst3 + +# Notarization +ditto -c -k --keepParent TorchDrum.vst3 TorchDrum.zip +xcrun notarytool submit TorchDrum.zip --keychain-profile "notarytool-password" --wait +xcrun stapler staple TorchDrum.vst3 + +# Install plugin for testing +sudo rm -rf /Library/Audio/Plug-Ins/VST3/TorchDrum.vst3 +rm -rf ~/Library/Audio/Plug-Ins/VST3/TorchDrum.vst3 + +sudo cp -r TorchDrum.vst3 /Library/Audio/Plug-Ins/VST3/ From 47a44ba5c57f6ec0868af710104bd3cc585f4bc5 Mon Sep 17 00:00:00 2001 From: jorshi Date: Tue, 19 Mar 2024 00:18:32 +0000 Subject: [PATCH 2/2] Adding parameters for onset detection --- source/Parameters.h | 16 ++++++++++++++-- source/PluginEditor.cpp | 1 - source/PluginProcessor.cpp | 7 +++++++ source/SynthController.h | 3 +++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/source/Parameters.h b/source/Parameters.h index 9eddab1..eba77bc 100644 --- a/source/Parameters.h +++ b/source/Parameters.h @@ -7,11 +7,17 @@ class Parameters public: Parameters() { + parameters.push_back(onThreshold); + parameters.push_back(offThreshold); + parameters.push_back(waitSamples); parameters.push_back(sensitivity); } void add(juce::AudioProcessor& processor) const { + processor.addParameter(onThreshold); + processor.addParameter(offThreshold); + processor.addParameter(waitSamples); processor.addParameter(sensitivity); } @@ -23,9 +29,15 @@ class Parameters delete param; } - //Raw pointers. They will be owned by either the processor or the APVTS (if you use it) + // Raw pointers. They will be owned by either the processor or the APVTS (if you use it) + juce::AudioParameterFloat* onThreshold = + new juce::AudioParameterFloat({ "onThreshold", 1 }, "On Threshold", 0.5f, 32.f, 16.0f); + juce::AudioParameterFloat* offThreshold = + new juce::AudioParameterFloat({ "offThreshold", 1 }, "Off Threshold", 0.0f, 32.f, 4.66f); + juce::AudioParameterInt* waitSamples = + new juce::AudioParameterInt({ "waitSamples", 1 }, "Wait Samples", 0, 5000, 1000); juce::AudioParameterFloat* sensitivity = - new juce::AudioParameterFloat({ "sensitivity", 1 }, "Sensitivity", 0.f, 4.f, 1.0f); + new juce::AudioParameterFloat({ "sensitivity", 1 }, "Mapping Sensitivity", 0.f, 4.f, 1.0f); private: std::vector parameters; diff --git a/source/PluginEditor.cpp b/source/PluginEditor.cpp index e42bf69..77fcc3b 100644 --- a/source/PluginEditor.cpp +++ b/source/PluginEditor.cpp @@ -32,7 +32,6 @@ TorchDrumEditor::TorchDrumEditor(TorchDrumProcessor& p) }; // Add the action listener to the SynthController - // TODO: This is probably causing the segfault!! processor.getSynthController().getBroadcaster().addActionListener(this); setSize(400, 600); diff --git a/source/PluginProcessor.cpp b/source/PluginProcessor.cpp index aa69fcb..b98101a 100644 --- a/source/PluginProcessor.cpp +++ b/source/PluginProcessor.cpp @@ -25,6 +25,13 @@ void TorchDrumProcessor::processBlock(juce::AudioBuffer& buffer, { juce::ignoreUnused(midiMessages); + // Parameters to update once per block + auto& onsetDetection = synthController.getOnsetDetection(); + onsetDetection.updateParameters( + parameters.onThreshold->get(), + parameters.offThreshold->get(), + parameters.waitSamples->get()); + for (int sample = 0; sample < buffer.getNumSamples(); ++sample) { // Process input audio for the controller -- mix to mono diff --git a/source/SynthController.h b/source/SynthController.h index de19d6c..2deeb07 100644 --- a/source/SynthController.h +++ b/source/SynthController.h @@ -52,6 +52,9 @@ class SynthController // Get the action broadcaster juce::ActionBroadcaster& getBroadcaster() { return broadcaster; } + // Get the onset detection object + OnsetDetection& getOnsetDetection() { return onsetDetection; } + private: // Add a sample to the circular audio buffer void addSampleToBuffer(float x);