Skip to content

Commit

Permalink
Custom Components First and PR Feedback Addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke committed Nov 8, 2023
1 parent 54836bf commit 68a7be3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
2 changes: 0 additions & 2 deletions src/processors/chain/ProcessorChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ void ProcessorChain::initializeProcessors()
for (int i = procs.size() - 1; i >= 0; --i)
{
if (auto* proc = procs[i])
{
proc->prepareProcessing (osSampleRate, osSamplesPerBlock);
}
}
}

Expand Down
45 changes: 23 additions & 22 deletions src/processors/other/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "processors/PlayheadHelpers.h"

using namespace chowdsp::RhythmUtils;
//using namespace chowdsp::RhythmParameter;

namespace
{
Expand All @@ -25,7 +26,7 @@ DelayModule::DelayModule (UndoManager* um) : BaseProcessor ("Delay", createParam
loadParameterPointer (feedbackParam, vts, feedBackTag);
loadParameterPointer (mixParam, vts, mixTag);
loadParameterPointer (delayTimeMsParam, vts, delayTimeMsTag);
delayTimeTempoSyncParam = vts.getRawParameterValue (tempoSyncAmountTag);
loadParameterPointer (delayTimeRhythmParam, vts, tempoSyncAmountTag);
tempoSyncOnOffParam = vts.getRawParameterValue (tempoSyncTag);
delayTypeParam = vts.getRawParameterValue (delayTypeTag);
pingPongParam = vts.getRawParameterValue (pingPongTag);
Expand All @@ -50,11 +51,11 @@ ParamLayout DelayModule::createParameterLayout()
createPercentParameter (params, feedBackTag, "Feedback", 0.0f);
createPercentParameter (params, mixTag, "Mix", 0.5f);

emplace_param<AudioParameterChoice> (params,
tempoSyncAmountTag,
"Tempo Sync Delay",
StringArray { "1/2", "1/4", "1/8", "1/8 dotted" },
0);
emplace_param<chowdsp::RhythmParameter>( params,
tempoSyncAmountTag,
"Delay Rhythm",
std::initializer_list<Rhythm>{HALF, QUARTER, EIGHTH, EIGHTH_DOT},
HALF );
emplace_param<AudioParameterBool> (params, tempoSyncTag, "Tempo Sync", 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 @@ -238,30 +239,30 @@ void DelayModule::processAudio (AudioBuffer<float>& buffer)
{
feedbackSmoothBuffer.process (std::pow (feedbackParam->getCurrentValue() * 0.67f, 0.9f), buffer.getNumSamples());
double tempo = playheadHelpers->bpm.load();
auto tempoSync = (int) *tempoSyncOnOffParam;
if (! tempoSync)
const auto tempoSync = *tempoSyncOnOffParam == 1.0f;
if (!tempoSync)
{
delaySmooth.setTargetValue (fs * *delayTimeMsParam * 0.001f);
}
else
{
float delayInSamples = fs * 200 * 0.001f;
auto noteDivision = (int) *delayTimeTempoSyncParam;
auto noteDivision = (int)*delayTimeRhythmParam;
if (noteDivision == 0)
{
delayInSamples = calculateTempoSyncDelayTime (HALF.getTimeSeconds (tempo), fs);
delayInSamples = calculateTempoSyncDelayTime(HALF.getTimeSeconds(tempo), fs);
}
else if (noteDivision == 1)
{
delayInSamples = calculateTempoSyncDelayTime (QUARTER.getTimeSeconds (tempo), fs);
delayInSamples = calculateTempoSyncDelayTime(QUARTER.getTimeSeconds(tempo), fs);
}
else if (noteDivision == 2)
{
delayInSamples = calculateTempoSyncDelayTime (EIGHTH.getTimeSeconds (tempo), fs);
delayInSamples = calculateTempoSyncDelayTime (EIGHTH.getTimeSeconds(tempo), fs);
}
else if (noteDivision == 3)
{
delayInSamples = calculateTempoSyncDelayTime (EIGHTH_DOT.getTimeSeconds (tempo), fs);
delayInSamples = calculateTempoSyncDelayTime (EIGHTH_DOT.getTimeSeconds(tempo), fs);
}
delaySmooth.setTargetValue (delayInSamples);
}
Expand Down Expand Up @@ -308,7 +309,7 @@ void DelayModule::processAudioBypassed (AudioBuffer<float>& buffer)
outputBuffers.getReference (0) = &buffer;
}

float DelayModule::calculateTempoSyncDelayTime (const double timeInSeconds, const double sampleRate) const
float DelayModule::calculateTempoSyncDelayTime(const double timeInSeconds, const double sampleRate)
{
return static_cast<float> (timeInSeconds * sampleRate);
}
Expand All @@ -323,7 +324,7 @@ bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowd
: vts (vtState),
tempoSyncSelectorAttach (vts, tempoSyncAmountTag, tempoSyncSelector),
delayTimeSlider (*getParameterPointer<chowdsp::FloatParameter*> (vts, delayTimeMsTag), hcp),
delayTimeAttach (vts, delayTimeMsTag, delayTimeSlider),
delayTimeAttach(vts, delayTimeMsTag, delayTimeSlider),
tempoSyncOnOffAttach (
*vts.getParameter (tempoSyncTag),
[this] (float newValue)
Expand All @@ -333,7 +334,7 @@ bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowd
addChildComponent (tempoSyncSelector);
addChildComponent (delayTimeSlider);

const auto* modeChoiceParam = getParameterPointer<AudioParameterChoice*> (vts, tempoSyncAmountTag);
const auto* modeChoiceParam = getParameterPointer<chowdsp::RhythmParameter*> (vts, tempoSyncAmountTag);
tempoSyncSelector.addItemList (modeChoiceParam->choices, 1);
tempoSyncSelector.setSelectedItemIndex (0);
tempoSyncSelector.setScrollWheelEnabled (true);
Expand Down Expand Up @@ -366,7 +367,7 @@ bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowd
void updateControlVisibility (bool tempoSyncOn)
{
tempoSyncSelector.setVisible (tempoSyncOn);
delayTimeSlider.setVisible (! tempoSyncOn);
delayTimeSlider.setVisible (!tempoSyncOn);

setName (vts.getParameter (tempoSyncOn ? tempoSyncAmountTag : delayTimeMsTag)->name);
if (auto* parent = getParentComponent())
Expand All @@ -384,10 +385,10 @@ bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowd
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));
tempoSyncSelector.setBounds (bounds.proportionOfWidth(0.15f),
bounds.proportionOfHeight(0.1f),
bounds.proportionOfWidth(0.7f),
bounds.proportionOfHeight(0.25f));
delayTimeSlider.setBounds (bounds);
}

Expand All @@ -410,5 +411,5 @@ bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowd

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

return false;
return true;
}
16 changes: 2 additions & 14 deletions src/processors/other/Delay.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "../BaseProcessor.h"
#include "processors/PlayheadHelpers.h"

class DelayModule : public BaseProcessor
{
Expand All @@ -16,33 +15,22 @@ class DelayModule : public BaseProcessor
void releaseMemory() override;
void processAudio (AudioBuffer<float>& buffer) override;
void processAudioBypassed (AudioBuffer<float>& buffer) override;
float calculateTempoSyncDelayTime (const double timeInSeconds, const double sampleRate) const;
static float calculateTempoSyncDelayTime(const double timeInSeconds, const double sampleRate);

private:
template <typename DelayType>
void processMonoStereoDelay (AudioBuffer<float>& buffer, DelayType& delayLine);
template <typename DelayType>
void processPingPongDelay (AudioBuffer<float>& buffer, DelayType& delayLine);

struct SimpleAudioPlayHead : juce::AudioPlayHead
{
juce::Optional<AudioPlayHead::PositionInfo> getPosition() const override
{
PositionInfo info;
return info;
}
};

SimpleAudioPlayHead audioPlayHead;

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;
chowdsp::RhythmParameter* delayTimeRhythmParam = nullptr;
std::atomic<float>* tempoSyncOnOffParam = nullptr;

dsp::DryWetMixer<float> dryWetMixer;
Expand Down

0 comments on commit 68a7be3

Please sign in to comment.