Add combobox on all effects for changing LFO and move lua/obj panel underneath other effects

pull/170/head
James Ball 2023-07-20 17:24:34 +01:00
rodzic 26535b7a69
commit e4bc512a66
7 zmienionych plików z 92 dodań i 22 usunięć

Wyświetl plik

@ -74,10 +74,15 @@ void OscirenderAudioProcessorEditor::resized() {
} else { } else {
collapseButton.setBounds(0, 0, 0, 0); collapseButton.setBounds(0, 0, 0, 0);
} }
effects.setBounds(area.removeFromRight(getWidth() / sections)); auto effectsSection = area.removeFromRight(1.2 * getWidth() / sections);
main.setBounds(area.removeFromTop(getHeight() / 2)); main.setBounds(area);
lua.setBounds(area); if (lua.isVisible() || obj.isVisible()) {
obj.setBounds(area); auto altEffectsSection = effectsSection.removeFromBottom(juce::jmin(effectsSection.getHeight() / 2, 300));
lua.setBounds(altEffectsSection);
obj.setBounds(altEffectsSection);
}
effects.setBounds(effectsSection);
} }
void OscirenderAudioProcessorEditor::addCodeEditor(int index) { void OscirenderAudioProcessorEditor::addCodeEditor(int index) {

Wyświetl plik

@ -46,26 +46,26 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
)); ));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
std::make_shared<RotateEffect>(), std::make_shared<RotateEffect>(),
new EffectParameter("2D Rotate Speed", "rotateSpeed", 0.0, 0.0, 1.0) new EffectParameter("2D Rotate", "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>(),
new EffectParameter("Vector Cancelling", "vectorCancelling", 0.0, 0.0, 1.0) new EffectParameter("Vector Cancel", "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>(false), std::make_shared<DistortEffect>(false),
new EffectParameter("Horizontal Distort", "horizontalDistort", 0.0, 0.0, 1.0) new EffectParameter("X Distort", "horizontalDistort", 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),
new EffectParameter("Vertical Distort", "verticalDistort", 0.0, 0.0, 1.0) new EffectParameter("Y Distort", "verticalDistort", 0.0, 0.0, 1.0)
)); ));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(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) {
input.x += values[0]; input.x += values[0];
input.y += values[1]; input.y += values[1];
return input; return input;
}, std::vector<EffectParameter*>{new EffectParameter("Translate x", "translateX", 0.0, -1.0, 1.0), new EffectParameter("Translate y", "translateY", 0.0, -1.0, 1.0)} }, std::vector<EffectParameter*>{new EffectParameter("Translate X", "translateX", 0.0, -1.0, 1.0), new EffectParameter("Translate Y", "translateY", 0.0, -1.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>(),

Wyświetl plik

@ -122,7 +122,7 @@ public:
} }
} }
return input; return input;
}, new EffectParameter("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) {
@ -137,7 +137,7 @@ public:
} }
} }
return input; return input;
}, new EffectParameter("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) {
@ -152,7 +152,7 @@ public:
} }
} }
return input; return input;
}, new EffectParameter("Rotate z", "rotateZ", 0.0, -1.0, 1.0) }, new EffectParameter("Rotate Z", "rotateZ", 0.0, -1.0, 1.0)
); );
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) {
@ -162,7 +162,7 @@ public:
obj->setRotationSpeed(values[0]); obj->setRotationSpeed(values[0]);
} }
return input; return input;
}, new EffectParameter("Rotate speed", "rotateSpeed", 0.0, -1.0, 1.0) }, new EffectParameter("Rotate Speed", "rotateSpeed", 0.0, -1.0, 1.0)
); );
std::shared_ptr<DelayEffect> delayEffect = std::make_shared<DelayEffect>(); std::shared_ptr<DelayEffect> delayEffect = std::make_shared<DelayEffect>();

Wyświetl plik

