Skip to content

Commit ee3c923

Browse files
authored
v3.1.0 (#24)
* #17 Moves useTCP definition from module to config file * (#13 #15) More foolproof version of config applescript Eliminates the need for "Only" option and allows easier updates * (#18) Create server setup file with applescript * Remove debugging lines * (#20) blank display if there is no playhead * Updated readme * Update notes in scripts
1 parent 236da14 commit ee3c923

5 files changed

Lines changed: 219 additions & 58 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ dist
105105

106106
# config file
107107
/open-stage-control-module/qlab-info-config.json
108+
/open-stage-control-module/qlab-display.config

README.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,41 @@ You can run the module with either a UDP or TCP connection to Qlab. I recommend
1313

1414
## Open Stage Control setup
1515

16-
- First, put the 'open-stage-control-module' folder on the computer you wish to run the server from. Ensure this is on the network, and file sharing is enabled.
17-
- Then, on your Qlab computer, navigate to the folder over the network and open 'Get-IDs.applescript' in script editor.
18-
- Ensure your Qlab file is open, the front-most Qlab file if there are multiple, and that the current cue list is the one you wish to monitor.
16+
- First, put the 'open-stage-control-module' folder on the computer you wish to run the server from. Ensure the computer is on the network, and file sharing is enabled.
17+
- On your Qlab computer, navigate to the folder over the network and open 'Get-IDs.applescript' in script editor.
18+
- Ensure your Qlab file is open, and the front-most Qlab workspace.
1919
- Run the 'Get-IDs' script - this will create 'qlab-info-config.json' in the root folder.
2020
- The first dialog box asks you to define the Qlab computer
21-
- If you only have a single Qlab computer, select "Only" when prompted to define this Qlab machine.
22-
- If you have a main and a backup Qlab computer, run this script first on the "Main", then repeat this process on the "Backup", and the script will append the necessary information on the end of the config file.
21+
- If this is your only Qlab computer, or if this is your "Main" or "A" machine, select "Main".
22+
- If you have a *main* and *backup* Qlab computer, ensure you run this setup process on the *main* first, then repeat the process on the *backup*, selecting "Backup", to complete the config file.
2323
- The second dialog box allows you to choose the cue list you wish to monitor.
2424
- The third dialog box asks you which local IP address you wish to use. If your computer is on multiple networks, e.g. a control network and a [Dante](https://www.audinate.com/meet-dante/what-is-dante) network, this allows you to select the correct one.
25-
- Settings for Backup computers are not used in the current release, but will be implemented in an imminent release.
26-
- Open **Open Stage Control**.
27-
- Set the following settings in the launcher, using files from the `open-stage-control-module` folder:
28-
- **load**: select the file `open-stage-control-template.json`
29-
- **custom-module**: select the file `get-cue-list-playhead.js`
30-
- **port**: this is the port that the web server is served to. Leave this blank to use the default 8080.
31-
- **no-gui**: if you do not want this open on the device which is the server, set this to true.
32-
- **IF USING UDP**
33-
- **osc-port**: set 53001. This is the port it will listen for replies from.
34-
- Ensure you also edit the variable useTCP to "false" in `get-cue-list-playhead.js`
35-
- **IF USING TCP**
36-
- **tcp-port**: set 53001.
37-
- **tcp-targets**: set \[Qlab IP\]:53000 (e.g. `127.0.0.1:53000`). Use a space to separate multiple instances.
38-
- Now, click start to launch the OSC & web server.
25+
- **NB**: 127.0.0.1 is the localhost address.
26+
- If you are running the server on a mac:
27+
- On the computer running the server, open 'Create-Server-Setup.applescript' in script editor, and run the script. This will create 'qlab-display.config'.
28+
- Open **Open Stage Control**.
29+
- Select *Load* and open 'qlab-display.config'.
30+
- Click start to launch the OSC & web server.
31+
- If you are running the server on a non-mac computer:
32+
- Set the following settings in the launcher, using files from the `open-stage-control-module` folder:
33+
- **load**: select the file `open-stage-control-template.json`
34+
- **custom-module**: select the file `get-cue-list-playhead.js`
35+
- **port**: this is the port that the web server is served to. Leave this blank to use the default 8080.
36+
- **no-gui**: if you do not want this open on the device which is the server, set this to true.
37+
- **IF USING UDP**
38+
- **osc-port**: set 53001. This is the port it will listen for replies from.
39+
- Ensure you also edit the variable useTCP to "false" in `get-cue-list-playhead.js`
40+
- **IF USING TCP**
41+
- **tcp-port**: set 53001.
42+
- **tcp-targets**: set \[Qlab IP\]:53000 (e.g. `127.0.0.1:53000`). Use a space to separate multiple instances.
43+
- Now, click start to launch the OSC & web server.
3944

4045
My suggested setup is to run the Open Stage Control server at Front Of House (for example, on the System computer), with the local GUI active, so the Sound No. 1 can see that it is working correctly. Then, the remote display for the MD is simply a browser window.
4146

4247
This has the added advantage that, if the Sound No 1 has to switch to the Backup due to issues with the Main, or the Main computer crashing entirely, they can also hit the "BACKUP" button on the viewer, which also switches it for the MD.
4348

49+
If you ever need to re-generate 'qlab-info-config.json', you can simply run the process again. This might happen if you bundle the workspace.
50+
4451
# Node JS version
4552

4653
## Methods
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
-- @description Create Open Stage Control server setup
2+
-- @author Ben Smith
3+
-- @link bensmithsound.uk
4+
-- @version 1.0-beta1
5+
-- @testedmacos 10.14.6
6+
-- @testedqlab 4.6.10
7+
-- @about Creates a file to open/load in Open Stage Control, with settings required to start the server.
8+
9+
-- @changelog
10+
-- v1.0 + init
11+
12+
13+
---- DECLARATIONS -------------------------
14+
15+
use framework "Foundation"
16+
use scripting additions
17+
18+
property ca : a reference to current application
19+
property NSData : a reference to ca's NSData
20+
property NSDictionary : a reference to ca's NSDictionary
21+
property NSJSONSerialization : a reference to ca's NSJSONSerialization
22+
property NSString : a reference to ca's NSString
23+
property NSUTF8StringEncoding : a reference to 4
24+
25+
26+
---- RUN SCRIPT ---------------------------
27+
28+
set qlabConfig to getConfig()
29+
30+
set configFile to ((getRootFolder() as text) & "qlab-display.config")
31+
32+
set configContents to "{"
33+
34+
if useTCP of control of qlabConfig is true then
35+
set configContents to configContents & "\"tcp-port\":53001,\"tcp-targets\":[\""
36+
37+
set configContents to configContents & |ip| of QlabMain of qlabConfig & ":53000\""
38+
39+
if QlabCount of qlabConfig is 2 then
40+
set configContents to configContents & ",\"" & |ip| of QlabBackup of qlabConfig & ":53000\""
41+
end if
42+
43+
set configContents to configContents & "],"
44+
45+
end if
46+
47+
set rootFolder to getRootFolder()
48+
set rootFolder to rootFolder as text
49+
set rootFolder to POSIX path of alias rootFolder
50+
51+
set configContents to configContents & "\"load\":\"" & rootFolder & "open-stage-control-template.json\",\"custom-module\":\"" & rootFolder & "get-cue-list-playhead.js\""
52+
53+
if useTCP of control of qlabConfig is false then
54+
set configContents to configContents & ",\"osc-port\":53001"
55+
end if
56+
57+
set configContents to configContents & "}"
58+
59+
60+
writeToFile((configContents as text), configFile, false)
61+
62+
63+
64+
-- FUNCTIONS ------------------------------
65+
66+
on JSONtoRecord from fp
67+
local fp
68+
69+
set JSONdata to NSData's dataWithContentsOfFile:fp
70+
71+
set [x, E] to (NSJSONSerialization's ¬
72+
JSONObjectWithData:JSONdata ¬
73+
options:0 ¬
74+
|error|:(reference))
75+
76+
if E missing value then error E
77+
78+
tell x to if its isKindOfClass:NSDictionary then ¬
79+
return it as record
80+
81+
x as list
82+
end JSONtoRecord
83+
84+
on getConfig()
85+
set qlabConfigFile to ((getRootFolder() as text) & "qlab-info-config.json")
86+
set qlabConfigPOSIX to POSIX path of qlabConfigFile
87+
set qlabConfig to JSONtoRecord from qlabConfigPOSIX
88+
return qlabConfig
89+
end getConfig
90+
91+
on getRootFolder()
92+
set thePath to path to me
93+
94+
tell application "Finder"
95+
set thePath to parent of thePath
96+
end tell
97+
end getRootFolder
98+
99+
on writeToFile(thisData, targetFile, appendData) -- (string, file path as string, boolean)
100+
try
101+
set the targetFile to the targetFile as text
102+
set the openTargetFile to ¬
103+
open for access file targetFile as «class furl» with write permission
104+
if appendData is false then ¬
105+
set eof of the openTargetFile to 0
106+
write thisData to the openTargetFile starting at eof
107+
close access the openTargetFile
108+
return true
109+
on error
110+
try
111+
close access file targetFile
112+
end try
113+
return false
114+
end try
115+
end writeToFile
116+
117+
on readFile(theFile)
118+
try
119+
set theFile to theFile as text
120+
set fileContents to paragraphs of (read file theFile)
121+
122+
return fileContents
123+
on error
124+
return "error"
125+
end try
126+
end readFile
127+
128+
on splitString(theString, theDelimiter)
129+
-- save delimiters to restore old settings
130+
set oldDelimiters to AppleScript's text item delimiters
131+
-- set delimiters to delimiter to be used
132+
set AppleScript's text item delimiters to theDelimiter
133+
-- create the array
134+
set theArray to every text item of theString
135+
-- restore old setting
136+
set AppleScript's text item delimiters to oldDelimiters
137+
-- return the array
138+
return theArray
139+
end splitString

open-stage-control-module/Get-IDs.applescript

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- @description Get Unique IDs for Open Stage Control monitoring
22
-- @author Ben Smith
33
-- @link bensmithsound.uk
4-
-- @version 2.1
4+
-- @version 3.0-beta2
55
-- @testedmacos 10.14.6
66
-- @testedqlab 4.6.10
77
-- @about
@@ -12,14 +12,13 @@
1212
-- @separateprocess TRUE
1313

1414
-- @changelog
15-
-- v2.1 + prompts user to select cue list
16-
-- + alerts the user if they try to configure the backup qlab mac first
15+
-- v3.0 + improvements in usability
1716

1817

1918
---- RUN SCRIPT ---------------------------
2019

2120
-- determine if this computer is MAIN or BACKUP
22-
set thisMac to (choose from list {"Main", "Backup", "Only"} with title "Which QLab mac is this?") as string
21+
set thisMac to (choose from list {"Main", "Backup"} with title "Which QLab mac is this?") as string
2322

2423
checkMain(thisMac)
2524

@@ -31,6 +30,13 @@ set thisCueList to chooseOption(theCueLists, "cue list")
3130
set listIPs to getIP()
3231
set thisIP to chooseOption(listIPs, "IP address")
3332

33+
-- get TCP or UDP from the user
34+
if thisMac is "Main" then
35+
set useProtocol to button returned of (display dialog "Would you like to use TCP or UDP to connect to Qlab? TCP is recommended" with title "Please select protocol" buttons {"TCP", "UDP", "Cancel"} default button "TCP" cancel button "Cancel")
36+
else
37+
set useProtocol to "not needed"
38+
end if
39+
3440
-- get QLab and Cue List info
3541
tell application id "com.figure53.Qlab.4" to tell front workspace
3642

@@ -42,32 +48,25 @@ end tell
4248

4349
-- format for JSON
4450
if thisMac is "Main" then
45-
set jsonString to " \"QlabCount\": 2,
46-
\"QlabMain\": {
51+
set jsonString to " \"QlabMain\": {
4752
\"ip\": \"" & thisIP & "\",
4853
\"workspaceID\": \"" & thisWorkspaceID & "\",
4954
\"cueListID\": \"" & thisCueListID & "\"
5055
},
51-
"
52-
else if thisMac is "Backup" then
53-
set jsonString to " \"QlabBackup\": {
54-
\"ip\": \"" & thisIP & "\",
55-
\"workspaceID\": \"" & thisWorkspaceID & "\",
56-
\"cueListID\": \"" & thisCueListID & "\"
57-
}
56+
\"QlabCount\": 1
5857
}"
59-
else if thisMac is "Only" then
60-
set jsonString to " \"QlabCount\": 1,
61-
\"QlabMain\": {
58+
else if thisMac is "Backup" then
59+
set jsonString to "\"QlabBackup\": {
6260
\"ip\": \"" & thisIP & "\",
6361
\"workspaceID\": \"" & thisWorkspaceID & "\",
6462
\"cueListID\": \"" & thisCueListID & "\"
65-
}
63+
},
64+
\"QlabCount\": 2
6665
}"
6766
end if
6867

