successfully notified release slider UI to move

This commit is contained in:
Alex Birch 2019-07-03 23:38:56 +01:00
parent 1fe64e31f7
commit 82f18ed4a0
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
6 changed files with 76 additions and 30 deletions

View File

@ -13,15 +13,15 @@
#include "GuiConstants.h" #include "GuiConstants.h"
//============================================================================== //==============================================================================
JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(JuicySFAudioProcessor& p, AudioProcessorValueTreeState& state) JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(JuicySFAudioProcessor& p, AudioProcessorValueTreeState& valueTreeState)
: AudioProcessorEditor{&p}, : AudioProcessorEditor{&p},
processor{p}, processor{p},
state{state}, valueTreeState{valueTreeState},
sharedParams{p.sharedParams}, sharedParams{p.sharedParams},
midiKeyboard{p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard}, midiKeyboard{p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard},
tablesComponent{p.getFluidSynthModel()}, tablesComponent{p.getFluidSynthModel()},
filePicker{p.getFluidSynthModel()}, filePicker{p.getFluidSynthModel()},
slidersComponent{p.sharedParams, state, p.getFluidSynthModel()} slidersComponent{p.sharedParams, valueTreeState, p.getFluidSynthModel()}
{ {
// set resize limits for this plug-in // set resize limits for this plug-in
setResizeLimits( setResizeLimits(

View File

@ -49,7 +49,7 @@ private:
// access the processor object that created it. // access the processor object that created it.
JuicySFAudioProcessor& processor; JuicySFAudioProcessor& processor;
AudioProcessorValueTreeState& state; AudioProcessorValueTreeState& valueTreeState;
shared_ptr<SharesParams> sharedParams; shared_ptr<SharesParams> sharedParams;
SurjectiveMidiKeyboardComponent midiKeyboard; SurjectiveMidiKeyboardComponent midiKeyboard;

View File

@ -17,6 +17,7 @@
#include "Util.h" #include "Util.h"
#include "SharesParams.h" #include "SharesParams.h"
#include "Params.h" #include "Params.h"
#include "MidiConstants.h"
using namespace std; using namespace std;
using Parameter = AudioProcessorValueTreeState::Parameter; using Parameter = AudioProcessorValueTreeState::Parameter;
@ -28,7 +29,7 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter();
JuicySFAudioProcessor::JuicySFAudioProcessor() JuicySFAudioProcessor::JuicySFAudioProcessor()
: AudioProcessor{getBusesProperties()} : AudioProcessor{getBusesProperties()}
, sharedParams{static_pointer_cast<SharesParams>(make_shared<Params>())} , sharedParams{static_pointer_cast<SharesParams>(make_shared<Params>())}
, state{*this, nullptr, , valueTreeState{*this, nullptr,
{ "PARAMETERS" /* MYPLUGINSETTINGS */ }, { "PARAMETERS" /* MYPLUGINSETTINGS */ },
createParameterLayout() createParameterLayout()
} }
@ -45,7 +46,8 @@ AudioProcessorValueTreeState::ParameterLayout JuicySFAudioProcessor::createParam
// for (int i = 1; i < 9; ++i) // for (int i = 1; i < 9; ++i)
// params.push_back (std::make_unique<AudioParameterInt> (String (i), String (i), 0, i, 0)); // params.push_back (std::make_unique<AudioParameterInt> (String (i), String (i), 0, i, 0));
vector<unique_ptr<AudioParameterInt>> params{ // https://stackoverflow.com/a/8469002/5257399
unique_ptr<AudioParameterInt> params[] = {
make_unique<AudioParameterInt>("attack", "volume envelope attack time", 0, 127, 0, "A" ), make_unique<AudioParameterInt>("attack", "volume envelope attack time", 0, 127, 0, "A" ),
make_unique<AudioParameterInt>("decay", "volume envelope sustain attentuation", 0, 127, 0, "D" ), make_unique<AudioParameterInt>("decay", "volume envelope sustain attentuation", 0, 127, 0, "D" ),
make_unique<AudioParameterInt>("sustain", "volume envelope decay time", 0, 127, 0, "S" ), make_unique<AudioParameterInt>("sustain", "volume envelope decay time", 0, 127, 0, "S" ),
@ -54,7 +56,10 @@ AudioProcessorValueTreeState::ParameterLayout JuicySFAudioProcessor::createParam
make_unique<AudioParameterInt>("filterResonance", "low-pass filter resonance attentuation", 0, 127, 0, "Res" ), make_unique<AudioParameterInt>("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() JuicySFAudioProcessor::~JuicySFAudioProcessor()
@ -205,12 +210,53 @@ void JuicySFAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer
fluid_synth_handle_midi_event(fluidSynth, midi_event); fluid_synth_handle_midi_event(fluidSynth, midi_event);
delete_fluid_midi_event(midi_event); delete_fluid_midi_event(midi_event);
sharedParams->acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue()); switch(static_cast<fluid_midi_control_change>(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<ExposesComponents*> (editor) != nullptr);
RangedAudioParameter *param {valueTreeState.getParameter("release")};
// dynamic_cast<AudioParameterInt&>(*param)
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (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()}; // sharedParams->acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue());
jassert(dynamic_cast<ExposesComponents*> (editor) != nullptr);
ExposesComponents* exposesComponents{dynamic_cast<ExposesComponents*>(editor)}; // AudioProcessorEditor* editor{getActiveEditor()};
exposesComponents->getSliders().acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue()); // jassert(dynamic_cast<ExposesComponents*> (editor) != nullptr);
// ExposesComponents* exposesComponents{dynamic_cast<ExposesComponents*>(editor)};
// exposesComponents->getSliders().acceptMidiControlEvent(m.getControllerNumber(), m.getControllerValue());
} else if (m.isProgramChange()) { } else if (m.isProgramChange()) {
fluid_midi_event_t *midi_event(new_fluid_midi_event()); fluid_midi_event_t *midi_event(new_fluid_midi_event());
fluid_midi_event_set_type(midi_event, static_cast<int>(PROGRAM_CHANGE)); fluid_midi_event_set_type(midi_event, static_cast<int>(PROGRAM_CHANGE));
@ -291,7 +337,7 @@ bool JuicySFAudioProcessor::hasEditor() const
AudioProcessorEditor* JuicySFAudioProcessor::createEditor() AudioProcessorEditor* JuicySFAudioProcessor::createEditor()
{ {
// grab a raw pointer to it for our own use // grab a raw pointer to it for our own use
return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this, state); return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this, valueTreeState);
} }
//============================================================================== //==============================================================================

View File

@ -74,7 +74,7 @@ public:
private: private:
void initialiseSynth(); void initialiseSynth();
AudioProcessorValueTreeState state; AudioProcessorValueTreeState valueTreeState;
FluidSynthModel fluidSynthModel; FluidSynthModel fluidSynthModel;
fluid_synth_t* fluidSynth; fluid_synth_t* fluidSynth;

View File

@ -106,10 +106,10 @@ void SlidersComponent::acceptMidiControlEvent(int controller, int value) {
SlidersComponent::SlidersComponent( SlidersComponent::SlidersComponent(
shared_ptr<SharesParams> sharedParams, shared_ptr<SharesParams> sharedParams,
AudioProcessorValueTreeState& state, AudioProcessorValueTreeState& valueTreeState,
FluidSynthModel* fluidSynthModel) FluidSynthModel* fluidSynthModel)
: sharedParams{sharedParams} : sharedParams{sharedParams}
, state{state} , valueTreeState{valueTreeState}
, fluidSynthModel{fluidSynthModel} , fluidSynthModel{fluidSynthModel}
, envelopeGroup{"envelopeGroup", "Envelope"} , envelopeGroup{"envelopeGroup", "Envelope"}
, filterGroup{"filterGroup", "Filter"} , filterGroup{"filterGroup", "Filter"}
@ -121,39 +121,39 @@ SlidersComponent::SlidersComponent(
attackSlider.setSliderStyle(style); attackSlider.setSliderStyle(style);
attackSlider.setRange(rangeMin, rangeMax, rangeStep); attackSlider.setRange(rangeMin, rangeMax, rangeStep);
attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast<int>(SOUND_CTRL4)); // attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast<int>(SOUND_CTRL4));
attackSlider.setTextBoxStyle(Slider::TextBoxBelow, true, attackSlider.getTextBoxWidth(), attackSlider.getTextBoxHeight()); attackSlider.setTextBoxStyle(Slider::TextBoxBelow, true, attackSlider.getTextBoxWidth(), attackSlider.getTextBoxHeight());
attackSliderAttachment = make_unique<SliderAttachment>(state, "attack", attackSlider); attackSliderAttachment = make_unique<SliderAttachment>(valueTreeState, "attack", attackSlider);
decaySlider.setSliderStyle(style); decaySlider.setSliderStyle(style);
decaySlider.setRange(rangeMin, rangeMax, rangeStep); decaySlider.setRange(rangeMin, rangeMax, rangeStep);
decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast<int>(SOUND_CTRL6)); // decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast<int>(SOUND_CTRL6));
decaySlider.setTextBoxStyle(Slider::TextBoxBelow, true, decaySlider.getTextBoxWidth(), decaySlider.getTextBoxHeight()); decaySlider.setTextBoxStyle(Slider::TextBoxBelow, true, decaySlider.getTextBoxWidth(), decaySlider.getTextBoxHeight());
decaySliderAttachment = make_unique<SliderAttachment>(state, "decay", decaySlider); decaySliderAttachment = make_unique<SliderAttachment>(valueTreeState, "decay", decaySlider);
sustainSlider.setSliderStyle(style); sustainSlider.setSliderStyle(style);
sustainSlider.setRange(rangeMin, rangeMax, rangeStep); sustainSlider.setRange(rangeMin, rangeMax, rangeStep);
sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast<int>(SOUND_CTRL10)); // sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast<int>(SOUND_CTRL10));
sustainSlider.setTextBoxStyle(Slider::TextBoxBelow, true, sustainSlider.getTextBoxWidth(), sustainSlider.getTextBoxHeight()); sustainSlider.setTextBoxStyle(Slider::TextBoxBelow, true, sustainSlider.getTextBoxWidth(), sustainSlider.getTextBoxHeight());
sustainSliderAttachment = make_unique<SliderAttachment>(state, "sustain", sustainSlider); sustainSliderAttachment = make_unique<SliderAttachment>(valueTreeState, "sustain", sustainSlider);
releaseSlider.setSliderStyle(style); releaseSlider.setSliderStyle(style);
releaseSlider.setRange(rangeMin, rangeMax, rangeStep); releaseSlider.setRange(rangeMin, rangeMax, rangeStep);
releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast<int>(SOUND_CTRL3)); // releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast<int>(SOUND_CTRL3));
releaseSlider.setTextBoxStyle(Slider::TextBoxBelow, true, releaseSlider.getTextBoxWidth(), releaseSlider.getTextBoxHeight()); releaseSlider.setTextBoxStyle(Slider::TextBoxBelow, true, releaseSlider.getTextBoxWidth(), releaseSlider.getTextBoxHeight());
releaseSliderAttachment = make_unique<SliderAttachment>(state, "release", releaseSlider); releaseSliderAttachment = make_unique<SliderAttachment>(valueTreeState, "release", releaseSlider);
filterCutOffSlider.setSliderStyle(style); filterCutOffSlider.setSliderStyle(style);
filterCutOffSlider.setRange(rangeMin, rangeMax, rangeStep); filterCutOffSlider.setRange(rangeMin, rangeMax, rangeStep);
filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast<int>(SOUND_CTRL5)); // filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast<int>(SOUND_CTRL5));
filterCutOffSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterCutOffSlider.getTextBoxWidth(), filterCutOffSlider.getTextBoxHeight()); filterCutOffSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterCutOffSlider.getTextBoxWidth(), filterCutOffSlider.getTextBoxHeight());
filterCutOffSliderAttachment = make_unique<SliderAttachment>(state, "filterCutOff", filterCutOffSlider); filterCutOffSliderAttachment = make_unique<SliderAttachment>(valueTreeState, "filterCutOff", filterCutOffSlider);
filterResonanceSlider.setSliderStyle(style); filterResonanceSlider.setSliderStyle(style);
filterResonanceSlider.setRange(rangeMin, rangeMax, rangeStep); filterResonanceSlider.setRange(rangeMin, rangeMax, rangeStep);
filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast<int>(SOUND_CTRL2)); // filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast<int>(SOUND_CTRL2));
filterResonanceSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterResonanceSlider.getTextBoxWidth(), filterResonanceSlider.getTextBoxHeight()); filterResonanceSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterResonanceSlider.getTextBoxWidth(), filterResonanceSlider.getTextBoxHeight());
filterResonanceSliderAttachment = make_unique<SliderAttachment>(state, "filterResonance", filterResonanceSlider); filterResonanceSliderAttachment = make_unique<SliderAttachment>(valueTreeState, "filterResonance", filterResonanceSlider);
addAndMakeVisible(attackSlider); addAndMakeVisible(attackSlider);
addAndMakeVisible(decaySlider); addAndMakeVisible(decaySlider);

View File

@ -14,7 +14,7 @@ class SlidersComponent : public Component,
public: public:
SlidersComponent( SlidersComponent(
shared_ptr<SharesParams> sharedParams, shared_ptr<SharesParams> sharedParams,
AudioProcessorValueTreeState& state, AudioProcessorValueTreeState& valueTreeState,
FluidSynthModel* fluidSynthModel); FluidSynthModel* fluidSynthModel);
~SlidersComponent(); ~SlidersComponent();
@ -36,7 +36,7 @@ private:
std::function<void()> makeSliderListener(Slider& slider, int controller); std::function<void()> makeSliderListener(Slider& slider, int controller);
shared_ptr<SharesParams> sharedParams; shared_ptr<SharesParams> sharedParams;
AudioProcessorValueTreeState& state; AudioProcessorValueTreeState& valueTreeState;
FluidSynthModel* fluidSynthModel; FluidSynthModel* fluidSynthModel;
GroupComponent envelopeGroup; GroupComponent envelopeGroup;