Skip to content

Commit 4121d7a

Browse files
committed
Plugins: Add Automatable params to Chorus and Delay
1 parent 72f6efe commit 4121d7a

4 files changed

Lines changed: 67 additions & 6 deletions

File tree

modules/tracktion_engine/plugins/effects/tracktion_Chorus.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,60 @@ namespace tracktion { inline namespace engine
1313

1414
ChorusPlugin::ChorusPlugin (PluginCreationInfo info) : Plugin (info)
1515
{
16+
depthParam = addParam ("depth", TRANS("Depth"), { 0.0f, 10.0f },
17+
[] (float value) { return juce::String (value, 1) + " ms"; },
18+
[] (const juce::String& s) { return s.getFloatValue(); });
19+
20+
speedParam = addParam ("speed", TRANS("Speed"), { 0.0f, 10.0f },
21+
[] (float value) { return juce::String (value, 1) + " Hz"; },
22+
[] (const juce::String& s) { return s.getFloatValue(); });
23+
24+
widthParam = addParam ("width", TRANS("Width"), { 0.0f, 1.0f },
25+
[] (float value) { return juce::String ((int)(100.0f * value)) + "%"; },
26+
[] (const juce::String& s) { return s.getFloatValue(); });
27+
28+
mixParam = addParam ("mix", TRANS("Mix"), { 0.0f, 1.0f },
29+
[] (float value) { return juce::String ((int)(100.0f * value)) + "%"; },
30+
[] (const juce::String& s) { return s.getFloatValue(); });
31+
1632
auto um = getUndoManager();
1733

1834
depthMs.referTo (state, IDs::depthMs, um, 3.0f);
1935
speedHz.referTo (state, IDs::speedHz, um, 1.0f);
2036
width.referTo (state, IDs::width, um, 0.5f);
2137
mixProportion.referTo (state, IDs::mixProportion, um, 0.5f);
38+
39+
// Attach parameters to their values
40+
depthParam->attachToCurrentValue (depthMs);
41+
speedParam->attachToCurrentValue (speedHz);
42+
widthParam->attachToCurrentValue (width);
43+
mixParam->attachToCurrentValue (mixProportion);
2244
}
2345

2446
ChorusPlugin::~ChorusPlugin()
2547
{
2648
notifyListenersOfDeletion();
49+
50+
// Detach parameters from their values
51+
depthParam->detachFromCurrentValue();
52+
speedParam->detachFromCurrentValue();
53+
widthParam->detachFromCurrentValue();
54+
mixParam->detachFromCurrentValue();
2755
}
2856

57+
// Add getter/setter implementations
58+
void ChorusPlugin::setDepth (float value) { depthParam->setParameter (juce::jlimit (0.0f, 10.0f, value), juce::sendNotification); }
59+
float ChorusPlugin::getDepth() { return depthParam->getCurrentValue(); }
60+
61+
void ChorusPlugin::setSpeed (float value) { speedParam->setParameter (juce::jlimit (0.0f, 10.0f, value), juce::sendNotification); }
62+
float ChorusPlugin::getSpeed() { return speedParam->getCurrentValue(); }
63+
64+
void ChorusPlugin::setWidth (float value) { widthParam->setParameter (juce::jlimit (0.0f, 1.0f, value), juce::sendNotification); }
65+
float ChorusPlugin::getWidth() { return widthParam->getCurrentValue(); }
66+
67+
void ChorusPlugin::setMix (float value) { mixParam->setParameter (juce::jlimit (0.0f, 1.0f, value), juce::sendNotification); }
68+
float ChorusPlugin::getMix() { return mixParam->getCurrentValue(); }
69+
2970
const char* ChorusPlugin::xmlTypeName = "chorus";
3071

3172
void ChorusPlugin::initialise (const PluginInitialisationInfo& info)

modules/tracktion_engine/plugins/effects/tracktion_Chorus.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,23 @@ class ChorusPlugin : public Plugin
3333

3434
void restorePluginStateFromValueTree (const juce::ValueTree&) override;
3535

36+
void setDepth (float value);
37+
float getDepth();
38+
39+
void setSpeed (float value);
40+
float getSpeed();
41+
42+
void setWidth (float value);
43+
float getWidth();
44+
45+
void setMix (float value);
46+
float getMix();
47+
3648
juce::CachedValue<float> depthMs, width, mixProportion, speedHz;
3749

50+
AutomatableParameter::Ptr depthParam, speedParam,
51+
widthParam, mixParam;
52+
3853
private:
3954
//==============================================================================
4055
DelayBufferBase delayBuffer;

modules/tracktion_engine/plugins/effects/tracktion_Delay.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ DelayPlugin::DelayPlugin (PluginCreationInfo info) : Plugin (info)
2121
[] (float value) { return juce::String (juce::roundToInt (value * 100.0f)) + "% wet"; },
2222
[] (const juce::String& s) { return s.getFloatValue() / 100.0f; });
2323

