-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtemController.py
266 lines (204 loc) · 7.68 KB
/
AtemController.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
import PyATEMMax
from pynput.keyboard import Key, Listener, KeyCode
from pynput import keyboard
import win32gui, win32process, os
import sys, time, threading
from colored import fg
PVW_color = fg('green_1')
PGM_color = fg('red_1')
sColor = fg('white')
cmd = 'mode 18,7'
os.system(cmd)
atemMini = PyATEMMax.ATEMMax()
atem4K = PyATEMMax.ATEMMax()
import tkinter as tk
from tkinter import messagebox
def exit_application():
msg_box = tk.messagebox.askquestion('Exit', 'Are you sure you want to exit?',
icon='question')
if msg_box == 'yes':
atem4K.disconnect()
atemMini.disconnect()
os.system("cls")
print("Disconnected")
exit()
quit()
return False # stop listener
# else:
# tk.messagebox.showinfo('Return', 'You will now return to the application screen')
def restart_application():
msg_box = tk.messagebox.askquestion('Restart', 'Are you sure you want to restart the application?',
icon='question')
if msg_box == 'yes':
atem4K.disconnect()
atemMini.disconnect()
os.startfile(__file__)
quit()
# os.execl(sys.executable, '"{}"'.format(sys.executable), *sys.argv)
# else:
# atem4K.disconnect()
# atemMini.disconnect()
# os.system("cls")
# print("Disconnected")
# exit()
# quit()
# return False # stop listener
def connectionFailed(key):
try:
k = key.char # single-char keys
except:
k = key.name # other keys
if k == 'r': # restart_application
restart_application()
# os.execl(sys.executable, '"{}"'.format(sys.executable), *sys.argv)
if key == keyboard.Key.esc:
exit_application()
def connectToAtem():
i = 0
while not atem4K.connected and not atemMini.connected and i < 1:
atemMini.connect("192.168.1.223")
atemMini.waitForConnection(infinite=False)
atem4K.connect("192.168.1.221")
atem4K.waitForConnection(infinite=False)
i += 1
def loadingAnimation(process):
while process.is_alive():
chars = ['', '.', '..', '...', ' ']
for char in chars:
sys.stdout.write('\r' + 'Connecting' + char)
time.sleep(.2)
sys.stdout.flush()
loading_process = threading.Thread(target=connectToAtem)
loading_process.start()
loadingAnimation(loading_process)
loading_process.join()
pressed = False
mode = "Dicséret"
sugo = "OpenLP" # OpenLP / M/E 1 PGM
def consoleText():
os.system('cls')
print(f"SÚGÓ: {sugo}")
print(f"MODE: {mode}\n")
print(PVW_color, end="")
print(f"PVW: ", end="")
print(sColor, end="")
print(f"{PVW}")
print(PGM_color, end="")
print(f"PGM: ", end="")
print(sColor, end="")
print(f"{PGM}")
def on_press(key):
global mode
global sugo
global pressed
global PVW
global PGM
focus_window_pid = win32process.GetWindowThreadProcessId(win32gui.GetForegroundWindow())[1]
current_process_pid = os.getppid()
if focus_window_pid == current_process_pid:
if key == keyboard.Key.esc:
exit_application()
# atem4K.disconnect()
# atemMini.disconnect()
# os.system("cls")
# print("Disconnected")
# return False # stop listener
try:
k = key.char # single-char keys
except:
k = key.name # other keys
if k in ['1', '2', '3', '4'] and k != PVW and k != PGM and pressed == False: # keys of interest #ATEM4k
# self.keys.append(k) # store it in global-like variable
pressed = True
kInt = int(k)
# print(type(kInt))
atem4K.setPreviewInputVideoSource(1, kInt) # set PVW on Atem4K M/E 2
#PVW = k
PVW = atem4K.previewInput[1].videoSource.value # k
consoleText()
if k in ['5', '6', '7', '8'] and k != PVW and k != PGM and mode == "Dicséret" and pressed == False: # ATEMmini
pressed = True
kInt = int(k) - 4
atemMini.setProgramInputVideoSource(0, kInt) # set PGM on AtemMini M/E 1
atem4K.setPreviewInputVideoSource(1, 5) # set PVW on Atem4K M/E 2
# PVW = k
PVW = atemMini.previewInput[1].videoSource.value + 4 # k
consoleText()
while key == keyboard.Key.space and pressed == False: ## and PVW != "-1" and PVW != "0": #CUT
atem4K.execCutME(1) # Cut on Atem4K M/E 2
# temp = PGM
# PGM = PVW
# PVW = temp
PGM = atem4K.programInput[1].videoSource.value
PVW = atem4K.previewInput[1].videoSource.value
consoleText()
print("CUT")
pressed = True
while key == keyboard.Key.enter and pressed == False: ## and PVW != "0" and PVW != "-1": #FADE
atem4K.execAutoME(1)
# temp = PGM
# PGM = PVW
# PVW = temp
PGM = atem4K.programInput[1].videoSource.value
PVW = atem4K.previewInput[1].videoSource.value # "-1" #temp
consoleText()
print("FADE")
pressed = True
# Mode selector
if k == 'm' and pressed == False: # key == Key.page_up and pressed == False:
if mode == "Dicséret":
mode = "Prédikáció"
else:
mode = "Dicséret"
consoleText()
pressed = True
# Súgó
if key == Key.home and pressed == False: # k == "s" and pressed == False:
if sugo == "OpenLP": # and mode == "Prédikáció":
sugo = "M/E 1 PGM"
atem4K.setAuxSourceInput(2, "mE1Prog")
elif sugo == "M/E 1 PGM":
sugo = "OpenLP"
atem4K.setAuxSourceInput(2, "mE3Prog")
consoleText()
pressed = True
if k == 'r': # restart_application
restart_application()
# Fölösleges#
# if key == Key.page_up: #Preaching mode
# mode = "Preaching"
# os.system('cls')
# print(f"PVW: {PVW}")
# print(f"PGM: {PGM}")
# print(f"MODE: {mode}")
PVW = atem4K.previewInput[1].videoSource.value # "-1"
PGM = atem4K.programInput[1].videoSource.value # "0"
def on_release(key): # The function that's called when a key is released
global pressed
pressed = False
if not atem4K.connected and not atemMini.connected:
consoleText()
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
else:
os.system('cls')
print("Connection Failed")
import ctypes # An included library with Python install.
# atem4K.disconnect()
# atemMini.disconnect()
# ctypes.windll.user32.MessageBoxW(0, "Failed to connect to Atem", "ERROR", 5)
with Listener(on_press=connectionFailed, on_release=on_release) as listener:
listener.join()
# failedConnectRetry()
# Original
# print(f"MODE: {mode}\n")
# print(f"PVW: {PVW}")
# print(f"PGM: {PGM}")
# listener = keyboard.Listener(on_press=on_press)
# listener.start() # start to listen on a separate thread
# listener.join() # remove if main thread is polling self.keys
# Collect events until released
# with Listener(on_press=on_press) as listener:listener.join()
# 1 2 3 4 5 6 7 8 Keys
# 1 2 3 4 5 5 5 5 Atem4K PVW
# x x x x 1 2 3 4 AtemMini PGM