Skip to content

Commit

Permalink
Merge pull request #17 from jorshi/feat/onset-ui
Browse files Browse the repository at this point in the history
Onset Detection Parameters on UI
  • Loading branch information
jorshi authored Mar 21, 2024
2 parents 2dd4717 + 47a44ba commit c1f084b
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ modules/libtorch/

# Files related to release packaging
Presets/
prepare_plugin_release.sh
remove_library_presets.sh
SignedPlugins/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cmake.configureOnOpen": true,
"cmake.cmakePath": "/opt/homebrew/bin/cmake"
}
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions scripts/ableton_debugging_osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xattr -rc "/Applications/Ableton Live 11 Suite.app"
./scripts/add_debug_entitlements.sh "/Applications/Ableton Live 11 Suite.app"
36 changes: 36 additions & 0 deletions scripts/add_debug_entitlements.sh
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions scripts/prepare_plugin_release.sh
Original file line number Diff line number Diff line change
@@ -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/
16 changes: 14 additions & 2 deletions source/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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<juce::RangedAudioParameter*> parameters;
Expand Down
1 change: 0 additions & 1 deletion source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ void TorchDrumProcessor::processBlock(juce::AudioBuffer<float>& 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
Expand Down
3 changes: 3 additions & 0 deletions source/SynthController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c1f084b

Please sign in to comment.