24+
lengthMs = addParam ("length", TRANS("Length"), { 0.0f, 1000.0f },
25+
[] (float value) { return juce::String (value, 1) + " ms"; },
26+
[] (const juce::String& s) { return s.getFloatValue(); });
27+
2428
auto um = getUndoManager();
2529

2630
feedbackValue.referTo (state, IDs::feedback, um, -6.0f);
2731
mixValue.referTo (state, IDs::mix, um, 0.3f);
28-
lengthMs.referTo (state, IDs::length, um, 150);
32+
lengthMsValue.referTo (state, IDs::length, um, 150);
2933

3034
feedbackDb->attachToCurrentValue (feedbackValue);
3135
mixProportion->attachToCurrentValue (mixValue);
36+
lengthMs->attachToCurrentValue (lengthMsValue);
3237
}
3338

3439
DelayPlugin::~DelayPlugin()
@@ -43,7 +48,7 @@ const char* DelayPlugin::xmlTypeName = "delay";
4348

4449
void DelayPlugin::initialise (const PluginInitialisationInfo& info)
4550
{
46-
const int lengthInSamples = (int) (lengthMs * info.sampleRate / 1000.0);
51+
const int lengthInSamples = (int) (lengthMsValue * info.sampleRate / 1000.0);
4752
delayBuffer.ensureMaxBufferSize (lengthInSamples);
4853
delayBuffer.clearBuffer();
4954
}
@@ -70,7 +75,7 @@ void DelayPlugin::applyToBuffer (const PluginRenderContext& fc)
7075

7176
const AudioFadeCurve::CrossfadeLevels wetDry (mixProportion->getCurrentValue());
7277

73-
const int lengthInSamples = (int) (lengthMs * sampleRate / 1000.0);
78+
const int lengthInSamples = (int) (lengthMsValue * sampleRate / 1000.0);
7479
delayBuffer.ensureMaxBufferSize (lengthInSamples);
7580

7681
const int offset = delayBuffer.bufferPos;
@@ -101,7 +106,7 @@ void DelayPlugin::applyToBuffer (const PluginRenderContext& fc)
101106

102107
void DelayPlugin::restorePluginStateFromValueTree (const juce::ValueTree& v)
103108
{
104-
copyPropertiesToCachedValues (v, feedbackValue, mixValue, lengthMs);
109+
copyPropertiesToCachedValues (v, feedbackValue, mixValue, lengthMsValue);
105110

106111
for (auto p : getAutomatableParameters())
107112
p->updateFromAttachedValue();

modules/tracktion_engine/plugins/effects/tracktion_Delay.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class DelayPlugin : public Plugin
7474
void restorePluginStateFromValueTree (const juce::ValueTree&) override;
7575

7676
juce::CachedValue<float> feedbackValue, mixValue;
77-
juce::CachedValue<int> lengthMs;
77+
juce::CachedValue<int> lengthMsValue;
7878

79-
AutomatableParameter::Ptr feedbackDb, mixProportion;
79+
AutomatableParameter::Ptr feedbackDb, mixProportion, lengthMs;
8080

8181
static float getMinDelayFeedbackDb() noexcept { return -30.0f; }
8282

0 commit comments

Comments
 (0)