2023-08-29 19:47:13 +00:00
|
|
|
#include "MidiComponent.h"
|
|
|
|
#include "PluginEditor.h"
|
|
|
|
|
|
|
|
MidiComponent::MidiComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
|
2023-12-18 13:41:56 +00:00
|
|
|
setText("MIDI Settings");
|
|
|
|
|
2023-08-29 19:47:13 +00:00
|
|
|
addAndMakeVisible(midiToggle);
|
2024-03-29 21:53:48 +00:00
|
|
|
addAndMakeVisible(midiLabel);
|
2023-12-21 14:14:33 +00:00
|
|
|
addAndMakeVisible(voicesSlider);
|
|
|
|
addAndMakeVisible(voicesLabel);
|
2023-08-29 19:47:13 +00:00
|
|
|
addAndMakeVisible(keyboard);
|
2023-09-10 17:52:21 +00:00
|
|
|
|
|
|
|
midiToggle.setToggleState(audioProcessor.midiEnabled->getBoolValue(), juce::dontSendNotification);
|
2023-12-21 14:14:33 +00:00
|
|
|
midiToggle.setTooltip("Enable MIDI input for the synth. If disabled, the synth will play a constant tone, as controlled by the frequency slider.");
|
2023-09-07 21:04:08 +00:00
|
|
|
|
|
|
|
midiToggle.onClick = [this]() {
|
|
|
|
audioProcessor.midiEnabled->setBoolValueNotifyingHost(midiToggle.getToggleState());
|
|
|
|
};
|
2023-11-25 15:37:33 +00:00
|
|
|
|
2023-12-21 14:14:33 +00:00
|
|
|
audioProcessor.midiEnabled->addListener(this);
|
|
|
|
|
|
|
|
voicesSlider.setRange(1, 16, 1);
|
|
|
|
voicesSlider.setValue(audioProcessor.voices->getValueUnnormalised(), juce::dontSendNotification);
|
|
|
|
voicesSlider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 50, 20);
|
|
|
|
|
|
|
|
voicesLabel.setText("Voices", juce::dontSendNotification);
|
|
|
|
voicesLabel.attachToComponent(&voicesSlider, true);
|
|
|
|
voicesLabel.setTooltip("Number of voices for the synth to use. Larger numbers will use more CPU, and may cause audio glitches.");
|
|
|
|
|
|
|
|
voicesSlider.onValueChange = [this]() {
|
|
|
|
audioProcessor.voices->setUnnormalisedValueNotifyingHost(voicesSlider.getValue());
|
|
|
|
};
|
|
|
|
|
|
|
|
audioProcessor.voices->addListener(this);
|
|
|
|
|
2023-11-25 15:37:33 +00:00
|
|
|
addAndMakeVisible(envelope);
|
|
|
|
envelope.setAdsrMode(true);
|
|
|
|
envelope.setEnv(audioProcessor.adsrEnv);
|
|
|
|
envelope.addListener(&audioProcessor);
|
2023-12-18 13:41:56 +00:00
|
|
|
envelope.setGrid(EnvelopeComponent::GridBoth, EnvelopeComponent::GridNone, 0.1, 0.25);
|
2023-11-25 15:37:33 +00:00
|
|
|
|
2024-01-31 17:08:00 +00:00
|
|
|
if (juce::JUCEApplicationBase::isStandaloneApp()) {
|
|
|
|
addAndMakeVisible(midiSettingsButton);
|
|
|
|
midiSettingsButton.onClick = [this]() {
|
|
|
|
pluginEditor.openAudioSettings();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-25 16:38:09 +00:00
|
|
|
audioProcessor.attackTime->addListener(this);
|
|
|
|
audioProcessor.attackLevel->addListener(this);
|
|
|
|
audioProcessor.attackShape->addListener(this);
|
|
|
|
audioProcessor.decayTime->addListener(this);
|
|
|
|
audioProcessor.decayShape->addListener(this);
|
|
|
|
audioProcessor.sustainLevel->addListener(this);
|
|
|
|
audioProcessor.releaseTime->addListener(this);
|
|
|
|
audioProcessor.releaseShape->addListener(this);
|
2023-12-21 14:43:15 +00:00
|
|
|
|
|
|
|
handleAsyncUpdate();
|
2023-08-29 19:47:13 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 15:37:33 +00:00
|
|
|
MidiComponent::~MidiComponent() {
|
|
|
|
envelope.removeListener(&audioProcessor);
|
2023-11-25 16:38:09 +00:00
|
|
|
audioProcessor.attackTime->removeListener(this);
|
|
|
|
audioProcessor.attackLevel->removeListener(this);
|
|
|
|
audioProcessor.attackShape->removeListener(this);
|
|
|
|
audioProcessor.decayTime->removeListener(this);
|
|
|
|
audioProcessor.decayShape->removeListener(this);
|
|
|
|
audioProcessor.sustainLevel->removeListener(this);
|
|
|
|
audioProcessor.releaseTime->removeListener(this);
|
|
|
|
audioProcessor.releaseShape->removeListener(this);
|
2023-12-21 14:14:33 +00:00
|
|
|
|
|
|
|
audioProcessor.midiEnabled->removeListener(this);
|
|
|
|
audioProcessor.voices->removeListener(this);
|
2023-11-25 15:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MidiComponent::parameterValueChanged(int parameterIndex, float newValue) {
|
|
|
|
triggerAsyncUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiComponent::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) {}
|
|
|
|
|
|
|
|
void MidiComponent::handleAsyncUpdate() {
|
2023-12-21 14:14:33 +00:00
|
|
|
midiToggle.setToggleState(audioProcessor.midiEnabled->getBoolValue(), juce::dontSendNotification);
|
|
|
|
voicesSlider.setValue(audioProcessor.voices->getValueUnnormalised(), juce::dontSendNotification);
|
|
|
|
|
2023-11-25 16:38:09 +00:00
|
|
|
Env newEnv = Env(
|
|
|
|
{
|
|
|
|
0.0,
|
|
|
|
audioProcessor.attackLevel->getValueUnnormalised(),
|
|
|
|
audioProcessor.sustainLevel->getValueUnnormalised(),
|
|
|
|
0.0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
audioProcessor.attackTime->getValueUnnormalised(),
|
|
|
|
audioProcessor.decayTime->getValueUnnormalised(),
|
|
|
|
audioProcessor.releaseTime->getValueUnnormalised()
|
|
|
|
},
|
|
|
|
std::vector<EnvCurve>{ audioProcessor.attackShape->getValueUnnormalised(), audioProcessor.decayShape->getValueUnnormalised(), audioProcessor.releaseShape->getValueUnnormalised() },
|
|
|
|
2
|
2023-11-25 15:37:33 +00:00
|
|
|
);
|
|
|
|
|
2023-11-25 17:57:35 +00:00
|
|
|
{
|
|
|
|
juce::SpinLock::ScopedLockType lock(audioProcessor.effectsLock);
|
|
|
|
audioProcessor.adsrEnv = newEnv;
|
|
|
|
}
|
|
|
|
|
2023-11-25 15:37:33 +00:00
|
|
|
envelope.setEnv(newEnv);
|
|
|
|
}
|
2023-08-29 19:47:13 +00:00
|
|
|
|
|
|
|
void MidiComponent::resized() {
|
2023-12-18 13:41:56 +00:00
|
|
|
auto area = getLocalBounds().withTrimmedTop(20).reduced(20);
|
2023-12-21 14:14:33 +00:00
|
|
|
auto topRow = area.removeFromTop(30);
|
2024-03-29 21:53:48 +00:00
|
|
|
auto midiToggleBounds = topRow.removeFromLeft(120);
|
|
|
|
midiToggle.setBounds(midiToggleBounds.removeFromLeft(30).withSizeKeepingCentre(30, 20).translated(0, 1));
|
|
|
|
midiLabel.setBounds(midiToggleBounds);
|
2023-12-21 14:14:33 +00:00
|
|
|
topRow.removeFromLeft(80);
|
|
|
|
voicesSlider.setBounds(topRow.removeFromLeft(250));
|
2024-01-31 17:08:00 +00:00
|
|
|
if (midiSettingsButton.isVisible()) {
|
|
|
|
midiSettingsButton.setBounds(topRow.removeFromRight(160));
|
|
|
|
}
|
2023-12-18 13:41:56 +00:00
|
|
|
area.removeFromTop(5);
|
|
|
|
keyboard.setBounds(area.removeFromBottom(50));
|
|
|
|
envelope.setBounds(area);
|
2023-08-29 19:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MidiComponent::paint(juce::Graphics& g) {
|
2023-12-18 13:41:56 +00:00
|
|
|
juce::GroupComponent::paint(g);
|
2023-08-29 19:47:13 +00:00
|
|
|
}
|