-
Notifications
You must be signed in to change notification settings - Fork 1
/
LWCPClient.py
executable file
·276 lines (210 loc) · 9.65 KB
/
LWCPClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
"""LWCP Client. An Open-Source Python Client for the Axia Livewire Control Protocol."""
import time
from LWCPClientComms import LWCPClientComms
__author__ = "Anthony Eden"
__copyright__ = "Copyright 2015-2018, Anthony Eden / Media Realm"
__credits__ = ["Anthony Eden"]
__license__ = "Commercial"
__version__ = "1.0"
class LWCPClient():
"""Provides a friendly API for the Livewire Control Protocol."""
def __init__(self, host, port=4010):
"""Init LWCP connection."""
# This is our access to the LWCP
self.LWCP = None
# This variable gets given the callback data, ready to be processed by a waiting function
self.waitingForCallback = False
self.callbackData = None
self.LWCP = LWCPClientComms(host, port)
self.LWCP.start()
def stop(self):
"""Close LWCP connection."""
self.LWCP.stop()
def waitForCallback(self, timeout=5):
"""Wait for data to be returned from the Comms class."""
# The time we need to stop waiting for data and return it
waitTimeout = time.time() + timeout
while True:
if self.waitingForCallback is False or waitTimeout <= time.time():
returnData = self.callbackData
self.callbackData = None
return returnData
else:
time.sleep(0.1)
def genericCallback(self, data):
"""Generic callback receiving function."""
self.callbackData = data
self.waitingForCallback = False
def errorSub(self, callback):
"""Subscribe to error messages."""
self.LWCP.addSubscription("ERROR", callback, False)
def getShowProfiles(self):
"""Get a list of profiles on the console."""
self.LWCP.addSubscription("ShowProfileList", self.genericCallback, 1)
self.LWCP.sendCommand("GET AppControl ShowProfList")
self.waitingForCallback = True
return self.waitForCallback()
def getShowProfile(self):
"""Gets the active show profile on the console."""
self.LWCP.addSubscription("ShowProfile", self.genericCallback, 1)
self.LWCP.sendCommand("GET AppControl ShowProfID,ShowProfName,ShowProfStat")
self.waitingForCallback = True
return self.waitForCallback()
def setShowProfile(self, profile_id):
"""Activates the specified Show Profile"""
self.LWCP.sendCommand("SET AppControl ShowProfID=" + str(profile_id))
def getSourceProfiles(self, chnum, chtype = "fader"):
"""Gets the list of source profiles on the selected fader."""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.addSubscription("SourceProfiles", self.genericCallback, 1)
self.LWCP.sendCommand("GET " + chtype_cmd + str(chnum) + " src_list")
self.waitingForCallback = True
return self.waitForCallback()
def getSourceProfile(self, chnum, chtype = "fader"):
"""Gets the currently active source profile on the selected fader."""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.addSubscription("SourceProfile", self.genericCallback, 1)
self.LWCP.sendCommand("GET " + chtype_cmd + str(chnum) + " src_id, src_name, src_lwch, src_stat")
self.waitingForCallback = True
return self.waitForCallback()
def setSourceProfile(self, chnum, src_id, chtype = "fader"):
"""Sets a new active source profile on the selected fader."""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.addSubscription("SourceProfile", self.genericCallback, 1)
self.LWCP.sendCommand("SET " + chtype_cmd + str(chnum) + " src_id=" + str(src_id))
def getChannelState(self, chnum, chtype = "fader"):
"""Gets the on/off state for the specified channel."""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.addSubscription("FaderState", self.genericCallback, 1)
self.LWCP.sendCommand("GET " + chtype_cmd + str(chnum) + " ON_State")
self.waitingForCallback = True
return self.waitForCallback()
def setChannelState(self, chnum, on, chtype = "fader"):
"""Sets the specified channel on/off"""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
# On or Off
if on is True:
on_cmd = "ON_State=ON"
else:
on_cmd = "ON_State=OFF"
self.LWCP.sendCommand("SET " + chtype_cmd + str(chnum) + " " + on_cmd)
def getChannelGain(self, chnum, chtype = "fader"):
"""Gets the level for the specified channel."""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.addSubscription("FaderGain", self.genericCallback, 1)
self.LWCP.sendCommand("GET " + chtype_cmd + str(chnum) + " Fader_Gain")
self.waitingForCallback = True
return self.waitForCallback()
def setChannelGain(self, chnum, level, chtype = "fader"):
"""Sets the level for the specified channel"""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.sendCommand("SET " + chtype_cmd + str(chnum) + " Fader_Gain=" + str(level))
def getChannelBus(self, chnum, chtype = "fader"):
"""Gets the bus assignment for the specified channel."""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
self.LWCP.addSubscription("ChannelBus", self.genericCallback, 1)
self.LWCP.sendCommand("GET " + chtype_cmd + str(chnum) + " Asg_PGM1, Asg_PGM2, Asg_PGM3, Asg_PGM4, Asg_PREV")
self.waitingForCallback = True
return self.waitForCallback()
def setChannelBus(self, chnum, pgm1=None, pgm2=None, pgm3=None, pgm4=None, prev=None, chtype = "fader"):
"""Assign or unassign channels from each bus on the console"""
# Fader or Livewire
if chtype == "fader":
chtype_cmd = "FaCH#"
elif chtype == "livewire":
chtype_cmd = "LwCH#"
else:
raise Exception("Invalid channel type provided. Use 'fader' or 'livewire'.")
commands_bus = []
commands_bus_text = ""
if pgm1 is True:
commands_bus.append("Asg_PGM1=ON")
elif pgm1 is False:
commands_bus.append("Asg_PGM1=OFF")
if pgm2 is True:
commands_bus.append("Asg_PGM2=ON")
elif pgm2 is False:
commands_bus.append("Asg_PGM2=OFF")
if pgm3 is True:
commands_bus.append("Asg_PGM3=ON")
elif pgm3 is False:
commands_bus.append("Asg_PGM3=OFF")
if pgm4 is True:
commands_bus.append("Asg_PGM4=ON")
elif pgm4 is False:
commands_bus.append("Asg_PGM4=OFF")
if prev is True:
commands_bus.append("Asg_PREV=ON")
elif prev is False:
commands_bus.append("Asg_PREV=OFF")
for cmd in commands_bus:
if commands_bus_text != "":
commands_bus_text += ", " + cmd
else:
commands_bus_text += cmd
self.LWCP.sendCommand("SET " + chtype_cmd + str(chnum) + " " + str(commands_bus_text))
def getVMixChannelState(self, vmix, chnum):
"""Gets the level for the specified channel."""
self.LWCP.addSubscription("VMix", self.genericCallback, 1)
self.LWCP.sendCommand("GET VMIX.SUB#"+str(vmix)+".IN#"+str(chnum)+" State, Gain, TimeUp, TimeDown")
self.waitingForCallback = True
return self.waitForCallback()
def setVMixChannelState(self, vmix, chnum, on):
"""Sets the channel on/off for the specified vmix channel"""
# On or Off
if on is True:
on_cmd = "State=ON"
else:
on_cmd = "State=OFF"
self.LWCP.sendCommand("SET VMIX.SUB#"+str(vmix)+".IN#"+str(chnum)+" " + on_cmd)
def setVMixChannelGain(self, vmix, chnum, gain):
"""Sets the level for the specified vmix channel"""
self.LWCP.sendCommand("SET VMIX.SUB#"+str(vmix)+".IN#"+str(chnum)+" Gain=" + str(gain))