This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdevice_FIRE-NFX.py
5313 lines (4377 loc) · 170 KB
/
device_FIRE-NFX.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
# 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.2023.0616"
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
from math import exp, log #GS
from fireNFX_Utils import *
from fireNFX_Display import *
from fireNFX_PluginDefs import *
from fireNFX_Helpers import *
from fireNFX_Macros import _MacroList, _PianoRollMacros, _CustomMacros
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 *
# fix
# widPlugin = 5
# widPluginEffect = 6
# widPluginGenerator = 7
# not safe to use as of Aug 20, 2022
# import _thread
# _task = True
# def task(a,b):
# while (_task) and (a < b):
# a += 1
# print('working...', a)
# time.sleep(1)
# print('done')
# def startTask():
# id = _thread.start_new_thread(task, (0,100))
# print('task started', id)
SetPallette(Settings.Pallette)
#region globals
dimDim = Settings.DIM_DIM
dimNormal = Settings.DIM_NORMAL
dimBright = Settings.DIM_BRIGHT
Settings.DEV_MODE = -1
_debugprint = Settings.SHOW_PRN
_rectTime = Settings.DISPLAY_RECT_TIME_MS
_ShiftHeld = False
_FLChannelFX = False
_AltHeld = False
_PatternCount = 0
_CurrentPattern = -1
_PatternPage = 1
_MixerPage = 1
_PlaylistPage = 1
_ChannelCount = 0
_CurrentChannel = -1
# _PreviousChannel = -1
_isAltMode = False
_isShiftMode = False
_ChannelPage = 1
_KnobMode = 0
_Beat = 1
_PadMap = list()
_PatternMap = list()
_PatternSelectedMap = list()
_ChannelMap = list()
_ChannelSelectedMap = list()
_PlaylistMap = list()
_PlaylistSelectedMap = list()
_MarkerMap = list()
_ProgressMapSong = list()
_MixerMap = list()
_OrigColor = 0x000000
_NewColor = 0x000000
_BlinkTimer = False
_BlinkLast = 0.0
_BlinkSeconds = 0.2
_ToBlinkOrNotToBlink = False
_showText = ['OFF', 'ON']
_WalkerChanIdx = -1
#display menu
_ShowMenu = 0
_menuItems = []
_chosenItem = 0
_menuItemSelected = _chosenItem
_menuHistory = []
MAXLEVELS = 2
_menuBackText = '<back>'
_progressZoom = [0,1,2,4]
_progressZoomIdx = 1
LOADED_PLUGINS = {}
_DirtyChannelFlags = 0
HW_CustomEvent_ShiftAlt = 0x20000
lyBanks = 0
lyStrips = 1
_Layouts = ['Banks', 'Strips']
#notes/scales
_ScaleIdx = Settings.SCALE
_ScaleDisplayText = ""
_ScaleNotes = list()
_lastNote =-1
_NoteIdx = Settings.NOTE_NAMES.index(Settings.ROOT_NOTE)
_NoteRepeat = False
_NoteRepeatLengthIdx = BeatLengthsDefaultOffs
_isRepeating = False
_SnapIdx = InitialSnapIndex
_OctaveIdx = OctavesList.index(Settings.OCTAVE)
_ShowChords = False
_ChordNum = -1
_ChordInvert = 0 # 0 = none, 1 = 1st, 2 = 2nd
_ChordTypes = ['Normal', '1st Inv', '2nd Inv']
_Chord7th = False
_VelocityMin = 100
_VelocityMax = 126
#GS
_AccentEnabled = Settings.ACCENT_ENABLED #GS
_AccentCurveShape = 0.4 #GS - The value should be in a range between 0.1 (very steep) and 1.0 (linear).
_AccentVelocityMin = 32 #GS - minimum velocity on the Fire is 32
_DebugPrn = True
_DebugMin = lvlD
#from fireNFX_Classes import _rd3d2PotParams, _rd3d2PotParamOffsets
from fireNFX_Macros import *
# list of notes that are mapped to pads
_NoteMap = list()
_NoteMapDict = {}
#_FPCNotesDict = {}
_SongPos = 0
_SongLen = -1
_ScrollTo = True # used to determine when to scroll to the channel/pattern
#endregion
#region FL MIDI API Events
def OnInit():
global _ScrollTo
if Settings.SHOW_AUDIO_PEAKS:
device.setHasMeters()
_ScrollTo = True
ClearAllPads()
# Refresh the control button states
# Initialize Some lights
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)
InititalizePadModes()
RefreshPageLights() # PAD Mutes akak Page
ResetBeatIndicators() #
RefreshPadModeButtons()
RefreshShiftAltButtons()
RefreshTransport()
InitDisplay()
line = '----------------------'
DisplayText(Font6x8, JustifyCenter, 0, Settings.STARTUP_TEXT_TOP, True)
DisplayText(Font6x16, JustifyCenter, 1, '+', True)
# DisplayText(Font10x16, JustifyCenter, 2, Settings.STARTUP_TEXT_BOT, True)
DisplayTextBottom('v' + _VERSION)
#fun "animation"
for i in range(16):
text = line[0:i]
DisplayText(Font6x16, JustifyCenter, 1, text, True)
time.sleep(.1)
# Init some data
RefreshAll()
_ScrollTo = False
ui.setHintMsg(Settings.STARTUP_FL_HINT)
ui.showWindow(widChannelRack) # helps the script to have a solid starting window.
_shuttingDown = False
def OnDeInit():
global _task
_task = False
time.sleep(1)
global _shuttingDown
_shuttingDown = True
DisplayTextAll(' ', ' ', ' ')
DeInitDisplay()
# turn of the lights and go to bed...
ClearAllPads()
SendCC(IDKnobModeLEDArray, 16)
for ctrlID in getNonPadLightCtrls():
SendCC(ctrlID, 0)
def ClearAllPads():
# clear the Pads
for pad in range(0,64):
SetPadColor(pad, 0x000000, 0)
def OnDoFullRefresh():
RefreshAll()
_lastHints = []
MAX_HINTS = 20
MONITOR_HINTS = False
SHOW_AUDIO = True
_IsOnIdleRefreshing = False
_peakCheckTime = None
_pressCheckTime = None
PEAKTIME = 0.0
LONG_PRESS_DELAY = 0.125
LONG_PRESS_DETECT = 0.5
_pressisRepeating = False
def OnIdle():
global _lastHints
global _BlinkTimer
global _BlinkLast
global _ToBlinkOrNotToBlink
global _lastFocus
global _lastWindowID
global _IsOnIdleRefreshing
global _peakCheckTime
global _pressCheckTime
global _pressisRepeating
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]):
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 adjustForAudioPeaks():
_peakCheckTime == None
else:
elapsed = time.time() - _peakCheckTime
if(elapsed > PEAKTIME):
if adjustForAudioPeaks():
if(_PadMode.Mode == MODE_DRUM) and (not _isAltMode): # FPC
RefreshFPCSelector()
if(_PadMode.Mode == MODE_PATTERNS):
if(getFocusedWID() in [widMixer, widChannelRack, widPlaylist]):
if isMixerMode():
RefreshMixerStrip()
elif isChannelMode():
RefreshChannelStrip()
elif isPlaylistMode():
RefreshPlaylist()
_peakCheckTime = time.time()
else:
if adjustForAudioPeaks():
_peakCheckTime = time.time()
if(Settings.WATCH_WINDOW_SWITCHING):
currFormID = getFocusedWID()
UpdateLastWindowID(currFormID)
if(currFormID in windowIDNames.keys()) and (currFormID != _lastFocus):
# print('WWS from ', windowIDNames[_lastFocus], 'to', windowIDNames[currFormID], ' calling OnRefresh(HW_Dirty_FocusedWindow)')
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(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]):
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):
RefreshGridLR()
#print('blink', _ToBlinkOrNotToBlink)
def UpdateLastWindowID(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(chanIdx):
return channels.getCurrentStepParam(chanIdx, mixer.getSongStepPos(), pPitch)
def HandleShowNotesOnPlayback():
global _PadMode
global _lastNote
if (_PadMode.Mode in [MODE_DRUM, MODE_NOTE]):
note = getNoteForChannel(getCurrChanIdx()) # channels.getCurrentStepParam(getCurrChanIdx(), mixer.getSongStepPos(), pPitch)
if(_lastNote != note):
ShowNote(_lastNote, False)
if(note > -1) and (note in _NoteMap):
ShowNote(note, True)
_lastNote = note
def CheckAndRefreshSongLen():
global _lastNote
global _SongLen
currSongLen = transport.getSongLength(SONGLENGTH_BARS)
if(currSongLen != _SongLen): # song length has changed
if(_SHOW_PROGRESS):
UpdateAndRefreshProgressAndMarkers()
_SongLen = currSongLen
def OnMidiMsg2(event):
if(event.data1 in KnobCtrls) and (_KnobMode in [KM_USER1, KM_USER2, KM_USER3]): # user defined knobs
# this code from the original script with slight modification:
data2 = event.data2
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
event.data1 += (_KnobMode-KM_USER1) * 4 # so the CC is different for each user mode
device.processMIDICC(event)
if (general.getVersion() > 9):
BaseID = EncodeRemoteControlID(device.getPortNumber(), 0, 0)
eventId = device.findEventID(BaseID + event.data1, 0)
if eventId != 2147483647:
s = device.getLinkedParamName(eventId)
s2 = device.getLinkedValueString(eventId)
DisplayTextAll(s, s2, '')
_SHOW_PROGRESS = True
def OnUpdateBeatIndicator(value):
global _Beat
if(not transport.isPlaying()):
RefreshTransport()
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 isPlaylistMode():
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):
RefreshPerformanceMode(_Beat)
#gets calledd too often
# def OnDirtyMixerTrack(track):
# pass
# #OnRefresh(HW_Dirty_LEDs)
def OnDirtyChannel(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
_FollowChannelFX = True
_lastFocus = -1
_lastWindowID = -1 # only tracks the basic windows with widXXXX values
windowIDNames = {
widMixer: 'Mixer',
widChannelRack: 'Channel Rack',
widPlaylist: 'Playlist',
widPianoRoll: 'Piano Roll',
widBrowser: 'Browser',
widPlugin: 'Plugin',
widPluginEffect: 'Plugin Effect',
widPluginGenerator: 'Plugin/Generator',
-1: 'Unknown'
}
def OnRefresh(flags):
global _PadMode
global _isAltMode
global _lastFocus
global _ignoreNextMixerRefresh
# 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'
RefreshShiftedStates()
if(_DoubleTap):
macShowScriptWindow.Execute()
if(_PadMode.Mode == MODE_PATTERNS):
if(isChannelMode()):
bottext = ''
elif(_AltHeld):
toptext = 'ALT +'
#feels like this code should be elsewhere
if(_PadMode.Mode == MODE_PATTERNS):
if(isChannelMode()):
midtext = 'Ptn = Clone'
bottext = 'Chn = Edit FX'
else: # released
RefreshDisplay()
# show the options on screen
if(toptext != ''):
DisplayTextAll(toptext, midtext, bottext)
RefreshPadModeButtons()
RefreshShiftAltButtons()
RefreshTransport()
return # no more processing needed.
if(HW_Dirty_ControlValues & flags):
# transport movement triggers this
if(_PadMode.Mode == MODE_PATTERNS):
if(isPlaylistMode()):
RefreshPlaylist()
RefreshProgress()
if(HW_Dirty_LEDs & flags):
RefreshTransport()
if(HW_Dirty_FocusedWindow & flags):
newWID = getFocusedWID()
focusedID = newWID
t = -1
s = -1
name = windowIDNames[newWID]
if(ui.getFocusedFormID() > 1000): # likely a mixer effect
focusedID = ui.getFocusedFormID()
t, s = 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)
# if(focusedID in [widMixer, widPlaylist, widChannelRack]):
# HandlePadModeChange(IDStepSeq)
if(_lastFocus != newWID ):
# print('Focus changed from ', windowIDNames[_lastFocus], 'to', name, focusedID, t, s)
RefreshModes()
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()
RefreshPatternStrip()
RefreshChannelStrip()
if(HW_Dirty_Patterns & flags):
#print('dirty patterns')
CloseBrowser()
HandlePatternChanges()
if(HW_Dirty_ChannelRackGroup & flags):
HandleChannelGroupChanges()
if(HW_ChannelEvent & flags):
CloseBrowser()
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()):
prnt('forcing chanfx')
SelectAndShowMixerTrack(trk)
# mixer.setTrackNumber(trk, curfxScrollToMakeVisible)
# ui.miDisplayRect(trk, trk, _rectTime, CR_ScrollToView)
if (_PadMode.Mode == MODE_DRUM):
if(not isFPCActive()):
_PadMode = modeDrumAlt
_isAltMode = True
SetPadMode()
RefreshDrumPads()
elif(_PadMode.Mode == MODE_PATTERNS):
scrollTo = _CurrentChannel != channels.channelNumber()
RefreshChannelStrip(scrollTo)
elif(_PadMode.Mode == MODE_NOTE):
RefreshNotes()
if(HW_Dirty_Colors & flags):
if (_PadMode.Mode == MODE_DRUM):
RefreshDrumPads()
elif(_PadMode.Mode == MODE_PATTERNS):
RefreshChannelStrip()
if(HW_Dirty_Tracks & flags):
if(isPlaylistMode()):
UpdatePlaylistMap()
RefreshPlaylist()
if(HW_Dirty_Mixer_Sel & flags):
if(isMixerMode()):
#UpdateMixerMap(-2)
RefreshMixerStrip(True)
def OnProjectLoad(status):
# status = 0 = starting load?
if(status == 0):
DisplayTextAll('Project Loading', '-', 'Please Wait...')
if(status >= 100): #finished loading
#print('project loaded')
SetPadMode()
#UpdateMarkerMap()
RefreshPadModeButtons()
UpdatePatternModeData()
RefreshAll()
_tempMsg = ''
_tempMsg2 = ''
def OnSendTempMsg(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():
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():
name, uname = getCurrChanPluginNames()
return name in KNOWN_PLUGINS.keys()
_prevCtrlID = 0
_proctime = 0
_DoubleTap = False
_isPMESafe = True
_isModalWindowOpen = False
def OnMidiIn(event):
global _proctime
global _prevCtrlID
global _DoubleTap
ctrlID = event.data1 # the low level hardware id of a button, knob, pad, etc
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]):
HandleShiftAlt(event, ctrlID)
event.handled = True
return
if(ctrlID in KnobCtrls): #if false, it's a custom userX knob link
event.handled = OnMidiIn_KnobEvent(event)
return
def OnMidiMsg(event):
global _ShiftHeld
global _AltHeld
global _PadMap
global _pressCheckTime
global _pressisRepeating
global _isPMESafe
global _isModalWindowOpen
ctrlID = event.data1 # the low level hardware id of a button, knob, pad, etc
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):
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
event.data1 += (_KnobMode-KM_USER1) * 4 # so the CC is different for each user mode
# prnt('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)
if (general.getVersion() > 9):
BaseID = EncodeRemoteControlID(device.getPortNumber(), 0, 0)
recEventIDIndex = device.findEventID(BaseID + event.data1, 0)
if recEventIDIndex != 2147483647:
# 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)
# 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):
progPads = getProgressPads()
if(_PadMode.Mode == MODE_PATTERNS) and (isPlaylistMode()):
if(padNum in progPads) and (pMap.Pressed == 1): # only handle on pressed.
event.handled = HandleProgressBar(padNum)
return event.handled
padsToHandle = pdWorkArea
if(isNoNav()):
padsToHandle = pdAllPads
# # handle effects when active
if(Settings.AUTO_SWITCH_TO_MAPPED_MIXER_EFFECTS) and isMixerMode():
print('mixer effect mode', padNum)
#is an effect mapped?
if(isKnownMixerEffectActive()) and (padNum in _ParamPadMapDict.keys()):
RefreshEffectMapping()
if(padNum in _ParamPadMapDict.keys()):
ForceNavSet(nsNone)
event.handled = HandleEffectPads(padNum)
return
if(padNum in padsToHandle):
if(_PadMode.Mode == MODE_DRUM): # handles on and off for PADS
event.handled = HandlePads(event, padNum)
return
elif(_PadMode.Mode == MODE_NOTE): # handles on and off for NOTES
event.handled = HandlePads(event, padNum)
return
elif(_PadMode.Mode == MODE_PERFORM): # handles on and off for PERFORMANCE
if(pMap.Pressed == 1):
event.handled = 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 = 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 = HandleColorPicker(padNum)
return
if(not isNoNav()):
# always handle macros
if(padNum in pdMacros) and (pMap.Pressed):
event.handled = HandleMacros(pdMacros.index(padNum))
RefreshMacros()
UpdateAndRefreshWindowStates()
return
# always handle nav
if(padNum in pdNav) and (pMap.Pressed):
event.handled = HandleNav(padNum)
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):
HandleShifted(event)
if( ctrlID in PadModeCtrls):
event.handled = HandlePadModeChange(event.data1) # ctrlID = event.data1
elif( ctrlID in TransportCtrls ):
event.handled = HandleTransport(event)
elif( ctrlID in PageCtrls): # defined as [IDMute1, IDMute2, IDMute3, IDMute4]
event.handled = HandlePage(event, ctrlID)
elif( ctrlID == KnobModeCtrlID):
event.handled = HandleKnobMode()
elif( ctrlID in KnobCtrls):
event.handled = HandleKnob(event, ctrlID)
elif( ctrlID in PattUpDnCtrls):
event.handled = HandlePattUpDn(ctrlID)
elif( ctrlID in GridLRCtrls):
event.handled = HandleGridLR(ctrlID)
elif( ctrlID == IDBrowser ):
event.handled = HandleBrowserButton()
elif(ctrlID in SelectWheelCtrls):
event.handled = HandleSelectWheel(event, ctrlID)
else: # Released
event.handled = True
def OnNoteOn(event):
prnt('OnNoteOn()', utils.GetNoteName(event.data1),event.data1,event.data2)
pass
def OnNoteOff(event):
prnt('OnNoteOff()', utils.GetNoteName(event.data1),event.data1,event.data2)
pass
#endregion
#region Handlers
def HandleChannelStrip(padNum): #, isChannelStripB):
global _PatternMap
global _ChannelMap
global _CurrentChannel
# global _PreviousChannel
global _ChannelCount
global _OrigColor
if(isMixerMode()):
return HandleMixerEffectsStrip(padNum)
if(isPlaylistMode()):
if(_SHOW_PROGRESS):
return HandleProgressBar(padNum)
else:
return True
prevChanIdx = getCurrChanIdx() # channels.channelNumber()
pageOffset = getChannelOffsetFromPage()
padOffset = 0
chanApads, chanBPads = 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 = 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(newChanIdx == prevChanIdx): # if it's already on the channel, toggle the windows
if( not _PadMode.NavSet.ColorPicker):
if(_ShiftHeld) and (Settings.SHOW_CHANNEL_MUTES): # new
if(_DoubleTap):
ui.showWindow(widPianoRoll)
macZoom.Execute(Settings.DBL_TAP_ZOOM)
else:
ShowPianoRoll(-1)
else:
ShowChannelEditor(-1)
else:
SelectAndShowChannel(newChanIdx)
if(_PadMode.NavSet.ColorPicker): # color picker mode
if(not isChannelStripB):
_OrigColor = FLColorToPadColor(channels.getChannelColor(getCurrChanIdx()), 1)
channels.setChannelColor(getCurrChanIdx(), _NewColor)
RefreshColorPicker()
SetPadMode()
return True
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 +
RefreshChannelStrip(False)
else: #old
channels.muteChannel(newChanIdx)
ui.crDisplayRect(0, newChanIdx, 0, 1, _rectTime, CR_ScrollToView + CR_HighlightChannelMute) # CR_HighlightChannels +
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 +
RefreshChannelStrip(False)
else: #old