Efficient way of toggling specific switch?
Posted: 28 Apr 2012 17:36
Is there a more efficient way to determine which switch in a switch element with 8 columns has been pressed most recently, and set it's label to 'On' or 'Off' according to the new value? This works, but seems really clunky. "last_press" is a variable local to the switch. The sysex variables are defined at project level, and "toggle_labels" is initialized as stretch('Off',8).
Thanks in advance,
CS
Code: Select all
//Switch ch_on (On Expression, x, any)
sys_msg=fill(1,{0x00},5);
decl i, diff = nonnull(ch_on.x - last_press);
if(ch_on.x[diff]==1) sys_msg[4]={0x01};
send_sysex({sys_channel_toggle,0x00,page_channels[active_page*8+diff],sys_msg});
last_press = ch_on.x;
for(i=0; i<8; i++){
if(last_press[i]==1) toggle_labels[i]='On';
else toggle_labels[i]='Off';
}
setattribute(ch_on,'labels',{toggle_labels});
CS