Troubleshooting

Fader Script to Select Tabs

Started by SBPBK on .

Sign in or create an account to join the conversation.

8 posts

Topic starter
Hi,

I'm trying to sort out a script.. I want the position of a fader to determine the selected tab of a container. This is based on a MIDI message sent to Lemur from my DAW (not my manual movement of the fader) and it doesn't necessarily even have to be a fader, just something that can select a tab based upon the current position of a particular CC value...

Here's what I'm currently working with:


if(firstof.x>=0.75) selecttab(ContainerDiva,0);
else
if(firstof.x>=0.5) selecttab(ContainerDiva,1);
else
if(firstof.x>=0.25) selecttab(ContainerDiva,2);
else
selecttab(ContainerDiva,3);



Any help with this would be greatly appreciated, I'm a little stumped as to what I'm doing wrong!

Cheers
If we are talking about a fader here, you shouldnt have used firstof(x) - its as simple as.... x
(fader.x if the script resides outside of fader, where "fader" the actual name of the fader object inside your template)

firstof(x) is a function useful for an array of x (usually a row of pads or switches) and returns the first position of the array where x != 0. For example, if you have a row of 16 pads and you press the third pad then firstof(x) = 2 (0 being the first position, x[0]). Furthermore the correct syntax is firstof(x) not .x but you dont even need it in your case.

So here's the corrext syntax

if(x>=0.75) selecttab(ContainerDiva,0);
else
if(x>=0.5) selecttab(ContainerDiva,1);
else
if(x>=0.25) selecttab(ContainerDiva,2);
else
selecttab(ContainerDiva,3);

Furthermore lets assume that x == 0.6;
it satisfies BOTH if(x>=0.5) and if(x>=0.25) so you might end up with the third case even though you are after the second.
I dont remember if the if - else if exits the statement when one of the ifs are satisfied - if not, you might have to make the syntax like this:


if(x>=0.75) {selecttab(ContainerDiva,0); return;}
else
if(x>=0.5) {selecttab(ContainerDiva,1); return;}
else
if(x>=0.25) {selecttab(ContainerDiva,2); return;}
else
selecttab(ContainerDiva,3);

Finally, the "return" function will exit the script so if you have more stuff down the script (below the if - else if) you will be exiting the script and those wont be executed so you are looking at this solution

if(x>=0.75) selecttab(ContainerDiva,0);
else
if(x<0.75 && x>=0.5) selecttab(ContainerDiva,1);
else
if(x<0.5 && x>=0.25) selecttab(ContainerDiva,2);
else
selecttab(ContainerDiva,3);


more info, and how to use other objects to control tabs of a container here:
http://forum.liine.net/viewtopic.php?f=34&t=3022
Hi

Another option
Script executing on Fader.x
decl tabs= {0,1,2,3};
selecttab(Container,tabs[Fader.x*4]);

This allows you reorder the tabs fairly easily by altering the array
Could also throw some introspection in ie Fader.x*sizeof(Fader.x) making it easily mutable

Similar thing with Switches
selecttab(Container,firstof(Switches.x)); // Direct correlation or use an array as in other example

Then it is simply a matter of mapping those objects . . .

The other option if you don't require the local object for use is to simply use a similar script executing OnMidi . .
This would make it purely dependent on Midi control which could be sent from anywhere ...

Hope that helps
We also make mistakes when we don't check our work properly . . .
Sorry about that...

For various reasons the following works far better. ....
selecttab(Container,tabs[Fader.x*sizeof(tabs)-0.01]); //3.99 for 4 tabs

This value could also be declared locally

Cheers
Mm
Thanks so much for the responses and all of the insight gents!!!

On a related note, I am trying to get CC info TO a set of switches, so that they respond to even portions of 0-127.. I.E. 0-31 selects switch 1, 32-64 selects switch 2, etc.

I attempted this by using a fader to receive the CC, and writing a script under the switches for x=Fader.x*127/4

I was unsuccessful with that but ultimately it is not even necessary for it to receive the CC information from the Fader, I just need it to respond to a CC value being sent from Ableton.