Rework log: Scripts!

A place where updates of QLC+ activities and technical articles are posted as if it was a blog
Post Reply
User avatar
mcallegari
Posts: 4482
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

The Script function...this big unknown black hole...

I think it was originally meant to provide a simple (yet custom!) scripting language to cover aspects that other QLC+ functions didn't cover.

Over the years, some commands have been added to Scripts (e.g. launching external applications) and some users even suggested to use a standardized scripting language like LUA.

Well, the QLC+ 5 UI is written with the QML language, and QML takes big advantage of an internal Qt JavaScript engine which is pretty fast and optimized.

So at some point I had this crazy idea to use JavaScript in Scripts...and I did it!
If you want to jump directly into the techy details, here's a document that explains the decisions taken.
Note that this change affects QLC+ 5 only (see above) and Scripts created in QLC+ 5 will not work in QLC+ 4.

The most difficult (and boring) part was to write the code to migrate the "old" syntax to the "new" JavaScript syntax.
Another tricky aspect is the "sandboxing" of JS Scripts to cause no harm to QLC+, because yes, giving this degree of freedom will surely cause disasters if used improperly.

For example, a script like this could cause harm to QLC+ (and your OS in general):

Code: Select all

while(1) {
  // die QLC+, die!
}
So, first off, the Script syntax has changed. QLC+ will expose a JavaScript Object called "Engine" to a Script.
The Engine object has several methods that can be called, and they open up for many more possibilities than QLC+ 4!
I haven't written the documentation yet, but you can have a look at the method prototypes, which are quite self-explanatory.
These are the exported JS methods available today.

It's interesting to notice that in this way, even C++ default arguments can be leveraged. For example the setFixture method can be called like:

Code: Select all

Engine.setFixture(1, 5, 100);
to set instantly channel 5, or

Code: Select all

Engine.setFixture(1, 5, 100, 3500);
which will fade channel 5 to value 100 in 3.5 seconds.

So, for example, this code

Code: Select all

var i;
for (i = 0; i < 10; i++) {
  Engine.setFixture(0, i, i * (25.5), 2000);
}
Engine.waitTime(3000);
for (i = 0; i < 10; i++) {
  Engine.setFixture(0, i, 0, 2000);
}
Engine.waitTime(3000);
Produces this result:
script_javascript.gif
Isn't that cool ?
I used one Script with the new syntax in the 3D demo project shared before, so check it out!

There is a lot of space now to improve the Script area, and I'm pretty sure that with the methods available today a lot can be achieved already.
One thing please do not ask: control over VC widgets. Scripts run in the QLC+ engine, which has no access at all to the virtual console.
I know, everything can be done in software, but unless super valid reasons or usage cases are explained, I'm not going to do that for now.
siegmund
Posts: 703
Joined: Mon Nov 02, 2015 11:03 am
Location: Germany
Real Name: Lukas

For me, this will be one of the most awesome new features in QLC+ 5. Having a powerful scripting language at hand and access to the QLC+ Engine, the possibilities are close to unlimited. I'm really looking forward to build some things that where not possible in v4.
mcallegari wrote: Fri Aug 17, 2018 3:02 pm One thing please do not ask: control over VC widgets. Scripts run in the QLC+ engine, which has no access at all to the virtual console.
I know, everything can be done in software, but unless super valid reasons or usage cases are explained, I'm not going to do that for now.
If one really needs control over VC widgets, there is always the possibility to go the loopback way. So I don't think this needs to be implemented directly at all.

Thanks Massimo! :)
User avatar
GGGss
Posts: 2732
Joined: Mon Sep 12, 2016 7:15 pm
Location: Belgium
Real Name: Fredje Gallon

If one could have 'switches' in scripting via loopbacks (inputs) ... and thru loopbacks influence VC (output) Ow Boy ...
(GrandMA is notorious for its need for scripts ... and yes it need a lot of them ... 1500-some in a standard setup??)
All electric machines work on smoke... when the smoke escapes... they don't work anymore
TheLightGuy
Posts: 25
Joined: Wed Jan 24, 2018 4:48 am
Real Name: Dakota

GGGss wrote: Sat Aug 18, 2018 1:28 pm If one could have 'switches' in scripting via loopbacks (inputs) ... and thru loopbacks influence VC (output) Ow Boy ...
(GrandMA is notorious for its need for scripts ... and yes it need a lot of them ... 1500-some in a standard setup??)
Agreed. Also, it would be great to be able to use scripts as macros to speed up programming time (such as creating custom color pallettes for all fixtures, or a certain layout in the VC). Super stoked to download the latest release and check it out.
Post Reply