Add .lua file settings with infinite (non-working) slider support

pull/170/head
James Ball 2023-07-02 21:00:14 +01:00
rodzic e4b5545723
commit 2ec4eaba52
10 zmienionych plików z 127 dodań i 29 usunięć

Wyświetl plik

@ -4,7 +4,7 @@
#include "audio/BitCrushEffect.h" #include "audio/BitCrushEffect.h"
#include "PluginProcessor.h" #include "PluginProcessor.h"
#include "components/DraggableListBox.h" #include "components/DraggableListBox.h"
#include "components/MyListComponent.h" #include "components/EffectsListComponent.h"
class EffectsComponent : public juce::GroupComponent { class EffectsComponent : public juce::GroupComponent {
public: public:
@ -18,8 +18,8 @@ private:
// juce::TextButton addBtn; // juce::TextButton addBtn;
MyListBoxItemData itemData; AudioEffectListBoxItemData itemData;
MyListBoxModel listBoxModel; EffectsListBoxModel listBoxModel;
DraggableListBox listBox; DraggableListBox listBox;
EffectComponent frequency = EffectComponent(0.0, 12000.0, 0.1, 400, "Frequency", "frequency"); EffectComponent frequency = EffectComponent(0.0, 12000.0, 0.1, 400, "Frequency", "frequency");

Wyświetl plik

@ -1,12 +1,18 @@
#include "LuaComponent.h" #include "LuaComponent.h"
#include "PluginEditor.h" #include "PluginEditor.h"
LuaComponent::LuaComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) { LuaComponent::LuaComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor), slidersModel(sliders) {
setText(".lua File Settings"); setText(".lua File Settings");
sliders.setModel(&slidersModel);
sliders.setRowHeight(30);
addAndMakeVisible(sliders);
} }
LuaComponent::~LuaComponent() { LuaComponent::~LuaComponent() {
} }
void LuaComponent::resized() { void LuaComponent::resized() {
auto area = getLocalBounds().reduced(20);
sliders.setBounds(area);
} }

Wyświetl plik

@ -2,6 +2,7 @@
#include <JuceHeader.h> #include <JuceHeader.h>
#include "PluginProcessor.h" #include "PluginProcessor.h"
#include "components/LuaListComponent.h"
class OscirenderAudioProcessorEditor; class OscirenderAudioProcessorEditor;
class LuaComponent : public juce::GroupComponent { class LuaComponent : public juce::GroupComponent {
@ -14,6 +15,8 @@ private:
OscirenderAudioProcessor& audioProcessor; OscirenderAudioProcessor& audioProcessor;
OscirenderAudioProcessorEditor& pluginEditor; OscirenderAudioProcessorEditor& pluginEditor;
LuaListBoxModel slidersModel;
juce::ListBox sliders;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LuaComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LuaComponent)
}; };

Wyświetl plik

