-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
3057 lines (2811 loc) · 104 KB
/
main.lua
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
-- set up include-path
_clibroot = 'cLib/classes/'
_xlibroot = 'xLib/classes/'
_trace_filters = nil
-- require some classes
require(_clibroot .. 'cDebug')
require(_clibroot .. 'cLib')
require(_xlibroot .. 'xLib')
require(_xlibroot .. 'xPatternSequencer')
rns = nil
local MY_INTERFACE
local MY_INTERFACE_RACK
local MIDI_IN
local MIDI_OUT
local OPTIONS = renoise.Document.create("ScriptingToolPreferences") {
MidiInput = "FL STUDIO FIRE",
MidiOutput = "FL STUDIO FIRE",
DevelopmentMode = false
}
renoise.tool().preferences = OPTIONS
local MIDI_IN_PORT = OPTIONS.MidiInput.value
local MIDI_OUT_PORT = OPTIONS.MidiOutput.value
local PAD_ROWS = 4
local PAD_COLUMNS = 16
local PADS = table.create()
local PADS_2ND = table.create()
local ROW_SELECT = table.create()
local ROW_SELECT_2ND = table.create()
local ROW_INDICATOR = table.create()
local ROW_INDICATOR_2ND = table.create()
local PADS_DEBUG = table.create()
local ROW_SELECT_DEBUG = table.create()
local ROW_INDICATOR_DEBUG = table.create()
local MODE_NOTE = 1
local MODE_DRUM = 2
local MODE_PERFORM = 3
local MODE_OVERVIEW = 4
local MODE = MODE_PERFORM
local NOTE_STEP_VIEW_POS = 1
local NOTE_COLUMN_VIEW_POS = 1
local NOTE_CURSOR_POS = 1
local PERFORM_HIDE_CURSOR = false
local PERFORM_TRACK_VIEW_POS = 1
local PERFORM_SEQUENCE_VIEW_POS = 1
local CURRENT_PATTERN
local CURRENT_LINE = -1
local CURRENT_SEQUENCE = -1
local CURRENT_TRACK = -1
local CURRENT_NOTE_COLUMN = -1
local PLAYBACK_LINE = -1
local PLAYBACK_SEQUENCE = -1
local PLAYBACK_NEXT_SEQUENCE = -1
local PLAYBACK_BEAT_IN_PATTERN = 1
local UI_MODE = 1
local UI_MODE_PRESSED = false
local UI_MODE_DEBUG
local UI_KNOB1_DEBUG
local UI_KNOB2_DEBUG
local UI_KNOB3_DEBUG
local UI_KNOB4_DEBUG
local UI_PAD_PRESSED_COUNT = 0
local UI_PAD_PROCESSED = false
local UI_BROWSE_PRESSED = false
local UI_BROWSE_DEBUG
local UI_PATTERN_PREV_DEBUG
local UI_PATTERN_NEXT_DEBUG
local UI_GRID_PREV_DEBUG
local UI_GRID_NEXT_DEBUG
local UI_STEP_PRESSED = false
local UI_STEP_LOCK = false
local UI_STEP_PROCESSED = false
local UI_STEP_DEBUG
local UI_NOTE_DEBUG
local UI_DRUM_DEBUG
local UI_PERFORM_DEBUG
local UI_SHIFT_PRESSED = false
local UI_SHIFT_DEBUG
local UI_ALT_PRESSED = false
local UI_ALT_DEBUG
local UI_SONG_DEBUG
local UI_PLAY_DEBUG
local UI_STOP_DEBUG
local UI_REC_DEBUG
local QUEUE_RENDER = false
local COLOR_OFF = { 0, 0, 0 }
local COLOR_RED_LOW = { 127, 0, 0 }
local COLOR_RED = { 255, 0, 0 }
local COLOR_GREEN = { 0, 255, 0 }
local COLOR_YELLOW = { 255, 255, 0 }
local INITIALIZED = false
function initialize()
renoise.tool().app_new_document_observable:add_notifier(function()
rns = renoise.song()
CURRENT_PATTERN = nil
rns_initialize()
end)
rns = nil
end
function rns_initialize()
for r = 1, PAD_ROWS do
PADS[r] = table.create()
PADS_2ND[r] = table.create()
ROW_SELECT[r] = { 0, 0, 0 }
ROW_SELECT_2ND[r] = { -1, -1, -1 }
ROW_INDICATOR[r] = { 0, 0, 0 }
ROW_INDICATOR_2ND[r] = { -1, -1, -1 }
for c = 1, PAD_COLUMNS do
PADS[r][c] = { 0, 0, 0, false }
PADS_2ND[r][c] = { -1, -1, -1, false }
end
end
if not INITIALIZED then
INITIALIZED = true
build_debug_interface()
midi_init()
ui_update_state_buttons()
ui_update_nav_buttons()
mark_as_dirty()
end
attach_notifier(nil)
if not (rns.selected_pattern_observable:has_notifier(attach_notifier)) then
rns.selected_pattern_observable:add_notifier(attach_notifier)
end
if not (renoise.tool().app_idle_observable:has_notifier(idler)) then
renoise.tool().app_idle_observable:add_notifier(idler)
end
if not (rns.tracks_observable:has_notifier(mark_as_dirty)) then
rns.tracks_observable:add_notifier(mark_as_dirty)
end
if not (rns.sequencer.pattern_sequence_observable:has_notifier(mark_as_dirty)) then
rns.sequencer.pattern_sequence_observable:add_notifier(mark_as_dirty)
end
if not (renoise.tool().app_release_document_observable:has_notifier(mark_as_dirty)) then
renoise.tool().app_release_document_observable:add_notifier(mark_as_dirty)
end
if not (rns.transport.playing_observable:has_notifier(ui_update_transport_buttons)) then
rns.transport.playing_observable:add_notifier(ui_update_transport_buttons)
end
if not (rns.transport.loop_pattern_observable:has_notifier(ui_update_transport_buttons)) then
rns.transport.loop_pattern_observable:add_notifier(ui_update_transport_buttons)
end
if not (rns.transport.edit_mode_observable:has_notifier(ui_update_transport_buttons)) then
rns.transport.edit_mode_observable:add_notifier(ui_update_transport_buttons)
end
idler()
end
function attach_notifier(_)
if CURRENT_PATTERN ~= nil then
CURRENT_PATTERN:remove_line_notifier(mark_as_dirty)
end
CURRENT_PATTERN = rns.selected_pattern
if not (CURRENT_PATTERN:has_line_notifier(mark_as_dirty)) then
CURRENT_PATTERN:add_line_notifier(mark_as_dirty)
end
mark_as_dirty()
ui_update_nav_buttons()
end
function mark_as_dirty()
QUEUE_RENDER = true
end
function idler(_)
local new_line_index = rns.selected_line_index
local new_sequence_index = rns.selected_sequence_index
local new_track_index = rns.selected_track_index
local new_note_column_index = rns.selected_note_column_index
local new_playback_line = rns.transport.playback_pos.line
local new_playback_sequence = rns.transport.playback_pos.sequence
local lpb = rns.transport.lpb
if CURRENT_LINE ~= new_line_index then
CURRENT_LINE = new_line_index
focus_line()
QUEUE_RENDER = true
end
if CURRENT_NOTE_COLUMN ~= new_note_column_index and new_note_column_index > 0 then
CURRENT_NOTE_COLUMN = new_note_column_index
focus_note_column()
QUEUE_RENDER = true
end
if CURRENT_TRACK ~= new_track_index and new_note_column_index > 0 then
CURRENT_TRACK = new_track_index
focus_track()
focus_note_column()
QUEUE_RENDER = true
end
if CURRENT_SEQUENCE ~= new_sequence_index then
CURRENT_SEQUENCE = new_sequence_index
focus_sequence()
QUEUE_RENDER = true
end
if UI_MODE ~= PLAYBACK_BEAT_IN_PATTERN then
UI_MODE = PLAYBACK_BEAT_IN_PATTERN
midi_mode(math.floor(16 * lpb * PLAYBACK_BEAT_IN_PATTERN / rns:pattern(rns.sequencer:pattern(PLAYBACK_SEQUENCE)).number_of_lines))
end
if QUEUE_RENDER then
QUEUE_RENDER = false
render()
render_debug()
elseif PLAYBACK_LINE ~= new_playback_line or PLAYBACK_SEQUENCE ~= new_playback_sequence then
PLAYBACK_LINE = new_playback_line
PLAYBACK_SEQUENCE = new_playback_sequence
PLAYBACK_BEAT_IN_PATTERN = math.floor(PLAYBACK_LINE / lpb)
if PLAYBACK_NEXT_SEQUENCE == PLAYBACK_SEQUENCE then
PLAYBACK_NEXT_SEQUENCE = -1
end
if MODE == MODE_DRUM or MODE == MODE_NOTE then
render_note_cursor(rns)
elseif MODE == MODE_PERFORM or MODE == MODE_OVERVIEW then
render()
end
render_debug()
end
end
function render()
if MODE == MODE_NOTE or MODE == MODE_DRUM then
render_note()
elseif MODE == MODE_PERFORM then
render_perform()
elseif MODE == MODE_OVERVIEW then
render_overview()
end
end
function render_debug()
-- render to debug surface
for r = 1, PAD_ROWS do
if ROW_SELECT[r][1] ~= ROW_SELECT_2ND[r][1] or ROW_SELECT[r][2] ~= ROW_SELECT_2ND[r][2] or ROW_SELECT[r][3] ~= ROW_SELECT_2ND[r][3] then
ROW_SELECT_2ND[r] = table.copy(ROW_SELECT[r])
midi_row(r, ROW_SELECT_2ND[r])
ROW_SELECT_DEBUG[r].color = ROW_SELECT_2ND[r]
end
if ROW_INDICATOR[r][1] ~= ROW_INDICATOR_2ND[r][1] or ROW_INDICATOR[r][2] ~= ROW_INDICATOR_2ND[r][2] or ROW_INDICATOR[r][3] ~= ROW_INDICATOR_2ND[r][3] then
ROW_INDICATOR_2ND[r] = table.copy(ROW_INDICATOR[r])
midi_indicator(r, ROW_INDICATOR_2ND[r])
ROW_INDICATOR_DEBUG[r].color = ROW_INDICATOR_2ND[r]
end
local sysex = midi_pad_start()
for c = 1, PAD_COLUMNS do
if PADS[r][c][1] ~= PADS_2ND[r][c][1] or PADS[r][c][2] ~= PADS_2ND[r][c][2] or PADS[r][c][3] ~= PADS_2ND[r][c][3] or PADS[r][c][4] ~= PADS_2ND[r][c][4] then
PADS_2ND[r][c] = table.copy(PADS[r][c])
local hsv = table.copy(PADS[r][c])
if hsv[2] == 0 and hsv[3] == 0 then
hsv[1] = 0
hsv[3] = 0
if hsv[4] then
hsv[2] = 0
hsv[3] = 0.2
end
else
if hsv[4] then
hsv[2] = hsv[2] - 0.2
hsv[2] = math.max(hsv[2], 0)
hsv[3] = math.min(hsv[3] + 0.2, 1.0)
end
end
hsv[1] = math.floor(hsv[1] * 12) / 12;
midi_pad(sysex, r, c, hsv_to_rgb(hsv))
end
end
midi_pad_end(sysex)
end
end
function focus_track()
if CURRENT_TRACK > PERFORM_TRACK_VIEW_POS + PAD_COLUMNS then
PERFORM_TRACK_VIEW_POS = CURRENT_TRACK - PAD_COLUMNS + 1
ui_update_nav_buttons()
elseif CURRENT_TRACK < PERFORM_TRACK_VIEW_POS then
PERFORM_TRACK_VIEW_POS = CURRENT_TRACK
ui_update_nav_buttons()
end
end
function focus_sequence()
if CURRENT_SEQUENCE > PERFORM_SEQUENCE_VIEW_POS + PAD_ROWS then
PERFORM_SEQUENCE_VIEW_POS = CURRENT_SEQUENCE - PAD_ROWS + 1
ui_update_nav_buttons()
elseif CURRENT_SEQUENCE < PERFORM_SEQUENCE_VIEW_POS then
PERFORM_SEQUENCE_VIEW_POS = CURRENT_SEQUENCE
ui_update_nav_buttons()
end
end
function focus_note_column()
if CURRENT_NOTE_COLUMN > NOTE_COLUMN_VIEW_POS + PAD_ROWS then
NOTE_COLUMN_VIEW_POS = CURRENT_NOTE_COLUMN - PAD_ROWS + 1
ui_update_nav_buttons()
elseif CURRENT_NOTE_COLUMN < NOTE_COLUMN_VIEW_POS then
NOTE_COLUMN_VIEW_POS = CURRENT_NOTE_COLUMN
ui_update_nav_buttons()
end
end
function focus_line()
local new_note_step_view_pos = CURRENT_LINE - ((CURRENT_LINE - 1) % PAD_COLUMNS)
if new_note_step_view_pos ~= NOTE_STEP_VIEW_POS then
NOTE_STEP_VIEW_POS = new_note_step_view_pos
ui_update_nav_buttons()
end
end
function render_perform()
for i = PERFORM_SEQUENCE_VIEW_POS, PERFORM_SEQUENCE_VIEW_POS + PAD_ROWS - 1 do
if i == PLAYBACK_SEQUENCE then
ROW_SELECT[i - PERFORM_SEQUENCE_VIEW_POS + 1] = { 0, 255, 0 }
else
ROW_SELECT[i - PERFORM_SEQUENCE_VIEW_POS + 1] = { 0, 0, 0 }
end
if i == PLAYBACK_NEXT_SEQUENCE then
ROW_INDICATOR[i - PERFORM_SEQUENCE_VIEW_POS + 1] = { 0, 255, 0 }
else
ROW_INDICATOR[i - PERFORM_SEQUENCE_VIEW_POS + 1] = { 0, 0, 0 }
end
for j = PERFORM_TRACK_VIEW_POS, PERFORM_TRACK_VIEW_POS + PAD_COLUMNS - 1 do
if i >= 1 and i <= #rns.sequencer.pattern_sequence and j >= 1 and j <= rns.sequencer_track_count then
local cell = rns:pattern(rns.sequencer:pattern(i)):track(j)
--local is_alias = false
--if cell.is_alias then
-- is_alias = true
-- cell = rns:pattern(cell.alias_pattern_index):track(j)
--end
if cell.color ~= nil then
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1] = rgb_to_hsv(cell.color)
else
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1] = rgb_to_hsv(rns:track(j).color)
end
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 1.0
if cell.is_empty then
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][1] = 0
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 0
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 0
if i == PLAYBACK_SEQUENCE then
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 0.1
end
else
--PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 1.0
--if not is_alias then
-- PADS[i][j][3] = PADS[i][j][3] * 2
--end
if PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][1] ~= 0 or PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][2] ~= 0 then
if rns.sequencer:track_sequence_slot_is_muted(j, i) then
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 0.7
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 0.2
else
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 1
end
end
end
if i == CURRENT_SEQUENCE and j == CURRENT_TRACK and not PERFORM_HIDE_CURSOR and not ((UI_STEP_PRESSED
and not UI_STEP_LOCK)
or (not
UI_STEP_PRESSED and UI_STEP_LOCK)) then
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 0
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 1
end
else
PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
end
end
end
end
function render_overview()
ROW_SELECT[1] = { 0, 255, 0 }
if PLAYBACK_NEXT_SEQUENCE == -1 or PLAYBACK_NEXT_SEQUENCE == PLAYBACK_SEQUENCE then
ROW_INDICATOR[1] = { 0, 255, 0 }
else
ROW_INDICATOR[1] = { 0, 0, 0 }
end
ROW_SELECT[2] = { 0, 0, 0 }
ROW_SELECT[3] = { 0, 0, 0 }
ROW_SELECT[4] = { 0, 0, 0 }
ROW_INDICATOR[2] = { 0, 0, 0 }
ROW_INDICATOR[3] = { 0, 0, 0 }
ROW_INDICATOR[4] = { 0, 0, 0 }
for j = PERFORM_TRACK_VIEW_POS, PERFORM_TRACK_VIEW_POS + PAD_COLUMNS - 1 do
if j >= 1 and j <= rns.sequencer_track_count then
local cell = rns:pattern(rns.sequencer:pattern(PLAYBACK_SEQUENCE)):track(j)
if cell.color ~= nil then
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1] = rgb_to_hsv(cell.color)
else
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1] = rgb_to_hsv(rns:track(j).color)
end
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 1.0
if cell.is_empty then
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][1] = 0
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 0
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 0
else
--PADS[i - PERFORM_SEQUENCE_VIEW_POS + 1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 1.0
--if not is_alias then
-- PADS[i][j][3] = PADS[i][j][3] * 2
--end
if PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][1] ~= 0 or PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][2] ~= 0 then
if rns.sequencer:track_sequence_slot_is_muted(j, PLAYBACK_SEQUENCE) then
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 0.7
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 0.2
else
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 1
end
end
end
if j == CURRENT_TRACK and not ((UI_STEP_PRESSED and not UI_STEP_LOCK) or (not UI_STEP_PRESSED and
UI_STEP_LOCK)) then
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][2] = 0
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1][3] = 1
end
PADS[2][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
if rns:track(j).solo_state then
PADS[3][j - PERFORM_TRACK_VIEW_POS + 1] = { 0.4, 1.0, 1.0, false }
if rns:track(j).mute_state ~= renoise.Track.MUTE_STATE_ACTIVE then
PADS[4][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 1.0, 0.2, false }
else
PADS[4][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
end
else
PADS[3][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
if rns:track(j).mute_state ~= renoise.Track.MUTE_STATE_ACTIVE then
PADS[4][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 1.0, 1.0, false }
else
PADS[4][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
end
end
else
PADS[1][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
PADS[2][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
PADS[3][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
PADS[4][j - PERFORM_TRACK_VIEW_POS + 1] = { 0, 0, 0, false }
end
end
end
function render_note_cursor()
local new_step_pos = PLAYBACK_LINE - NOTE_STEP_VIEW_POS + 1
if rns.selected_sequence_index ~= PLAYBACK_SEQUENCE or new_step_pos <= 0 or new_step_pos > PAD_COLUMNS then
new_step_pos = 0
end
for i = 1, PAD_ROWS do
if NOTE_COLUMN_VIEW_POS + i - 1 == CURRENT_NOTE_COLUMN then
ROW_SELECT[i] = { 0, 255, 0 }
else
ROW_SELECT[i] = { 0, 0, 0 }
end
if NOTE_COLUMN_VIEW_POS + i - 1 <= rns:track(rns.selected_track_index).visible_note_columns then
ROW_INDICATOR[i] = { 0, 127, 0 }
else
ROW_INDICATOR[i] = { 0, 0, 0 }
end
if NOTE_CURSOR_POS > 0 then
PADS[i][NOTE_CURSOR_POS][4] = false
end
if new_step_pos > 0 then
PADS[i][new_step_pos][4] = true
end
end
NOTE_CURSOR_POS = new_step_pos
end
function render_note()
render_note_cursor()
local column_num = rns:track(rns.selected_track_index).visible_note_columns
local last_note = table.create()
local last_volume = table.create()
if MODE == MODE_NOTE or (MODE == MODE_DRUM and UI_STEP_PRESSED) then
for i = 1, column_num do
last_note[i] = -1
end
for pos, line in rns.pattern_iterator:note_columns_in_pattern_track(rns.selected_pattern_index, rns.selected_track_index, true) do
if pos.line >= NOTE_STEP_VIEW_POS then
break
end
local note_value = line.note_value
if note_value == 120 then
last_note[pos.column] = -1
last_volume[pos.column] = 0
elseif note_value < 120 then
last_note[pos.column] = note_value % 12
last_volume[pos.column] = line.volume_value
end
end
for i = NOTE_COLUMN_VIEW_POS, NOTE_COLUMN_VIEW_POS + PAD_ROWS - 1 do
if i <= column_num then
render_note_row(i, last_note[i], last_volume[i])
else
for j = 1, PAD_COLUMNS do
PADS[i - NOTE_COLUMN_VIEW_POS + 1][j] = { 0, 0, 0, false }
end
end
end
else
for i = NOTE_COLUMN_VIEW_POS, NOTE_COLUMN_VIEW_POS + PAD_ROWS - 1 do
if i <= column_num then
render_drum_row(i, last_note[i])
else
for j = 1, PAD_COLUMNS do
PADS[i - NOTE_COLUMN_VIEW_POS + 1][j] = { 0, 0, 0, false }
end
end
end
end
end
function is_selected_column(track, column, selection)
if selection == nil then
return track == rns.selected_track_index and column == CURRENT_NOTE_COLUMN
end
if track < selection.start_track or track > selection.end_track then
return false
end
if track == selection.start_track and column < selection.start_column then
return false
end
if track == selection.end_track and column > selection.end_column then
return false
end
return true
end
function is_selected_line(line, selection)
if selection == nil then
return line == CURRENT_LINE
end
if line < selection.start_line or line > selection.end_line then
return false
end
return true
end
function render_note_row(ix, last_note, last_volume)
local track_index = rns.selected_track_index
local note_column_index = ix
local line_count = rns.selected_pattern.number_of_lines
local selection = rns.selection_in_pattern
local is_selected = is_selected_column(track_index, note_column_index, selection)
local track = rns.selected_pattern:track(track_index)
for i = NOTE_STEP_VIEW_POS, NOTE_STEP_VIEW_POS + PAD_COLUMNS - 1 do
local pad = PADS[ix - NOTE_COLUMN_VIEW_POS + 1][i - NOTE_STEP_VIEW_POS + 1]
if i <= line_count and i > 0 then
local line = track:line(i)
local note_value = line:note_column(note_column_index).note_value
local volume_value = line:note_column(note_column_index).volume_value
if note_value < 120 then
last_note = note_value % 12
last_volume = volume_value
elseif note_value == 120 then
last_note = -1
last_volume = 0
end
if last_note < 0 then
pad[1] = 0.0
pad[2] = 0.0
pad[3] = 0.0
if is_selected and is_selected_line(i, selection) then
pad[3] = pad[3] + 0.2
end
else
pad[1] = last_note / 12.0
pad[2] = 1.0
if note_value < 120 then
if note_value < 120 and volume_value >= 128 then
pad[3] = 0.9
elseif note_value < 120 then
pad[3] = 0.1 + 0.8 * volume_value / 128
end
else
if last_volume < 128 then
pad[3] = 0.1 + 0.1 * last_volume / 256
else
pad[3] = 0.2
end
end
if is_selected and is_selected_line(i, selection) then
pad[2] = 0.5
end
end
else
pad[1] = 0.0
pad[2] = 0.0
pad[3] = 0.0
end
end
end
function render_drum_row(ix)
local track_index = rns.selected_track_index
local note_column_index = ix
local color = rgb_to_hsv(rns:track(track_index).color)
local line_count = rns.selected_pattern.number_of_lines
local selection = rns.selection_in_pattern
local is_selected = is_selected_column(track_index, note_column_index, selection)
local track = rns.selected_pattern:track(track_index)
for i = NOTE_STEP_VIEW_POS, NOTE_STEP_VIEW_POS + PAD_COLUMNS - 1 do
local pad = PADS[ix - NOTE_COLUMN_VIEW_POS + 1][i - NOTE_STEP_VIEW_POS + 1]
if i <= line_count and i > 0 then
local line = track:line(i)
local note_value = line:note_column(note_column_index).note_value
local volume_value = line:note_column(note_column_index).volume_value
if note_value >= 120 then
pad[1] = 0.0
pad[2] = 0.0
pad[3] = 0.0
if is_selected and is_selected_line(i, selection) then
pad[3] = pad[3] + 0.2
end
else
pad[1] = color[1]
pad[2] = 1.0
if note_value < 120 and volume_value >= 128 then
pad[3] = 1.0
elseif note_value < 120 then
pad[3] = 0.1 + 0.9 * volume_value / 128
end
if is_selected and is_selected_line(i, selection) then
pad[2] = 0.2
end
end
else
pad[1] = 0.0
pad[2] = 0.0
pad[3] = 0.0
end
end
end
function get_selection()
local selection = rns.selection_in_pattern
if selection == nil then
selection = {}
selection.start_track = rns.selected_track_index
selection.end_track = rns.selected_track_index
selection.start_line = rns.selected_line_index
selection.end_line = rns.selected_line_index
selection.start_column = CURRENT_NOTE_COLUMN
selection.end_column = CURRENT_NOTE_COLUMN
end
return selection
end
function set_selection(new_selection)
local selection = new_selection
rns.selected_track_index = selection.start_track
if not (selection.start_line == 1 and selection.end_line == rns.selected_pattern.number_of_lines) then
rns.selected_note_column_index = selection.start_column
rns.selected_line_index = selection.start_line
end
if selection.start_track == selection.end_track and selection.start_column == selection.end_column and selection.start_line == selection.end_line then
rns.selection_in_pattern = {}
else
rns.selection_in_pattern = selection
end
end
function shift_selection(steps)
local selection = get_selection()
local line_count = rns.selected_pattern.number_of_lines
local step_remap = table.create()
if selection.end_line - selection.start_line == line_count - 1 then
-- full pattern selected
if steps > 0 then
-- rotate right
for i = 1, line_count - steps do
step_remap[i] = steps;
end
for i = line_count - steps + 1, line_count do
step_remap[i] = steps - line_count
end
else
-- rotate left
for i = 1, -steps do
step_remap[i] = line_count + steps;
end
for i = -steps + 1, line_count do
step_remap[i] = steps
end
end
else
if steps > 0 then
-- shift right
if selection.end_line + steps > line_count then
return
end
for i = selection.start_line, selection.end_line do
step_remap[i] = steps;
end
for i = selection.end_line + 1, selection.end_line + steps do
step_remap[i] = -(selection.end_line - selection.start_line + 1)
end
else
-- shift left
if selection.start_line + steps < 1 then
return
end
for i = selection.start_line, selection.end_line do
step_remap[i] = steps;
end
for i = selection.start_line + steps, selection.start_line - 1 do
step_remap[i] = selection.end_line - selection.start_line + 1
end
end
selection.start_line = selection.start_line + steps
selection.end_line = selection.end_line + steps
end
remap_selection(step_remap, nil)
set_selection(selection)
mark_as_dirty()
end
function get_nearest_note()
local track = rns.selected_pattern:track(rns.selected_track_index)
local line_count = rns.selected_pattern.number_of_lines
local line_index = rns.selected_line_index
local note_column_index = CURRENT_NOTE_COLUMN
for i = 1, line_count do
if line_index - i < 1 and line_index + i > line_count then
return nil
end
if line_index - i >= 1 then
local note_column = track:line(line_index - i):note_column(note_column_index)
if note_column.note_value < 120 then
return note_column
end
end
if line_index + i <= line_count then
local note_column = track:line(line_index + i):note_column(note_column_index)
if note_column.note_value < 120 then
return note_column
end
end
end
end
function remap_selection(step_remap, row_remap)
local seq_len = rns.transport.song_length.sequence + 1
local current_seq_index = rns.selected_sequence_index
local note_column_len = rns:track(rns.selected_track_index).visible_note_columns
local pattern_copy_index = rns.sequencer:insert_new_pattern_at(seq_len)
local pattern_copy = rns:pattern(pattern_copy_index)
rns.selected_sequence_index = current_seq_index
pattern_copy:copy_from(rns.selected_pattern)
local line_count = rns.selected_pattern.number_of_lines
local selection = rns.selection_in_pattern
local not_whole_track_selected = selection == nil or selection.start_line ~= 1 or selection.end_line ~= line_count
local track_index = rns.selected_track_index
local row_remap_local = row_remap
if row_remap_local == nil then
row_remap_local = table.create()
if selection == nil then
row_remap_local[rns.selected_note_column_index] = 0;
else
for i = 1, note_column_len do
if is_selected_column(rns.selected_track_index, i, selection) then
row_remap_local[i] = 0;
end
end
end
end
for i = 1, note_column_len do
if (not_whole_track_selected or is_selected_column(rns.selected_track_index, i, selection)) then
local new_track_index = track_index
local new_note_column_index
if row_remap_local[i] ~= nil then
new_note_column_index = i + row_remap_local[i]
end
if new_note_column_index ~= nil then
local track = pattern_copy:track(track_index)
local new_track = rns.selected_pattern:track(new_track_index)
for j = 1, line_count do
local new_step_pos = j
if new_note_column_index >= 1 and new_note_column_index <= note_column_len and step_remap[j] ~= nil then
new_step_pos = new_step_pos + step_remap[j]
local line = track:line(j)
local new_line = new_track:line(new_step_pos)
local data = line:note_column(i)
local new_data = new_line:note_column(new_note_column_index)
new_data:copy_from(data)
--new_data.note_value = data.note_value
--new_data.instrument_value = data.instrument_value
--new_data.volume_value = data.volume_value
--new_data.panning_value = data.panning_value
--new_data.delay_value = data.delay_value
--new_data.effect_number_value = data.effect_number_value
--new_data.effect_amount_value = data.effect_amount_value
end
end
end
end
end
rns.sequencer:delete_sequence_at(seq_len)
mark_as_dirty()
end
function apply_to_selection(apply)
local line_count = rns.selected_pattern.number_of_lines
local note_column_len = rns:track(rns.selected_track_index).visible_note_columns
local selection = rns.selection_in_pattern
for i = 1, note_column_len do
local track_index = rns.selected_track_index
local note_column_index = i
local is_selected = is_selected_column(track_index, note_column_index, selection)
local track = rns.selected_pattern:track(track_index)
for j = 1, line_count do
local line = track:line(j)
local data = line:note_column(note_column_index)
if is_selected and is_selected_line(j, selection) then
apply(data)
end
end
end
mark_as_dirty()
end
function ui_pad_press(row, column)
UI_PAD_PROCESSED = false
if MODE == MODE_OVERVIEW then
local track_ix = PERFORM_TRACK_VIEW_POS + column - 1
if track_ix >= 1 and track_ix <= rns.sequencer_track_count then
if row == 1 then
if ((UI_STEP_PRESSED and not UI_STEP_LOCK) or (not UI_STEP_PRESSED and UI_STEP_LOCK)) then
rns.sequencer:set_track_sequence_slot_is_muted(track_ix, PLAYBACK_SEQUENCE, not rns
.sequencer:track_sequence_slot_is_muted(track_ix, PLAYBACK_SEQUENCE))
else
rns.selected_track_index = track_ix
end
elseif row == 3 then
if UI_SHIFT_PRESSED then
for i = 1, rns.sequencer_track_count do
if i ~= track_ix then
rns:track(i).solo_state = false
end
end
rns:track(track_ix):solo()
else
rns:track(track_ix):solo()
end
elseif row == 4 then
if rns:track(track_ix).mute_state == renoise.Track.MUTE_STATE_ACTIVE then
if UI_SHIFT_PRESSED then
rns:track(track_ix).mute_state = renoise.Track.MUTE_STATE_MUTED
else
rns:track(track_ix).mute_state = renoise.Track.MUTE_STATE_OFF
end
else
rns:track(track_ix).mute_state = renoise.Track.MUTE_STATE_ACTIVE
end
end
mark_as_dirty()
end
elseif MODE == MODE_PERFORM then
local seq_ix = PERFORM_SEQUENCE_VIEW_POS + row - 1
local track_ix = PERFORM_TRACK_VIEW_POS + column - 1
if seq_ix >= 1 and seq_ix <= #rns.sequencer.pattern_sequence and track_ix >= 1 and track_ix <= rns.sequencer_track_count then
if (not UI_SHIFT_PRESSED and UI_ALT_PRESSED) or UI_PAD_PRESSED_COUNT >= 1 then
local source = rns:pattern(rns.sequencer:pattern(rns.selected_sequence_index)):track(rns.selected_track_index)
local target = rns:pattern(rns.sequencer:pattern(seq_ix)):track(track_ix)
target:copy_from(source)
mark_as_dirty()
elseif UI_SHIFT_PRESSED and not UI_ALT_PRESSED then
local source = rns:pattern(rns.sequencer:pattern(rns.selected_sequence_index)):track(rns.selected_track_index)
local target = rns:pattern(rns.sequencer:pattern(seq_ix)):track(track_ix)
target:copy_from(source)
source:clear()
rns.selected_sequence_index = seq_ix
rns.selected_track_index = track_ix
mark_as_dirty()
elseif ((UI_STEP_PRESSED and not UI_STEP_LOCK) or (not UI_STEP_PRESSED and UI_STEP_LOCK)) then
rns.sequencer:set_track_sequence_slot_is_muted(track_ix, seq_ix, not rns.sequencer:track_sequence_slot_is_muted(track_ix, seq_ix))
mark_as_dirty()
elseif UI_ALT_PRESSED and UI_SHIFT_PRESSED then
local target = rns:pattern(rns.sequencer:pattern(seq_ix)):track(track_ix)
target:clear()
mark_as_dirty()
elseif not UI_ALT_PRESSED and not UI_SHIFT_PRESSED then
rns.selected_sequence_index = seq_ix
rns.selected_track_index = track_ix
ui_update_nav_buttons()
mark_as_dirty()
end
end
elseif MODE == MODE_NOTE or MODE == MODE_DRUM then
local row_ix = NOTE_COLUMN_VIEW_POS + row - 1
local column_ix = NOTE_STEP_VIEW_POS + column - 1
if UI_STEP_PRESSED then
UI_STEP_PROCESSED = true
local track = rns.selected_pattern:track(rns.selected_track_index)
local line_count = rns.selected_pattern.number_of_lines
if column_ix + 1 <= line_count then
local note_column = track:line(column_ix + 1):note_column(row_ix)
if note_column.note_value == 120 then
note_column.note_value = 121
elseif note_column.note_value == 121 then
note_column.note_value = 120
end
end
-- clean following OFFs
for i = column_ix, 1, -1 do
local note_column = track:line(i):note_column(row_ix)
if note_column.note_value == 120 then
note_column.note_value = 121
elseif note_column.note_value < 120 then
break
end
end
if column_ix + 1 <= line_count and track:line(column_ix + 1):note_column(row_ix).note_value >= 120 then
for i = column_ix + 2, line_count do
local note_column = track:line(i):note_column(row_ix)
if note_column.note_value == 120 then
note_column.note_value = 121
elseif note_column.note_value < 120 then
break
end
end
end
elseif UI_SHIFT_PRESSED and UI_ALT_PRESSED then
if is_selected_column(rns.selected_track_index, row_ix, rns.selection_in_pattern) and is_selected_line(column_ix, rns.selection_in_pattern) then
apply_to_selection(function(note_column)
note_column:clear()
end)
end
UI_PAD_PROCESSED = true
elseif UI_SHIFT_PRESSED or UI_PAD_PRESSED_COUNT >= 1 then
local start_line = rns.selected_line_index
local start_track = rns.selected_track_index
local start_column = CURRENT_NOTE_COLUMN
local end_line = column_ix
local end_track = rns.selected_track_index
local end_column = row_ix
if start_line > end_line then
start_line = column_ix