separate functions to refresh presets, banks. update list of presets when bank changes. filter presets list by current bank.
This commit is contained in:
parent
99bb294ece
commit
fc1d45d77c
|
@ -27,10 +27,14 @@ FluidSynthModel::FluidSynthModel(
|
||||||
, channel{0}/*,
|
, channel{0}/*,
|
||||||
mod(nullptr)*/
|
mod(nullptr)*/
|
||||||
{
|
{
|
||||||
|
valueTreeState.addParameterListener("bank", this);
|
||||||
|
valueTreeState.addParameterListener("preset", this);
|
||||||
valueTreeState.state.addListener(this);
|
valueTreeState.state.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
FluidSynthModel::~FluidSynthModel() {
|
FluidSynthModel::~FluidSynthModel() {
|
||||||
|
valueTreeState.removeParameterListener("bank", this);
|
||||||
|
valueTreeState.removeParameterListener("preset", this);
|
||||||
valueTreeState.state.removeListener(this);
|
valueTreeState.state.removeListener(this);
|
||||||
// if (initialised) {
|
// if (initialised) {
|
||||||
// delete_fluid_audio_driver(driver);
|
// delete_fluid_audio_driver(driver);
|
||||||
|
@ -202,6 +206,28 @@ void FluidSynthModel::initialise() {
|
||||||
// initialised = true;
|
// initialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FluidSynthModel::parameterChanged(const String& parameterID, float newValue) {
|
||||||
|
if (parameterID == "bank") {
|
||||||
|
RangedAudioParameter *param {valueTreeState.getParameter("bank")};
|
||||||
|
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||||
|
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||||
|
int value{castParam->get()};
|
||||||
|
fluid_synth_bank_select(synth.get(), channel, value);
|
||||||
|
refreshPresets();
|
||||||
|
// fluid_sfont_t* sfont{fluid_synth_get_sfont_by_id(synth.get(), sfont_id)};
|
||||||
|
// fluid_sfont_iteration_start(sfont);
|
||||||
|
// fluid_preset_t* presetObj{fluid_sfont_iteration_next(sfont)};
|
||||||
|
// int offset{fluid_synth_get_bank_offset(synth.get(), sfont_id)};
|
||||||
|
// int bank{fluid_preset_get_banknum(presetObj) + offset};
|
||||||
|
// int preset{fluid_preset_get_num(presetObj)};
|
||||||
|
} else if (parameterID == "preset") {
|
||||||
|
RangedAudioParameter *param {valueTreeState.getParameter("preset")};
|
||||||
|
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||||
|
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||||
|
int value{castParam->get()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FluidSynthModel::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged,
|
void FluidSynthModel::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged,
|
||||||
const Identifier& property) {
|
const Identifier& property) {
|
||||||
if (treeWhosePropertyHasChanged.getType() == StringRef("soundFont")) {
|
if (treeWhosePropertyHasChanged.getType() == StringRef("soundFont")) {
|
||||||
|
@ -339,55 +365,117 @@ void FluidSynthModel::loadFont(const String &absPath) {
|
||||||
currentSoundFontAbsPath = absPath;
|
currentSoundFontAbsPath = absPath;
|
||||||
sfont_id++;
|
sfont_id++;
|
||||||
fluid_synth_sfload(synth.get(), absPath.toStdString().c_str(), 1);
|
fluid_synth_sfload(synth.get(), absPath.toStdString().c_str(), 1);
|
||||||
|
refreshBanks();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FluidSynthModel::refreshBanks() {
|
||||||
fluid_sfont_t* sfont {fluid_synth_get_sfont_by_id(synth.get(), sfont_id)};
|
fluid_sfont_t* sfont {fluid_synth_get_sfont_by_id(synth.get(), sfont_id)};
|
||||||
ValueTree banks{"banks"};
|
ValueTree banks{"banks"};
|
||||||
ValueTree presets{"presets"};
|
|
||||||
if (sfont != nullptr) {
|
if (sfont != nullptr) {
|
||||||
int initialBankOffset{fluid_synth_get_bank_offset(synth.get(), sfont_id)};
|
int initialBank{fluid_synth_get_bank_offset(synth.get(), sfont_id)};
|
||||||
banks.appendChild({ "bank", {
|
banks.appendChild({ "bank", {
|
||||||
{ "num", initialBankOffset },
|
{ "num", initialBank },
|
||||||
}, {} }, nullptr);
|
}, {} }, nullptr);
|
||||||
int greatestPersistedBank{initialBankOffset};
|
int greatestPersistedBank{initialBank};
|
||||||
|
|
||||||
fluid_sfont_iteration_start(sfont);
|
fluid_sfont_iteration_start(sfont);
|
||||||
|
|
||||||
for(fluid_preset_t* preset {fluid_sfont_iteration_next(sfont)};
|
for(fluid_preset_t* preset {fluid_sfont_iteration_next(sfont)};
|
||||||
preset != nullptr;
|
preset != nullptr;
|
||||||
preset = fluid_sfont_iteration_next(sfont)) {
|
preset = fluid_sfont_iteration_next(sfont)) {
|
||||||
int bankOffset{fluid_preset_get_banknum(preset) + initialBankOffset};
|
int bank{fluid_preset_get_banknum(preset) + initialBank};
|
||||||
// ValueTree preset{"preset"};
|
if (bank > greatestPersistedBank) {
|
||||||
// banksToPresets.insert(BanksToPresets::value_type(
|
|
||||||
// fluid_preset_get_banknum(preset) + bankOffset,
|
|
||||||
// *new Preset(
|
|
||||||
// fluid_preset_get_num(preset),
|
|
||||||
// fluid_preset_get_name(preset)
|
|
||||||
// )
|
|
||||||
// ));
|
|
||||||
if (bankOffset > greatestPersistedBank) {
|
|
||||||
banks.appendChild({ "bank", {
|
banks.appendChild({ "bank", {
|
||||||
{ "num", bankOffset },
|
{ "num", bank },
|
||||||
}, {} }, nullptr);
|
}, {} }, nullptr);
|
||||||
greatestPersistedBank = bankOffset;
|
greatestPersistedBank = bank;
|
||||||
}
|
}
|
||||||
presets.appendChild({ "preset", {
|
|
||||||
{ "num", fluid_preset_get_num(preset) },
|
|
||||||
{ "name", String{fluid_preset_get_name(preset)} }
|
|
||||||
}, {} }, nullptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// valueTreeState.state.getChildWithName("banks") = banks;
|
|
||||||
// valueTreeState.state.getChildWithName("presets") = presets;
|
|
||||||
valueTreeState.state.getChildWithName("banks").copyPropertiesAndChildrenFrom(banks, nullptr);
|
valueTreeState.state.getChildWithName("banks").copyPropertiesAndChildrenFrom(banks, nullptr);
|
||||||
valueTreeState.state.getChildWithName("presets").copyPropertiesAndChildrenFrom(presets, nullptr);
|
|
||||||
valueTreeState.state.getChildWithName("banks").sendPropertyChangeMessage("synthetic");
|
valueTreeState.state.getChildWithName("banks").sendPropertyChangeMessage("synthetic");
|
||||||
valueTreeState.state.getChildWithName("presets").sendPropertyChangeMessage("synthetic");
|
refreshPresets();
|
||||||
|
|
||||||
#if JUCE_DEBUG
|
|
||||||
unique_ptr<XmlElement> xml{valueTreeState.state.createXml()};
|
|
||||||
Logger::outputDebugString(xml->createDocument("",false,false));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FluidSynthModel::refreshPresets() {
|
||||||
|
fluid_sfont_t* sfont {fluid_synth_get_sfont_by_id(synth.get(), sfont_id)};
|
||||||
|
ValueTree presets{"presets"};
|
||||||
|
if (sfont != nullptr) {
|
||||||
|
RangedAudioParameter *param {valueTreeState.getParameter("bank")};
|
||||||
|
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||||
|
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||||
|
int value{castParam->get()};
|
||||||
|
|
||||||
|
int initialBank{fluid_synth_get_bank_offset(synth.get(), sfont_id)};
|
||||||
|
|
||||||
|
fluid_sfont_iteration_start(sfont);
|
||||||
|
|
||||||
|
for(fluid_preset_t* preset {fluid_sfont_iteration_next(sfont)};
|
||||||
|
preset != nullptr;
|
||||||
|
preset = fluid_sfont_iteration_next(sfont)) {
|
||||||
|
int bank{fluid_preset_get_banknum(preset) + initialBank};
|
||||||
|
if (bank == value) {
|
||||||
|
presets.appendChild({ "preset", {
|
||||||
|
{ "num", fluid_preset_get_num(preset) },
|
||||||
|
{ "name", String{fluid_preset_get_name(preset)} }
|
||||||
|
}, {} }, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valueTreeState.state.getChildWithName("presets").copyPropertiesAndChildrenFrom(presets, nullptr);
|
||||||
|
valueTreeState.state.getChildWithName("presets").sendPropertyChangeMessage("synthetic");
|
||||||
|
}
|
||||||
|
|
||||||
|
// void FluidSynthModel::refreshBanksAndPresets() {
|
||||||
|
// fluid_sfont_t* sfont {fluid_synth_get_sfont_by_id(synth.get(), sfont_id)};
|
||||||
|
// ValueTree banks{"banks"};
|
||||||
|
// ValueTree presets{"presets"};
|
||||||
|
// if (sfont != nullptr) {
|
||||||
|
// int initialBankOffset{fluid_synth_get_bank_offset(synth.get(), sfont_id)};
|
||||||
|
// banks.appendChild({ "bank", {
|
||||||
|
// { "num", initialBankOffset },
|
||||||
|
// }, {} }, nullptr);
|
||||||
|
// int greatestPersistedBank{initialBankOffset};
|
||||||
|
|
||||||
|
// fluid_sfont_iteration_start(sfont);
|
||||||
|
|
||||||
|
// for(fluid_preset_t* preset {fluid_sfont_iteration_next(sfont)};
|
||||||
|
// preset != nullptr;
|
||||||
|
// preset = fluid_sfont_iteration_next(sfont)) {
|
||||||
|
// int bankOffset{fluid_preset_get_banknum(preset) + initialBankOffset};
|
||||||
|
// // ValueTree preset{"preset"};
|
||||||
|
// // banksToPresets.insert(BanksToPresets::value_type(
|
||||||
|
// // fluid_preset_get_banknum(preset) + bankOffset,
|
||||||
|
// // *new Preset(
|
||||||
|
// // fluid_preset_get_num(preset),
|
||||||
|
// // fluid_preset_get_name(preset)
|
||||||
|
// // )
|
||||||
|
// // ));
|
||||||
|
// if (bankOffset > greatestPersistedBank) {
|
||||||
|
// banks.appendChild({ "bank", {
|
||||||
|
// { "num", bankOffset },
|
||||||
|
// }, {} }, nullptr);
|
||||||
|
// greatestPersistedBank = bankOffset;
|
||||||
|
// }
|
||||||
|
// presets.appendChild({ "preset", {
|
||||||
|
// { "num", fluid_preset_get_num(preset) },
|
||||||
|
// { "name", String{fluid_preset_get_name(preset)} }
|
||||||
|
// }, {} }, nullptr);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // valueTreeState.state.getChildWithName("banks") = banks;
|
||||||
|
// // valueTreeState.state.getChildWithName("presets") = presets;
|
||||||
|
// valueTreeState.state.getChildWithName("banks").copyPropertiesAndChildrenFrom(banks, nullptr);
|
||||||
|
// valueTreeState.state.getChildWithName("presets").copyPropertiesAndChildrenFrom(presets, nullptr);
|
||||||
|
// valueTreeState.state.getChildWithName("banks").sendPropertyChangeMessage("synthetic");
|
||||||
|
// valueTreeState.state.getChildWithName("presets").sendPropertyChangeMessage("synthetic");
|
||||||
|
|
||||||
|
// #if JUCE_DEBUG
|
||||||
|
// unique_ptr<XmlElement> xml{valueTreeState.state.createXml()};
|
||||||
|
// Logger::outputDebugString(xml->createDocument("",false,false));
|
||||||
|
// #endif
|
||||||
|
// }
|
||||||
|
|
||||||
// FluidSynthModel::Listener::~Listener() {
|
// FluidSynthModel::Listener::~Listener() {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class FluidSynthModel: public ValueTree::Listener {
|
class FluidSynthModel
|
||||||
|
: public ValueTree::Listener
|
||||||
|
, public AudioProcessorValueTreeState::Listener {
|
||||||
public:
|
public:
|
||||||
FluidSynthModel(
|
FluidSynthModel(
|
||||||
AudioProcessorValueTreeState& valueTreeState
|
AudioProcessorValueTreeState& valueTreeState
|
||||||
|
@ -68,6 +70,7 @@ public:
|
||||||
|
|
||||||
const String& getCurrentSoundFontAbsPath();
|
const String& getCurrentSoundFontAbsPath();
|
||||||
|
|
||||||
|
virtual void parameterChanged (const String& parameterID, float newValue) override;
|
||||||
|
|
||||||
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
|
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
|
||||||
const Identifier& property) override;
|
const Identifier& property) override;
|
||||||
|
@ -101,6 +104,9 @@ private:
|
||||||
// };
|
// };
|
||||||
|
|
||||||
int handleMidiEvent(void* data, fluid_midi_event_t* event);
|
int handleMidiEvent(void* data, fluid_midi_event_t* event);
|
||||||
|
void refreshBanks();
|
||||||
|
void refreshPresets();
|
||||||
|
// void refreshBanksAndPresets();
|
||||||
|
|
||||||
// ValueTreeListener valueTreeListener;
|
// ValueTreeListener valueTreeListener;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user