# Update the UI when an APVTS parameter changes

**URL:** <https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362>\
**Category:** General JUCE discussion\
**Created:** [January 3, 2024, 5:12pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362 "2024-01-03T17:12:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.juce.com/u/Ben)\
**Post date:** [January 3, 2024, 5:12pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/1 "2024-01-03T17:12:18Z")

</div>

I have a UI display with setBufferedToImage(true) and I would like to only repaint when actually necessary. It’s a filter response display that should react whenever one of my EQ parameters changes. My editor is a listener to all of these parameters and sets a flag “eqDisplayChanged” when one of them changes. Then in the timer callback, the display is repainted.

The problem is that the parameter changes are not reflected in this callback. I sort of expected this because the documentation does mention that I’m supposed to use the “newValue” to see the updated value. But I thought that in the Timer thread I could expect the updated value. I’m kind of at a loss how I could update the display properly if I have no way of knowing when the parameter has actually been updated. I could manually keep track of every EQ parameter but that’s a really ugly solution. I could blindly repaint every Timer tick but I’d like to avoid that.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [January 3, 2024, 11:18pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/2 "2024-01-03T23:18:25Z")

</div>

If you query the value from the APVTS itself at the time your update the UI, they should be updated. Not sure when/where you’re getting those values.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.juce.com/u/Ben)\
**Post date:** [January 3, 2024, 11:42pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/3 "2024-01-03T23:42:42Z")

</div>

Are you sure? For getRawParamter value the docs say

> Returns a pointer to a floating point representation of a particular parameter which a realtime process can read to find out its current value.
> 
> Note that calling this method from within AudioProcessorValueTreeState::Listener::parameterChanged() is not guaranteed to return an up-to-date value for the parameter.

Right now, I’m trying to just store separate variables in the Component that reflect the more up to date value, but it’s really not such a nice solution…

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.juce.com/u/Ben)\
**Post date:** [January 3, 2024, 11:48pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/4 "2024-01-03T23:48:29Z")

</div>

I tried to use Value::Listener directly but for some reason the valueChanged is not called at all…

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [January 3, 2024, 11:55pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/5 "2024-01-03T23:55:50Z")

</div>

Not using getRawParameter. Get the parameter by ID from the APVTS, and get its value directly from the parameter itself.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.juce.com/u/Ben)\
**Post date:** [January 3, 2024, 11:58pm UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/6 "2024-01-03T23:58:55Z")

</div>

Same result for me unfortunately. apvts.getParameterAsValue().getValue() was not returning the same thing as the newValue passed into parameterChanged. Either way, do they not use the same underlying logic?

---

<div class="post-metadata">

**Author:** ![zsliu98](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zsliu98/32/22502_2.png) [@zsliu98](https://forum.juce.com/u/zsliu98)\
**Post date:** [January 4, 2024, 12:33am UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/7 "2024-01-04T00:33:43Z")

</div>

IIRC, I used the same method in a wave-shapper and it did work. I am not sure why it does not work in your case. According to the documentation, `getRawParameterValue()` should return the up-to-date value outside the `parameterChanged()`.  
By the way, why not using `juce::AsyncUpdater` to trigger the `repaint()`? Since you only need to repaint when the filter changes, it is more intuitive.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.juce.com/u/Ben)\
**Post date:** [January 4, 2024, 1:08am UTC](https://forum.juce.com/t/update-the-ui-when-an-apvts-parameter-changes/59362/8 "2024-01-04T01:08:42Z")

</div>

I have it working with the solution I mentioned but still not sure why getRawParameterValue isn’t working… I’ll look into it if I run into the problem again on another component.

I suppose I could use AsyncUpdater but doesn’t repaint just notify the UI thread (or whatever handles it) anyways?
