Cabbage Logo
Back to Cabbage Site

Widget chnset text and colour

Hi Rory,

I’d like to change the text and colour for e.g. the label and the rslider widgets independently in two separate steps. There seems to be a little bug or I am doing something wrong? It seems I can’t chnset text and colour in two steps (sequentially). Further minor thing: it seems that rslider text cannot be changed if the new text contains the “rslider” string. Using Cabbage version: 2.5.13

Example scenario: rslider’s label depends on rslider’s position as well as on the state of a switch (button) while the rslider’s colour depends on the state of the switch.

My approach: trigger a block on change of rslider or button, chnset text depending on the states of rslider and button, chnset colour depending on the state of the button.

Alternatively I could use elseif statements and chnset both text and colour with single instructions (which works), but it becomes pretty ugly in more complex scenarios.

A simple code to test:

<Cabbage>
form caption("Test_text_colour") size(365, 225), pluginid("tex1") 
rslider bounds(132, 32, 40, 68) range(0, 1, 0, 1, 1e-06) channel("IO_rslider") identchannel("ID_rslider") text("slider") textcolour(0, 255, 0, 255)  trackercolour(0, 100, 0, 255) popuptext("0")
</Cabbage>

<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --displays

</CsOptions>
<CsInstruments>
sr = 44100
ksmps 	=  16;	

instr 1

; this doesn't work
;chnset "text(rslider1)", "ID_rslider"

; this works
;chnset "text(slider1) textcolour(255, 255, 0, 255)", "ID_rslider"

; 1. test these two lines only (only the 2nd instruction applies)
;chnset "textcolour(255, 255, 0, 255)", "ID_rslider"
;chnset "text(slider1)", "ID_rslider"

; 2. test these two lines only (only the 2nd instruction applies)
;chnset "text(slider1)", "ID_rslider"
;chnset "textcolour(255, 255, 0, 255)", "ID_rslider"

endin
</CsInstruments>

<CsScore>
f0 z
i 1 0 [3600*24*7]
</CsScore>
</CsoundSynthesizer>

Thanks for your help and all the great work!

Best wishes,
Samo

In the first instance you are trying to set the name as rslider1, if you change it to slider1 it works. Strange, but I feel it might have something to do with the fact that sliders are given default channels names such as rslider1, rslider2, but I can’t right now think of how this might affect what’s going on here.

The second two cases don’t surprised me. You call chnset and pass it a value, then in the same k-cycle you call it again and give it another value. So the second value is the only one that ever get received.

Thanks for the super fast reply as usually!
The “reserved name” issue can easily be avoided :slight_smile:
The second “issue” was my very basic csound mistake - thanks for clarifying it for me!
I see now and it makes perfect sense that widgets can receive messages only ones per k-cycle.

It is pretty reasonable when it is explained, but I remember struggling with this when I first started working on identifier channels. I couldn’t get my head around it, until I had that d’oh moment. So yeah, it happens us all.