render pills. use cheat to notify that tree of presets/banks has changed.

This commit is contained in:
Alex Birch 2019-07-14 19:31:05 +01:00
parent 11d7296813
commit 99bb294ece
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
7 changed files with 78 additions and 22 deletions

View File

@ -379,6 +379,8 @@ void FluidSynthModel::loadFont(const String &absPath) {
// valueTreeState.state.getChildWithName("presets") = presets; // valueTreeState.state.getChildWithName("presets") = presets;
valueTreeState.state.getChildWithName("banks").copyPropertiesAndChildrenFrom(banks, nullptr); valueTreeState.state.getChildWithName("banks").copyPropertiesAndChildrenFrom(banks, nullptr);
valueTreeState.state.getChildWithName("presets").copyPropertiesAndChildrenFrom(presets, nullptr); valueTreeState.state.getChildWithName("presets").copyPropertiesAndChildrenFrom(presets, nullptr);
valueTreeState.state.getChildWithName("banks").sendPropertyChangeMessage("synthetic");
valueTreeState.state.getChildWithName("presets").sendPropertyChangeMessage("synthetic");
#if JUCE_DEBUG #if JUCE_DEBUG
unique_ptr<XmlElement> xml{valueTreeState.state.createXml()}; unique_ptr<XmlElement> xml{valueTreeState.state.createXml()};

View File

@ -19,6 +19,7 @@ Pill::Pill(
, bank{bank} , bank{bank}
, textButton{String(bank)} , textButton{String(bank)}
{ {
setOpaque(true);
textButton.setConnectedEdges ( textButton.setConnectedEdges (
(isFirst ? 0 : Button::ConnectedOnLeft) (isFirst ? 0 : Button::ConnectedOnLeft)
| (isLast ? 0 : Button::ConnectedOnRight) | (isLast ? 0 : Button::ConnectedOnRight)
@ -27,11 +28,23 @@ Pill::Pill(
loadToggleState(); loadToggleState();
textButton.setClickingTogglesState(true); textButton.setClickingTogglesState(true);
addAndMakeVisible(textButton);
valueTreeState.addParameterListener("bank", this); valueTreeState.addParameterListener("bank", this);
// valueTreeState.state.addListener(this); // valueTreeState.state.addListener(this);
textButton.addListener(this); textButton.addListener(this);
} }
void Pill::paint (Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
}
void Pill::resized() {
textButton.setBounds(getLocalBounds());
}
Pill::~Pill() { Pill::~Pill() {
valueTreeState.removeParameterListener("bank", this); valueTreeState.removeParameterListener("bank", this);
// valueTreeState.state.removeListener(this); // valueTreeState.state.removeListener(this);
@ -101,8 +114,10 @@ void Pills::valueTreePropertyChanged(
ValueTree& treeWhosePropertyHasChanged, ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) { const Identifier& property) {
if (treeWhosePropertyHasChanged.getType() == StringRef("banks")) { if (treeWhosePropertyHasChanged.getType() == StringRef("banks")) {
if (property == StringRef("synthetic")) {
loadModelFrom(treeWhosePropertyHasChanged); loadModelFrom(treeWhosePropertyHasChanged);
} }
}
} }
void Pills::loadModelFrom(ValueTree& banks) { void Pills::loadModelFrom(ValueTree& banks) {
@ -114,13 +129,15 @@ void Pills::loadModelFrom(ValueTree& banks) {
// rows.push_back(unique_ptr<Pill>(new Pill(), [](Pill* pill) { // rows.push_back(unique_ptr<Pill>(new Pill(), [](Pill* pill) {
// pill->remo // pill->remo
// })); // }));
pills.push_back( unique_ptr<Pill> pill{make_unique<Pill>(
make_unique<Pill>(
valueTreeState, valueTreeState,
num, num,
i == 0, i == 0,
i == numChildren - 1)); i == numChildren - 1)};
addAndMakeVisible(pill.get());
pills.push_back(move(pill));
} }
resized();
} }
// void Pills::populate(int initiallySelectedItem) { // void Pills::populate(int initiallySelectedItem) {
@ -210,7 +227,7 @@ void Pills::resized() {
Rectangle<int> r2 (getLocalBounds()); Rectangle<int> r2 (getLocalBounds());
r2.removeFromLeft(equalWidth * index); r2.removeFromLeft(equalWidth * index);
r2.removeFromRight(equalWidth * (static_cast<int>(pills.size())-index-1)); r2.removeFromRight(equalWidth * (static_cast<int>(pills.size())-index-1));
pill->textButton.setBounds (r2); pill->setBounds(r2);
index++; index++;
} }
} }

View File

@ -9,7 +9,8 @@
using namespace std; using namespace std;
class Pill class Pill
: public Button::Listener : public Component
, public Button::Listener
, public AudioProcessorValueTreeState::Listener , public AudioProcessorValueTreeState::Listener
{ {
public: public:
@ -23,6 +24,9 @@ public:
void buttonClicked (Button* button) override; void buttonClicked (Button* button) override;
void resized() override;
void paint(Graphics& g) override;
virtual void parameterChanged (const String& parameterID, float newValue) override; virtual void parameterChanged (const String& parameterID, float newValue) override;
private: private:
void loadToggleState(); void loadToggleState();

View File

@ -73,7 +73,7 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(
tablesComponent.setWantsKeyboardFocus(false); tablesComponent.setWantsKeyboardFocus(false);
setWantsKeyboardFocus(true); setWantsKeyboardFocus(true);
addAndMakeVisible (midiKeyboard); addAndMakeVisible(midiKeyboard);
addAndMakeVisible(slidersComponent); addAndMakeVisible(slidersComponent);
addAndMakeVisible(tablesComponent); addAndMakeVisible(tablesComponent);

View File

@ -73,8 +73,8 @@ AudioProcessorValueTreeState::ParameterLayout JuicySFAudioProcessor::createParam
// make_unique<AudioParameterInt>("uiHeightTemp", "height of this plugin's GUI. Editor writes here on change (e.g. on window resize). Processor copies this into Persist before any save.", GuiConstants::minHeight, GuiConstants::maxHeight, GuiConstants::minHeight, "UI Height Temp" ), // make_unique<AudioParameterInt>("uiHeightTemp", "height of this plugin's GUI. Editor writes here on change (e.g. on window resize). Processor copies this into Persist before any save.", GuiConstants::minHeight, GuiConstants::maxHeight, GuiConstants::minHeight, "UI Height Temp" ),
// make_unique<AudioParameterInt>("uiWidth", "width of this plugin's GUI", GuiConstants::minWidth, GuiConstants::maxWidth, GuiConstants::minWidth, "UI Width" ), // make_unique<AudioParameterInt>("uiWidth", "width of this plugin's GUI", GuiConstants::minWidth, GuiConstants::maxWidth, GuiConstants::minWidth, "UI Width" ),
// make_unique<AudioParameterInt>("uiHeight", "height of this plugin's GUI", GuiConstants::minHeight, GuiConstants::maxHeight, GuiConstants::minHeight, "UI Height" ), // make_unique<AudioParameterInt>("uiHeight", "height of this plugin's GUI", GuiConstants::minHeight, GuiConstants::maxHeight, GuiConstants::minHeight, "UI Height" ),
// todo: check whether bank really is 0-127 // SoundFont 2.4 spec section 7.2: zero through 127, or 128.
make_unique<AudioParameterInt>("bank", "which bank is selected in the soundfont", MidiConstants::midiMinValue, MidiConstants::midiMaxValue, MidiConstants::midiMinValue, "Bank" ), make_unique<AudioParameterInt>("bank", "which bank is selected in the soundfont", MidiConstants::midiMinValue, 128, MidiConstants::midiMinValue, "Bank" ),
// note: banks may be sparse, and lack a 0th preset. so defend against this. // note: banks may be sparse, and lack a 0th preset. so defend against this.
make_unique<AudioParameterInt>("preset", "which patch (aka patch, program, instrument) is selected in the soundfont", MidiConstants::midiMinValue, MidiConstants::midiMaxValue, MidiConstants::midiMinValue, "Preset" ), make_unique<AudioParameterInt>("preset", "which patch (aka patch, program, instrument) is selected in the soundfont", MidiConstants::midiMinValue, MidiConstants::midiMaxValue, MidiConstants::midiMinValue, "Preset" ),
make_unique<AudioParameterInt>("attack", "volume envelope attack time", MidiConstants::midiMinValue, MidiConstants::midiMaxValue, MidiConstants::midiMinValue, "A" ), make_unique<AudioParameterInt>("attack", "volume envelope attack time", MidiConstants::midiMinValue, MidiConstants::midiMaxValue, MidiConstants::midiMinValue, "A" ),

View File

@ -120,19 +120,52 @@ void TableComponent::parameterChanged(const String& parameterID, float newValue)
} }
} }
// void TableComponent::valueTreePropertyChanged( void TableComponent::valueTreePropertyChanged(
// ValueTree& treeWhosePropertyHasChanged, ValueTree& treeWhosePropertyHasChanged,
// const Identifier& property) { const Identifier& property) {
// if (treeWhosePropertyHasChanged.getType() == StringRef("presets")) { if (treeWhosePropertyHasChanged.getType() == StringRef("presets")) {
// loadModelFrom(treeWhosePropertyHasChanged); if (property == StringRef("synthetic")) {
loadModelFrom(treeWhosePropertyHasChanged);
}
}
}
// void TableComponent::valueTreeParentChanged(ValueTree& treeWhoseParentHasChanged) {
// if (treeWhoseParentHasChanged.getType() == StringRef("presets")) {
// loadModelFrom(treeWhoseParentHasChanged);
// } // }
// } // }
void TableComponent::valueTreeParentChanged(ValueTree& treeWhoseParentHasChanged) { // void TableComponent::valueTreePropertyChanged(
if (treeWhoseParentHasChanged.getType() == StringRef("presets")) { // ValueTree& treeWhosePropertyHasChanged,
loadModelFrom(treeWhoseParentHasChanged); // const Identifier& property) {
} // DEBUG_PRINT(treeWhosePropertyHasChanged.getType().toString());
} // }
// void TableComponent::valueTreeChildAdded(
// ValueTree& parentTree,
// ValueTree& childWhichHasBeenAdded) {
// DEBUG_PRINT(parentTree.getType().toString());
// }
// void TableComponent::valueTreeChildRemoved(
// ValueTree& parentTree,
// ValueTree& childWhichHasBeenRemoved,
// int indexFromWhichChildWasRemoved) {
// DEBUG_PRINT(parentTree.getType().toString());
// }
// void TableComponent::valueTreeChildOrderChanged(
// ValueTree& parentTreeWhoseChildrenHaveMoved,
// int oldIndex,
// int newIndex) {
// DEBUG_PRINT(parentTreeWhoseChildrenHaveMoved.getType().toString());
// }
// void TableComponent::valueTreeParentChanged(
// ValueTree& treeWhoseParentHasChanged) {
// DEBUG_PRINT(treeWhoseParentHasChanged.getType().toString());
// }
// void TableComponent::valueTreeRedirected(
// ValueTree& treeWhichHasBeenChanged) {
// DEBUG_PRINT(treeWhichHasBeenChanged.getType().toString());
// }
// void TableComponent::setRows(const vector<vector<string>>& rows, int initiallySelectedRow) { // void TableComponent::setRows(const vector<vector<string>>& rows, int initiallySelectedRow) {
// this->rows = rows; // this->rows = rows;

View File

@ -79,8 +79,8 @@ public:
virtual void parameterChanged (const String& parameterID, float newValue) override; virtual void parameterChanged (const String& parameterID, float newValue) override;
inline virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) override {}; const Identifier& property) override;
inline virtual void valueTreeChildAdded (ValueTree& parentTree, inline virtual void valueTreeChildAdded (ValueTree& parentTree,
ValueTree& childWhichHasBeenAdded) override {}; ValueTree& childWhichHasBeenAdded) override {};
inline virtual void valueTreeChildRemoved (ValueTree& parentTree, inline virtual void valueTreeChildRemoved (ValueTree& parentTree,
@ -88,7 +88,7 @@ public:
int indexFromWhichChildWasRemoved) override {}; int indexFromWhichChildWasRemoved) override {};
inline virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved, inline virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved,
int oldIndex, int newIndex) override {}; int oldIndex, int newIndex) override {};
virtual void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) override; inline virtual void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) override {};
inline virtual void valueTreeRedirected (ValueTree& treeWhichHasBeenChanged) override {}; inline virtual void valueTreeRedirected (ValueTree& treeWhichHasBeenChanged) override {};
private: private:
void loadModelFrom(ValueTree& presets); void loadModelFrom(ValueTree& presets);