From 745adf8fdec29d571e2d73b2da90dbc2b4a08ccc Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Sat, 20 Jul 2019 19:56:12 +0100 Subject: [PATCH] make table once again respond to bank changes. support bank offset again. --- Source/FluidSynthModel.cpp | 7 ++-- Source/TableComponent.cpp | 67 +++++++++++++++++++++----------------- Source/TableComponent.h | 1 + 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index 4fd4891..d0294c0 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -226,11 +226,12 @@ void FluidSynthModel::parameterChanged(const String& parameterID, float newValue AudioParameterInt* castParam {dynamic_cast (param)}; preset = castParam->get(); } + int bankOffset{fluid_synth_get_bank_offset(synth.get(), sfont_id)}; fluid_synth_program_select( synth.get(), channel, sfont_id, - static_cast(bank), + static_cast(bankOffset + bank), static_cast(preset)); // fluid_synth_bank_select(synth.get(), channel, value); @@ -255,12 +256,12 @@ void FluidSynthModel::parameterChanged(const String& parameterID, float newValue AudioParameterInt* castParam {dynamic_cast (param)}; preset = castParam->get(); } - // int bank{fluid_synth_get_bank_offset(synth.get(), sfont_id)}; + int bankOffset{fluid_synth_get_bank_offset(synth.get(), sfont_id)}; fluid_synth_program_select( synth.get(), channel, sfont_id, - static_cast(bank), + static_cast(bankOffset + bank), static_cast(preset)); } } diff --git a/Source/TableComponent.cpp b/Source/TableComponent.cpp index e067906..b43d253 100644 --- a/Source/TableComponent.cpp +++ b/Source/TableComponent.cpp @@ -91,9 +91,13 @@ TableComponent::TableComponent( // table.setMultipleSelectionEnabled (false); valueTreeState.state.addListener(this); + valueTreeState.addParameterListener("bank", this); + valueTreeState.addParameterListener("preset", this); } TableComponent::~TableComponent() { + valueTreeState.removeParameterListener("bank", this); + valueTreeState.removeParameterListener("preset", this); valueTreeState.state.removeListener(this); } @@ -114,7 +118,6 @@ TableComponent::~TableComponent() { // } void TableComponent::loadModelFrom(ValueTree& banks) { - rows.clear(); banksToPresets.clear(); int banksChildren{banks.getNumChildren()}; for(int bankIx{0}; bankIx(param) != nullptr); - AudioParameterInt* castParam{dynamic_cast(param)}; - int bank{castParam->get()}; - - BanksToPresets::iterator lowerBound{banksToPresets.lower_bound(bank)}; - BanksToPresets::iterator upperBound{banksToPresets.upper_bound(bank)}; - - // basic syntaxes for a lambda which return's a pair's .second - // https://stackoverflow.com/questions/2568194/populate-a-vector-with-all-multimap-values-with-a-given-key - // shorter syntax with mem_fn() - // https://stackoverflow.com/a/36775400/5257399 - transform( - lowerBound, - upperBound, - back_inserter(rows), - mem_fn(&BanksToPresets::value_type::second) -// [](BanksToPresets::value_type element){return element.second;} - ); - } - - table.deselectAllRows(); - table.updateContent(); - table.getHeader().setSortColumnId(0, true); - selectCurrentPreset(); - table.repaint(); + repopulateTable(); } void TableComponent::parameterChanged(const String& parameterID, float newValue) { // valueTreeState.getParameter - if (parameterID == "preset") { + if (parameterID == "bank") { + repopulateTable(); + } else if (parameterID == "preset") { selectCurrentPreset(); // RangedAudioParameter *param {valueTreeState.getParameter("preset")}; // jassert(dynamic_cast (param) != nullptr); @@ -172,6 +151,34 @@ void TableComponent::parameterChanged(const String& parameterID, float newValue) } } +void TableComponent::repopulateTable() { + rows.clear(); + RangedAudioParameter *param{valueTreeState.getParameter("bank")}; + jassert(dynamic_cast(param) != nullptr); + AudioParameterInt* castParam{dynamic_cast(param)}; + int bank{castParam->get()}; + + BanksToPresets::iterator lowerBound{banksToPresets.lower_bound(bank)}; + BanksToPresets::iterator upperBound{banksToPresets.upper_bound(bank)}; + + // basic syntaxes for a lambda which return's a pair's .second + // https://stackoverflow.com/questions/2568194/populate-a-vector-with-all-multimap-values-with-a-given-key + // shorter syntax with mem_fn() + // https://stackoverflow.com/a/36775400/5257399 + transform( + lowerBound, + upperBound, + back_inserter(rows), + mem_fn(&BanksToPresets::value_type::second) + // [](BanksToPresets::value_type element){return element.second;} + ); + table.deselectAllRows(); + table.updateContent(); + table.getHeader().setSortColumnId(0, true); + selectCurrentPreset(); + table.repaint(); +} + void TableComponent::valueTreePropertyChanged( ValueTree& treeWhosePropertyHasChanged, const Identifier& property) { @@ -323,7 +330,7 @@ void TableComponent::selectCurrentPreset() { for (auto it = rows.begin(); it != rows.end(); ++it) { if(it->preset == value) { - int index {static_cast(std::distance(rows.begin(), it))}; + int index {static_cast(distance(rows.begin(), it))}; table.selectRow(index); break; } diff --git a/Source/TableComponent.h b/Source/TableComponent.h index e5a914f..28e02a3 100644 --- a/Source/TableComponent.h +++ b/Source/TableComponent.h @@ -94,6 +94,7 @@ public: private: // void loadModelFrom(ValueTree& presets); void loadModelFrom(ValueTree& banks); + void repopulateTable(); void selectCurrentPreset(); AudioProcessorValueTreeState& valueTreeState;