Scripting Reference

General

The M.1k2 uses a LUA engine to run user defined scripts that can perform complexe setups by the press of a button. Custom commands expand lua's standard feature set to read the device's status and settings and configure it.

LUA

LUA itself is beyond the scope of this reference. If you are interested in getting to know LUA, please visit LUA's documentation page.

For safety reasons, the LUA engine in the M.1k2 is heavily sandboxed:

Script Header

M.1k2 LUA scripts have four mandatory header lines to provide name, color and description for the button configuration. These four tags have to be within the first 512 bytes of the script, so it is best to place them right at the top.

Script Header

-- @name Button text
-- @desc Description, version information etc.
-- @fg #FEDCBA
-- @bg #123456

For your convenience, choose a foreground and background color below. The values will be inserted in the snippet above, just copy'n'paste the header into your script and insert your button text and description.

Button text

TagDescription
@nameThis text is displayed in the button
@descThe description will be shown in the button's tool tip
@fg/@bgForeground/background color of the button. You can use any HTML color definition ('red', 'white') or RGB hex values (with the dash prefix '#').

Indices

All port, channel, wordclock etc. IDs start with 1. So port 1..port 16 equals ID 1..16, channel 1..1024 equals ID 1..1024 etc.

Note: Array indices in LUA begin with 1.

Command List (by topic)

Audio Matrix

Serial Matrix

MIDI Matrix

MADI Configuration

Clock Configuration

GPO

Snapshots

MIDI

Doppelgaenger (Device Mirroring)

Device Configuration

Misc

Command List (alphabetical)

Command Reference

bulkbegin

bulkbegin()

No configuration changes are committed until a bulkend is called or a timeout of 1s since the last command has passed. Use this to mark the beginning of a sequence of commands that have to be executed at the same time.

Example

bulkbegin()
audioxp(1, 1, 1)
audioxp(1, 2, 1)
bulkend()

Both audio crosspoints will be set at the same time.

See also: bulkend.

bulkend

bulkend()

End a bulk request and commit all changes.

See also: bulkbegin.

getaudiolock

getaudiolock(channel)

Returns 0 if the channel has no lock and 1 if it is locked.

See also: setaudiolock.

getaudioxp

getaudioxp(channel, matrix)

Returns the source for destination channel (1..1024) in matrix (0=online, 1=offline). If the destination is not connected, -1 is returned.

See also: getaudioxps, setaudioxp.

getaudioxps

getaudioxps(matrix)

Returns an array with all 1024 source channels for the given matrix (0=online, 1=offline). If a destination is not connected, -1 is returned.

See also: getaudioxp, setaudioxp.

getdeadchannel

getdeadchannel(channel)

Returns the dead channel status for the given channel. A dead channel is a channel with no signal (> -60dBFS) since the last invocation of resetdeadchannels.

See also: resetdeadchannels.

getdevicecontact

getdevicecontact()

Return the contact data set for this device.

See also: setdevicecontact.

getdevicename

getdevicename()

Return the device's name.

See also: setdevicename.

getdoppelgaenger

getdoppelgaenger()

Return the current doppelgaenger status:

ValueDescription
0not connected
1connecting to master
2connected to master, initializing
3connected to master and active
4reconnecting to master

See also: getlocalcontrol, getmasterip.

getfan

getfan()

Return the current fan speed in percent, 0..100.

See also: gettemp, setfan.

getfansettings

getfansettings()

Return the current fan configuration values as an array of three values for 'warm', 'full' and 'critical' temperature (in degrees Celsius).

See also: setfan.

getframe96kfollow

getframe96kfollow()

Return the current state of the automatic 96k switch.

See also: setframe96kfollow.

getfreq

getfreq(clock)

Read out the sample rate of an external clock source. The clock parameter is one of the following:

1..16Port 1..16
17Word clock input
18Video 44.1kHz
19Video 48kHz
20Master clock output

getgain

getgain(channel)

Return the current gain in dB for channel, 1..1024.

Note: Channel and port gains add up to the final gain for every channel.

See also: setgain, setportgain, getportgain.

getgainlock

getgainlock(channel)

Return the current gain lock status for channel, 1..1024. If enabled, the gain for channel cannot be altered. A value of 0 indicates 'no lock', a value of 1 indicates 'lock'.

See also: setgainlock.

getgpo

