Skip to content
Open
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
41 changes: 41 additions & 0 deletions modules/tracktion_engine/plugins/effects/tracktion_Chorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions modules/tracktion_engine/plugins/effects/tracktion_Chorus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> depthMs, width, mixProportion, speedHz;

AutomatableParameter::Ptr depthParam, speedParam,
widthParam, mixParam;

private:
//==============================================================================
DelayBufferBase delayBuffer;
Expand Down
14 changes: 10 additions & 4 deletions modules/tracktion_engine/plugins/effects/tracktion_Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions modules/tracktion_engine/plugins/effects/tracktion_Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class DelayPlugin : public Plugin
void restorePluginStateFromValueTree (const juce::ValueTree&) override;

juce::CachedValue<float> feedbackValue, mixValue;
juce::CachedValue<int> lengthMs;
juce::CachedValue<int> lengthMsValue;

AutomatableParameter::Ptr feedbackDb, mixProportion;
AutomatableParameter::Ptr feedbackDb, mixProportion, lengthMs;

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

Expand Down