-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIRE_NFX_V2.py
5585 lines (4641 loc) · 206 KB
/
FIRE_NFX_V2.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
# name=FIRE-NFX-V2.9
# supportedDevices=FL STUDIO FIRE
#
# author: Nelson F. Fernandez Jr. <nfxbeats@gmail.com>
#
# develoment started: 11/24/2021
# first public beta: 07/13/2022
#
# thanks to: HDSQ, TayseteDj, CBaum83, MegaSix, rd3d2, DAWNLIGHT, Jaimezin, a candle, Miro and Image-Line and more...
# thanks to GeorgBit (#GS comments in code) for velocity curve for accent mode featue.
#
VERSION = "2.2024.0821"
print('VERSION ' + VERSION)
import device
import midi
import channels
import patterns
import utils
import time
import ui
import transport
import mixer
import general
import plugins
import playlist
import arrangement
import math
# from math import exp, log #GS
from fireNFX_Utils import *
from fireNFX_Display import *
from fireNFX_PluginDefs import *
from fireNFX_Helpers import *
from fireNFX_FireUtils import *
from fireNFX_Colors import *
from fireNFX_PadDefs import *
from fireNFX_HarmonicScales import *
from fireNFX_DefaultSettings import *
from fireNFX_Classes import *
from fireNFX_Defs import *
#from fireNFX_Classes import rd3d2PotParams, rd3d2PotParamOffsets
from fireNFX_SysMacros import *
from fireNFX_Globals import *
import fireNFX_Bridge
# fix
# widPlugin = 5
# widPluginEffect = 6
# widPluginGenerator = 7
# not safe to use as of Aug 20, 2022
# import thread
# task = True
# def task(self,a,b):
# while (task) and (a < b):
# a += 1
# print('working...', a)
# time.sleep(1)
# print('done')
# def startTask(self):
# id = thread.start_new_thread(task, (0,100))
# print('task started', id)
class TFireNFX():
BridgeDisplayText1 = ""
BridgeDisplayText2 = ""
BridgeDisplayText3 = ""
BridgeMacros = {}
def __init__(self):
SetPallette(Settings.Pallette)
if 'MISSING' in Settings.DEVMODE:
Settings.add_field('DEVMODE', "0")
persist.save_object(Settings, 'Settings.json')
#region FL MIDI API Events
def OnInit(self):
global ScrollTo
global User1Knobs
global User2Knobs
global User3Knobs
for knob in range(4):
User1Knobs.append(TnfxUserKnob(knob))
User2Knobs.append(TnfxUserKnob(knob))
User3Knobs.append(TnfxUserKnob(knob))
if Settings.SHOW_AUDIO_PEAKS:
device.setHasMeters()
ScrollTo = True
self.ClearAllPads()
# FIRE NFX V2 pattern lights
# SendCC(IDPatternUp, SingleColorOff)
# SendCC(IDPatternDown, SingleColorHalfBright)
print("FIRE NFX V2")
# Refresh the control button states
# Initialize Some lights
self.RefreshKnobMode() # Top Knobs operting mode
# turn off top buttons: the Pat Up/Dn, browser and Grid Nav buttons
# SendCC(IDPatternUp, SingleColorOff)
# SendCC(IDPatternDown, SingleColorOff)
SendCC(IDBankL, SingleColorOff)
SendCC(IDBankR, SingleColorOff)
SendCC(IDBrowser, SingleColorOff)
self.InititalizePadModes()
self.RefreshPageLights() # PAD Mutes akak Page
self.ResetBeatIndicators() #
self.RefreshPadModeButtons()
self.RefreshShiftAltButtons()
self.RefreshTransport()
global shuttingDown
shuttingDown = False
# Init some data
InitDisplay()
ScrollTo = False
ui.setHintMsg(Settings.STARTUP_FL_HINT)
ui.showWindow(widChannelRack) # helps the script to have a solid starting window.
self.RefreshAll()
def OnDeInit(self):
print('OnDeInit V2')
global task
task = False
time.sleep(1)
global shuttingDown
shuttingDown = True
DisplayTextAll(' ', ' ', ' ')
DeInitDisplay()
# turn of the lights and go to bed...
self.ClearAllPads()
SendCC(IDKnobModeLEDArray, 16)
for ctrl_ID in getNonPadLightCtrls():
SendCC(ctrl_ID, 0)
self.Reset()
def ClearAllPads(self):
# clear the Pads
for pad in range(0,64):
SetPadColor(pad, 0x000000, 0)
def OnDoFullRefresh(self):
self.RefreshAll()
def OnIdle(self):
global lastHints
global BlinkTimer
global BlinkLast
global ToBlinkOrNotToBlink
global lastFocus
global lastWindowID
global IsOnIdleRefreshing
global peakCheckTime
global pressCheckTime
global pressisRepeating
global BlinkSeconds
if(shuttingDown):
return
if(pressCheckTime != None):
pMapPressed = next((x for x in PadMap if x.Pressed == 1), None)
if(pMapPressed != None):
elapsed = time.time() - pressCheckTime
prevTime = pressCheckTime
pressCheckTime = None # prevent it from checking until we are done
#print('pressed Pad', pMapPressed.PadIndex, 'time', elapsed, 'isPressRep?', pressisRepeating)
if(pressisRepeating):
if (elapsed >= LONG_PRESS_DELAY):
if(pMapPressed.PadIndex in [pdUp, pdDown, pdLeft, pdRight]):
self.HandleNav(pMapPressed.PadIndex)
pressCheckTime = time.time()
else:
pressCheckTime = prevTime
else:
pressisRepeating = (elapsed >= LONG_PRESS_DETECT) # turn on 'pad' repeat mode
pressCheckTime = prevTime
else:
pressCheckTime = None
if(peakCheckTime != None): # we are waiting for next chek
if not self.adjustForAudioPeaks():
peakCheckTime == None
else:
elapsed = time.time() - peakCheckTime
if(elapsed > PEAKTIME):
if self.adjustForAudioPeaks():
if(PadMode.Mode == MODE_DRUM) and (self,not isAltMode): # FPC
self.RefreshFPCSelector()
if(PadMode.Mode == MODE_PATTERNS):
if(self.getFocusedWID() in [widMixer, widChannelRack, widPlaylist]):
if self.isMixerMode():
self.RefreshMixerStrip()
elif self.isChannelMode():
self.RefreshChannelStrip()
elif self.isPlaylistMode():
self.RefreshPlaylist()
peakCheckTime = time.time()
else:
if self.adjustForAudioPeaks():
peakCheckTime = time.time()
if(Settings.WATCH_WINDOW_SWITCHING):
currFormID = self.getFocusedWID()
self.UpdateLastWindowID(currFormID)
if(currFormID in windowIDNames.keys()) and (currFormID != lastFocus):
# print('WWS from ', windowIDNames[_lastFocus], 'to', windowIDNames[currFormID], ' calling OnRefresh(HW_Dirty_FocusedWindow)')
self.OnRefresh(HW_Dirty_FocusedWindow)
if(MONITOR_HINTS): # needs a condition
hintMsg = ui.getHintMsg()
if( len(lastHints) == 0 ):
lastHints.append('')
if(hintMsg != lastHints[-1]):
lastHints.append(hintMsg)
if(len(lastHints) > MAX_HINTS):
lastHints.pop(0)
#
# if(self.isPlaylistMode()):
# CheckAndRefreshSongLen()
# determines if we need show note playback
if(Settings.SHOW_PLAYBACK_NOTES) and (transport.isPlaying() or transport.isRecording()):
if(PadMode.Mode in [MODE_DRUM, MODE_NOTE]):
self.HandleShowNotesOnPlayback()
if PadMode.Mode == MODE_PERFORM:
BlinkTimer = transport.isPlaying() == 1
if(BlinkTimer):
if(BlinkLast == 0):
BlinkLast = time.time()
else:
elapsed = time.time() - BlinkLast
if(elapsed >= BlinkSeconds):
BlinkLast = time.time()
ToBlinkOrNotToBlink = not ToBlinkOrNotToBlink
if(PadMode.NavSet.BlinkButtons):
self.RefreshGridLR()
#print('blink', ToBlinkOrNotToBlink)
def UpdateLastWindowID(self,currFormID):
# this tracks which of the 3 main windows was last focused.
global lastWindowID
if(currFormID in [widChannelRack, widPlaylist, widMixer]):
lastWindowID = currFormID
elif(currFormID in [widPlugin, widPluginEffect, widPianoRoll]):
lastWindowID = widChannelRack
elif(currFormID == widPluginEffect):
lastWindowID = widMixer
def getNoteForChannel(self,chanIdx):
return channels.getCurrentStepParam(chanIdx, mixer.getSongStepPos(), pPitch)
def HandleShowNotesOnPlayback(self):
global PadMode
global lastNote
if (PadMode.Mode in [MODE_DRUM, MODE_NOTE]):
note = self.getNoteForChannel(getCurrChanIdx()) # channels.getCurrentStepParam(getCurrChanIdx(), mixer.getSongStepPos(), pPitch)
if(lastNote != note):
self.ShowNote(lastNote, False)
if(note > -1) and (note in NoteMap):
self.ShowNote(note, True)
lastNote = note
def CheckAndRefreshSongLen(self):
global lastNote
global SongLen
global SHOW_PROGRESS
currSongLen = transport.getSongLength(SONGLENGTH_BARS)
if(currSongLen != SongLen): # song length has changed
if(SHOW_PROGRESS):
self.UpdateAndRefreshProgressAndMarkers()
SongLen = currSongLen
def OnUpdateBeatIndicator(self,value):
global Beat
if(not transport.isPlaying()):
self.RefreshTransport()
self.ResetBeatIndicators()
return
if(value == 0):
SendCC(IDPlay, IDColPlayOn)
elif(value == 1):
SendCC(IDPlay, IDColPlayOnBar)
Beat = 0
if(SHOW_PROGRESS):
if(PadMode.Mode == MODE_PATTERNS) and self.isPlaylistMode(self):
self.UpdateAndRefreshProgressAndMarkers()
elif(value == 2):
SendCC(IDPlay, IDColPlayOnBeat)
Beat += 1
if Beat > len(BeatIndicators):
Beat = 0
isLastBar = transport.getSongPos(SONGLENGTH_BARS) == transport.getSongLength(SONGLENGTH_BARS)
for i in range(0, len(BeatIndicators) ):
if(Beat >= i):
if(isLastBar):
SendCC(BeatIndicators[i], SingleColorHalfBright) # red
else:
SendCC(BeatIndicators[i], SingleColorFull) # green
else:
SendCC(BeatIndicators[i], SingleColorOff)
if(PadMode.Mode == MODE_PERFORM):
if PadMode.IsAlt:
self.RefreshAltPerformanceMode()
else:
self.RefreshPerformanceMode(Beat)
#gets calledd too often
def OnDirtyMixerTrack(self,track):
pass
#OnRefresh(HW_DirtyLEDs)
def OnSysEx(self, event):
pass
def OnControlChange(self, event):
pass
def OnProgramChange(self, event):
pass
def OnPitchBend(self, event):
pass
def OnKeyPressure(self, event):
pass
def OnChannelPressure(self, event):
pass
def OnMidiOutMsg(self, event):
pass
def OnFirstConnect(self):
pass
def OnWaitingForInput(self):
pass
def OnDirtyChannel(self,chan, flags):
global DirtyChannelFlags
# Called on channel rack channel(s) change,
# 'index' indicates channel that changed or -1 when all channels changed
# NOTE PER DOCS:
# collect info about 'dirty' channels here but do not handle channels(s) refresh,
# wait for OnRefresh event with HW_ChannelEvent flag
#
# CE_New 0 new channel is added
# CE_Delete 1 channel deleted
# CE_Replace 2 channel replaced
# CE_Rename 3 channel renamed
# CE_Select 4 channel selection changed
DirtyChannelFlags = flags
def OnRefresh(self, flags):
global PadMode
global isAltMode
global lastFocus
global ignoreNextMixerRefresh
global FollowChannelFX
# print('OnRefresh', flags)
if(flags == HW_CustomEvent_ShiftAlt):
# called by HandleShiftAlt
toptext = ''
midtext = ''
bottext = ''
if(AltHeld and ShiftHeld):
toptext = 'SHIFT + ALT +'
elif(ShiftHeld):
toptext = 'SHIFT +'
midtext = 'Options'
self.RefreshShiftedStates()
if(DoubleTap):
macShowScriptWindow.Execute()
if(PadMode.Mode == MODE_PATTERNS):
if(self.isChannelMode()):
bottext = ''
elif(AltHeld):
toptext = 'ALT +'
#feels like this code should be elsewhere
if(PadMode.Mode == MODE_PATTERNS):
if(self.isChannelMode()):
midtext = 'Ptn = Clone'
bottext = 'Chn = Edit FX'
else: # released
self.RefreshDisplay()
# show the options on screen
if(toptext != ''):
DisplayTextAll(toptext, midtext, bottext)
self.RefreshPadModeButtons()
self.RefreshShiftAltButtons()
self.RefreshTransport()
return # no more processing needed.
if(HW_Dirty_ControlValues & flags):
# transport movement triggers this
if(PadMode.Mode == MODE_PATTERNS):
if(self.isPlaylistMode()):
self.RefreshPlaylist()
self.RefreshProgress()
if(HW_Dirty_LEDs & flags):
self.RefreshTransport()
if(HW_Dirty_Names & flags):
#print('nameflag', flags)
if Settings.AUTO_COLOR_ENABLED:
# newcol = GetColorFor(name)
chan = channels.channelNumber()
trk = mixer.trackNumber()
pat = patterns.patternNumber()
if(HW_Dirty_FocusedWindow & flags):
newWID = self.getFocusedWID()
focusedID = newWID
t = -1
s = -1
name = windowIDNames[newWID]
if(ui.getFocusedFormID() > 1000): # likely a mixer effect
focusedID = ui.getFocusedFormID()
t, s = self.getTrackSlotFromFormID(focusedID)
newWID = widPluginEffect
pname, uname, vname = getPluginNames(t, s)
name = pname + " (" + plugins.getPluginName(t, s) + ") Track: {}, Slot: {}".format(t, s+1)
elif(focusedID in [widPlugin, widPluginGenerator]):
newWID = focusedID
chanIdx = getCurrChanIdx()
if(plugins.isValid(chanIdx, -1)):
pname, uname, vname = getPluginNames(chanIdx, -1)
name = pname + " (" + uname + ") Channel: " + str(chanIdx)
# print('Focus: ', name, focusedID)
# if(focusedID in [widMixer, widPlaylist, widChannelRack]):
# HandlePadModeChange(IDStepSeq)
if(lastFocus != newWID ):
# print('Focus changed from ', windowIDNames[_lastFocus], 'to', name, focusedID, t, s)
self.RefreshModes()
self.UpdateAndRefreshWindowStates()
#if(Settings.AUTO_SWITCH_TO_MAPPED_MIXER_EFFECTS):
#print('checking mixer effects')
# formCap = ui.getFocusedFormCaption()
# UpdateAndRefreshWindowStates()
# if(lastFocus in widDict.keys()):
# print('=====> Changed to ', widDict[lastFocus], formCap)
# pass
# elif(lastFocus == -1):
# print('=====> None')
# pass
# else:
# slotIdx, uname, pname = GetActiveMixerEffectSlotInfo()
# if isKnownMixerEffectActive():
# RefreshModes()
# RefreshEffectMapping() #GBMapTest()
# else:
# print("=====> FormCap ", formCap)
# pass
if(HW_Dirty_Performance & flags): # called when new channels or patterns added
if(PadMode.Mode == MODE_PATTERNS):
# RefreshChannelStrip()
self.RefreshPatternStrip()
self.RefreshChannelStrip()
if(HW_Dirty_Patterns & flags):
#print('dirty patterns')
self.CloseBrowser()
self.HandlePatternChanges()
if(HW_Dirty_ChannelRackGroup & flags):
self.HandleChannelGroupChanges()
if(HW_ChannelEvent & flags):
self.CloseBrowser()
self.UpdateChannelMap()
# DirtyChannelFlags should have the specific CE_xxxx flags if needed
# https://www.image-line.com/fl-studio-learning/fl-studio-online-manual/html/midi_scripting.htm#OnDirtyChannelFlag
# something change in FL 21.0.2, that makes the mixer no longer follow when the selected channel changes
# so I check if it needs to move here
if (PadMode.Mode != MODE_PERFORM): # ignore when in perf mode
if(CE_Select & DirtyChannelFlags) and (FollowChannelFX):
trk = channels.getTargetFxTrack(getCurrChanIdx())
if(trk != mixer.trackNumber()):
#self.prnt('forcing chanfx')
self.SelectAndShowMixerTrack(trk)
# mixer.setTrackNumber(trk, curfxScrollToMakeVisible)
# ui.miDisplayRect(trk, trk, rectTime, CR_ScrollToView)
if (PadMode.Mode == MODE_DRUM):
if(not self.isFPCActive()):
PadMode = modeDrumAlt
isAltMode = True
self.SetPadMode()
self.RefreshDrumPads()
elif(PadMode.Mode == MODE_PATTERNS):
scrollTo = CurrentChannel != channels.channelNumber()
self.RefreshChannelStrip(scrollTo)
elif(PadMode.Mode == MODE_NOTE):
self.RefreshNotes()
if(HW_Dirty_Colors & flags):
if (PadMode.Mode == MODE_DRUM):
self.RefreshDrumPads()
elif(PadMode.Mode == MODE_PATTERNS):
self.RefreshChannelStrip()
if(HW_Dirty_Tracks & flags):
if(self.isPlaylistMode()):
self.UpdatePlaylistMap()
self.RefreshPlaylist()
if(HW_Dirty_Mixer_Sel & flags):
if(self.isMixerMode()):
#UpdateMixerMap(-2)
self.RefreshMixerStrip(True)
self.RefreshDisplay()
def OnProjectLoad(self, status):
#print('Window active:', self.isChannelMode(), self.isPlaylistMode(), self.isMixerMode())
# status = 0 = starting load?
if(status == 0):
DisplayTextAll('Project Loading', '-', 'Please Wait...')
if(status >= 100): #finished loading
self.SetPadMode()
#UpdateMarkerMap()
self.RefreshPadModeButtons()
self.UpdatePatternModeData()
self.RefreshAll()
def OnSendTempMsg(self, msg, duration):
global tempMsg
global tempMsg2
tempMsg = msg
# if(' - ' in msg):
# tempMsg = msg
#print('TempMsg', "[{}]".format(tempMsg), duration, 'inMenu', ui.isInPopupMenu())
# else:
# tempMsg2 = msg
# print('TempMsg2', "[{}]".format(tempMsg2), duration, 'inMenu', ui.isInPopupMenu())
def FLHasFocus(self):
ui.showWindow(widChannelRack)
transport.globalTransport(90, 1)
time.sleep(0.025)
ui.down()
res = tempMsg.startswith("File -") or tempMsg.startswith("Menu - File")
if (ui.isInPopupMenu()):
ui.closeActivePopupMenu()
return res
def isKnownPlugin(self):
name, uname = self.getCurrChanPluginNames()
return name in KNOWN_PLUGINS.keys()
def OnMidiIn(self,event):
global proctime
global prevCtrlID
global DoubleTap
ctrlID = event.data1 # the low level hardware id of a button, knob, pad, etc
#self.prnt('OnMidiIn', ctrlID, event.data2)
# check for double tap
if(event.data2 > 0) and (ctrlID not in [IDKnob1, IDKnob2, IDKnob3, IDKnob4, IDSelect]):
prevtime = proctime
proctime = time.monotonic_ns() // 1000000
elapsed = proctime-prevtime
if (prevCtrlID == ctrlID):
DoubleTap = (elapsed < Settings.DBL_TAP_DELAY_MS)
else:
prevCtrlID = ctrlID
DoubleTap = False
# handle shift/alt
if(ctrlID in [IDAlt, IDShift]):
self.HandleShiftAlt(event, ctrlID)
event.handled = True
return
if(ctrlID in KnobCtrls): #if false, it's a custom userX knob link
event.handled = self.OnMidiIn_KnobEvent(event)
return
def OnMidiMsg(self,event):
global ShiftHeld
global AltHeld
global PadMap
global pressCheckTime
global pressisRepeating
global isPMESafe
global isModalWindowOpen
global User1Knobs
global User2Knobs
global User3Knobs
ctrlID = event.data1 # the low level hardware id of a button, knob, pad, etc
#self.prnt('OnMidiMsg', ctrlID, event.data2, 'status', event.status)
# check PME flags. note that these will be different from OnMidiIn PME values
isModalWindowOpen = (event.pmeFlags & PME_System_Safe == 0)
isPMESafe = (event.pmeFlags & PME_System != 0)
if(not isPMESafe):
self.prnt('pme not safe', event.pmeFlags)
event.handled = True
return
if(event.data1 in KnobCtrls) and (KnobMode in [KM_USER1, KM_USER2, KM_USER3]): # user defined knobs
knobOffset = KnobCtrls.index(event.data1)
event.data1 += (KnobMode-KM_USER1) * 4 # so the CC is different for each user mode
# self.prnt(self,'knob CC', event.data1)
if not (event.status in [MIDI_NOTEON, MIDI_NOTEOFF]): # to prevent the mere touching of the knob generating a midi note event.
# this code from the original script with slight modification:
event.inEv = event.data2
if event.inEv >= 0x40:
event.outEv = event.inEv - 0x80
else:
event.outEv = event.inEv
event.isIncrement = 1
event.handled = False # user modes, free
device.processMIDICC(event)
# USER KNOB
if(KnobMode == KM_USER1):
userknob = User1Knobs[knobOffset]
elif(KnobMode == KM_USER2):
userknob = User2Knobs[knobOffset]
else:
userknob = User3Knobs[knobOffset]
if (general.getVersion() > 9):
BaseID = EncodeRemoteControlID(device.getPortNumber(), 0, 0)
recEventIDIndex = device.findEventID(BaseID + event.data1, 0)
if recEventIDIndex != 2147483647: # check if it has been assigned to a control yet...
# show the name/value on the display
Name = device.getLinkedParamName(recEventIDIndex)
currVal = device.getLinkedValue(recEventIDIndex)
valstr = device.getLinkedValueString(recEventIDIndex)
Bipolar = device.getLinkedInfo(recEventIDIndex) == Event_Centered
DisplayBar2(Name, currVal, valstr, Bipolar)
if (userknob.PluginName == ''):
name = LastActiveWindow.Name # ui.getFocusedFormCaption()
userknob.PluginName = name
#print('assigning knob', name, 'tweak', Name)
else:
#print('knob', userknob.PluginName, 'tweak', Name, currVal, valstr, Bipolar)
pass
# handle a pad
if( IDPadFirst <= ctrlID <= IDPadLast):
padNum = ctrlID - IDPadFirst
pMap = PadMap[padNum]
cMap = getColorMap()
col = cMap[padNum].PadColor
if (col == cOff):
col = Settings.PAD_PRESSED_COLOR
if(event.data2 > 0): # pressed
pMap.Pressed = 1
SetPadColor(padNum, col,dimBright, False) # False will not save the color to the ColorMap
else: #released
pMap.Pressed = 0
# SetPadColor(padNum, -1, dimNormal) # -1 will rever to the ColorMap color
# if no other pads held, reset the long press timer
pMapPressed = next((x for x in PadMap if x.Pressed == 1), None)
if(pMapPressed == None):
pressCheckTime = None
pressisRepeating = False
else:
pressCheckTime = time.time()
#PROGRESS BAR
if(SHOW_PROGRESS):
if(PadMode.Mode == MODE_PATTERNS) and (self.isPlaylistMode()):
progPads = self.getProgressPads()
if(padNum in progPads) and (pMap.Pressed == 1): # only handle on pressed.
event.handled = self.HandleProgressBar(padNum)
return event.handled
padsToHandle = pdWorkArea
if(self.isNoNav()):
padsToHandle = pdAllPads
# # handle effects when active
if(Settings.AUTO_SWITCH_TO_MAPPED_MIXER_EFFECTS) and self.isMixerMode():
#print('mixer effect mode', padNum)
#is an effect mapped?
if(self.isKnownMixerEffectActive()) and (padNum in ParamPadMapDict.keys()):
self.RefreshEffectMapping()
if(padNum in ParamPadMapDict.keys()):
self.ForceNavSet(nsNone)
event.handled = self.HandleEffectPads(padNum)
return
if(padNum in padsToHandle):
if(PadMode.Mode == MODE_DRUM): # handles on and off for PADS
event.handled = self.HandlePads(event, padNum)
return
elif(PadMode.Mode == MODE_NOTE): # handles on and off for NOTES
event.handled = self.HandlePads(event, padNum)
return
elif(PadMode.Mode == MODE_PERFORM): # handles on and off for PERFORMANCE
if(pMap.Pressed == 1):
if PadMode.IsAlt:
event.handled = self.HandleAltPerform(padNum)
else:
event.handled = self.HandlePerform(padNum)
else:
event.handled = True
return
elif(PadMode.Mode == MODE_PATTERNS): # if STEP/PATTERN mode, treat as controls and not notes...
if(pMap.Pressed == 1): # On Pressed
event.handled = self.HandlePads(event, padNum)
return
else:
event.handled = True #prevents a note off message
return
# special handler for color picker
if(PadMode.NavSet.ColorPicker):
if(padNum in pdPallette) or (padNum in pdCurrColors):
event.handled = self.HandleColorPicker(padNum)
return
if(not self.isNoNav()):
# always handle macros
if(padNum in pdMacros):
if (pMap.Pressed):
event.handled = self.HandleMacros(pdMacros.index(padNum))
# self.RefreshMacros()
self.UpdateAndRefreshWindowStates()
else:
event.handled = True #prevents a note off message
return
# always handle nav
if(padNum in pdNav):
if (pMap.Pressed):
event.handled = self.HandleNav(padNum)
else:
#self.RefreshNavPads()
event.handled = True #prevents a note off message
return
return
# handle other "non" Pads
# here we will get a message for on (press) and off (release), so we need to
# determine where it's best to handle. For example, the play button should trigger
# immediately on press and ignore on release, so we code it that way
if(event.data2 > 0) and (not event.handled): # Pressed
if(ShiftHeld):
self.HandleShifted(event)
if( ctrlID in PadModeCtrls):
event.handled = self.HandlePadModeChange(event.data1) # ctrlID = event.data1
elif( ctrlID in TransportCtrls ):
event.handled = self.HandleTransport(event)
elif( ctrlID in PageCtrls): # defined as [IDMute1, IDMute2, IDMute3, IDMute4]
event.handled = self.HandlePage(event, ctrlID)
elif( ctrlID == KnobModeCtrlID):
event.handled = self.HandleKnobMode()
elif( ctrlID in KnobCtrls):
event.handled = self.HandleKnob(event, ctrlID)
elif( ctrlID in PattUpDnCtrls):
event.handled = self.HandlePattUpDn(ctrlID)
elif( ctrlID in GridLRCtrls):
event.handled = self.HandleGridLR(ctrlID)
elif( ctrlID == IDBrowser ):
event.handled = self.HandleBrowserButton()
elif(ctrlID in SelectWheelCtrls):
event.handled = self.HandleSelectWheel(event, ctrlID)
else: # Released
event.handled = True
def OnNoteOn(self,event):
#self.prnt('OnNoteOn()', utils.GetNoteName(event.data1),event.data1,event.data2)
self.ShowNote(event.data1, True)
pass
def OnNoteOff(self,event):
#self.prnt('OnNoteOff()', utils.GetNoteName(event.data1),event.data1,event.data2)
self.ShowNote(event.data1, False)
pass
#endregion
#region Handlers
def HandleChannelStrip(self,padNum): #, isChannelStripB):
global PatternMap
global ChannelMap
global CurrentChannel
# global PreviousChannel
global ChannelCount
global OrigColor
global rectTime
if(self.isMixerMode()):
return self.HandleMixerEffectsStrip(padNum)
if(self.isPlaylistMode()):
if(SHOW_PROGRESS):
return self.HandleProgressBar(padNum)
else:
return True
prevChanIdx = getCurrChanIdx() # channels.channelNumber()
pageOffset = self.getChannelOffsetFromPage()
padOffset = 0
chanApads, chanBPads = self.getChannelPads()
if(padNum in chanApads):
padOffset = chanApads.index(padNum)
isChannelStripB = False
elif(padNum in chanBPads):
padOffset = chanBPads.index(padNum)
isChannelStripB = True
chanIdx = padOffset + pageOffset
channelMap = self.getChannelMap()
channel = None
if(chanIdx < len(channelMap) ):
channel = channelMap[chanIdx]
if(channel == None):
return True
newChanIdx = channel.FLIndex # pMap.FLIndex
newMixerIdx = channel.Mixer.FLIndex
if (newChanIdx > -1): #is it a valid chan number?
if(not isChannelStripB): # its the A strip
if(PadMode.NavSet.ColorPicker): # color picker mode
if(self,not isChannelStripB):
OrigColor = FLColorToPadColor(channels.getChannelColor(getCurrChanIdx()), 1) # xxxx
channels.setChannelColor(getCurrChanIdx(), PadColorToFLColor(NewColor))
self.RefreshColorPicker()
self.SetPadMode()
return True
elif(newChanIdx == prevChanIdx): # if it's already on the channel, toggle the windows
if(ShiftHeld) and (Settings.SHOW_CHANNEL_MUTES): # new
if(DoubleTap):
ui.showWindow(widPianoRoll)
macZoom.Execute(Settings.DBL_TAP_ZOOM)
else:
self.ShowPianoRoll(-1)
else:
self.ShowChannelEditor(-1)
else:
self.SelectAndShowChannel(newChanIdx)
else: # is B STrip
if(ShiftHeld):
if (Settings.SHOW_CHANNEL_MUTES): # new
channels.soloChannel(newChanIdx)
ui.crDisplayRect(0, newChanIdx, 0, 1, rectTime, CR_ScrollToView + CR_HighlightChannelMute) # CR_HighlightChannels +
self.RefreshChannelStrip(False)
else: #old
channels.muteChannel(newChanIdx)
ui.crDisplayRect(0, newChanIdx, 0, 1, rectTime, CR_ScrollToView + CR_HighlightChannelMute) # CR_HighlightChannels +
self.RefreshChannelStrip(False)
else: #not SHIFTed
if (Settings.SHOW_CHANNEL_MUTES): # new
channels.muteChannel(newChanIdx)
ui.crDisplayRect(0, newChanIdx, 0, 1, rectTime, CR_ScrollToView + CR_HighlightChannelMute) # CR_HighlightChannels +
self.RefreshChannelStrip(False)
else: #old
if(newChanIdx == prevChanIdx): # if it's already on the channel, toggle the windows
if(DoubleTap):
ui.showWindow(widPianoRoll)
macZoom.Execute(Settings.DBL_TAP_ZOOM)
else:
self.ShowPianoRoll(-1)
else: #'new' channel, close the previous windows first
self.SelectAndShowChannel(newChanIdx)
ChannelCount = channels.channelCount()
self.RefreshDisplay()
return True
def HandleAltPerform(self, padNum):
if len(UserMacros) > 0:
self.RunMacro(UserMacros[padNum])
return True
def HandlePerform(self,padNum):
global PerformanceBlocks
if isPMESafe:
if(padNum in PerformanceBlocks.keys()):
block = PerformanceBlocks[padNum]
# self.prnt('handling block', block, 'alt', AltHeld, 'shift', ShiftHeld)
tlcMode = TLC_MuteOthers | TLC_Fill
if(AltHeld and ShiftHeld):
playlist.soloTrack(block.FLTrackIndex, -1)
elif(ShiftHeld):
tlcMode = -1 # stop all
elif(AltHeld):
playlist.muteTrack(block.FLTrackIndex)
block.Trigger(tlcMode)
self.RefreshPerformanceMode(-1)
return True
def HandlePlaylist(self,padNum):
plPadsA, plPadsB = self.getPlaylistPads()
flIdx = PadMap[padNum].FLIndex
if(flIdx > -1):
if(padNum in plPadsA):
playlist.selectTrack(flIdx)
if(padNum in plPadsB):
patNum = patterns.patternNumber()
if(ShiftHeld):
playlist.soloTrack(flIdx)
else:
playlist.muteTrack(flIdx)
#workaround
if Settings.MUTE_PLTRACK_IMMEDIATELY:
patterns.jumpToPattern(patNum+1)
patterns.jumpToPattern(patNum)
self.UpdatePlaylistMap()
self.RefreshPlaylist()
self.RefreshDisplay()
return True
def HandleProgressBar(self,padNum):
progPads = self.getProgressPads()
padOffs = progPads.index(padNum)
prgMap = ProgressMapSong[padOffs]
newSongPos = transport.getSongPos(SONGLENGTH_ABSTICKS) # current location
if(prgMap.BarNumber > 0):
newSongPos = prgMap.SongPosAbsTicks
transport.setSongPos(newSongPos, SONGLENGTH_ABSTICKS)
if(AltHeld):
markerOffs = padOffs + 1
arrangement.addAutoTimeMarker(prgMap.SongPosAbsTicks, Settings.MARKER_PREFIX_TEXT.format(markerOffs))