getgpo(gpo)

Return the current level for gpo. The M.1k2 has four GPOs, 1..4. A return value of 0 indicates the GPO is turned off, 1 indicates the GPO is on.

See also: setgpo.

getgpoautomation

getgpoautomation(gpo)

Return the current setting for gpo automation. The M.1k2 has four GPOs, 1..4, and every GPO can be triggered by an internal event.

See also: setgpoautomation.

getgpopolarity

getgpopolarity(gpo)

Return the current polarity setting for a gpo. Polarity can be normal (0) or inverted (1).

See also: setgpopolarity.

getidentify

getidentify()

Returns 0 if identify is off and 1 otherwise.

See also: setidentify.

getinputportframe

getinputportframe(port)

Returns the MADI frame type of the incoming signal on a port, 1..16. The M.1k2 supports 48k and 96k frames, this function returns 48 or 96 resp.

See also: getinputportmode.

getinputportmode

getinputportmode(port)

Returns the number of channels of the incoming signal on a port, 1..16. This function returns 56, 57 or 64, depending on the signal, M.1k2 model and firmware version.

See also: getinputportframe.

getinputredundancy

getinputredundancy(port)

Returns the redundancy port for a MADI input port, 1..16. The returned value is the port this port. It it is the ID of the given port, the inpurt redundancy for this port is deactivated.

See also: setinputredundancy.

getioboard

getioboard(slot)

If a board is present in the given slot, 1..2, this function returns its serial number and the type of the physical interface:

ValueInterface
0N/C
1BNC
2SC multi mode
3SC single mode
4ST multi mode
5ST single mode
6SFP

If no IO board is installed in the slot, nil is returned.

Example

for idx=1,2 do
 serial,type = getioboard(idx)
 if (serial) then
  print(..idx..": #"..serial..", type: "..type)
 else
  print("no board in slot "..idx)
 end
end

Output the serial and connector type of the installed IO boards.

getipaddr

getipaddr()

Return the current IPv4 address of the device as a single 32bit unsigned integer.

getlabel

getlabel(type, id)

Return name, foreground and background color of a label of given type and id. For a list of possible label types, see the table of label types at the end of this page.

See also: setlabel, table of label types.

getlocalcontrol

getlocalcontrol()

Returns wether local control is possible (0) or if the device is remotely controlled (1).

getmasterclock

getmasterclock()

Returns 0 if the master clock override is not active, and 1 if it is active.

See also: setmasterclock, getmasterfs.

getmasterfallback

getmasterfallback()

Returns the two fallback clock sources in an array with two elements.

See also: setmasterfallback.

getmasterfs

getmasterfs()

Returns 0 if the master clock multiplier override is not active, and 1 if it is active.

See also: setmasterfs, getmasterclock.

getmasterip

getmasterip()

Return the IPv4 address of the currently active doppelgaenger master. The value will be an unsigned 32bit integer.

getmastersource

getmastersource()

Returns the currently active master clock source. This is not neccessarily the clock source configured via setwcksource, as the master clock fallback could have been triggered.

See also: setwcksource.

getmidixp

getmidixp(destination)

Returns the source connected to the MIDI destination, 1..18. If no source is connected to the destination, -1 is returned.

See also: setmidixp, getmidixps, list of MIDI ports.

getmidixps

getmidixps()

Returns all 18 MIDI destination in one array.

See also: setmidixp, getmidixp, list of MIDI ports.

getmirror

getmirror()

Returns 0 if this device is configured to be a master (default) or 1 for slave.

See also: setmirror.

getmsglevel

getmsglevel()

Return the current setting for the syslog message level.

See also: setmsglevel.

getoutputportframe

getoutputportframe(port)

Returns the output frame format setting for port, 1..16. The value can be 48 or 96 for 48k or 96k frames.

See also: setportframe.

getoutputportmode

getoutputportmode(port)

Returns the output channel number setting for port, 1..16. The value can be 56, 57 or 64, depending on your M.1k2 version and firmware.

See also: setportmode.

getportfollow

getportfollow(port)

Returns the port the given port is following. See setportfollow for a full explanation of this feature.

See also: setportfollow.

getportgain

getportgain(port)

Returns the port gain in dB for the given port, 1..16.

See also: setportgain, setgain, getgain.

getpsu

getpsu(id)

