-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmolights.py
100 lines (84 loc) · 2.54 KB
/
qmolights.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
from pythonosc.udp_client import SimpleUDPClient
from pythonosc.osc_server import ThreadingOSCUDPServer
from pythonosc.dispatcher import Dispatcher
from typing import List, Any
import json
from natsort import natsorted
import threading
import time
import rtmidi
import qmomidi
dispatcher = Dispatcher()
server = None
client = None
lights = dict()
light_update = 0
def accept_anything(address: str, *osc_args: List[Any]) -> None:
global lights
global light_update
print(f"address={address}")
if address[:18] == "/update/workspace/":
if address[54:71] == "/cue_id/dashboard":
cmd = address[54:] + "/children/shallow"
print(f"cmd={cmd}")
client.send_message(cmd, [])
elif address[-17:] == "/lightCommandText":
for i in osc_args:
d = json.loads(i)
d = d['data'].split('\n')
for j in d:
j = j.split(' = ')
if j[1] == 'home':
j[1] = 0
lights[j[0]] = int(j[1])
light_update = light_update + 1
dispatcher.set_default_handler(accept_anything)
def get_lights():
global lights
return natsorted(list(lights.keys()))
def get_light(l):
global lights
return lights[l]
def set_light(l, v, send=False):
global lights
global client
global server
lights[l] = v
print(f"set_light({l}, {v}, {send})")
if send:
client.send_message("/dashboard/setLight", [l, v])
def send_message(msg, args):
client.send_message(msg, args)
def update_lights():
global lights
global client
global light_update
msg = rtmidi.MidiMessage.noteOn(1, 51, 127)
qmomidi.midiout().sendMessage(msg)
client.send_message("/new", "light")
client.send_message("/dashboard/recordAllToSelected", [])
client.send_message("/cue/selected/lightCommandText", [])
client.send_message("/delete/selected", [])
while light_update == 0:
time.sleep(0.1)
light_update = 0
client.send_message("/updates", 1)
client.send_message("/cueLists", [])
msg = rtmidi.MidiMessage.noteOn(1, 51, 0)
qmomidi.midiout().sendMessage(msg)
print(get_lights())
print(lights)
def osc_server():
global server
server = ThreadingOSCUDPServer(("127.0.0.1", 53001), dispatcher)
print("starting OSC server")
server.serve_forever()
def init_lights():
global lights
global server
global client
t = threading.Thread(target=osc_server)
t.start()
client = SimpleUDPClient("127.0.0.1", 53000)
update_lights()
print(lights)