juicysfplugin/Source/TablesComponent.cpp

196 lines
5.7 KiB
C++
Raw Normal View History

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(
AudioProcessorValueTreeState& valueTreeState
// FluidSynthModel& fluidSynthModel
)
: valueTreeState{valueTreeState}
// , fluidSynthModel{fluidSynthModel}
, banks{valueTreeState}
, presetTable{valueTreeState}
// , banksToPresets{fluidSynthModel.getBanks()}
// , initialised{false}
2018-02-27 08:25:20 +08:00
{
// fluid_preset_t* currentPreset = getCurrentPreset();
// selectedBank = -1;
// int selectedPreset = -1;
2018-02-27 08:25:20 +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
// auto rowToPresetMapper = [this](const vector<string> &row) {
// return stoi(row[0]);
// };
// 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);
// initialised = true;
2018-02-27 08:25:20 +08:00
// fluidSynthModel.addListener(this);
2018-02-27 08:25:20 +08:00
}
// fluid_preset_t* TablesComponent::getCurrentPreset() {
// shared_ptr<fluid_synth_t> synth {fluidSynthModel.getSynth()};
2018-02-27 08:25:20 +08:00
// return fluid_synth_get_channel_preset(synth.get(), fluidSynthModel.getChannel());
// }
2018-02-27 08:25:20 +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
// 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
// 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
// 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
// TablesComponent::~TablesComponent() {
// delete presetTable;
// delete banks;
// // fluidSynthModel.removeListener(this);
// }
2018-02-27 08:25:20 +08:00
// vector<string> TablesComponent::mapBanks(const BanksToPresets &banksToPresets) {
// vector<string> rows;
2018-02-27 08:25:20 +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
// 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
// return rows;
// }
2018-02-27 08:25:20 +08:00
// vector<vector<string>> TablesComponent::mapPresets(const BanksToPresets &banksToPresets, int bank) {
// vector<vector<string>> rows;
2018-02-27 08:25:20 +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
// rows.push_back(row);
// }
2018-02-27 08:25:20 +08:00
// return rows;
// }
2018-02-27 08:25:20 +08:00
void TablesComponent::resized() {
Rectangle<int> r (getLocalBounds());
banks.setBounds (r.removeFromTop(27).reduced(5,0));
2018-02-27 08:25:20 +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) {
banks.cycle(key.getKeyCode() == KeyPress::rightKey);
2018-02-27 08:25:20 +08:00
return true;
}
return presetTable.keyPressed(key);
2018-02-27 08:25:20 +08:00
}
// void TablesComponent::fontChanged(FluidSynthModel *, const String &) {
// banksToPresets = fluidSynthModel.getBanks();
2018-02-27 08:25:20 +08:00
// fluid_preset_t* currentPreset = getCurrentPreset();
2018-02-27 08:25:20 +08:00
// selectedBank = fluid_preset_get_banknum(currentPreset);
// int selectedPreset = fluid_preset_get_num(currentPreset);
2018-02-27 08:25:20 +08:00
// presetTable->setRows(
// mapPresets(
// banksToPresets,
// selectedBank
// ),
// presetToIndexMapper(selectedPreset)
// );
2018-02-27 08:25:20 +08:00
// banks->setItems(
// mapBanks(banksToPresets),
// selectedBank
// );
// }