@ -2,6 +2,17 @@
#include "../shape/Vector2.h" #include "../shape/Vector2.h"
#include <JuceHeader.h> #include <JuceHeader.h>
enum class LfoType : int {
Static = 1,
Sine = 2,
Square = 3,
Seesaw = 4,
Triangle = 5,
Sawtooth = 6,
ReverseSawtooth = 7,
Noise = 8
};
class EffectParameter : public juce::AudioProcessorParameter { class EffectParameter : public juce::AudioProcessorParameter {
public: public:
juce::String name; juce::String name;
@ -11,6 +22,7 @@ public:
std::atomic<float> max = 1.0; std::atomic<float> max = 1.0;
std::atomic<float> step = 0.001; std::atomic<float> step = 0.001;
std::atomic<bool> smoothValueChange = true; std::atomic<bool> smoothValueChange = true;
std::atomic<LfoType> lfoType = LfoType::Static;
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) {}

Wyświetl plik

@ -3,6 +3,19 @@
EffectComponent::EffectComponent(Effect& effect, int index) : effect(effect), index(index) { EffectComponent::EffectComponent(Effect& effect, int index) : effect(effect), index(index) {
addAndMakeVisible(slider); addAndMakeVisible(slider);
addAndMakeVisible(selected); addAndMakeVisible(selected);
addAndMakeVisible(lfo);
lfo.addItem("Static", static_cast<int>(LfoType::Static));
lfo.addItem("Sine", static_cast<int>(LfoType::Sine));
lfo.addItem("Square", static_cast<int>(LfoType::Square));
lfo.addItem("Seesaw", static_cast<int>(LfoType::Seesaw));
lfo.addItem("Triangle", static_cast<int>(LfoType::Triangle));
lfo.addItem("Sawtooth", static_cast<int>(LfoType::Sawtooth));
lfo.addItem("Reverse Sawtooth", static_cast<int>(LfoType::ReverseSawtooth));
lfo.addItem("Noise", static_cast<int>(LfoType::Noise));
lfo.setLookAndFeel(&lfoLookAndFeel);
effect.addListener(index, this); effect.addListener(index, this);
setupComponent(); setupComponent();
} }
@ -24,11 +37,19 @@ void EffectComponent::setupComponent() {
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, 70, slider.getTextBoxHeight());
bool enabled = effect.enabled == nullptr || effect.enabled->getValue(); bool enabled = effect.enabled == nullptr || effect.enabled->getValue();
selected.setToggleState(enabled, juce::dontSendNotification); selected.setToggleState(enabled, juce::dontSendNotification);
lfo.setSelectedId(static_cast<int>(parameter->lfoType.load()), juce::dontSendNotification);
lfo.onChange = [this]() {
if (lfo.getSelectedId() != 0) {
effect.parameters[index]->lfoType = static_cast<LfoType>(lfo.getSelectedId());
}
};
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);
@ -64,22 +85,25 @@ EffectComponent::~EffectComponent() {
effect.removeListener(index, this); effect.removeListener(index, this);
} }
void EffectComponent::resized() { void EffectComponent::resized() {
auto sliderRight = getWidth() - 160;
auto bounds = getLocalBounds(); auto bounds = getLocalBounds();
auto componentBounds = bounds.removeFromRight(25); auto componentBounds = bounds.removeFromRight(25);
if (component != nullptr) { if (component != nullptr) {
component->setBounds(componentBounds); component->setBounds(componentBounds);
} }
slider.setBounds(bounds.removeFromRight(sliderRight)); lfo.setBounds(bounds.removeFromRight(100).reduced(5));
auto checkboxLabel = bounds.removeFromLeft(110);
if (checkboxVisible) { if (checkboxVisible) {
bounds.removeFromLeft(2); checkboxLabel.removeFromLeft(2);
selected.setBounds(bounds.removeFromLeft(25)); selected.setBounds(checkboxLabel.removeFromLeft(25));
} else { } else {
bounds.removeFromLeft(5); checkboxLabel.removeFromLeft(5);
} }
textBounds = bounds; textBounds = checkboxLabel;
slider.setBounds(bounds);
} }
void EffectComponent::paint(juce::Graphics& g) { void EffectComponent::paint(juce::Graphics& g) {

Wyświetl plik

@ -4,6 +4,33 @@
#include "../audio/Effect.h" #include "../audio/Effect.h"
#include "LabelledTextBox.h" #include "LabelledTextBox.h"
class SmallComboBoxArrow : public juce::LookAndFeel_V4 {
void drawComboBox(juce::Graphics& g, int width, int height, bool, int, int, int, int, juce::ComboBox& box) override {
auto cornerSize = box.findParentComponentOfClass<juce::ChoicePropertyComponent>() != nullptr ? 0.0f : 3.0f;
juce::Rectangle<int> boxBounds{0, 0, width, height};
g.setColour(box.findColour(juce::ComboBox::backgroundColourId));
g.fillRoundedRectangle(boxBounds.toFloat(), cornerSize);
g.setColour(box.findColour(juce::ComboBox::outlineColourId));
g.drawRoundedRectangle(boxBounds.toFloat().reduced(0.5f, 0.5f), cornerSize, 1.0f);
juce::Rectangle<int> arrowZone{width - 15, 0, 10, height};
juce::Path path;
path.startNewSubPath((float) arrowZone.getX(), (float) arrowZone.getCentreY() - 3.0f);
path.lineTo((float) arrowZone.getCentreX(), (float) arrowZone.getCentreY() + 4.0f);
path.lineTo((float) arrowZone.getRight(), (float) arrowZone.getCentreY() - 3.0f);
path.closeSubPath();
g.setColour(box.findColour(juce::ComboBox::arrowColourId).withAlpha((box.isEnabled() ? 0.9f : 0.2f)));
g.fillPath(path);
}
void positionComboBoxText(juce::ComboBox& box, juce::Label& label) {
label.setBounds(1, 1, box.getWidth() - 15, box.getHeight() - 2);
label.setFont(getComboBoxFont(box));
}
};
class EffectComponent : public juce::Component, public juce::AudioProcessorParameter::Listener, juce::AsyncUpdater { class EffectComponent : public juce::Component, public juce::AudioProcessorParameter::Listener, juce::AsyncUpdater {
public: public:
@ -27,6 +54,8 @@ public:
Effect& effect; Effect& effect;
int index; int index;
juce::ToggleButton selected; juce::ToggleButton selected;
SmallComboBoxArrow lfoLookAndFeel;
juce::ComboBox lfo;
private: private:
void setupComponent(); void setupComponent();

Wyświetl plik

@ -86,6 +86,6 @@ void VisualiserComponent::paintXY(juce::Graphics& g, juce::Rectangle<float> area
double strength = 10; double strength = 10;
lengthScale = std::log(strength * lengthScale + 1) / std::log(strength + 1); lengthScale = std::log(strength * lengthScale + 1) / std::log(strength + 1);
g.setColour(waveformColour.withAlpha(lengthScale)); g.setColour(waveformColour.withAlpha(lengthScale));
g.drawLine(line, 1.0f); g.drawLine(line, 2.0f);
} }
} }