Script syntax question

Discuss problems and solutions.
Cumulonimbus
Newbie
Posts: 12
Joined: 01 Mar 2015 07:03

Script syntax question

Post by Cumulonimbus »

Hi,

New to Lemur. I'm trying to set the value of a bunch of Knobs whenever the interface loads. The knobs are inside a container object, which contains two tabs (each with different knobs). I attached the following script to the container object using "On Load" but I don't understand why I get a syntax error:

Code: Select all

decl object;
object = getfirst(Knobs_Container);
while (object) {
   object.x = 0.1;
   object = getnext(Knobs_Container);
}
I tried this with "setattribute(object, 'x', 0.1)" but this doesn't work either.

Thanks for your help.
Cubase Pro 8.0 & VEP 5.3. OS X Yosemite 10.10.1, Mac Pro 2009 Quad 2.66, 28gb RAM, RME Fireface UC, iPad Air 2, iOS8.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: Script syntax question

Post by Softcore »

setexpression(object, 'x', 0.1)


X is an expression, not an attribute! ;)
Cumulonimbus
Newbie
Posts: 12
Joined: 01 Mar 2015 07:03

Re: Script syntax question

Post by Cumulonimbus »

Thanks, I don't get a syntax error now, but the script doesn't work (knobs values are not reset at all). Any ideas?
Cubase Pro 8.0 & VEP 5.3. OS X Yosemite 10.10.1, Mac Pro 2009 Quad 2.66, 28gb RAM, RME Fireface UC, iPad Air 2, iOS8.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Script syntax question

Post by oldgearguy »

Try is using a manual script. i.e. - create a pad. add a script to the pad. Have the pad script execute on expression x going from low to high (arrow pointing up).
in the pad script, try setting the controls to the value using setexpression.

The point is - initializing things directly in onload() scripts is weird. Sometimes some things work, other times not. I've had bizarre bugs because of what I was trying to do.
I've used other methods for initializing things. Let us know if you can get it to work properly via the manual button push method.
Cumulonimbus
Newbie
Posts: 12
Joined: 01 Mar 2015 07:03

Re: Script syntax question

Post by Cumulonimbus »

Doesn't work either. Maybe it's my hierarchy? Let me simplify what I have here:

Project
-Interface1 (folder)
--Knobs_Container
---Tab1 (folder)
----Knob1
----Knob2
----Label1
----Label2
---Tab2 (folder)
----Knob3
----Knob4
----Label3
----Label4
--Pad with script

The script is the one in my first post with the modification given by Softcore. I assume labels would be ignored by the script's setexpression function, but maybe I'm wrong?

EDIT: I've created a test Container with no tabs or labels, and the script only sets the first knob in it. Somehow the getnext function isn't working (or I'm getting it wrong, more likely). It doesn't work even if I do this:

Code: Select all

decl object;
object = getfirst(Container);
setexpression(object, 'x', 0.2);
object = getnext(Container);
setexpression(object, 'x', 0.2);
BTW the forum doesn't send email notifications on new replies even though I've checked that option. Sorry for the delay in response...
Cubase Pro 8.0 & VEP 5.3. OS X Yosemite 10.10.1, Mac Pro 2009 Quad 2.66, 28gb RAM, RME Fireface UC, iPad Air 2, iOS8.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Script syntax question

Post by oldgearguy »

it apparently doesn't work the way we think. Try this code instead:

Code: Select all

decl object;
object = getfirst(Container);
setexpression(object, 'x', 0.2);
object = getnext(object);
setexpression(object, 'x', 0.5);
object = getnext(object);
setexpression(object, 'x', 1.0);
The idea is similar to C code functions that basically walk a pointer through a list, so you use the last position as the next starting point

(edit): and doing it in an onload() script seems to work (at least in a trivial template).
Cumulonimbus
Newbie
Posts: 12
Joined: 01 Mar 2015 07:03

Re: Script syntax question

Post by Cumulonimbus »

That's odd, I did exactly what you suggested, on a new template with just a container, two knobs and a pad to trigger the script, and it still doesn't work. If anyone has time, please have a look at the file (it's the new project with only the controls needed to illustrate my problem, not the entire thing).

Thanks.
KnobsScript.jzml
(7.15 KiB) Downloaded 54 times
Cubase Pro 8.0 & VEP 5.3. OS X Yosemite 10.10.1, Mac Pro 2009 Quad 2.66, 28gb RAM, RME Fireface UC, iPad Air 2, iOS8.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Script syntax question

Post by oldgearguy »

I think you missed my change.

In the ResetKnob() script you say:

object = getfirst(Knobs_Container);
setexpression(object, 'x', 0.2);
object = getnext(Knobs_Container);
setexpression(object, 'x', 0.5);


The change was in the getnext() call. It should be:

object = getfirst(Knobs_Container);
setexpression(object, 'x', 0.2);
object = getnext(object);
setexpression(object, 'x', 0.5);


In other words, use getfirst(Container name) and save off the returned object. Then in calls to getnext(object), use the returned object from the previous call.

So with 3 objects, it would look like this:

object = getfirst(Container);
// do something with object
object = getnext(object);
// do something with 2nd object
object = getnext(object);
// do something with 3rd object
Cumulonimbus
Newbie
Posts: 12
Joined: 01 Mar 2015 07:03

Re: Script syntax question

Post by Cumulonimbus »

I did miss it. Thank you very much, it works now even with the while loop.

Just out of curiosity, because I don't get it:

object = getfirst(Container) gets the first object in the Container, which is a Knob object.

It seems to me that object = getnext(object) would then get the next object in the Knob, which isn't meaningful.

It works, but I don't see why... :)
Cubase Pro 8.0 & VEP 5.3. OS X Yosemite 10.10.1, Mac Pro 2009 Quad 2.66, 28gb RAM, RME Fireface UC, iPad Air 2, iOS8.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Script syntax question

Post by oldgearguy »

Cumulonimbus wrote:I did miss it. Thank you very much, it works now even with the while loop.

Just out of curiosity, because I don't get it:

object = getfirst(Container) gets the first object in the Container, which is a Knob object.

It seems to me that object = getnext(object) would then get the next object in the Knob, which isn't meaningful.

It works, but I don't see why... :)
It really comes down to how Lemur stores the references to the objects internally. If you think of the objects in a Container as links of a chain, then what you do when you say getfirst(Container) is to return the whole chain, with your hand holding the first link. Getnext(object) starts where you are holding the chain and moves to the next link. If you say getnext(Container) you are saying give me the next link starting from Container, which is going to always return the first link only.

You can play around with it by creating another Container inside the first one between the knobs (change knob2 name to knob3 and create a container called knob2) and see what happens. If you print the object name out (create a Monitor object and insert: Monitor.value = getattribute(object, 'name'); after a getnext(object) call, you will see that in fact knob1 is returned first, then knob2 (which is a container), then knob 3. If you embed another object in the new container (say another knob inside your knob2 container), you can't get to it using getnext(). Conceptually, it's like another small chain hanging down from one of the middle links and you can only traverse one chain at a time. You would need to do a getfirst(knob2) to start walking through those links.

I don't see any obvious way to be able to distinguish between objects other than by some attribute you set (i.e. - compare name, color, position, etc), so either you have to construct the objects in the way you want or do lots of checking after every return from getnext().
Post Reply