Merge pull request #12 from Birch-san/restore-program

restore preset and bank _after_ soundfont
This commit is contained in:
Birch-san 2019-08-10 23:23:06 +01:00 committed by GitHub
commit aabb0b1aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 };
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<AudioParameterInt*>(param) != nullptr);
AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*>(param)};
int value{castParam->get()};
setControllerValue(static_cast<int>(controller), value);
// let's zero out every audio param that we manage
for (const auto &[controller, param]: controllerToParam) {
setControllerValue(static_cast<int>(controller), 0);
}
// http://www.synthfont.com/SoundFont_NRPNs.PDF
@ -355,6 +343,11 @@ void FluidSynthModel::processBlock(AudioBuffer<float>& 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,

View File

@ -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<AudioProcessorParameterWithID*>(param))
p->setValue(static_cast<float>(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<AudioProcessorParameterWithID*>(param)) {
p->setValueNotifyingHost(static_cast<float>(params->getDoubleAttribute(p->paramID, p->getValue())));
}
}
}
}
}
}