6968
-- write to config file
70-
writeToConfig(jsonString)
69+
writeToConfig(jsonString, thisMac, useProtocol)
7170

7271

7372
-- FUNCTIONS ------------------------------
@@ -99,7 +98,8 @@ end getCueLists
9998
on getIP()
10099
try
101100
set theReturned to (do shell script "ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2")
102-
set theIPs to splitString(theReturned, "")
101+
set theIPs to splitString(theReturned, "
102+
")
103103
on error
104104
set theIPs to {"Can't get Local IP"}
105105
end try
@@ -111,17 +111,25 @@ on chooseOption(theList, theName)
111111
return theOption
112112
end chooseOption
113113

114-
on checkConfig()
114+
on checkConfig(thisMac, useProtocol)
115115
set configFile to ((getRootFolder() as text) & "qlab-info-config.json")
116-
set configContents to readFile(configFile)
117-
if configContents is "error" then
116+
if thisMac is "Main" then
118117
set configPreface to ¬
119118
"{
120119
\"control\": {
121120
\"address\": {
122121
\"name\": \"/next/name\",
123122
\"number\": \"/next/number\"
124-
}
123+
},
124+
\"useTCP\": "
125+
126+
if useProtocol is "TCP" then
127+
set configPreface to configPreface & "true"
128+
else if useProtocol is "UDP" then
129+
set configPreface to configPreface & "false"
130+
end if
131+
132+
set configPreface to configPreface & "
125133
},
126134
"
127135

