Skip to content

Commit

Permalink
Templated Constructor Added To BaseProcessor For Handling Input and O…
Browse files Browse the repository at this point in the history
…utput Port Types
  • Loading branch information
RachelMaryamLocke committed Jun 22, 2023
1 parent 86213d4 commit 60e10a1
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/gui/pedalboard/editors/Port.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Port.h"
#include "../src/processors/BaseProcessor.h"
#include "../cables/CableDrawingHelpers.h"

Port::Port (const Colour& processorColour, const PortType type) : Component ("Port"),
Expand Down
8 changes: 2 additions & 6 deletions src/gui/pedalboard/editors/Port.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

#include <pch.h>

enum class PortType
{
audio = 0,
modulation,
};
enum class PortType;

class Port : public Component
{
Expand All @@ -25,7 +21,7 @@ class Port : public Component
bool isConnected = false;

const Colour& procColour;
const PortType portType = PortType::audio;
const PortType portType;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Port)
};
13 changes: 7 additions & 6 deletions src/processors/BaseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

BaseProcessor::BaseProcessor (const String& name,
ParamLayout params,
UndoManager* um,
int nInputs,
int nOutputs) : JuceProcWrapper (name),
vts (*this, um, Identifier ("Parameters"), std::move (params)),
numInputs (nInputs),
numOutputs (nOutputs)
UndoManager* um) : BaseProcessor (name,
params,
BasicInputPort{},
BasicOutputPort{},
um,
[] (auto) { return PortType::audio; },
[] (auto) { return PortType::audio; })
{
onOffParam = vts.getRawParameterValue ("on_off");

Expand Down
79 changes: 76 additions & 3 deletions src/processors/BaseProcessor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "JuceProcWrapper.h"
#include "netlist_helpers/CircuitQuantity.h"

enum ProcessorType
{
Expand All @@ -11,6 +12,12 @@ enum ProcessorType
Other,
};

enum class PortType
{
audio = 0,
modulation
};

struct ProcessorUIOptions
{
Colour backgroundColour = Colours::red;
Expand Down Expand Up @@ -40,16 +47,70 @@ struct ConnectionInfo
int endPort;
};

namespace base_processor_detail
{
using PortTypesVector = chowdsp::SmallVector<PortType, 4>;

template <typename Port, typename PortMapper>
static PortTypesVector initialisePortTypes (PortMapper mapper)
{
auto portTypes = PortTypesVector (magic_enum::enum_count<Port>(), PortType::audio);
magic_enum::enum_for_each<Port> ([&portTypes, &mapper] (auto portType)
{
const auto portIndex = *magic_enum::enum_index ((Port) portType);
portTypes[portIndex] = mapper ((Port) portType); });
return portTypes;
}
}

class BaseProcessor : private JuceProcWrapper
{
public:
using Ptr = std::unique_ptr<BaseProcessor>;

template <typename Port>
static constexpr auto defaultPortMapper (Port) { return PortType::audio; }

template <typename InputPort,
typename OutputPort,
typename InputPortMapper = decltype (&defaultPortMapper<InputPort>),
typename OutputPortMapper = decltype (&defaultPortMapper<OutputPort>)>
BaseProcessor (const String& name,
ParamLayout params,
ParamLayout& params,
InputPort,
OutputPort,
UndoManager* um = nullptr,
int nInputs = 1,
int nOutputs = 1);
InputPortMapper inputPortMapper = &defaultPortMapper<InputPort>,
OutputPortMapper outputPortMapper = &defaultPortMapper<OutputPort>) : JuceProcWrapper (name),
vts (*this, um, Identifier ("Parameters"), std::move (params)),
numInputs(magic_enum::enum_count<InputPort>()),
numOutputs(magic_enum::enum_count<OutputPort>()),
inputPortTypes (base_processor_detail::initialisePortTypes<InputPort> (inputPortMapper)),
outputPortTypes (base_processor_detail::initialisePortTypes<OutputPort> (outputPortMapper))
{

std::cout << "Creating processor: " << name << std::endl;
std::cout << "With input ports: " << std::endl;
for (size_t i = 0; i < inputPortTypes.size(); ++i)
std::cout << " " << magic_enum::enum_name ((InputPort) i) << " (" << magic_enum::enum_name (inputPortTypes[i]) << ")" << std::endl;
std::cout << "With output ports: " << std::endl;
for (size_t i = 0; i < outputPortTypes.size(); ++i)
std::cout << " " << magic_enum::enum_name ((OutputPort) i) << " (" << magic_enum::enum_name (outputPortTypes[i]) << ")" << std::endl;

onOffParam = vts.getRawParameterValue ("on_off");

outputBuffers.resize (jmax (1, numOutputs));
outputBuffers.fill (nullptr);
outputConnections.resize (numOutputs);

inputBuffers.resize (numInputs);
inputsConnected.resize (0);
portMagnitudes.resize (numInputs);
}

BaseProcessor (const String& name,
ParamLayout params,
UndoManager* um = nullptr);
~BaseProcessor();

// metadata
Expand Down Expand Up @@ -186,6 +247,16 @@ class BaseProcessor : private JuceProcWrapper
*/
auto& getSharedConvolutionMessageQueue() { return convolutionMessageQueue.get(); }

enum class BasicInputPort
{
AudioInput,
};

enum class BasicOutputPort
{
AudioOutput,
};

private:
std::atomic<float>* onOffParam = nullptr;

Expand Down Expand Up @@ -221,6 +292,8 @@ class BaseProcessor : private JuceProcWrapper

juce::Array<int> inputModulationPorts {};
juce::Array<int> outputModulationPorts {};
base_processor_detail::PortTypesVector inputPortTypes;
base_processor_detail::PortTypesVector outputPortTypes;

std::unordered_map<int, std::vector<String>> paramsToDisableWhenInputConnected {};

Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/Chorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const String delayTypeTag = "delay_type";

Chorus::Chorus (UndoManager* um) : BaseProcessor ("Chorus",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (rateParam, vts, "rate");
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/Flanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const String delayTypeTag = "delay_type";

Flanger::Flanger (UndoManager* um) : BaseProcessor ("Flanger",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (rateParam, vts, "rate");
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/Panner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const String stereoModeTag = "stereo_mode";

Panner::Panner (UndoManager* um) : BaseProcessor ("Panner",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (mainPan, vts, mainPanTag);
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/Rotary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const String stereoTag = "stereo";

Rotary::Rotary (UndoManager* um) : BaseProcessor ("Rotary",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
chowdsp::ParamUtils::loadParameterPointer (rateHzParam, vts, "rate");
chowdsp::ParamUtils::loadParameterPointer (stereoParam, vts, stereoTag);
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/Tremolo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const String v1WaveTag = "v1_wave";

Tremolo::Tremolo (UndoManager* um) : BaseProcessor ("Tremolo",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (rateParam, vts, "rate");
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/phaser/Phaser4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const String stereoTag = "stereo";

Phaser4::Phaser4 (UndoManager* um) : BaseProcessor ("Phaser4",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (rateHzParam, vts, rateTag);
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/phaser/Phaser8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const String modulationTag = "modulation";

Phaser8::Phaser8 (UndoManager* um) : BaseProcessor ("Phaser8",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (rateHzParam, vts, rateTag);
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/scanner_vibrato/ScannerVibrato.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ float ramp_down (float x, int off)

ScannerVibrato::ScannerVibrato (UndoManager* um) : BaseProcessor ("Scanner Vibrato",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
loadParameterPointer (rateHzParam, vts, rateTag);
Expand Down
4 changes: 1 addition & 3 deletions src/processors/modulation/uni_vibe/UniVibe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const String mixTag = "mix";

UniVibe::UniVibe (UndoManager* um) : BaseProcessor ("Solo-Vibe",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
magic_enum::enum_count<OutputPort>())
um)
{
using namespace ParameterHelpers;
speedParamSmooth.setParameterHandle (getParameterPointer<chowdsp::FloatParameter*> (vts, speedTag));
Expand Down
2 changes: 1 addition & 1 deletion src/processors/utility/FreqBandSplitter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "FreqBandSplitter.h"
#include "../ParameterHelpers.h"

FreqBandSplitter::FreqBandSplitter (UndoManager* um) : BaseProcessor ("Frequency Splitter", createParameterLayout(), um, 1, numOuts)
FreqBandSplitter::FreqBandSplitter (UndoManager* um) : BaseProcessor ("Frequency Splitter", createParameterLayout(), um)
{
using namespace ParameterHelpers;
loadParameterPointer (crossLowParam, vts, "cross_low");
Expand Down
2 changes: 1 addition & 1 deletion src/processors/utility/InputProcessor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "InputProcessor.h"
#include "../ParameterHelpers.h"

InputProcessor::InputProcessor (UndoManager* um) : BaseProcessor ("Input", createParameterLayout(), um, 0, 1)
InputProcessor::InputProcessor (UndoManager* um) : BaseProcessor ("Input", createParameterLayout(), um)
{
uiOptions.backgroundColour = Colours::orange;
}
Expand Down
4 changes: 1 addition & 3 deletions src/processors/utility/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

Mixer::Mixer (UndoManager* um) : BaseProcessor ("Mixer",
createParameterLayout(),
um,
numIns,
1)
um)
{
for (int i = 0; i < numIns; ++i)
chowdsp::ParamUtils::loadParameterPointer (gainDBParams[i], vts, "gain" + String (i));
Expand Down
2 changes: 1 addition & 1 deletion src/processors/utility/Oscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace
constexpr int scopeFps = 30;
}

Oscilloscope::Oscilloscope (UndoManager* um) : BaseProcessor ("Oscilloscope", createParameterLayout(), um, 1, 0)
Oscilloscope::Oscilloscope (UndoManager* um) : BaseProcessor ("Oscilloscope", createParameterLayout(), um)
{
uiOptions.backgroundColour = Colours::silver.brighter (0.2f);
uiOptions.powerColour = Colours::red;
Expand Down
2 changes: 1 addition & 1 deletion src/processors/utility/OutputProcessor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "OutputProcessor.h"
#include "../ParameterHelpers.h"

OutputProcessor::OutputProcessor (UndoManager* um) : BaseProcessor ("Output", createParameterLayout(), um, 1, 0)
OutputProcessor::OutputProcessor (UndoManager* um) : BaseProcessor ("Output", createParameterLayout(), um)
{
uiOptions.backgroundColour = Colours::lightskyblue;
}
Expand Down
4 changes: 1 addition & 3 deletions src/processors/utility/StereoMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

StereoMerger::StereoMerger (UndoManager* um) : BaseProcessor ("Stereo Merger",
createParameterLayout(),
um,
magic_enum::enum_count<InputPort>(),
1)
um)
{
modeParam = vts.getRawParameterValue ("mode");

Expand Down
2 changes: 1 addition & 1 deletion src/processors/utility/StereoSplitter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "StereoSplitter.h"
#include "../ParameterHelpers.h"

StereoSplitter::StereoSplitter (UndoManager* um) : BaseProcessor ("Stereo Splitter", createParameterLayout(), um, 1, numOuts)
StereoSplitter::StereoSplitter (UndoManager* um) : BaseProcessor ("Stereo Splitter", createParameterLayout(), um)
{
modeParam = vts.getRawParameterValue ("mode");

Expand Down
2 changes: 1 addition & 1 deletion src/processors/utility/Tuner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace
constexpr int tunerRefreshHz = 24;
}

Tuner::Tuner (UndoManager* um) : BaseProcessor ("Tuner", createParameterLayout(), um, 1, 0)
Tuner::Tuner (UndoManager* um) : BaseProcessor ("Tuner", createParameterLayout(), um)
{
uiOptions.backgroundColour = Colours::silver.brighter (0.2f);
uiOptions.powerColour = Colours::red;
Expand Down

0 comments on commit 60e10a1

Please sign in to comment.