-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PakettiTkna.lua
1495 lines (1245 loc) · 60.6 KB
/
PakettiTkna.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
-- All of these have been requested by tkna91 via
function loopReleaseToggle()
if renoise.song().selected_sample.loop_release
then renoise.song().selected_sample.loop_release=false
else renoise.song().selected_sample.loop_release=true end
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Loop Release On/Off",invoke=function() loopReleaseToggle() end}
function oneShotToggle()
if renoise.song().selected_sample.oneshot
then renoise.song().selected_sample.oneshot=false
else renoise.song().selected_sample.oneshot=true end
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample One-Shot On/Off",invoke=function() oneShotToggle() end}
function selectedSampleLoopSet(number)
renoise.song().selected_sample.oneshot=false
local loop_modet = renoise.song().selected_sample.loop_mode
if renoise.song().selected_sample.loop_mode==number then renoise.song().selected_sample.loop_mode=1 else loop_modet = number
renoise.song().selected_sample.loop_mode=loop_modet
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Loop 1 (Off)",invoke=function() selectedSampleLoopSet(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Loop 2 (Forward)",invoke=function() selectedSampleLoopSet(2) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Loop 3 (Backward)",invoke=function() selectedSampleLoopSet(3) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Loop 4 (PingPong)",invoke=function() selectedSampleLoopSet(4) end}
function selectedSampleTranspose(amount)
local currentSampleTranspose = renoise.song().selected_sample.transpose
local changedSampleTranspose = currentSampleTranspose + amount
if changedSampleTranspose > 120 then changedSampleTranspose = 120
else if changedSampleTranspose < -120 then changedSampleTranspose = -120 end end
renoise.song().selected_sample.transpose=changedSampleTranspose
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Transpose (-1)",invoke=function() selectedSampleTranspose(-1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Transpose (+1)",invoke=function() selectedSampleTranspose(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Transpose (-12)",invoke=function() selectedSampleTranspose(-12) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Transpose (+12)",invoke=function() selectedSampleTranspose(12) end}
renoise.tool():add_keybinding{name="Global:Paketti:Selected Sample Transpose (0)",invoke=function() renoise.song().selected_sample.transpose=0 end}
function selectedSampleFinetune(amount)
local currentSampleFinetune = renoise.song().selected_sample.fine_tune
local changedSampleFinetune = currentSampleFinetune + amount
if changedSampleFinetune > 127 then changedSampleFinetune = 127
else if changedSampleFinetune < -127 then changedSampleFinetune = -127 end end
renoise.song().selected_sample.fine_tune=changedSampleFinetune
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Finetune (-1)",invoke=function() selectedSampleFinetune(-1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Finetune (+1)",invoke=function() selectedSampleFinetune(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Finetune (-10)",invoke=function() selectedSampleFinetune(-10) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Finetune (+10)",invoke=function() selectedSampleFinetune(10) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Finetune (0)",invoke=function() renoise.song().selected_sample.fine_tune=0 end}
function selectedSamplePanning(amount)
local currentSamplePanning = renoise.song().selected_sample.panning
local changedSamplePanning = currentSamplePanning + amount
if changedSamplePanning > 1.0 then changedSamplePanning = 1.0
else if changedSamplePanning < 0.0 then changedSamplePanning = 0.0 end end
renoise.song().selected_sample.panning=changedSamplePanning
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Panning 0.5 (Center)",invoke=function() renoise.song().selected_sample.panning=0.5 end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Panning 0.0 (Left)",invoke=function() renoise.song().selected_sample.panning=0.0 end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Panning 1.0 (Right)",invoke=function() renoise.song().selected_sample.panning=1.0 end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Panning (+0.01)",invoke=function() selectedSamplePanning(0.01) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Panning (-0.01)",invoke=function() selectedSamplePanning(-0.01) end}
function selectedSampleVolume(amount)
local currentSampleVolume = renoise.song().selected_sample.volume
local changedSampleVolume = currentSampleVolume + amount
if changedSampleVolume > 4.0 then changedSampleVolume = 4.0
else if changedSampleVolume < 0.0 then changedSampleVolume = 0.0 end end
renoise.song().selected_sample.volume=changedSampleVolume
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Volume (+0.01)",invoke=function() selectedSampleVolume(0.01) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Volume (-0.01)",invoke=function() selectedSampleVolume(-0.01) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Volume Reset (0.0dB)",invoke=function() renoise.song().selected_sample.volume=1 end }
function selectedSampleInterpolation(amount)
renoise.song().selected_sample.interpolation_mode=amount
end
function selectedSampleOversampleOn()
renoise.song().selected_sample.oversample_enabled=true
end
function selectedSampleOversampleOff()
renoise.song().selected_sample.oversample_enabled=false
end
function selectedSampleOversampleToggle()
if renoise.song().selected_sample.oversample_enabled then
renoise.song().selected_sample.oversample_enabled = false else
renoise.song().selected_sample.oversample_enabled = true
end end
function selectedSampleAutoseekToggle()
if renoise.song().selected_sample.autoseek then
renoise.song().selected_sample.autoseek = false else
renoise.song().selected_sample.autoseek = true
end end
function selectedSampleAutofadeToggle()
if renoise.song().selected_sample.autofade then
renoise.song().selected_sample.autofade = false else
renoise.song().selected_sample.autofade = true
end end
function selectedSampleNNA(number)
renoise.song().selected_sample.new_note_action = number
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Interpolation to 1 (None)",invoke=function() selectedSampleInterpolation(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Interpolation to 2 (Linear)",invoke=function() selectedSampleInterpolation(2) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Interpolation to 3 (Cubic)",invoke=function() selectedSampleInterpolation(3) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Interpolation to 4 (Sinc)",invoke=function() selectedSampleInterpolation(4) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Oversample On",invoke=function() selectedSampleOversampleOn() end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Oversample Off",invoke=function() selectedSampleOversampleOff() end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Oversample On/Off",invoke=function() selectedSampleOversampleToggle() end}
function selectedSampleBeatsync(number)
renoise.song().selected_sample.beat_sync_mode = number
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync 1 (Repitch)",invoke=function() selectedSampleBeatsync(1) end }
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync 2 (Time-Stretch Percussion)",invoke=function() selectedSampleBeatsync(2) end }
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync 3 (Time-Stretch Texture)",invoke=function() selectedSampleBeatsync(3) end }
function selectedSampleBeatsyncAndToggleOn(number)
if renoise.song().selected_sample == nil then return else
if renoise.song().selected_sample.beat_sync_enabled and renoise.song().selected_sample.beat_sync_mode ~= number then
renoise.song().selected_sample.beat_sync_mode = number
return end
renoise.song().selected_sample.beat_sync_mode = number
if renoise.song().selected_sample.beat_sync_enabled == false then
renoise.song().selected_sample.beat_sync_enabled = true
renoise.song().selected_sample.beat_sync_mode = number
else
renoise.song().selected_sample.beat_sync_enabled = false
end
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync On/Off 1 (Repitch)",invoke=function() selectedSampleBeatsyncAndToggleOn(1) end }
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync On/Off 2 (Time-Stretch Percussion)",invoke=function() selectedSampleBeatsyncAndToggleOn(2) end }
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync On/Off 3 (Time-Stretch Texture)",invoke=function() selectedSampleBeatsyncAndToggleOn(3) end }
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync On/Off",invoke=function()
if renoise.song().selected_sample == nil then return else
if renoise.song().selected_sample.beat_sync_enabled then
renoise.song().selected_sample.beat_sync_enabled = false else
renoise.song().selected_sample.beat_sync_enabled = true
end end end}
function selectedSampleBeatsyncLine(number)
local currentBeatsyncLine = renoise.song().selected_sample.beat_sync_lines
local changedBeatsyncLine = currentBeatsyncLine + number
if changedBeatsyncLine > 512 then changedBeatsyncLine = 512
else if changedBeatsyncLine < 1 then -- renoise.song().selected_sample.beat_sync_enabled = false
return end end
renoise.song().selected_sample.beat_sync_lines=changedBeatsyncLine
renoise.song().selected_sample.beat_sync_enabled = true
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync Line (+1)",invoke=function() selectedSampleBeatsyncLine(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync Line (-1)",invoke=function() selectedSampleBeatsyncLine(-1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Autofade On/Off",invoke=function() selectedSampleAutofadeToggle() end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Autoseek On/Off",invoke=function() selectedSampleAutoseekToggle() end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample NNA to 1 (Cut)",invoke=function() selectedSampleNNA(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample NNA to 2 (Note-Off)",invoke=function() selectedSampleNNA(2) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample NNA to 3 (Continue)",invoke=function() selectedSampleNNA(3) end}
function selectedSampleMuteGroup(number)
if renoise.song().selected_sample == nil then return else
renoise.song().selected_sample.mute_group = number end
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to 0 (Off)",invoke=function() selectedSampleMuteGroup(0) end}
for i=1,9 do
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to ".. i,invoke=function() selectedSampleMuteGroup(i) end}
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to A",invoke=function() selectedSampleMuteGroup(10) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to B",invoke=function() selectedSampleMuteGroup(11) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to C",invoke=function() selectedSampleMuteGroup(12) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to D",invoke=function() selectedSampleMuteGroup(13) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to E",invoke=function() selectedSampleMuteGroup(14) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Mute Group to F",invoke=function() selectedSampleMuteGroup(15) end}
-- Change Output Routing per Selected Track
function set_output_routing_by_index(number)
local available_output_routings = renoise.song().tracks[renoise.song().selected_track_index].available_output_routings
if number >= 1 and number <= #available_output_routings then
renoise.song().tracks[renoise.song().selected_track_index].output_routing = available_output_routings[number]
else
print("Index out of range. Please use an index between 1 and " .. #available_output_routings)
end
end
function find_current_routing_index(available_routings, current_routing)
for index, routing in ipairs(available_routings) do
if routing == current_routing then
return index
end
end
return nil -- Return nil if the current routing is not found
end
function apply_selected_routing(selected_index)
local selected_track_index = renoise.song().selected_track_index
local available_output_routings = renoise.song().tracks[selected_track_index].available_output_routings
if selected_index and selected_index >= 1 and selected_index <= #available_output_routings then
renoise.song().tracks[selected_track_index].output_routing = available_output_routings[selected_index]
else
print("Index out of range. Please use an index between 1 and " .. #available_output_routings)
end
end
-- Function to open a dialog with the list of available output routings using a popup
function showAvailableRoutings()
local selected_track_index = renoise.song().selected_track_index
local available_output_routings = renoise.song().tracks[selected_track_index].available_output_routings
local current_routing = renoise.song().tracks[selected_track_index].output_routing
local selected_routing_index = find_current_routing_index(available_output_routings, current_routing)
-- Create a ViewBuilder object
local vb = renoise.ViewBuilder()
local dialog -- Pre-declare the dialog variable so it can be referenced inside button callbacks
-- Define the content of the dialog
local dialog_content = vb:column {
margin = 10,
spacing = 5,
vb:text {
text = "Select Output Routing:"
},
vb:popup {
id = "popup_output_routings",
items = available_output_routings,
value = selected_routing_index or 1, -- Set the popup to the current routing, or default to the first item
width = 300,
notifier = function(index)
-- Update the selected index when a new item is selected
selected_routing_index = index
end
},
vb:row {
spacing = 10,
vb:button {
text = "OK",
notifier = function()
apply_selected_routing(selected_routing_index)
dialog:close()
end
},
vb:button {
text = "Cancel",
notifier = function()
dialog:close()
end
}
}
}
-- Show the dialog
dialog = renoise.app():show_custom_dialog("Output Routings", dialog_content, my_keyhandler_func)
end
function simpleOutputRoute(output)
-- Get the selected track from the current song
local track = renoise.song().tracks[renoise.song().selected_track_index]
-- Check if the desired output index is within the range of available output routings
if output <= #track.available_output_routings then
-- If the index is valid, set the output routing
track.output_routing = track.available_output_routings[output]
else
-- If the index is invalid (i.e., the output doesn't exist), do nothing.
end
end
for i=0,63 do
renoise.tool():add_keybinding{
name="Global:Paketti:Set Selected Track Output Routing "..formatDigits(2,i),
invoke=function() simpleOutputRoute(i+1) end
}
end
--------
function pakettiMasterOutputRoutings(output)
local song=renoise.song()
local masterTrack=song:track(song.sequencer_track_count+1)
if output<=#masterTrack.available_output_routings then
masterTrack.output_routing=masterTrack.available_output_routings[output]
else
renoise.app():show_status("This Master Output Routing Channel is not available on the selected sound device.")
end
end
for i=0,63 do
renoise.tool():add_keybinding{
name="Global:Paketti:Set Master Track Output Routing "..string.format("%02d",i),
invoke=function() pakettiMasterOutputRoutings(i+1) end
}
end
-----
function setBeatsyncLineAbove()
local currentBeatsyncLine = renoise.song().selected_sample.beat_sync_lines
-- Calculate the next higher power of 2
local power = math.ceil(math.log(currentBeatsyncLine) / math.log(2))
local nextPowerOfTwo = 2 ^ power
if nextPowerOfTwo <= currentBeatsyncLine then -- Ensure we actually move up
nextPowerOfTwo = nextPowerOfTwo * 2
end
-- Clamp to maximum allowed value
if nextPowerOfTwo > 512 then nextPowerOfTwo = 512 end
renoise.song().selected_sample.beat_sync_lines = nextPowerOfTwo
renoise.song().selected_sample.beat_sync_enabled = true
end
function setBeatsyncLineBelow()
local currentBeatsyncLine = renoise.song().selected_sample.beat_sync_lines
if currentBeatsyncLine <= 1 then -- Prevent going below 1
return
end
local power = math.floor(math.log(currentBeatsyncLine) / math.log(2))
local prevPowerOfTwo = 2 ^ power
if prevPowerOfTwo >= currentBeatsyncLine then -- Ensure we actually move down
prevPowerOfTwo = prevPowerOfTwo / 2
end
renoise.song().selected_sample.beat_sync_lines = prevPowerOfTwo
renoise.song().selected_sample.beat_sync_enabled = true
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync Line (Power of Two Above)",invoke=function() setBeatsyncLineAbove() end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample Beatsync Line (Power of Two Below)",invoke=function() setBeatsyncLineBelow() end}
-- Function to toggle the sequence selection based on the provided sequence number
function tknaToggleSequenceSelection(number)
local seq_index = number + 1 -- Adjusting to 1-based index as required by Renoise
-- Check if the current selection matches the specified sequence number
if renoise.song().sequencer.selection_range and
#renoise.song().sequencer.selection_range == 2 and
renoise.song().sequencer.selection_range[1] == seq_index and
renoise.song().sequencer.selection_range[2] == seq_index then
-- If so, clear the selection
renoise.song().sequencer.selection_range = {}
else
-- Otherwise, set the selection to the specified sequence number
renoise.song().sequencer.selection_range = {seq_index, seq_index}
end
end
-- Loop to create keybindings for sequence numbers 00 to 32
for i = 1, 33 do
local padded_number = string.format("%02d", i - 1)
local keybinding_name = "Global:Paketti:Toggle Sequence Selection " .. padded_number
-- Create a keybinding for each sequence number
renoise.tool():add_keybinding{name=keybinding_name, invoke=function() tknaToggleSequenceSelection(i - 1) end}
end
-- Function to toggle the sequence selection based on the provided sequence number
-- If there is a selection_range, turn it into a sequence loop
function SequenceSelectionToLoop()
local song = renoise.song()
local selection_start = song.sequencer.selection_range[1]
local selection_end = song.sequencer.selection_range[2]
-- Check if the loop range matches the current selection
if song.transport.loop_sequence_range[1] == selection_start and
song.transport.loop_sequence_range[2] == selection_end then
-- If it matches, disable the loop by setting it to nil
song.transport.loop_sequence_range = {}
else
-- Otherwise, set the loop range to the current selection
song.transport.loop_sequence_range = { selection_start, selection_end }
end
end
-- Adding a key binding for the function
renoise.tool():add_keybinding{name="Global:Paketti:Toggle Sequence Selection to Loop",invoke=function() SequenceSelectionToLoop() end}
-- Adding a menu entry for the function
renoise.tool():add_menu_entry{name="Pattern Sequencer:Paketti..:Toggle Sequence Selection to Loop",invoke=function() SequenceSelectionToLoop() end}
renoise.tool():add_keybinding{name="Global:Paketti:Toggle Sequence Selection (All) On/Off",invoke=function()
local sequencerCount=#renoise.song().sequencer.pattern_sequence
--if renoise.song().sequencer.selection_range=={1,sequencerCount}
--then renoise.song().sequencer.selection_range={} else
renoise.song().sequencer.selection_range={1,#renoise.song().sequencer.pattern_sequence}
--end
end
}
function tknaUnselectSequenceSelection()
renoise.song().sequencer.selection_range={}
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Sequence Selection Off",invoke=tknaUnselectSequenceSelection}
-- Function to toggle the current sequence selection
function tknaToggleCurrentSequenceSelection()
-- Check if the current selection matches the selected sequence index
if renoise.song().sequencer.selection_range and
#renoise.song().sequencer.selection_range == 2 and
renoise.song().sequencer.selection_range[1] == renoise.song().selected_sequence_index and
renoise.song().sequencer.selection_range[2] == renoise.song().selected_sequence_index then
-- If so, clear the selection
renoise.song().sequencer.selection_range = {}
else
-- Otherwise, set the selection to the current sequence index
renoise.song().sequencer.selection_range = {renoise.song().selected_sequence_index, renoise.song().selected_sequence_index}
end
end
-- Add keybinding for the function
renoise.tool():add_keybinding{name="Global:Paketti:Toggle Current Sequence Selection On/Off", invoke=tknaToggleCurrentSequenceSelection}
-- Helper function to select and loop a specific section
function select_and_loop_section(section_number)
local song = renoise.song()
local sequencer = song.sequencer
local sequence_count = #sequencer.pattern_sequence
local current_section_start = nil
local current_section_index = 0
-- Find the start index of the specific section
for i = 1, sequence_count do
if sequencer:sequence_is_start_of_section(i) then
current_section_index = current_section_index + 1
if current_section_index == section_number then
current_section_start = i
break
end
end
end
-- If the specified section is not found, exit the function
if not current_section_start then
renoise.app():show_status("No such Section exists, doing nothing.")
return
end
-- Find the end index of the current section
local current_section_end = sequence_count
for i = current_section_start + 1, sequence_count do
if sequencer:sequence_is_start_of_section(i) then
current_section_end = i - 1
break
end
end
-- Set the loop to the current section
song.transport.loop_sequence_range = {current_section_start, current_section_end}
-- Notify the user
renoise.app():show_status("Loop set to section " .. section_number .. " from sequence " .. current_section_start .. " to " .. current_section_end)
end
-- Helper function to find the current section index
function find_current_section_index()
local song = renoise.song()
local sequencer = song.sequencer
local sequence_count = #sequencer.pattern_sequence
local current_pos = song.transport.edit_pos.sequence
local loop_start = song.transport.loop_sequence_range[1]
local loop_end = song.transport.loop_sequence_range[2]
-- Check if a section is currently selected
if loop_start > 0 and loop_end > 0 and loop_start <= loop_end then
local current_section_index = 0
for i = 1, sequence_count do
if sequencer:sequence_is_start_of_section(i) then
current_section_index = current_section_index + 1
if loop_start == i then
return current_section_index
end
end
end
end
-- If no section is selected, find the section based on the current edit position
local current_section_index = 0
for i = 1, sequence_count do
if sequencer:sequence_is_start_of_section(i) then
current_section_index = current_section_index + 1
if i > current_pos then
return current_section_index - 1
end
end
end
return current_section_index
end
-- Function to select and loop the next section
function select_and_loop_section_next()
local current_section_index = find_current_section_index()
if current_section_index < 32 then
select_and_loop_section(current_section_index + 1)
else
renoise.app():show_status("There is no Next Section available.")
end
end
-- Function to select and loop the previous section
function select_and_loop_section_previous()
local current_section_index = find_current_section_index()
if current_section_index > 1 then
select_and_loop_section(current_section_index - 1)
else
renoise.app():show_status("There is no Previous Section available.")
end
end
-- Function to turn off the sequence selection
function set_sequence_selection_off()
local song = renoise.song()
song.transport.loop_sequence_range = {0, 0}
renoise.app():show_status("Sequence selection turned off.")
end
-- Function to select and loop a specific section, or deselect it if already selected
function select_and_loop_section(section_index)
local song = renoise.song()
local sequencer = song.sequencer
local sequence_count = #sequencer.pattern_sequence
local current_section_index = 0
local loop_start = 0
local loop_end = 0
for i = 1, sequence_count do
if sequencer:sequence_is_start_of_section(i) then
current_section_index = current_section_index + 1
if current_section_index == section_index then
loop_start = i
for j = i + 1, sequence_count do
if sequencer:sequence_is_start_of_section(j) then
loop_end = j - 1
break
end
end
if loop_end == 0 then
loop_end = sequence_count
end
break
end
end
end
if song.transport.loop_sequence_range[1] == loop_start and song.transport.loop_sequence_range[2] == loop_end then
set_sequence_selection_off()
else
song.transport.loop_sequence_range = {loop_start, loop_end}
renoise.app():show_status("Looped section " .. section_index)
end
end
for section_number = 1, 32 do
renoise.tool():add_keybinding{name="Global:Paketti:Select and Loop Sequence Section " .. string.format("%02d", section_number),
invoke=function() select_and_loop_section(section_number) end
}
end
renoise.tool():add_keybinding{name="Global:Paketti:Select and Loop Section (Next)",invoke=select_and_loop_section_next}
renoise.tool():add_keybinding{name="Global:Paketti:Select and Loop Section (Previous)",invoke=select_and_loop_section_previous}
renoise.tool():add_keybinding{name="Global:Paketti:Set Sequence Loop Selection Off",invoke=set_sequence_selection_off}
function tknaNextSequence(count)
local currSeq = renoise.song().selected_sequence_index
local nextSeq = currSeq + count
local total_sequences = #renoise.song().sequencer.pattern_sequence
if nextSeq < 1 then renoise.app():show_status("You are on the first sequence.") return else
if nextSeq <= total_sequences then
renoise.song().selected_sequence_index = nextSeq
else
renoise.app():show_status("No more sequences available.")
end
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Jump to Sequence (Next)",invoke=function() tknaNextSequence(1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Jump to Sequence (Previous)",invoke=function() tknaNextSequence(-1) end}
function tknaContinueSequenceFromSameLine(number)
local storedSequence = renoise.song().selected_sequence_index
local storedRow = renoise.song().selected_line_index
if number <= #renoise.song().sequencer.pattern_sequence then
if renoise.song().transport.follow_player then
renoise.song().selected_sequence_index = number
else
renoise.song().transport.follow_player = true
renoise.song().selected_sequence_index = number
renoise.song().transport.follow_player = false
renoise.song().selected_sequence_index=storedSequence
renoise.song().selected_line_index=storedRow
end
else
renoise.app():show_status("Sequence does not exist, doing nothing.")
end
end
for i = 1, 32 do
-- Zero-pad the number for sequence naming
local padded_number = string.format("%02d", i - 1)
-- Add keybinding for each sequence
renoise.tool():add_keybinding{name="Global:Paketti:Continue Sequence " .. padded_number .. " From Same Line", invoke=function()
if i < #renoise.song().sequencer.pattern_sequence then
tknaContinueSequenceFromSameLine(i)
else
renoise.song():show_status("Sequence does not exist, doing nothing.")
end
end}
end
--------
function tknaContinueCurrentSequenceFromCurrentLine()
local song = renoise.song()
local storedSequence = song.selected_sequence_index
local step = 1
local function processStep()
if step == 1 then
renoise.song().transport.follow_player = true
renoise.app():show_status("Jumping to Previously Selected (Current) Sequence")
step = step + 1
elseif step == 2 then
renoise.song().selected_sequence_index = storedSequence
step = step + 1
elseif step == 3 then
renoise.song().transport.follow_player = false
renoise.tool().app_idle_observable:remove_notifier(processStep)
end
end
renoise.tool().app_idle_observable:add_notifier(processStep)
end
renoise.tool():add_keybinding{name="Global:Paketti:Continue Current Sequence From Same Line", invoke=function()
tknaContinueCurrentSequenceFromCurrentLine()
end}
---------
function tknaMidiMapSequence(value)
local max_seq = #renoise.song().sequencer.pattern_sequence - 1
local sequence_num = math.floor((value / 127) * max_seq) + 1
tknaContinueSequenceFromSameLine(sequence_num)
end
-- Add MIDI mapping
renoise.tool():add_midi_mapping{name="Paketti:Continue Sequence From Same Line [Set Sequence]", invoke=function(message)
if message:is_abs_value() then
tknaMidiMapSequence(message.int_value)
end
end}
--------
for i = 1, 32 do
-- Zero-pad the number for sequence naming
local padded_number = string.format("%02d", i - 1)
-- Add keybinding for each sequence
renoise.tool():add_keybinding{name="Global:Paketti:Selected Specific Sequence " .. padded_number, invoke=function()
if i < #renoise.song().sequencer.pattern_sequence then
renoise.song().selected_sequence_index = i
else renoise.app():show_status("Sequence does not exist, doing nothing.")
end
end}
end
function tknaTriggerSequence(number)
local total_sequences = #renoise.song().sequencer.pattern_sequence
if number < total_sequences then
renoise.song().transport:trigger_sequence(number)
else
renoise.app():show_status("This sequence position does not exist.")
end
end
for i = 1, 32 do
local padded_number = string.format("%02d", i - 1)
renoise.tool():add_keybinding{name="Global:Paketti:Trigger Sequence " .. padded_number, invoke=function() tknaTriggerSequence(i) end}
end
function tknaSetSequenceAsScheduledList(number)
if renoise.song().transport.playing then else renoise.song().transport.playing=true
end
local total_sequences = #renoise.song().sequencer.pattern_sequence
if number < total_sequences then
renoise.song().transport:set_scheduled_sequence(number)
else
renoise.app():show_status("This sequence position does not exist.")
end
end
for i = 1,32 do
local padded_number = string.format("%02d", i - 1)
-- Add keybinding for each sequence
renoise.tool():add_keybinding{name="Global:Paketti:Set Sequence " .. padded_number .. " as Scheduled List", invoke=function() tknaSetSequenceAsScheduledList(i) end}
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Current Sequence as Scheduled List", invoke=function()
renoise.song().transport:set_scheduled_sequence(renoise.song().selected_sequence_index) end}
renoise.tool():add_keybinding{name="Global:Paketti:Add Current Sequence to Scheduled List", invoke=function()
renoise.song().transport:add_scheduled_sequence(renoise.song().selected_sequence_index) end}
function tknaAddSequenceToScheduledList(number)
if renoise.song().transport.playing then else renoise.song().transport.playing=true
end
local total_sequences = #renoise.song().sequencer.pattern_sequence
if number < total_sequences then
renoise.song().transport:add_scheduled_sequence(number)
else
renoise.app():show_status("This sequence position does not exist.")
end
end
for i = 1,32 do
local padded_number = string.format("%02d", i - 1)
-- Add keybinding for each sequence
renoise.tool():add_keybinding{name="Global:Paketti:Add Sequence " .. padded_number .. " to Scheduled List", invoke=function() tknaAddSequenceToScheduledList(i) end}
end
for i = 1, 32 do
local padded_number = string.format("%02d", i - 1)
renoise.tool():add_keybinding{
name="Global:Paketti:Toggle Sequence Loop to " .. padded_number,
invoke=function()
local total_sequences = #renoise.song().sequencer.pattern_sequence
if i <= total_sequences then
local current_range = renoise.song().transport.loop_sequence_range
if current_range[1] == i and current_range[2] == i then
-- Turn off the loop
renoise.song().transport.loop_sequence_range = {}
renoise.app():show_status("Sequence loop turned off.")
else
-- Set the loop to the specified range
renoise.song().transport.loop_sequence_range = {i, i}
renoise.app():show_status("Sequence loop set to " .. padded_number)
end
else
renoise.app():show_status("This sequence does not exist.")
end
end
}
end
renoise.tool():add_keybinding{name="Global:Paketti:Clear Pattern Sequence Loop",invoke=function()
renoise.song().transport.loop_sequence_range = {} end}
-- Function to compare two tables for value equality
function tables_equal(t1, t2)
if #t1 ~= #t2 then
return false
end
for i = 1, #t1 do
if t1[i] ~= t2[i] then
return false
end
end
return true
end
-- Function to set the sequence loop from current loop position to specified position
function setSequenceLoopFromCurrentTo(position)
local total_sequences = #renoise.song().sequencer.pattern_sequence
local current_range = renoise.song().transport.loop_sequence_range
-- Ensure the specified position is within the valid range
if position > total_sequences then
renoise.app():show_status("This sequence does not exist.")
return
end
-- Check if current_range is {0,0} using the tables_equal function
if tables_equal(current_range, {0,0}) then
renoise.song().transport.loop_sequence_range = {position, position}
return
end
local current_start = current_range[1]
-- Check if the specified position is valid for setting the loop
if position < current_start then
renoise.song().transport.loop_sequence_range = {position, current_start}
renoise.app():show_status("Sequence loop set from " .. position .. " to " .. current_start)
else
renoise.song().transport.loop_sequence_range = {current_start, position}
renoise.app():show_status("Sequence loop set from " .. current_start .. " to " .. position)
end
end
-- Loop to create keybindings for setting the loop range from current to specified position
for i = 1, 32 do
local padded_number = string.format("%02d", i - 1)
renoise.tool():add_keybinding{name="Global:Paketti:Set Sequence Loop from Current to " .. padded_number,invoke=function()
setSequenceLoopFromCurrentTo(i)
end}
end
-- Function to set the scheduled sequence as the current section
function tknaSetCurrentSectionAsScheduledSequence()
local song = renoise.song()
local sequencer = song.sequencer
local transport = song.transport
local current_sequence_index = song.selected_sequence_index
local total_sequences = #sequencer.pattern_sequence
-- Helper function to find all sections
local function findSections()
local sections = {}
for i = 1, total_sequences do
if sequencer:sequence_is_start_of_section(i) then
table.insert(sections, i)
end
end
return sections
end
-- Helper function to find the section index for a given sequence index
local function findSectionIndex(sections, sequence_index)
local total_sections = #sections
for i, section_start in ipairs(sections) do
local section_end = (i < total_sections) and (sections[i + 1] - 1) or total_sequences
if sequence_index >= section_start and sequence_index <= section_end then
return i, section_start, section_end
end
end
return nil
end
local sections = findSections()
local current_section_index, current_section_start, current_section_end = findSectionIndex(sections, current_sequence_index)
-- Set the scheduled sequence to the current section if it exists
if current_section_index then
transport:set_scheduled_sequence(current_section_start)
for i = current_section_start + 1, current_section_end do
transport:add_scheduled_sequence(i)
end
renoise.app():show_status("Set scheduled sequence to current section: " .. current_section_start .. " to " .. current_section_end)
else
renoise.app():show_status("Current sequence is not inside any section.")
end
end
-- Function to add the current section to the scheduled sequences
function tknaAddCurrentSectionToScheduledSequences()
local song = renoise.song()
local sequencer = song.sequencer
local transport = song.transport
local current_sequence_index = song.selected_sequence_index
local total_sequences = #sequencer.pattern_sequence
-- Helper function to find all sections
local function findSections()
local sections = {}
for i = 1, total_sequences do
if sequencer:sequence_is_start_of_section(i) then
table.insert(sections, i)
end
end
return sections
end
-- Helper function to find the section index for a given sequence index
local function findSectionIndex(sections, sequence_index)
local total_sections = #sections
for i, section_start in ipairs(sections) do
local section_end = (i < total_sections) and (sections[i + 1] - 1) or total_sequences
if sequence_index >= section_start and sequence_index <= section_end then
return i, section_start, section_end
end
end
return nil
end
local sections = findSections()
local current_section_index, current_section_start, current_section_end = findSectionIndex(sections, current_sequence_index)
-- Add the current section to the scheduled sequences if it exists
if current_section_index then
for i = current_section_start, current_section_end do
transport:add_scheduled_sequence(i)
end
renoise.app():show_status("Added current section to scheduled sequences: " .. current_section_start .. " to " .. current_section_end)
else
renoise.app():show_status("Current sequence is not inside any section.")
end
end
-- Adding keybindings for the functions
renoise.tool():add_keybinding{name="Global:Paketti:Set Current Section as Scheduled Sequence",invoke=tknaSetCurrentSectionAsScheduledSequence}
renoise.tool():add_keybinding{name="Global:Paketti:Add Current Section to Scheduled Sequences",invoke=tknaAddCurrentSectionToScheduledSequences}
-- Adding menu entries for the functions
renoise.tool():add_menu_entry{name="Pattern Sequencer:Paketti..:Set Current Section as Scheduled Sequence",invoke=tknaSetCurrentSectionAsScheduledSequence}
renoise.tool():add_menu_entry{name="Pattern Sequencer:Paketti..:Add Current Section to Scheduled Sequences",invoke=tknaAddCurrentSectionToScheduledSequences}
-- Adding MIDI mappings for the functions
renoise.tool():add_midi_mapping{name="Paketti:Set Current Section as Scheduled Sequence",invoke=tknaSetCurrentSectionAsScheduledSequence}
renoise.tool():add_midi_mapping{name="Paketti:Add Current Section to Scheduled Sequences",invoke=tknaAddCurrentSectionToScheduledSequences}
-- Function to expand the section loop step-by-step, adding the next section
function expandSectionLoopNext()
local song = renoise.song()
local sequencer = song.sequencer
local transport = song.transport
local current_sequence_index = song.selected_sequence_index
local total_sequences = #sequencer.pattern_sequence
-- Helper function to find all sections
local function findSectionsA()
local sections = {}
for i = 1, total_sequences do
if sequencer:sequence_is_start_of_section(i) then
table.insert(sections, i)
end
end
return sections
end
local sections = findSectionsA()
local total_sections = #sections
-- Helper function to find the section index for a given sequence index
local function findSectionIndexA(sequence_index)
for i, section_start in ipairs(sections) do
local section_end = (i < total_sections) and (sections[i + 1] - 1) or total_sequences
if sequence_index >= section_start and sequence_index <= section_end then
return i, section_start, section_end
end
end
return nil
end
local current_section_index, current_section_start, current_section_end = findSectionIndexA(current_sequence_index)
local loop_range = transport.loop_sequence_range
-- If no loop range or an invalid loop range exists, set it to the current section
if not loop_range or #loop_range ~= 2 or
(loop_range[1] == 0 and loop_range[2] == 0) then
if current_section_index then
transport.loop_sequence_range = {current_section_start, current_section_end}