Read the status of the power supplies. id has to be 0 or 1 to identify the PSU. getpsu() returns

ValueMeaning
0PSU off
1PSU on
2PSU failed

getrs485echo

getrs485echo()

Returns the setting for the RS485 local echo function. 0=echo off, 1=echo on.

See also: setrs485echo, setrs4xxmode, getrs4xxmode.

getrs4xxmode

getrs4xxmode()

Returns the serial mode setting for the RS4XX port: 0=RS422, 1=RS485.

See also: setrs4xxmode, setrs485echo, getrs485echo.

getserialxp

getserialxp(destination)

Returns the source connected to the serial destination, 1..20. If no source is connected to the destination, -1 is returned.

See also: setserialxp, getserialxps, list of serial ports.

getserialxps

getserialxp(destination)

Returns all 20 serial destinations in one array.

See also: setserialxp, getserialxp, list of serial ports.

getsignal

getsignal(channel)

Returns the signal state for the given channel, 1..1024. If there was a signal above -60dBFS in the second before calling this function, a 1 is returned, 0 otherwise.

See also: getdeadchannel, resetdeadchannels.

getslaves

getslaves()

If the M.1k2 this function is invoked on acts as master for other M.1k2s, this function returns the IPv4 addresses of the connected slaced

See also: setserialxp, getserialxps, list of serial ports.

getsync

getsync(source)

Return the current sync status and timestamp of the last status change of an external source. source can be:

ValueSource
1..16MADI port 1..16
17Word clock input
18Video input

gettemp

gettemp()

Returns the device's temperature in degrees Celsius.

getterm

getterm()

Returns the current word clock termination status. 0 indicates 'off', 1 indicates 'on'.

See also: setterm.

getvideomode

getvideomode()

Return the video mode, PAL (=0) or NTSC (=1), that is currently seen at the video input.

getwckmode

getwckmode()

Returns the signal type at the word clock input, analogue word clock (=0) or AES3 (=1).

getwckmul

getwckmul(clock)

Return the current speed factor setting for a clock: 1, 2 or 4FS. The clock argument is a value from the table of clocks.

See also: setwckmul, table of clocks.

getwcksource

getwcksource(clock)

Return the current clock source for a clock. For clocks, please see the table of clocks, for clock sources the table of clock sources.

See also: setwcksource, getwckmul, table of clocks, table of clock sources.

miditx

miditx(data, len)

Send len bytes of data through the controller's output. The MIDI data will then be routed through the MIDI Matrix.

Examples

miditx("\192\1", 2)
Send program change C0 01, encoded as decimal values.

resetdeadchannels

resetdeadchannels()

Reset the table of dead channels (all channels that do not have a signal >-60dBFS in them).

See also: getdeadchannel, getsignal.

setaudiolock

setaudiolock(channel, lock)

Lock (lock=1) or unlock (lock=0) an output channel, 1..1024. Locking an audio channel prevents changes to the routing of this output channel.

See also: getaudiolock.

setaudioxp

setaudioxp(source, destination, matrix)

Set or clear an audio crosspoint.

ParameterUsage
source Source channel, 1..1024, or -1 to disconnect crosspoint.
destinationDestination channel, 1..1024
matrix selects the matrix to use: 0=online, 1=offline matrix

Examples

  1. setaudioxp(1, 1, 0)

    Connect the first input and first output channel of port 1.
  2. setaudioxp(-1, 1, 0)

    Disconnect whatever is connected to the first output channel of port 1.

setdevicename

setdevicename(name)

Set the device's name. It can be up to 64 bytes long.

See also: getdevicename, setdevicecontact.

setdevicecontact

setdevicontact(contact)

Set the device's contact information. It can be up to 256 bytes long.

See also: getdevicecontact, setdevicename.

setfan

setfan(warm, full, critical)

Configure the device's fan control curve. The fan starts blowing once the device reaches the warm, 30..60 degrees Celsius, temperature, the fan is blowing at 100% at the full, 40..70 degrees Celsius, temperature. If the critical, 40..70 degrees Celsius, temperature is reached it triggers an internal signal that can switch GPOs etc.

See also: getfansettings, getfan.

setframe96kfollow

setframe96kfollow(enable)

Enable (=1) or disable (=0) the automatic 96k frame format switch. If enabled, the output MADI signal automatically switches to 96k frame format if a 96k frame is detected at the input.

