Main or Backup

This chapter was written for QLab 4, but it also works with QLab 5 with only a few small modifications. Example workspaces are provided for both QLab 4 and QLab 5.

Many of us use QLab in redundant systems, with a Main and a Backup machine. The general approach to creating a backup for audio and video is to use external hardware to selectively mute or un-mute the output of each machine, so that only one of the two computers is “speaking” at a time. There are a variety of solutions available for switching audio and video signals, but switching control signals like DMX, MIDI, Timecode, and OSC can be more difficult.

QLab’s Override Controls can solve this neatly, allowing you to mute the output of MIDI, MSC, SysEx, OSC, Timecode, and DMX from QLab, but it can be inconvenient to manually toggle all the buttons in the Override Controls panel manually, especially on both a main and a backup mac.

This workspace demonstrates a method of automating the muting and un-muting of control signals. It uses a text file on the desktop of each Mac to determine if the workspace on that Mac should behave as the main or backup, and allows you to switch output from main to backup by running the same Script cue on both the main and backup workspace.

The example workspace has three numbered cues which contain the working smarts of the switching system. These three cues can be copied into your workspace.

The first cue is a Memo cue with cue number status which displays the current state of the workspace. The name and color of this cue are changed by the Script cues as needed.

The second is a Script cue with cue number choose. To set the workspace as main or backup, run this cue. The script is as follows:

-- tell the script where to look for your text file
-- this example uses the Desktop for the current user
set newFile to ((POSIX path of (path to home folder)) & "Desktop/computer.rtf")
set theFileContents to paragraphs of (read newFile)

-- define a variable, computerType, that will be filled in by the next block of code
set computerType to ""

-- check the text file for the word 'Main' or the word 'Backup', and fill in the appropriate value for computerType
repeat with p in theFileContents
  if p contains "Backup" then
    set computerType to "Backup"
  else if p contains "Main" then
    set computerType to "Main"
  end if
end repeat

-- set up the mac as main or backup depending on the contents of computerType
tell application id "com.figure53.QLab.4" to tell front workspace
  
  if computerType is "Main" then --set this mac as the main computer
    
    -- set the overrides
    tell application id "com.figure53.QLab.4"
      set midi output enabled of overrides to true
      set msc output enabled of overrides to true
      set sysex output enabled of overrides to true
      set osc output enabled of overrides to true
      set timecode output enabled of overrides to true
      set artnet enabled of overrides to true
    end tell
    
    -- set up the "switch" cue appropriately
    set script source of cue "switch" to "tell application id \"com.figure53.QLab.4\"
      set midi output enabled of overrides to false
      set msc output enabled of overrides to false
      set sysex output enabled of overrides to false
      set osc output enabled of overrides to false
      set timecode output enabled of overrides to false
      set artnet enabled of overrides to false
      set q name of cue \"status\" of front workspace to \"Main – MUTED\"
      set q color of cue \"status\" of front workspace to \"red\"
    end tell"
    
    -- report back to the user
    set q name of cue "status" to "Main – Active"
    set q color of cue "status" to "green"
    display dialog "I'm the Main" buttons {"OK"} default button 1
    
  else if computerType is "Backup" then
    
    -- set the overrides
    tell application id "com.figure53.QLab.4"
      set midi output enabled of overrides to false
      set msc output enabled of overrides to false
      set sysex output enabled of overrides to false
      set osc output enabled of overrides to false
      set timecode output enabled of overrides to false
      set artnet enabled of overrides to false
    end tell
    
    -- set up the "switch" cue appropriately
    set script source of cue "switch" to "tell application id \"com.figure53.QLab.4\"
        set midi output enabled of overrides to true
      set msc output enabled of overrides to true
      set sysex output enabled of overrides to true
      set osc output enabled of overrides to true
      set timecode output enabled of overrides to true
      set artnet enabled of overrides to true
      set q name of cue \"status\" of front workspace to \"Backup – ACTIVE\"
      set q color of cue \"status\" of front workspace to \"blue\"
    end tell"
    
    -- report back to the user
    set q name of cue "status" to "Backup – Muted"
    set q color of cue "status" to "orange"
    display dialog "I'm the Backup" buttons {"OK"} default button 1
    
  end if
end tell

The script defines a variable, “computerType” and then looks inside a text file on the Desktop called “computer.rtf” for either the word “main” or “backup” (case-insensitive… “Main” or “main”, “Backup” or “backup”.) That word is copied into the variable, and then the variable is used to indicate whether the output overrides should be enabled or disabled.

The script also replaces the contents of the switch Script cue with a script that inverts the overrides. So, if the text file says that this computer is “main,” then all the overrides are set to false (un-muted) and the switch cue is rewritten to set all the overrides to true (muted.) If the text file says that this computer is “backup,” then all the overrides are set to true (muted) and the switch cue is rewritten to set all the overrides to false (un-muted.)

Both the choose script and the switch script set the color and name of the status cue to show the current state of the workspace.

When the switch cue is run simultaneously on both Macs, the main workspace mutes itself and the backup workspace un-mutes itself. In order to run the switch cue simultaneously on both Macs, it’s recommended that you use a MIDI controller which sends messages to both Macs, and assign a button on the controller as a MIDI trigger for the switch cue.