Rework log: Scripts!
Posted: Fri Aug 17, 2018 3:02 pm
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):
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:
to set instantly channel 5, or
which will fade channel 5 to value 100 in 3.5 seconds.
So, for example, this code
Produces this result:
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.
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!
}
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);
Code: Select all
Engine.setFixture(1, 5, 100, 3500);
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);
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.