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
/
processorhelpers.py
1235 lines (959 loc) · 38.4 KB
/
processorhelpers.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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
processorhelpers.py
This script includes objects useful for event processors.
It is worth investigating potential applications of these functions when writing your processors,
or adding other frequently-required functions here.
Author: Miguel Guthridge [hdsq@outlook.com.au]
"""
import time
import utils
import ui
import plugins
import config
import eventconsts
import internal
import internal.consts
import lightingconsts
class UIMode:
def __init__(self, name, colour, process_function, redraw_function):
self.name = name
self.colour = colour
self.process_function = process_function
self.redraw_function = redraw_function
def process(self, command):
self.process_function(command)
def redraw(self, lights):
self.redraw_function(lights)
class UiModeHandler:
"""This object is used to manage menu layers, which can be toggled and switched through.
It is best used in handler scripts to allow for a plugin or window to have multiple menus.
"""
def __init__(self):
"""Create instance of UIModeHandler.
Args:
num_modes (int): The number of different menus to be contained in the object
"""
self.is_down = False
self.used = False
self.modes = []
self.current_mode = 0
# Switch to next mode
def nextMode(self):
"""Jump to the next menu layer
Returns:
int: mode number
"""
self.current_mode += 1
if self.current_mode == len(self.modes):
self.current_mode = 0
return self.current_mode
def prevMode(self):
"""Jump to previous menu layer
Returns:
int: mode number
"""
self.current_mode -= 1
if self.current_mode == -1:
self.current_mode = len(self.modes) - 1
return self.current_mode
def resetMode(self):
"""Resets menu layer to zero
"""
self.current_mode = 0
# Get current mode number
def getMode(self):
"""Returns mode number
Returns:
int: mode number
"""
return self.current_mode
def press(self):
self.is_down = True
self.used = False
def lift(self):
self.is_down = False
if not self.used:
self.nextMode()
def redraw(self, lights):
lights.setPadColour(8, 0, self.modes[self.current_mode].colour)
self.modes[self.current_mode].redraw(lights)
def process(self, command):
# For mode toggle
if (command.type is eventconsts.TYPE_BASIC_PAD or command.type is eventconsts.TYPE_PAD) and command.coord_Y == 0 and command.coord_X == 8:
if command.is_lift:
self.lift()
command.handle("Lift UI mode button")
internal.window.resetAnimationTick()
else:
self.press()
command.handle("Press UI mode button")
self.modes[self.current_mode].process(command)
def addMode(self, name, colour, process_function, redraw_function):
self.modes.append(UIMode(name, colour, process_function, redraw_function))
class UiModeSelector:
"""This object is used to manage menu layers, which can be toggled and switched through.
Unlike UiModeHandler, it doesn't handle calling functions for processing
It is best used in handler scripts to allow for a plugin or window to have multiple menus.
"""
def __init__(self, num_modes):
"""Create instance of UIModeHandler.
Args:
num_modes (int): The number of different menus to be contained in the object
"""
self.is_down = False
self.used = False
self.mode = 0
self.num_modes = num_modes
# Switch to next mode
def nextMode(self):
"""Jump to the next menu layer
Returns:
int: mode number
"""
self.mode += 1
if self.mode == self.num_modes:
self.mode = 0
return self.mode
def prevMode(self):
"""Jump to previous menu layer
Returns:
int: mode number
"""
self.mode -= 1
if self.mode == -1:
self.mode = self.num_modes - 1
return self.mode
def resetMode(self):
"""Resets menu layer to zero
"""
self.mode = 0
# Get current mode number
def getMode(self):
"""Returns mode number
Returns:
int: mode number
"""
return self.mode
def press(self):
self.is_down = True
self.used = False
def lift(self):
self.is_down = False
if not self.used:
self.nextMode()
def redraw(self, lights):
pass
def process(self, command):
pass
def snap(value, snapTo):
"""Returns a snapped value
Args:
value (float): value being snapped
snapTo (float or list of floats): value(s) to snap to
Returns:
float: value after snapping
"""
if not config.ENABLE_SNAPPING:
return value
# Change to list
if type(snapTo) is float or type(snapTo) is int:
snapTo = [snapTo]
for i in range(len(snapTo)):
if abs(value - snapTo[i]) <= config.SNAP_RANGE:
return snapTo[i]
else: return value
def didSnap(value, snapTo):
"""Returns a boolean indicating whether a value was snapped
Args:
value (float): value being snapped
snapTo (float or list of floats): value(s) to snap to
Returns:
bool: whether the value would snap
"""
return abs(value - snapTo) <= config.SNAP_RANGE and config.ENABLE_SNAPPING
def toFloat(value, min = 0, max = 1):
"""Converts a MIDI event value (data2) to a float to set parameter values.
Args:
value (int): MIDI event value (0-127)
min (float, optional): lower value to set between. Defaults to 0.
max (float, optional): upper value to set between. Defaults to 1.
Returns:
float: range value
"""
return (value / 127) * (max - min) + min
class ExtensibleNote():
"""A note with other notes tacked on. Used for playing chords in note processors.
"""
def __init__(self, root_note, extended_notes):
"""Create instance of ExtensibleNote object
Args:
root_note (note event): the note that the user pressed (or a modified version of it).
Can be of type RawEvent, ParsedEvent or FLMidiMessage.
extended_notes (list of note events): List of notes that should also be pressed. Can be of
same types as root_note, but RawEvent is recommended for performance reasons.
"""
self.root = root_note
self.extended_notes = extended_notes
def convertPadMapping(padNumber):
"""Converts between basic mode pad mapping and extended mode mapping
Args:
padNumber (int): note number for extended pad
Returns:
int: note number for basic pad
"""
for y in range(len(eventconsts.Pads)):
for x in range(len(eventconsts.Pads[y])):
if padNumber == eventconsts.Pads[y][x]:
return eventconsts.BasicPads[y][x]
lastPressID = -1
lastPressTime = -1
def isDoubleClickPress(id_val):
"""Returns whether a press event was a double click
Args:
id_val (int): Event ID
Returns:
bool: whether the event was a double click
"""
global lastPressID
global lastPressTime
ret = False
currentTime = time.perf_counter()
if id_val == lastPressID and (currentTime - lastPressTime < config.DOUBLE_PRESS_TIME):
ret = True
lastPressID = id_val
lastPressTime = currentTime
return ret
lastLiftID = -1
lastLiftTime = -1
def isDoubleClickLift(id_val):
"""Returns whether a lift event was a double click
Args:
id_val (int): Event ID
Returns:
bool: whether the event was a double click
"""
global lastLiftID
global lastLiftTime
ret = False
currentTime = time.perf_counter()
if id_val == lastLiftID and (currentTime - lastLiftTime < config.DOUBLE_PRESS_TIME):
ret = True
lastLiftID = id_val
lastLiftTime = currentTime
return ret
def isLongPressLift(id_val):
"""Returns whether a lift event was held down for a long time
Args:
id_val (int): Event ID
Returns:
bool: whether the event was a long press
"""
global lastPressID, lastPressTime
currentTime = time.perf_counter()
return (id_val == lastPressID) and (currentTime - lastPressTime >= config.LONG_PRESS_TIME)
class Action:
"""Stores an action as a string
"""
def __init__(self, act, silent):
"""Create an event action
Args:
act (str): The action taken
silent (bool): Whether the action should be set as a hint message
"""
self.act = act
self.silent = silent
class ActionList:
"""Stores a list of actions taken by a single processor
"""
def __init__(self, name):
"""Create an action list
Args:
name (str): Name of the processor
"""
self.name = name
self.list = []
self.handle_type = False
def appendAction(self, action, silent, handle):
"""Append action to list of actions
Args:
action (str): The action taken
silent (bool): Whether the action should be set as a hint message
handle (int): How this action handled the event (using internal.consts.EVENT_<handle type>)
"""
self.list.append(Action(action, silent))
# Set flag indicating that this processor handled the event
self.handle_type = handle
def getString(self):
"""Returns a string of the actions taken
Returns:
str: actions taken
"""
# Return that no action was taken if list is empty
if len(self.list) == 0:
return internal.getTab(self.name + ":", 2) + "[No actions]"
# No indentation required if there was only one action
elif len(self.list) == 1:
ret = internal.getTab(self.name + ":", 2) + self.list[0].act
# If there are multiple actions, indent them
else:
ret = self.name + ":"
for i in range(len(self.list)):
ret += '\n' + internal.getTab("") + self.list[i].act
if self.handle_type == internal.consts.EVENT_HANDLE:
ret += '\n' + internal.getTab("") + "[Handled]"
elif self.handle_type == internal.consts.EVENT_IGNORE:
ret += '\n' + internal.getTab("") + "[Ignored]"
return ret
# Returns the latest non-silent action to set as the hint message
def getHintMsg(self):
"""Returns string of hint message to set, empty string if none
Returns:
str: Hint message
"""
ret = ""
for i in range(len(self.list)):
if self.list[i].silent == False:
ret = self.list[i].act
return ret
class ActionPrinter:
"""Object containing actions taken by all processor modules
"""
def __init__(self):
# String that is output after each event is processed
self.eventProcessors = []
def addProcessor(self, name):
"""Add an event processor
Args:
name (str): Name of the processor
"""
self.eventProcessors.append(ActionList(name))
def appendAction(self, act, silent=False, handle_type=internal.consts.EVENT_NO_HANDLE):
"""Appends an action to the current event processor
Args:
act (str): The action taken
silent (bool, optional): Whether the action should be set as a hint message. Defaults to False.
handled (int, optional): How the action handled/ignored the event. Defaults to internal.consts.EVENT_NO_HANDLE.
"""
# Add some random processor if a processor doesn't exist for some reason
if len(self.eventProcessors) == 0:
self.addProcessor("NoProcessor")
internal.debugLog("Added NoProcessor Processor", internal.consts.DEBUG.WARNING_DEPRECIATED_FEATURE)
# Append the action
self.eventProcessors[len(self.eventProcessors) - 1].appendAction(act, silent, handle_type)
def flush(self):
"""Log all actions taken, and set a hint message if applicable
"""
# Log all actions taken
for x in range(len(self.eventProcessors)):
internal.debugLog(self.eventProcessors[x].getString(), internal.consts.DEBUG.EVENT_ACTIONS)
# Get hint message to set (ignores silent messages)
hint_msg = ""
for x in range(len(self.eventProcessors)):
cur_msg = self.eventProcessors[x].getHintMsg()
# Might want to fix this some time, some handler modules append this manually
if cur_msg != "" and cur_msg != "[Did not handle]":
hint_msg = cur_msg
if hint_msg != "":
# Sometimes this fails...
try:
ui.setHintMsg(hint_msg)
except:
pass
self.eventProcessors.clear()
class RawEvent:
"""Stores event in raw form. A quick way to generate events for editing.
"""
def __init__(self, status, data1, data2):
"""Create a RawEvent object
Args:
status (int): Status byte
data1 (int): First data byte
data2 (int): 2nd data byte
"""
self.status = status
self.data1 = data1
self.data2 = data2
class ParsedEvent:
"""Stores data about an event, including useful parsed data
"""
def __init__(self, event):
"""Create ParsedEvent from event object
Args:
event (MIDI Event): FL Studio MIDI Event
"""
self.recieved_internal = False
self.edited = False
self.actions = ActionPrinter()
self.handled = False
self.ignored = False
self.status = event.status
self.note = event.data1
self.data1 = event.data1
self.value = event.data2
self.data2 = event.data2
self.status_nibble = event.status >> 4 # Get first half of status byte
self.channel = event.status & int('00001111', 2) # Get 2nd half of status byte
if self.channel == internal.consts.INTERNAL_CHANNEL_STATUS:
self.recieved_internal = True
# PME Flags to make sure errors don't happen or something
self.processPmeFlags(event.pmeFlags)
# Add sysex information
self.sysex = event.sysex
# Bit-shift status and data bytes to get event ID
self.id = (self.status + (self.note << 8))
self.parse()
# Process sysex events
if self.type is eventconsts.TYPE_SYSEX_EVENT:
internal.processSysEx(self)
def parse(self):
"""Parses information about the event
"""
# Indicates whether to consider as a value or as an on/off
self.isBinary = False
# Determine type of event | unrecognised by default
self.type = eventconsts.TYPE_UNRECOGNISED
# If using basic port, check for notes
if self.status == eventconsts.SYSEX:
self.type = eventconsts.TYPE_SYSEX_EVENT
elif self.id in eventconsts.InControlButtons:
self.type = eventconsts.TYPE_INCONTROL
self.isBinary = True
elif self.id in eventconsts.SystemMessages:
self.type = eventconsts.TYPE_SYSTEM_MSG
self.isBinary = True
elif self.id in eventconsts.TransportControls:
self.type = eventconsts.TYPE_TRANSPORT
self.isBinary = True
elif self.id in eventconsts.Knobs:
self.type = eventconsts.TYPE_KNOB
self.coord_X = self.note - 0x15
elif self.id in eventconsts.BasicKnobs:
self.type = eventconsts.TYPE_BASIC_KNOB
self.coord_X = self.note - 0x15
elif self.id in eventconsts.Faders:
self.type = eventconsts.TYPE_FADER
self.coord_X = self.note - 0x29
if self.note == 0x07: self.coord_X = 8
elif self.id in eventconsts.BasicFaders:
self.type = eventconsts.TYPE_BASIC_FADER
self.coord_X = self.note - 0x29
if self.note == 0x07: self.coord_X = 8
elif self.id in eventconsts.FaderButtons:
self.type = eventconsts.TYPE_FADER_BUTTON
self.coord_X = self.note - 0x33
self.isBinary = True
elif self.id in eventconsts.BasicFaderButtons:
self.type = eventconsts.TYPE_BASIC_FADER_BUTTON
self.coord_X = self.note - 0x33
self.isBinary = True
elif self.id in eventconsts.BasicEvents:
self.type = eventconsts.TYPE_BASIC_EVENT
if self.id == eventconsts.PEDAL:
self.isBinary = True
elif self.status_nibble == eventconsts.NOTE_ON or self.status_nibble == eventconsts.NOTE_OFF:
# Pads are actually note events
if (self.status == 0x9F or self.status == 0x8F) or ((self.status == 0x99 or self.status == 0x89)):
x, y = self.getPadCoord()
if x != -1 and y != -1:
# Is a pad
self.coord_X = x
self.coord_Y = y
self.isBinary = True
if self.isPadExtendedMode():
self.type = eventconsts.TYPE_PAD
else:
self.type = eventconsts.TYPE_BASIC_PAD
else:
self.type = eventconsts.TYPE_NOTE
self.isBinary = True
# Detect basic circular pads
elif self.status == 0xB0 and self.note in eventconsts.BasicPads[8]:
self.type = eventconsts.TYPE_BASIC_PAD
self.coord_X = 8
self.coord_Y = eventconsts.BasicPads[8].index(self.note)
self.isBinary = True
if self.recieved_internal:
self.type = eventconsts.TYPE_INTERNAL_EVENT
# Check if buttons were lifted
if self.value == 0:
self.is_lift = True
else:
self.is_lift = False
# Don't process these for internal events
if self.type != eventconsts.TYPE_INTERNAL_EVENT:
# Process long presses
if self.is_lift:
self.is_long_press = isLongPressLift(self.id)
else:
self.is_long_press = False
# Process double presses (seperate for lifted and pressed buttons)
self.is_double_click = False
if self.isBinary is True:
if self.is_lift is True:
self.is_double_click = isDoubleClickLift(self.id)
elif self.is_lift is False and self.isBinary is True:
self.is_double_click = isDoubleClickPress(self.id)
else:
self.is_double_click = False
self.is_long_press = False
def edit(self, event, reason):
"""Edit the event to change data
Args:
event (RawEvent): A MIDI Event to change this event to
"""
self.edited = True
self.status = event.status
self.note = event.data1
self.data1 = event.data1
self.value = event.data2
self.data2 = event.data2
self.status_nibble = event.status >> 4 # Get first half of status byte
self.channel = event.status & int('00001111', 2) # Get 2nd half of status byte
# Bit-shift status and data bytes to get event ID
self.id = (self.status + (self.note << 8))
self.parse()
newEventStr = "Changed event: " + reason
if internal.consts.DEBUG.EVENT_DATA in config.CONSOLE_DEBUG_MODE:
newEventStr += "\n" + self.getInfo()
self.act(newEventStr)
def handle(self, action, silent=False):
"""Handles the event and prevents further processing, both in the script and in FL Studio.
Args:
action (str): The action that handled the event
silent (bool, optional): Whether the action should be set as a hint message. Defaults to False.
"""
self.handled = True
self.ignored = True
self.actions.appendAction(action, silent, internal.consts.EVENT_HANDLE)
def ignore(self, action, silent=False):
"""Prevents further processing in the script but allows processing in FL Studio.
Args:
action (str): The action taken
silent (bool, optional): Whether the action should be written to the hint panel.
Defaults to False.
"""
self.ignored = True
self.actions.appendAction(action, silent, internal.consts.EVENT_IGNORE)
def act(self, action, silent=True):
"""Adds an action to the event without handling it.
Args:
action (str): The action taken
"""
self.actions.appendAction(action, silent, internal.consts.EVENT_NO_HANDLE)
def addProcessor(self, name):
"""Adds an event processor to the processor list.
Args:
name (str): Name of processor
"""
self.actions.addProcessor(name)
def getInfo(self):
"""Returns info about event
Returns:
str: Details about the event
"""
out = "Event:"
out = internal.getTab(out)
# Event type and ID
temp = self.getType()
out += temp
out = internal.getTab(out)
# Event value
temp = self.getValue()
out += temp
out = internal.getTab(out)
# Event full data
temp = self.getDataString()
out += temp
out = internal.getTab(out)
if self.is_double_click:
out += "[Double Click]"
out = internal.getTab(out)
if self.is_long_press:
out += "[Long Press]"
out = internal.getTab(out)
if internal.shifts.query():
out += "[Shifted | " + internal.shifts.current_down + "]"
out = internal.getTab(out)
""" # Add this back soon hopefully
if self.id == config.SHIFT_BUTTON:
out += "[Shift Key]"
out = internal.getTab(out)
"""
# For internal events, have a different printing flag
if self.type == eventconsts.TYPE_INTERNAL_EVENT:
if not internal.consts.DEBUG.PRINT_INTERNAL_EVENTS in config.CONSOLE_DEBUG_MODE:
out = ""
return out
def printInfo(self):
"""Prints string info about event
"""
internal.debugLog(self.getInfo(), internal.consts.DEBUG.EVENT_DATA)
def printOutput(self):
"""Prints actions taken whilst handling event
"""
if internal.consts.DEBUG.PRINT_INTERNAL_EVENTS in config.CONSOLE_DEBUG_MODE or self.type != eventconsts.TYPE_INTERNAL_EVENT:
internal.debugLog("", internal.consts.DEBUG.EVENT_ACTIONS)
self.actions.flush()
if self.handled:
internal.debugLog("[Event was handled]", internal.consts.DEBUG.EVENT_ACTIONS)
else:
internal.debugLog("[Event wasn't handled]", internal.consts.DEBUG.EVENT_ACTIONS)
def getType(self):
"""Returns string detailing type and ID of event
Returns:
str: Type and ID of event info
"""
a = ""
b = ""
if self.type is eventconsts.TYPE_UNRECOGNISED:
a = "Unrecognised"
elif self.type is eventconsts.TYPE_SYSEX_EVENT:
a = "Sysex"
elif self.type is eventconsts.TYPE_NOTE:
a = "Note"
b = utils.GetNoteName(self.note) + " (Ch. " + str(self.channel) + ')'
elif self.type is eventconsts.TYPE_SYSTEM_MSG:
a = "System"
b = self.getID_System()
elif self.type is eventconsts.TYPE_INCONTROL:
a = "InControl"
b = self.getID_InControl()
elif self.type is eventconsts.TYPE_TRANSPORT:
a = "Transport"
b = self.getID_Transport()
elif self.type is eventconsts.TYPE_KNOB or self.type is eventconsts.TYPE_BASIC_KNOB:
a = "Knob"
b = self.getID_Knobs()
elif self.type is eventconsts.TYPE_FADER or self.type is eventconsts.TYPE_BASIC_FADER:
a = "Fader"
b = self.getID_Fader()
elif self.type is eventconsts.TYPE_FADER_BUTTON or self.type is eventconsts.TYPE_BASIC_FADER_BUTTON:
a = "Fader Button"
b = self.getID_FaderButton()
elif self.type is eventconsts.TYPE_PAD:
a = "Pad"
b = self.getID_Pads()
elif self.type is eventconsts.TYPE_BASIC_PAD:
a = "Pad (Basic)"
b = self.getID_Pads()
elif self.type is eventconsts.TYPE_BASIC_EVENT:
a = "Basic Event"
b = self.getID_Basic()
elif self.type is eventconsts.TYPE_INTERNAL_EVENT:
a = "Internal event"
else:
internal.debugLog("Bad event type")
a = "ERROR!!!"
a = internal.getTab(a)
return a + b
def processPmeFlags(self, flags):
"""Processes PME flags on event (Currently very broken)
Args:
flags (int): PME flags
"""
#print(flags)
bin_string = format(flags, '8b')[:5]
#print(bin_string)
flags_list = [x == '1' for x in bin_string]
self.pme_system = flags_list[0]
self.pme_system_safe = flags_list[1]
self.pme_preview_note = flags_list[2]
self.pme_from_host = flags_list[3]
self.pme_from_midi = flags_list[4]
def getID_System(self):
"""Returns string event ID for system events
Returns:
str: Event ID details
"""
if self.id == eventconsts.SYSTEM_EXTENDED: return "InControl"
elif self.id == eventconsts.SYSTEM_MISC: return "Misc"
else: return "ERROR"
def getID_InControl(self):
"""Returns string event ID for InControl events
Returns:
str: Event ID details
"""
if self.id == eventconsts.INCONTROL_KNOBS: return "Knobs"
elif self.id == eventconsts.INCONTROL_FADERS: return "Faders"
elif self.id == eventconsts.INCONTROL_PADS: return "Pads"
else: return "ERROR"
def getID_Basic(self):
"""Returns string event ID for basic events
Returns:
str: Event ID Details
"""
if self.id == eventconsts.PEDAL: return "Pedal"
elif self.id == eventconsts.MOD_WHEEL: return "Modulation"
elif self.id == eventconsts.PITCH_BEND: return "Pitch Bend"
else: return "ERROR"
def getID_Transport(self):
"""Returns string event ID for transport events
Returns:
str: Event ID details
"""
if self.id == eventconsts.TRANSPORT_BACK: return "Back"
elif self.id == eventconsts.TRANSPORT_FORWARD: return "Forward"
elif self.id == eventconsts.TRANSPORT_STOP: return "Stop"
elif self.id == eventconsts.TRANSPORT_PLAY: return "Play"
elif self.id == eventconsts.TRANSPORT_LOOP: return "Loop"
elif self.id == eventconsts.TRANSPORT_RECORD: return "Record"
elif self.id == eventconsts.TRANSPORT_TRACK_NEXT: return "Next Track"
elif self.id == eventconsts.TRANSPORT_TRACK_PREVIOUS: return "Previous Track"
else: return "ERROR"
def getID_Pads(self):
"""Returns string eventID for pad events
Returns:
str: Event ID details
"""
x_map, y_map = self.getPadCoord()
ret_str = ""
if y_map == 0: ret_str += "Top "
elif y_map == 1: ret_str += "Bottom "
else: return "ERROR"
if x_map == 8:
ret_str += "Button"
return ret_str
ret_str += str(x_map + 1)
return ret_str
def getID_Fader(self):
"""Returns string eventID for fader events
Returns:
str: Event ID details
"""
return str(self.coord_X + 1)
def getID_FaderButton(self):
"""Returns string eventID for fader button events
Returns:
str: Event ID details
"""
return str(self.coord_X + 1)
def getID_Knobs(self):
"""Returns string eventID for knob events
Returns:
str: Event ID details
"""
return str(self.coord_X + 1)
def getPadCoord(self):
"""Returns X, Y coordinates for pad events
Returns:
int: X
int: Y
"""
y_map = -1
x_map = -1
done_flag = False
for x in range(len(eventconsts.Pads)):
for y in range(len(eventconsts.Pads[x])):
if self.note == eventconsts.Pads[x][y] or self.note == eventconsts.BasicPads[x][y]:
y_map = y
x_map = x
done_flag = True
break
if done_flag: break
return x_map, y_map
def isPadExtendedMode(self):
"""Returns True if Pad is Extended
Returns:
bool: whether pad is extended
"""
if self.note == eventconsts.Pads[self.coord_X][self.coord_Y]: return True
elif self.note == eventconsts.BasicPads[self.coord_X][self.coord_Y]: return False
else: print("ERROR!!?")
def getValue(self):
"""Returns (formatted) value of event
Returns:
str: Formatted value (data2) of event
"""
a = str(self.value)
b = ""
if self.isBinary:
if self.value == 0:
b = "(Off)"