Page 1 of 1

SetValue() doesn't update the GUI.

Posted: Sun Jan 22, 2023 5:39 am
by Centripidity
Calling SetValue on a knob in the Notify method does not appear to update the GUI for the knob.

As a simple example I have a single knob (knob1) and in the Notify method the following code:

Code: Select all

      case Knob_Changed:   // doubleValue is the new VoltageKnob value
      {
         if(component == knob1)
         {
            if (doubleValue > 0.5)
            {
               knob1.SetValue(0.5, true);
            }
         }
      }
      break;
As expected, if the knob is dragged by mouse the code never lets the knobs value get above 0.5 but the knob graphic can rotate beyond the 0.5 position.

Is this just a limitation of the API or an I doing this wrong?

Basically, I need to restrict a knobs value to below some threshold but that threshold value changes while the code is running.

Should I be trying to change the Max and Min values on the fly?

Cheers,
Peter

Re: SetValue() doesn't update the GUI.

Posted: Sun Jan 22, 2023 2:40 pm
by AllanH
In view of your description, I suspect you have to use a combination of SetRange​() and SetKnobParams​() to set min/max values and start/end angles.

Speculation: If VM is written in JUCE, I do not think the mouse-drag code uses the current value until the drag has ended, i.e. you let go of the mouse button.

Re: SetValue() doesn't update the GUI.

Posted: Sun Jan 22, 2023 10:57 pm
by UrbanCyborg
It's never a good idea to modify a control inside its own handler. It's a pain, but you need to insert a level of indirection, say, by setting a flag in the handler that you can respond to in a timer event, where you modify the control and reset the flag.

Another way is to do the control change on the mouse button up event for the control. That's what I do in my Boolean Truth module to keep the knobs in ascending sequence.

And always, make use of SetValueNoNotification() when you're modifying control values in code. If nothing else, it helps avoid spurious events during module initialization, when every control gets notified twice (at least).

Reid

Re: SetValue() doesn't update the GUI.

Posted: Thu Jan 26, 2023 6:24 am
by Centripidity
Thanks for the replies, all good advice.

This module was my first attempt and so I made a few early design choices that I would have done differently if I'd had a better knowledge/understanding of the API.