"else if" and Monitor Object

Discuss Lemur and share techniques.
Post Reply
fader8
Newbie
Posts:20
Joined:24 Feb 2012 12:20
"else if" and Monitor Object

Post by fader8 » 09 Aug 2012 18:13

Hi!
I have Osculator sending me different OSC values depending on the song position of my sequencer. I can pick up those values in Lemur with a monitor object. The message received by Lemur is "/songloaded/value" and its from 0 to 1. That part works just fine. However, I need to translate the value into a textual message. So, I created a text object named "songcue" and followed the instructions in the manual example on else if statements. The script is associated to the monitor object. Like this:

Code: Select all

decl text, val;
val = firstof(x);
if (val==.00) text = 'No Song Cued';
else if (val==.02) text = 'Song One';
else if (val==.11) text = 'Song Two';
setattribute(songcue, 'content', text); 
I've tried "On Expression" and "On OSC" and I'm getting an error flag on the script. I tried replacing "x" with "value" in the script, too.

Anyone willing to help me figure out why I get the error? Or maybe there's a simpler way to do this?

axel_liine
Liine Staff
Posts:126
Joined:14 Dec 2011 12:12

Re: "else if" and Monitor Object

Post by axel_liine » 09 Aug 2012 21:02

The Monitor has no 'x' variable, so that should probably be 'value'. The script should be set to "On Expression", with "value" as the trigger, so that it's run anytime the Monitor's value changes.
Also you're using firstof here. It's meant to be use on arrays, and return the index of the first non-null value. If the value of the Monitor is an array and you want to read its first item, try :

Code: Select all

val = value[0];
Does that fix your problem ?

fader8
Newbie
Posts:20
Joined:24 Feb 2012 12:20

Re: "else if" and Monitor Object

Post by fader8 » 09 Aug 2012 23:42

OK, thanks. Almost there. Rewriting it to be this:

Code: Select all

decl text, val;
val = value[0];
if (val==.00) text = 'No Song Cued';
else if (val==.02) text = 'Song One';
else if (val==.11) text = 'Song Two';
setattribute(songcue, 'content', text);
...makes the error flag go away. Along with setting the script to "On Expression".

But my "songcue" text object isn't reflecting new content. Still just says "text". As for the monitor being an array, I wouldn't know. "songloaded/value" is the address of the monitor in Lemur. Logic sends song position pointer to Osculator, which in turn transmits a value between 0 and 1. The monitor presently displays the value when it arrives, e.g. .02, .11, .15, etc.

I tried just removing [0] from the script above. I entered "value" in the text area to the left of the trigger mode menu. So far, no joy. Any other suggestions welcome.

axel_liine
Liine Staff
Posts:126
Joined:14 Dec 2011 12:12

Re: "else if" and Monitor Object

Post by axel_liine » 10 Aug 2012 22:20

When working with float values such as 0.11, 0.15, etc, it's a bit hard to test for equality.
OSCulator could send 0.15 as something like 0.149999, and the Lemur engine could encode 0.15 as 0.1500001, so the equality test would always fail.

You should try and replace equality tests with relative comparisons, and pick values that are greater than the ones you expect, such as :

Code: Select all

if (val==.00) text = 'No Song Cued';
else if (val<.03) text = 'Song One';
else if (val<.12) text = 'Song Two';
setattribute(songcue, 'content', text)

fader8
Newbie
Posts:20
Joined:24 Feb 2012 12:20

Re: "else if" and Monitor Object

Post by fader8 » 13 Aug 2012 21:14

Thanks Axel, that was the issue. Managed to have Osculator send out big integer numbers and that seems to square the issue. Thanks again.

directory
Newbie
Posts:1
Joined:15 Jan 2013 08:38

Re: "else if" and Monitor Object

Post by directory » 15 Jan 2013 12:04

I am having a similar issue. Regarding the above post, will it work if I manage to have the Osculator send out big integer numbers? I am new to all this so I am finding it quite hard to follow the instructions.

Post Reply