make table once again respond to bank changes. support bank offset again.

This commit is contained in:
Alex Birch 2019-07-20 19:56:12 +01:00
parent 0587e2f68a
commit 745adf8fde
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
3 changed files with 42 additions and 33 deletions

View File

@ -226,11 +226,12 @@ void FluidSynthModel::parameterChanged(const String& parameterID, float newValue
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (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<unsigned int>(bank),
static_cast<unsigned int>(bankOffset + bank),
static_cast<unsigned int>(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<AudioParameterInt*> (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<unsigned int>(bank),
static_cast<unsigned int>(bankOffset + bank),
static_cast<unsigned int>(preset));
}
}

View File

@ -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<banksChildren; bankIx++) {
@ -132,7 +135,24 @@ void TableComponent::loadModelFrom(ValueTree& banks) {
banksToPresets.emplace(bankNum, move(row));
}
}
{
repopulateTable();
}
void TableComponent::parameterChanged(const String& parameterID, float newValue) {
// valueTreeState.getParameter
if (parameterID == "bank") {
repopulateTable();
} else if (parameterID == "preset") {
selectCurrentPreset();
// RangedAudioParameter *param {valueTreeState.getParameter("preset")};
// jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
// AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
// int value{castParam->get()};
}
}
void TableComponent::repopulateTable() {
rows.clear();
RangedAudioParameter *param{valueTreeState.getParameter("bank")};
jassert(dynamic_cast<AudioParameterInt*>(param) != nullptr);
AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*>(param)};
@ -152,8 +172,6 @@ void TableComponent::loadModelFrom(ValueTree& banks) {
mem_fn(&BanksToPresets::value_type::second)
// [](BanksToPresets::value_type element){return element.second;}
);
}
table.deselectAllRows();
table.updateContent();
table.getHeader().setSortColumnId(0, true);
@ -161,17 +179,6 @@ void TableComponent::loadModelFrom(ValueTree& banks) {
table.repaint();
}
void TableComponent::parameterChanged(const String& parameterID, float newValue) {
// valueTreeState.getParameter
if (parameterID == "preset") {
selectCurrentPreset();
// RangedAudioParameter *param {valueTreeState.getParameter("preset")};
// jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
// AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
// int value{castParam->get()};
}
}
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<int>(std::distance(rows.begin(), it))};
int index {static_cast<int>(distance(rows.begin(), it))};
table.selectRow(index);
break;
}

View File

@ -94,6 +94,7 @@ public:
private:
// void loadModelFrom(ValueTree& presets);
void loadModelFrom(ValueTree& banks);
void repopulateTable();
void selectCurrentPreset();
AudioProcessorValueTreeState& valueTreeState;