SetValue() doesn't update the GUI.

Post Reply
Centripidity
Posts: 140
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

SetValue() doesn't update the GUI.

Post 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
AllanH
Posts: 13
Joined: Sat Nov 26, 2022 5:23 pm

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

Post 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.
UrbanCyborg
Posts: 588
Joined: Mon Nov 15, 2021 9:23 pm

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

Post 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
Cyberwerks Heavy Industries -- viewforum.php?f=76
Centripidity
Posts: 140
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

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

Post 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.
Post Reply

Return to “Module Designer”