@ -11,7 +11,7 @@
//============================================================================== //==============================================================================
OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioProcessor& p) OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioProcessor& p)
: AudioProcessorEditor(&p), audioProcessor(p), effects(p), main(p, *this), collapseButton("Collapse", juce::Colours::white, juce::Colours::white, juce::Colours::white) : AudioProcessorEditor(&p), audioProcessor(p), effects(p), main(p, *this), collapseButton("Collapse", juce::Colours::white, juce::Colours::white, juce::Colours::white), lua(p, *this)
{ {
// Make sure that before the constructor has finished, you've set the // Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be. // editor's size to whatever you need it to be.
@ -20,6 +20,7 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr
addAndMakeVisible(effects); addAndMakeVisible(effects);
addAndMakeVisible(main); addAndMakeVisible(main);
addAndMakeVisible(lua);
addAndMakeVisible(collapseButton); addAndMakeVisible(collapseButton);
collapseButton.onClick = [this] { collapseButton.onClick = [this] {
@ -74,6 +75,7 @@ void OscirenderAudioProcessorEditor::resized() {
} }
effects.setBounds(area.removeFromRight(getWidth() / sections)); effects.setBounds(area.removeFromRight(getWidth() / sections));
main.setBounds(area.removeFromTop(getHeight() / 2)); main.setBounds(area.removeFromTop(getHeight() / 2));
lua.setBounds(area);
} }
void OscirenderAudioProcessorEditor::addCodeEditor(int index) { void OscirenderAudioProcessorEditor::addCodeEditor(int index) {

Wyświetl plik

@ -12,6 +12,7 @@
#include "PluginProcessor.h" #include "PluginProcessor.h"
#include "EffectsComponent.h" #include "EffectsComponent.h"
#include "MainComponent.h" #include "MainComponent.h"
#include "LuaComponent.h"
//============================================================================== //==============================================================================
/** /**
@ -33,6 +34,7 @@ private:
OscirenderAudioProcessor& audioProcessor; OscirenderAudioProcessor& audioProcessor;
MainComponent main; MainComponent main;
LuaComponent lua;
EffectsComponent effects; EffectsComponent effects;
std::vector<std::shared_ptr<juce::CodeDocument>> codeDocuments; std::vector<std::shared_ptr<juce::CodeDocument>> codeDocuments;
std::vector<std::shared_ptr<juce::CodeEditorComponent>> codeEditors; std::vector<std::shared_ptr<juce::CodeEditorComponent>> codeEditors;

Wyświetl plik

@ -1,11 +1,11 @@
#include "MyListComponent.h" #include "EffectsListComponent.h"
MyListComponent::MyListComponent(DraggableListBox& lb, MyListBoxItemData& data, int rn, std::shared_ptr<EffectComponent> effectComponent) : DraggableListBoxItem(lb, data, rn), effectComponent(effectComponent) { EffectsListComponent::EffectsListComponent(DraggableListBox& lb, AudioEffectListBoxItemData& data, int rn, std::shared_ptr<EffectComponent> effectComponent) : DraggableListBoxItem(lb, data, rn), effectComponent(effectComponent) {
addAndMakeVisible(*effectComponent); addAndMakeVisible(*effectComponent);
effectComponent->slider.setValue(data.getValue(rn), juce::dontSendNotification); effectComponent->slider.setValue(data.getValue(rn), juce::dontSendNotification);
effectComponent->slider.onValueChange = [this] { effectComponent->slider.onValueChange = [this] {
((MyListBoxItemData&)modelData).setValue(rowNum, this->effectComponent->slider.getValue()); ((AudioEffectListBoxItemData&)modelData).setValue(rowNum, this->effectComponent->slider.getValue());
}; };
// check if effect is in audioProcessor enabled effects // check if effect is in audioProcessor enabled effects
@ -18,13 +18,13 @@ MyListComponent::MyListComponent(DraggableListBox& lb, MyListBoxItemData& data,
} }
effectComponent->selected.setToggleState(isSelected, juce::dontSendNotification); effectComponent->selected.setToggleState(isSelected, juce::dontSendNotification);
effectComponent->selected.onClick = [this] { effectComponent->selected.onClick = [this] {
((MyListBoxItemData&)modelData).setSelected(rowNum, this->effectComponent->selected.getToggleState()); ((AudioEffectListBoxItemData&)modelData).setSelected(rowNum, this->effectComponent->selected.getToggleState());
}; };
} }
MyListComponent::~MyListComponent() {} EffectsListComponent::~EffectsListComponent() {}
void MyListComponent::paint(juce::Graphics& g) { void EffectsListComponent::paint(juce::Graphics& g) {
DraggableListBoxItem::paint(g); DraggableListBoxItem::paint(g);
auto bounds = getLocalBounds(); auto bounds = getLocalBounds();
bounds.removeFromLeft(20); bounds.removeFromLeft(20);
@ -42,18 +42,18 @@ void MyListComponent::paint(juce::Graphics& g) {
g.fillEllipse(leftPad + spacing, topPad + 2 * spacing, size, size); g.fillEllipse(leftPad + spacing, topPad + 2 * spacing, size, size);
} }
void MyListComponent::resized() { void EffectsListComponent::resized() {
auto area = getLocalBounds(); auto area = getLocalBounds();
area.removeFromLeft(20); area.removeFromLeft(20);
effectComponent->setBounds(area); effectComponent->setBounds(area);
} }
juce::Component* MyListBoxModel::refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component *existingComponentToUpdate) { juce::Component* EffectsListBoxModel::refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component *existingComponentToUpdate) {
std::unique_ptr<MyListComponent> item(dynamic_cast<MyListComponent*>(existingComponentToUpdate)); std::unique_ptr<EffectsListComponent> item(dynamic_cast<EffectsListComponent*>(existingComponentToUpdate));
if (juce::isPositiveAndBelow(rowNumber, modelData.getNumItems())) { if (juce::isPositiveAndBelow(rowNumber, modelData.getNumItems())) {
auto data = (MyListBoxItemData&)modelData; auto data = (AudioEffectListBoxItemData&)modelData;
std::shared_ptr<EffectComponent> effectComponent = std::make_shared<EffectComponent>(0, 1, 0.01, 0, data.getText(rowNumber), data.getId(rowNumber)); std::shared_ptr<EffectComponent> effectComponent = std::make_shared<EffectComponent>(0, 1, 0.01, 0, data.getText(rowNumber), data.getId(rowNumber));
item = std::make_unique<MyListComponent>(listBox, (MyListBoxItemData&)modelData, rowNumber, effectComponent); item = std::make_unique<EffectsListComponent>(listBox, (AudioEffectListBoxItemData&)modelData, rowNumber, effectComponent);
} }
return item.release(); return item.release();
} }

Wyświetl plik

@ -6,12 +6,12 @@
#include "EffectComponent.h" #include "EffectComponent.h"
// Application-specific data container // Application-specific data container
struct MyListBoxItemData : public DraggableListBoxItemData struct AudioEffectListBoxItemData : public DraggableListBoxItemData
{ {
std::vector<std::shared_ptr<Effect>> data; std::vector<std::shared_ptr<Effect>> data;
OscirenderAudioProcessor& audioProcessor; OscirenderAudioProcessor& audioProcessor;
MyListBoxItemData(OscirenderAudioProcessor& p) : audioProcessor(p) {} AudioEffectListBoxItemData(OscirenderAudioProcessor& p) : audioProcessor(p) {}
int getNumItems() override { int getNumItems() override {
return data.size(); return data.size();
@ -91,11 +91,11 @@ struct MyListBoxItemData : public DraggableListBoxItemData
}; };
// Custom list-item Component (which includes item-delete button) // Custom list-item Component (which includes item-delete button)
class MyListComponent : public DraggableListBoxItem class EffectsListComponent : public DraggableListBoxItem
{ {
public: public:
MyListComponent(DraggableListBox& lb, MyListBoxItemData& data, int rn, std::shared_ptr<EffectComponent> effectComponent); EffectsListComponent(DraggableListBox& lb, AudioEffectListBoxItemData& data, int rn, std::shared_ptr<EffectComponent> effectComponent);
~MyListComponent(); ~EffectsListComponent();
void paint(juce::Graphics& g) override; void paint(juce::Graphics& g) override;
void resized() override; void resized() override;
@ -103,15 +103,15 @@ public:
protected: protected:
std::shared_ptr<EffectComponent> effectComponent; std::shared_ptr<EffectComponent> effectComponent;
private: private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MyListComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EffectsListComponent)
}; };
// Customized DraggableListBoxModel overrides refreshComponentForRow() to ensure that every // Customized DraggableListBoxModel overrides refreshComponentForRow() to ensure that every
// list-item Component is a MyListComponent. // list-item Component is a EffectsListComponent.
class MyListBoxModel : public DraggableListBoxModel class EffectsListBoxModel : public DraggableListBoxModel
{ {
public: public:
MyListBoxModel(DraggableListBox& lb, DraggableListBoxItemData& md) EffectsListBoxModel(DraggableListBox& lb, DraggableListBoxItemData& md)
: DraggableListBoxModel(lb, md) {} : DraggableListBoxModel(lb, md) {}
juce::Component* refreshComponentForRow(int, bool, juce::Component*) override; juce::Component* refreshComponentForRow(int, bool, juce::Component*) override;

Wyświetl plik

@ -0,0 +1,48 @@
#include "LuaListComponent.h"
LuaListComponent::LuaListComponent(int sliderNum) {
juce::String sliderName = "";
sliderNum++;
while (sliderNum > 0) {
int mod = (sliderNum - 1) % 26;
sliderName = (char)(mod + 'A') + sliderName;
sliderNum = (sliderNum - mod) / 26;
}
effectComponent = std::make_shared<EffectComponent>(0.0, 1.0, 0.01, 0, "Lua " + sliderName, "lua" + sliderName);
effectComponent->setHideCheckbox(true);
addAndMakeVisible(*effectComponent);
}
LuaListComponent::~LuaListComponent() {}
void LuaListComponent::resized() {
effectComponent->setBounds(getLocalBounds());
}
void paintListBoxItem(int sliderNum, juce::Graphics& g, int width, int height, bool rowIsSelected) {}
int LuaListBoxModel::getNumRows() {
return numSliders + 1;
}
void LuaListBoxModel::paintListBoxItem(int rowNumber, juce::Graphics& g, int width, int height, bool rowIsSelected) {}
juce::Component* LuaListBoxModel::refreshComponentForRow(int sliderNum, bool isRowSelected, juce::Component *existingComponentToUpdate) {
if (sliderNum < getNumRows() - 1) {
std::unique_ptr<LuaListComponent> item(dynamic_cast<LuaListComponent*>(existingComponentToUpdate));
if (juce::isPositiveAndBelow(sliderNum, getNumRows())) {
item = std::make_unique<LuaListComponent>(sliderNum);
}
return item.release();
} else {
std::unique_ptr<juce::TextButton> item(dynamic_cast<juce::TextButton*>(existingComponentToUpdate));
item = std::make_unique<juce::TextButton>("Add");
item->onClick = [this]() {
numSliders++;
listBox.updateContent();
};
return item.release();
}
}

Wyświetl plik

@ -0,0 +1,33 @@
#pragma once
#include <JuceHeader.h>
#include "../PluginProcessor.h"
#include "../audio/Effect.h"
#include "EffectComponent.h"
class LuaListComponent : public juce::Component
{
public:
LuaListComponent(int sliderNum);
~LuaListComponent();
void resized() override;
protected:
std::shared_ptr<EffectComponent> effectComponent;
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LuaListComponent)
};
class LuaListBoxModel : public juce::ListBoxModel
{
public:
LuaListBoxModel(juce::ListBox& lb) : listBox(lb) {}
int getNumRows() override;
void paintListBoxItem(int rowNumber, juce::Graphics& g, int width, int height, bool rowIsSelected) override;
juce::Component* refreshComponentForRow(int sliderNum, bool isRowSelected, juce::Component *existingComponentToUpdate) override;
private:
int numSliders = 5;
juce::ListBox& listBox;
};

Wyświetl plik

@ -88,10 +88,14 @@
file="Source/components/EffectComponent.cpp"/> file="Source/components/EffectComponent.cpp"/>
<FILE id="u4UCwb" name="EffectComponent.h" compile="0" resource="0" <FILE id="u4UCwb" name="EffectComponent.h" compile="0" resource="0"
file="Source/components/EffectComponent.h"/> file="Source/components/EffectComponent.h"/>
<FILE id="M9ImIg" name="MyListComponent.cpp" compile="1" resource="0" <FILE id="JG4NCF" name="EffectsListComponent.cpp" compile="1" resource="0"
file="Source/components/MyListComponent.cpp"/> file="Source/components/EffectsListComponent.cpp"/>
<FILE id="goyxlC" name="MyListComponent.h" compile="0" resource="0" <FILE id="dcLchL" name="EffectsListComponent.h" compile="0" resource="0"
file="Source/components/MyListComponent.h"/> file="Source/components/EffectsListComponent.h"/>
<FILE id="qIxm1z" name="LuaListComponent.cpp" compile="1" resource="0"
file="Source/components/LuaListComponent.cpp"/>
<FILE id="x0Syav" name="LuaListComponent.h" compile="0" resource="0"
file="Source/components/LuaListComponent.h"/>
</GROUP> </GROUP>
<GROUP id="{85A33213-D880-BD92-70D8-1901DA6D23F0}" name="audio"> <GROUP id="{85A33213-D880-BD92-70D8-1901DA6D23F0}" name="audio">
<FILE id="NWuowi" name="BitCrushEffect.cpp" compile="1" resource="0" <FILE id="NWuowi" name="BitCrushEffect.cpp" compile="1" resource="0"