juicysfplugin/Source/PluginEditor.cpp

126 lines
4.1 KiB
C++
Raw Permalink Normal View History

2018-02-27 08:17:12 +08:00
/*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "GuiConstants.h"
2018-02-27 08:17:12 +08:00
//==============================================================================
JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(
JuicySFAudioProcessor& p,
AudioProcessorValueTreeState& valueTreeState)
: AudioProcessorEditor{&p}
, processor{p}
, valueTreeState{valueTreeState}
, midiKeyboard{p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard}
, tablesComponent{valueTreeState}
, filePicker{valueTreeState}
, slidersComponent{valueTreeState, p.getFluidSynthModel()}
2018-02-27 08:17:12 +08:00
{
2021-09-07 14:04:35 +08:00
setResizable(true, true);
2018-02-27 08:25:20 +08:00
// set resize limits for this plug-in
setResizeLimits(
GuiConstants::minWidth,
GuiConstants::minHeight,
GuiConstants::maxWidth,
GuiConstants::maxHeight);
2019-07-09 06:36:27 +08:00
lastUIWidth.referTo(valueTreeState.state.getChildWithName("uiState").getPropertyAsValue("width", nullptr));
lastUIHeight.referTo(valueTreeState.state.getChildWithName("uiState").getPropertyAsValue("height", nullptr));
// set our component's initial size to be the last one that was stored in the filter's settings
setSize(lastUIWidth.getValue(), lastUIHeight.getValue());
lastUIWidth.addListener(this);
lastUIHeight.addListener(this);
2018-02-27 08:25:20 +08:00
midiKeyboard.setName ("MIDI Keyboard");
midiKeyboard.setWantsKeyboardFocus(false);
tablesComponent.setWantsKeyboardFocus(false);
setWantsKeyboardFocus(true);
addAndMakeVisible(midiKeyboard);
2018-02-27 08:25:20 +08:00
2019-06-30 17:59:07 +08:00
addAndMakeVisible(slidersComponent);
2018-02-27 08:25:20 +08:00
addAndMakeVisible(tablesComponent);
addAndMakeVisible(filePicker);
2019-06-30 17:59:07 +08:00
2018-02-27 08:17:12 +08:00
}
2019-07-09 06:36:27 +08:00
// called when the stored window size changes
void JuicySFAudioProcessorEditor::valueChanged(Value&) {
setSize(lastUIWidth.getValue(), lastUIHeight.getValue());
}
2018-02-28 07:34:22 +08:00
JuicySFAudioProcessorEditor::~JuicySFAudioProcessorEditor()
2018-02-27 08:17:12 +08:00
{
2019-07-09 06:36:27 +08:00
lastUIWidth.removeListener(this);
lastUIHeight.removeListener(this);
}
2018-02-27 08:17:12 +08:00
//==============================================================================
2018-02-28 07:34:22 +08:00
void JuicySFAudioProcessorEditor::paint (Graphics& g)
2018-02-27 08:17:12 +08:00
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
2018-02-27 08:25:20 +08:00
if (!focusInitialized) {
if (!hasKeyboardFocus(false) && isVisible()) {
grabKeyboardFocus();
}
if (getCurrentlyFocusedComponent() == this) {
focusInitialized = true;
}
}
2018-02-27 08:17:12 +08:00
}
2018-02-28 07:34:22 +08:00
void JuicySFAudioProcessorEditor::resized()
2018-02-27 08:17:12 +08:00
{
2019-06-30 17:59:07 +08:00
const int padding{8};
const int pianoHeight{70};
const int filePickerHeight{25};
2019-06-30 18:39:39 +08:00
Rectangle<int> r{getLocalBounds()};
2018-02-27 08:25:20 +08:00
filePicker.setBounds(r.removeFromTop(filePickerHeight + padding).reduced(padding, 0).withTrimmedTop(padding));
2019-06-30 17:59:07 +08:00
2018-02-27 08:25:20 +08:00
midiKeyboard.setBounds (r.removeFromBottom (pianoHeight).reduced(padding, 0));
2019-06-30 18:39:39 +08:00
Rectangle<int> rContent{r.reduced(0, padding)};
slidersComponent.setBounds(rContent.removeFromRight(slidersComponent.getDesiredWidth() + padding).withTrimmedRight(padding));
tablesComponent.setBounds(rContent);
2019-07-09 06:36:27 +08:00
lastUIWidth = getWidth();
lastUIHeight = getHeight();
2018-02-27 08:17:12 +08:00
}
2018-02-27 08:25:20 +08:00
2018-02-28 07:34:22 +08:00
bool JuicySFAudioProcessorEditor::keyPressed(const KeyPress &key) {
2018-02-27 08:25:20 +08:00
const int cursorKeys[] = {
KeyPress::leftKey,
KeyPress::rightKey,
KeyPress::upKey,
KeyPress::downKey
};
if (any_of(
begin(cursorKeys),
end(cursorKeys),
[&](int i) { return i == key.getKeyCode(); }
)) {
return tablesComponent.keyPressed(key);
} else {
return midiKeyboard.keyPressed(key);
}
return false;
}
2018-02-28 07:34:22 +08:00
bool JuicySFAudioProcessorEditor::keyStateChanged (bool isKeyDown) {
2018-02-27 08:25:20 +08:00
return midiKeyboard.keyStateChanged(isKeyDown);
}