From b54f89ced123fcb1fa39d60456278520e74fcc78 Mon Sep 17 00:00:00 2001 From: Adam Hammad Date: Sat, 18 Jan 2025 09:46:50 +0100 Subject: [PATCH] Plugins: Add Automatable params to Chorus and Delay --- .../plugins/effects/tracktion_Chorus.cpp | 41 +++++++++++++++++++ .../plugins/effects/tracktion_Chorus.h | 15 +++++++ .../plugins/effects/tracktion_Delay.cpp | 14 +++++-- .../plugins/effects/tracktion_Delay.h | 4 +- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/modules/tracktion_engine/plugins/effects/tracktion_Chorus.cpp b/modules/tracktion_engine/plugins/effects/tracktion_Chorus.cpp index 07fbae8683d..21fc34d3422 100644 --- a/modules/tracktion_engine/plugins/effects/tracktion_Chorus.cpp +++ b/modules/tracktion_engine/plugins/effects/tracktion_Chorus.cpp @@ -13,19 +13,60 @@ namespace tracktion { inline namespace engine ChorusPlugin::ChorusPlugin (PluginCreationInfo info) : Plugin (info) { + depthParam = addParam ("depth", TRANS("Depth"), { 0.0f, 10.0f }, + [] (float value) { return juce::String (value, 1) + " ms"; }, + [] (const juce::String& s) { return s.getFloatValue(); }); + + speedParam = addParam ("speed", TRANS("Speed"), { 0.0f, 10.0f }, + [] (float value) { return juce::String (value, 1) + " Hz"; }, + [] (const juce::String& s) { return s.getFloatValue(); }); + + widthParam = addParam ("width", TRANS("Width"), { 0.0f, 1.0f }, + [] (float value) { return juce::String ((int)(100.0f * value)) + "%"; }, + [] (const juce::String& s) { return s.getFloatValue(); }); + + mixParam = addParam ("mix", TRANS("Mix"), { 0.0f, 1.0f }, + [] (float value) { return juce::String ((int)(100.0f * value)) + "%"; }, + [] (const juce::String& s) { return s.getFloatValue(); }); + auto um = getUndoManager(); depthMs.referTo (state, IDs::depthMs, um, 3.0f); speedHz.referTo (state, IDs::speedHz, um, 1.0f); width.referTo (state, IDs::width, um, 0.5f); mixProportion.referTo (state, IDs::mixProportion, um, 0.5f); + + // Attach parameters to their values + depthParam->attachToCurrentValue (depthMs); + speedParam->attachToCurrentValue (speedHz); + widthParam->attachToCurrentValue (width); + mixParam->attachToCurrentValue (mixProportion); } ChorusPlugin::~ChorusPlugin() { notifyListenersOfDeletion(); + + // Detach parameters from their values + depthParam->detachFromCurrentValue(); + speedParam->detachFromCurrentValue(); + widthParam->detachFromCurrentValue(); + mixParam->detachFromCurrentValue(); } +// Add getter/setter implementations +void ChorusPlugin::setDepth (float value) { depthParam->setParameter (juce::jlimit (0.0f, 10.0f, value), juce::sendNotification); } +float ChorusPlugin::getDepth() { return depthParam->getCurrentValue(); } + +void ChorusPlugin::setSpeed (float value) { speedParam->setParameter (juce::jlimit (0.0f, 10.0f, value), juce::sendNotification); } +float ChorusPlugin::getSpeed() { return speedParam->getCurrentValue(); } + +void ChorusPlugin::setWidth (float value) { widthParam->setParameter (juce::jlimit (0.0f, 1.0f, value), juce::sendNotification); } +float ChorusPlugin::getWidth() { return widthParam->getCurrentValue(); } + +void ChorusPlugin::setMix (float value) { mixParam->setParameter (juce::jlimit (0.0f, 1.0f, value), juce::sendNotification); } +float ChorusPlugin::getMix() { return mixParam->getCurrentValue(); } + const char* ChorusPlugin::xmlTypeName = "chorus"; void ChorusPlugin::initialise (const PluginInitialisationInfo& info) diff --git a/modules/tracktion_engine/plugins/effects/tracktion_Chorus.h b/modules/tracktion_engine/plugins/effects/tracktion_Chorus.h index fc2bd31d49c..c4a14612878 100644 --- a/modules/tracktion_engine/plugins/effects/tracktion_Chorus.h +++ b/modules/tracktion_engine/plugins/effects/tracktion_Chorus.h @@ -33,8 +33,23 @@ class ChorusPlugin : public Plugin void restorePluginStateFromValueTree (const juce::ValueTree&) override; + void setDepth (float value); + float getDepth(); + + void setSpeed (float value); + float getSpeed(); + + void setWidth (float value); + float getWidth(); + + void setMix (float value); + float getMix(); + juce::CachedValue depthMs, width, mixProportion, speedHz; + AutomatableParameter::Ptr depthParam, speedParam, + widthParam, mixParam; + private: //============================================================================== DelayBufferBase delayBuffer; diff --git a/modules/tracktion_engine/plugins/effects/tracktion_Delay.cpp b/modules/tracktion_engine/plugins/effects/tracktion_Delay.cpp index 9685fe2e888..913a5e70842 100644 --- a/modules/tracktion_engine/plugins/effects/tracktion_Delay.cpp +++ b/modules/tracktion_engine/plugins/effects/tracktion_Delay.cpp @@ -21,14 +21,19 @@ DelayPlugin::DelayPlugin (PluginCreationInfo info) : Plugin (info) [] (float value) { return juce::String (juce::roundToInt (value * 100.0f)) + "% wet"; }, [] (const juce::String& s) { return s.getFloatValue() / 100.0f; }); + lengthMs = addParam ("length", TRANS("Length"), { 0.0f, 1000.0f }, + [] (float value) { return juce::String (value, 1) + " ms"; }, + [] (const juce::String& s) { return s.getFloatValue(); }); + auto um = getUndoManager(); feedbackValue.referTo (state, IDs::feedback, um, -6.0f); mixValue.referTo (state, IDs::mix, um, 0.3f); - lengthMs.referTo (state, IDs::length, um, 150); + lengthMsValue.referTo (state, IDs::length, um, 150); feedbackDb->attachToCurrentValue (feedbackValue); mixProportion->attachToCurrentValue (mixValue); + lengthMs->attachToCurrentValue (lengthMsValue); } DelayPlugin::~DelayPlugin() @@ -37,13 +42,14 @@ DelayPlugin::~DelayPlugin() feedbackDb->detachFromCurrentValue(); mixProportion->detachFromCurrentValue(); + lengthMs->detachFromCurrentValue(); } const char* DelayPlugin::xmlTypeName = "delay"; void DelayPlugin::initialise (const PluginInitialisationInfo& info) { - const int lengthInSamples = (int) (lengthMs * info.sampleRate / 1000.0); + const int lengthInSamples = (int) (lengthMsValue * info.sampleRate / 1000.0); delayBuffer.ensureMaxBufferSize (lengthInSamples); delayBuffer.clearBuffer(); } @@ -70,7 +76,7 @@ void DelayPlugin::applyToBuffer (const PluginRenderContext& fc) const AudioFadeCurve::CrossfadeLevels wetDry (mixProportion->getCurrentValue()); - const int lengthInSamples = (int) (lengthMs * sampleRate / 1000.0); + const int lengthInSamples = (int) (lengthMsValue * sampleRate / 1000.0); delayBuffer.ensureMaxBufferSize (lengthInSamples); const int offset = delayBuffer.bufferPos; @@ -101,7 +107,7 @@ void DelayPlugin::applyToBuffer (const PluginRenderContext& fc) void DelayPlugin::restorePluginStateFromValueTree (const juce::ValueTree& v) { - copyPropertiesToCachedValues (v, feedbackValue, mixValue, lengthMs); + copyPropertiesToCachedValues (v, feedbackValue, mixValue, lengthMsValue); for (auto p : getAutomatableParameters()) p->updateFromAttachedValue(); diff --git a/modules/tracktion_engine/plugins/effects/tracktion_Delay.h b/modules/tracktion_engine/plugins/effects/tracktion_Delay.h index 67d8eeef8e9..470b3e67732 100644 --- a/modules/tracktion_engine/plugins/effects/tracktion_Delay.h +++ b/modules/tracktion_engine/plugins/effects/tracktion_Delay.h @@ -74,9 +74,9 @@ class DelayPlugin : public Plugin void restorePluginStateFromValueTree (const juce::ValueTree&) override; juce::CachedValue feedbackValue, mixValue; - juce::CachedValue lengthMs; + juce::CachedValue lengthMsValue; - AutomatableParameter::Ptr feedbackDb, mixProportion; + AutomatableParameter::Ptr feedbackDb, mixProportion, lengthMs; static float getMinDelayFeedbackDb() noexcept { return -30.0f; }