See also: getframe96kfollow, setportframe.

setgain

setgain(channel, gain)

Set the gain for an output channel. The final gain of an audio channel is the sum of channel and port gain.

channelOutput channel, 1..1024
gainGain value, -60..+30 dB. 0=unity gain.

See also: getgain, setportgain.

setgainlock

setgainlock(channel, lock)

Lock (=1) or unlock (=0) an output channel, 1..1024, gain. Locking an audio channel gain prevents changes to the channel gain.

See also: getgainlock.

setgpo

setgpo(gpo, value)

Manually turn a GPO, 1..4, on (=1) or off (=0). The output level depends on the polarity that is configured for this GPO.

See also: getgpo, setgpopolarity.

setgpoautomation

setgpoautomation(gpo, source)

Configure a GPO, 1..4, to be automatically triggered by an automation source. The the condition of the trigger is met, is switches to the level configured with setgpopolarity.

See also: getgpo, setgpopolarity, table of GPO automation sources.

setgpopolarity

setgpopolarity(gpo, polarity)

Configure the active level of a GPO, 1..4. With normal polarity (=0), the GPO has an active high level. With inversed polarity (=1) the active level is low.

See also: getgpopolarity.

setidentify

setidentify(enable)

When active (=1), the status and PSU leds blink slowly to help find the device. The identify function does not self cancel and has to be turned off manually (=0).

See also: getidentify.

setinputredundancy

setinputredundancy(port, rport)

Set the redundancy port for a MADI input port, 1..16. To enable input failover redundancy, set this to the value of the other MADI port. To disable input failover redundancy, set the rport value to the port itself.

See also: getinputredundancy.

setlabel

setlabel(type, id, label, fg, bg)

Configure a label.

ArgumentUsage
type1..8, see the table of label types
idValue range depending on the type, see the table of label types
labelLabel, 16 bytes
fgText color, see colors
bgBackground color, see colors

See also: getlabel, table of label types, colors.

setmasterclock

setmasterclock(enable)

Enable (=1) or disable (=0) the master clock. If enabled, all inputs use the master clock as clock reference.

See also: getmasterclock, setmasterfs.

setmasterfallback

setmasterfallback(id, source)

If the master clock source loses sync, the fallback sources take over in order of their id. To configure one of the fallback sources, choose the primary (id=0) or secondary (id=1) fallback and a clock source.

See also: getmasterfallback.

setmasterfs

setmasterfs(id, source)

Enable (=1) or disable (=0) the master clock speed factor. If enabled, all inputs use the same speed factor as the master clock.

See also: getmasterfs, setmasterclock.

setmidixp

setmidixp(source, destination)

Set or clear a MIDI crosspoint.

sourceSource channel, 1..18, or -1 to disconnect crosspoint.
destinationDestination channel, 1..18

Note: The MIDI matrix only affects the embedding and de-embedding of the MIDI data contained in channel 56. If you disconnect a port but route an incoming channel 56 onto the corresponding outgoing channel 56, the MIDI data will be routed as well.

Examples

  1. setmidixp(1, 1)

    Connect MIDI input and output of port 1.
  2. setaudioxp(-1, 1)

    Disconnect the MIDI output of port 1.

setmirror

setmirror(enable)

Enable (=1) or disable (=0) the slave mode. If enabled, local control on the device is disabled.

See also: getmirror, getlocalcontrol.

setmsglevel

setmsglevel(level)

Set the syslog message level.

LevelDescription
4Only generate warnings
6Info, be more verbose
7Debug, every action will be traced

See also: getmsglevel.

setportfollow

setportfollow(port, fport)

Let a port's clock source and speed setting follow another port to create a clock domain. To disable the follow function, set fport to port.

See also: getportfollow.

setportframe

setportframe(port, frame)

Set the frame format for port, 1..16. Possible values for frame are 48 and 96 for 48k.

See also: getoutputportframe.

setportmode

setportmode(port, mode)

Set the number of channels of the MADI output stream for a single port, 1..16. Possible values for mode are 56, 57 and 64.

Note: 57ch transmission is only available on black series M.1k2 with FPGA firmware 3.7 or above.

See also: getoutputportmode.

setportgain

setportgain(port, gain)

Set the gain for an output port, 1..16. Channel and port gains will be added and applied to each channel. The gain argument is a float -60..+30dB, unity gain=0.

