# ButtonAttachment doesn't call AudioProcessorValueTreeState::Listener::parameterChanged

**URL:** <https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515>\
**Category:** General JUCE discussion\
**Created:** [May 3, 2018, 9:34am UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515 "2018-05-03T09:34:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 3, 2018, 9:34am UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/1 "2018-05-03T09:34:49Z")

</div>

Hi there,  
I’m still learning here so I hope that question is not dumb…

So far I’m managing all my Sliders and Comboboxes using the AudioProcessorValueTreeState as explained in [this tutorial](https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html). Of course I’ve set up my AudioProcessor to inherit from AudioProcessorValueTreeState::Listener and I override the parameterChanged callback in my AudioProcessor too.  
So far so good, everything works fine.

Now I’ve added a TextButton and set up a ButtonAttachment (the same way I’ve done it before with the Sliders and ComboBoxes). However, when I press the button the parameterChanged function is not called.

Why is that and how do I make this work?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![noahdayan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/noahdayan/32/4093_2.png) [@noahdayan](https://forum.juce.com/u/noahdayan)\
**Post date:** [May 3, 2018, 10:12am UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/2 "2018-05-03T10:12:51Z")

</div>

The advantage of using `Attachment` classes is that you don’t need to inherit from a `Listener` class to have your `Component` control the parameters of the `AudioProcessor`.

If you still want to inherit from `AudioProcessorValueTreeState::Listener` and get callbacks through `parameterChanged()` you need to add yourself as a listener by calling `addParameterListener()`.

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 3, 2018, 12:37pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/3 "2018-05-03T12:37:10Z")

</div>

Sorry, I don’t see how this answers my question… It actually raises more 😉

If my AudioProcessor doesn’t inherit from AudioProcessorValueTreeState::Listener so I can override parameterChanged, then where would I call the function to set my parameter (e.g. setCutoff(value))? Shall I use getRawParameterValue each time the processBlock is called? That doesn’t really make sense to me neither…

At the moment my AudioProcessor inherits from AudioProcessorValueTreeState::Listener and also has an AudioProcessorValueTreeState as a class member. It passes the AudioProcessorValueTreeState by reference to the PluginEditor.  
In the PluginEditor I’m using Attachments and in the AudioProcessor I’m overriding the parameterChanged function as well as using createAndAddParameter and addParameterListener. Actually I’m just doing like in the tutorial - is there a better way to do this?

Last but not least: How do I get that TextButton to work? I’ve used addParameterListener already, because that’s how it worked with Sliders and Comboboxes as well…

---

<div class="post-metadata">

**Author:** ![noahdayan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/noahdayan/32/4093_2.png) [@noahdayan](https://forum.juce.com/u/noahdayan)\
**Post date:** [May 3, 2018, 1:30pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/4 "2018-05-03T13:30:29Z")

</div>

As it stands, the tutorial currently uses the `getRawParameterValue()` to retrieve a pointer that is later dereferenced in the `processBlock()`.

As far as I know, the tutorial does not inherit from `AudioProcessorValueTreeState::Listener` nor does it call the `addParameterListener()` function.

All you need to do is, call `createAndAddParameter()` in the `AudioProcessor` and create a `ButtonAttachment` in the `AudioProcessorEditor` by passing the `TextButton` in the constructor.

Does that make sense?

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 3, 2018, 2:20pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/5 "2018-05-03T14:20:40Z")

</div>

You are right, I think I combined two tutorials somehow… Anyway, it all makes sense, thanks!  
Is there any disadvantage in doing it the way I do? I kind of like the parameterChanged function because it keeps my processBlock clean…  
Also I still wonder why the parameterChanged is not called when I push the button, it does so for Sliders and ComboBoxes.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [May 3, 2018, 3:04pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/6 "2018-05-03T15:04:55Z")

</div>

Can you provide a minimal working example, maybe as a [PIP](https://forum.juce.com/t/what-is-a-pip/26821)? It would be much easier for us to work out what’s going on if we can reproduce the problem.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 3, 2018, 3:12pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/7 "2018-05-03T15:12:52Z")

</div>

A first thing to check would be for typos when you registered the parameterListener, where you have to pass the paramID. When you use a string literal in the code, try to declare it once as static String, so you can use auto-complete and the compiler can check for typos.

@noahdayan maybe we can add in `void AudioProcessorValueTreeState::addParameterListener (StringRef paramID, Listener* listener)` something like `else jassertfalse;`, in case somebody tries to listen to an unattended paramID…

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 3, 2018, 7:34pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/8 "2018-05-03T19:34:07Z")

</div>

Here it is! The generated PIP wasn’t working and I’m not in the mood at the moment to get my head around that now - but the files are really small anyway. Thanks!  
[PluginProcessor.cpp](https://forum.juce.com/uploads/short-url/uAZ20Twv67JnIgP3JAUvPFhRaZo.cpp) (6.6 KB)  
[PluginEditor.h](https://forum.juce.com/uploads/short-url/xbCE5GPI5lARqKCWhCmLlvoaWxU.h) (1.3 KB)  
[PluginProcessor.h](https://forum.juce.com/uploads/short-url/4Yqhm8RPKLiBZSVchyaCz1VSiZo.h) (2.5 KB)  
[PluginEditor.cpp](https://forum.juce.com/uploads/short-url/bodYp8htdy3R5ebO0D5nhNuestc.cpp) (1.5 KB)

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 3, 2018, 7:36pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/9 "2018-05-03T19:36:42Z")

</div>

That’s a good idea about using static String! However I just checked my project and there is no typo. The example I’ve uploaded doesn’t call parameterChanged either btw  
Adding `else jassertfalse` for detecting unattended paramIDs is still a nice idea 😉  
Thanks!

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 3, 2018, 7:52pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/10 "2018-05-03T19:52:06Z")

</div>

So the logic is, that the AudioProcessorValueTreeState calls the parameterChanged() of the processor. However you are overriding it as a private method, so the state doesn’t see this method.

Please try if it works if you move the parameterChanged() into the public scope…

HTH

(Kind of strange that it compiles though, since from a public point of view the processor is still pure abstract…)

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 3, 2018, 8:04pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/11 "2018-05-03T20:04:43Z")

</div>

Ok, that makes sense, however even moving the parameterChanged() function to public doesn’t invoke a callback when using a TextButton. It all works fine for Sliders and Comboboxes though, even when the function was private 🤨  
Would you suggest that workflow in general btw? As I said, I’m still learning… I’m thinking about just using a Timer Callback instead, comparing the current value of each parameter to the one used in my AudioProcessor - that will make sure that my AudioProcessor’s parameters are the same as shown in the GUI because parameterChanged() is not comparing values but only gets called when a change happens… Am I right?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 3, 2018, 9:26pm UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/12 "2018-05-03T21:26:47Z")

</div>

Ok, I compiled it an checked…  
To get a reaction, the button should change it’s state, so it helps to set

```auto
textButton.setClickingTogglesState (true);
addAndMakeVisible (textButton);

```

and then you should get change messages.

HTH

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [May 4, 2018, 6:48am UTC](https://forum.juce.com/t/buttonattachment-doesnt-call-audioprocessorvaluetreestate-parameterchanged/27515/13 "2018-05-04T06:48:54Z")

</div>

Yes! That did it! Thanks a lot 🙂
