SmartGuitarAmp

Guitar plugin made with JUCE that uses neural networks to emulate a tube amplifier
Log | Files | Refs | Submodules | README

commit 61204de8088a17a3b6b53bcdfac153193cd851bc
parent bb36c643ae4408fbb0f9204971753d3330a1df21
Author: Matti Pesonen <[email protected]>
Date:   Tue, 21 Mar 2023 23:13:32 +0200

Support for resizing the GUI window

Diffstat:
Msrc/PluginEditor.cpp | 52+++++++++++++++++++++++++++++++++++++++-------------
Msrc/PluginEditor.h | 22++++++++++++++++++----
Msrc/PluginProcessor.cpp | 4++--
3 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/src/PluginEditor.cpp b/src/PluginEditor.cpp @@ -12,8 +12,8 @@ #include "PluginEditor.h" //============================================================================== -WaveNetVaAudioProcessorEditor::WaveNetVaAudioProcessorEditor (WaveNetVaAudioProcessor& p) - : AudioProcessorEditor (&p), processor (p) +WaveNetVaComponent::WaveNetVaComponent (WaveNetVaAudioProcessor& p) + : processor (p) { // Make sure that before the constructor has finished, you've set the // editor's size to whatever you need it to @@ -124,14 +124,11 @@ WaveNetVaAudioProcessorEditor::WaveNetVaAudioProcessorEditor (WaveNetVaAudioProc ampMasterKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20 ); ampMasterKnob.setDoubleClickReturnValue(true, 0.5); - // Size of plugin GUI - setSize (1085, 540); - processor.loadConfigAmp(); resetImages(); } -WaveNetVaAudioProcessorEditor::~WaveNetVaAudioProcessorEditor() +WaveNetVaComponent::~WaveNetVaComponent() { ampPresenceKnob.setLookAndFeel(nullptr); ampCleanBassKnob.setLookAndFeel(nullptr); @@ -146,7 +143,7 @@ WaveNetVaAudioProcessorEditor::~WaveNetVaAudioProcessorEditor() } //============================================================================== -void WaveNetVaAudioProcessorEditor::paint (Graphics& g) +void WaveNetVaComponent::paint (Graphics& g) { // Workaround for graphics on Windows builds (clipping code doesn't work correctly on Windows) @@ -160,7 +157,7 @@ void WaveNetVaAudioProcessorEditor::paint (Graphics& g) } -void WaveNetVaAudioProcessorEditor::resized() +void WaveNetVaComponent::resized() { // This is generally where you'll want to lay out the positions of any // subcomponents in your editor.. @@ -183,7 +180,7 @@ void WaveNetVaAudioProcessorEditor::resized() ampLED.setBounds(975, 40, 15, 25); } -void WaveNetVaAudioProcessorEditor::buttonClicked(juce::Button* button) +void WaveNetVaComponent::buttonClicked(juce::Button* button) { if (button == &ampOnButton) { ampOnButtonClicked(); @@ -192,7 +189,7 @@ void WaveNetVaAudioProcessorEditor::buttonClicked(juce::Button* button) } } -void WaveNetVaAudioProcessorEditor::ampOnButtonClicked() { +void WaveNetVaComponent::ampOnButtonClicked() { if (processor.amp_state == 0) { processor.amp_state = 1; } @@ -202,7 +199,7 @@ void WaveNetVaAudioProcessorEditor::ampOnButtonClicked() { resetImages(); } -void WaveNetVaAudioProcessorEditor::ampCleanLeadButtonClicked() { +void WaveNetVaComponent::ampCleanLeadButtonClicked() { if (processor.amp_lead == 1) { processor.amp_lead = 0; processor.loadConfigAmp(); @@ -217,7 +214,7 @@ void WaveNetVaAudioProcessorEditor::ampCleanLeadButtonClicked() { resetImages(); } -void WaveNetVaAudioProcessorEditor::sliderValueChanged(Slider* slider) +void WaveNetVaComponent::sliderValueChanged(Slider* slider) { // Amp @@ -238,7 +235,7 @@ void WaveNetVaAudioProcessorEditor::sliderValueChanged(Slider* slider) } -void WaveNetVaAudioProcessorEditor::resetImages() +void WaveNetVaComponent::resetImages() { if (processor.amp_state == 1 && processor.amp_lead == 1 ) { background_set = background_lead; @@ -289,3 +286,31 @@ void WaveNetVaAudioProcessorEditor::resetImages() } repaint(); } + +// Wrapper implementation +WrappedWaveNetVaAudioProcessorEditor::WrappedWaveNetVaAudioProcessorEditor(WaveNetVaAudioProcessor& p) + : AudioProcessorEditor(p), waveNetVaComponent(p) +{ + addAndMakeVisible(waveNetVaComponent); + + if (auto* constrainer = getConstrainer()) + { + constrainer->setFixedAspectRatio(static_cast<double> (originalWidth) / static_cast<double> (originalHeight)); + constrainer->setSizeLimits(originalWidth / 4, originalHeight / 4, originalWidth * 2, originalHeight * 2); + } + + setResizable(true, true); + setSize(originalWidth, originalHeight); +} + +void WrappedWaveNetVaAudioProcessorEditor::resized() +{ + const auto scaleFactor = static_cast<float> (getWidth()) / originalWidth; + waveNetVaComponent.setTransform(AffineTransform::scale(scaleFactor)); + waveNetVaComponent.setBounds(0, 0, originalWidth, originalHeight); +} + +void WrappedWaveNetVaAudioProcessorEditor::resetImages() +{ + waveNetVaComponent.resetImages(); +} +\ No newline at end of file diff --git a/src/PluginEditor.h b/src/PluginEditor.h @@ -17,14 +17,14 @@ //============================================================================== /** */ -class WaveNetVaAudioProcessorEditor : public AudioProcessorEditor, +class WaveNetVaComponent : public Component, private Button::Listener, private Slider::Listener { public: - WaveNetVaAudioProcessorEditor (WaveNetVaAudioProcessor&); - ~WaveNetVaAudioProcessorEditor(); + WaveNetVaComponent (WaveNetVaAudioProcessor&); + ~WaveNetVaComponent(); //============================================================================== void paint (Graphics&) override; @@ -84,5 +84,18 @@ public: std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> presenceSliderAttach; std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> masterSliderAttach; - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveNetVaAudioProcessorEditor) + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveNetVaComponent) }; + +class WrappedWaveNetVaAudioProcessorEditor : public AudioProcessorEditor +{ +public: + WrappedWaveNetVaAudioProcessorEditor(WaveNetVaAudioProcessor&); + void resized() override; + void resetImages(); +private: + static constexpr int originalWidth { 1085 }; + static constexpr int originalHeight { 540 }; + + WaveNetVaComponent waveNetVaComponent; +}; +\ No newline at end of file diff --git a/src/PluginProcessor.cpp b/src/PluginProcessor.cpp @@ -225,7 +225,7 @@ bool WaveNetVaAudioProcessor::hasEditor() const AudioProcessorEditor* WaveNetVaAudioProcessor::createEditor() { - return new WaveNetVaAudioProcessorEditor (*this); + return new WrappedWaveNetVaAudioProcessorEditor (*this); } //============================================================================== @@ -255,7 +255,7 @@ void WaveNetVaAudioProcessor::setStateInformation (const void* data, int sizeInB treeState.replaceState (juce::ValueTree::fromXml (*xmlState)); amp_state = xmlState->getBoolAttribute ("amp_state"); amp_lead = xmlState->getBoolAttribute ("amp_lead"); - if (auto* editor = dynamic_cast<WaveNetVaAudioProcessorEditor*> (getActiveEditor())) + if (auto* editor = dynamic_cast<WrappedWaveNetVaAudioProcessorEditor*> (getActiveEditor())) editor->resetImages(); } }