Cabbage Logo
Back to Cabbage Site

Can label text be dynamically changed?

I’ve been having trouble trying to find a way to update the text of a label widget so that I can display the values of sliders as they are changed by the user. Kinda like a dedicated value display box that resides in the corner of my plugin. Would this be possible, or are there better, more efficient ways to do this?

In this attempt I try to chnset the label if a parameter changes. The metro is there to make the text updates slower than k-rate. However this doesn’t have any effect on the label and any printf instances within the nested if-then don’t output anything.

kmetro metro 15
if (kmetro == 1) then
    if (changed(gkcut) == 1) then
        Slab sprintfk "text(\"Cutoff: %.4f\")", gkcut
        chnset Slab, "Label"


I’ve also tried removing the metro and the if-then associated with the metro == 1. Alternatively I have also tried making the output of changed a variable by putting it in its own line of code, then processing that variable through the if-then but that doesn’t have any effect either. Both this example and the widget retrieving “gkcut” are included in instruments that are always running. I’m sorry for the newb question, but why doesn’t this code work?

Let me prepare an example for you, one sec

KnobLabel.csd (778 Bytes)

Like this?

Note: this uses a beta-version of Cabbage, and identifiers will be in camelCase style instead of the old one. So if you can’t run the code, try changing the capitalletters in identifiers back to lower case

Yes, precisely! I’ve just tried modifying your example to match what I was attempting to accomplish in my instrument and it works properly as well. I’ll attach the modified .csd for reference.

Hmm since you’ve proven that this is possible, it looks like there’s something I’m doing wrong… maybe it’s because I’m using a global variable which is being defined in a separate instr? That seems to be the only thing different that I can spot.

Also, thanks for your quick and helpful reply!
KnobLabel.csd (899 Bytes)

The global variable should be fine I think. Notice I’m using a identchannel and not a channel for setting the text to the label. Also I normally use changed2 instead of changed, thought it was worth mentioning.

Ah, I’ve found what was causing the label to not update in my instrument - I needed to remove the channel argument of the label while still only having the identchannel (I initially had both a channel and identchannel for the label with the same names). I don’t think I would’ve been able to figure that out without your example to compare to, so thanks again for that.

And thanks for the note about changed2. That would definitely be more appropriate for this scenario, so I’ll convert to the ways of changed2 for this one.

1 Like

You should always avoid having the same names for any channels/identchannels. Although at time it can be useful it generally leads to unexpected behaviour down the line. :+1:

1 Like