Cabbage Logo
Back to Cabbage Site

Turning off and unlatching a button

I can’t seem to get this to work. I’m not sure If I’m doing something the wrong way, or if there’s an underlying bug involving latched buttons changing with identchannel values.

I’d like to have one button that changes the latched() mode of another button. So far, that much works.

However, when turning latched off, I would like to make sure that the button is also turned off. This, I can’t seem to get to work. Whether I try setting value(0) in the same chnset as the latched(0) to the identchannel, or whether I send 0 to the variable’s channel… the button responds as if it’s still latched, and then pops back to pressed.

Attached is an example that I think illustrates this problem:
latched_value.csd (688 Bytes)

To see the behavior, note that in the example the “PUSH” button starts unlatched.
Press the “LATCH” button.
Press the “PUSH” button, it is now latched.
Leaving the “PUSH” button pressed, press the “UNLATCH” button.
Note the behavior of the “PUSHED” button, it turns off, but immediately back on.

I’m not getting the same behaviour as you when I press the ‘Latch’ button. I wonder if it has something to do with the initialisation issues you’re seeing. Leave it with me. I did some test yesterday and was almost able to reproduce your other issues. Let me get to the end of that first, then I’ll take a look at this.

You are right in trying to use chnset 0, “but1”, but the problem is that Csound sees that 0 as an i-rate constant. You need to cast it as k-rate.

if changed(klatch)==1 then
  chnset k(0), "but1" 
  chnset sprintfk("latched(%d)",klatch),"test" 
endif

I’d be lying if I said I haven’t been caught out with that before!

p.s. the value identifier is only used for initialising a widget’s value. You should use chnset and its channel identifier to set its value from there on in.

AHA! Yeah, the i vs k problem has bit me before too… I can’t believe it was such a simple mistake, especially considering I’ve gotten accustomed to casting to k() lately. Thanks for pointing that out Rory!

And yes, my original plan was to use chnset 0 rather than value(0), but when it didn’t work I decided to try both methods just in case it was an issue of writing twice to the same channel (I didn’t think identchannel and channel on the same cycle would pose a problem, but I wasn’t sure).