Skip to content

Commit

Permalink
Playhead helpers re-organization
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Nov 1, 2023
1 parent 00bd58c commit 08fa4bb
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 45 deletions.
6 changes: 2 additions & 4 deletions src/BYOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ BYOD::BYOD() : chowdsp::PluginBase<BYOD> (&undoManager),

pluginSettings->initialise (settingsFilePath);
procs = std::make_unique<ProcessorChain> (procStore, vts, presetManager, paramForwarder, [&] (int l)
{ updateSampleLatency (l); }); //make unique
{ updateSampleLatency (l); });
paramForwarder = std::make_unique<ParamForwardManager> (vts, *procs);
presetManager = std::make_unique<PresetManager> (procs.get(), vts);
stateManager = std::make_unique<StateManager> (vts, *procs, *presetManager);
// playheadHelper = std::make_unique<PlayheadHelpers> ();

#if JUCE_IOS
LookAndFeel::setDefaultLookAndFeel (lnfAllocator->getLookAndFeel<chowdsp::ChowLNF>());
Expand Down Expand Up @@ -68,8 +67,7 @@ void BYOD::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midi)
AudioProcessLoadMeasurer::ScopedTimer loadTimer { loadMeasurer, buffer.getNumSamples() };

//get playhead
playheadHelper.process(getPlayHead(), buffer.getNumSamples());
procs->setPlayheadHelpersReference(playheadHelper);
procs->getPlayheadHelper().process (getPlayHead(), buffer.getNumSamples());

// push samples into bypass delay
bypassScratchBuffer.makeCopyOf (buffer, true);
Expand Down
2 changes: 0 additions & 2 deletions src/BYOD.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class BYOD : public chowdsp::PluginBase<BYOD>

std::unique_ptr<chowdsp::OpenGLHelper> openGLHelper = nullptr;

PlayheadHelpers playheadHelper;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BYOD)
};

Expand Down
8 changes: 0 additions & 8 deletions src/processors/BaseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ void BaseProcessor::processAudioBlock (AudioBuffer<float>& buffer)
processAudio (buffer);
}

void BaseProcessor::setPlayheadHelpersReference(PlayheadHelpers& helpers) {
playheadHelpersReference = &helpers;
}

PlayheadHelpers& BaseProcessor::getPlayheadHelpersReference() {
return *playheadHelpersReference;
}

