From 2ec4eaba524d6e20528881ac83bb092ab034bd05 Mon Sep 17 00:00:00 2001 From: James Ball Date: Sun, 2 Jul 2023 21:00:14 +0100 Subject: [PATCH] Add .lua file settings with infinite (non-working) slider support --- Source/EffectsComponent.h | 6 +-- Source/LuaComponent.cpp | 8 +++- Source/LuaComponent.h | 3 ++ Source/PluginEditor.cpp | 4 +- Source/PluginEditor.h | 2 + ...Component.cpp => EffectsListComponent.cpp} | 22 ++++----- ...ListComponent.h => EffectsListComponent.h} | 18 +++---- Source/components/LuaListComponent.cpp | 48 +++++++++++++++++++ Source/components/LuaListComponent.h | 33 +++++++++++++ osci-render.jucer | 12 +++-- 10 files changed, 127 insertions(+), 29 deletions(-) rename Source/components/{MyListComponent.cpp => EffectsListComponent.cpp} (58%) rename Source/components/{MyListComponent.h => EffectsListComponent.h} (81%) create mode 100644 Source/components/LuaListComponent.cpp create mode 100644 Source/components/LuaListComponent.h diff --git a/Source/EffectsComponent.h b/Source/EffectsComponent.h index a3654a8..76917d9 100644 --- a/Source/EffectsComponent.h +++ b/Source/EffectsComponent.h @@ -4,7 +4,7 @@ #include "audio/BitCrushEffect.h" #include "PluginProcessor.h" #include "components/DraggableListBox.h" -#include "components/MyListComponent.h" +#include "components/EffectsListComponent.h" class EffectsComponent : public juce::GroupComponent { public: @@ -18,8 +18,8 @@ private: // juce::TextButton addBtn; - MyListBoxItemData itemData; - MyListBoxModel listBoxModel; + AudioEffectListBoxItemData itemData; + EffectsListBoxModel listBoxModel; DraggableListBox listBox; EffectComponent frequency = EffectComponent(0.0, 12000.0, 0.1, 400, "Frequency", "frequency"); diff --git a/Source/LuaComponent.cpp b/Source/LuaComponent.cpp index fa6af2c..a04bb1a 100644 --- a/Source/LuaComponent.cpp +++ b/Source/LuaComponent.cpp @@ -1,12 +1,18 @@ #include "LuaComponent.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"); + + sliders.setModel(&slidersModel); + sliders.setRowHeight(30); + addAndMakeVisible(sliders); } LuaComponent::~LuaComponent() { } void LuaComponent::resized() { + auto area = getLocalBounds().reduced(20); + sliders.setBounds(area); } diff --git a/Source/LuaComponent.h b/Source/LuaComponent.h index da17505..7f5b4ad 100644 --- a/Source/LuaComponent.h +++ b/Source/LuaComponent.h @@ -2,6 +2,7 @@ #include #include "PluginProcessor.h" +#include "components/LuaListComponent.h" class OscirenderAudioProcessorEditor; class LuaComponent : public juce::GroupComponent { @@ -14,6 +15,8 @@ private: OscirenderAudioProcessor& audioProcessor; OscirenderAudioProcessorEditor& pluginEditor; + LuaListBoxModel slidersModel; + juce::ListBox sliders; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LuaComponent) }; \ No newline at end of file diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 2e7da2e..558b363 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -11,7 +11,7 @@ //============================================================================== 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 // editor's size to whatever you need it to be. @@ -20,6 +20,7 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr addAndMakeVisible(effects); addAndMakeVisible(main); + addAndMakeVisible(lua); addAndMakeVisible(collapseButton); collapseButton.onClick = [this] { @@ -74,6 +75,7 @@ void OscirenderAudioProcessorEditor::resized() { } effects.setBounds(area.removeFromRight(getWidth() / sections)); main.setBounds(area.removeFromTop(getHeight() / 2)); + lua.setBounds(area); } void OscirenderAudioProcessorEditor::addCodeEditor(int index) { diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index fd0c884..d92818c 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -12,6 +12,7 @@ #include "PluginProcessor.h" #include "EffectsComponent.h" #include "MainComponent.h" +#include "LuaComponent.h" //============================================================================== /** @@ -33,6 +34,7 @@ private: OscirenderAudioProcessor& audioProcessor; MainComponent main; + LuaComponent lua; EffectsComponent effects; std::vector> codeDocuments; std::vector> codeEditors; diff --git a/Source/components/MyListComponent.cpp b/Source/components/EffectsListComponent.cpp similarity index 58% rename from Source/components/MyListComponent.cpp rename to Source/components/EffectsListComponent.cpp index f1b585c..06b369c 100644 --- a/Source/components/MyListComponent.cpp +++ b/Source/components/EffectsListComponent.cpp @@ -1,11 +1,11 @@ -#include "MyListComponent.h" +#include "EffectsListComponent.h" -MyListComponent::MyListComponent(DraggableListBox& lb, MyListBoxItemData& data, int rn, std::shared_ptr effectComponent) : DraggableListBoxItem(lb, data, rn), effectComponent(effectComponent) { +EffectsListComponent::EffectsListComponent(DraggableListBox& lb, AudioEffectListBoxItemData& data, int rn, std::shared_ptr effectComponent) : DraggableListBoxItem(lb, data, rn), effectComponent(effectComponent) { addAndMakeVisible(*effectComponent); effectComponent->slider.setValue(data.getValue(rn), juce::dontSendNotification); 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 @@ -18,13 +18,13 @@ MyListComponent::MyListComponent(DraggableListBox& lb, MyListBoxItemData& data, } effectComponent->selected.setToggleState(isSelected, juce::dontSendNotification); 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); auto bounds = getLocalBounds(); bounds.removeFromLeft(20); @@ -42,18 +42,18 @@ void MyListComponent::paint(juce::Graphics& g) { g.fillEllipse(leftPad + spacing, topPad + 2 * spacing, size, size); } -void MyListComponent::resized() { +void EffectsListComponent::resized() { auto area = getLocalBounds(); area.removeFromLeft(20); effectComponent->setBounds(area); } -juce::Component* MyListBoxModel::refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component *existingComponentToUpdate) { - std::unique_ptr item(dynamic_cast(existingComponentToUpdate)); +juce::Component* EffectsListBoxModel::refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component *existingComponentToUpdate) { + std::unique_ptr item(dynamic_cast(existingComponentToUpdate)); if (juce::isPositiveAndBelow(rowNumber, modelData.getNumItems())) { - auto data = (MyListBoxItemData&)modelData; + auto data = (AudioEffectListBoxItemData&)modelData; std::shared_ptr effectComponent = std::make_shared(0, 1, 0.01, 0, data.getText(rowNumber), data.getId(rowNumber)); - item = std::make_unique(listBox, (MyListBoxItemData&)modelData, rowNumber, effectComponent); + item = std::make_unique(listBox, (AudioEffectListBoxItemData&)modelData, rowNumber, effectComponent); } return item.release(); } diff --git a/Source/components/MyListComponent.h b/Source/components/EffectsListComponent.h similarity index 81% rename from Source/components/MyListComponent.h rename to Source/components/EffectsListComponent.h index 8fa4947..9f6a746 100644 --- a/Source/components/MyListComponent.h +++ b/Source/components/EffectsListComponent.h @@ -6,12 +6,12 @@ #include "EffectComponent.h" // Application-specific data container -struct MyListBoxItemData : public DraggableListBoxItemData +struct AudioEffectListBoxItemData : public DraggableListBoxItemData { std::vector> data; OscirenderAudioProcessor& audioProcessor; - MyListBoxItemData(OscirenderAudioProcessor& p) : audioProcessor(p) {} + AudioEffectListBoxItemData(OscirenderAudioProcessor& p) : audioProcessor(p) {} int getNumItems() override { return data.size(); @@ -91,11 +91,11 @@ struct MyListBoxItemData : public DraggableListBoxItemData }; // Custom list-item Component (which includes item-delete button) -class MyListComponent : public DraggableListBoxItem +class EffectsListComponent : public DraggableListBoxItem { public: - MyListComponent(DraggableListBox& lb, MyListBoxItemData& data, int rn, std::shared_ptr effectComponent); - ~MyListComponent(); + EffectsListComponent(DraggableListBox& lb, AudioEffectListBoxItemData& data, int rn, std::shared_ptr effectComponent); + ~EffectsListComponent(); void paint(juce::Graphics& g) override; void resized() override; @@ -103,15 +103,15 @@ public: protected: std::shared_ptr effectComponent; 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 -// list-item Component is a MyListComponent. -class MyListBoxModel : public DraggableListBoxModel +// list-item Component is a EffectsListComponent. +class EffectsListBoxModel : public DraggableListBoxModel { public: - MyListBoxModel(DraggableListBox& lb, DraggableListBoxItemData& md) + EffectsListBoxModel(DraggableListBox& lb, DraggableListBoxItemData& md) : DraggableListBoxModel(lb, md) {} juce::Component* refreshComponentForRow(int, bool, juce::Component*) override; diff --git a/Source/components/LuaListComponent.cpp b/Source/components/LuaListComponent.cpp new file mode 100644 index 0000000..1926a91 --- /dev/null +++ b/Source/components/LuaListComponent.cpp @@ -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(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 item(dynamic_cast(existingComponentToUpdate)); + if (juce::isPositiveAndBelow(sliderNum, getNumRows())) { + item = std::make_unique(sliderNum); + } + return item.release(); + } else { + std::unique_ptr item(dynamic_cast(existingComponentToUpdate)); + item = std::make_unique("Add"); + item->onClick = [this]() { + numSliders++; + listBox.updateContent(); + }; + return item.release(); + } +} diff --git a/Source/components/LuaListComponent.h b/Source/components/LuaListComponent.h new file mode 100644 index 0000000..1d0d63e --- /dev/null +++ b/Source/components/LuaListComponent.h @@ -0,0 +1,33 @@ +#pragma once +#include +#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; +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; +}; diff --git a/osci-render.jucer b/osci-render.jucer index f5be6b6..072aa95 100644 --- a/osci-render.jucer +++ b/osci-render.jucer @@ -88,10 +88,14 @@ file="Source/components/EffectComponent.cpp"/> - - + + + +