SmartGuitarAmp

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

PluginEditor.cpp (15904B)


      1 /*
      2   ==============================================================================
      3 
      4     This file was auto-generated!
      5 
      6     It contains the basic framework code for a JUCE plugin editor.
      7 
      8   ==============================================================================
      9 */
     10 
     11 #include "PluginProcessor.h"
     12 #include "PluginEditor.h"
     13 
     14 //==============================================================================
     15 WaveNetVaComponent::WaveNetVaComponent (WaveNetVaAudioProcessor& p)
     16     : processor (p)
     17 {
     18     // Make sure that before the constructor has finished, you've set the
     19     // editor's size to whatever you need it to
     20 
     21     // Set Widget Graphics
     22     ampSilverKnobLAF.setLookAndFeel(ImageCache::getFromMemory(BinaryData::knob_silver_png, BinaryData::knob_silver_pngSize));
     23 
     24     ampOnButton.setImages(true, true, true,
     25         ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
     26         Image(), 1.0, Colours::transparentWhite,
     27         ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
     28         0.0);
     29     addAndMakeVisible(ampOnButton);
     30     ampOnButton.addListener(this);
     31 
     32     ampCleanLeadButton.setImages(true, true, true,
     33         ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
     34         Image(), 1.0, Colours::transparentWhite,
     35         ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
     36         0.0);
     37     addAndMakeVisible(ampCleanLeadButton);
     38     ampCleanLeadButton.addListener(this);
     39 
     40     ampLED.setImages(true, true, true,
     41         ImageCache::getFromMemory(BinaryData::led_blue_on_png, BinaryData::led_blue_on_pngSize), 1.0, Colours::transparentWhite,
     42         Image(), 1.0, Colours::transparentWhite,
     43         ImageCache::getFromMemory(BinaryData::led_blue_on_png, BinaryData::led_blue_on_pngSize), 1.0, Colours::transparentWhite,
     44         0.0);
     45     addAndMakeVisible(ampLED);
     46 
     47     presenceSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, PRESENCE_ID, ampPresenceKnob);
     48     addAndMakeVisible(ampPresenceKnob);
     49     ampPresenceKnob.setLookAndFeel(&ampSilverKnobLAF);
     50     ampPresenceKnob.addListener(this);
     51     ampPresenceKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
     52     ampPresenceKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 75, 20);
     53     ampPresenceKnob.setDoubleClickReturnValue(true, 0.0);
     54 
     55     cleanBassSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, CLEAN_BASS_ID, ampCleanBassKnob);
     56     addAndMakeVisible(ampCleanBassKnob);
     57     ampCleanBassKnob.setLookAndFeel(&ampSilverKnobLAF);
     58     ampCleanBassKnob.addListener(this);
     59     ampCleanBassKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
     60     ampCleanBassKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
     61     ampCleanBassKnob.setDoubleClickReturnValue(true, 0.0);
     62 
     63     cleanMidSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, CLEAN_MID_ID, ampCleanMidKnob);
     64     addAndMakeVisible(ampCleanMidKnob);
     65     ampCleanMidKnob.setLookAndFeel(&ampSilverKnobLAF);
     66     ampCleanMidKnob.addListener(this);
     67     ampCleanMidKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
     68     ampCleanMidKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
     69     ampCleanMidKnob.setDoubleClickReturnValue(true, 0.0);
     70 
     71     cleanTrebleSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, CLEAN_TREBLE_ID, ampCleanTrebleKnob);
     72     addAndMakeVisible(ampCleanTrebleKnob);
     73     ampCleanTrebleKnob.setLookAndFeel(&ampSilverKnobLAF);
     74     ampCleanTrebleKnob.addListener(this);
     75     ampCleanTrebleKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
     76     ampCleanTrebleKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
     77     ampCleanTrebleKnob.setDoubleClickReturnValue(true, 0.0);
     78 
     79     cleanGainSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, CLEAN_GAIN_ID, ampCleanGainKnob);
     80     addAndMakeVisible(ampCleanGainKnob);
     81     ampCleanGainKnob.setLookAndFeel(&ampSilverKnobLAF);
     82     ampCleanGainKnob.addListener(this);
     83     ampCleanGainKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
     84     ampCleanGainKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
     85     ampCleanGainKnob.setDoubleClickReturnValue(true, 0.5);
     86 
     87     leadBassSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, LEAD_BASS_ID, ampLeadBassKnob);
     88     addAndMakeVisible(ampLeadBassKnob);
     89     ampLeadBassKnob.setLookAndFeel(&ampSilverKnobLAF);
     90     ampLeadBassKnob.addListener(this);
     91     ampLeadBassKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
     92     ampLeadBassKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
     93     ampLeadBassKnob.setDoubleClickReturnValue(true, 0.0);
     94 
     95     leadMidSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, LEAD_MID_ID, ampLeadMidKnob);
     96     addAndMakeVisible(ampLeadMidKnob);
     97     ampLeadMidKnob.setLookAndFeel(&ampSilverKnobLAF);
     98     ampLeadMidKnob.addListener(this);
     99     ampLeadMidKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
    100     ampLeadMidKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);;
    101     ampLeadMidKnob.setDoubleClickReturnValue(true, 0.0);
    102 
    103     leadTrebleSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, LEAD_TREBLE_ID, ampLeadTrebleKnob);
    104     addAndMakeVisible(ampLeadTrebleKnob);
    105     ampLeadTrebleKnob.setLookAndFeel(&ampSilverKnobLAF);
    106     ampLeadTrebleKnob.addListener(this);
    107     ampLeadTrebleKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
    108     ampLeadTrebleKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
    109     ampLeadTrebleKnob.setDoubleClickReturnValue(true, 0.0);
    110 
    111     leadGainSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, LEAD_GAIN_ID, ampLeadGainKnob);
    112     addAndMakeVisible(ampLeadGainKnob);
    113     ampLeadGainKnob.setLookAndFeel(&ampSilverKnobLAF);
    114     ampLeadGainKnob.addListener(this);
    115     ampLeadGainKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
    116     ampLeadGainKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20);
    117     ampLeadGainKnob.setDoubleClickReturnValue(true, 0.5);
    118 
    119     masterSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, MASTER_ID, ampMasterKnob);
    120     addAndMakeVisible(ampMasterKnob);
    121     ampMasterKnob.setLookAndFeel(&ampSilverKnobLAF);
    122     ampMasterKnob.addListener(this);
    123     ampMasterKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag);
    124     ampMasterKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20 );
    125     ampMasterKnob.setDoubleClickReturnValue(true, 0.5);
    126 
    127     processor.loadConfigAmp();
    128     resetImages();
    129 }
    130 
    131 WaveNetVaComponent::~WaveNetVaComponent()
    132 {
    133     ampPresenceKnob.setLookAndFeel(nullptr);
    134     ampCleanBassKnob.setLookAndFeel(nullptr);
    135     ampCleanMidKnob.setLookAndFeel(nullptr);
    136     ampCleanTrebleKnob.setLookAndFeel(nullptr);
    137     ampCleanGainKnob.setLookAndFeel(nullptr);
    138     ampLeadBassKnob.setLookAndFeel(nullptr);
    139     ampLeadMidKnob.setLookAndFeel(nullptr);
    140     ampLeadTrebleKnob.setLookAndFeel(nullptr);
    141     ampLeadGainKnob.setLookAndFeel(nullptr);
    142     ampMasterKnob.setLookAndFeel(nullptr);
    143 }
    144 
    145 //==============================================================================
    146 void WaveNetVaComponent::paint (Graphics& g)
    147 {
    148 
    149     // Workaround for graphics on Windows builds (clipping code doesn't work correctly on Windows)
    150 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
    151     g.drawImageAt(background_set, 0, 0);  // Debug Line: Redraw entire background image
    152 #else
    153 // Redraw only the clipped part of the background image
    154     juce::Rectangle<int> ClipRect = g.getClipBounds();
    155     g.drawImage(background_set, ClipRect.getX(), ClipRect.getY(), ClipRect.getWidth(), ClipRect.getHeight(), ClipRect.getX(), ClipRect.getY(), ClipRect.getWidth(), ClipRect.getHeight());
    156 #endif
    157 
    158 }
    159 
    160 void WaveNetVaComponent::resized()
    161 {
    162     // This is generally where you'll want to lay out the positions of any
    163     // subcomponents in your editor..
    164 
    165     // Amp Widgets
    166     ampPresenceKnob.setBounds(97, 375, 75, 105);
    167     ampCleanBassKnob.setBounds(197, 375, 75, 105);
    168     ampCleanMidKnob.setBounds(280, 375, 75, 105);
    169     ampCleanTrebleKnob.setBounds(378, 375, 75, 105);
    170     ampCleanGainKnob.setBounds(456, 375, 75, 105);
    171     ampLeadBassKnob.setBounds(553, 375, 75, 105);
    172     ampLeadMidKnob.setBounds(636, 375, 75, 105);
    173     ampLeadTrebleKnob.setBounds(726, 375, 75, 105);
    174     ampLeadGainKnob.setBounds(806, 375, 75, 105);
    175     ampMasterKnob.setBounds(903, 375, 75, 105);
    176 
    177     ampOnButton.setBounds(9, 375, 35, 45);
    178     ampCleanLeadButton.setBounds(959, 375, 15, 25);
    179 
    180     ampLED.setBounds(975, 40, 15, 25);
    181 }
    182 
    183 void WaveNetVaComponent::buttonClicked(juce::Button* button)
    184 {
    185     if (button == &ampOnButton) {
    186         ampOnButtonClicked();
    187     } else if (button == &ampCleanLeadButton) {
    188         ampCleanLeadButtonClicked();
    189     }
    190 }
    191 
    192 void WaveNetVaComponent::ampOnButtonClicked() {
    193     if (processor.amp_state == 0) {
    194         processor.amp_state = 1;
    195     }
    196     else {
    197         processor.amp_state = 0;
    198     }
    199     resetImages();
    200 }
    201 
    202 void WaveNetVaComponent::ampCleanLeadButtonClicked() {
    203     if (processor.amp_lead == 1) {
    204         processor.amp_lead = 0;
    205         processor.loadConfigAmp();
    206         processor.set_ampEQ(ampCleanBassKnob.getValue(), ampCleanMidKnob.getValue(), ampCleanTrebleKnob.getValue(), ampPresenceKnob.getValue());
    207     }
    208     else  {
    209         processor.amp_lead = 1;
    210         processor.loadConfigAmp();
    211         processor.set_ampEQ(ampLeadBassKnob.getValue(), ampLeadMidKnob.getValue(), ampLeadTrebleKnob.getValue(), ampPresenceKnob.getValue());
    212     }
    213 
    214     resetImages();
    215 }
    216 
    217 void WaveNetVaComponent::sliderValueChanged(Slider* slider)
    218 {
    219     // Amp
    220 
    221     if (slider == &ampCleanBassKnob || slider == &ampCleanMidKnob || slider == &ampCleanTrebleKnob) {
    222         if (processor.amp_lead == 0)
    223             processor.set_ampEQ(ampCleanBassKnob.getValue(), ampCleanMidKnob.getValue(), ampCleanTrebleKnob.getValue(), ampPresenceKnob.getValue());
    224     }
    225     else if (slider == &ampLeadBassKnob || slider == &ampLeadMidKnob || slider == &ampLeadTrebleKnob) {
    226         if (processor.amp_lead == 1)
    227             processor.set_ampEQ(ampLeadBassKnob.getValue(), ampLeadMidKnob.getValue(), ampLeadTrebleKnob.getValue(), ampPresenceKnob.getValue());       
    228     }
    229     else if (slider == &ampPresenceKnob) {
    230         if (processor.amp_lead == 0)
    231             processor.set_ampEQ(ampCleanBassKnob.getValue(), ampCleanMidKnob.getValue(), ampCleanTrebleKnob.getValue(), ampPresenceKnob.getValue());
    232         else if (processor.amp_lead == 1)
    233             processor.set_ampEQ(ampLeadBassKnob.getValue(), ampLeadMidKnob.getValue(), ampLeadTrebleKnob.getValue(), ampPresenceKnob.getValue());
    234     }
    235 
    236 }
    237 
    238 void WaveNetVaComponent::resetImages()
    239 {
    240     if (processor.amp_state == 1 && processor.amp_lead == 1 ) {
    241         background_set = background_lead;
    242     } else if (processor.amp_state == 1 && processor.amp_lead == 0) {
    243         background_set = background_clean;
    244     } else {
    245         background_set = background_off;
    246     }
    247     // Set On/Off amp graphic
    248     if (processor.amp_state == 0) {
    249         ampOnButton.setImages(true, true, true,
    250             ImageCache::getFromMemory(BinaryData::power_switch_down_png, BinaryData::power_switch_down_pngSize), 1.0, Colours::transparentWhite,
    251             Image(), 1.0, Colours::transparentWhite,
    252             ImageCache::getFromMemory(BinaryData::power_switch_down_png, BinaryData::power_switch_down_pngSize), 1.0, Colours::transparentWhite,
    253             0.0);
    254         ampLED.setImages(true, true, true,
    255             ImageCache::getFromMemory(BinaryData::led_blue_off_png, BinaryData::led_blue_off_pngSize), 1.0, Colours::transparentWhite,
    256             Image(), 1.0, Colours::transparentWhite,
    257             ImageCache::getFromMemory(BinaryData::led_blue_off_png, BinaryData::led_blue_off_pngSize), 1.0, Colours::transparentWhite,
    258             0.0);
    259     }
    260     else {
    261         ampOnButton.setImages(true, true, true,
    262             ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
    263             Image(), 1.0, Colours::transparentWhite,
    264             ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
    265             0.0);
    266         ampLED.setImages(true, true, true,
    267             ImageCache::getFromMemory(BinaryData::led_blue_on_png, BinaryData::led_blue_on_pngSize), 1.0, Colours::transparentWhite,
    268             Image(), 1.0, Colours::transparentWhite,
    269             ImageCache::getFromMemory(BinaryData::led_blue_on_png, BinaryData::led_blue_on_pngSize), 1.0, Colours::transparentWhite,
    270             0.0);
    271     }
    272     // Set clean/lead switch graphic
    273     if (processor.amp_lead == 1) {
    274         ampCleanLeadButton.setImages(true, true, true,
    275             ImageCache::getFromMemory(BinaryData::power_switch_down_png, BinaryData::power_switch_down_pngSize), 1.0, Colours::transparentWhite,
    276             Image(), 1.0, Colours::transparentWhite,
    277             ImageCache::getFromMemory(BinaryData::power_switch_down_png, BinaryData::power_switch_down_pngSize), 1.0, Colours::transparentWhite,
    278             0.0);
    279     }
    280     else {
    281         ampCleanLeadButton.setImages(true, true, true,
    282             ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
    283             Image(), 1.0, Colours::transparentWhite,
    284             ImageCache::getFromMemory(BinaryData::power_switch_up_png, BinaryData::power_switch_up_pngSize), 1.0, Colours::transparentWhite,
    285             0.0);
    286     }
    287     repaint();
    288 }
    289 
    290 float WaveNetVaComponent::getGuiScaleFactor()
    291 {
    292     return static_cast<float> (processor.gui_scale_factor);
    293 }
    294 
    295 void WaveNetVaComponent::persistGuiScaleFactor(float scaleFactor)
    296 {
    297     processor.gui_scale_factor = static_cast<double> (scaleFactor);
    298 }
    299 
    300 // Wrapper implementation
    301 WrappedWaveNetVaAudioProcessorEditor::WrappedWaveNetVaAudioProcessorEditor(WaveNetVaAudioProcessor& p)
    302     : AudioProcessorEditor(p), waveNetVaComponent(p)
    303 {
    304     addAndMakeVisible(waveNetVaComponent);
    305 
    306     if (auto* constrainer = getConstrainer())
    307     {
    308         constrainer->setFixedAspectRatio(static_cast<double> (originalWidth) / static_cast<double> (originalHeight));
    309         constrainer->setSizeLimits(originalWidth / 4, originalHeight / 4, originalWidth * 2, originalHeight * 2);
    310     }
    311 
    312     setResizable(true, true);    
    313     float scaledWidth = static_cast<float> (originalWidth) * waveNetVaComponent.getGuiScaleFactor();
    314     float scaledHeight = static_cast<float> (originalHeight) * waveNetVaComponent.getGuiScaleFactor();
    315     setSize(scaledWidth, scaledHeight);
    316     resetImages();
    317 }
    318 
    319 void WrappedWaveNetVaAudioProcessorEditor::resized()
    320 {
    321     const auto scaleFactor = static_cast<float> (getWidth()) / originalWidth;
    322     waveNetVaComponent.setTransform(AffineTransform::scale(scaleFactor));
    323     waveNetVaComponent.setBounds(0, 0, originalWidth, originalHeight);
    324     waveNetVaComponent.persistGuiScaleFactor(scaleFactor);
    325 }
    326 
    327 void WrappedWaveNetVaAudioProcessorEditor::resetImages()
    328 {
    329     waveNetVaComponent.resetImages();
    330 }