-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPakettiImpulseTracker.lua
2350 lines (2054 loc) · 87.1 KB
/
PakettiImpulseTracker.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
----------------------------------------------------------------------------------------------------------------
-- F2
function F2()
local w=renoise.app().window
local raw=renoise.ApplicationWindow
w.lock_keyboard_focus=true
if w.active_middle_frame==raw.MIDDLE_FRAME_PATTERN_EDITOR and w.lower_frame_is_visible then
--renoise.app().window:select_preset(8)
w.lower_frame_is_visible=false
renoise.app().window.pattern_advanced_edit_is_visible=false
w.upper_frame_is_visible=false
w.pattern_advanced_edit_is_visible=false
w.instrument_box_is_visible=true
w.disk_browser_is_visible=true
w.pattern_matrix_is_visible=false
else w.active_middle_frame=raw.MIDDLE_FRAME_PATTERN_EDITOR
w.lower_frame_is_visible=true
w.upper_frame_is_visible=true
renoise.app().window.pattern_advanced_edit_is_visible=false
w.active_lower_frame=raw.LOWER_FRAME_TRACK_DSPS
--w.pattern_advanced_edit_is_visible=true
w.instrument_box_is_visible=true
w.disk_browser_is_visible=true
-- w.pattern_matrix_is_visible = true
return end
if w.disk_browser_is_visible then
w.active_middle_frame=raw.MIDDLE_FRAME_PATTERN_EDITOR
w.lower_frame_is_visible=false
w.upper_frame_is_visible=false
w.pattern_advanced_edit_is_visible=false
w.disk_browser_is_visible=false
renoise.app().window.pattern_advanced_edit_is_visible=true
--renoise.app().window:select_preset(8)
return end
--if preferences.upperFramePreference ~= 0 then w.active_upper_frame = preferences.upperFramePreference else end
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F2 Pattern Editor",invoke=function() F2() end}
-- F2
function F2Only()
local w=renoise.app().window
local raw=renoise.ApplicationWindow
w.active_middle_frame=raw.MIDDLE_FRAME_PATTERN_EDITOR
w.lower_frame_is_visible=true
w.upper_frame_is_visible=true
w.active_lower_frame=raw.LOWER_FRAME_TRACK_DSPS
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F2 Pattern Editor ONLY",invoke=function() F2Only() end}
----------------------------------------------------------------------------------------------------------------
function MixerToF2()
local w=renoise.app().window
if w.active_middle_frame == 2 then F2() else w.active_middle_frame=2 end
w.pattern_matrix_is_visible=false
w.pattern_advanced_edit_is_visible=false
w.instrument_box_is_visible=true
w.disk_browser_is_visible=true
end
renoise.tool():add_keybinding{name="Mixer:Paketti:To Pattern Editor",invoke=function() MixerToF2() end}
----------------------------------------------------------------------------------------------------------------
function F2mini()
local w=renoise.app().window
w.lock_keyboard_focus=true
w.active_middle_frame = 1
w.lower_frame_is_visible=false
w.upper_frame_is_visible=false
w.pattern_advanced_edit_is_visible=false
w.instrument_box_is_visible=false
w.disk_browser_is_visible=false
w.pattern_matrix_is_visible=false
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F2 Pattern Editor Mini",invoke=function() F2mini() end}
----------------------------------------------------------------------------------------------------------------
-- F3
function F3()
local w = renoise.app().window
local raw = renoise.ApplicationWindow
if w.active_middle_frame == raw.MIDDLE_FRAME_MIXER and w.upper_frame_is_visible == false then
w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
w.upper_frame_is_visible = true
return else end
if w.active_middle_frame == raw.MIDDLE_FRAME_INSTRUMENT_MIDI_EDITOR or
w.active_middle_frame == raw.MIDDLE_FRAME_INSTRUMENT_PLUGIN_EDITOR or
w.active_middle_frame == raw.MIDDLE_FRAME_INSTRUMENT_PHRASE_EDITOR or
w.active_middle_frame == raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_KEYZONES or
w.active_middle_frame == raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_MODULATION
then
w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
w.lock_keyboard_focus = true
w.disk_browser_is_visible = true
w.instrument_box_is_visible = true
return
end
if w.active_middle_frame == 5 then
w.active_middle_frame = 7
return
elseif w.active_middle_frame == 7 then
w.active_middle_frame = 5
return
end
-- Rest of the original logic remains unchanged
w.pattern_matrix_is_visible = false
w.pattern_advanced_edit_is_visible = false
if w.active_middle_frame == 1 then
w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
w.lock_keyboard_focus = true
w.disk_browser_is_visible = true
w.instrument_box_is_visible = true
if w.upper_frame_is_visible == true then
w.active_upper_frame = 2
else
return
end
w.upper_frame_is_visible = true
w.active_upper_frame = 2
return
else
end
if w.upper_frame_is_visible == true then
else
return
end
if w.active_middle_frame == raw.MIDDLE_FRAME_PATTERN_EDITOR and w.lower_frame_is_visible == false and w.pattern_advanced_edit_is_visible == false and w.upper_frame_is_visible == false then
w.upper_frame_is_visible = true
w.disk_browser_is_visible = true
return
else
end
local s = renoise.song()
s.selected_instrument.active_tab = 1
w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F3 Sample Editor",invoke=function() F3() end}
---
-- F3 Only
function F3Only()
local w=renoise.app().window
local s=renoise.song()
local raw=renoise.ApplicationWindow
w.pattern_matrix_is_visible=false
w.pattern_advanced_edit_is_visible=false
w.upper_frame_is_visible = true
w.disk_browser_is_visible=true
s.selected_instrument.active_tab=1
w.active_middle_frame=raw.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F3 Sample Editor Only",invoke=function() F3Only() end}
----------------------------------------------------------------------------------------------------------------
-- F4, or "Impulse Tracker Shortcut F4 display-change", "Instrument Editor".
-- Hides Pattern Matrix, Hides Advanced Edit.
-- Changes to Sample Keyzones, Disk Browser, Instrument Settings.
-- Sample Recorder will stay open, if Sample Recorder is already open.
function F4()
local w=renoise.app().window
local raw=renoise.ApplicationWindow
--if w.active_upper_frame == 1 and w.active_middle_frame == 3 and w.active_lower_frame == 3 and w.disk_browser_is_expanded==false
--then w.disk_browser_is_expanded=true return
--end
--w.lower_frame_is_visible=true
--w.upper_frame_is_visible=true
--if preferences.upperFramePreference ~= 0 then
-- w.active_upper_frame = preferences.upperFramePreference
--else end
--w.active_upper_frame=1 -- Force-sets to Track Scopes.
--w.active_lower_frame =3 -- Set to Instrument Settings
--w.lock_keyboard_focus=true
--w.pattern_matrix_is_visible=false
--w.pattern_advanced_edit_is_visible=false
--w.disk_browser_is_expanded=true
if w.active_middle_frame == raw.MIDDLE_FRAME_INSTRUMENT_MIDI_EDITOR then
w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_PLUGIN_EDITOR
w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_PHRASE_EDITOR
else w.active_middle_frame = raw.MIDDLE_FRAME_INSTRUMENT_MIDI_EDITOR end
--if renoise.app().window.active_middle_frame==renoise.Instrument.TAB_PLUGIN then renoise.app().window.active_middle_frame=5 else
--renoise.app().window.active_middle_frame=renoise.Instrument.TAB_PLUGIN end
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F4 Instrument Editor",invoke=function() F4() end}
----------------------------------------------------------------------------------------------------------------
-- F5
function ImpulseTrackerPlaySong()
local s = renoise.song()
local t = s.transport
local startpos = t.playback_pos
if t.playing then t:panic() ResetAllSteppers() else end
t:panic()
ResetAllSteppers()
startpos.sequence = 1
startpos.line = 1
t.playback_pos = startpos
local start_time = os.clock()
while (os.clock() - start_time < 0.225) do
-- Delay the start after panic. Don't go below 0.2 seconds
-- or you might tempt some plugins to crash and take Renoise in the fall!!
-- ^^^ I don't know or remember who wrote the above comments but it wasn't me -Esa
end
t.follow_player=true
t.edit_mode=false
t.metronome_enabled=false
t.loop_block_enabled=false
t.loop_pattern = false
t.loop_block_enabled=false
t:start_at(startpos)
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F5 Start Playback",invoke=function() ImpulseTrackerPlaySong() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F5 Start Playback (2nd)",invoke=function() ImpulseTrackerPlaySong() end}
----------------------------------------------------------------------------------------------------------------
-- F6, or Impulse Tracker Play Pattern.
-- There is currently no need for this, but if there one day is, this'll be where it will reside :)
-- You can map F6 to Global:Transport:Play Pattern.
----------------------------------------------------------------------------------------------------------------
-- F7, or Impulse Tracker Play from line.
function ImpulseTrackerPlayFromLine()
local monitoring_enabled = true
--InitSBx()
reset_repeat_counts()
ResetAllSteppers()
local s = renoise.song()
local t = s.transport
local startpos = t.playback_pos
if t.playing == true then
t.loop_pattern=false
t:panic()
t.loop_pattern=false
t.loop_block_enabled=false
t.edit_mode=true
startpos.line = s.selected_line_index
startpos.sequence = s.selected_sequence_index
t.playback_pos = startpos
t:start(renoise.Transport.PLAYMODE_CONTINUE_PATTERN)
return
else
t:panic()
t.loop_pattern=false
t.loop_block_enabled=false
t.edit_mode=true
startpos.line = s.selected_line_index
startpos.sequence = s.selected_sequence_index
t.playback_pos = startpos
t:start(renoise.Transport.PLAYMODE_CONTINUE_PATTERN)
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F7 Start Playback from Cursor Row",invoke=function() ImpulseTrackerPlayFromLine() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F7 Start Playback from Cursor Row (2nd)",invoke=function() ImpulseTrackerPlayFromLine() end}
------------------------------------------------------------------------------------------------------------------------------------------- F8
function ImpulseTrackerStop()
local t = renoise.song().transport
local s = renoise.song()
-- If playing, stop playback
if t.playing then
t.follow_player = false
t:panic()
t.loop_pattern = false
t.loop_block_enabled = false
ResetAllSteppers()
return
end
-- If stopped and not on first line, move to first line
if s.selected_line_index > 1 then
s.selected_line_index = 1
return
end
-- If on first line but not first pattern, move to first pattern
if s.selected_sequence_index > 1 then
s.selected_sequence_index = 1
s.selected_line_index = 1
return
end
-- If already at first pattern and line, trigger panic
if s.selected_sequence_index == 1 and s.selected_line_index == 1 then
t:panic()
ResetAllSteppers()
end
end
-- Keep your existing keybindings
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F8 Stop Playback (Panic)",invoke=function() ImpulseTrackerStop() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F8 Stop Playback (Panic) (2nd)",invoke=function() ImpulseTrackerStop() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F8 Stop/Start Playback (Panic)",invoke=function()
local t = renoise.song().transport
local startpos = t.playback_pos
if t.playing then ImpulseTrackerStop()
t.edit_mode=true
ResetAllSteppers()
else
startpos.sequence = 1
startpos.line = 1
t.playback_pos = startpos
t.playing=true
-- ImpulseTrackerPlaySong()
t.edit_mode=false end
end}
----------------------------------------------------------------------------------------------------------------
-- F11, or "Impulse Tracker Shortcut F11 display-change", "Order List",
-- Hides Pattern Matrix, Hides Advanced Edit.
-- Changes to Mixer, Track Scopes, Track DSPs.
-- Second press makes Pattern Matrix visible and changes to Automation.
-- Sample Recorder will stay open, if Sample Recorder is already open.
function F11()
local w=renoise.app().window
local raw=renoise.ApplicationWindow
if w.upper_frame_is_visible==true and w.pattern_matrix_is_visible==false and w.active_middle_frame==2 and w.active_lower_frame==1 then
w.pattern_matrix_is_visible=true
w.active_lower_frame=raw.LOWER_FRAME_TRACK_AUTOMATION
else w.pattern_matrix_is_visible=false
w.active_lower_frame=raw.LOWER_FRAME_TRACK_DSPS
end
-- if preferences and preferences.upperFramePreference and preferences.upperFramePreference ~= 0 then
-- w.active_upper_frame = preferences.upperFramePreference
-- end
--w.active_upper_frame=raw.UPPER_FRAME_TRACK_SCOPES
w.active_middle_frame=raw.MIDDLE_FRAME_MIXER
w.lower_frame_is_visible=true
w.upper_frame_is_visible=true
w.lock_keyboard_focus=true
w.pattern_advanced_edit_is_visible=false
--w.instrument_box_is_visible=false
--w.disk_browser_is_visible=false
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F11 Order List",invoke=function() F11() end}
----------------------------------------------------------------------------------------------------------------
-- F12, or "Not really IT F11, not really IT F12 either".
-- Hides Pattern Matrix, Hides Advanced Edit.
-- Changes to Mixer, Track DSPs, Master Spectrum.
-- Changes to Master track.
-- Second press switches to Song Settings.
-- Sample Recorder will stay open, if Sample Recorder is already open.
function F12()
local w = renoise.app().window
local s = renoise.song()
local raw = renoise.ApplicationWindow
w.pattern_matrix_is_visible = false
if renoise.app().window.active_middle_frame==8 or renoise.app().window.active_middle_frame==9 or renoise.app().window.active_middle_frame == 5 or renoise.app().window.active_middle_frame == 7 or renoise.app().window.active_middle_frame == 1 then
s.selected_track_index = s.sequencer_track_count + 1
w.active_middle_frame = raw.MIDDLE_FRAME_MIXER
w.active_lower_frame = raw.LOWER_FRAME_TRACK_DSPS
w.upper_frame_is_visible = true
return else end
-- Check if the Mixer is not visible and Track Automation is displaying
if w.active_middle_frame ~= raw.MIDDLE_FRAME_MIXER and w.active_lower_frame == raw.LOWER_FRAME_TRACK_AUTOMATION then
s.selected_track_index = s.sequencer_track_count + 1
w.active_middle_frame = raw.MIDDLE_FRAME_MIXER
w.active_lower_frame = raw.LOWER_FRAME_TRACK_DSPS
return
end
w.lower_frame_is_visible = true
w.upper_frame_is_visible = true
-- Ensure the Master track is selected
if s.selected_track_index ~= s.sequencer_track_count + 1 then
s.selected_track_index = s.sequencer_track_count + 1
w.active_lower_frame = raw.LOWER_FRAME_TRACK_DSPS
return
end
-- Cycle through Track DSPs and Track Automation when the Master track is selected
if w.active_lower_frame == raw.LOWER_FRAME_TRACK_DSPS and s.selected_track_index == s.sequencer_track_count + 1 then
w.active_lower_frame = raw.LOWER_FRAME_TRACK_AUTOMATION
return
end
-- Default case: set the lower frame to Track DSPs and upper frame to Track Scopes
w.active_lower_frame = raw.LOWER_FRAME_TRACK_DSPS
w.active_upper_frame = raw.UPPER_FRAME_TRACK_SCOPES
w.lock_keyboard_focus = true
w.pattern_advanced_edit_is_visible = false
end
-- Add the keybinding to ensure the function can be invoked using F12
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker F12 Master",invoke=function() F12() end}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Impulse Tracker Next / Previous Pattern (Keyboard + Midi)
function ImpulseTrackerNextPattern()
local s=renoise.song()
if s.transport.follow_player==false then s.transport.follow_player=true end
if s.transport.playing==false then
if s.selected_sequence_index==(table.count(s.sequencer.pattern_sequence)) then return
else
s.selected_sequence_index=s.selected_sequence_index+1 end
else if s.selected_sequence_index==(table.count(s.sequencer.pattern_sequence)) then
s.transport:trigger_sequence(1) else s.transport:trigger_sequence(s.selected_sequence_index+1) end
end
end
function ImpulseTrackerPrevPattern()
local s=renoise.song()
local t=s.transport
if t.follow_player==false then t.follow_player=true end
if t.playing==false then
if s.selected_sequence_index==1 then return
else s.selected_sequence_index=s.selected_sequence_index-1 end
else
if s.selected_sequence_index==1 then t:trigger_sequence(s.selected_sequence_index) else
t:trigger_sequence(s.selected_sequence_index-1) end
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker Pattern (Next)",invoke=function() ImpulseTrackerNextPattern() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker Pattern (Previous)",invoke=function() ImpulseTrackerPrevPattern() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker Pattern (Next) 2nd",invoke=function() ImpulseTrackerNextPattern() end}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker Pattern (Previous) 2nd",invoke=function() ImpulseTrackerPrevPattern() end}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--IT: ALT-D (whole track) Double-select
function DoubleSelect()
local s = renoise.song()
local win = renoise.app().window
local middle_frame = win.active_middle_frame
------------------------------------------------------------------------------
-- PHRASE EDITOR branch
------------------------------------------------------------------------------
if middle_frame == renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_PHRASE_EDITOR then
if renoise.API_VERSION >= 6.2 then
local phrase = s.selected_phrase
if not phrase then
renoise.app():show_error("No phrase is selected!")
return
end
local lpb = s.transport.lpb
local sip = s.selection_in_phrase -- may be nil
local start_line = renoise.song().selected_phrase_line_index
local total_columns = phrase.visible_note_columns + phrase.visible_effect_columns
-- Ensure there's at least one column
if total_columns < 1 then
total_columns = 1
phrase.visible_note_columns = 1
end
-- Helper function to visualize selection
local function selection_to_string(sel)
return sel and string.format("start_line=%d, end_line=%d, start_col=%d, end_col=%d",
sel.start_line, sel.end_line, sel.start_column, sel.end_column) or "nil"
end
if not sip or (sip.start_line ~= start_line) or (sip.end_line == start_line) then
print("Creating NEW selection because:")
print("No selection: ", not sip)
print("Start line mismatch: ", sip and (sip.start_line ~= start_line) or false)
print("Single line selection: ", sip and (sip.end_line == start_line) or false)
-- Calculate new end_line
local new_end_line = start_line + lpb - 1
if new_end_line > phrase.number_of_lines then
new_end_line = phrase.number_of_lines
end
-- Prepare the new selection
renoise.song().selection_in_phrase = {
start_line = renoise.song().selected_phrase_line_index,
end_line = new_end_line,
start_column = 1,
end_column = total_columns,
}
-- Assign the new selection and print the assigned values
--s.selection_in_phrase = new_selection
print("Assigned selection_in_phrase:")
print(selection_to_string(s.selection_in_phrase))
-- Verify the assignment
if s.selection_in_phrase and
s.selection_in_phrase.start_line == new_selection.start_line and
s.selection_in_phrase.end_line == new_selection.end_line and
s.selection_in_phrase.start_column == new_selection.start_column and
s.selection_in_phrase.end_column == new_selection.end_column then
print("Verification succeeded: selection_in_phrase matches the assigned values.")
else
print("Verification failed: selection_in_phrase does not match the assigned values!")
print("Expected: ", selection_to_string(new_selection))
print("Actual: ", selection_to_string(s.selection_in_phrase))
end
else
print("Expanding EXISTING selection: ", selection_to_string(sip))
-- Calculate new end_line to expand selection
local current_length = sip.end_line - sip.start_line + 1
local new_end_line = sip.start_line + (current_length * 2) - 1
if new_end_line > phrase.number_of_lines then
new_end_line = phrase.number_of_lines
print("Clamping new_end_line to phrase length")
end
-- Prepare the expanded selection
local new_selection = {
start_line = sip.start_line,
end_line = new_end_line,
start_column = 1,
end_column = total_columns,
}
-- Assign the expanded selection and print the assigned values
s.selection_in_phrase = new_selection
print("Expanded selection_in_phrase:")
print(selection_to_string(s.selection_in_phrase))
-- Verify the assignment
if s.selection_in_phrase and
s.selection_in_phrase.start_line == new_selection.start_line and
s.selection_in_phrase.end_line == new_selection.end_line and
s.selection_in_phrase.start_column == new_selection.start_column and
s.selection_in_phrase.end_column == new_selection.end_column then
print("Verification succeeded: selection_in_phrase matches the assigned values.")
else
print("Verification failed: selection_in_phrase does not match the assigned values!")
print("Expected: ", selection_to_string(new_selection))
print("Actual: ", selection_to_string(s.selection_in_phrase))
end
end
else
renoise.app():show_error("Phrase Editor functionality requires API version 6.2 or higher!")
return
end
------------------------------------------------------------------------------
-- PATTERN EDITOR branch
------------------------------------------------------------------------------
elseif middle_frame == renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR then
local lpb = s.transport.lpb
local sip = s.selection_in_pattern
local last_column = s.selected_track.visible_effect_columns +
s.selected_track.visible_note_columns
local protect_row = s.selected_line_index + lpb - 1
if protect_row > s.selected_pattern.number_of_lines then
protect_row = s.selected_pattern.number_of_lines
end
if (not sip)
or (sip.start_track ~= s.selected_track_index)
or (s.selected_line_index ~= sip.start_line) then
s.selection_in_pattern = {
start_line = s.selected_line_index,
end_line = protect_row,
start_track = s.selected_track_index,
end_track = s.selected_track_index,
start_column = 1,
end_column = last_column,
}
else
local new_end_line = (sip.end_line - sip.start_line) * 2 + (sip.start_line + 1)
if new_end_line > s.selected_pattern.number_of_lines then
new_end_line = s.selected_pattern.number_of_lines
end
s.selection_in_pattern = {
start_line = sip.start_line,
end_line = new_end_line,
start_track = s.selected_track_index,
end_track = s.selected_track_index,
start_column = 1,
end_column = last_column,
}
end
else
renoise.app():show_error("Active middle frame not recognized for DoubleSelect!")
end
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-D Double Select",invoke=DoubleSelect}
renoise.tool():add_keybinding{name="Phrase Editor:Paketti:Impulse Tracker ALT-D Double Select",invoke=DoubleSelect}
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker ALT-D Double Select",invoke=DoubleSelect}
-----------
-- Function to select the pattern range in automation
function selectPatternRangeInAutomation()
local song = renoise.song()
-- Check if the automation lower frame is displayed
if not (renoise.app().window.active_lower_frame == renoise.ApplicationWindow.LOWER_FRAME_TRACK_AUTOMATION) then
renoise.app():show_status("Automation lower frame is not displayed.")
return
end
local selected_pattern_index = song.selected_pattern_index
local selected_track_index = song.selected_track_index
-- Check if an automatable parameter is selected
local automation_parameter = song.selected_automation_parameter
if not automation_parameter or not automation_parameter.is_automatable then
renoise.app():show_status("Please select an automatable parameter.")
return
end
-- Get the selection in the pattern editor
local pattern_selection = song.selection_in_pattern
if pattern_selection == nil then
renoise.app():show_status("No selection in Pattern Editor.")
return
end
local start_line = pattern_selection.start_line
local end_line = pattern_selection.end_line
-- Access the track's automation for the selected parameter
local track_automation = song:pattern(selected_pattern_index):track(selected_track_index)
local envelope = track_automation:find_automation(automation_parameter)
-- If no automation envelope exists, create one
if not envelope then
envelope = track_automation:create_automation(automation_parameter)
end
-- Calculate automation selection range based on pattern selection
local pattern_lines = song:pattern(selected_pattern_index).number_of_lines
local automation_start = math.floor((start_line / pattern_lines) * envelope.length)
local automation_end = math.floor(((end_line + 1) / pattern_lines) * envelope.length)
-- Set the selection range in the automation envelope
envelope.selection_range = { automation_start, automation_end }
-- Notify the user
renoise.app():show_status("Automation selection set from line " .. start_line .. " to line " .. end_line)
end
-- IT: ALT-D (whole track) Double-select
function DoubleSelectAutomation()
local s = renoise.song()
local lpb = s.transport.lpb
local sip = s.selection_in_pattern
local last_column = s.selected_track.visible_effect_columns + s.selected_track.visible_note_columns
local protectrow = lpb + s.selected_line_index - 1
if protectrow > s.selected_pattern.number_of_lines then
protectrow = s.selected_pattern.number_of_lines
end
if sip == nil or sip.start_track ~= s.selected_track_index or s.selected_line_index ~= s.selection_in_pattern.start_line then
s.selection_in_pattern = {
start_line = s.selected_line_index,
end_line = protectrow,
start_track = s.selected_track_index,
end_track = s.selected_track_index,
start_column = 1,
end_column = last_column
}
else
local endline = sip.end_line
local startline = sip.start_line
local new_endline = (endline - startline) * 2 + (startline + 1)
if new_endline > s.selected_pattern.number_of_lines then
new_endline = s.selected_pattern.number_of_lines
end
s.selection_in_pattern = {
start_line = startline,
end_line = new_endline,
start_track = s.selected_track_index,
end_track = s.selected_track_index,
start_column = 1,
end_column = last_column
}
end
-- After updating the pattern selection, update the automation selection
selectPatternRangeInAutomation()
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-D Double Select W/ Automation",invoke=function() DoubleSelectAutomation() end}
renoise.tool():add_keybinding{name="Automation:Paketti:Impulse Tracker ALT-D Double Select W/ Automation",invoke=function() DoubleSelectAutomation() end}
--------------------------------------------------------------------------------------------------------------------------------
-- Protman's set octave with or without EditStep
-- Protman: Thanks to suva for the function per octave declaration loop :)
-- http://www.protman.com
function Octave(new_octave, use_editstep)
local new_pos = 0
local s = renoise.song()
local editstep = s.transport.edit_step
new_pos = s.transport.edit_pos
if ((s.selected_note_column ~= nil) and (s.selected_note_column.note_value < 120)) then
s.selected_note_column.note_value = s.selected_note_column.note_value % 12 + (12 * new_octave)
end
if use_editstep then
new_pos.line = new_pos.line + editstep
if new_pos.line <= s.selected_pattern.number_of_lines then
s.transport.edit_pos = new_pos
end
end
end
-- Create keybindings for both with and without EditStep
for oct=0,9 do
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Set Note to Octave " .. oct .. " with EditStep",
invoke=function() Octave(oct, true) end }
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Set Note to Octave " .. oct .. " without EditStep",
invoke=function() Octave(oct, false) end }
end
-------------------------------------------------------------------------------------------------------------------------------------
------Protman PageUp PageDn
--PageUp / PageDown ImpulseTracker behaviour (reads according to LPB, and disables
--Pattern Follow to "eject" you out of playback back to editing step-by-step)
function Jump(Dir)
local new_pos = 0
local s=renoise.song()
local lpb = s.transport.lpb
local pat_lines = s.selected_pattern.number_of_lines
new_pos = s.transport.edit_pos
new_pos.line = new_pos.line + lpb * 2 * Dir
if (new_pos.line < 1) then
s.transport.follow_player = false
new_pos.line = 1
else if (new_pos.line > pat_lines) then
s.transport.follow_player = false
new_pos.line = pat_lines
end
end
if ((Dir == -1) and (new_pos.line == pat_lines - ((lpb * 2)))) then
new_pos.line = (pat_lines - (lpb*2) + 1)
s.transport.follow_player = false
end
s.transport.edit_pos = new_pos
s.transport.follow_player = false
end
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker PageUp Jump Lines",invoke=function() Jump(-1) end }
renoise.tool():add_keybinding{name="Global:Paketti:Impulse Tracker PageDown Jump Lines",invoke=function() Jump(1) end }
--------------------------------------------------------------------------------------------------
---------Protman's Expand Selection
function cpclex_line(track, from_line, to_line)
local s=renoise.song()
local cur_track = s:pattern(s.selected_pattern_index):track(track)
cur_track:line(to_line):copy_from(cur_track:line(from_line))
cur_track:line(from_line):clear()
cur_track:line(to_line+1):clear()
end
function ExpandSelection()
local s = renoise.song()
if s.selection_in_pattern == nil then
renoise.app():show_status("Nothing selected to Expand, doing nothing.")
return
else
local sl = s.selection_in_pattern.start_line
local el = s.selection_in_pattern.end_line
local st = s.selection_in_pattern.start_track
local et = s.selection_in_pattern.end_track
local nl = s.selected_pattern.number_of_lines
local tr
for tr=st,et do
for l =el,sl,-1 do
if l ~= sl and l*2-sl <= nl
then
cpclex_line(tr,l,l*2-sl)
end
end
end
end
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-F Expand Selection",invoke=function() ExpandSelection() end}
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-F Expand Selection Twice",invoke=function() ExpandSelection() ExpandSelection() end}
-----------------------------------------------------------------------------------------------
-------Protman's Shrink Selection
function cpclsh_line(track, from_line, to_line)
local cur_track = renoise.song():pattern(renoise.song().selected_pattern_index):track(track)
cur_track:line(to_line):copy_from(cur_track:line(from_line))
cur_track:line(from_line):clear()
cur_track:line(from_line+1):clear()
end
function ShrinkSelection()
local s = renoise.song()
if s.selection_in_pattern == nil then
renoise.app():show_status("Nothing selected to Shrink, doing nothing.")
return
else
local sl = s.selection_in_pattern.start_line
local el = s.selection_in_pattern.end_line
local st = s.selection_in_pattern.start_track
local et = s.selection_in_pattern.end_track
local tr
for tr=st,et do
for l =sl,el,2 do
if l ~= sl
then
cpclsh_line(tr,l,l/2+sl/2)
end
end
end
end
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-G Shrink Selection",invoke=function() ShrinkSelection() end}
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-G Shrink Selection Twice",invoke=function() ShrinkSelection() ShrinkSelection() end}
--------------------------------------------------------
-- Renamed helper function to cpclexrep_line
function cpclexrep_line(track, from_line, to_line)
local s = renoise.song()
local cur_pattern = s:pattern(s.selected_pattern_index)
local cur_track = cur_pattern:track(track)
-- Copy from from_line to to_line
cur_track:line(to_line):copy_from(cur_track:line(from_line))
-- Clear from_line
cur_track:line(from_line):clear()
-- Clear to_line + 1 only if it's within the valid range
if to_line + 1 <= s.selected_pattern.number_of_lines then
cur_track:line(to_line + 1):clear()
end
end
function ExpandSelectionReplicate()
local s = renoise.song()
local currentLine = s.selected_line_index
if s.selection_in_pattern == nil then
renoise.app():show_status("Nothing selected to Expand, doing nothing.")
return
end
local sl = s.selection_in_pattern.start_line
local el = s.selection_in_pattern.end_line
local st = s.selection_in_pattern.start_track
local et = s.selection_in_pattern.end_track
local nl = s.selected_pattern.number_of_lines
-- Calculate the original and new selection lengths
local original_length = el - sl + 1
local new_end_line = el * 2
if new_end_line > nl then
new_end_line = nl
end
-- First pass: Expand the selection
for tr = st, et do
for l = el, sl, -1 do
if l ~= sl then
local new_line = (l * 2) - sl
if new_line <= nl then
cpclexrep_line(tr, l, new_line)
end
end
end
end
-- Update selection to include expanded area
local expanded_length = new_end_line - sl + 1
s.selection_in_pattern = {start_line=sl, start_track=st, end_track=et, end_line = new_end_line}
floodfill_with_selection()
renoise.app():show_status(string.format("Expanded and replicated selection from line %d to %d", sl, nl))
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-F Expand Selection Replicate",invoke=function() ExpandSelectionReplicate() end}
-----------------------------------------------------------------------------------------------
-------Protman's Shrink Selection
-- Renamed helper function to cpclshrep_line
function cpclshrep_line(track, from_line, to_line)
local s = renoise.song()
local cur_pattern = s:pattern(s.selected_pattern_index)
local cur_track = cur_pattern:track(track)
-- Copy from from_line to to_line
cur_track:line(to_line):copy_from(cur_track:line(from_line))
-- Clear from_line
cur_track:line(from_line):clear()
-- Clear from_line + 1 only if it's within the valid range
if from_line + 1 <= s.selected_pattern.number_of_lines then
cur_track:line(from_line + 1):clear()
end
end
function ShrinkSelectionReplicate()
local s = renoise.song()
local currentLine = s.selected_line_index
if s.selection_in_pattern == nil then
renoise.app():show_status("Nothing selected to Shrink, doing nothing.")
return
else
local sl = s.selection_in_pattern.start_line
local el = s.selection_in_pattern.end_line
local st = s.selection_in_pattern.start_track
local et = s.selection_in_pattern.end_track
local nl = s.selected_pattern.number_of_lines
-- Remove the problematic line index setting
-- renoise.song().selected_line_index = el + 1 -- This was causing the error
-- renoise.song().selected_line_index = currentLine
for tr = st, et do
for l = sl, el, 2 do
if l ~= sl then
-- Calculate new_line as an integer
local new_line = math.floor(l / 2 + sl / 2)
-- Ensure new_line is within valid range
if new_line >= 1 and new_line <= nl then
cpclshrep_line(tr, l, new_line)
end
end
end
end
-- Update selection to include shrunken area and trigger replication
local new_end_line = math.min(math.floor((el - sl) / 2) + sl, nl)
s.selection_in_pattern = {start_line=sl, start_track=st, end_track=et, end_line=new_end_line}
floodfill_with_selection()
renoise.app():show_status(string.format("Shrank and replicated selection from line %d to %d", sl, nl))
end
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-G Shrink Selection Replicate",invoke=function() ShrinkSelectionReplicate() end}
--------------------------------------------------------
--Protman's Set Instrument
function SetInstrument()
local s=renoise.song()
local EMPTY_INSTRUMENT = renoise.PatternTrackLine.EMPTY_INSTRUMENT
local pattern_iter = s.pattern_iterator
local pattern_index = s.selected_pattern_index
for _,line in pattern_iter:lines_in_pattern(pattern_index) do
-- will be nil when a send or the master track is iterated
for i=0,s.tracks[s.selected_track_index].visible_note_columns do
local first_note_column = line.note_columns[i]
if (first_note_column and
first_note_column.instrument_value ~= EMPTY_INSTRUMENT and
first_note_column.is_selected)
then
first_note_column.instrument_value = s.selected_instrument_index - 1 end
end
end
end
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Impulse Tracker ALT-S Set Selection to Instrument",invoke=function() SetInstrument() end}
----------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
function MarkTrackMarkPattern()
--Known bug: Has no idea as to what to do with Groups.
local st=nil
local et=nil
local sl=nil
local el=nil
local s=renoise.song()
local sip=s.selection_in_pattern
local sp=s.selected_pattern