Advertisement
Advertisement
Lua scripts
Lua scripts
We use a scripting language called Lua, which has been extended to provide functionality specific to the Unison
Mosaic Controllers. Tutorials and reference manuals for the Lua language can be found at www.lua.org
. We will not attempt to document the Lua language here, but just the Unison Mosaic specific extensions. Please contact
if you need assistance with preparing a script or if you would like some examples as a starting point.
Lua script editor
The Lua Script Editor allows you to edit scripts from Triggers Conditions and Actions, and Custom presets within
Designer. The Script Editor is launched by pressing the Launch Editor button in the trigger properties:
The main area of the editor is the code editor where you enter the source code of the script. The code editor will colour the Lua syntax to aid readability. Standard clipboards shortcuts and undo/redo are supported.
To import a Lua script from an external file, use File > Import (Ctrl+I).
To save a Lua script to a file, use File > Export (Ctrl+E).
To compile the script and check for syntax errors, use Build > Build (F7). If there are errors in the script, they will be displayed at the bottom of the window.
When you have finished editing the script, press Ok to close the Script Editor. If there are still errors in your script, you will be prompted whether the invalid source should be saved or not.
To discard any changes close the Script Editor and select Discard from the confirmation dialog.
Debugging Lua scripts
If your script contains no errors, use Debug > Run (F5) to execute it in a debugger. This will run the script and report any runtime errors in the Output tab below the source editor. Note that only Custom preset scripts can be executed in the debugger.
If there are errors, you can place breakpoints in the source to force the debugger to halt execution at that point and allow you to examine the state of variables and execute further instructions one at a time.
- 207 -
Unison Mosaic Designer User Manual
To add/remove a breakpoint on a line of source code, click the mouse to the left of the relevant line number, or use Debug > Toggle Breakpoint (F9) to set a breakpoint at the text cursor. Now, when you run the script with
Debug > Run (F5), the debugger will halt at the first breakpoint that it encounters.
When the debugger is halted, you can examine the values of variable in the script in the Watch tab below the source editor.
l l l l l l
To execute the next line of code, use Debug > Step Over (F10).
If the debugger is halted at a function call, use Debug > Step Into (F11) to step into the function.
To step out of the current function, use Debug > Step Out (Shift+F11).
To resume normal execution, use Debug > Run (F5).
To terminate execution immediately and return to editing the source, use Debug > Stop (Ctrl+F5).
While a script is executing, use Debug > Break to halt execution at the current line.
Unison Mosaic language extensions for triggers
Accessing the realtime clock (local to this Controller)
realtime.year
realtime.month
realtime.monthday
realtime.weekday
realtime.hour
realtime.minute
realtime.second
The year
The month (1 to 12)
The day of the month (1 to 31)
The day of the week (0 = Sunday; 1 = Monday; etc.)
The hour (0-23)
The minute (0-59)
The second (0-59)
NOTE: The location of the Controller must be set correctly in
for these to return the correct values.
Accessing the calculated sunrise and sunset times (local to this Controller)
sunrise.hour
sunrise.minute
sunrise.second
sunset.hour
sunset.minute
sunset.second
The hour of sunrise (0-23)
The minute of sunrise (0-59)
The second of sunrise (0-59)
The hour of sunset (0-23)
The minute of sunset (0-59)
The second of sunset (0-59)
NOTE: The location of the Controller must be set correctly in
for these to return the correct values.
Accessing the calculated twilight times (local to this Controller)
civil_dawn.hour
civil_dawn.minute
civil_dawn.second
civil_dusk.hour
The hour of civil dawn (0-23)
The minute of civil dawn (0-59)
The second of civil dawn (0-59)
The hour of civil dusk (0-23)
- 208 -
Lua scripts civil_dusk.minute
civil_dusk.second
nautical_dawn.hour
nautical_dawn.minute
nautical_dawn.second
nautical_dusk.hour
nautical_dusk.minute
nautical_dusk.second
The minute of civil dusk (0-59)
The second of civil dusk (0-59)
The hour of nautical dawn (0-23)
The minute of nautical dawn (0-59)
The second of nautical dawn (0-59)
The hour of nautical dusk (0-23)
The minute of nautical dusk (0-59)
The second of nautical dusk (0-59)
NOTE: The location of the Controller must be set correctly in
for these to return the correct values.
TPC user interface control
These are only executed on the local Controller, which must be a TPC.
set_control_value(controlKey, valueIndex, value) set_control_value(controlKey, value) set_control_state(controlKey, stateName) set_page(pageName) set_locked(lock) set_enabled(enable)
Sets the value of the TPC control. Control key is a string, e.g. "slider002". Value index 1 for sliders or 1, 2 or 3 for colour pickers
Shorthand form with value index equal to 1, useful for sliders. Control key is a string, e.g. "slider002"
Provide feedback by changing the appearance of a control.
Control key is a string, e.g. "slider002".
Change the current page of the user interface
Lock or unlock the TPC (lock: true of false)
Enable or disable the user interface (enable: true of false)
Accessing the current state of the digital inputs on this Controller
digital[index]
Boolean value on input (index 1 to 8)
Accessing the values of DMX inputs on the local Controller
DMXIN[channel] get_dmxin(x)
The value of the specified channel (1 to 512)
Returns a DMXIN object for port (x is 1 or 2)
Checking the local Controller number
get_controller_number() Returns the number of this Controller
Checking the status of timelines (local to this Controller)
is_timeline_running(num) is_timeline_onstage(num)
Is timeline with specified user number between start and end time?
Is timeline with specified user number actually in control of fixtures on this Controller?
- 209 -
Unison Mosaic Designer User Manual
Injecting a trigger
Equivalent to clicking a trigger in the web control screen.
inject_trigger(num)
Fires the trigger with the specified number. Additional arguments are passed as variables.
Timeline control
Note that unlike a normal trigger action these will only affect the local Controller. This can be a powerful additional feature in certain situations. If you want to fire a timeline system-wide then inject an appropriate trigger.
start_timeline(num) stop_timeline(num, time) halt_timeline(num) resume_timeline(num) stop_all()
Start timeline with the specified user number
Stop timeline with the specified user number with optional fade time (in seconds)
Halt timeline with the specified user number
Resume timeline with the specified user number
Stop all timelines
Timecode control (local to this Controller)
set_timecode_source_enabled(source, [enabled])
Enable or disable a timecode source (source is one of
TCODE_1
, TCODE_2, TCODE_3, TCODE_4, TCODE_5,
TCODE_6
, AUDIO_1, AUDIO_2, AUDIO_3, AUDIO_4; enabled assumed true if not specified) set_timecode_source(timeline_num, source, [offset])
Set the current timecode source for a timeline (source is one of DEFAULT, TCODE_1, TCODE_2, TCODE_3, TCODE_4,
TCODE_5
, TCODE_6;offset in msecs, assumed 0 if not specified) set_timecode_source(timeline_num, source, band, channel, [peak])
Set the current audio source for a timeline (source is one of
AUDIO_1
, AUDIO_2, AUDIO_3, AUDIO_4; band can be any number or VOLUME; channel is one of LEFT, RIGHT,
COMBINED
; peak is optional, assumed false if not specified)
Fixture control (local to this Controller)
A script can directly control fixtures as if it was a high priority timeline. It can only control fixtures local to the Controller on which the script is running. It can also only control whole fixtures – there is no access to individual elements of compound fixtures.
set_intensity(fixture, value, time) set_red(fixture, value, time) set_green(fixture, value, time) set_blue(fixture, value, time)
Set intensity on fixture to value (as DMX). Optionally give a time (in seconds) to fade.
Set red on fixture to value (as DMX). Optionally give a time (in seconds) to fade.
Set green on fixture to value (as DMX). Optionally give a time (in seconds) to fade.
Set blue on fixture to value (as DMX). Optionally give a time (in seconds)
- 210 -
Lua scripts clear_fixture(fixture, time) clear_all(time) to fade.
Clear the direct settings on fixture with optional fade time (in seconds).
Clear all direct settings with optional fade time.
Accessing the values of DMX channels (local to this Controller)
DMXOUT[channel] get_dmxout(universe)
The value of the specified channel (1 to 512)
Returns a DMXOUT object for universe (see table below)
Park and Unpark DMX channels (local to this Controller)
park(universe, channel, value) unpark(universe, channel)
Park the specified channel (1-512) on universe (see table below) at value
(0-255).
Unpark the specified channel (1-512) on universe (see table below).
The value for the universe argument for both of the above functions depends on the protocol type:
MSC 1's DMX
MSC 2's DMX
Controller's Art-Net II
Controller's Pathport
Controller's ETCNet2
Controller's sACN
Controller's KiNet
Universe = 1.
Universe = 1 or 2.
Universe = ARTNET+<Art-Net II universe number>.
Universe = PATHPORT+<Pathport universe number>.
Universe = NET2+<ETCNet2 universe number>.
Universe = SACN+<sACN universe number>.
Universe is obtained using the get_kinet_universe(powerSupplyNum, portNum) function.
For example: park(ARTNET+2, 1, 255) park(ARTNET, 2, 128) park(SACN+1, 1, 255) park(get_kinet_universe(2, 15), 1,
255)
Parks channel 1 of Art-Net II universe 2 at full.
Parks channel 2 of Art-Net II universe 0 at 50%.
Parks channel 1 of sACN universe 1 at full.
Parks channel 1 of port 15 of KiNet power supply 2 at full.
Accessing the current state of the digital inputs on a RIO
get_rio(type, number) rio[input]
Returns as an object the RIO by type (RIO_80, RIO_44 or RIO_08) and number.
Boolean value on input (1 to 8) of the returned RIO object.
For example: myRIO = get_rio(RIO_80, 2) rioInput1 = myRIO[1]
- 211 -
Unison Mosaic Designer User Manual
Accessing the current state of BPS buttons and setting BPS LEDs
get_bps(number) bps:get_state(button)
Returns as an object the BPS by number.
State of the button (1 to 8) of the returned BPS object, values are
RELEASED, PRESSED, HELD or REPEAT.
bps:set_LED(button, effect, intensity, fade)
Sets the button (1 to 8) of the returned BPS object, effect can be OFF,
STATIC, SLOW_FLASH, FAST_FLASH, DOUBLE_FLASH, BLINK,
PULSE, SINGLE, RAMP_ON or RAMP_OFF. Intensity is optional and should be between 0 and 255, if not specified, the LED intensity is left unchanged from its current value. If intensity is specified, fade can also optionally be specified and should be between 0s and 25.4s.
For example: myBPS = get_bps(1) if (myBPS:get_state(2) == HELD) then mpBPS:set_LED(2, FAST_FLASH, 255, 0.5) end
Accessing trigger variables
The variable must have been captured by the trigger running the script.
variable[index] Value of variable with given index
Writing messages to the Controller's status log
log(“string”)
Writes string into the log
Storing data on the memory card
Using a Lua script it is possible to store data as a file on the memory card. Unlike variables in memory, data stored to a file will not be affected by resetting the Controller or cycling the power. The file can be read back at any time to access the data. This can be very useful in show control situations where some system status information needs to be stored persistently even if the Controller is reset. Alternatively it can allow you to store large data tables on the memory card and only read the data when it is needed.
To work with files on the memory card use the standard I/O library functions described in the Lua documentation.
When writing to a file always close the file explicitly to make sure your data is correctly stored. The full file path to a file on the memory card differs per Controller, so we have provided a function to create the full file path for you:
Returns the full file path for the given file name.
get_resource_path("my_file")
For example: file = io.open(get_resource_path("myfile"), "r") if (file ~= nil) then local line = file:read()
- 212 -
end file:close()
Lua scripts
- 213 -
Download
Advertisement