From 9d39d3c9ce9a741d4f6fc739e2ed713860c14b29 Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Sat, 10 Aug 2019 23:18:43 +0100 Subject: [PATCH] restore preset and bank _after_ soundfont (upon whose successful loading they depend). notify listeners (i.e. fluidsynthmodel) --- Source/FluidSynthModel.cpp | 23 ++++++++--------------- Source/PluginProcessor.cpp | 14 ++++++++------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index a3d89e2..2cc6507 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -73,10 +73,6 @@ void FluidSynthModel::initialise() { synth = { new_fluid_synth(settings.get()), delete_fluid_synth }; fluid_synth_set_sample_rate(synth.get(), currentSampleRate); - - ValueTree soundFont{valueTreeState.state.getChildWithName("soundFont")}; - String path = soundFont.getProperty("path", ""); - loadFont(path); // I can't hear a damned thing fluid_synth_set_gain(synth.get(), 2.0); @@ -88,17 +84,9 @@ void FluidSynthModel::initialise() { // and yet, I'm finding that default modulators start at MIN, // i.e. we are forced to start at 0 and climb from there // -- - // let's loop through all audio params that we manage, - // restore them to whatever value we have stored for them - // (which by default would be 0) - // super likely to be 0 regardless, since JuicySFAudioProcessor::initialise() - // runs earlier than JuicySFAudioProcessor::setStateInformation() - for (const auto &[controller, parameterID]: controllerToParam) { - RangedAudioParameter *param{valueTreeState.getParameter(parameterID)}; - jassert(dynamic_cast(param) != nullptr); - AudioParameterInt* castParam{dynamic_cast(param)}; - int value{castParam->get()}; - setControllerValue(static_cast(controller), value); + // let's zero out every audio param that we manage + for (const auto &[controller, param]: controllerToParam) { + setControllerValue(static_cast(controller), 0); } // http://www.synthfont.com/SoundFont_NRPNs.PDF @@ -355,6 +343,11 @@ void FluidSynthModel::processBlock(AudioBuffer& buffer, MidiBuffer& midiM *castParam = m.getControllerValue(); } } else if (m.isProgramChange()) { +#if JUCE_DEBUG + String debug{"MIDI program change: "}; + debug << m.getProgramChangeNumber(); + Logger::outputDebugString(debug); +#endif int result{fluid_synth_program_change( synth.get(), channel, diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index dfb9255..7331d41 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -260,12 +260,6 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt if (xmlState.get() != nullptr) { // make sure that it's actually our type of XML object.. if (xmlState->hasTagName(valueTreeState.state.getType())) { - XmlElement* params{xmlState->getChildByName("params")}; - if (params) - for (auto* param : getParameters()) - if (auto* p = dynamic_cast(param)) - p->setValue(static_cast(params->getDoubleAttribute(p->paramID, p->getValue()))); - { XmlElement* xmlElement{xmlState->getChildByName("soundFont")}; if (xmlElement) { @@ -288,6 +282,14 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt } } } + XmlElement* params{xmlState->getChildByName("params")}; + if (params) { + for (auto* param : getParameters()) { + if (auto* p = dynamic_cast(param)) { + p->setValueNotifyingHost(static_cast(params->getDoubleAttribute(p->paramID, p->getValue()))); + } + } + } } } }