kopia lustrzana https://github.com/jameshball/osci-render
Convert all parameters to raw pointers as JUCE manages them
rodzic
28f8626dbc
commit
230707823d
|
@ -38,46 +38,47 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
|
||||||
|
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<BitCrushEffect>(),
|
std::make_shared<BitCrushEffect>(),
|
||||||
std::vector<EffectParameter>(1, { "Bit Crush", "bitCrush", 0.0, 0.0, 1.0 })
|
new EffectParameter("Bit Crush", "bitCrush", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<BulgeEffect>(),
|
std::make_shared<BulgeEffect>(),
|
||||||
std::vector<EffectParameter>(1, { "Bulge", "bulge", 0.0, 0.0, 1.0 })
|
new EffectParameter("Bulge", "bulge", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<RotateEffect>(),
|
std::make_shared<RotateEffect>(),
|
||||||
std::vector<EffectParameter>(1, { "2D Rotate Speed", "rotateSpeed", 0.0, 0.0, 1.0 })
|
new EffectParameter("2D Rotate Speed", "rotateSpeed", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<VectorCancellingEffect>(),
|
std::make_shared<VectorCancellingEffect>(),
|
||||||
std::vector<EffectParameter>(1, { "Vector cancelling", "vectorCancelling", 0.0, 0.0, 1.0 })
|
new EffectParameter("Vector cancelling", "vectorCancelling", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<DistortEffect>(true),
|
std::make_shared<DistortEffect>(true),
|
||||||
std::vector<EffectParameter>(1, { "Vertical shift", "verticalDistort", 0.0, 0.0, 1.0 })
|
new EffectParameter("Vertical shift", "verticalDistort", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<DistortEffect>(false),
|
std::make_shared<DistortEffect>(false),
|
||||||
std::vector<EffectParameter>(1, { "Horizontal shift", "horizontalDistort", 0.0, 0.0, 1.0 })
|
new EffectParameter("Horizontal shift", "horizontalDistort", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<SmoothEffect>(),
|
std::make_shared<SmoothEffect>(),
|
||||||
std::vector<EffectParameter>(1, { "Smoothing", "smoothing", 0.0, 0.0, 1.0 })
|
new EffectParameter("Smoothing", "smoothing", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
wobbleEffect,
|
wobbleEffect,
|
||||||
std::vector<EffectParameter>(1, { "Wobble", "wobble", 0.0, 0.0, 1.0 })
|
new EffectParameter("Wobble", "wobble", 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
delayEffect,
|
delayEffect,
|
||||||
std::vector<EffectParameter>{{ "Delay Decay", "delayDecay", 0.0, 0.0, 1.0 }, { "Delay Length", "delayEchoLength", 0.5, 0.0, 1.0 }}
|
std::vector<EffectParameter*>{new EffectParameter("Delay Decay", "delayDecay", 0.0, 0.0, 1.0), new EffectParameter("Delay Length", "delayEchoLength", 0.5, 0.0, 1.0)}
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(traceMax);
|
toggleableEffects.push_back(traceMax);
|
||||||
toggleableEffects.push_back(traceMin);
|
toggleableEffects.push_back(traceMin);
|
||||||
|
|
||||||
for (auto& effect : toggleableEffects) {
|
for (auto& effect : toggleableEffects) {
|
||||||
addParameter(&effect->enabled);
|
effect->markEnableable(false);
|
||||||
effect->enabled.setValueNotifyingHost(false);
|
addParameter(effect->enabled);
|
||||||
|
effect->enabled->setValueNotifyingHost(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
permanentEffects.push_back(frequencyEffect);
|
permanentEffects.push_back(frequencyEffect);
|
||||||
|
@ -98,14 +99,24 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
|
||||||
effects.insert(effects.end(), luaEffects.begin(), luaEffects.end());
|
effects.insert(effects.end(), luaEffects.begin(), luaEffects.end());
|
||||||
|
|
||||||
for (auto effect : effects) {
|
for (auto effect : effects) {
|
||||||
for (auto& parameter : effect->parameters) {
|
for (auto parameter : effect->parameters) {
|
||||||
addParameter(¶meter);
|
addParameter(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hiddenEffects.push_back(currentRotateX);
|
||||||
|
hiddenEffects.push_back(currentRotateY);
|
||||||
|
hiddenEffects.push_back(currentRotateZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
OscirenderAudioProcessor::~OscirenderAudioProcessor() {
|
||||||
|
for (auto effect : hiddenEffects) {
|
||||||
|
for (auto parameter : effect->parameters) {
|
||||||
|
delete parameter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OscirenderAudioProcessor::~OscirenderAudioProcessor() {}
|
|
||||||
|
|
||||||
const juce::String OscirenderAudioProcessor::getName() const {
|
const juce::String OscirenderAudioProcessor::getName() const {
|
||||||
return JucePlugin_Name;
|
return JucePlugin_Name;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +216,7 @@ void OscirenderAudioProcessor::addLuaSlider() {
|
||||||
|
|
||||||
luaEffects.push_back(std::make_shared<Effect>(
|
luaEffects.push_back(std::make_shared<Effect>(
|
||||||
std::make_shared<LuaEffect>(sliderName, *this),
|
std::make_shared<LuaEffect>(sliderName, *this),
|
||||||
std::vector<EffectParameter>(1, { "Lua " + sliderName, "lua" + sliderName, 0.0, 0.0, 1.0, 0.001, false })
|
new EffectParameter("Lua " + sliderName, "lua" + sliderName, 0.0, 0.0, 1.0, 0.001, false)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +452,7 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
|
||||||
{
|
{
|
||||||
juce::SpinLock::ScopedLockType lock(effectsLock);
|
juce::SpinLock::ScopedLockType lock(effectsLock);
|
||||||
for (auto& effect : toggleableEffects) {
|
for (auto& effect : toggleableEffects) {
|
||||||
if (effect->enabled.getValue()) {
|
if (effect->enabled->getValue()) {
|
||||||
channels = effect->apply(sample, channels);
|
channels = effect->apply(sample, channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,21 +78,21 @@ public:
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
frequency = values[0];
|
frequency = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Frequency", "frequency", 440.0, 0.0, 12000.0, 0.1 })
|
}, new EffectParameter("Frequency", "frequency", 440.0, 0.0, 12000.0, 0.1)
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> volumeEffect = std::make_shared<Effect>(
|
std::shared_ptr<Effect> volumeEffect = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
volume = values[0];
|
volume = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Volume", "volume", 1.0, 0.0, 3.0 })
|
}, new EffectParameter("Volume", "volume", 1.0, 0.0, 3.0)
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> thresholdEffect = std::make_shared<Effect>(
|
std::shared_ptr<Effect> thresholdEffect = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
threshold = values[0];
|
threshold = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Threshold", "threshold", 1.0, 0.0, 1.0 })
|
}, new EffectParameter("Threshold", "threshold", 1.0, 0.0, 1.0)
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> focalLength = std::make_shared<Effect>(
|
std::shared_ptr<Effect> focalLength = std::make_shared<Effect>(
|
||||||
|
@ -103,7 +103,7 @@ public:
|
||||||
camera->setFocalLength(values[0]);
|
camera->setFocalLength(values[0]);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Focal length", "focalLength", 1.0, 0.0, 2.0 })
|
}, new EffectParameter("Focal length", "focalLength", 1.0, 0.0, 2.0)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateX = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateX = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -113,7 +113,7 @@ public:
|
||||||
obj->setBaseRotationX(values[0] * std::numbers::pi);
|
obj->setBaseRotationX(values[0] * std::numbers::pi);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Rotate x", "rotateX", 1.0, -1.0, 1.0 })
|
}, new EffectParameter("Rotate x", "rotateX", 1.0, -1.0, 1.0)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateY = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateY = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -123,7 +123,7 @@ public:
|
||||||
obj->setBaseRotationY(values[0] * std::numbers::pi);
|
obj->setBaseRotationY(values[0] * std::numbers::pi);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Rotate y", "rotateY", 1.0, -1.0, 1.0 })
|
}, new EffectParameter("Rotate y", "rotateY", 1.0, -1.0, 1.0)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateZ = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateZ = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -133,7 +133,7 @@ public:
|
||||||
obj->setBaseRotationZ(values[0] * std::numbers::pi);
|
obj->setBaseRotationZ(values[0] * std::numbers::pi);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Rotate z", "rotateZ", 0.0, -1.0, 1.0 })
|
}, new EffectParameter("Rotate z", "rotateZ", 0.0, -1.0, 1.0)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> currentRotateX = std::make_shared<Effect>(
|
std::shared_ptr<Effect> currentRotateX = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -143,7 +143,7 @@ public:
|
||||||
obj->setCurrentRotationX(values[0] * std::numbers::pi);
|
obj->setCurrentRotationX(values[0] * std::numbers::pi);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Current Rotate x", "currentRotateX", 0.0, 0.0, 1.0, 0.001, false })
|
}, new EffectParameter("Current Rotate x", "currentRotateX", 0.0, 0.0, 1.0, 0.001, false)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> currentRotateY = std::make_shared<Effect>(
|
std::shared_ptr<Effect> currentRotateY = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -153,7 +153,7 @@ public:
|
||||||
obj->setCurrentRotationY(values[0] * std::numbers::pi);
|
obj->setCurrentRotationY(values[0] * std::numbers::pi);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Current Rotate y", "currentRotateY", 0.0, 0.0, 1.0, 0.001, false })
|
}, new EffectParameter("Current Rotate y", "currentRotateY", 0.0, 0.0, 1.0, 0.001, false)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> currentRotateZ = std::make_shared<Effect>(
|
std::shared_ptr<Effect> currentRotateZ = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -163,7 +163,7 @@ public:
|
||||||
obj->setCurrentRotationZ(values[0] * std::numbers::pi);
|
obj->setCurrentRotationZ(values[0] * std::numbers::pi);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Current Rotate z", "currentRotateZ", 0.0, 0.0, 1.0, 0.001, false })
|
}, new EffectParameter("Current Rotate z", "currentRotateZ", 0.0, 0.0, 1.0, 0.001, false)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateSpeed = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateSpeed = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
|
@ -173,7 +173,7 @@ public:
|
||||||
obj->setRotationSpeed(values[0]);
|
obj->setRotationSpeed(values[0]);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Rotate speed", "rotateSpeed", 0.0, -1.0, 1.0 })
|
}, new EffectParameter("Rotate speed", "rotateSpeed", 0.0, -1.0, 1.0)
|
||||||
);
|
);
|
||||||
std::atomic<bool> fixedRotateX = false;
|
std::atomic<bool> fixedRotateX = false;
|
||||||
std::atomic<bool> fixedRotateY = false;
|
std::atomic<bool> fixedRotateY = false;
|
||||||
|
@ -227,20 +227,23 @@ private:
|
||||||
bool invalidateFrameBuffer = false;
|
bool invalidateFrameBuffer = false;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Effect>> permanentEffects;
|
std::vector<std::shared_ptr<Effect>> permanentEffects;
|
||||||
|
// any effects that are not added as a plugin parameter must be deleted manually
|
||||||
|
// as JUCE will not delete them upon destruction of the AudioProcessor
|
||||||
|
std::vector<std::shared_ptr<Effect>> hiddenEffects;
|
||||||
|
|
||||||
std::shared_ptr<Effect> traceMax = std::make_shared<Effect>(
|
std::shared_ptr<Effect> traceMax = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
traceMaxValue = values[0];
|
traceMaxValue = values[0];
|
||||||
traceMaxEnabled = true;
|
traceMaxEnabled = true;
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Trace max", "traceMax", 1.0, 0.0, 1.0 })
|
}, new EffectParameter("Trace max", "traceMax", 1.0, 0.0, 1.0)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> traceMin = std::make_shared<Effect>(
|
std::shared_ptr<Effect> traceMin = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
||||||
traceMinValue = values[0];
|
traceMinValue = values[0];
|
||||||
traceMinEnabled = true;
|
traceMinEnabled = true;
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Trace min", "traceMin", 0.0, 0.0, 1.0 })
|
}, new EffectParameter("Trace min", "traceMin", 0.0, 0.0, 1.0)
|
||||||
);
|
);
|
||||||
const double MIN_TRACE = 0.005;
|
const double MIN_TRACE = 0.005;
|
||||||
double traceMaxValue = traceMax->getValue();
|
double traceMaxValue = traceMax->getValue();
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
#include "Effect.h"
|
#include "Effect.h"
|
||||||
|
|
||||||
Effect::Effect(std::shared_ptr<EffectApplication> effectApplication, std::vector<EffectParameter> parameters) : effectApplication(effectApplication), parameters(parameters), enabled(parameters[0].name + " Enabled", parameters[0].id + "Enabled", true) {
|
Effect::Effect(std::shared_ptr<EffectApplication> effectApplication, std::vector<EffectParameter*> parameters) : effectApplication(effectApplication), parameters(parameters), enabled(nullptr) {
|
||||||
smoothValues = std::vector<double>(parameters.size(), 0.0);
|
smoothValues = std::vector<double>(parameters.size(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Effect::Effect(std::shared_ptr<EffectApplication> effectApplication, EffectParameter parameter) : Effect(effectApplication, std::vector<EffectParameter>{parameter}) {}
|
Effect::Effect(std::shared_ptr<EffectApplication> effectApplication, EffectParameter* parameter) : Effect(effectApplication, std::vector<EffectParameter*>{parameter}) {}
|
||||||
|
|
||||||
Effect::Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, std::vector<EffectParameter> parameters) : application(application), parameters(parameters), enabled(parameters[0].name + " Enabled", parameters[0].id + "Enabled", true) {
|
Effect::Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, std::vector<EffectParameter*> parameters) : application(application), parameters(parameters), enabled(nullptr) {
|
||||||
smoothValues = std::vector<double>(parameters.size(), 0.0);
|
smoothValues = std::vector<double>(parameters.size(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Effect::Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, EffectParameter parameter) : Effect(application, std::vector<EffectParameter>{parameter}) {}
|
Effect::Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, EffectParameter* parameter) : Effect(application, std::vector<EffectParameter*>{parameter}) {}
|
||||||
|
|
||||||
Vector2 Effect::apply(int index, Vector2 input) {
|
Vector2 Effect::apply(int index, Vector2 input) {
|
||||||
for (int i = 0; i < parameters.size(); i++) {
|
for (int i = 0; i < parameters.size(); i++) {
|
||||||
double weight = parameters[i].smoothValueChange ? 0.0005 : 1.0;
|
double weight = parameters[i]->smoothValueChange ? 0.0005 : 1.0;
|
||||||
smoothValues[i] = (1.0 - weight) * smoothValues[i] + weight * parameters[i].getValueUnnormalised();
|
smoothValues[i] = (1.0 - weight) * smoothValues[i] + weight * parameters[i]->getValueUnnormalised();
|
||||||
}
|
}
|
||||||
if (application) {
|
if (application) {
|
||||||
return application(index, input, smoothValues, sampleRate);
|
return application(index, input, smoothValues, sampleRate);
|
||||||
|
@ -30,7 +30,7 @@ void Effect::apply() {
|
||||||
}
|
}
|
||||||
|
|
||||||
double Effect::getValue(int index) {
|
double Effect::getValue(int index) {
|
||||||
return parameters[index].getValueUnnormalised();
|
return parameters[index]->getValueUnnormalised();
|
||||||
}
|
}
|
||||||
|
|
||||||
double Effect::getValue() {
|
double Effect::getValue() {
|
||||||
|
@ -38,7 +38,7 @@ double Effect::getValue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::setValue(int index, double value) {
|
void Effect::setValue(int index, double value) {
|
||||||
parameters[index].setUnnormalisedValueNotifyingHost(value);
|
parameters[index]->setUnnormalisedValueNotifyingHost(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::setValue(double value) {
|
void Effect::setValue(double value) {
|
||||||
|
@ -54,21 +54,31 @@ void Effect::setPrecedence(int precedence) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::addListener(int index, juce::AudioProcessorParameter::Listener* listener) {
|
void Effect::addListener(int index, juce::AudioProcessorParameter::Listener* listener) {
|
||||||
juce::SpinLock::ScopedLockType lock(listenerLock);
|
parameters[index]->addListener(listener);
|
||||||
parameters[index].addListener(listener);
|
if (enabled != nullptr) {
|
||||||
enabled.addListener(listener);
|
enabled->addListener(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::removeListener(int index, juce::AudioProcessorParameter::Listener* listener) {
|
void Effect::removeListener(int index, juce::AudioProcessorParameter::Listener* listener) {
|
||||||
juce::SpinLock::ScopedLockType lock(listenerLock);
|
parameters[index]->removeListener(listener);
|
||||||
parameters[index].removeListener(listener);
|
if (enabled != nullptr) {
|
||||||
enabled.removeListener(listener);
|
enabled->removeListener(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Effect::markEnableable(bool enable) {
|
||||||
|
if (enabled != nullptr) {
|
||||||
|
enabled->setValue(enable);
|
||||||
|
} else {
|
||||||
|
enabled = new BooleanParameter(getName() + " Enabled", getId() + "Enabled", enable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
juce::String Effect::getId() {
|
juce::String Effect::getId() {
|
||||||
return parameters[0].id;
|
return parameters[0]->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
juce::String Effect::getName() {
|
juce::String Effect::getName() {
|
||||||
return parameters[0].name;
|
return parameters[0]->name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
class Effect {
|
class Effect {
|
||||||
public:
|
public:
|
||||||
Effect(std::shared_ptr<EffectApplication> effectApplication, std::vector<EffectParameter> parameters);
|
Effect(std::shared_ptr<EffectApplication> effectApplication, std::vector<EffectParameter*> parameters);
|
||||||
Effect(std::shared_ptr<EffectApplication> effectApplication, EffectParameter parameter);
|
Effect(std::shared_ptr<EffectApplication> effectApplication, EffectParameter* parameter);
|
||||||
Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, std::vector<EffectParameter> parameters);
|
Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, std::vector<EffectParameter*> parameters);
|
||||||
Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, EffectParameter parameter);
|
Effect(std::function<Vector2(int, Vector2, const std::vector<double>&, double)> application, EffectParameter* parameter);
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input);
|
Vector2 apply(int index, Vector2 input);
|
||||||
void apply();
|
void apply();
|
||||||
|
@ -23,11 +23,12 @@ public:
|
||||||
void setPrecedence(int precedence);
|
void setPrecedence(int precedence);
|
||||||
void addListener(int index, juce::AudioProcessorParameter::Listener* listener);
|
void addListener(int index, juce::AudioProcessorParameter::Listener* listener);
|
||||||
void removeListener(int index, juce::AudioProcessorParameter::Listener* listener);
|
void removeListener(int index, juce::AudioProcessorParameter::Listener* listener);
|
||||||
|
void markEnableable(bool enabled);
|
||||||
juce::String getId();
|
juce::String getId();
|
||||||
juce::String getName();
|
juce::String getName();
|
||||||
|
|
||||||
std::vector<EffectParameter> parameters;
|
std::vector<EffectParameter*> parameters;
|
||||||
BooleanParameter enabled;
|
BooleanParameter* enabled;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -14,18 +14,6 @@ public:
|
||||||
|
|
||||||
EffectParameter(juce::String name, juce::String id, float value, float min, float max, float step = 0.001, bool smoothValueChange = true) : name(name), id(id), value(value), min(min), max(max), step(step), smoothValueChange(smoothValueChange) {}
|
EffectParameter(juce::String name, juce::String id, float value, float min, float max, float step = 0.001, bool smoothValueChange = true) : name(name), id(id), value(value), min(min), max(max), step(step), smoothValueChange(smoothValueChange) {}
|
||||||
|
|
||||||
// COPY CONSTRUCTOR SHOULD ONLY BE USED BEFORE
|
|
||||||
// THE OBJECT IS USED IN MULTIPLE THREADS
|
|
||||||
EffectParameter(const EffectParameter& other) {
|
|
||||||
name = other.name;
|
|
||||||
id = other.id;
|
|
||||||
value.store(other.value.load());
|
|
||||||
min.store(other.min.load());
|
|
||||||
max.store(other.max.load());
|
|
||||||
step.store(other.step.load());
|
|
||||||
smoothValueChange.store(other.smoothValueChange.load());
|
|
||||||
}
|
|
||||||
|
|
||||||
juce::String getName(int maximumStringLength) const override {
|
juce::String getName(int maximumStringLength) const override {
|
||||||
return name.substring(0, maximumStringLength);
|
return name.substring(0, maximumStringLength);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,42 +18,43 @@ EffectComponent::EffectComponent(Effect& effect, bool checkboxVisible) : EffectC
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectComponent::setupComponent() {
|
void EffectComponent::setupComponent() {
|
||||||
EffectParameter& parameter = effect.parameters[index];
|
EffectParameter* parameter = effect.parameters[index];
|
||||||
|
|
||||||
slider.setRange(parameter.min, parameter.max, parameter.step);
|
slider.setRange(parameter->min, parameter->max, parameter->step);
|
||||||
slider.setValue(parameter.getValueUnnormalised(), juce::dontSendNotification);
|
slider.setValue(parameter->getValueUnnormalised(), juce::dontSendNotification);
|
||||||
|
|
||||||
slider.setSliderStyle(juce::Slider::LinearHorizontal);
|
slider.setSliderStyle(juce::Slider::LinearHorizontal);
|
||||||
slider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 90, slider.getTextBoxHeight());
|
slider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 90, slider.getTextBoxHeight());
|
||||||
|
|
||||||
selected.setToggleState(effect.enabled.getValue(), juce::dontSendNotification);
|
bool enabled = effect.enabled == nullptr || effect.enabled->getValue();
|
||||||
|
selected.setToggleState(enabled, juce::dontSendNotification);
|
||||||
|
|
||||||
min.textBox.setValue(parameter.min, juce::dontSendNotification);
|
min.textBox.setValue(parameter->min, juce::dontSendNotification);
|
||||||
max.textBox.setValue(parameter.max, juce::dontSendNotification);
|
max.textBox.setValue(parameter->max, juce::dontSendNotification);
|
||||||
|
|
||||||
min.textBox.onValueChange = [this]() {
|
min.textBox.onValueChange = [this]() {
|
||||||
double minValue = min.textBox.getValue();
|
double minValue = min.textBox.getValue();
|
||||||
double maxValue = max.textBox.getValue();
|
double maxValue = max.textBox.getValue();
|
||||||
if (minValue >= maxValue) {
|
if (minValue >= maxValue) {
|
||||||
minValue = maxValue - effect.parameters[index].step;
|
minValue = maxValue - effect.parameters[index]->step;
|
||||||
min.textBox.setValue(minValue, juce::dontSendNotification);
|
min.textBox.setValue(minValue, juce::dontSendNotification);
|
||||||
}
|
}
|
||||||
effect.parameters[index].min = minValue;
|
effect.parameters[index]->min = minValue;
|
||||||
slider.setRange(effect.parameters[index].min, effect.parameters[index].max, effect.parameters[index].step);
|
slider.setRange(effect.parameters[index]->min, effect.parameters[index]->max, effect.parameters[index]->step);
|
||||||
};
|
};
|
||||||
|
|
||||||
max.textBox.onValueChange = [this]() {
|
max.textBox.onValueChange = [this]() {
|
||||||
double minValue = min.textBox.getValue();
|
double minValue = min.textBox.getValue();
|
||||||
double maxValue = max.textBox.getValue();
|
double maxValue = max.textBox.getValue();
|
||||||
if (maxValue <= minValue) {
|
if (maxValue <= minValue) {
|
||||||
maxValue = minValue + effect.parameters[index].step;
|
maxValue = minValue + effect.parameters[index]->step;
|
||||||
max.textBox.setValue(maxValue, juce::dontSendNotification);
|
max.textBox.setValue(maxValue, juce::dontSendNotification);
|
||||||
}
|
}
|
||||||
effect.parameters[index].max = maxValue;
|
effect.parameters[index]->max = maxValue;
|
||||||
slider.setRange(effect.parameters[index].min, effect.parameters[index].max, effect.parameters[index].step);
|
slider.setRange(effect.parameters[index]->min, effect.parameters[index]->max, effect.parameters[index]->step);
|
||||||
};
|
};
|
||||||
|
|
||||||
popupLabel.setText(parameter.name + " Settings", juce::dontSendNotification);
|
popupLabel.setText(parameter->name + " Settings", juce::dontSendNotification);
|
||||||
popupLabel.setJustificationType(juce::Justification::centred);
|
popupLabel.setJustificationType(juce::Justification::centred);
|
||||||
popupLabel.setFont(juce::Font(14.0f, juce::Font::bold));
|
popupLabel.setFont(juce::Font(14.0f, juce::Font::bold));
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ void EffectComponent::resized() {
|
||||||
void EffectComponent::paint(juce::Graphics& g) {
|
void EffectComponent::paint(juce::Graphics& g) {
|
||||||
g.fillAll(juce::Colours::black);
|
g.fillAll(juce::Colours::black);
|
||||||
g.setColour(juce::Colours::white);
|
g.setColour(juce::Colours::white);
|
||||||
g.drawText(effect.parameters[index].name, textBounds, juce::Justification::left);
|
g.drawText(effect.parameters[index]->name, textBounds, juce::Justification::left);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectComponent::mouseDown(const juce::MouseEvent& event) {
|
void EffectComponent::mouseDown(const juce::MouseEvent& event) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ EffectsListComponent::EffectsListComponent(DraggableListBox& lb, AudioEffectList
|
||||||
std::shared_ptr<EffectComponent> effectComponent = std::make_shared<EffectComponent>(*effect, i, i == 0);
|
std::shared_ptr<EffectComponent> effectComponent = std::make_shared<EffectComponent>(*effect, i, i == 0);
|
||||||
// using weak_ptr to avoid circular reference and memory leak
|
// using weak_ptr to avoid circular reference and memory leak
|
||||||
std::weak_ptr<EffectComponent> weakEffectComponent = effectComponent;
|
std::weak_ptr<EffectComponent> weakEffectComponent = effectComponent;
|
||||||
effectComponent->slider.setValue(parameters[i].getValueUnnormalised(), juce::dontSendNotification);
|
effectComponent->slider.setValue(parameters[i]->getValueUnnormalised(), juce::dontSendNotification);
|
||||||
effectComponent->slider.onValueChange = [this, i, weakEffectComponent] {
|
effectComponent->slider.onValueChange = [this, i, weakEffectComponent] {
|
||||||
if (auto effectComponent = weakEffectComponent.lock()) {
|
if (auto effectComponent = weakEffectComponent.lock()) {
|
||||||
this->effect->setValue(i, effectComponent->slider.getValue());
|
this->effect->setValue(i, effectComponent->slider.getValue());
|
||||||
|
|
|
@ -74,9 +74,9 @@ struct AudioEffectListBoxItemData : public DraggableListBoxItemData
|
||||||
|
|
||||||
void setSelected(int itemIndex, bool selected) {
|
void setSelected(int itemIndex, bool selected) {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
data[itemIndex]->enabled.setValueNotifyingHost(true);
|
data[itemIndex]->enabled->setValueNotifyingHost(true);
|
||||||
} else {
|
} else {
|
||||||
data[itemIndex]->enabled.setValueNotifyingHost(false);
|
data[itemIndex]->enabled->setValueNotifyingHost(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ VolumeComponent::VolumeComponent(OscirenderAudioProcessor& p) : audioProcessor(p
|
||||||
volumeSlider.setColour(juce::Slider::ColourIds::backgroundColourId, juce::Colours::transparentWhite);
|
volumeSlider.setColour(juce::Slider::ColourIds::backgroundColourId, juce::Colours::transparentWhite);
|
||||||
volumeSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::transparentWhite);
|
volumeSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::transparentWhite);
|
||||||
volumeSlider.setOpaque(false);
|
volumeSlider.setOpaque(false);
|
||||||
auto& volumeParam = audioProcessor.volumeEffect->parameters[0];
|
auto volumeParam = audioProcessor.volumeEffect->parameters[0];
|
||||||
volumeSlider.setRange(volumeParam.min, volumeParam.max, volumeParam.step);
|
volumeSlider.setRange(volumeParam->min, volumeParam->max, volumeParam->step);
|
||||||
volumeSlider.setValue(volumeParam.getValueUnnormalised());
|
volumeSlider.setValue(volumeParam->getValueUnnormalised());
|
||||||
volumeSlider.setLookAndFeel(&thumbRadiusLookAndFeel);
|
volumeSlider.setLookAndFeel(&thumbRadiusLookAndFeel);
|
||||||
volumeSlider.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::black);
|
volumeSlider.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::black);
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ VolumeComponent::VolumeComponent(OscirenderAudioProcessor& p) : audioProcessor(p
|
||||||
thresholdSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::transparentWhite);
|
thresholdSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::transparentWhite);
|
||||||
thresholdSlider.setOpaque(false);
|
thresholdSlider.setOpaque(false);
|
||||||
auto& thresholdParam = audioProcessor.thresholdEffect->parameters[0];
|
auto& thresholdParam = audioProcessor.thresholdEffect->parameters[0];
|
||||||
thresholdSlider.setRange(thresholdParam.min, thresholdParam.max, thresholdParam.step);
|
thresholdSlider.setRange(thresholdParam->min, thresholdParam->max, thresholdParam->step);
|
||||||
thresholdSlider.setValue(thresholdParam.getValueUnnormalised());
|
thresholdSlider.setValue(thresholdParam->getValueUnnormalised());
|
||||||
thresholdSlider.setLookAndFeel(&thresholdLookAndFeel);
|
thresholdSlider.setLookAndFeel(&thresholdLookAndFeel);
|
||||||
thresholdSlider.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::black);
|
thresholdSlider.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::black);
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue