2018-02-27 08:25:20 +08:00
|
|
|
//
|
|
|
|
// Created by Alex Birch on 17/09/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "TablesComponent.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace placeholders;
|
|
|
|
|
|
|
|
TablesComponent::TablesComponent(
|
2019-07-15 00:22:36 +08:00
|
|
|
AudioProcessorValueTreeState& valueTreeState
|
|
|
|
// FluidSynthModel& fluidSynthModel
|
2019-07-07 07:22:47 +08:00
|
|
|
)
|
|
|
|
: valueTreeState{valueTreeState}
|
2019-07-15 00:22:36 +08:00
|
|
|
// , fluidSynthModel{fluidSynthModel}
|
|
|
|
, banks{valueTreeState}
|
|
|
|
, presetTable{valueTreeState}
|
|
|
|
// , banksToPresets{fluidSynthModel.getBanks()}
|
|
|
|
// , initialised{false}
|
2018-02-27 08:25:20 +08:00
|
|
|
{
|
2019-07-15 00:22:36 +08:00
|
|
|
// fluid_preset_t* currentPreset = getCurrentPreset();
|
|
|
|
// selectedBank = -1;
|
|
|
|
// int selectedPreset = -1;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-13 07:16:35 +08:00
|
|
|
|
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// if (currentPreset != nullptr) {
|
|
|
|
// selectedBank = fluid_preset_get_banknum(currentPreset);
|
|
|
|
// selectedPreset = fluid_preset_get_num(currentPreset);
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-13 07:16:35 +08:00
|
|
|
// auto rowToPresetMapper = [this](const vector<string> &row) {
|
|
|
|
// return stoi(row[0]);
|
|
|
|
// };
|
2019-07-15 00:22:36 +08:00
|
|
|
// auto itemToBankMapper = [](const string &item) {
|
|
|
|
// return stoi(item);
|
|
|
|
// };
|
|
|
|
|
|
|
|
// presetTable = new TableComponent(
|
|
|
|
// valueTreeState,
|
|
|
|
// // {"#", "Name"},
|
|
|
|
// // mapPresets(
|
|
|
|
// // banksToPresets,
|
|
|
|
// // selectedBank
|
|
|
|
// // ),
|
|
|
|
// // [this](int preset){
|
|
|
|
// // this->onPresetSelected(preset);
|
|
|
|
// // },
|
|
|
|
// // rowToPresetMapper,
|
|
|
|
// // presetToIndexMapper(selectedPreset)
|
|
|
|
// );
|
|
|
|
// banks = new Pills(
|
|
|
|
// "Banks",
|
|
|
|
// mapBanks(banksToPresets),
|
|
|
|
// [this](int bank){
|
|
|
|
// this->onBankSelected(bank);
|
|
|
|
// },
|
|
|
|
// itemToBankMapper,
|
|
|
|
// selectedBank
|
|
|
|
// );
|
|
|
|
|
|
|
|
presetTable.setWantsKeyboardFocus(false);
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
addAndMakeVisible(presetTable);
|
|
|
|
|
|
|
|
addAndMakeVisible(banks);
|
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// initialised = true;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// fluidSynthModel.addListener(this);
|
2018-02-27 08:25:20 +08:00
|
|
|
}
|
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// fluid_preset_t* TablesComponent::getCurrentPreset() {
|
|
|
|
// shared_ptr<fluid_synth_t> synth {fluidSynthModel.getSynth()};
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// return fluid_synth_get_channel_preset(synth.get(), fluidSynthModel.getChannel());
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// Preset TablesComponent::getFirstPresetInBank(int bank) {
|
|
|
|
// pair<BanksToPresets::const_iterator, BanksToPresets::const_iterator> iterators = banksToPresets.equal_range(bank);
|
|
|
|
// BanksToPresets::const_iterator it = iterators.first;
|
|
|
|
// return it->second;
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// void TablesComponent::onBankSelected(int bank) {
|
|
|
|
// if (!initialised || bank == -1) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// cout << "Bank " << bank << endl;
|
|
|
|
// selectedBank = bank;
|
|
|
|
// Preset firstPresetInBank = getFirstPresetInBank(bank);
|
|
|
|
// presetTable->setRows(
|
|
|
|
// mapPresets(
|
|
|
|
// banksToPresets,
|
|
|
|
// bank
|
|
|
|
// ),
|
|
|
|
// presetToIndexMapper(firstPresetInBank.getPreset())
|
|
|
|
// );
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// int TablesComponent::presetToIndexMapper(int preset) {
|
|
|
|
// int ix = 0;
|
|
|
|
// pair<BanksToPresets::const_iterator, BanksToPresets::const_iterator> iterators = this->banksToPresets.equal_range(this->selectedBank);
|
|
|
|
// for (auto it = iterators.first; it != iterators.second; ++it, ix++) {
|
|
|
|
// Preset b = it->second;
|
|
|
|
// if (preset == b.getPreset()) {
|
|
|
|
// return ix;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return 0;
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
// void TablesComponent::onPresetSelected(int preset) {
|
|
|
|
// if (!initialised || preset == -1) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// cout << "Preset " << preset << endl;
|
|
|
|
// // selectedPreset = preset;
|
|
|
|
// fluidSynthModel.changePreset(selectedBank, preset);
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// TablesComponent::~TablesComponent() {
|
|
|
|
// delete presetTable;
|
|
|
|
// delete banks;
|
|
|
|
// // fluidSynthModel.removeListener(this);
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// vector<string> TablesComponent::mapBanks(const BanksToPresets &banksToPresets) {
|
|
|
|
// vector<string> rows;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// const auto compareKey = [](const BanksToPresets::value_type& lhs, const BanksToPresets::value_type& rhs) {
|
|
|
|
// return lhs.first < rhs.first;
|
|
|
|
// };
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// for(auto i = banksToPresets.begin(); i != banksToPresets.end(); i = std::upper_bound(i, banksToPresets.end(), *i, compareKey)) {
|
|
|
|
// rows.push_back(to_string(i->first));
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
// return rows;
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
// vector<vector<string>> TablesComponent::mapPresets(const BanksToPresets &banksToPresets, int bank) {
|
|
|
|
// vector<vector<string>> rows;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
// pair<BanksToPresets::const_iterator, BanksToPresets::const_iterator> iterators = banksToPresets.equal_range(bank);
|
|
|
|
// for (auto it = iterators.first; it != iterators.second; ++it) {
|
|
|
|
// Preset b = it->second;
|
|
|
|
// vector<string> row;
|
|
|
|
// row.push_back(to_string(b.getPreset()));
|
|
|
|
// row.push_back(b.getName());
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
// rows.push_back(row);
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
// return rows;
|
|
|
|
// }
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
void TablesComponent::resized() {
|
|
|
|
Rectangle<int> r (getLocalBounds());
|
2019-07-15 00:22:36 +08:00
|
|
|
banks.setBounds (r.removeFromTop(27).reduced(5,0));
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-15 00:22:36 +08:00
|
|
|
presetTable.setBounds (r);
|
2018-02-27 08:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TablesComponent::keyPressed(const KeyPress &key) {
|
|
|
|
if (key.getKeyCode() == KeyPress::leftKey
|
|
|
|
|| key.getKeyCode() == KeyPress::rightKey) {
|
2019-07-15 00:22:36 +08:00
|
|
|
banks.cycle(key.getKeyCode() == KeyPress::rightKey);
|
2018-02-27 08:25:20 +08:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-15 00:22:36 +08:00
|
|
|
return presetTable.keyPressed(key);
|
2018-02-27 08:25:20 +08:00
|
|
|
}
|
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// void TablesComponent::fontChanged(FluidSynthModel *, const String &) {
|
|
|
|
// banksToPresets = fluidSynthModel.getBanks();
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// fluid_preset_t* currentPreset = getCurrentPreset();
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// selectedBank = fluid_preset_get_banknum(currentPreset);
|
|
|
|
// int selectedPreset = fluid_preset_get_num(currentPreset);
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// presetTable->setRows(
|
|
|
|
// mapPresets(
|
|
|
|
// banksToPresets,
|
|
|
|
// selectedBank
|
|
|
|
// ),
|
|
|
|
// presetToIndexMapper(selectedPreset)
|
|
|
|
// );
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// banks->setItems(
|
|
|
|
// mapBanks(banksToPresets),
|
|
|
|
// selectedBank
|
|
|
|
// );
|
|
|
|
// }
|