-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIRE_NFX_OG_plus.py
3089 lines (2626 loc) · 131 KB
/
FIRE_NFX_OG_plus.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=AKAI FL Studio Fire OG+ v3
# url=https://forum.image-line.com/viewtopic.php?p=1496543#p1496543
# receiveFrom=AKAI FL Studio Fire
import patterns
import channels
import mixer
import device
import transport
import arrangement
import general
import launchMapPages
import playlist
import ui
import screen
import plugins
from midi import *
import utils
import time
import OG_plus_harmonicScales
import OG_plus_nfx_Helpers
from fireNFX_Defs import *
from OG_plus_defs import *
class TAccentModeParams:
def __init__(self, pitch, vel, pan, modx, mody):
self.Pitch = pitch
self.Vel = vel
self.Pan = pan
self.ModX = modx
self.ModY = mody
class TiniKeyRecord:
def __init__(self, name, prt):
self.Name = name
self.prt = prt
class TiniKeySection:
def __init__(self, name, keys):
self.Name = name
self.keys = keys
class TMidiEvent:
def __init__(self):
self.handled = False
self.timestamp = 0
self.status = 0
self.data1 = 0
self.data2 = 0
self.port = 0
self.isIncrement = 0
self.res = 0.0
self.inEV = 0
self.outEV = 0
self.midiId = 0
self.midiChan = 0
self.midiChanEx = 0
self.SenderId = 0
self.pmeFlags = 0
self.sysexLen = 0
self.sysexData = 0
class TFire():
def __init__(self):
self.FPCNoteMap = {}
self.ChanRackOfs = 0
self.ChanRackStartPos = 0
self.TrackOfs = 0
self.ClipOfs = 0
self.BtnT = bytearray(IdxButtonLast) # see buttons indexes above
self.BtnLastClip = [0 for x in range(PadsH * PadsW)]
for n in range(0, len(self.BtnLastClip)):
self.BtnLastClip[n] = utils.TClipLauncherLastClip(MaxInt, MaxInt, MaxInt)
self.BtnMap = [0] * 64
self.PlayingNotes = bytearray(0)
self.PlayingChannels = [] # for "omni" drum mode
self.CurStep = 0 # current playing step when FL plays
self.MuteBtnStates = [False] * 4 # to know if mute buttons are held
self.DidTweakLooping = False
self.CurrentNoteGrid = [[0 for x in range(PadsH)] for y in range(PadsW)]
self.SlavedDevices = {} # port -> mode layout
self.MultiDeviceMode = MultiDev_Single
self.SlaveModeLayout = 0 # see SlaveModeLayout_ constants
self.SlaveLayoutSelectionMode = False # when True, shows a menu to select the slave layout
self.AnalyzerMode = 0
self.AnalyzerChannel = 0
self.AnalyzerFlipX = False
self.analyzerFlipY = False
self.AnalyzerScrollX = False
self.AnalyzerScrollY = False
self.CurrentMode = 0
self.NonVisMode = 0
self.OldMode = 0
self.OldMode = 0 # see mode constants
self.AccentMode = False # True when "accent" is enabled in step seq mode
self.AccentParams = TAccentModeParams(0, 0, 0, 0, 0) # default param values of steps in accent mode
self.OverviewMode = False # True when in "overview" in perf mode
self.BrowserMode = False # True when "browser" is enabled
self.BrowserShouldClose = False
self.BrowserShouldAutoHide = False # to restore the state of the browser when exiting browser mode
self.JogWheelPushed = False # True when holding down the jogwheel
self.JogWheelHeldTime = 0.0 # time (number of idle calls) during which the Jog button was held
self.GridBtnHeldTime = 0 # time (number of idle calls) during which the grid buttons were held
self.GridBtnHeldTriggerTime = 0 # time before it retriggers the same action (reduces the more you hold)
self.GridUpBtnHeld = False
self.GridDownBtnHeld = False # True if either grid buttons are pressed
self.PatBtnHeldTime = 0 # time (number of idle calls) during which the pattern up | down button was held
self.PatUpBtnHeld = False
self.PatDownBtnHeld = False # True if either (or both) pat up | pat down buttons are held
self.PatBtnHeldTriggerTime = 0 # time before it retriggers the same action (reduces the more you hold)
self.CurrentKnobsMode = 0 # active mode for knobs (CR, mixer, user1, user2)
self.CurrentMixerTrack = 0 # mixer track being tweaked by the knobs
self.CurrentNoteMode = 0
self.OldNoteMode = 0 # for notes mode (dual keyboards | scales)
self.CurrentDrumMode = 0 # for drum mode (FPC, Slicex, etc)
self.TopText = '' # text at the top of the screen
self.DisplayedText = '' # central text (bigger)
self.KeyOffset = 36 # for notes mode
self.TextTimer = 0 # to make the text disappear after a while
self.TopTextTimer = 0.0
self.DisplayZoneTimer = 0 # to make the self.Display zone disappearing after using the jog
self.BlinkTimer = 0 # to make buttons blink
self.TrackSelIdleValue = 0 # for the idle anim of the track selectors (when "receive notes from" is active)
self.HeldPadsChanged = False # True when held pads were tweaked via knobs/jogwheel (to avoid switching their state after changing a param)
self.ShiftHeld = False
self.AltHeld = False # True when holding shift | alt buttons
self.LayoutSelectionMode = False # True when selection the layout in notes mode
self.MixerTrackSelectionMode = False # True when assigning a channel's mixer track
self.TouchingKnob = False # Is the user currently handling a knob?
self.KnobTouched = 0 # The knob the user is currently touching
self.UHP = 0
self.UHC = 0
self.UHL = 0 # Stored history (undo) positions
self.ChangeFlag = False # Set if the user changes a step parameter
self.MasterDeviceChanRackOfs = 0
self.MasterDeviceChanRackStartPos = 0
self.MasterDeviceClipOfs = 0
self.MasterTrackOfs = 0
self.MasterClipOfs = 0
self.bmpTimer = 0 #TDateTime
self.NoteColorSet = 0
self.LastRawData1 = 0
self.LastRawData2 = 0
self.LastIdleSec = 0
self.IdleFPS = 0
self.ScreenMode = ScreenModeNone
self.KnobsV = [0] * 4
self.HeldPads = bytearray(0)
self.PlayingPads = []
#todo def GetEventForPad(Device: TMIDIInDevice_Fire PadNum): pRecEvent
#todo def GetTimeForPad(Device: TMIDIInDevice_Fire PadNum):
self.KeyColorsDefault = [[0xFF4000, 0xFFFFFF, 0x0F0F0F, 0x7F7F7F, 0x9CFF00, 0x00FF00, 0x80FF00, 0xFFFF00, 0xFF4000, 0x000080, 0x0060FF, 0x000080], [0x00FFFF, 0xFFFFFF, 0x0F0F0F, 0x7F7F7F, 0xFF4000, 0x00FFFF, 0x7FFFFF, 0xFFFFFF, 0xFF0000, 0x000080, 0x0060FF, 0x000080]]
self.KeyColors = [[0 for x in range(7 + PadsH+ 1)] for y in range(2)]
self.FLFirePadBrightness = 0
self.FLFirePadSaturation = 0
self.FLFireDeviceCount = 0
self.IdleDeviceCount = 0
self.AnalyzerHue = 0.0
def LoadKeyColors(self):
for n in range(0, 2):
for i in range(0, 7 + PadsH+ 1):
self.KeyColors[n][i] = self.KeyColorsDefault[n][i]
def OnInit(self):
self.FLFireDeviceCount += 1
if self.FLFireDeviceCount == 1: # first (or only) FL Fire unit. Load the settings
self.LoadKeyColors()
self.FLFirePadBrightness = 96
self.FLFirePadSaturation = 101
self.FromToReg(False)
self.ScreenMode = ScreenModeNone
self.CurStep = -1
self.ChanRackOfs = 0
self.ChanRackStartPos = 0
self.TrackOfs = 0
self.ClipOfs = 0
self.KeyOffset = 36
self.CurrentMode = ModeStepSeq
self.OldMode = 128 # make sure it's invalid not to miss the first update
self.CurrentKnobsMode = KnobsModeChannelRack
self.CurrentNoteMode =NoteModeDualKeyb
self.OldNoteMode = -1
self.CurrentDrumMode = DrumModeFPC #DrumModeFPCCenter
self.TopText = 'FL Studio'
self.DisplayedText = ''
self.ShiftHeld = False
self.AltHeld = False
self.OverviewMode = False
self.JogWheelPushed = False
self.JogWheelHeldTime = 0
self.BrowserMode = False
self.BrowserShouldClose = False
self.BrowserShouldAutoHide = False
self.TextTimer = 0
self.TopTextTimer = 0.0
self.DisplayZoneTimer = 0
self.BlinkTimer = 0
self.HeldPadsChanged = False
self.TrackSelIdleValue = 0
self.CurrentMixerTrack = 0
self.MultiDeviceMode = MultiDev_Single
self.SlaveModeLayout = SlaveModeLayout_Right # to the right by default
self.MasterDevice = 0
self.SlavedDevices = {}
self.TouchingKnob = False
self.KnobTouched = 0
self.PatBtnHeldTime = 0
self.PatUpBtnHeld = False
self.PatDownBtnHeld = False
self.PatBtnHeldTriggerTime = HeldButtonRetriggerTime
self.GridBtnHeldTime = 0
self.GridUpBtnHeld = False
self.GridDownBtnHeld = False
self.GridBtnHeldTriggerTime = HeldButtonRetriggerTime // 2
for n in range(0, 4):
self.MuteBtnStates[n] = False
self.DidTweakLooping = False
self.AccentParams = TAccentModeParams(DotNote_Default, 100, 64, 127, 0)
self.DisplayWidth = 128
self.DisplayHeight = 64
for n in range(0, len(self.BtnT)):
self.BtnT[n] = 0
self.ClearBtnMap()
self.ClearAllButtons()
launchMapPages.createOverlayMap(1, 8, PadsW, PadsH)
for y in range(0, PadsH):
for x in range(0, PadsW):
launchMapPages.setMapItemTarget(-1, y * PadsW + x, y * PadsStride + x)
screen.init(self.DisplayWidth, self.DisplayHeight, TextRowHeight, FireFontSize, 0xFFFFFF, 0)
sysexHeader = int.from_bytes(bytes([MIDI_BEGINSYSEX, ManufacturerIDConst, DeviceIDBroadCastConst ,ProductIDConst, MsgIDSendPackedOLEDData]), byteorder='little')
screen.setup(sysexHeader, ScreenActiveTimeout, ScreenAutoTimeout, TextScrollPause, TextScrollSpeed, TextDisplayTime)
self.BgCol = 0x000000
self.FgCol = 0xFFFFFF
self.DiCol = 0xFFFFFF
screen.fillRect(0, 0, self.DisplayWidth, self.DisplayHeight, 0)
self.bmpTimer = time.time()
self.Reset()
self.SetOfs(self.TrackOfs, self.ClipOfs)
self.ClearDisplay()
# OG Pattern lights
# self.SendCC(IDPatternUp, SingleColorHalfBright)
# self.SendCC(IDPatternDown, SingleColorOff)
print("OG+ Mode")
def OnProjectLoad(self,status):
pass
def OnDoFullRefresh(self):
pass
def OnDirtyChannel(self,chan, flags):
pass
def OnNoteOn(self,event):
pass
def OnNoteOff(self,event):
pass
def OnSysEx(self, event):
pass
def OnSendTempMsg(self, msg, duration):
pass
def OnDirtyMixerTrack(self,track):
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 OnDeInit(self):
if self.FLFireDeviceCount == 1: # last (or only) FL Fire unit. Save the settings
self.FromToReg(True)
self.Reset()
screen.deInit()
self.FLFireDeviceCount -= 1
def CutPlayingNotes(self):
if (len(self.PlayingNotes) == 0) & (len(self.PlayingChannels) == 0):
return
#for n in range(0, len(self.PlayingChannels)):
# if utils.InterNoSwap(self.PlayingChannels[n], 0, channels.channelCount()):
# channels.midiNoteOn(self.PlayingChannels[n], DotNote_Default, -127)
self.PlayingChannels = []
chanNum = self.IsLockedByReceiveNotesFrom()
if chanNum < 0:
chanNum = channels.channelNumber()
if chanNum < 0:
return
#for n in range(0, len(self.PlayingNotes)):
# channels.midiNoteOn(chanNum, self.PlayingNotes[n], -127) # negative vel for note off
self.PlayingNotes = bytearray(0)
def Reset(self):
self.ClearAllPads()
self.CurStep = -1
self.ClearAllButtons()
self.ClearDisplay()
self.ClearBtnMap()
self.ClearKnobsMode()
self.PlayingNotes = bytearray(0)
self.PlayingChannels = []
def FromToReg(self, ToReg):
return
#todo IntegerFromToReg(['PadBrightness', 'PadSaturation'], [@self.FLFirePadBrightness, @self.FLFirePadSaturation], FIniFile, Ini_Devices + '\' + FLFireDeviceName, ToReg)
def Sign(self, AValue):
Result = 0
if AValue < 0:
Result = -1
elif AValue > 0:
Result = 1
return Result
def DisplayText(self, Font, Justification, PageTop, Text, CheckIfSame, DisplayTime = 0):
screen.displayText(Font, Justification, PageTop, Text, CheckIfSame, DisplayTime)
def DisplayBar(self, Text, Value, Bipolar):
screen.displayBar(0, TextRowHeight * TimedTextRow, Text, Value, Bipolar)
def DisplayTimedText(self, Text):
screen.displayTimedText(Text, TimedTextRow)
def OnDisplayZone(self):
if self.MultiDeviceMode == MultiDev_Slave:
self.DispatchMessageToDeviceScripts(SM_SlaveUpdateDisplayZone, 0, 0, 0)
else:
if playlist.getDisplayZone() != 0:
R = self.GetGridRect(ModePerf)
playlist.liveDisplayZone(R.Left, R.Top, R.Right, R.Bottom, 2000)
else:
playlist.liveDisplayZone(-1, -1, -1, -1, 2000)
def GetChanRackOfs(self):
if (self.MultiDeviceMode == MultiDev_Single) | (self.MultiDeviceMode == MultiDev_Master):
if not channels.isHighLighted():
self.ChanRackOfs = 0
return self.ChanRackOfs
else:
return self.MasterDeviceChanRackOfs + SlaveModeLayoutYShift[self.SlaveModeLayout]
def GetChanRackStartPos(self):
if (self.MultiDeviceMode == MultiDev_Single) | (self.MultiDeviceMode == MultiDev_Master):
if not channels.isHighLighted():
self.ChanRackStartPos = 0
return self.ChanRackStartPos
else:
return self.MasterDeviceChanRackStartPos + SlaveModeLayoutXShift[self.SlaveModeLayout]
def GetClipOfs(self):
if (self.MultiDeviceMode == MultiDev_Single) | (self.MultiDeviceMode == MultiDev_Master):
return self.ClipOfs
else:
return self.MasterDeviceClipOfs + SlaveModeLayoutXShift[self.SlaveModeLayout]
def GetGridRect(self, Mode):
if Mode == ModeStepSeq:
ofsX = self.GetChanRackStartPos()
ofsY = self.GetChanRackOfs()
elif Mode == ModePerf:
ofsX = self.GetClipOfs()
ofsY = self.GetTrackOfs() + 1
else:
ofsX = 0
ofsY = 0
r = utils.TRect(ofsX, ofsY, PadsW, PadsH)
if Mode == ModePerf:
r.Right += ofsX
r.Bottom += ofsY
Result = r
if self.MultiDeviceMode == MultiDev_Single:
Result = r
elif self.MultiDeviceMode == MultiDev_Slave:
Result = r #Result = self.MasterDevice.GetGridRect(Mode) #todo
print('todo')
else: #is master
for port, layout in self.SlavedDevices.items():
if layout == SlaveModeLayout_Right:
r.Right += PadsW
elif layout == SlaveModeLayout_Bottom:
r.Bottom += PadsH
Result = r
return Result
def GetTrackOfs(self):
if (self.MultiDeviceMode == MultiDev_Single) | (self.MultiDeviceMode == MultiDev_Master):
return self.TrackOfs
else:
return self.MasterTrackOfs + SlaveModeLayoutYShift[self.SlaveModeLayout]
def GetNoteModeName(self):
if self.CurrentNoteMode == NoteModeDualKeyb:
return 'Dual keyboard'
else:
scale = self.CurrentNoteMode - 1
return OG_plus_harmonicScales.HarmonicScaleNamesT[scale]
def GetOmniNoteValue(self, Data1):
y = Data1 // PadsStride
x = Data1 - y * PadsStride
y = PadsH- 1 - y # invert y (we want bottom to top)
return x + y * PadsStride # rebuild pad num
def GetSlicexNoteValue(self, Data1):
y = Data1 // PadsStride
x = Data1 - y * PadsStride
y = PadsH- 1 - y # invert y (we want bottom to top)
Result = x + y * PadsStride # rebuild note num
Result += 5 * 12 # +5 octaves
return Result
def GetStepParam(self, Step, Param):
return channels.getStepParam(Step, Param, self.GetChanRackOfs(), self.GetChanRackStartPos(), PadsStride)
def GetCurStepParam(self, ChanIndex, Param):
return channels.getCurrentStepParam(ChanIndex, self.CurStep, Param)
def GetDualKeybWhiteNoteVal(self, x, y):
conv = [0, 2, 4, 5, 7, 9, 11, 0 + 12, 2 + 12, 4 + 12, 5 + 12, 7 + 12, 9 + 12, 11 + 12, 0 + 24, 2 + 24]
if x < 16:
Result = conv[x]
else:
Result = -1
if Result >= 0:
Result += self.KeyOffset + (12 * int(y >= 2)) # two octaves up in keyb mode
return max(0, min(Result, 127))
def GetFPCNoteValue(self, Data1):
result = -1
if(Data1 in self.FPCNoteMap.keys()):
result =self.FPCNoteMap[Data1]
#print("FPCNoteMap Pad:", Data1, '=', result)
return result
# convert to FPC notes
# if Data1 ==52:
# Result = 37 # C#3
# elif Data1 ==53:
# Result = 36 # C3
# elif Data1 ==54:
# Result = 42 # F#3
# elif Data1 ==55:
# Result = 54 # F#4
# elif Data1 ==56:
# Result = 60 # C5
# elif Data1 ==57:
# Result = 61 # C#5
# elif Data1 ==58:
# Result = 62 # D5
# elif Data1 ==59:
# Result = 63 # D#5
# elif Data1 ==36:
# Result = 40 # E3
# elif Data1 ==37:
# Result = 38 # D3
# elif Data1 ==38:
# Result = 46 # A#3
# elif Data1 ==39:
# Result = 44 # G#3
# elif Data1 ==40:
# Result = 64 # E5
# elif Data1 ==41:
# Result = 65 # F5
# elif Data1 ==42:
# Result = 66 # F#5
# elif Data1 ==43:
# Result = 67 # G5
# elif Data1 ==20:
# Result = 48 # C4
# elif Data1 ==21:
# Result = 47 # B3
# elif Data1 ==22:
# Result = 45 # A3
# elif Data1 ==23:
# Result = 43 # G3
# elif Data1 ==24:
# Result = 68 # G#5
# elif Data1 ==25:
# Result = 69 # A5
# elif Data1 ==26:
# Result = 70 # A#5
# elif Data1 ==27:
# Result = 71 # B5
# elif Data1 == 4:
# Result = 49 # C#4
# elif Data1 == 5:
# Result = 55 # G4
# elif Data1 == 6:
# Result = 51 # D#4
# elif Data1 == 7:
# Result = 53 # F4
# elif Data1 == 8:
# Result = 72 # C6
# elif Data1 == 9:
# Result = 73 # C#6
# elif Data1 == 10:
# Result = 74 # D6
# elif Data1 == 11:
# Result = 75 # E6
# else:
# Result = -1
# return Result
def GetDualKeybBlackNoteVal(self, x, y):
conv = (-1, 1, 3, -1, 6, 8, 10, -1, 1 + 12, 3 + 12, -1, 6 + 12, 8 + 12, 10 + 12, -1, 1 + 24)
if x < 16:
Result = conv[x]
else:
Result = -1
if Result >= 0:
Result += self.KeyOffset + (12 * int(y >= 2)) # two octaves up in keyb mode
return max(0, min(Result, 127))
return Result
def OnIdle(self):
def BlinkBtn(b, id):
if not device.isAssigned():
return
if b:
if self.BlinkTimer < BlinkSpeed:
self.SendCC(id, DualColorFull2)
else:
self.SendCC(id, DualColorOff)
else:
self.SendCC(id, DualColorOff)
#************
if self.IdleDeviceCount == 0:
self.IdleDeviceCount = self.FLFireDeviceCount
self.AnalyzerHue = self.AnalyzerHue + 10
if self.AnalyzerHue >= 360:
self.AnalyzerHue = self.AnalyzerHue - 360
else:
self.IdleDeviceCount -= 1
TopLineJustify = JustifyLeft
if self.SlaveLayoutSelectionMode: # this mode takes over the other ones (it's "blocking")
self.TopText = 'Slave device layout'
self.DisplayTimedText(SlaveModeLayoutNamesT[self.SlaveModeLayout])
self.TopTextTimer = 0
elif self.TopTextTimer > 0:
TopLineJustify = JustifyCenter
self.TopTextTimer = self.TopTextTimer - device.getIdleElapsed()
if self.TopTextTimer < 0:
self.TopTextTimer = 0
else:
s = patterns.getPatternName(patterns.patternNumber())
if transport.getLoopMode() == SM_Pat:
self.TopText = s
else:
self.TopText = 'Song (' + s + ')'
if self.LayoutSelectionMode:
self.TopText = 'Layout select'
self.CurStep = mixer.getSongStepPos() # set current playing step
self.DisplayText(Font6x16 , TopLineJustify, 0, self.TopText, True)
#NFX - show ALT + options
self.DisplayText(Font6x16, JustifyLeft, 1, '', True) # clear line
self.DisplayText(Font6x16, JustifyLeft, 2, '', True) # clear line
if(self.AltHeld):
self.DisplayText(Font6x16, JustifyLeft, 0, 'Alt +', True)
self.DisplayText(Font6x16, JustifyLeft, 1, 'DRUM = COPY', True)
self.DisplayText(Font6x16, JustifyLeft, 2, 'PERF = PASTE', True)
elif self.JogWheelPushed & self.AltHeld:
self.JogWheelHeldTime = self.JogWheelHeldTime + device.getIdleElapsed()
if self.JogWheelHeldTime >= 2000:
self.JogWheelHeldTime = 0
self.SetAsMasterDevice(not self.IsMasterDevice())
else:
self.JogWheelHeldTime = 0
self.BlinkTimer += 1
if self.BlinkTimer >= BlinkSpeed * 2:
self.BlinkTimer = 0
if (self.PatDownBtnHeld | self.PatUpBtnHeld) & (not self.AltHeld):
self.PatBtnHeldTime += 1
if self.PatBtnHeldTime >= self.PatBtnHeldTriggerTime:
self.PatBtnHeldTime = 0
# resend pat up/down while button is held
if self.PatBtnHeldTriggerTime > 2:
self.PatBtnHeldTriggerTime -= 1 # make it go faster & faster
fakeMidi = TMidiEvent()
fakeMidi.handled = 0
fakeMidi.midiId = MIDI_NOTEON
if self.PatDownBtnHeld:
fakeMidi.data1 = IDPatternDown
else:
fakeMidi.data1 = IDPatternUp
fakeMidi.data2 = 127
self.OnMidiMsg(fakeMidi) # NFX
else:
self.PatBtnHeldTime = 0
self.PatBtnHeldTriggerTime = HeldButtonRetriggerTime # reset to max time
if (self.GridDownBtnHeld | self.GridUpBtnHeld) & (not self.BrowserMode):
self.GridBtnHeldTime += 1
if self.GridBtnHeldTime >= self.GridBtnHeldTriggerTime:
self.GridBtnHeldTime = 0
# resend Grid up/down while button is held
if self.GridBtnHeldTriggerTime > 2:
self.GridBtnHeldTriggerTime -= 1 # make it go faster & faster
fakeMidi = TMidiEvent()
fakeMidi.handled = 0
fakeMidi.midiId = MIDI_NOTEON
if self.GridDownBtnHeld:
fakeMidi.data1 = IDBankR
else:
fakeMidi.data1 = IDBankL
fakeMidi.data2 = 127
oldShift = self.ShiftHeld
oldAlt = self.AltHeld
self.ShiftHeld = False
self.AltHeld = False
self.OnMidiMsg(fakeMidi)
self.ShiftHeld = oldShift
self.AltHeld = oldAlt
else:
self.GridBtnHeldTime = 0
self.GridBtnHeldTriggerTime = HeldButtonRetriggerTime # reset to max time
if self.TextTimer > 0:
self.TextTimer -= 1
if self.TextTimer == 0:
self.DisplayTimedText(chr(13))
if self.DisplayZoneTimer > 0:
self.DisplayZoneTimer -= 1
if self.DisplayZoneTimer == 0:
playlist.lockDisplayZone(1 + self.GetTrackOfs(), False)
self.UpdateCurrentKnobsMode()
self.UpdateCurrentPadsMode()
self.RefreshTransport()
if self.ShiftHeld:
# metronome status
BlinkBtn(ui.isMetronomeEnabled(), IDPatternSong)
# wait before rec
BlinkBtn(ui.isStartOnInputEnabled(), IDPlay)
# countdown
BlinkBtn(ui.isPrecountEnabled(), IDStop)
# looprec
BlinkBtn(ui.isLoopRecEnabled(), IDRec)
# snap
BlinkBtn(ui.getSnapMode() != Snap_None, IDNote)
# accent
BlinkBtn(self.AccentMode, IDStepSeq)
# overview
BlinkBtn(self.OverviewMode, IDPerform)
elif self.AltHeld: # NFX added copy/paste
self.SendCC(IDStepSeq, SingleColorOff)
self.SendCC(IDNote, SingleColorOff)
self.SendCC(IDDrum, SingleColorHalfBright) # copy
self.SendCC(IDPerform, SingleColorHalfBright) # paste
else:
self.UpdateCurrentModeBtns()
res = screen.findTextLine(0, 20, 128, 20 + 44)
if (res < 0) & (self.ScreenMode != ScreenModeNone):
i = self.ScreenMode
self.ScreenMode = ScreenModeNone
self.SetScreenMode(i)
screen.animateText(self.ScreenMode)
t = time.time()
if self.LastIdleSec == 0:
self.LastIdleSec = t
self.IdleFPS = 0
else:
if t < self.LastIdleSec:
# i = Integer((Int64(t) + 0x100000000) - Int64(self.LastIdleSec)) # rewrote for syntax issues. python doesnt support Integer or Int64
i = int((int(t) + 0x100000000) - int(self.LastIdleSec))
else:
i = (t - self.LastIdleSec)
if i >= 1000:
screenActiveCounter = screen.getScreenActiveCounter()
if (screenActiveCounter > 0) & (not screen.isBlanked()):
screenActiveCounter -= 1
screen.setScreenActiveCounter(screenActiveCounter)
if screenActiveCounter > ScreenAutoTimeout:
screen.keepDisplayActive()
elif screenActiveCounter == 0:
screen.blank(True, self.ScreenMode)
self.LastIdleSec = t
R = utils.TRect(0, TextRowHeight * FPSRow, self.DisplayWidth, (TextRowHeight * FPSRow) + TextRowHeight)
R2 = R
utils.OffsetRect(R2, 0, TextOffset)
screen.eraseRect(R2.Left, R2.Top, R2.Right, R2.Bottom)
screen.drawText(0, 'FPS: ' + str(self.IdleFPS), R2.Left, R2.Top, R2.Right, R2.Bottom)
self.IdleFPS = 0
else:
self.IdleFPS += 1
if screen.isUnBlank():
screen.blank(False, self.ScreenMode)
screen.update()
screen.unBlank(False)
def Init(self):
self.Reset()
self.SetOfs(self.TrackOfs, self.ClipOfs)
self.ClearDisplay()
def IsLockedByReceiveNotesFrom(self):
for n in range(0, channels.channelCount()):
if channels.getChannelMidiInPort(n) == device.getPortNumber():
return(n)
return -1
def IsMasterDevice(self):
return self.MultiDeviceMode == MultiDev_Master
def TranslateNote(self, event):
Data1 = event.data1
Data2 = 0
Result = True
if (Data1 >= PadFirst) & (Data1 <= PadLast):
Data1 -= PadFirst
Data2 = event.data2
if self.CurrentMode == ModeNotes:
Data2 = self.AdaptVelocity(Data2)
y = Data1 // PadsStride
x = Data1 - y * PadsStride
if self.CurrentNoteMode != NoteModeDualKeyb:
Data1 = self.CurrentNoteGrid[x][ y]
Data1 = max(0, min(Data1, 127))
else:
y = PadsH- 1 - y # invert y (we want bottom to top)
if y % 2 == 0:
# white notes
Data1 = self.GetDualKeybWhiteNoteVal(x, y)
if Data1 < 0:
Result = False
return Result
else:
# black notes
Data1 = self.GetDualKeybBlackNoteVal(x, y)
if Data1 < 0:
Result = False
return Result
elif self.CurrentMode == ModeDrum:
if self.CurrentDrumMode in [DrumModeFPC, DrumModeFPCCenter]:
# if (self.CurrentDrumMode == DrumModeFPCCenter):
# Data1 += 4 # offset to match center layout
Data1 = self.GetFPCNoteValue(Data1)
elif self.CurrentDrumMode == DrumModeSlicex:
Data1 = self.GetSlicexNoteValue(Data1)
elif self.CurrentDrumMode == DrumModeOmni:
Data1 = self.GetOmniNoteValue(Data1)
if Data1 < 0:
Result = False
if Result:
event.data1 = Data1
event.data2 = Data2
return Result
def OnMidiIn(self, event):
if ((event.status == MIDI_NOTEON) | (event.status == MIDI_NOTEOFF)) & utils.InterNoSwap(event.data1, IDKnob1, IDKnob4) & self.ShiftHeld:
print('Ignored note on/off')
return
else:
self.LastRawData1 = event.data1
self.LastRawData2 = event.data2
if (event.status & 0xF0) in [MIDI_NOTEON, MIDI_NOTEOFF]:
if not self.TranslateNote(event):
event.handled = False #todo
return
if event.status == 0xF4:
ID = event.sysex[4]
data1 = event.sysex[7] + (event.sysex[8] << 7)
data2 = event.sysex[9] + (event.sysex[10] << 7)
data3 = event.sysex[11] + (event.sysex[12] << 7)
if ID == SM_SetAsSlave:
self.SetAsSlaveDevice(data1)
self.DispatchMessageToDeviceScripts(SM_SlaveDeviceModeLayout, self.SlaveModeLayout, device.getPortNumber(), 0)
elif ID == SM_SetAsSingle:
self.SetAsSingleDevice()
elif ID == SM_MasterDeviceChanRackOfs:
if self.MultiDeviceMode == MultiDev_Slave:
self.MasterDeviceChanRackOfs = data1
self.SetChanRackOfs(0, False)
elif ID == SM_MasterDeviceChanStartPos:
self.MasterDeviceChanRackStartPos = data1
elif ID == SM_SlaveDeviceSetOfs:
if self.MultiDeviceMode == MultiDev_Master:
self.SetOfs(self.GetTrackOfs() + data1 - 128, self.GetClipOfs() + data2 - 128, False)
self.DispatchMessageToDeviceScripts(SM_MasterDeviceSetOfs, self.TrackOfs + 128, self.ClipOfs + 128, 0)
elif ID == SM_MasterDeviceSetOfs:
if self.MultiDeviceMode == MultiDev_Slave:
self.MasterTrackOfs = data1 - 128
self.MasterClipOfs = data1 - 128
self.SetOfs(self.MasterTrackOfs, self.MasterClipOfs, False)
elif ID == SM_SlaveDeviceStartPos:
if self.MultiDeviceMode == MultiDev_Master:
self.SetChanRackStartPos(self.GetChanRackStartPos() + data1 - 128, False)
elif ID == SM_SlaveDeviceRackOfs:
if self.MultiDeviceMode == MultiDev_Master:
self.SetChanRackOfs(self.GetChanRackOfs() + data1 - 128, False)
self.DispatchMessageToDeviceScripts(SM_MasterDeviceChanRackOfs, self.ChanRackOfs, 0, 0)
elif ID == SM_UpdateLiveMode:
if self.MultiDeviceMode == MultiDev_Slave:
self.OnUpdateLiveMode(1, playlist.trackCount())
elif ID == SM_SlaveDeviceModeLayout:
if self.MultiDeviceMode == MultiDev_Master:
self.SlavedDevices[data2] = data1
elif ID == SM_SlaveUpdateDisplayZone:
if self.MultiDeviceMode == MultiDev_Master:
self.OnDisplayZone()
event.handled = True
# def GetTimeForPad(self, Device, PadNum):
# Result = (self.GetChanRackStartPos() + PadNum - ((PadNum // PadsStride) * PadsStride)) * RecPPS
# return Result # added - NFX
def GetChannelNumForPad(self, PadNum):
Result = -1
padRow = PadNum // PadsStride
if self.CurrentMode == ModeStepSeq:
if not utils.InterNoSwap(padRow + self.GetChanRackOfs(), 0, channels.channelCount() - 1):
return
Result = padRow + self.GetChanRackOfs()
return Result
# def GetEventForPad(self, PadNum):
# Result = -1
# #chNum = self.GetChannelNumForPad(Device, PadNum)
# chNum = self.GetChannelNumForPad(PadNum) # NFX fixed too many args
# if chNum > -1:
# cID = channels.getChannelIndex(chNum)
# Time = self.GetTimeForPad(Device, PadNum)
# if Assigned(PatInfoT[patterns.patternNumber()].NoteRecChan):
# for i in range(0, Count):
# Event = pNoteEvent(GetEventAtPos(i))
# if (Event.ChanID == cID) & (((Event.Time // RecPPS) * RecPPS) == Time):
# Result = pRecEvent(Event)
# return
# return Result
def OnMidiMsg(self, event):
tempHeldPads = bytearray()
ParamNames = ('Step pitch', 'Velocity', 'Release', 'Fine pitch', 'Panning', 'Mod X', 'Mod Y', 'Shift')
def SetStep(padNum, Force):
Result = False
padRow = padNum // PadsStride
padCol = padNum - padRow * PadsStride
general.saveUndo('Fire: Step seq edit', UF_PR, True)
if self.CurrentMode == ModeStepSeq:
if not utils.InterNoSwap(padRow + self.GetChanRackOfs(), 0, channels.channelCount() - 1):
return
index = padRow + self.GetChanRackOfs()
if channels.isGridBitAssigned(index):
if Force:
if channels.getGridBit(index, padCol + self.GetChanRackStartPos()) == 0:
channels.setGridBit(index, padCol + self.GetChanRackStartPos(), 1)
Result = True
else:
if channels.getGridBit(index, padCol + self.GetChanRackStartPos()) > 0:
channels.setGridBit(index, padCol + self.GetChanRackStartPos(), 0)
else:
channels.setGridBit(index, padCol + self.GetChanRackStartPos(), 1)
Result = True
return Result
def HandleStepSeqPad(id, padNum):
# store pads being held
if id == MIDI_NOTEON:
self.HeldPads.append(padNum)
else:
for i in range(0, len(self.HeldPads)):
if self.HeldPads[i] != padNum:
tempHeldPads.append(self.HeldPads[i])
self.HeldPads = bytearray(len(tempHeldPads))
for i in range(0, len(tempHeldPads)):
self.HeldPads[i] = tempHeldPads[i]
didSetStep = False
if id == MIDI_NOTEOFF:
didSetStep = SetStep(padNum, self.HeldPadsChanged) # if we tweaked a param, force the step on upon releasing
if self.AccentMode & didSetStep:
self.SetStepParam(padNum, pPitch, self.AccentParams.Pitch)
self.SetStepParam(padNum, pVelocity, self.AccentParams.Vel)
self.SetStepParam(padNum, pPan, self.AccentParams.Pan)
self.SetStepParam(padNum, pModX, self.AccentParams.ModX)
self.SetStepParam(padNum, pModY, self.AccentParams.ModY)
channels.updateGraphEditor()
if len(self.HeldPads) == 0:
self.HeldPadsChanged = False
channels.closeGraphEditor(True)
def HandleKnob(ID, Data2, Name, Bipolar):
mixer.automateEvent(ID, Data2, REC_MIDIController, 0, 1, EKRes)
barVal = device.getLinkedValue(ID)
self.DisplayBar(Name, barVal, Bipolar)
def HandleHeldPadsParam(Data2, Param):
ParamDefVal = (DotNote_Default, 100, 64, 120, 64, 128, 128, 0)