From 82f18ed4a0731f2184de8d1cd3002d7e1453f4a7 Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Wed, 3 Jul 2019 23:38:56 +0100 Subject: [PATCH] successfully notified release slider UI to move --- Source/PluginEditor.cpp | 6 ++-- Source/PluginEditor.h | 2 +- Source/PluginProcessor.cpp | 64 +++++++++++++++++++++++++++++++------ Source/PluginProcessor.h | 2 +- Source/SlidersComponent.cpp | 28 ++++++++-------- Source/SlidersComponent.h | 4 +-- 6 files changed, 76 insertions(+), 30 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 5531372..42b0f63 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -13,15 +13,15 @@ #include "GuiConstants.h" //============================================================================== -JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(JuicySFAudioProcessor& p, AudioProcessorValueTreeState& state) +JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(JuicySFAudioProcessor& p, AudioProcessorValueTreeState& valueTreeState) : AudioProcessorEditor{&p}, processor{p}, - state{state}, + valueTreeState{valueTreeState}, sharedParams{p.sharedParams}, midiKeyboard{p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard}, tablesComponent{p.getFluidSynthModel()}, filePicker{p.getFluidSynthModel()}, - slidersComponent{p.sharedParams, state, p.getFluidSynthModel()} + slidersComponent{p.sharedParams, valueTreeState, p.getFluidSynthModel()} { // set resize limits for this plug-in setResizeLimits( diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 6c2fd07..10ada3a 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -49,7 +49,7 @@ private: // access the processor object that created it. JuicySFAudioProcessor& processor; - AudioProcessorValueTreeState& state; + AudioProcessorValueTreeState& valueTreeState; shared_ptr sharedParams; SurjectiveMidiKeyboardComponent midiKeyboard; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index fb9e166..2090560 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -17,6 +17,7 @@ #include "Util.h" #include "SharesParams.h" #include "Params.h" +#include "MidiConstants.h" using namespace std; using Parameter = AudioProcessorValueTreeState::Parameter; @@ -28,7 +29,7 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter(); JuicySFAudioProcessor::JuicySFAudioProcessor() : AudioProcessor{getBusesProperties()} , sharedParams{static_pointer_cast(make_shared())} -, state{*this, nullptr, +, valueTreeState{*this, nullptr, { "PARAMETERS" /* MYPLUGINSETTINGS */ }, createParameterLayout() } @@ -45,7 +46,8 @@ AudioProcessorValueTreeState::ParameterLayout JuicySFAudioProcessor::createParam // for (int i = 1; i < 9; ++i) // params.push_back (std::make_unique (String (i), String (i), 0, i, 0)); - vector> params{ + // https://stackoverflow.com/a/8469002/5257399 + unique_ptr params[] = { make_unique("attack", "volume envelope attack time", 0, 127, 0, "A" ), make_unique("decay", "volume envelope sustain attentuation", 0, 127, 0, "D" ), make_unique("sustain", "volume envelope decay time", 0, 127, 0, "S" ), @@ -54,7 +56,10 @@ AudioProcessorValueTreeState::ParameterLayout JuicySFAudioProcessor::createParam make_unique("filterResonance", "low-pass filter resonance attentuation", 0, 127, 0, "Res" ), }; - return { params.begin(), params.end() }; + return { + make_move_iterator(begin(params)), + make_move_iterator(end(params)) + }; } JuicySFAudioProcessor::~JuicySFAudioProcessor() @@ -205,12 +210,53 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer fluid_synth_handle_midi_event(fluidSynth, midi_event); delete_fluid_midi_event(midi_event); - sharedParams->acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue()); + switch(static_cast(m.getControllerNumber())) { + case SOUND_CTRL2: { // MIDI CC 71 Timbre/Harmonic Intensity (filter resonance) + valueTreeState.state.setProperty({"filterResonance"}, m.getControllerValue(), nullptr); + break; + } + case SOUND_CTRL3: { // MIDI CC 72 Release time +// valueTreeState.state.setProperty({"release"}, m.getControllerValue(), nullptr); +// valueTreeState.state.flushParameterValuesToValueTree(); +// jassert(dynamic_cast (editor) != nullptr); + RangedAudioParameter *param {valueTreeState.getParameter("release")}; +// dynamic_cast(*param) + jassert(dynamic_cast (param) != nullptr); + AudioParameterInt* castParam {dynamic_cast (param)}; +// castParam->setValue(m.getControllerValue()); +// castParam-> +// param->setValue(m.getControllerValue()); +// param->setValueNotifyingHost(m.getControllerValue()); + *castParam = m.getControllerValue(); + break; + } + case SOUND_CTRL4: { // MIDI CC 73 Attack time + valueTreeState.state.setProperty({"attack"}, m.getControllerValue(), nullptr); + break; + } + case SOUND_CTRL5: { // MIDI CC 74 Brightness (cutoff frequency, FILTERFC) + valueTreeState.state.setProperty({"filterCutOff"}, m.getControllerValue(), nullptr); + break; + } + case SOUND_CTRL6: { // MIDI CC 75 Decay Time + valueTreeState.state.setProperty({"decay"}, m.getControllerValue(), nullptr); + break; + } + case SOUND_CTRL10: { // MIDI CC 79 undefined + valueTreeState.state.setProperty({"sustain"}, m.getControllerValue(), nullptr); + break; + } + default: { + break; + } + } - AudioProcessorEditor* editor{getActiveEditor()}; - jassert(dynamic_cast (editor) != nullptr); - ExposesComponents* exposesComponents{dynamic_cast(editor)}; - exposesComponents->getSliders().acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue()); + // sharedParams->acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue()); + + // AudioProcessorEditor* editor{getActiveEditor()}; + // jassert(dynamic_cast (editor) != nullptr); + // ExposesComponents* exposesComponents{dynamic_cast(editor)}; + // exposesComponents->getSliders().acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue()); } else if (m.isProgramChange()) { fluid_midi_event_t *midi_event(new_fluid_midi_event()); fluid_midi_event_set_type(midi_event, static_cast(PROGRAM_CHANGE)); @@ -291,7 +337,7 @@ bool JuicySFAudioProcessor::hasEditor() const AudioProcessorEditor* JuicySFAudioProcessor::createEditor() { // grab a raw pointer to it for our own use - return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this, state); + return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this, valueTreeState); } //============================================================================== diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 93554f2..a0599f8 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -74,7 +74,7 @@ public: private: void initialiseSynth(); - AudioProcessorValueTreeState state; + AudioProcessorValueTreeState valueTreeState; FluidSynthModel fluidSynthModel; fluid_synth_t* fluidSynth; diff --git a/Source/SlidersComponent.cpp b/Source/SlidersComponent.cpp index 608a7fd..edf88a5 100644 --- a/Source/SlidersComponent.cpp +++ b/Source/SlidersComponent.cpp @@ -106,10 +106,10 @@ void SlidersComponent::acceptMidiControlEvent(int controller, int value) { SlidersComponent::SlidersComponent( shared_ptr sharedParams, - AudioProcessorValueTreeState& state, + AudioProcessorValueTreeState& valueTreeState, FluidSynthModel* fluidSynthModel) : sharedParams{sharedParams} -, state{state} +, valueTreeState{valueTreeState} , fluidSynthModel{fluidSynthModel} , envelopeGroup{"envelopeGroup", "Envelope"} , filterGroup{"filterGroup", "Filter"} @@ -121,39 +121,39 @@ SlidersComponent::SlidersComponent( attackSlider.setSliderStyle(style); attackSlider.setRange(rangeMin, rangeMax, rangeStep); - attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast(SOUND_CTRL4)); + // attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast(SOUND_CTRL4)); attackSlider.setTextBoxStyle(Slider::TextBoxBelow, true, attackSlider.getTextBoxWidth(), attackSlider.getTextBoxHeight()); - attackSliderAttachment = make_unique(state, "attack", attackSlider); + attackSliderAttachment = make_unique(valueTreeState, "attack", attackSlider); decaySlider.setSliderStyle(style); decaySlider.setRange(rangeMin, rangeMax, rangeStep); - decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast(SOUND_CTRL6)); + // decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast(SOUND_CTRL6)); decaySlider.setTextBoxStyle(Slider::TextBoxBelow, true, decaySlider.getTextBoxWidth(), decaySlider.getTextBoxHeight()); - decaySliderAttachment = make_unique(state, "decay", decaySlider); + decaySliderAttachment = make_unique(valueTreeState, "decay", decaySlider); sustainSlider.setSliderStyle(style); sustainSlider.setRange(rangeMin, rangeMax, rangeStep); - sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast(SOUND_CTRL10)); + // sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast(SOUND_CTRL10)); sustainSlider.setTextBoxStyle(Slider::TextBoxBelow, true, sustainSlider.getTextBoxWidth(), sustainSlider.getTextBoxHeight()); - sustainSliderAttachment = make_unique(state, "sustain", sustainSlider); + sustainSliderAttachment = make_unique(valueTreeState, "sustain", sustainSlider); releaseSlider.setSliderStyle(style); releaseSlider.setRange(rangeMin, rangeMax, rangeStep); - releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast(SOUND_CTRL3)); + // releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast(SOUND_CTRL3)); releaseSlider.setTextBoxStyle(Slider::TextBoxBelow, true, releaseSlider.getTextBoxWidth(), releaseSlider.getTextBoxHeight()); - releaseSliderAttachment = make_unique(state, "release", releaseSlider); + releaseSliderAttachment = make_unique(valueTreeState, "release", releaseSlider); filterCutOffSlider.setSliderStyle(style); filterCutOffSlider.setRange(rangeMin, rangeMax, rangeStep); - filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast(SOUND_CTRL5)); + // filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast(SOUND_CTRL5)); filterCutOffSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterCutOffSlider.getTextBoxWidth(), filterCutOffSlider.getTextBoxHeight()); - filterCutOffSliderAttachment = make_unique(state, "filterCutOff", filterCutOffSlider); + filterCutOffSliderAttachment = make_unique(valueTreeState, "filterCutOff", filterCutOffSlider); filterResonanceSlider.setSliderStyle(style); filterResonanceSlider.setRange(rangeMin, rangeMax, rangeStep); - filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast(SOUND_CTRL2)); + // filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast(SOUND_CTRL2)); filterResonanceSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterResonanceSlider.getTextBoxWidth(), filterResonanceSlider.getTextBoxHeight()); - filterResonanceSliderAttachment = make_unique(state, "filterResonance", filterResonanceSlider); + filterResonanceSliderAttachment = make_unique(valueTreeState, "filterResonance", filterResonanceSlider); addAndMakeVisible(attackSlider); addAndMakeVisible(decaySlider); diff --git a/Source/SlidersComponent.h b/Source/SlidersComponent.h index cc8d1dc..613182c 100644 --- a/Source/SlidersComponent.h +++ b/Source/SlidersComponent.h @@ -14,7 +14,7 @@ class SlidersComponent : public Component, public: SlidersComponent( shared_ptr sharedParams, - AudioProcessorValueTreeState& state, + AudioProcessorValueTreeState& valueTreeState, FluidSynthModel* fluidSynthModel); ~SlidersComponent(); @@ -36,7 +36,7 @@ private: std::function makeSliderListener(Slider& slider, int controller); shared_ptr sharedParams; - AudioProcessorValueTreeState& state; + AudioProcessorValueTreeState& valueTreeState; FluidSynthModel* fluidSynthModel; GroupComponent envelopeGroup;