diff --git a/src/BYOD.cpp b/src/BYOD.cpp index 9221f8aa..4fc2f403 100644 --- a/src/BYOD.cpp +++ b/src/BYOD.cpp @@ -24,11 +24,10 @@ BYOD::BYOD() : chowdsp::PluginBase (&undoManager), pluginSettings->initialise (settingsFilePath); procs = std::make_unique (procStore, vts, presetManager, paramForwarder, [&] (int l) - { updateSampleLatency (l); }); //make unique + { updateSampleLatency (l); }); paramForwarder = std::make_unique (vts, *procs); presetManager = std::make_unique (procs.get(), vts); stateManager = std::make_unique (vts, *procs, *presetManager); -// playheadHelper = std::make_unique (); #if JUCE_IOS LookAndFeel::setDefaultLookAndFeel (lnfAllocator->getLookAndFeel()); @@ -68,8 +67,7 @@ void BYOD::processBlock (AudioBuffer& 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); diff --git a/src/BYOD.h b/src/BYOD.h index df99c854..074eada4 100644 --- a/src/BYOD.h +++ b/src/BYOD.h @@ -69,8 +69,6 @@ class BYOD : public chowdsp::PluginBase std::unique_ptr openGLHelper = nullptr; - PlayheadHelpers playheadHelper; - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BYOD) }; diff --git a/src/processors/BaseProcessor.cpp b/src/processors/BaseProcessor.cpp index 003b24cf..c06b1bda 100644 --- a/src/processors/BaseProcessor.cpp +++ b/src/processors/BaseProcessor.cpp @@ -115,14 +115,6 @@ void BaseProcessor::processAudioBlock (AudioBuffer& 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)); diff --git a/src/processors/BaseProcessor.h b/src/processors/BaseProcessor.h index b875a853..f2155156 100644 --- a/src/processors/BaseProcessor.h +++ b/src/processors/BaseProcessor.h @@ -1,7 +1,6 @@ #pragma once #include "JuceProcWrapper.h" -#include "processors/PlayheadHelpers.h" enum ProcessorType { @@ -36,6 +35,7 @@ struct ProcessorUIOptions class BaseProcessor; class ProcessorEditor; +struct PlayheadHelpers; namespace netlist { struct CircuitQuantityList; @@ -111,8 +111,6 @@ class BaseProcessor : private JuceProcWrapper void prepareProcessing (double sampleRate, int numSamples); void freeInternalMemory(); void processAudioBlock (AudioBuffer& buffer); - void setPlayheadHelpersReference(PlayheadHelpers& helpers); - PlayheadHelpers& getPlayheadHelpersReference(); // methods for working with port input levels float getInputLevelDB (int portIndex) const noexcept; @@ -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); @@ -305,8 +306,6 @@ class BaseProcessor : private JuceProcWrapper StringArray popupMenuParameterIDs; OwnedArray popupMenuParameterAttachments; - PlayheadHelpers* playheadHelpersReference; - const base_processor_detail::PortTypesVector inputPortTypes; const base_processor_detail::PortTypesVector outputPortTypes; diff --git a/src/processors/PlayheadHelpers.h b/src/processors/PlayheadHelpers.h index 19f4b8f3..69d4dd95 100644 --- a/src/processors/PlayheadHelpers.h +++ b/src/processors/PlayheadHelpers.h @@ -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 bpm; - AudioPlayHead::PositionInfo info; }; - diff --git a/src/processors/chain/ProcessorChain.cpp b/src/processors/chain/ProcessorChain.cpp index 8d24184e..99fc3201 100644 --- a/src/processors/chain/ProcessorChain.cpp +++ b/src/processors/chain/ProcessorChain.cpp @@ -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(); @@ -74,8 +70,6 @@ void ProcessorChain::initializeProcessors() { if (auto* proc = procs[i]) { - if (proc->getName() == "Delay") - proc->setPlayheadHelpersReference(*playheadHelpersReference); proc->prepareProcessing (osSampleRate, osSamplesPerBlock); } } diff --git a/src/processors/chain/ProcessorChain.h b/src/processors/chain/ProcessorChain.h index 363773b7..5ea64753 100644 --- a/src/processors/chain/ProcessorChain.h +++ b/src/processors/chain/ProcessorChain.h @@ -5,6 +5,7 @@ #include "../utility/InputProcessor.h" #include "../utility/OutputProcessor.h" +#include "processors/PlayheadHelpers.h" class ProcessorChainActionHelper; class ProcessorChainPortMagnitudesHelper; @@ -27,7 +28,6 @@ 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; } @@ -35,6 +35,7 @@ class ProcessorChain : private AudioProcessorValueTreeState::Listener auto& getActionHelper() { return *actionHelper; } auto& getStateHelper() { return *stateHelper; } auto& getOversampling() { return ioProcessor.getOversampling(); } + auto& getPlayheadHelper() { return playheadHelper; } chowdsp::Broadcaster processorAddedBroadcaster; chowdsp::Broadcaster processorRemovedBroadcaster; @@ -79,7 +80,7 @@ class ProcessorChain : private AudioProcessorValueTreeState::Listener std::unique_ptr& paramForwardManager; MidiBuffer internalMidiBuffer; - PlayheadHelpers* playheadHelpersReference = nullptr; + PlayheadHelpers playheadHelper; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorChain) }; diff --git a/src/processors/chain/ProcessorChainActions.cpp b/src/processors/chain/ProcessorChainActions.cpp index 28ff340c..f864796d 100644 --- a/src/processors/chain/ProcessorChainActions.cpp +++ b/src/processors/chain/ProcessorChainActions.cpp @@ -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); diff --git a/src/processors/other/Delay.cpp b/src/processors/other/Delay.cpp index 3eb1c6be..d276320e 100644 --- a/src/processors/other/Delay.cpp +++ b/src/processors/other/Delay.cpp @@ -1,6 +1,7 @@ #include "Delay.h" #include "../ParameterHelpers.h" #include "gui/utils/ModulatableSlider.h" +#include "processors/PlayheadHelpers.h" namespace { @@ -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); @@ -242,10 +242,9 @@ void DelayModule::processAudio (AudioBuffer& 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; diff --git a/src/processors/other/Delay.h b/src/processors/other/Delay.h index a170bc0c..9f79f6da 100644 --- a/src/processors/other/Delay.h +++ b/src/processors/other/Delay.h @@ -84,7 +84,6 @@ class DelayModule : public BaseProcessor AudioBuffer stereoBuffer; bool bypassNeedsReset = false; - std::atomic& bpm; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DelayModule) };