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("banks").copyPropertiesAndChildrenFrom(banks, nullptr);
valueTreeState.state.getChildWithName("presets").copyPropertiesAndChildrenFrom(presets, nullptr);
valueTreeState.state.getChildWithName("banks").sendPropertyChangeMessage("synthetic");
valueTreeState.state.getChildWithName("presets").sendPropertyChangeMessage("synthetic");
#if JUCE_DEBUG
unique_ptr<XmlElement> xml{valueTreeState.state.createXml()};

View File

@ -19,6 +19,7 @@ Pill::Pill(
, bank{bank}
, textButton{String(bank)}
{
setOpaque(true);
textButton.setConnectedEdges (
(isFirst ? 0 : Button::ConnectedOnLeft)
| (isLast ? 0 : Button::ConnectedOnRight)
@ -26,12 +27,24 @@ Pill::Pill(
textButton.setRadioGroupId(34567);
loadToggleState();
textButton.setClickingTogglesState(true);
addAndMakeVisible(textButton);
valueTreeState.addParameterListener("bank", this);
// valueTreeState.state.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() {
valueTreeState.removeParameterListener("bank", this);
// valueTreeState.state.removeListener(this);
@ -101,7 +114,9 @@ void Pills::valueTreePropertyChanged(
ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) {
if (treeWhosePropertyHasChanged.getType() == StringRef("banks")) {
loadModelFrom(treeWhosePropertyHasChanged);
if (property == StringRef("synthetic")) {
loadModelFrom(treeWhosePropertyHasChanged);
}
}
}
@ -114,13 +129,15 @@ void Pills::loadModelFrom(ValueTree& banks) {
// rows.push_back(unique_ptr<Pill>(new Pill(), [](Pill* pill) {
// pill->remo
// }));
pills.push_back(
make_unique<Pill>(
unique_ptr<Pill> pill{make_unique<Pill>(
valueTreeState,
num,
i == 0,
i == numChildren - 1));
i == numChildren - 1)};
addAndMakeVisible(pill.get());
pills.push_back(move(pill));
}
resized();
}
// void Pills::populate(int initiallySelectedItem) {
@ -210,7 +227,7 @@ void Pills::resized() {
Rectangle<int> r2 (getLocalBounds());
r2.removeFromLeft(equalWidth * index);
r2.removeFromRight(equalWidth * (static_cast<int>(pills.size())-index-1));
pill->textButton.setBounds (r2);
pill->setBounds(r2);
index++;
}
}

View File

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

View File

@ -73,7 +73,7 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(
tablesComponent.setWantsKeyboardFocus(false);
setWantsKeyboardFocus(true);
addAndMakeVisible (midiKeyboard);
addAndMakeVisible(midiKeyboard);
addAndMakeVisible(slidersComponent);
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>("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" ),
// todo: check whether bank really is 0-127
make_unique<AudioParameterInt>("bank", "which bank is selected in the soundfont", MidiConstants::midiMinValue, MidiConstants::midiMaxValue, MidiConstants::midiMinValue, "Bank" ),
// 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, 128, MidiConstants::midiMinValue, "Bank" ),
// 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>("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(
// ValueTree& treeWhosePropertyHasChanged,
// const Identifier& property) {
// if (treeWhosePropertyHasChanged.getType() == StringRef("presets")) {
// loadModelFrom(treeWhosePropertyHasChanged);
void TableComponent::valueTreePropertyChanged(
ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) {
if (treeWhosePropertyHasChanged.getType() == StringRef("presets")) {
if (property == StringRef("synthetic")) {
loadModelFrom(treeWhosePropertyHasChanged);
}
}
}
// void TableComponent::valueTreeParentChanged(ValueTree& treeWhoseParentHasChanged) {
// if (treeWhoseParentHasChanged.getType() == StringRef("presets")) {
// loadModelFrom(treeWhoseParentHasChanged);
// }
// }
void TableComponent::valueTreeParentChanged(ValueTree& treeWhoseParentHasChanged) {
if (treeWhoseParentHasChanged.getType() == StringRef("presets")) {
loadModelFrom(treeWhoseParentHasChanged);
}
}
// void TableComponent::valueTreePropertyChanged(
// ValueTree& treeWhosePropertyHasChanged,
// 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) {
// this->rows = rows;

View File

@ -79,8 +79,8 @@ public:
virtual void parameterChanged (const String& parameterID, float newValue) override;
inline virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) override {};
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) override;
inline virtual void valueTreeChildAdded (ValueTree& parentTree,
ValueTree& childWhichHasBeenAdded) override {};
inline virtual void valueTreeChildRemoved (ValueTree& parentTree,
@ -88,7 +88,7 @@ public:
int indexFromWhichChildWasRemoved) override {};
inline virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved,
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 {};
private:
void loadModelFrom(ValueTree& presets);