@@ -134,15 +142,23 @@ on checkMain(thisMac)
134142
set configFile to ((getRootFolder() as text) & "qlab-info-config.json")
135143
set configContents to readFile(configFile)
136144
if configContents is "error" and thisMac is "Backup" then
137-
display dialog "Please run this script on the Main Qlab first"
145+
display dialog "Please run this script on the Main Qlab first" with title "Alert" with icon stop
146+
error -128
147+
else if item -2 of configContents is " \"QlabCount\": 2" and thisMac is "Backup" then
148+
display dialog "Please run this script on the Main Qlab first, to generate an updated config file" with title "Alert" with icon stop
138149
error -128
139150
end if
151+
log item -2 of configContents
140152
end checkMain
141153

142-
on writeToConfig(theText)
143-
set configFile to checkConfig()
154+
on writeToConfig(theText, thisMac, useProtocol)
155+
set configFile to checkConfig(thisMac, useProtocol)
144156

145-
writeToFile(theText, configFile, true)
157+
if thisMac is "Main" then
158+
writeToFile(theText, configFile, true)
159+
else if thisMac is "Backup" then
160+
writeToFile(theText, configFile, "backup")
161+
end if
146162
end writeToConfig
147163

148164
on writeToFile(thisData, targetFile, appendData) -- (string, file path as string, boolean)
@@ -152,6 +168,8 @@ on writeToFile(thisData, targetFile, appendData) -- (string, file path as string
152168
open for access file targetFile with write permission
153169
if appendData is false then ¬
154170
set eof of the openTargetFile to 0
171+
if appendData is "backup" then ¬
172+
set eof of the openTargetFile to ((get eof of the openTargetFile) - 16)
155173
write thisData to the openTargetFile starting at eof
156174
close access the openTargetFile
157175
return true

0 commit comments

Comments
 (0)