diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 7f1769b..bf8a484 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -102,6 +102,22 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr addAndMakeVisible(lua); addAndMakeVisible(luaResizerBar); addAndMakeVisible(visualiser); + + visualiser.openSettings = [this] { + visualiserSettingsWindow.setVisible(true); + visualiserSettingsWindow.toFront(true); + }; + + visualiser.closeSettings = [this] { + visualiserSettingsWindow.setVisible(false); + }; + + visualiserSettingsWindow.setResizable(false, false); + visualiserSettingsWindow.setUsingNativeTitleBar(true); + visualiserSettings.setLookAndFeel(&getLookAndFeel()); + visualiserSettings.setSize(550, 230); + visualiserSettingsWindow.setContentNonOwned(&visualiserSettings, true); + visualiserSettingsWindow.centreWithSize(550, 230); tooltipDropShadow.setOwner(&tooltipWindow); } diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 8f367e6..0e5ad9b 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -9,6 +9,7 @@ #include "LookAndFeel.h" #include "components/ErrorCodeEditorComponent.h" #include "components/LuaConsole.h" +#include "components/VisualiserSettings.h" class OscirenderAudioProcessorEditor : public juce::AudioProcessorEditor, private juce::CodeDocument::Listener, public juce::AsyncUpdater, public juce::ChangeListener { public: @@ -48,7 +49,10 @@ public: std::atomic editingCustomFunction = false; - VisualiserComponent visualiser{audioProcessor, nullptr, audioProcessor.legacyVisualiserEnabled->getBoolValue()}; + VisualiserSettings visualiserSettings = VisualiserSettings(audioProcessor); + SettingsWindow visualiserSettingsWindow = SettingsWindow("Visualiser Settings"); + VisualiserComponent visualiser{audioProcessor, visualiserSettings, nullptr, audioProcessor.legacyVisualiserEnabled->getBoolValue()}; + SettingsComponent settings{audioProcessor, *this}; juce::ComponentAnimator codeEditorAnimator; diff --git a/Source/components/VisualiserComponent.cpp b/Source/components/VisualiserComponent.cpp index ee49ff1..fb107f2 100644 --- a/Source/components/VisualiserComponent.cpp +++ b/Source/components/VisualiserComponent.cpp @@ -1,20 +1,13 @@ #include "../LookAndFeel.h" #include "VisualiserComponent.h" -VisualiserComponent::VisualiserComponent(OscirenderAudioProcessor& p, VisualiserComponent* parent, bool useOldVisualiser) : backgroundColour(juce::Colours::black), waveformColour(juce::Colour(0xff00ff00)), audioProcessor(p), oldVisualiser(useOldVisualiser), juce::Thread("VisualiserComponent"), parent(parent) { +VisualiserComponent::VisualiserComponent(OscirenderAudioProcessor& p, VisualiserSettings& settings, VisualiserComponent* parent, bool useOldVisualiser) : settings(settings), backgroundColour(juce::Colours::black), waveformColour(juce::Colour(0xff00ff00)), audioProcessor(p), oldVisualiser(useOldVisualiser), juce::Thread("VisualiserComponent"), parent(parent) { setVisualiserType(oldVisualiser); resetBuffer(); startTimerHz(60); startThread(); - settingsWindow.setResizable(false, false); - settingsWindow.setUsingNativeTitleBar(true); - settings.setLookAndFeel(&getLookAndFeel()); - settings.setSize(550, 230); - settingsWindow.setContentNonOwned(&settings, true); - settingsWindow.centreWithSize(550, 230); - setMouseCursor(juce::MouseCursor::PointingHandCursor); setWantsKeyboardFocus(true); @@ -228,6 +221,9 @@ void VisualiserComponent::setVisualiserType(bool oldVisualiser) { } if (oldVisualiser) { browser.reset(); + if (closeSettings != nullptr) { + closeSettings(); + } } else { initialiseBrowser(); } @@ -349,8 +345,10 @@ void VisualiserComponent::childChanged() { } void VisualiserComponent::popoutWindow() { - auto visualiser = new VisualiserComponent(audioProcessor, this, oldVisualiser); + auto visualiser = new VisualiserComponent(audioProcessor, settings, this, oldVisualiser); visualiser->settings.setLookAndFeel(&getLookAndFeel()); + visualiser->openSettings = openSettings; + visualiser->closeSettings = closeSettings; child = visualiser; childChanged(); popOutButton.setVisible(false); @@ -365,8 +363,3 @@ void VisualiserComponent::popoutWindow() { resized(); popOutButton.setVisible(false); } - -void VisualiserComponent::openSettings() { - settingsWindow.setVisible(true); - settingsWindow.toFront(true); -} diff --git a/Source/components/VisualiserComponent.h b/Source/components/VisualiserComponent.h index 85e9b7c..547d90a 100644 --- a/Source/components/VisualiserComponent.h +++ b/Source/components/VisualiserComponent.h @@ -18,10 +18,12 @@ enum class FullScreenMode { class VisualiserWindow; class VisualiserComponent : public juce::Component, public juce::Timer, public juce::Thread, public juce::MouseListener, public juce::SettableTooltipClient { public: - VisualiserComponent(OscirenderAudioProcessor& p, VisualiserComponent* parent = nullptr, bool useOldVisualiser = false); + VisualiserComponent(OscirenderAudioProcessor& p, VisualiserSettings& settings, VisualiserComponent* parent = nullptr, bool useOldVisualiser = false); ~VisualiserComponent() override; - void openSettings(); + std::function openSettings; + std::function closeSettings; + void childChanged(); void enableFullScreen(); void setFullScreenCallback(std::function callback); @@ -76,8 +78,8 @@ private: std::shared_ptr consumer; std::function fullScreenCallback; - VisualiserSettings settings = VisualiserSettings(audioProcessor, *this); - SettingsWindow settingsWindow = SettingsWindow("Visualiser Settings"); + + VisualiserSettings& settings; juce::WebBrowserComponent::ResourceProvider provider = [this](const juce::String& path) { juce::String mimeType; diff --git a/Source/components/VisualiserSettings.cpp b/Source/components/VisualiserSettings.cpp index af78ce7..025525c 100644 --- a/Source/components/VisualiserSettings.cpp +++ b/Source/components/VisualiserSettings.cpp @@ -2,7 +2,7 @@ #include "VisualiserComponent.h" #include "../PluginEditor.h" -VisualiserSettings::VisualiserSettings(OscirenderAudioProcessor& p, VisualiserComponent& visualiser) : audioProcessor(p), visualiser(visualiser) { +VisualiserSettings::VisualiserSettings(OscirenderAudioProcessor& p) : audioProcessor(p) { addAndMakeVisible(intensity); addAndMakeVisible(persistence); addAndMakeVisible(hue); diff --git a/Source/components/VisualiserSettings.h b/Source/components/VisualiserSettings.h index 5ea48f6..4a44a65 100644 --- a/Source/components/VisualiserSettings.h +++ b/Source/components/VisualiserSettings.h @@ -6,17 +6,15 @@ #include "../LookAndFeel.h" #include "SwitchButton.h" -class VisualiserComponent; class VisualiserSettings : public juce::Component { public: - VisualiserSettings(OscirenderAudioProcessor&, VisualiserComponent&); + VisualiserSettings(OscirenderAudioProcessor&); ~VisualiserSettings(); void resized() override; juce::var getSettings(); private: OscirenderAudioProcessor& audioProcessor; - VisualiserComponent& visualiser; EffectComponent intensity{audioProcessor, *audioProcessor.intensityEffect}; EffectComponent persistence{audioProcessor, *audioProcessor.persistenceEffect};