See also: getportgain, setgain.

setrs4xxmode

setrs4xxmode(mode)

Configure the modus operandi of the RS4XX port: 0=RS422, 1=RS485.

See also: getrs4xxmode, setrs485echo, getrs485echo.

setrs485echo

setrs485echo()

Configure the RS485 local echo function. 0=echo off, 1=echo on.

See also: getrs485echo, setrs4xxmode, getrs4xxmode.

setserialxp

setserialxp(source, destination)

Set or clear a serial crosspoint.

ParameterValues
sourceSource, 1..20, or -1 to disconnect crosspoint.
destinationDestination, 1..20

Note: The MIDI matrix only affects the embedding and de-embedding of the serial data contained in channels 1..9. If you disconnect a port but route an incoming channels 1..9 onto the corresponding outgoing channels 1..9, the serial data will be routed as well.

Examples

  1. setserialxp(1, 1)

    Connect serial input and output of port 1.
  2. setserialxp(-1, 1)

    Disconnect the serial output of port 1.

setterm

setterm(enable)

Enable or disable the word clock termination. 0 indicates 'off', 1 indicates 'on'.

See also: getterm.

setwckmul

setwckmul(clock, mul)

Set the speed factor for a clock. The speed factor can be 1, 2 or 4 for 1FS, 2FS or 4FS operation. For clocks please see the table of clocks.

See also: getwckmul, table of clocks.

setwcksource

setwcksource(clock, source)

Set the clock source for a clock. For clocks, please see the table of clocks, for clock sources the table of clock sources.

See also: getwcksource, setwckmul, table of clocks, table of clock sources.

snapload

snapload(id)

Load a system snapshots with ID id, ranging from 0..127. The system snapshot has to be defined previously, see the page on system snapshots or snapstore.

The full content of the snapshot (all matrices and settings) will be restored.

See also: snapstore.

snapstore

snapstore(id, name, comment, fg, bg, projectname, projectfg, projectbg)

The current configuration is stored in a system snapshot slot. The parameters, and there are many, are:

ParameterValues
idID of the system snapshot. If there is already a snapshot in that slot, it will be overwritten.
nameName for this snapshot, up to 64 characters.
comment(optional) Comment for this snapshot, up to 512 characters.
fgText color represented as 24bit RGB value.
bgBackground color represented as 24bit RGB value.
projectnameName of the project. The project name is used to group snapshots. Up to 64 characters.
projectfgText color of the project name as 24bit RGB value.
projectbgBackground color of the project name as 24bit RGB value.

Example

snapstore(42, "last known good configuration", "no comment", 255*65536, 255*256, "LUA tutorial", 255*65535 + 255*256 + 255, 0)

Colors

A few commands need color values as argument or return them. Color values are always 24bit RGB data. The values for red, green and blue range from 0..255 and are added together: R*65536 + G*256 + B.

Clocks

IDClock
1..16Input port 1..16
17Word clock output
18Master clock

Clock Sources

These clock source IDs are used by multiple commands. They identify sync references for inputs, the master clock and the word clock output.

IDSource
1..16Input port 1..16
17Word clock input
18Video 44.1kHz
19Video 48kHz
20Internal 44.1kHz
21Internal 48kHz

Serial ports

IDSource
1..16MADI port 1..16
17Front RS232
18Front RS4XX
19USB
20Controller

MIDI ports

IDSource
1..16MADI port 1..16
17Front MIDI
18Controller

GPO Automation Sources

ValueEvent Trigger
0Off (manual activation, see setgpo)
1Port redundancy triggered (see setinputredundancy)
2'Full' temperature reached (see setfan)
3'Critical' temperature reached (see setfan)
4Sync loss on any MADI input
5Sync loss on any word clock input
6Sync loss on any video input
7PSU 1 fail
8PSU 2 fail
9Any PSU fail
10Doppelgaenger: Master ok
11Doppelgaenger: Master fail
12Doppelgaenger: Slave ok
13Doppelgaenger: Slave fail

Label Types

TypeLabelID range
1Input ports1..16
2Output ports1..16
3Input channels1..1014
4Output channels1..1024
5Serial input1..20
6Serial output1..20
7MIDI input1..18
8MIDI output1..18
Text and images © 2017 DirectOut Technologies, 08.02.2017