This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
eventprocessor.py
294 lines (210 loc) · 8.55 KB
/
eventprocessor.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
"""
eventprocessor.py
This file processes events and lighting redraws.
Author: Miguel Guthridge [hdsq@outlook.com.au]
"""
import time
import device
import ui
import utils
import eventconsts
import internal
import internal.consts
import config
import lighting
import lightingconsts
import otherprocessors.processdefault as processdefault
import otherprocessors.processfirst as processfirst
import otherprocessors.processfirst_basic as processfirst_basic
import windowprocessors
import pluginprocessors
import noteprocessors
import controllerprocessors
"""
num_sys_safe = 0
num_sys = 0
num_ct = 0
"""
def processExtended(command):
"""Processes event: used in extended Script
Args:
command (ParsedEvent): a parsed MIDI event
"""
try:
# Process internal commands
if command.recieved_internal:
processReceived(command)
return
# Reset idle timer
if not ((command.type is eventconsts.TYPE_BASIC_PAD or command.type is eventconsts.TYPE_PAD or command.type is eventconsts.TYPE_TRANSPORT) and not command.is_lift):
if lighting.idleLightshowActive():
command.handle("End Idle Light Show", True)
internal.window.resetIdleTick()
# Process key mappings
controllerprocessors.process(command)
# Process shifts
internal.shifts.processShift(command)
if command.ignored: return
# Call primary processor
processfirst.process(command)
if command.ignored: return
# Process through shift processors
internal.shifts.process(command)
if command.ignored: return
# Note Processors
noteprocessors.process(command)
if command.ignored: return
# Only call plugin and window processors if it is safe to do so | Disabled because of errors
if command.pme_system_safe or True:
# Shouldn't be called in extended mode
# Attempt to process event using custom processors for plugins
pluginprocessors.process(command)
#if command.ignored: return
# Process content from windows
windowprocessors.process(command)
# If command hasn't been handled by any above uses, use the default controls
if command.handled is False:
processdefault.process(command)
except Exception as e:
internal.errors.triggerError(e)
def processBasic(command):
"""Processes ParsedEvents in basic mode script
Args:
command (ParsedEvent): a parsed MIDI event
"""
# Send event to reset other controller
internal.sendCompleteInternalMidiMessage(internal.consts.MESSAGE_RESET_INTERNAL_CONTROLLER)
try:
if command.recieved_internal:
processReceived(command)
return
# Process key mappings
controllerprocessors.process(command)
# Call primary processor
processfirst_basic.process(command)
if command.ignored: return
# Process through shift processors
internal.shifts.process(command)
if command.ignored: return
# Send to note processors
noteprocessors.process(command)
if command.type == eventconsts.TYPE_PAD:
command.handle("Post-note-processor pad catch", True)
if command.ignored: return
# For note events quit now
if command.type == eventconsts.TYPE_NOTE:
return
# Only call plugin and window processors if it is safe to do so | Currently disabled due to errors
if command.pme_system_safe or True:
# Attempt to process event using custom processors for plugins
pluginprocessors.process(command)
if command.ignored: return
except Exception as e:
internal.errors.triggerError(e)
def processReceived(command):
"""Processes events recieved internally (from other script)
Args:
command (ParsedEvent): A parsed MIDI event
"""
command.actions.addProcessor("Internal event processor")
data = command.getDataMIDI()
if data == internal.consts.MESSAGE_IDLE_NOTIFICATION:
internal.idleProcessor()
if internal.shifts["MAIN"].query():
internal.state.idleShift()
command.handle("Receive idle tick", True)
elif data == internal.consts.MESSAGE_RESET_INTERNAL_CONTROLLER:
internal.window.resetIdleTick()
command.handle("Reset idle tick", True)
elif data == internal.consts.MESSAGE_ERROR_CRASH:
internal.errors.triggerErrorFromOtherScript()
command.handle("Trigger error state")
elif data == internal.consts.MESSAGE_ERROR_RECOVER:
internal.errors.recoverError(False, True)
command.handle("Recover from error state")
elif data == internal.consts.MESSAGE_ERROR_RECOVER_DEBUG:
internal.errors.recoverError(True, True)
command.handle("Recover from error state, enable debugging")
elif data == internal.consts.MESSAGE_SHIFT_DOWN:
internal.shifts.setDown("MAIN", True)
command.handle("Press shift", True)
elif data == internal.consts.MESSAGE_SHIFT_UP:
internal.shifts.setDown("MAIN", False)
command.handle("Release shift", True)
elif data == internal.consts.MESSAGE_SHIFT_USE:
internal.shifts["MAIN"].use()
command.handle("Use shift", True)
elif command.id == internal.consts.MESSAGE_INPUT_MODE_SELECT:
noteprocessors.setModeByIndex(command.value)
command.handle("Set note state", True)
elif data == internal.consts.MESSAGE_RESTART_DEVICE:
internal.state.restartDevice()
command.handle("Restart device", True)
elif data == internal.consts.MESSAGE_ENTER_DEBUG_MODE:
internal.state.enterDebugMode()
command.handle("Enter debug mode", True)
# Called after a window is activated
def activeStart():
"""Activates a new window or plugin
"""
# Only in extended mode:
if internal.state.PORT == config.DEVICE_PORT_EXTENDED:
if internal.window.plugin_focused:
pluginprocessors.activeStart()
else:
windowprocessors.activeStart()
def activeEnd():
"""Deactivates an old window or plugin
"""
# Only in extended mode:
if internal.state.PORT == config.DEVICE_PORT_EXTENDED:
if internal.window.plugin_focused:
pluginprocessors.activeEnd()
else:
windowprocessors.activeEnd()
def redraw():
"""Creates LightMap object and forwards it to various redraw functions to gather data about next lighting redraw.
"""
lights = lighting.LightMap()
if internal.errors.getError():
internal.errors.redrawError(lights)
lighting.state.setFromMap(lights)
return
for _ in range(1):
# Error handling: set controller into an error state
try:
# Draw initialisation lightshow
if internal.window.getAbsoluteTick() < len(lightingconsts.PALLETE_NORMAL) + 8:
lighting.initLightShow(lights)
elif internal.window.getAbsoluteTick() == len(lightingconsts.PALLETE_NORMAL) + 8:
internal.window.resetAnimationTick()
# Draws idle thing if idle
lighting.idleLightshow(lights)
# Straight to drawing function if lightMap is solidified
if lights.isSolid(): break
# Redraw shift menus
internal.shifts.redraw(lights)
if lights.isSolid(): break
# Get UI from primary processor
processfirst.redraw(lights)
noteprocessors.redraw(lights)
if lights.isSolid(): break
if not internal.extendedMode.query(eventconsts.INCONTROL_PADS):
# Get UI drawn from plugins
pluginprocessors.redraw(lights)
else:
# Get UI drawn from windows
windowprocessors.redraw(lights)
if lights.isSolid(): break
if lights.isSolid(): break
except Exception as e:
internal.errors.triggerError(e)
# Get UI drawn from default processor
processdefault.redraw(lights)
# Call pads refresh function
lighting.state.setFromMap(lights)
def beatChange(beat):
pluginprocessors.beatChange(beat)
windowprocessors.beatChange(beat)
noteprocessors.beatChange(beat)
internal.beat.setBeat(beat)