forked from lebaston100/MIDItoOBS
/
setup.py
executable file
·595 lines (573 loc) · 27.8 KB
/
setup.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/usr/bin/env python
import mido, threading, sys, atexit, json, time
from tinydb import TinyDB, Query
from websocket import create_connection
####Change IP and Port here
serverIP = "localhost"
serverPort = "4444"
####
# QND: workaround to make multiple instances/devices work with a different configuration
configfile = "config.json"
if len(sys.argv) > 1:
configfile = sys.argv[1]
db = TinyDB(configfile, indent=4)
buttonActions = ["SetCurrentScene", "SetPreviewScene", "TransitionToProgram", "SetCurrentTransition", "SetSourceVisibility", "ToggleSourceVisibility", "ToggleMute", "SetMute",
"StartStopStreaming", "StartStreaming", "StopStreaming", "StartStopRecording", "StartRecording", "StopRecording", "StartStopReplayBuffer",
"StartReplayBuffer", "StopReplayBuffer", "SaveReplayBuffer", "SetTransitionDuration", "SetCurrentProfile","SetCurrentSceneCollection",
"ResetSceneItem", "SetTextGDIPlusText", "SetBrowserSourceURL", "ReloadBrowserSource"]
faderActions = ["SetVolume", "SetSyncOffset", "SetSourcePosition", "SetSourceRotation", "SetSourceScale", "SetTransitionDuration"]
jsonArchive = {"SetCurrentScene": """{"request-type": "SetCurrentScene", "message-id" : "1", "scene-name" : "%s"}""",
"SetPreviewScene": """{"request-type": "SetPreviewScene", "message-id" : "1","scene-name" : "%s"}""",
"TransitionToProgram": """{"request-type": "TransitionToProgram", "message-id" : "1"%s}""",
"SetCurrentTransition": """{"request-type": "SetCurrentTransition", "message-id" : "1", "transition-name" : "%s"}""",
"StartStopStreaming": """{"request-type": "StartStopStreaming", "message-id" : "1"}""",
"StartStreaming": """{"request-type": "StartStreaming", "message-id" : "1"}""",
"StopStreaming": """{"request-type": "StopStreaming", "message-id" : "1"}""",
"StartStopRecording": """{"request-type": "StartStopRecording", "message-id" : "1"}""",
"StartRecording": """{"request-type": "StartRecording", "message-id" : "1"}""",
"StopRecording": """{"request-type": "StopRecording", "message-id" : "1"}""",
"ToggleMute": """{"request-type": "ToggleMute", "message-id" : "1", "source": "%s"}""",
"SetMute": """{"request-type": "SetMute", "message-id" : "1", "source": "%s", "mute": %s}""",
"StartStopReplayBuffer": """{"request-type": "StartStopReplayBuffer", "message-id" : "1"}""",
"StartReplayBuffer": """{"request-type": "StartReplayBuffer", "message-id" : "1"}""",
"StopReplayBuffer": """{"request-type": "StopReplayBuffer", "message-id" : "1"}""",
"SaveReplayBuffer": """{"request-type": "SaveReplayBuffer", "message-id" : "1"}""",
"SetTransitionDuration": """{"request-type": "SetTransitionDuration", "message-id" : "1", "duration": %s}""",
"SetVolume": """{"request-type": "SetVolume", "message-id" : "1", "source": "%s", "volume": %s}""",
"SetSyncOffset": """{"request-type": "SetSyncOffset", "message-id" : "1", "source": "%s", "offset": %s}""",
"SetCurrentProfile": """{"request-type": "SetCurrentProfile", "message-id" : "1", "profile-name": "%s"}""",
"SetCurrentSceneCollection": """{"request-type": "SetCurrentSceneCollection", "message-id" : "1", "sc-name": "%s"}""",
"ResetSceneItem": """{"request-type": "ResetSceneItem", "message-id" : "1", "item": %s}""",
"SetTextGDIPlusText": """{"request-type": "SetTextGDIPlusProperties", "message-id" : "1", "source": "%s", "text": "%s"}""",
"SetBrowserSourceURL": """{"request-type": "SetBrowserSourceProperties", "message-id" : "1", "source": "%s", "url": "%s"}""",
"SetSourcePosition": """{"request-type": "SetSceneItemProperties", "message-id" : "1", "scene": "%s", "item": "%s", "position": {"%s": %s}}""",
"SetSourceRotation": """{"request-type": "SetSceneItemProperties", "message-id" : "1", "scene": "%s", "item": "%s", "rotation": %s}""",
"SetSourceVisibility": """{"request-type": "SetSceneItemProperties", "message-id" : "1", "item": "%s", "visible": %s}""",
"ToggleSourceVisibility": """{"request-type": "SetSceneItemProperties", "message-id" : "1", "item": "%s", "visible": %s}""",
"SetSourceScale": """{"request-type": "SetSceneItemProperties", "message-id" : "1", "scene": "%s", "item": "%s", "scale": {"%s": %s}}""",
"ReloadBrowserSource": """{"request-type": "SetBrowserSourceProperties", "message-id" : "1", "source": "%s", "url": "%s"}"""}
sceneListShort = []
sceneListLong = []
transitionList = []
specialSourcesList = []
profilesList = []
sceneCollectionList = []
gdisourcesList = []
ignore = 255
savetime1 = time.time()
def exitScript():
print("Exiting...")
midiport.close()
db.close()
def midicallback(message):
global ignore
print()
print(message)
print()
if message.type == "note_on": #button only
ignore = message.note
print("Select Action:")
counter = 0
for action in buttonActions:
print("%s: %s" % (counter, action))
counter += 1
input_select = int(input("Select 0-%s: " % str(len(buttonActions)-1)))
if input_select in range(0, len(buttonActions)):
action = buttonActions[input_select]
setupButtonEvents(action, message.note, message.type)
elif message.type == "program_change": #button only
ignore = message.program
print("Select Action:")
counter = 0
for action in buttonActions:
print("%s: %s" % (counter, action))
counter += 1
input_select = int(input("Select 0-%s: " % str(len(buttonActions)-1)))
if input_select in range(0, len(buttonActions)):
action = buttonActions[input_select]
setupButtonEvents(action, message.program, message.type)
elif message.type == "control_change": #button or fader
ignore = message.control
print("Select input type:\n0: Button\n1: Fader/Knob\n2: Ignore")
try:
input_select = int(input("Select 0-2: "))
if input_select in range(0, 3):
if input_select == 0:
print()
print("Select Action:")
counter = 0
for action in buttonActions:
print("%s: %s" % (counter, action))
counter += 1
input_select = int(input("Select 0-%s: " % str(len(buttonActions)-1)))
if input_select in range(0, len(buttonActions)):
action = buttonActions[input_select]
setupButtonEvents(action, message.control, message.type)
elif input_select == 1:
print()
print("Select Action:")
counter = 0
for action in faderActions:
print("%s: %s" % (counter, action))
counter += 1
input_select = int(input("Select 0-%s: " % str(len(faderActions)-1)))
if input_select in range(0, len(faderActions)):
action = faderActions[input_select]
setupFaderEvents(action, message.control, message.type)
except ValueError:
print("Please try again and enter a valid number")
#I know this is kinda messy, but i challange you to make a better version(as a native plugin or pull request to obs-studio)
def setupFaderEvents(action, NoC, msgType):
print()
print("You selected: %s" % action)
if action == "SetVolume":
updateSceneList()
updateSpecialSources()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
for item in specialSourcesList:
tempSceneList.append(item)
source = printArraySelect(tempSceneList)
scale = (0,1)
action = jsonArchive["SetVolume"] % (source, "%s")
saveFaderToFile(msgType, NoC, "fader" , action, scale, "SetVolume")
elif action == "SetSyncOffset":
updateSceneList()
updateSpecialSources()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
for item in specialSourcesList:
tempSceneList.append(item)
source = printArraySelect(tempSceneList)
scale = askForInputScaling()
action = jsonArchive["SetSyncOffset"] % (source, "%s")
saveFaderToFile(msgType, NoC, "fader" , action, scale, "SetSyncOffset")
elif action == "SetSourcePosition":
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
tmpOBJ = {"scene": scene["name"], "source": line["name"]}
tempSceneList.append(tmpOBJ)
counter = 0
for line in tempSceneList:
print("%s: Source '%s' in scene '%s'" % (counter, line["source"], line["scene"]))
counter += 1
selected = tempSceneList[int(input("Select 0-%s: " % str(len(tempSceneList)-1)))]
tempTargetList = ["x", "y"]
target = int(input("\n0: X\n1: Y\nSelect Target to change (0-1): "))
if target in range(0, 2):
scale = askForInputScaling()
action = jsonArchive["SetSourcePosition"] % (selected["scene"], selected["source"], tempTargetList[target], "%s")
saveFaderToFile(msgType, NoC, "fader" , action, scale, "SetSourcePosition")
elif action == "SetSourceRotation":
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
tmpOBJ = {"scene": scene["name"], "source": line["name"]}
tempSceneList.append(tmpOBJ)
counter = 0
for line in tempSceneList:
print("%s: Source '%s' in scene '%s'" % (counter, line["source"], line["scene"]))
counter += 1
selected = tempSceneList[int(input("Select 0-%s: " % str(len(tempSceneList)-1)))]
scale = askForInputScaling()
action = jsonArchive["SetSourceRotation"] % (selected["scene"], selected["source"], "%s")
saveFaderToFile(msgType, NoC, "fader" , action, scale, "SetSourceRotation")
elif action == "SetTransitionDuration":
scale = askForInputScaling()
action = jsonArchive["SetTransitionDuration"]
saveFaderToFile(msgType, NoC, "fader" , action, scale, "SetTransitionDuration")
elif action == "SetSourceScale":
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
tmpOBJ = {"scene": scene["name"], "source": line["name"]}
tempSceneList.append(tmpOBJ)
counter = 0
for line in tempSceneList:
print("%s: Source '%s' in scene '%s'" % (counter, line["source"], line["scene"]))
counter += 1
selected = tempSceneList[int(input("Select 0-%s: " % str(len(tempSceneList)-1)))]
tempTargetList = ["x", "y"]
target = int(input("\n0: X\n1: Y\nSelect Target to change (0-1): "))
if target in range(0, 2):
scale = askForInputScaling()
action = jsonArchive["SetSourceScale"] % (selected["scene"], selected["source"], tempTargetList[target], "%s")
saveFaderToFile(msgType, NoC, "fader" , action, scale, "SetSourceScale")
def setupButtonEvents(action, NoC, msgType):
print()
print("You selected: %s" % action)
if action == "SetCurrentScene": #fertig
updateSceneList()
scene = printArraySelect(sceneListShort)
action = jsonArchive["SetCurrentScene"] % scene
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetPreviewScene": #fertig
updateSceneList()
scene = printArraySelect(sceneListShort)
action = jsonArchive["SetPreviewScene"] % scene
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "TransitionToProgram": #fertig
updateTransitionList()
transitionList.append("--Current--")
transition = printArraySelect(transitionList)
print(transition)
if transition != "--Current--":
tmp = ' , "with-transition": {"name": "' + transition + '"}'
action = jsonArchive["TransitionToProgram"] % tmp
else:
action = jsonArchive["TransitionToProgram"] % ""
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetCurrentTransition": #fertig
updateTransitionList()
transition = printArraySelect(transitionList)
action = jsonArchive["SetCurrentTransition"] % transition
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StartStopStreaming": #fertig
action = jsonArchive["StartStopStreaming"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StartStreaming": #fertig
action = jsonArchive["StartStreaming"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StopStreaming": #fertig
action = jsonArchive["StopStreaming"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StartStopRecording": #fertig
action = jsonArchive["StartStopRecording"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StartRecording": #fertig
action = jsonArchive["StartRecording"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StopRecording": #fertig
action = jsonArchive["StopRecording"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StartStopReplayBuffer": #fertig
action = jsonArchive["StartStopReplayBuffer"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StartReplayBuffer": #fertig
action = jsonArchive["StartReplayBuffer"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "StopReplayBuffer": #fertig
action = jsonArchive["StopReplayBuffer"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SaveReplayBuffer": #fertig
action = jsonArchive["SaveReplayBuffer"]
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetSourceVisibility": #fertig
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
source = printArraySelect(tempSceneList)
renderArray = ["0 (Invisible)", "1 (Visible)"]
render = printArraySelect(renderArray)
if render == "0 (Invisible)":
render = "false"
else:
render = "true"
sceneListShort.append("--Current--")
scene = printArraySelect(sceneListShort)
if scene != "--Current--":
source = source + '", "scene": "' + scene
action = jsonArchive["SetSourceVisibility"] % (source, str(render))
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "ToggleSourceVisibility": #fertig
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
source = printArraySelect(tempSceneList)
sceneListShort.append("--Current--")
scene = printArraySelect(sceneListShort)
if scene != "--Current--":
source = source + '", "scene": "' + scene
action = jsonArchive["ToggleSourceVisibility"] % (source, "%s")
saveTODOButtonToFile(msgType, NoC, "button" , action, "ToggleSourceVisibility", "x")
elif action == "ToggleMute": #fertig
updateSceneList()
updateSpecialSources()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
for item in specialSourcesList:
tempSceneList.append(item)
source = printArraySelect(tempSceneList)
action = jsonArchive["ToggleMute"] % source
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetMute": #fertig
updateSceneList()
updateSpecialSources()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
for item in specialSourcesList:
tempSceneList.append(item)
source = printArraySelect(tempSceneList)
tempArray = ["0 (Muted)", "1 (Unmuted)"]
muted = printArraySelect(tempArray)
if muted == "0 (Muted)":
muted = "false"
else:
muted = "true"
action = jsonArchive["SetMute"] % (source, muted)
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetTransitionDuration": #fertig
time = int(input("Input the desired time(in milliseconds): "))
action = jsonArchive["SetTransitionDuration"] % time
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetCurrentProfile": #fertig
updateProfileList()
profilename = printArraySelect(profilesList)
action = jsonArchive["SetCurrentProfile"] % profilename
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetRecordingFolder": #fertig
recpath = str(input("Input the desired path: "))
action = jsonArchive["SetRecordingFolder"] % recpath
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetCurrentSceneCollection": #fertig
updatesceneCollectionList()
scenecollection = printArraySelect(sceneCollectionList)
print(scenecollection)
action = jsonArchive["SetCurrentSceneCollection"] % scenecollection
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "ResetSceneItem": #fertig
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList:
tempSceneList.append(line["name"])
source = printArraySelect(tempSceneList)
sceneListShort.append("--Current--")
scene = printArraySelect(sceneListShort)
if scene != "--Current--":
render = '"' + str(source) + '", "scene-name": "' + scene + '"'
else:
render = '"' + str(source) + '"'
action = jsonArchive["ResetSceneItem"] % (render)
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetTextGDIPlusText":
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList and line["type"] == "text_gdiplus":
tempSceneList.append(line["name"])
source = printArraySelect(tempSceneList)
text = str(input("Input the desired text: "))
action = jsonArchive["SetTextGDIPlusText"] % (source, text)
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "SetBrowserSourceURL":
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList and line["type"] == "browser_source":
tempSceneList.append(line["name"])
source = printArraySelect(tempSceneList)
url = str(input("Input the desired URL: "))
action = jsonArchive["SetBrowserSourceURL"] % (source, url)
saveButtonToFile(msgType, NoC, "button" , action)
elif action == "ReloadBrowserSource":
updateSceneList()
tempSceneList = []
for scene in sceneListLong:
for line in scene["sources"]:
if line["name"] not in tempSceneList and line["type"] == "browser_source":
tempSceneList.append(line["name"])
source = printArraySelect(tempSceneList)
action = jsonArchive["ReloadBrowserSource"] % (source, "%s")
saveTODOButtonToFile(msgType, NoC, "button" , action, "ReloadBrowserSource", source)
def saveFaderToFile(msg_type, msgNoC, input_type, action, scale, cmd):
print("Saved %s with control %s for action %s" % (msg_type, msgNoC, cmd))
Search = Query()
result = db.search((Search.msg_type == msg_type) & (Search.msgNoC == msgNoC))
if result:
db.remove(Search.msgNoC == msgNoC)
db.insert({"msg_type": msg_type, "msgNoC": msgNoC, "input_type": input_type, "scale_low": scale[0], "scale_high": scale[1], "action": action, "cmd": cmd})
else:
db.insert({"msg_type": msg_type, "msgNoC": msgNoC, "input_type": input_type, "scale_low": scale[0], "scale_high": scale[1], "action": action, "cmd": cmd})
def saveButtonToFile(msg_type, msgNoC, input_type, action):
print("Saved %s with note/control %s for action %s" % (msg_type, msgNoC, action))
Search = Query()
result = db.search((Search.msg_type == msg_type) & (Search.msgNoC == msgNoC))
if result:
db.remove(Search.msgNoC == msgNoC)
db.insert({"msg_type": msg_type, "msgNoC": msgNoC, "input_type": input_type, "action" : action})
else:
db.insert({"msg_type": msg_type, "msgNoC": msgNoC, "input_type": input_type, "action" : action})
def saveTODOButtonToFile(msg_type, msgNoC, input_type, action, request, target):
print("Saved %s with note/control %s for action %s" % (msg_type, msgNoC, action))
Search = Query()
result = db.search((Search.msg_type == msg_type) & (Search.msgNoC == msgNoC))
if result:
db.remove(Search.msgNoC == msgNoC)
db.insert({"msg_type": msg_type, "msgNoC": msgNoC, "input_type": input_type, "action" : action, "request": request, "target": target})
else:
db.insert({"msg_type": msg_type, "msgNoC": msgNoC, "input_type": input_type, "action" : action, "request": request, "target": target})
def printArraySelect(array):
counter = 0
for line in array:
print("%s: %s" % (counter, line))
counter += 1
return array[int(input("Select 0-%s: " % str(len(array)-1)))]
def askForInputScaling():
print("Setup input scale")
low = int(input("Select lower output value: "))
high = int(input("Select higher output value: "))
return low, high
def updateTransitionList():
global transitionList
ws = create_connection("ws://" + serverIP + ":" + serverPort)
print("Updating transition list, plase wait")
ws.send("""{"request-type": "GetTransitionList", "message-id": "999999"}""")
result = ws.recv()
jsn = json.loads(result)
transitionList = []
if jsn["message-id"] == "999999":
for item in jsn["transitions"]:
transitionList.append(item["name"])
print("Transitions updated")
else:
print("Failed to update")
ws.close()
def updateSceneList():
global sceneListShort
global sceneListLong
ws = create_connection("ws://" + serverIP + ":" + serverPort)
print("Updating scene list, plase wait")
ws.send("""{"request-type": "GetSceneList", "message-id": "9999999"}""")
result = ws.recv()
jsn = json.loads(result)
sceneListShort = []
sceneListLong = []
if jsn["message-id"] == "9999999":
sceneListLong = jsn["scenes"]
for item in jsn["scenes"]:
sceneListShort.append(item["name"])
print("Scenes updatet")
else:
print("Failed to update")
ws.close()
def updateSpecialSources():
global specialSourcesList
ws = create_connection("ws://" + serverIP + ":" + serverPort)
print("Updating special sources, plase wait")
ws.send("""{"request-type": "GetSpecialSources", "message-id": "99999999"}""")
result = ws.recv()
jsn = json.loads(result)
specialSourcesList = []
if jsn["message-id"] == "99999999":
for line in jsn:
if line == "status" or line == "message-id":
x=1
else:
specialSourcesList.append(jsn[line])
print("Special sources updatet")
else:
print("Failed to update")
ws.close()
def updateProfileList():
global profilesList
ws = create_connection("ws://" + serverIP + ":" + serverPort)
print("Updating Profiles List, plase wait")
ws.send("""{"request-type": "ListProfiles", "message-id": "99999999"}""")
result = ws.recv()
jsn = json.loads(result)
profilesList = []
if jsn["message-id"] == "99999999":
for line in jsn["profiles"]:
profilesList.append(line["profile-name"])
print("Profiles List updatet")
else:
print("Failed to update")
ws.close()
def updatesceneCollectionList():
global sceneCollectionList
ws = create_connection("ws://" + serverIP + ":" + serverPort)
print("Updating Scene Collection List, plase wait")
ws.send("""{"request-type": "ListSceneCollections", "message-id": "99999999"}""")
result = ws.recv()
jsn = json.loads(result)
sceneCollectionList = []
if jsn["message-id"] == "99999999":
for line in jsn["scene-collections"]:
sceneCollectionList.append(line["sc-name"])
print("Scene Collection List updatet")
else:
print("Failed to update")
ws.close()
def mainLoop():
global ignore
global savetime1
while True:
try:
msg = midiport.receive()
if msg:
if msg.type == "note_on":
if msg.note != ignore:
midicallback(msg)
savetime1 = time.time()
if msg.type == "program_change":
if msg.program != ignore:
midicallback(msg)
savetime1 = time.time()
if msg.type == "control_change":
if msg.control != ignore:
midicallback(msg)
savetime1 = time.time()
if time.time() - savetime1 > 3:
savetime1 = time.time()
ignore = 255
except KeyboardInterrupt:
print("Exiting")
sys.exit()
break
if __name__ == "__main__":
print("MIDItoOBS made by lebaston100.de")
print("!!MAKE SURE OBS IS RUNNING OR THIS SCRIPT WILL CRASH!!")
print("Select Midi Device")
deviceList = mido.get_input_names()
counter = 0
for device in deviceList:
print("%s: %s" % (counter, device))
counter += 1
input_select = int(input("Select 0-%s: " % str(len(deviceList)-1)))
if input_select in range(0, len(deviceList)):
print("You selected: %s (%s)" % (str(input_select), deviceList[input_select]))
result = db.search(Query().value == deviceList[input_select])
if result:
db.remove(Query().type == "device")
db.insert({"type" : "device", "value": deviceList[input_select]})
else:
db.insert({"type" : "device", "value": deviceList[input_select]})
try:
midiport = mido.open_input(deviceList[input_select])
except:
print("The midi device might be used by another application.")
print("Please close the device in the other application and restart this script.")
time.sleep(8)
sys.exit()
atexit.register(exitScript)
print("Please press key or move fader/knob on midi controller")
mainLoop()
else:
print("Please select a valid device and restart the script")
sys.exit()