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"

    endif
    
endif

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

Hi Rory and hi to all!
I tried to change numbers sended from csound in a label. I managed to do it without guiMode(“queue”) (see below). How I have to do with guiMode(“queue”)?
Andrea S.

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginId("def1")
;rslider bounds(296, 162, 100, 100), channel("gain"), range(0, 5, 0), text("Gain"), trackerColour("lime"), outlineColour(0, 0, 0, 50), textColour("black")
label bounds(136, 118, 140, 16), identChannel("SecsCounter")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
;kGain chnget "gain"
gkvuTime timeinsts
ktrig metro 10                ;write every .1 secs.
if (ktrig == 1) then
    if (changed(gkvuTime)==1) then
    SIdent sprintfk "text(\"Secs.: %.2f\")", gkvuTime
    chnset SIdent, "SecsCounter" 
    endif
endif
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Hi @strapparts! GOod to hear from you. Will you accept a single line answer :laughing:

instr 1
    cabbageSet metro(10), "SecsCounter", sprintfk("text(\"Secs.: %.2f\")", timeinsts()) 
endin

Just make sure to add guiMode("queue"), and change the identChannel("SecsCounter") to channel("SecsCounter"). No need for identChannels with the new system.

Wow! I have no words to thank you! So I have completed, at least for now, a new effect plugin for my composition!
I’m attaching it, for the Cabbage-Csound community.
Any suggestion GrainOnFly.csd (8.5 KB) is welcome!
Andrea S.

I was studying how to make values/names change dynamically without using guiMode (“queue”) , maybe there is a simpler way, :smile: but if anyone is interested: KnobLabel 2.csd (2.1 KB)

1 Like

I don’t think there is, without using guiMode("queue").