kopia lustrzana https://github.com/jameshball/osci-render
Update effect sliders when DAW changes parameter
rodzic
e22897d8d0
commit
28f8626dbc
|
@ -92,7 +92,7 @@ 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) {
|
||||||
threshold = values[0];
|
threshold = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, std::vector<EffectParameter>(1, { "Threshold", "threshold", 3.0, 0.0, 3.0 })
|
}, std::vector<EffectParameter>(1, { "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>(
|
||||||
|
|
|
@ -53,6 +53,18 @@ void Effect::setPrecedence(int precedence) {
|
||||||
this->precedence = precedence;
|
this->precedence = precedence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Effect::addListener(int index, juce::AudioProcessorParameter::Listener* listener) {
|
||||||
|
juce::SpinLock::ScopedLockType lock(listenerLock);
|
||||||
|
parameters[index].addListener(listener);
|
||||||
|
enabled.addListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Effect::removeListener(int index, juce::AudioProcessorParameter::Listener* listener) {
|
||||||
|
juce::SpinLock::ScopedLockType lock(listenerLock);
|
||||||
|
parameters[index].removeListener(listener);
|
||||||
|
enabled.removeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
juce::String Effect::getId() {
|
juce::String Effect::getId() {
|
||||||
return parameters[0].id;
|
return parameters[0].id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ public:
|
||||||
void setValue(double value);
|
void setValue(double value);
|
||||||
int getPrecedence();
|
int getPrecedence();
|
||||||
void setPrecedence(int precedence);
|
void setPrecedence(int precedence);
|
||||||
|
void addListener(int index, juce::AudioProcessorParameter::Listener* listener);
|
||||||
|
void removeListener(int index, juce::AudioProcessorParameter::Listener* listener);
|
||||||
juce::String getId();
|
juce::String getId();
|
||||||
juce::String getName();
|
juce::String getName();
|
||||||
|
|
||||||
|
@ -29,6 +31,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
juce::SpinLock listenerLock;
|
||||||
std::vector<double> smoothValues;
|
std::vector<double> smoothValues;
|
||||||
double frequency = 1.0;
|
double frequency = 1.0;
|
||||||
int precedence = -1;
|
int precedence = -1;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "EffectComponent.h"
|
#include "EffectComponent.h"
|
||||||
|
|
||||||
EffectComponent::EffectComponent(Effect& effect, int index) : effect(effect), index(index) {
|
EffectComponent::EffectComponent(Effect& effect, int index) : effect(effect), index(index) {
|
||||||
componentSetup();
|
addAndMakeVisible(slider);
|
||||||
|
addAndMakeVisible(selected);
|
||||||
|
effect.addListener(index, this);
|
||||||
|
setupComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectComponent::EffectComponent(Effect& effect, int index, bool checkboxVisible) : EffectComponent(effect, index) {
|
EffectComponent::EffectComponent(Effect& effect, int index, bool checkboxVisible) : EffectComponent(effect, index) {
|
||||||
|
@ -14,10 +17,7 @@ EffectComponent::EffectComponent(Effect& effect, bool checkboxVisible) : EffectC
|
||||||
setCheckboxVisible(checkboxVisible);
|
setCheckboxVisible(checkboxVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectComponent::componentSetup() {
|
void EffectComponent::setupComponent() {
|
||||||
addAndMakeVisible(slider);
|
|
||||||
addAndMakeVisible(selected);
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -26,7 +26,7 @@ void EffectComponent::componentSetup() {
|
||||||
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(false, juce::dontSendNotification);
|
selected.setToggleState(effect.enabled.getValue(), 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);
|
||||||
|
@ -59,7 +59,9 @@ void EffectComponent::componentSetup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EffectComponent::~EffectComponent() {}
|
EffectComponent::~EffectComponent() {
|
||||||
|
effect.removeListener(index, this);
|
||||||
|
}
|
||||||
|
|
||||||
void EffectComponent::resized() {
|
void EffectComponent::resized() {
|
||||||
auto sliderRight = getWidth() - 160;
|
auto sliderRight = getWidth() - 160;
|
||||||
|
@ -97,6 +99,16 @@ void EffectComponent::mouseDown(const juce::MouseEvent& event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EffectComponent::parameterValueChanged(int parameterIndex, float newValue) {
|
||||||
|
triggerAsyncUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EffectComponent::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) {}
|
||||||
|
|
||||||
|
void EffectComponent::handleAsyncUpdate() {
|
||||||
|
setupComponent();
|
||||||
|
}
|
||||||
|
|
||||||
void EffectComponent::setComponent(std::shared_ptr<juce::Component> component) {
|
void EffectComponent::setComponent(std::shared_ptr<juce::Component> component) {
|
||||||
this->component = component;
|
this->component = component;
|
||||||
addAndMakeVisible(component.get());
|
addAndMakeVisible(component.get());
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "LabelledTextBox.h"
|
#include "LabelledTextBox.h"
|
||||||
|
|
||||||
|
|
||||||
class EffectComponent : public juce::Component {
|
class EffectComponent : public juce::Component, public juce::AudioProcessorParameter::Listener, juce::AsyncUpdater {
|
||||||
public:
|
public:
|
||||||
EffectComponent(Effect& effect, int index);
|
EffectComponent(Effect& effect, int index);
|
||||||
EffectComponent(Effect& effect, int index, bool checkboxVisible);
|
EffectComponent(Effect& effect, int index, bool checkboxVisible);
|
||||||
|
@ -16,6 +16,9 @@ public:
|
||||||
void resized() override;
|
void resized() override;
|
||||||
void paint(juce::Graphics& g) override;
|
void paint(juce::Graphics& g) override;
|
||||||
void mouseDown(const juce::MouseEvent& event) override;
|
void mouseDown(const juce::MouseEvent& event) override;
|
||||||
|
void parameterValueChanged(int parameterIndex, float newValue) override;
|
||||||
|
void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override;
|
||||||
|
void handleAsyncUpdate() override;
|
||||||
|
|
||||||
void setCheckboxVisible(bool visible);
|
void setCheckboxVisible(bool visible);
|
||||||
void setComponent(std::shared_ptr<juce::Component> component);
|
void setComponent(std::shared_ptr<juce::Component> component);
|
||||||
|
@ -26,7 +29,7 @@ public:
|
||||||
juce::ToggleButton selected;
|
juce::ToggleButton selected;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void componentSetup();
|
void setupComponent();
|
||||||
bool checkboxVisible = true;
|
bool checkboxVisible = true;
|
||||||
juce::Rectangle<int> textBounds;
|
juce::Rectangle<int> textBounds;
|
||||||
std::shared_ptr<juce::Component> component;
|
std::shared_ptr<juce::Component> component;
|
||||||
|
|
|
@ -14,8 +14,6 @@ EffectsListComponent::EffectsListComponent(DraggableListBox& lb, AudioEffectList
|
||||||
};
|
};
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
bool isSelected = effect->enabled.getValue();
|
|
||||||
effectComponent->selected.setToggleState(isSelected, juce::dontSendNotification);
|
|
||||||
effectComponent->selected.onClick = [this, weakEffectComponent] {
|
effectComponent->selected.onClick = [this, weakEffectComponent] {
|
||||||
if (auto effectComponent = weakEffectComponent.lock()) {
|
if (auto effectComponent = weakEffectComponent.lock()) {
|
||||||
auto data = (AudioEffectListBoxItemData&)modelData;
|
auto data = (AudioEffectListBoxItemData&)modelData;
|
||||||
|
|
|
@ -11,8 +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);
|
||||||
volumeSlider.setRange(0, 2, 0.001);
|
auto& volumeParam = audioProcessor.volumeEffect->parameters[0];
|
||||||
volumeSlider.setValue(1);
|
volumeSlider.setRange(volumeParam.min, volumeParam.max, volumeParam.step);
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ -22,8 +23,9 @@ VolumeComponent::VolumeComponent(OscirenderAudioProcessor& p) : audioProcessor(p
|
||||||
thresholdSlider.setColour(juce::Slider::ColourIds::backgroundColourId, juce::Colours::transparentWhite);
|
thresholdSlider.setColour(juce::Slider::ColourIds::backgroundColourId, juce::Colours::transparentWhite);
|
||||||
thresholdSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::transparentWhite);
|
thresholdSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::transparentWhite);
|
||||||
thresholdSlider.setOpaque(false);
|
thresholdSlider.setOpaque(false);
|
||||||
thresholdSlider.setRange(0, 1, 0.001);
|
auto& thresholdParam = audioProcessor.thresholdEffect->parameters[0];
|
||||||
thresholdSlider.setValue(1);
|
thresholdSlider.setRange(thresholdParam.min, thresholdParam.max, thresholdParam.step);
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ -85,6 +87,8 @@ void VolumeComponent::paint(juce::Graphics& g) {
|
||||||
|
|
||||||
void VolumeComponent::timerCallback() {
|
void VolumeComponent::timerCallback() {
|
||||||
repaint();
|
repaint();
|
||||||
|
volumeSlider.setValue(audioProcessor.volumeEffect->getValue(), juce::NotificationType::dontSendNotification);
|
||||||
|
thresholdSlider.setValue(audioProcessor.thresholdEffect->getValue(), juce::NotificationType::dontSendNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeComponent::run() {
|
void VolumeComponent::run() {
|
||||||
|
|
Ładowanie…
Reference in New Issue