Skip to content

Commit

Permalink
Custom Components Added to Delay Module To Allow Tempo Sync Delay Tim…
Browse files Browse the repository at this point in the history
…e Option
  • Loading branch information
RachelMaryamLocke committed Oct 24, 2023
1 parent 4df9f96 commit 04b1131
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 12 deletions.
139 changes: 128 additions & 11 deletions src/processors/other/Delay.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
#include "Delay.h"
#include "../ParameterHelpers.h"
#include "gui/utils/ModulatableSlider.h"

namespace
{
const String delayTypeTag = "delay_type";
const String pingPongTag = "ping_pong";
const String freqTag = "freq";
const String feedBackTag = "feedback";
const String mixTag = "mix";

const String delayTimeMsTag = "time_ms";
const String tempoSyncTag = "tempo_sync";
const String tempoSyncAmountTag = "delay_time_type";
} // namespace

DelayModule::DelayModule (UndoManager* um) : BaseProcessor ("Delay", createParameterLayout(), um)
{
using namespace ParameterHelpers;
loadParameterPointer (delayTimeMsParam, vts, "time_ms");
loadParameterPointer (freqParam, vts, "freq");
loadParameterPointer (feedbackParam, vts, "feedback");
loadParameterPointer (mixParam, vts, "mix");
loadParameterPointer (freqParam, vts, freqTag);
loadParameterPointer (feedbackParam, vts, feedBackTag);
loadParameterPointer (mixParam, vts, mixTag);
loadParameterPointer (delayTimeMsParam, vts, delayTimeMsTag);
delayTimeTempoSyncParam = vts.getRawParameterValue (tempoSyncAmountTag);
tempoSyncOnOffParam = vts.getRawParameterValue (tempoSyncTag);
delayTypeParam = vts.getRawParameterValue (delayTypeTag);
pingPongParam = vts.getRawParameterValue (pingPongTag);

addPopupMenuParameter (delayTypeTag);
addPopupMenuParameter (pingPongTag);
addPopupMenuParameter (tempoSyncTag);

uiOptions.backgroundColour = Colours::cyan.darker (0.1f);
uiOptions.powerColour = Colours::gold;
Expand All @@ -31,12 +42,17 @@ ParamLayout DelayModule::createParameterLayout()
using namespace ParameterHelpers;
auto params = createBaseParams();

createTimeMsParameter (params, "time_ms", "Delay Time", createNormalisableRange (20.0f, 2000.0f, 200.0f), 100.0f);

createFreqParameter (params, "freq", "Cutoff", 500.0f, 10000.0f, 4000.0f, 10000.0f);
createPercentParameter (params, "feedback", "Feedback", 0.0f);
createPercentParameter (params, "mix", "Mix", 0.5f);

createTimeMsParameter (params, delayTimeMsTag, "Delay Time", createNormalisableRange (20.0f, 2000.0f, 200.0f), 100.0f);
createFreqParameter (params, freqTag, "Cutoff", 500.0f, 10000.0f, 4000.0f, 10000.0f);
createPercentParameter (params, feedBackTag, "Feedback", 0.0f);
createPercentParameter (params, mixTag, "Mix", 0.5f);

emplace_param<AudioParameterChoice> (params,
tempoSyncAmountTag,
"Tempo Sync",
StringArray { "1/2", "1/4", "1/8" },
0);
emplace_param<AudioParameterBool> (params, tempoSyncTag, "Tempo Sync Delay", false);
emplace_param<AudioParameterChoice> (params, delayTypeTag, "Delay Type", StringArray { "Clean", "Lo-Fi" }, 0);
emplace_param<AudioParameterBool> (params, pingPongTag, "Ping-Pong", false);

Expand Down Expand Up @@ -218,10 +234,11 @@ void DelayModule::processPingPongDelay (AudioBuffer<float>& buffer, DelayType& d
void DelayModule::processAudio (AudioBuffer<float>& buffer)
{
feedbackSmoothBuffer.process (std::pow (feedbackParam->getCurrentValue() * 0.67f, 0.9f), buffer.getNumSamples());
delaySmooth.setTargetValue (fs * *delayTimeMsParam * 0.001f);
delaySmooth.setTargetValue (fs * *delayTimeMsParam * 0.001f); //delay time in samples (if tempo-sync change the calculation here?)
freqSmooth.setTargetValue (*freqParam);

const auto delayTypeIndex = (int) *delayTypeParam;
const auto tempoSyncAmountIndex = (int) *delayTimeTempoSyncParam;
if (delayTypeIndex != prevDelayTypeIndex)
{
cleanDelayLine.reset();
Expand Down Expand Up @@ -261,3 +278,103 @@ void DelayModule::processAudioBypassed (AudioBuffer<float>& buffer)

outputBuffers.getReference (0) = &buffer;
}

bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowdsp::HostContextProvider& hcp)
{
using namespace chowdsp::ParamUtils;
class DelayTimeModeControl : public Slider
{
public:
DelayTimeModeControl (AudioProcessorValueTreeState& vtState, chowdsp::HostContextProvider& hcp)
: vts (vtState),
tempoSyncSelectorAttach (vts, tempoSyncAmountTag, tempoSyncSelector),
delayTimeSlider (*getParameterPointer<chowdsp::FloatParameter*> (vts, delayTimeMsTag), hcp),
delayTimeAttach(vts, delayTimeMsTag, delayTimeSlider),
tempoSyncOnOffAttach (
*vts.getParameter (tempoSyncTag),
[this] (float newValue)
{ updateControlVisibility (newValue == 1.0f); },
vts.undoManager)
{
addChildComponent (tempoSyncSelector);
addChildComponent (delayTimeSlider);

const auto* modeChoiceParam = getParameterPointer<AudioParameterChoice*> (vts, tempoSyncAmountTag);
tempoSyncSelector.addItemList (modeChoiceParam->choices, 1);
tempoSyncSelector.setSelectedItemIndex (0);
tempoSyncSelector.setScrollWheelEnabled (true);
hcp.registerParameterComponent (tempoSyncSelector, *modeChoiceParam);

hcp.registerParameterComponent (delayTimeSlider, delayTimeSlider.getParameter());

this->setName (tempoSyncAmountTag + "__" + delayTimeMsTag + "__");
}

void colourChanged() override
{
for (auto colourID : { Slider::textBoxOutlineColourId,
Slider::textBoxTextColourId,
Slider::textBoxBackgroundColourId,
Slider::textBoxHighlightColourId,
Slider::thumbColourId })
{
delayTimeSlider.setColour (colourID, findColour (colourID, false));
}

for (auto colourID : { ComboBox::outlineColourId,
ComboBox::textColourId,
ComboBox::arrowColourId })
{
tempoSyncSelector.setColour (colourID, findColour (Slider::textBoxTextColourId, false));
}
}

void updateControlVisibility (bool tempoSyncOn)
{
tempoSyncSelector.setVisible (tempoSyncOn);
delayTimeSlider.setVisible (!tempoSyncOn);

setName (vts.getParameter (tempoSyncOn ? tempoSyncAmountTag : delayTimeMsTag)->name);
if (auto* parent = getParentComponent())
parent->repaint();
}

void visibilityChanged() override
{
updateControlVisibility (vts.getRawParameterValue (tempoSyncTag)->load() == 1.0f);
}

void resized() override
{
delayTimeSlider.setSliderStyle (getSliderStyle());
delayTimeSlider.setTextBoxStyle (getTextBoxPosition(), false, getTextBoxWidth(), getTextBoxHeight());

const auto bounds = getLocalBounds();
tempoSyncSelector.setBounds (bounds.proportionOfWidth(0.15f),
bounds.proportionOfHeight(0.1f),
bounds.proportionOfWidth(0.7f),
bounds.proportionOfHeight(0.25f));
delayTimeSlider.setBounds (bounds);
}

private:
using SliderAttachment = AudioProcessorValueTreeState::SliderAttachment;
using BoxAttachment = AudioProcessorValueTreeState::ComboBoxAttachment;

AudioProcessorValueTreeState& vts;

ComboBox tempoSyncSelector;
BoxAttachment tempoSyncSelectorAttach;

ModulatableSlider delayTimeSlider;
SliderAttachment delayTimeAttach;

ParameterAttachment tempoSyncOnOffAttach;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DelayTimeModeControl)
};

customComps.add (std::make_unique<DelayTimeModeControl> (vts, hcp));

return false;
}
6 changes: 5 additions & 1 deletion src/processors/other/Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DelayModule : public BaseProcessor

ProcessorType getProcessorType() const override { return Other; }
static ParamLayout createParameterLayout();
bool getCustomComponents (OwnedArray<Component>& customComps, chowdsp::HostContextProvider& hcp) override;

void prepare (double sampleRate, int samplesPerBlock) override;
void releaseMemory() override;
Expand All @@ -21,13 +22,16 @@ class DelayModule : public BaseProcessor
template <typename DelayType>
void processPingPongDelay (AudioBuffer<float>& buffer, DelayType& delayLine);

chowdsp::FloatParameter* delayTimeMsParam = nullptr;
chowdsp::FloatParameter* freqParam = nullptr;
chowdsp::FloatParameter* feedbackParam = nullptr;
chowdsp::FloatParameter* mixParam = nullptr;
std::atomic<float>* delayTypeParam = nullptr;
std::atomic<float>* pingPongParam = nullptr;

chowdsp::FloatParameter* delayTimeMsParam = nullptr;
std::atomic<float>* delayTimeTempoSyncParam = nullptr;
std::atomic<float>* tempoSyncOnOffParam = nullptr;

dsp::DryWetMixer<float> dryWetMixer;
dsp::DryWetMixer<float> dryWetMixerMono;

Expand Down

0 comments on commit 04b1131

Please sign in to comment.