float BaseProcessor::getInputLevelDB (int portIndex) const noexcept
{
jassert (isPositiveAndBelow (portIndex, numInputs));
Expand Down
9 changes: 4 additions & 5 deletions src/processors/BaseProcessor.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

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

enum ProcessorType
{
Expand Down Expand Up @@ -36,6 +35,7 @@ struct ProcessorUIOptions

class BaseProcessor;
class ProcessorEditor;
struct PlayheadHelpers;
namespace netlist
{
struct CircuitQuantityList;
Expand Down Expand Up @@ -111,8 +111,6 @@ class BaseProcessor : private JuceProcWrapper
void prepareProcessing (double sampleRate, int numSamples);
void freeInternalMemory();
void processAudioBlock (AudioBuffer<float>& buffer);
void setPlayheadHelpersReference(PlayheadHelpers& helpers);
PlayheadHelpers& getPlayheadHelpersReference();

// methods for working with port input levels
float getInputLevelDB (int portIndex) const noexcept;
Expand Down Expand Up @@ -200,6 +198,9 @@ class BaseProcessor : private JuceProcWrapper
*/
const MidiBuffer* midiBuffer = nullptr;

/** Provided by the processor chain */
const PlayheadHelpers* playheadHelpers = nullptr;

/** Returns a tooltip string for a given port. */
virtual String getTooltipForPort (int portIndex, bool isInput);

Expand Down Expand Up @@ -305,8 +306,6 @@ class BaseProcessor : private JuceProcWrapper
StringArray popupMenuParameterIDs;
OwnedArray<ParameterAttachment> popupMenuParameterAttachments;

PlayheadHelpers* playheadHelpersReference;

const base_processor_detail::PortTypesVector inputPortTypes;
const base_processor_detail::PortTypesVector outputPortTypes;

Expand Down
18 changes: 7 additions & 11 deletions src/processors/PlayheadHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@

struct PlayheadHelpers
{
static void prepare(double sampleRate, int maxBlockSize)
void process (AudioPlayHead* playHead, int numSamples)
{
ignoreUnused(sampleRate, maxBlockSize);
}

void process(AudioPlayHead* playHead, int numSamples)
{
ignoreUnused(numSamples);
ignoreUnused (numSamples);
if (playHead != nullptr)
{
info = *playHead->getPosition();
bpm.store(*info.getBpm());
bpm.store (playHead->getPosition().orFallback (AudioPlayHead::PositionInfo {}).getBpm().orFallback (120.0));
}
else
{
bpm.store (120.0);
}
}

std::atomic<double> bpm;
AudioPlayHead::PositionInfo info;
};

6 changes: 0 additions & 6 deletions src/processors/chain/ProcessorChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ void ProcessorChain::createParameters (Parameters& params)
ChainIOProcessor::createParameters (params);
}

void ProcessorChain::setPlayheadHelpersReference(PlayheadHelpers& helpers) {
playheadHelpersReference = &helpers;
}

void ProcessorChain::initializeProcessors()
{
const auto osFactor = ioProcessor.getOversamplingFactor();
Expand All @@ -74,8 +70,6 @@ void ProcessorChain::initializeProcessors()
{
if (auto* proc = procs[i])
{
if (proc->getName() == "Delay")
proc->setPlayheadHelpersReference(*playheadHelpersReference);
proc->prepareProcessing (osSampleRate, osSamplesPerBlock);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/processors/chain/ProcessorChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "../utility/InputProcessor.h"
#include "../utility/OutputProcessor.h"
#include "processors/PlayheadHelpers.h"

class ProcessorChainActionHelper;
class ProcessorChainPortMagnitudesHelper;
Expand All @@ -27,14 +28,14 @@ class ProcessorChain : private AudioProcessorValueTreeState::Listener
auto& getProcessors() { return procs; }
const auto& getProcessors() const { return procs; }
ProcessorStore& getProcStore() { return procStore; }
void setPlayheadHelpersReference(PlayheadHelpers& helpers);

InputProcessor& getInputProcessor() { return inputProcessor; }
OutputProcessor& getOutputProcessor() { return outputProcessor; }

auto& getActionHelper() { return *actionHelper; }
auto& getStateHelper() { return *stateHelper; }
auto& getOversampling() { return ioProcessor.getOversampling(); }
auto& getPlayheadHelper() { return playheadHelper; }

chowdsp::Broadcaster<void (BaseProcessor*)> processorAddedBroadcaster;
chowdsp::Broadcaster<void (const BaseProcessor*)> processorRemovedBroadcaster;
Expand Down Expand Up @@ -79,7 +80,7 @@ class ProcessorChain : private AudioProcessorValueTreeState::Listener
std::unique_ptr<ParamForwardManager>& paramForwardManager;

MidiBuffer internalMidiBuffer;
PlayheadHelpers* playheadHelpersReference = nullptr;
PlayheadHelpers playheadHelper;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorChain)
};
1 change: 1 addition & 0 deletions src/processors/chain/ProcessorChainActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ProcChainActions
{
Logger::writeToLog (String ("Creating processor: ") + newProc->getName());

newProc->playheadHelpers = &chain.playheadHelper;
auto osFactor = chain.ioProcessor.getOversamplingFactor();
newProc->prepareProcessing (osFactor * chain.mySampleRate, osFactor * chain.mySamplesPerBlock);

Expand Down
11 changes: 5 additions & 6 deletions src/processors/other/Delay.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Delay.h"
#include "../ParameterHelpers.h"
#include "gui/utils/ModulatableSlider.h"
#include "processors/PlayheadHelpers.h"

namespace
{
Expand All @@ -15,8 +16,7 @@ const String tempoSyncTag = "tempo_sync";
const String tempoSyncAmountTag = "delay_time_type";
} // namespace

DelayModule::DelayModule (UndoManager* um) : BaseProcessor ("Delay", createParameterLayout(), um),
bpm(getPlayheadHelpersReference().bpm)
DelayModule::DelayModule (UndoManager* um) : BaseProcessor ("Delay", createParameterLayout(), um)
{
using namespace ParameterHelpers;
loadParameterPointer (freqParam, vts, freqTag);
Expand Down Expand Up @@ -242,10 +242,9 @@ void DelayModule::processAudio (AudioBuffer<float>& buffer)
delaySmooth.setTargetValue (fs * *delayTimeMsParam * 0.001f); //delay time in samples (if tempo-sync change the calculation here?)
}

// PlayheadHelpers& PlayheadHelpersRef = this->getPlayheadHelpersReference();
// std::cout << playheadHelpersReference.bpmDouble << std::endl;
// double tempo = bpm.load();
// std::cout << "My BPM: " << tempo << std::endl;
std::cout << playheadHelpers->bpm << std::endl;
double tempo = playheadHelpers->bpm.load();
std::cout << "My BPM: " << tempo << std::endl;
// int myIntVal = intRef.load();
// std::cout << "My Int: " << myIntVal << std::endl;

Expand Down
1 change: 0 additions & 1 deletion src/processors/other/Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class DelayModule : public BaseProcessor
AudioBuffer<float> stereoBuffer;

bool bypassNeedsReset = false;
std::atomic<double>& bpm;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DelayModule)
};

0 comments on commit 08fa4bb

Please sign in to comment.