102 lines
3.9 KiB
C++
102 lines
3.9 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
This file contains the basic framework code for a JUCE plugin editor.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#include "PluginProcessor.h"
|
|
#include "PluginEditor.h"
|
|
#include "ScopeComponent.h"
|
|
|
|
//==============================================================================
|
|
NeuralSynthAudioProcessorEditor::NeuralSynthAudioProcessorEditor (NeuralSynthAudioProcessor& p)
|
|
: AudioProcessorEditor (&p), audioProcessor (p), scopeComponent(audioProcessor.getAudioBufferQueue())
|
|
{
|
|
// Make sure that before the constructor has finished, you've set the
|
|
// editor's size to whatever you need it to be.
|
|
setSize(400, 500);
|
|
|
|
auto& tree = audioProcessor.parameters;
|
|
|
|
auto area = getLocalBounds();
|
|
scopeComponent.setTopLeftPosition(0, 0);
|
|
scopeComponent.setSize(400, 200);
|
|
|
|
addAndMakeVisible(scopeComponent);
|
|
|
|
attackAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(tree, "attack", attackSlider);
|
|
decayAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(tree, "decay", decaySlider);
|
|
sustainAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(tree, "sustain", sustainSlider);
|
|
releaseAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(tree, "release", releaseSlider);
|
|
|
|
addAndMakeVisible(waveformSelector);
|
|
|
|
waveformSelector.setTopLeftPosition(15, 225);
|
|
|
|
int leftPosition = 15;
|
|
const int sliderWidth = 60;
|
|
for (auto* slider : { &attackSlider, &decaySlider, &sustainSlider, &releaseSlider })
|
|
{
|
|
slider->setSliderStyle(juce::Slider::Rotary);
|
|
slider->setTextBoxStyle(juce::Slider::TextBoxBelow, false, sliderWidth, 20);
|
|
addAndMakeVisible(*slider);
|
|
slider->setTopLeftPosition(leftPosition, 250);
|
|
leftPosition += (sliderWidth + 40);
|
|
}
|
|
|
|
waveformSelector.addItem("Sine", 1);
|
|
waveformSelector.addItem("Saw", 2);
|
|
waveformSelector.addItem("Square", 3);
|
|
waveformSelector.addItem("Triangle", 4);
|
|
|
|
|
|
// Attach to parameter
|
|
waveformAttachment = std::make_unique<juce::AudioProcessorValueTreeState::ComboBoxAttachment>(
|
|
audioProcessor.parameters, "waveform", waveformSelector);
|
|
|
|
addAndMakeVisible(midiKeyboardComponent);
|
|
|
|
|
|
//scopeComponent.setSize(area.getWidth(), area.getHeight());
|
|
|
|
midiKeyboardComponent.setMidiChannel(2);
|
|
midiKeyboardState.addListener(&audioProcessor.getMidiMessageCollector());
|
|
|
|
midiKeyboardComponent.setBounds(area.removeFromTop(80).reduced(8));
|
|
midiKeyboardComponent.setTopLeftPosition(8, 420);
|
|
}
|
|
|
|
NeuralSynthAudioProcessorEditor::~NeuralSynthAudioProcessorEditor()
|
|
{
|
|
}
|
|
|
|
//==============================================================================
|
|
void NeuralSynthAudioProcessorEditor::paint (juce::Graphics& g)
|
|
{
|
|
// (Our component is opaque, so we must completely fill the background with a solid colour)
|
|
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
|
|
|
|
//g.setColour (juce::Colours::white);
|
|
//g.setFont (juce::FontOptions (15.0f));
|
|
//g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1);
|
|
}
|
|
|
|
void NeuralSynthAudioProcessorEditor::resized()
|
|
{
|
|
// This is generally where you'll want to lay out the positions of any
|
|
// subcomponents in your editor..
|
|
auto bounds = getLocalBounds().reduced(20);
|
|
auto row = bounds.removeFromTop(150);
|
|
|
|
int knobWidth = row.getWidth() / 4;
|
|
|
|
attackSlider.setBounds(row.removeFromLeft(knobWidth).reduced(10));
|
|
decaySlider.setBounds(row.removeFromLeft(knobWidth).reduced(10));
|
|
sustainSlider.setBounds(row.removeFromLeft(knobWidth).reduced(10));
|
|
releaseSlider.setBounds(row.removeFromLeft(knobWidth).reduced(10));
|
|
|
|
waveformSelector.setBounds(20, 20, 120, 30);
|
|
}
|