restore preset and bank _after_ soundfont (upon whose successful loading they depend). notify listeners (i.e. fluidsynthmodel)

This commit is contained in:
Alex Birch 2019-08-10 23:18:43 +01:00
parent f9a28c36e7
commit 9d39d3c9ce
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
2 changed files with 16 additions and 21 deletions

View File

@ -74,10 +74,6 @@ void FluidSynthModel::initialise() {
synth = { new_fluid_synth(settings.get()), delete_fluid_synth }; synth = { new_fluid_synth(settings.get()), delete_fluid_synth };
fluid_synth_set_sample_rate(synth.get(), currentSampleRate); 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 // I can't hear a damned thing
fluid_synth_set_gain(synth.get(), 2.0); 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, // and yet, I'm finding that default modulators start at MIN,
// i.e. we are forced to start at 0 and climb from there // i.e. we are forced to start at 0 and climb from there
// -- // --
// let's loop through all audio params that we manage, // let's zero out every audio param that we manage
// restore them to whatever value we have stored for them for (const auto &[controller, param]: controllerToParam) {
// (which by default would be 0) setControllerValue(static_cast<int>(controller), 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<AudioParameterInt*>(param) != nullptr);
AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*>(param)};
int value{castParam->get()};
setControllerValue(static_cast<int>(controller), value);
} }
// http://www.synthfont.com/SoundFont_NRPNs.PDF // http://www.synthfont.com/SoundFont_NRPNs.PDF
@ -355,6 +343,11 @@ void FluidSynthModel::processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiM
*castParam = m.getControllerValue(); *castParam = m.getControllerValue();
} }
} else if (m.isProgramChange()) { } 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( int result{fluid_synth_program_change(
synth.get(), synth.get(),
channel, channel,

View File

@ -260,12 +260,6 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
if (xmlState.get() != nullptr) { if (xmlState.get() != nullptr) {
// make sure that it's actually our type of XML object.. // make sure that it's actually our type of XML object..
if (xmlState->hasTagName(valueTreeState.state.getType())) { if (xmlState->hasTagName(valueTreeState.state.getType())) {
XmlElement* params{xmlState->getChildByName("params")};
if (params)
for (auto* param : getParameters())
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*>(param))
p->setValue(static_cast<float>(params->getDoubleAttribute(p->paramID, p->getValue())));
{ {
XmlElement* xmlElement{xmlState->getChildByName("soundFont")}; XmlElement* xmlElement{xmlState->getChildByName("soundFont")};
if (xmlElement) { 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<AudioProcessorParameterWithID*>(param)) {
p->setValueNotifyingHost(static_cast<float>(params->getDoubleAttribute(p->paramID, p->getValue())));
}
}
}
} }
} }
} }