2018-02-27 08:25:20 +08:00
|
|
|
//
|
|
|
|
// Model.hpp
|
|
|
|
// Lazarus
|
|
|
|
//
|
|
|
|
// Created by Alex Birch on 01/09/2017.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../JuceLibraryCode/JuceHeader.h"
|
|
|
|
#include "PresetsToBanks.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2019-07-21 01:49:39 +08:00
|
|
|
#include <map>
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
class TableRow {
|
|
|
|
public:
|
|
|
|
TableRow(
|
|
|
|
int preset,
|
|
|
|
String name
|
|
|
|
);
|
|
|
|
private:
|
2019-07-14 21:19:27 +08:00
|
|
|
/** 1-indexed */
|
|
|
|
String getStringContents(int columnId);
|
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
int preset;
|
|
|
|
String name;
|
|
|
|
|
|
|
|
friend class TableComponent;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
class TableComponent : public Component,
|
2019-07-13 07:16:35 +08:00
|
|
|
public TableListBoxModel,
|
2019-07-14 21:19:27 +08:00
|
|
|
public ValueTree::Listener,
|
|
|
|
public AudioProcessorValueTreeState::Listener {
|
2018-02-27 08:25:20 +08:00
|
|
|
public:
|
|
|
|
TableComponent(
|
2019-07-14 21:19:27 +08:00
|
|
|
AudioProcessorValueTreeState& valueTreeState
|
2019-07-13 07:16:35 +08:00
|
|
|
// const vector<string> &columns,
|
2019-07-14 05:37:26 +08:00
|
|
|
// const vector<TableRow> &rows,
|
2019-07-14 21:19:27 +08:00
|
|
|
// const function<void (int)> &onRowSelected,
|
2019-07-13 07:16:35 +08:00
|
|
|
// const function<int (const vector<string>&)> &rowToIDMapper,
|
2019-07-14 21:19:27 +08:00
|
|
|
// int initiallySelectedRow
|
2018-02-27 08:25:20 +08:00
|
|
|
);
|
2019-07-13 07:16:35 +08:00
|
|
|
~TableComponent();
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
int getNumRows() override;
|
|
|
|
|
|
|
|
void paintRowBackground (
|
|
|
|
Graphics& g,
|
|
|
|
int rowNumber,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
bool rowIsSelected
|
|
|
|
) override;
|
|
|
|
void paintCell (
|
|
|
|
Graphics& g,
|
|
|
|
int rowNumber,
|
|
|
|
int columnId,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
bool rowIsSelected
|
|
|
|
) override;
|
|
|
|
|
|
|
|
void sortOrderChanged (int newSortColumnId, bool isForwards) override;
|
|
|
|
|
|
|
|
int getColumnAutoSizeWidth (int columnId) override;
|
|
|
|
|
|
|
|
void selectedRowsChanged (int row) override;
|
|
|
|
|
|
|
|
void resized() override;
|
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// void setRows(const vector<TableRow>& rows, int initiallySelectedRow);
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
bool keyPressed(const KeyPress &key) override;
|
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
virtual void parameterChanged (const String& parameterID, float newValue) override;
|
2019-07-13 07:16:35 +08:00
|
|
|
|
2019-07-15 02:31:05 +08:00
|
|
|
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
|
|
|
|
const Identifier& property) override;
|
2019-07-13 07:16:35 +08:00
|
|
|
inline virtual void valueTreeChildAdded (ValueTree& parentTree,
|
|
|
|
ValueTree& childWhichHasBeenAdded) override {};
|
|
|
|
inline virtual void valueTreeChildRemoved (ValueTree& parentTree,
|
|
|
|
ValueTree& childWhichHasBeenRemoved,
|
|
|
|
int indexFromWhichChildWasRemoved) override {};
|
|
|
|
inline virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved,
|
|
|
|
int oldIndex, int newIndex) override {};
|
2019-07-15 02:31:05 +08:00
|
|
|
inline virtual void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) override {};
|
2019-07-13 07:16:35 +08:00
|
|
|
inline virtual void valueTreeRedirected (ValueTree& treeWhichHasBeenChanged) override {};
|
2018-02-27 08:25:20 +08:00
|
|
|
private:
|
2019-07-21 01:49:39 +08:00
|
|
|
// void loadModelFrom(ValueTree& presets);
|
|
|
|
void loadModelFrom(ValueTree& banks);
|
2019-07-21 02:56:12 +08:00
|
|
|
void repopulateTable();
|
2019-07-14 21:19:27 +08:00
|
|
|
void selectCurrentPreset();
|
|
|
|
|
2019-07-13 07:16:35 +08:00
|
|
|
AudioProcessorValueTreeState& valueTreeState;
|
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
TableListBox table; // the table component itself
|
|
|
|
Font font;
|
|
|
|
|
2019-07-21 01:49:39 +08:00
|
|
|
typedef multimap<int, TableRow> BanksToPresets;
|
|
|
|
BanksToPresets banksToPresets;
|
|
|
|
|
2019-07-14 05:37:26 +08:00
|
|
|
// vector<string> columns;
|
|
|
|
vector<TableRow> rows;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
2019-07-14 21:19:27 +08:00
|
|
|
// function<void (int)> onRowSelected;
|
2019-07-13 07:16:35 +08:00
|
|
|
// function<int (const vector<string>&)> rowToIDMapper;
|
2018-02-27 08:25:20 +08:00
|
|
|
|
|
|
|
// A comparator used to sort our data when the user clicks a column header
|
|
|
|
class DataSorter {
|
|
|
|
public:
|
|
|
|
DataSorter (
|
|
|
|
int columnByWhichToSort,
|
|
|
|
bool forwards
|
|
|
|
);
|
|
|
|
|
|
|
|
bool operator ()(
|
2019-07-14 05:37:26 +08:00
|
|
|
TableRow first,
|
|
|
|
TableRow second
|
2018-02-27 08:25:20 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int columnByWhichToSort;
|
|
|
|
int direction;
|
|
|
|
};
|
|
|
|
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TableComponent)
|
2019-07-14 05:37:26 +08:00
|
|
|
};
|