This is my first post, I've been using lemur for about a week and have decided to try to build my first template. I've been looking at the manual and other peoples templates to learn from. So far so good, lemur is deep and I want to learn all I can about scripting in it. So far I've setup CC's, NRPN's, Note messages, simple stuff really. I'm trying to understand switches now. I was able to get a basic single switch working with a CC and a sysex message. But I need to use radio buttons and more than one set of them to control my synth.
Here is what I'm trying to accomplish. I have 7 switches which are arranged in 2 sets of 3 radio switches and 2 individual switches. I would like to figure out how to read all the switches when any single one is clicked, and then assign each switches value (0 or 1) to a variable that I can use in a mathematical equation. So an example would be... one of the switches is clicked and all 7 switches are scanned and I get 0 or 1 variables returned on each switch ie. s1=1, s2=0, s3=0, ----- s6=1, s7=1.
I would greatly appreciate any assistance that could help me figure this out and learn scripting better. Also any advice on the best way to monitor for debugging?
Help with switches
Re: Help with switches
Not sure what you are trying to do and with what equation but referencing and retrieving the state of switches is very easy.
in scripts Switch_name.x will give you the switch state (0 if off, 1 if On).
In case of switch object with multiple columns or rows the states of each individual switch can be "scanned" by using vector variables. For example the state of the third switch of the first row would be Switch_name.x[2] (again 0 if off, 1 if on)
So.....in order to know what state any switch is you just look up in scripts the above expressions (variables).
In the case of radio switches you can find which one is on by using firstof(x) in your scripts. For example in an object with three radio switches where the third is on firstof(x)=2 (remember that 0 is the first switch).
Now in order to control-change the state of the switch you just assign them to 0 or 1
For example if you create a script Switch_name.x=1 then the switch turns to on.
If you need further assistance, upload a template with specific things needed to be done!
in scripts Switch_name.x will give you the switch state (0 if off, 1 if On).
In case of switch object with multiple columns or rows the states of each individual switch can be "scanned" by using vector variables. For example the state of the third switch of the first row would be Switch_name.x[2] (again 0 if off, 1 if on)
So.....in order to know what state any switch is you just look up in scripts the above expressions (variables).
In the case of radio switches you can find which one is on by using firstof(x) in your scripts. For example in an object with three radio switches where the third is on firstof(x)=2 (remember that 0 is the first switch).
Now in order to control-change the state of the switch you just assign them to 0 or 1
For example if you create a script Switch_name.x=1 then the switch turns to on.
If you need further assistance, upload a template with specific things needed to be done!
Re: Help with switches
Here are some stuff to illustrate the above and possibly help you understand the logic
Re: Help with switches
Great! Thanks for the help, it got me right where I needed to be. Hopefully I can use some of what I learned here with other multi-objects(multiball and breakpoint).
I do have a couple more questions on the switch topic. Is there a way to inverse the output of the switch? 0/1 to 1/0? Is it possible to trigger a script via 'on expression' when you have multiple switch banks? I have a midiout script that I'd like to trigger with an 'on expression' from Switches.x, Switches2.x, Switches3.x, but when I try it it will only let me use one, not all three.
I do have a couple more questions on the switch topic. Is there a way to inverse the output of the switch? 0/1 to 1/0? Is it possible to trigger a script via 'on expression' when you have multiple switch banks? I have a midiout script that I'd like to trigger with an 'on expression' from Switches.x, Switches2.x, Switches3.x, but when I try it it will only let me use one, not all three.
Re: Help with switches
Besides scripting....read the Lemur manual about the custom expressions....Not only you can invert a switch's output you can do whatever you imagine via custom expressions.
Adding a custom expression ("x=" button) allows you to invert x by simple maths...here is an example
For your second question, keep in mind that a script can be created at project level (i.e. not belong to a specific object), be set as "manual" (only be triggered when called) and that the switches can then trigger the script either when pushed to on, when pushed to off, or in both cases (notice the difference of the scripts in the below example - any, up arrow, down arrow settings right next to "on expression x")
Here is an example where the switches all add one increment (in Midi values) to a knob but with different scenarios - when pushed, when turned on, when turned off)
Adding a custom expression ("x=" button) allows you to invert x by simple maths...here is an example
For your second question, keep in mind that a script can be created at project level (i.e. not belong to a specific object), be set as "manual" (only be triggered when called) and that the switches can then trigger the script either when pushed to on, when pushed to off, or in both cases (notice the difference of the scripts in the below example - any, up arrow, down arrow settings right next to "on expression x")
Here is an example where the switches all add one increment (in Midi values) to a knob but with different scenarios - when pushed, when turned on, when turned off)