pills no longer listen to valueTree; I didn't like the idea of having up to 128 listeners when the parent could do dispatch with just one listener
This commit is contained in:
parent
745adf8fde
commit
304ec6ce88
|
@ -25,20 +25,19 @@ Pill::Pill(
|
|||
| (isLast ? 0 : Button::ConnectedOnRight)
|
||||
);
|
||||
textButton.setRadioGroupId(34567);
|
||||
loadToggleState();
|
||||
// loadToggleState();
|
||||
textButton.setClickingTogglesState(true);
|
||||
|
||||
addAndMakeVisible(textButton);
|
||||
|
||||
valueTreeState.addParameterListener("bank", this);
|
||||
// valueTreeState.addParameterListener("bank", this);
|
||||
// valueTreeState.state.addListener(this);
|
||||
textButton.addListener(this);
|
||||
}
|
||||
|
||||
void Pill::paint (Graphics& g)
|
||||
{
|
||||
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));
|
||||
g.fillAll(getLookAndFeel().findColour(ResizableWindow::backgroundColourId));
|
||||
}
|
||||
|
||||
void Pill::resized() {
|
||||
|
@ -46,19 +45,23 @@ void Pill::resized() {
|
|||
}
|
||||
|
||||
Pill::~Pill() {
|
||||
valueTreeState.removeParameterListener("bank", this);
|
||||
// valueTreeState.removeParameterListener("bank", this);
|
||||
// valueTreeState.state.removeListener(this);
|
||||
textButton.removeListener(this);
|
||||
}
|
||||
|
||||
void Pill::loadToggleState() {
|
||||
RangedAudioParameter *param {valueTreeState.getParameter("bank")};
|
||||
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||
int value{castParam->get()};
|
||||
textButton.setToggleState(value == bank, dontSendNotification);
|
||||
void Pill::bankChanged(int bank) {
|
||||
textButton.setToggleState(this->bank == bank, dontSendNotification);
|
||||
}
|
||||
|
||||
// void Pill::loadToggleState() {
|
||||
// RangedAudioParameter *param {valueTreeState.getParameter("bank")};
|
||||
// jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||
// AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||
// int value{castParam->get()};
|
||||
// textButton.setToggleState(value == bank, dontSendNotification);
|
||||
// }
|
||||
|
||||
void Pill::buttonClicked (Button* button) {
|
||||
// selected = button;
|
||||
// onItemSelected(itemToIDMapper(button->getName().toStdString()));
|
||||
|
@ -68,11 +71,11 @@ void Pill::buttonClicked (Button* button) {
|
|||
*castParam = bank;
|
||||
}
|
||||
|
||||
void Pill::parameterChanged(const String& parameterID, float newValue) {
|
||||
if (parameterID == "bank") {
|
||||
loadToggleState();
|
||||
}
|
||||
}
|
||||
// void Pill::parameterChanged(const String& parameterID, float newValue) {
|
||||
// if (parameterID == "bank") {
|
||||
// loadToggleState();
|
||||
// }
|
||||
// }
|
||||
|
||||
// void Pill::valueTreePropertyChanged(
|
||||
// ValueTree& treeWhosePropertyHasChanged,
|
||||
|
@ -104,12 +107,30 @@ Pills::Pills(
|
|||
loadModelFrom(banks);
|
||||
|
||||
valueTreeState.state.addListener(this);
|
||||
valueTreeState.addParameterListener("bank", this);
|
||||
}
|
||||
|
||||
Pills::~Pills() {
|
||||
valueTreeState.removeParameterListener("bank", this);
|
||||
valueTreeState.state.removeListener(this);
|
||||
}
|
||||
|
||||
void Pills::parameterChanged(const String& parameterID, float newValue) {
|
||||
if (parameterID == "bank") {
|
||||
updatePillToggleStates();
|
||||
}
|
||||
}
|
||||
|
||||
void Pills::updatePillToggleStates() {
|
||||
RangedAudioParameter *param {valueTreeState.getParameter("bank")};
|
||||
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||
int bank{castParam->get()};
|
||||
for (auto& pill: pills) {
|
||||
pill->bankChanged(bank);
|
||||
}
|
||||
}
|
||||
|
||||
void Pills::valueTreePropertyChanged(
|
||||
ValueTree& treeWhosePropertyHasChanged,
|
||||
const Identifier& property) {
|
||||
|
@ -137,6 +158,7 @@ void Pills::loadModelFrom(ValueTree& banks) {
|
|||
addAndMakeVisible(pill.get());
|
||||
pills.push_back(move(pill));
|
||||
}
|
||||
updatePillToggleStates();
|
||||
resized();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ using namespace std;
|
|||
class Pill
|
||||
: public Component
|
||||
, public Button::Listener
|
||||
, public AudioProcessorValueTreeState::Listener
|
||||
// , public AudioProcessorValueTreeState::Listener
|
||||
{
|
||||
public:
|
||||
Pill(
|
||||
|
@ -22,14 +22,16 @@ public:
|
|||
);
|
||||
~Pill();
|
||||
|
||||
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;
|
||||
void bankChanged(int bank);
|
||||
|
||||
// virtual void parameterChanged (const String& parameterID, float newValue) override;
|
||||
private:
|
||||
void loadToggleState();
|
||||
// void loadToggleState();
|
||||
|
||||
AudioProcessorValueTreeState& valueTreeState;
|
||||
int bank;
|
||||
|
@ -41,6 +43,7 @@ private:
|
|||
class Pills
|
||||
: public Component
|
||||
, public ValueTree::Listener
|
||||
, public AudioProcessorValueTreeState::Listener
|
||||
{
|
||||
public:
|
||||
Pills(
|
||||
|
@ -61,6 +64,8 @@ public:
|
|||
// void buttonClicked (Button* button) override;
|
||||
void cycle(bool right);
|
||||
|
||||
virtual void parameterChanged (const String& parameterID, float newValue) override;
|
||||
|
||||
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
|
||||
const Identifier& property) override;
|
||||
inline virtual void valueTreeChildAdded (ValueTree& parentTree,
|
||||
|
@ -87,6 +92,8 @@ private:
|
|||
|
||||
// Pill* addToList (Pill* newButton);
|
||||
|
||||
void updatePillToggleStates();
|
||||
|
||||
void populate(int initiallySelectedItem);
|
||||
void resized() override;
|
||||
void paint(Graphics& g) override;
|
||||
|
|
Loading…
Reference in New Issue
Block a user