#include "PluginProcessor.h" #include "PluginEditor.h" void AnimationComp::paint(juce::Graphics &g) { tyal = backgroundColor.interpolatedWith(Colour(0xffffffff), fader.getCurrentValue()); g.fillAll(tyal); g.setColour(Colours::black); g.drawRect(getLocalBounds()); g.setFont(20); if (update) { if (fader.tick()) { update = false; } } g.drawText(String(fader.getStepNum()), getLocalBounds(), Justification::centred); } void AnimationComp::timerCallback() { if (update) { repaint(); } } void AnimationComp::mouseExit(const juce::MouseEvent &e) { DBG("MouseExited"); fader.setTargetValue(0.f, 200); anLook.fadeOut(0.f, 200); update = true; } void AnimationComp::mouseEnter(const juce::MouseEvent &e) { DBG("MouseEntered"); fader.setTargetValue(1.f, 30); anLook.fadeIn(1.f, 30); update = true; } void OtherLookAndFeel::drawRotarySlider(Graphics &g, int x, int y, int width, int height, float sliderPos, float rotaryStartAngle, float rotaryEndAngle, Slider &slider) { float diameter = 75; float radius = diameter / 2; float centreX = x + width / 2; float centreY = y + height / 2; float rx = centreX - radius; float ry = centreY - radius; rotaryStartAngle = 5.000f; rotaryEndAngle = 9.000f; float angle = rotaryEndAngle + (sliderPos * (rotaryEndAngle - rotaryStartAngle)); Rectangle dialArea(rx, ry, diameter, diameter); g.setColour(scar); g.fillEllipse(dialArea); Path dialTick; dialTick.addTriangle(radius / 2.0, radius / 6.0, radius / 2.0, -radius / 6.0, radius * 0.9, 0.0); dialTick.addEllipse(radius * 0.4, radius / 4.0, 5.0, 5.0); dialTick.addEllipse(radius * 0.2, radius / 2.0, 3.0, 3.0); dialTick.addEllipse(radius * 0.4, (-radius / 4.0) - 5.0, 5.0, 5.0); dialTick.addEllipse(radius * 0.2, (-radius / 2.0) - 5.0, 3.0, 3.0); g.setColour(Colours::coral); g.fillPath(dialTick, AffineTransform::rotation(angle).translated(centreX, centreY)); g.setColour(Colours::black); g.setFont(20); if (update1) { if (hfader.tick()) { update1 = false; } } g.drawText(String(hfader.getStepNum()), getLocalBounds(), Justification::centred); } void OtherLookAndFeel::fadeIn(float t, int n) { hfader.setTargetValue(t, n); update1 = true; } void OtherLookAndFeel::fadeOut(float t, int n) { hfader.setTargetValue(t, n); update1 = true; } //============================================================================== SpectrogramPluginAudioProcessorEditor::SpectrogramPluginAudioProcessorEditor(SpectrogramPluginAudioProcessor& p) : AudioProcessorEditor(&p), processor (p) { // Make sure that before the constructor has finished, you’ve set the // editor’s size to whatever you need it to be. addAndMakeVisible(&m_SpectroGramComp); addAndMakeVisible(comp); addAndMakeVisible(frequencySlider); frequencySlider.setSliderStyle(Slider::SliderStyle::RotaryHorizontalVerticalDrag); frequencySlider.setTextBoxStyle(Slider::TextBoxBelow, false,150,frequencySlider.getTextBoxHeight()); frequencySlider.setRange(20, 20000.0); frequencySlider.setTextValueSuffix(" Hz"); frequencySlider.onValueChange = [this] { processor.freq->setValueNotifyingHost (frequencySlider.getValue()); }; frequencySlider.setValue(processor.freq->get(), dontSendNotification); frequencySlider.setLookAndFeel(&otherLookAndFeel); addAndMakeVisible(frequencyLabel); frequencyLabel.setText("Frequency", dontSendNotification); frequencyLabel.attachToComponent(&frequencySlider, true); addAndMakeVisible(durationSlider); durationSlider.setRange(0.0 ,1.0); durationSlider.setTextValueSuffix(" Q"); durationSlider.onValueChange = [this] { processor.res->setValueNotifyingHost (durationSlider.getValue()); }; addAndMakeVisible(durationLabel); durationLabel.setText("Width", dontSendNotification); durationLabel.attachToComponent(&durationSlider, true); addAndMakeVisible(gainSlider); gainSlider.setRange(0.0, 1.0); gainSlider.setTextValueSuffix(" db"); gainSlider.setValue(processor.gain->get(), dontSendNotification); gainSlider.onValueChange = [this] { processor.gain->setValueNotifyingHost (gainSlider.getValue()); }; addAndMakeVisible(gainLabel); gainLabel.setText("Gain", dontSendNotification); gainLabel.attachToComponent(&gainSlider, true); // make the text boxes wider //frequencySlider.setTextBoxStyle(Slider::TextBoxLeft, false, 160, frequencySlider.getTextBoxHeight()); durationSlider.setTextBoxStyle(Slider::TextBoxLeft, false, 160, durationSlider.getTextBoxHeight()); gainSlider.setTextBoxStyle(Slider::TextBoxLeft, false, 160, gainSlider.getTextBoxHeight()); // change the skew of the sliders frequencySlider.setSkewFactorFromMidPoint(1500); durationSlider.setSkewFactorFromMidPoint(0.5); gainSlider.setSkewFactorFromMidPoint(0.5); setSize(800, 600); } SpectrogramPluginAudioProcessorEditor::~SpectrogramPluginAudioProcessorEditor() { } //============================================================================== void SpectrogramPluginAudioProcessorEditor::paint(Graphics& g) { // (Our component is opaque, so we must completely fill the background with a solid colour) g.fillAll(Colours::green); } void SpectrogramPluginAudioProcessorEditor::resized() { m_SpectroGramComp.setBounds(0, 0, getWidth(), getHeight()); comp.setBounds(getLocalBounds().withSizeKeepingCentre(200, 300)); auto sliderLeft = 120; frequencySlider.setBounds(200,300,100,100); durationSlider.setBounds(sliderLeft, 50, getWidth() - sliderLeft - 10, 20); gainSlider.setBounds(sliderLeft, 80, getWidth() - sliderLeft - 10, 20); }