progress integrating table with store, decoupling from fluidsynth model
This commit is contained in:
parent
e1a8df9e8f
commit
4140b3b85b
|
@ -324,7 +324,7 @@ void FluidSynthModel::onFileNameChanged(const String &absPath, int bank, int pre
|
|||
valueTree.setPropertyExcludingListener(this, "path", absPath, nullptr);
|
||||
// valueTree.setPropertyExcludingListener(this, "soundFontPath", absPath, nullptr);
|
||||
// sharedParams.setSoundFontPath(absPath);
|
||||
eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
|
||||
// eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
|
||||
}
|
||||
|
||||
void FluidSynthModel::unloadAndLoadFont(const String &absPath) {
|
||||
|
@ -377,8 +377,8 @@ void FluidSynthModel::loadFont(const String &absPath) {
|
|||
valueTreeState.state.getChildWithName("presets") = presets;
|
||||
}
|
||||
|
||||
FluidSynthModel::Listener::~Listener() {
|
||||
}
|
||||
// FluidSynthModel::Listener::~Listener() {
|
||||
// }
|
||||
|
||||
bool FluidSynthModel::shouldLoadFont(const String &absPath) {
|
||||
if (absPath.isEmpty()) {
|
||||
|
@ -390,23 +390,23 @@ bool FluidSynthModel::shouldLoadFont(const String &absPath) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void FluidSynthModel::Listener::fontChanged(FluidSynthModel * model, const String &absPath) {
|
||||
}
|
||||
// void FluidSynthModel::Listener::fontChanged(FluidSynthModel * model, const String &absPath) {
|
||||
// }
|
||||
|
||||
const String& FluidSynthModel::getCurrentSoundFontAbsPath() {
|
||||
return currentSoundFontAbsPath;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void FluidSynthModel::addListener (FluidSynthModel::Listener* const newListener)
|
||||
{
|
||||
eventListeners.add(newListener);
|
||||
}
|
||||
// void FluidSynthModel::addListener (FluidSynthModel::Listener* const newListener)
|
||||
// {
|
||||
// eventListeners.add(newListener);
|
||||
// }
|
||||
|
||||
void FluidSynthModel::removeListener (FluidSynthModel::Listener* const listener)
|
||||
{
|
||||
eventListeners.remove(listener);
|
||||
}
|
||||
// void FluidSynthModel::removeListener (FluidSynthModel::Listener* const listener)
|
||||
// {
|
||||
// eventListeners.remove(listener);
|
||||
// }
|
||||
|
||||
void FluidSynthModel::setSampleRate(float sampleRate) {
|
||||
currentSampleRate = sampleRate;
|
||||
|
|
|
@ -43,26 +43,26 @@ public:
|
|||
|
||||
@see Button::addListener, Button::removeListener
|
||||
*/
|
||||
class Listener
|
||||
{
|
||||
public:
|
||||
/** Destructor. */
|
||||
virtual ~Listener();
|
||||
// class Listener
|
||||
// {
|
||||
// public:
|
||||
// /** Destructor. */
|
||||
// virtual ~Listener();
|
||||
|
||||
/** Called when the button is clicked. */
|
||||
virtual void fontChanged (FluidSynthModel*, const String &absPath);
|
||||
};
|
||||
// /** Called when the button is clicked. */
|
||||
// virtual void fontChanged (FluidSynthModel*, const String &absPath);
|
||||
// };
|
||||
|
||||
/** Registers a listener to receive events when this button's state changes.
|
||||
If the listener is already registered, this will not register it again.
|
||||
@see removeListener
|
||||
*/
|
||||
void addListener (Listener* newListener);
|
||||
// void addListener (Listener* newListener);
|
||||
|
||||
/** Removes a previously-registered button listener
|
||||
@see addListener
|
||||
*/
|
||||
void removeListener (Listener* listener);
|
||||
// void removeListener (Listener* listener);
|
||||
|
||||
void setSampleRate(float sampleRate);
|
||||
|
||||
|
@ -137,7 +137,7 @@ private:
|
|||
|
||||
// fluid_mod_t* mod;
|
||||
|
||||
ListenerList<Listener> eventListeners;
|
||||
// ListenerList<Listener> eventListeners;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FluidSynthModel)
|
||||
};
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
//
|
||||
|
||||
#include "TableComponent.h"
|
||||
#include "Util.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Util;
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
|
@ -17,15 +19,16 @@ using namespace std;
|
|||
TableComponent::TableComponent(
|
||||
AudioProcessorValueTreeState& valueTreeState,
|
||||
// const vector<string> &columns,
|
||||
const vector<vector<string>> &rows,
|
||||
// const vector<TableRow> &rows,
|
||||
const function<void (int)> &onRowSelected,
|
||||
// const function<int (const vector<string>&)> &rowToIDMapper,
|
||||
int initiallySelectedRow
|
||||
)
|
||||
: font (14.0f)
|
||||
, columns(columns)
|
||||
, rows(rows)
|
||||
, onRowSelected(onRowSelected)/*,
|
||||
: valueTreeState{valueTreeState}
|
||||
, font{14.0f}
|
||||
//, columns{columns}
|
||||
//, rows{rows}
|
||||
, onRowSelected{onRowSelected}/*,
|
||||
rowToIDMapper(rowToIDMapper)*/
|
||||
{
|
||||
// Create our table component and add it to this component..
|
||||
|
@ -104,26 +107,34 @@ TableComponent::~TableComponent() {
|
|||
void TableComponent::valueTreePropertyChanged(
|
||||
ValueTree& treeWhosePropertyHasChanged,
|
||||
const Identifier& property) {
|
||||
if (treeWhosePropertyHasChanged.getType() == StringRef("soundFont")) {
|
||||
if (treeWhosePropertyHasChanged.getType() == StringRef("presets")) {
|
||||
rows.clear();
|
||||
int numChildren{treeWhosePropertyHasChanged.getNumChildren()};
|
||||
for(int i{0}; i<numChildren; i++) {
|
||||
ValueTree child{treeWhosePropertyHasChanged.getChild(i)};
|
||||
int num{child.getProperty("num")};
|
||||
String name{child.getProperty("name")};
|
||||
rows.emplace_back(num, name);
|
||||
}
|
||||
// if (&treeWhosePropertyHasChanged == &valueTree) {
|
||||
if (property == StringRef("path")) {
|
||||
String soundFontPath{treeWhosePropertyHasChanged.getProperty("path", "")};
|
||||
// if (property == StringRef("path")) {
|
||||
// String soundFontPath{treeWhosePropertyHasChanged.getProperty("path", "")};
|
||||
// DEBUG_PRINT(soundFontPath);
|
||||
// if (soundFontPath.isNotEmpty()) {
|
||||
// loadFont(soundFontPath);
|
||||
// }
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void TableComponent::setRows(const vector<vector<string>>& rows, int initiallySelectedRow) {
|
||||
this->rows = rows;
|
||||
table.deselectAllRows();
|
||||
table.updateContent();
|
||||
table.getHeader().setSortColumnId(0, true);
|
||||
table.selectRow(initiallySelectedRow);
|
||||
table.repaint();
|
||||
}
|
||||
// void TableComponent::setRows(const vector<vector<string>>& rows, int initiallySelectedRow) {
|
||||
// this->rows = rows;
|
||||
// table.deselectAllRows();
|
||||
// table.updateContent();
|
||||
// table.getHeader().setSortColumnId(0, true);
|
||||
// table.selectRow(initiallySelectedRow);
|
||||
// table.repaint();
|
||||
// }
|
||||
|
||||
// This is overloaded from TableListBoxModel, and must return the total number of rows in our table
|
||||
int TableComponent::getNumRows()
|
||||
|
@ -160,7 +171,14 @@ void TableComponent::paintCell (
|
|||
g.setColour (getLookAndFeel().findColour (ListBox::textColourId));
|
||||
g.setFont (font);
|
||||
|
||||
g.drawText (rows[rowNumber][columnId-1], 2, 0, width - 4, height, Justification::centredLeft, true);
|
||||
TableRow& row{rows[rowNumber]};
|
||||
String text;
|
||||
if (columnId <= 1) {
|
||||
text = String(row.preset);
|
||||
} else {
|
||||
text = row.name;
|
||||
}
|
||||
g.drawText (text, 2, 0, width - 4, height, Justification::centredLeft, true);
|
||||
|
||||
g.setColour (getLookAndFeel().findColour (ListBox::backgroundColourId));
|
||||
g.fillRect (width - 1, 0, 1, height);
|
||||
|
@ -174,20 +192,25 @@ void TableComponent::sortOrderChanged (
|
|||
) {
|
||||
if (newSortColumnId != 0) {
|
||||
int selectedRowIx = table.getSelectedRow();
|
||||
vector<string> selectedRow;
|
||||
if (selectedRowIx >= 0) {
|
||||
selectedRow = rows[selectedRowIx];
|
||||
}
|
||||
// TableRow* selectedRow;
|
||||
// if (selectedRowIx >= 0) {
|
||||
// selectedRow = &rows[selectedRowIx];
|
||||
// }
|
||||
|
||||
TableComponent::DataSorter sorter (newSortColumnId, isForwards);
|
||||
sort(rows.begin(), rows.end(), sorter);
|
||||
|
||||
table.updateContent();
|
||||
|
||||
RangedAudioParameter *param {valueTreeState.getParameter("preset")};
|
||||
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||
int value{castParam->get()};
|
||||
|
||||
if (selectedRowIx >= 0) {
|
||||
for (auto it = rows.begin(); it != rows.end(); ++it) {
|
||||
if(*it == selectedRow) {
|
||||
int index = static_cast<int>(std::distance(rows.begin(), it));
|
||||
if(it->preset == value) {
|
||||
int index {static_cast<int>(std::distance(rows.begin(), it))};
|
||||
table.selectRow(index);
|
||||
break;
|
||||
}
|
||||
|
@ -206,8 +229,15 @@ int TableComponent::getColumnAutoSizeWidth (int columnId) {
|
|||
int widest = 32;
|
||||
|
||||
// find the widest bit of text in this column..
|
||||
for (int i = getNumRows(); --i >= 0;) {
|
||||
widest = jmax (widest, font.getStringWidth (rows[i][columnId-1]));
|
||||
for (int i{getNumRows()}; --i >= 0;) {
|
||||
TableRow& row{rows[i]};
|
||||
String text;
|
||||
if (columnId <= 1) {
|
||||
text = String(row.preset);
|
||||
} else {
|
||||
text = row.name;
|
||||
}
|
||||
widest = jmax (widest, font.getStringWidth (text));
|
||||
}
|
||||
|
||||
return widest + 8;
|
||||
|
@ -226,20 +256,24 @@ TableComponent::DataSorter::DataSorter (
|
|||
int columnByWhichToSort,
|
||||
bool forwards
|
||||
)
|
||||
: columnByWhichToSort (columnByWhichToSort),
|
||||
direction (forwards ? 1 : -1)
|
||||
: columnByWhichToSort (columnByWhichToSort)
|
||||
, direction (forwards ? 1 : -1)
|
||||
{}
|
||||
|
||||
bool TableComponent::DataSorter::operator ()(
|
||||
vector<string> first,
|
||||
vector<string> second
|
||||
TableRow first,
|
||||
TableRow second
|
||||
) {
|
||||
int result = String(first[columnByWhichToSort-1])
|
||||
.compareNatural (String(second[columnByWhichToSort-1]));
|
||||
|
||||
if (result == 0)
|
||||
result = String(first[0])
|
||||
.compareNatural (String(second[0]));
|
||||
int result;
|
||||
if (columnByWhichToSort <= 1) {
|
||||
result = compare(first.preset, second.preset);
|
||||
} else {
|
||||
result = first.name
|
||||
.compareNatural (second.name);
|
||||
if (result == 0) {
|
||||
result = compare(first.preset, second.preset);
|
||||
}
|
||||
}
|
||||
|
||||
result *= direction;
|
||||
|
||||
|
@ -252,7 +286,7 @@ void TableComponent::selectedRowsChanged (int row) {
|
|||
}
|
||||
// onRowSelected(rowToIDMapper(rows[row]));
|
||||
// onRowSelected(stoi(rows[row][0]));
|
||||
int newPreset{stoi(rows[row][0])};
|
||||
int newPreset{rows[row].preset};
|
||||
RangedAudioParameter *param {valueTreeState.getParameter("preset")};
|
||||
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||
|
@ -262,3 +296,11 @@ void TableComponent::selectedRowsChanged (int row) {
|
|||
bool TableComponent::keyPressed(const KeyPress &key) {
|
||||
return table.keyPressed(key);
|
||||
}
|
||||
|
||||
TableRow::TableRow(
|
||||
int preset,
|
||||
String name
|
||||
)
|
||||
: preset{preset}
|
||||
: name{name}
|
||||
{}
|
||||
|
|
|
@ -15,6 +15,21 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class TableRow {
|
||||
public:
|
||||
TableRow(
|
||||
int preset,
|
||||
String name
|
||||
);
|
||||
private:
|
||||
int preset;
|
||||
String name;
|
||||
|
||||
friend class TableComponent;
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TableRow)
|
||||
};
|
||||
|
||||
|
||||
class TableComponent : public Component,
|
||||
public TableListBoxModel,
|
||||
public ValueTree::Listener/*,
|
||||
|
@ -23,7 +38,7 @@ public:
|
|||
TableComponent(
|
||||
AudioProcessorValueTreeState& valueTreeState,
|
||||
// const vector<string> &columns,
|
||||
const vector<vector<string>> &rows,
|
||||
// const vector<TableRow> &rows,
|
||||
const function<void (int)> &onRowSelected,
|
||||
// const function<int (const vector<string>&)> &rowToIDMapper,
|
||||
int initiallySelectedRow
|
||||
|
@ -56,7 +71,7 @@ public:
|
|||
|
||||
void resized() override;
|
||||
|
||||
void setRows(const vector<vector<string>>& rows, int initiallySelectedRow);
|
||||
// void setRows(const vector<TableRow>& rows, int initiallySelectedRow);
|
||||
|
||||
bool keyPressed(const KeyPress &key) override;
|
||||
|
||||
|
@ -79,8 +94,8 @@ private:
|
|||
TableListBox table; // the table component itself
|
||||
Font font;
|
||||
|
||||
vector<string> columns;
|
||||
vector<vector<string>> rows;
|
||||
// vector<string> columns;
|
||||
vector<TableRow> rows;
|
||||
|
||||
function<void (int)> onRowSelected;
|
||||
// function<int (const vector<string>&)> rowToIDMapper;
|
||||
|
@ -94,8 +109,8 @@ private:
|
|||
);
|
||||
|
||||
bool operator ()(
|
||||
vector<string> first,
|
||||
vector<string> second
|
||||
TableRow first,
|
||||
TableRow second
|
||||
);
|
||||
|
||||
private:
|
||||
|
|
|
@ -35,11 +35,12 @@ TablesComponent::TablesComponent(
|
|||
};
|
||||
|
||||
presetTable = new TableComponent(
|
||||
valueTreeState,
|
||||
// {"#", "Name"},
|
||||
mapPresets(
|
||||
banksToPresets,
|
||||
selectedBank
|
||||
),
|
||||
// mapPresets(
|
||||
// banksToPresets,
|
||||
// selectedBank
|
||||
// ),
|
||||
[this](int preset){
|
||||
this->onPresetSelected(preset);
|
||||
},
|
||||
|
@ -169,24 +170,24 @@ bool TablesComponent::keyPressed(const KeyPress &key) {
|
|||
return presetTable->keyPressed(key);
|
||||
}
|
||||
|
||||
void TablesComponent::fontChanged(FluidSynthModel *, const String &) {
|
||||
banksToPresets = fluidSynthModel.getBanks();
|
||||
// void TablesComponent::fontChanged(FluidSynthModel *, const String &) {
|
||||
// banksToPresets = fluidSynthModel.getBanks();
|
||||
|
||||
fluid_preset_t* currentPreset = getCurrentPreset();
|
||||
// fluid_preset_t* currentPreset = getCurrentPreset();
|
||||
|
||||
selectedBank = fluid_preset_get_banknum(currentPreset);
|
||||
int selectedPreset = fluid_preset_get_num(currentPreset);
|
||||
// selectedBank = fluid_preset_get_banknum(currentPreset);
|
||||
// int selectedPreset = fluid_preset_get_num(currentPreset);
|
||||
|
||||
presetTable->setRows(
|
||||
mapPresets(
|
||||
banksToPresets,
|
||||
selectedBank
|
||||
),
|
||||
presetToIndexMapper(selectedPreset)
|
||||
);
|
||||
// presetTable->setRows(
|
||||
// mapPresets(
|
||||
// banksToPresets,
|
||||
// selectedBank
|
||||
// ),
|
||||
// presetToIndexMapper(selectedPreset)
|
||||
// );
|
||||
|
||||
banks->setItems(
|
||||
mapBanks(banksToPresets),
|
||||
selectedBank
|
||||
);
|
||||
}
|
||||
// banks->setItems(
|
||||
// mapBanks(banksToPresets),
|
||||
// selectedBank
|
||||
// );
|
||||
// }
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class TablesComponent : public Component,
|
||||
public FluidSynthModel::Listener
|
||||
class TablesComponent : public Component/*,
|
||||
public FluidSynthModel::Listener */
|
||||
{
|
||||
public:
|
||||
TablesComponent(
|
||||
|
@ -28,7 +28,7 @@ public:
|
|||
void resized() override;
|
||||
|
||||
bool keyPressed(const KeyPress &key) override;
|
||||
void fontChanged(FluidSynthModel *, const String &) override;
|
||||
// void fontChanged(FluidSynthModel *, const String &) override;
|
||||
|
||||
private:
|
||||
AudioProcessorValueTreeState& valueTreeState;
|
||||
|
|
|
@ -9,3 +9,11 @@
|
|||
#define DEBUG_PRINT(str)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace Util {
|
||||
inline int compare(int a, int b) {
|
||||
if (a > b) return 1;
|
||||
if (a == b) return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user