-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPakettiEightOneTwenty.lua
1914 lines (1704 loc) · 73.4 KB
/
PakettiEightOneTwenty.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
-- Paketti Groovebox 8120 Script
-- Add this line right after stored_step_counts
local sequential_load_current_row = 1
-- "Random" keybinding: Selects a random sample and mutes others
function sample_random()
local song = renoise.song()
local ing = song.selected_instrument
-- Edge case: no instrument or no samples
if not ing or #ing.samples == 0 then
renoise.app():show_status("No instrument or samples available.")
return
end
-- Pick a random sample index
local random_index = math.random(1, #ing.samples)
song.selected_sample_index = random_index
-- Set velocity ranges accordingly
pakettiSampleVelocityRangeChoke(random_index)
end
-- Function to update track name with step count
local function updateTrackNameWithSteps(track, steps)
local base_name = track.name:match("8120_%d+")
if base_name then
track.name = string.format("%s[%03d]", base_name, steps)
end
end
-- Function to get step count from track name
local function getStepsFromTrackName(track_name)
local steps = track_name:match("%[(%d+)%]")
return steps and tonumber(steps) or 16 -- Default to 16 if no steps found
end
-- Initialization
local vb = renoise.ViewBuilder()
local dialog, rows = nil, {}
local track_names, track_indices, instrument_names
local play_checkbox, follow_checkbox, bpm_display, groove_enabled_checkbox, random_gate_button, fill_empty_label, fill_empty_slider, global_step_buttons, global_controls
local local_groove_sliders, local_groove_labels
local number_buttons_row
local number_buttons
local initializing = false -- Add initializing flag
-- Ensure instruments exist
function ensure_instruments_exist()
local instrument_count = #renoise.song().instruments
if instrument_count < 8 then
for i = instrument_count + 1, 8 do
renoise.song():insert_instrument_at(i)
renoise.song().instruments[i].name = "Instrument " .. i
end
end
instrument_names = {}
for i, instr in ipairs(renoise.song().instruments) do
table.insert(instrument_names, instr.name ~= "" and instr.name or "Instrument " .. i)
end
end
-- Function to update instrument and track lists
function update_instrument_list_and_popups()
instrument_names = {}
for i, instr in ipairs(renoise.song().instruments) do
table.insert(instrument_names, instr.name ~= "" and instr.name or "Instrument " .. i)
end
for i, row_elements in ipairs(rows) do
local instrument_popup = row_elements.instrument_popup
local previous_value = instrument_popup.value
instrument_popup.items = instrument_names
if previous_value <= #instrument_names then
instrument_popup.value = previous_value
else
instrument_popup.value = 1
end
row_elements.update_sample_name_label()
end
track_names = {}
track_indices = {}
for i, track in ipairs(renoise.song().tracks) do
if track.type == renoise.Track.TRACK_TYPE_SEQUENCER then
table.insert(track_names, track.name)
table.insert(track_indices, i)
end
end
for i, row_elements in ipairs(rows) do
local track_popup = row_elements.track_popup
local previous_value = track_popup.value
track_popup.items = track_names
if previous_value <= #track_names then
track_popup.value = previous_value
else
track_popup.value = 1
end
end
end
-- Function to create a row in the UI
function PakettiEightSlotsByOneTwentyCreateRow(row_index)
local row_elements = {}
local normal_color, highlight_color = nil, {0x22 / 255, 0xaa / 255, 0xff / 255}
-- Create Number Buttons (1-16)
local number_buttons = {}
for i = 1, 16 do
local is_highlight = (i == 1 or i == 5 or i == 9 or i == 13)
number_buttons[i] = vb:button {
text = string.format("%02d", i),
width = 30,
color = is_highlight and highlight_color or normal_color,
notifier = function() end,
active = false
}
end
-- Add Output Delay Controls
local output_delay_label = vb:text {
text = "Output Delay",
font = "bold",
style = "strong"
}
local output_delay_value_label = vb:text {
text = "0ms",
width= 50,
font = "bold",
style = "strong"
}
-- In PakettiEightSlotsByOneTwentyCreateRow, after creating the output delay controls:
local output_delay_slider = vb:slider {
min = -100,
max = 100,
steps = {1, -1},
value = renoise.song().tracks[row_index].output_delay, -- Initialize with current value
width = 150,
notifier = function(value)
local track_index = track_indices[row_elements.track_popup.value]
if track_index then
value = math.floor(value) -- Ensure whole number
renoise.song().tracks[track_index].output_delay = value
output_delay_value_label.text = string.format("%+04dms", value)
end
end
}
-- Initialize the label with the current value
output_delay_value_label.text = string.format("%+04dms", renoise.song().tracks[row_index].output_delay)
local output_delay_reset = vb:button {
text = "Reset",
notifier = function()
local track_index = track_indices[row_elements.track_popup.value]
if track_index then
output_delay_slider.value = 0
renoise.song().tracks[track_index].output_delay = 0
output_delay_value_label.text = "0ms" -- Consistent format when reset
end
end
}
local number_buttons_row = vb:row(number_buttons)
-- Add Output Delay Controls to the same row
number_buttons_row:add_child(output_delay_label)
number_buttons_row:add_child(output_delay_slider)
number_buttons_row:add_child(output_delay_value_label)
number_buttons_row:add_child(output_delay_reset)
-- Create Note Checkboxes (1-16)
local checkboxes = {}
local checkbox_row_elements = {}
for i = 1, 16 do
checkboxes[i] = vb:checkbox {
value = false,
width = 30,
notifier = function()
if not row_elements.updating_checkboxes then
row_elements.print_to_pattern()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
end
}
table.insert(checkbox_row_elements, checkboxes[i])
end
-- Valuebox for Steps
local valuebox = vb:valuebox {
min = 1,
max = 512,
value = 16, -- Default to 16, will be updated in initialize_row()
width = 55,
notifier = function(value)
if not row_elements.updating_steps then
local track_index = track_indices[row_elements.track_popup.value]
local track = renoise.song():track(track_index)
updateTrackNameWithSteps(track, value)
row_elements.print_to_pattern()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
else
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
end
}
-- Sample Name Label
local sample_name_label = vb:text {
text = "Sample Name",
font = "bold",
style = "strong"
}
-- Append valuebox and sample name label after checkboxes
table.insert(checkbox_row_elements, valuebox)
table.insert(checkbox_row_elements, sample_name_label)
-- Create Yxx Checkboxes (1-16)
local yxx_checkboxes = {}
local yxx_checkbox_row_elements = {}
for i = 1, 16 do
yxx_checkboxes[i] = vb:checkbox {
value = false,
width = 30,
notifier = function()
if not row_elements.updating_yxx_checkboxes then
row_elements.print_to_pattern()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
end
}
table.insert(yxx_checkbox_row_elements, yxx_checkboxes[i])
end
-- Create the valuebox first
local yxx_valuebox = vb:valuebox {
min = 0,
max = 255,
value = 0, -- Initialize to 00
width = 55,
tostring = function(value)
return string.format("%02X", value)
end,
tonumber = function(text)
return tonumber(text, 16)
end,
notifier = function(value)
row_elements.print_to_pattern()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
}
-- Create the slider that updates the valuebox
local yxx_slider = vb:slider {
min = 0,
max = 255,
steps = {1, -1},
value = 32, -- Default to 0x20
width = 300,
notifier = function(value)
yxx_valuebox.value = math.floor(value)
row_elements.print_to_pattern()
end
}
row_elements.yxx_slider = yxx_slider
-- Append yxx_valuebox and label after yxx checkboxes
table.insert(yxx_checkbox_row_elements, yxx_valuebox)
table.insert(yxx_checkbox_row_elements, vb:text {font="bold",style="strong",text = "Yxx"})
-- Randomize Button for Yxx Slider
local yxx_randomize_button = vb:button {
text = "Random Yxx",
width = 70, -- Adjust width as needed
notifier = function()
local random_value = math.random(0, 255)
yxx_slider.value = random_value
yxx_valuebox.value = random_value
row_elements.print_to_pattern()
end
}
-- **Clear Button for Yxx Checkboxes**
local yxx_clear_button = vb:button {
text = "Clear Yxx",
width = 40, -- Adjust width as needed
notifier = function()
for _, checkbox in ipairs(yxx_checkboxes) do
checkbox.value = false
end
row_elements.print_to_pattern()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
}
-- Add slider and buttons to yxx_checkbox_row_elements
table.insert(yxx_checkbox_row_elements, yxx_slider)
table.insert(yxx_checkbox_row_elements, yxx_randomize_button)
table.insert(yxx_checkbox_row_elements, yxx_clear_button)
-- === End of Yxx Value Buttons Addition ===
-- Adjusted Track Popup
local default_track_index = row_index
if default_track_index > #track_names then
default_track_index = ((row_index - 1) % #track_names) + 1 -- Wrap around
end
local track_popup = vb:popup {
items = track_names,
value = default_track_index,
notifier = function(value)
row_elements.initialize_row()
end
}
local mute_checkbox = vb:checkbox {
value = false,
notifier = function(value)
local track_index = track_indices[track_popup.value]
local track = renoise.song().tracks[track_index]
track.mute_state = value and renoise.Track.MUTE_STATE_MUTED or renoise.Track.MUTE_STATE_ACTIVE
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
}
-- Function to map sample index to slider value
function row_elements.sample_to_slider_value(sample_index, num_samples)
if num_samples <= 0 then return 1 end
-- Reverse the mapping: sample index -> slider value
return math.floor(1 + ((sample_index - 1) * 120) / num_samples)
end
-- Function to map slider value to sample index
function row_elements.slider_to_sample_index(slider_value, num_samples)
if num_samples <= 0 then return 1 end
-- Map slider value -> sample index
local actual_value = math.floor(1 + ((slider_value - 1) / 120) * num_samples)
return math.max(1, math.min(actual_value, num_samples))
end
local slider = vb:slider {
min = 1,
max = 120,
value = 1,
width = 130,
steps = {1, -1},
notifier = function(value)
value = math.floor(value)
local instrument_index = row_elements.instrument_popup.value
local instrument = renoise.song().instruments[instrument_index]
if instrument and instrument.samples[1] and instrument.samples[1].slice_markers and #instrument.samples[1].slice_markers > 0 then
renoise.app():show_status("This instrument contains Slices, doing nothing.")
return
end
renoise.song().selected_instrument_index = instrument_index
-- Set the selected track before changing the sample
local track_index = track_indices[row_elements.track_popup.value]
renoise.song().selected_track_index = track_index
if instrument and #instrument.samples > 0 then
value = math.min(value, #instrument.samples)
pakettiSampleVelocityRangeChoke(value)
end
row_elements.update_sample_name_label()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
}
-- Update the slider value when updating sample name label
local original_update_sample_name_label = row_elements.update_sample_name_label
row_elements.update_sample_name_label = function()
original_update_sample_name_label()
local instrument_index = row_elements.instrument_popup.value
local instrument = renoise.song().instruments[instrument_index]
if instrument and #instrument.samples > 0 then
slider.value = renoise.song().selected_sample_index
end
end
-- Adjusted Instrument Popup
local instrument_popup = vb:popup {
items = instrument_names,
value = row_index, -- Set default instrument index to row number
width = 150,
notifier = function(value)
row_elements.print_to_pattern()
row_elements.update_sample_name_label()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
}
-- Function to Print to Pattern
function row_elements.print_to_pattern()
if initializing then return end
local song = renoise.song()
local pattern = song.selected_pattern
local pattern_length = pattern.number_of_lines
local steps = valuebox.value
local track_index = track_indices[track_popup.value]
local instrument_index = instrument_popup.value
local track_in_pattern = pattern.tracks[track_index]
-- Ensure the track has at least one visible effect column
local track = renoise.song().tracks[track_index]
if track.visible_effect_columns == 0 then
track.visible_effect_columns = 1
end
-- First clear all lines in the pattern for this track
for line = 1, pattern_length do
local note_line = track_in_pattern:line(line).note_columns[1]
local effect_column = track_in_pattern:line(line).effect_columns[1]
note_line:clear()
effect_column:clear()
end
-- Only write notes to the first 16 steps
for line = 1, math.min(16, steps) do
local note_checkbox_value = checkboxes[line].value
local yxx_checkbox_value = yxx_checkboxes[line].value
local note_line = track_in_pattern:line(line).note_columns[1]
local effect_column = track_in_pattern:line(line).effect_columns[1]
if note_checkbox_value then
note_line.note_string = "C-4"
note_line.instrument_value = instrument_index - 1
if yxx_checkbox_value then
effect_column.number_string = "0Y"
effect_column.amount_value = yxx_valuebox.value
else
effect_column:clear()
end
end
end
-- Repeat the pattern if needed
if pattern_length > steps then
local full_repeats = math.floor(pattern_length / steps)
for repeat_num = 1, full_repeats - 1 do
local start_line = repeat_num * steps + 1
for line = 1, math.min(16, steps) do
local source_line = track_in_pattern:line(line)
local dest_line = track_in_pattern:line(start_line + line - 1)
dest_line.note_columns[1]:copy_from(source_line.note_columns[1])
dest_line.effect_columns[1]:copy_from(source_line.effect_columns[1])
end
end
end
end
-- Function to Update Sample Name Label
function row_elements.update_sample_name_label()
local instrument = renoise.song().instruments[instrument_popup.value]
local sample_name = "No sample available"
if instrument and #instrument.samples > 0 then
for _, sample in ipairs(instrument.samples) do
local velocity_min = sample.sample_mapping and sample.sample_mapping.velocity_range and sample.sample_mapping.velocity_range[1]
local velocity_max = sample.sample_mapping and sample.sample_mapping.velocity_range and sample.sample_mapping.velocity_range[2]
if velocity_min == 0x00 and velocity_max == 0x7F then
sample_name = sample.name ~= "" and sample.name or "Sample " .. sample.index
-- Truncate sample name if longer than 50 characters
if #sample_name > 50 then
sample_name = sample_name:sub(1, 47) .. "..."
end
break
end
end
end
sample_name_label.text = sample_name
end
-- Function to Initialize Row
function row_elements.initialize_row()
local track_index = track_indices[track_popup.value]
if track_index then
local track = renoise.song().tracks[track_index]
-- Get step count from track name when initializing row
local step_count = getStepsFromTrackName(track.name)
valuebox.value = step_count
local current_delay = renoise.song().tracks[track_index].output_delay
output_delay_slider.value = current_delay
output_delay_value_label.text = string.format("%+04dms", current_delay)
end
local track = renoise.song().tracks[track_index]
local pattern = renoise.song().selected_pattern
local line_count = pattern.number_of_lines
row_elements.updating_checkboxes = true
row_elements.updating_yxx_checkboxes = true
for i = 1, 16 do
checkboxes[i].active = false
checkboxes[i].value = false
yxx_checkboxes[i].active = false
yxx_checkboxes[i].value = false
end
local yxx_value_found = false
for line = 1, math.min(line_count, 16) do
local note_line = pattern.tracks[track_index].lines[line].note_columns[1]
local effect_column = pattern.tracks[track_index].lines[line].effect_columns[1]
if note_line and note_line.note_string == "C-4" then
checkboxes[line].value = true
if effect_column and effect_column.number_string == "0Y" then
yxx_checkboxes[line].value = true
yxx_valuebox.value = effect_column.amount_value
yxx_value_found = true
else
yxx_checkboxes[line].value = false
end
end
end
if not yxx_value_found then
yxx_valuebox.value = 0 -- Initialize to 00 if no Yxx content
end
local mute = track.mute_state == renoise.Track.MUTE_STATE_MUTED
mute_checkbox.value = mute
-- Find the current 00-7F sample and set slider accordingly
local instrument = renoise.song().instruments[instrument_popup.value]
if instrument then
local found_samples = {}
for sample_index, sample in ipairs(instrument.samples) do
local velocity_min = sample.sample_mapping and sample.sample_mapping.velocity_range and sample.sample_mapping.velocity_range[1]
local velocity_max = sample.sample_mapping and sample.sample_mapping.velocity_range and sample.sample_mapping.velocity_range[2]
if velocity_min == 0x00 and velocity_max == 0x7F then
table.insert(found_samples, sample_index)
end
end
-- If exactly one 00-7F sample found, set slider to that index
-- Otherwise, set to minimum value
if #found_samples == 1 then
slider.value = found_samples[1]
else
slider.value = 1
end
end
local instrument_used = nil
for line = 1, math.min(line_count, 16) do
local note_line = pattern.tracks[track_index].lines[line].note_columns[1]
if note_line and not note_line.is_empty and note_line.note_string ~= '---' then
instrument_used = note_line.instrument_value
break
end
end
if instrument_used and instrument_used + 1 <= #instrument_names then
instrument_popup.value = instrument_used + 1
else
instrument_popup.value = row_index -- Set default instrument index to row number
end
row_elements.update_sample_name_label()
row_elements.updating_checkboxes = false
row_elements.updating_yxx_checkboxes = false
for i = 1, 16 do
checkboxes[i].active = true
yxx_checkboxes[i].active = true
end
end
-- Function to Browse Instrument
function row_elements.browse_instrument()
local track_popup_value = track_popup.value
local instrument_popup_value = instrument_popup.value
local track_index = track_indices[track_popup_value]
local instrument_index = instrument_popup_value
renoise.song().selected_track_index = track_index
renoise.song().selected_instrument_index = instrument_index
pitchBendDrumkitLoader()
local instrument = renoise.song().instruments[instrument_index]
if not instrument then
renoise.app():show_warning("Selected instrument does not exist.")
return
end
for _, sample in ipairs(instrument.samples) do
sample.sample_mapping.base_note = 48
sample.sample_mapping.note_range = {0, 119}
end
renoise.app():show_status("Base notes set to C-4 and key mapping adjusted for all samples.")
if renoise.song().tracks[track_index] then
-- Preserve the 8120 track name format
local track = renoise.song().tracks[track_index]
if not track.name:match("^8120_%d+%[%d+%]$") then
local base_name = string.format("8120_%02d", track_index)
track.name = string.format("%s[016]", base_name) -- Initialize with 16 steps
end
else
renoise.app():show_warning("Selected track does not exist.")
end
update_instrument_list_and_popups()
slider.value = 1
pakettiSampleVelocityRangeChoke(1)
row_elements.update_sample_name_label()
row_elements.random_button_pressed = row_elements.random_button_pressed
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
-- Function to Refresh Instruments
function row_elements.refresh_instruments()
update_instrument_list_and_popups()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
-- Function to Select Instrument
function row_elements.select_instrument()
renoise.song().selected_instrument_index = instrument_popup.value
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
local track_index = track_indices[track_popup.value]
local track = renoise.song().tracks[track_index]
renoise.song().selected_track_index = track_index
end
-- Function for Random Button Pressed
function row_elements.random_button_pressed()
if initializing then return end
row_elements.updating_checkboxes = true
row_elements.updating_yxx_checkboxes = true
local instrument_index = row_elements.instrument_popup.value
local instrument = renoise.song().instruments[instrument_index]
if instrument and instrument.samples[1] and instrument.samples[1].slice_markers and #instrument.samples[1].slice_markers > 0 then
renoise.app():show_status("This instrument contains Slices, doing nothing.")
return
end
renoise.song().selected_instrument_index = instrument_index
sample_random()
-- Update slider to match the currently selected sample
local selected_index = renoise.song().selected_sample_index
if selected_index and selected_index > 0 then
slider.value = selected_index
end
row_elements.update_sample_name_label()
renoise.song().selected_track_index = 1
row_elements.updating_checkboxes = false
row_elements.updating_yxx_checkboxes = false
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
-- Function to Randomize Steps
function row_elements.randomize()
if initializing then return end
row_elements.updating_checkboxes = true
row_elements.updating_yxx_checkboxes = true
for i = 1, 16 do
checkboxes[i].value = math.random() >= 0.5
yxx_checkboxes[i].value = math.random() >= 0.5
end
row_elements.print_to_pattern()
row_elements.updating_checkboxes = false
row_elements.updating_yxx_checkboxes = false
end
function row_elements.show_automation()
local song = renoise.song()
local track_index = track_indices[track_popup.value]
local track = song.tracks[track_index]
-- First switch to mixer view and show automation
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_MIXER
renoise.app().window.lower_frame_is_visible = true
renoise.app().window.active_lower_frame = renoise.ApplicationWindow.LOWER_FRAME_TRACK_AUTOMATION
-- Select the track
song.selected_track_index = track_index
-- Find and select the PitchBend parameter
local found_pitchbend = false
for device_index, device in ipairs(track.devices) do
for param_index, param in ipairs(device.parameters) do
if param.name:find("Pitchbend") then
song.selected_automation_parameter = param
-- Create automation in the pattern if it doesn't exist
local pattern = song.selected_pattern
local pattern_track = pattern.tracks[track_index]
local existing_automation = pattern_track:find_automation(param)
-- If no automation exists, create it
if not existing_automation then
local automation = pattern_track:create_automation(param)
automation:add_point_at(1, 0.5) -- Start at middle
automation:add_point_at(pattern.number_of_lines, 0.5) -- End at middle
end
found_pitchbend = true
renoise.app():show_status(string.format('In Track "%s" Pitchbend automation', track.name))
break
end
end
if found_pitchbend then break end
end
if not found_pitchbend then
renoise.app():show_status(string.format('No Pitchbend automation found in Track "%s"', track.name))
end
end
--[[function row_elements.show_macros()
local instrument_index = row_elements.instrument_popup.value
local instrument = renoise.song().instruments[instrument_index]
-- Find the active sample (the one with velocity range 00-7F)
local selected_sample_index = 1
if instrument and #instrument.samples > 0 then
for i, sample in ipairs(instrument.samples) do
local velocity_min = sample.sample_mapping and sample.sample_mapping.velocity_range and sample.sample_mapping.velocity_range[1]
local velocity_max = sample.sample_mapping and sample.sample_mapping.velocity_range and sample.sample_mapping.velocity_range[2]
if velocity_min == 0x00 and velocity_max == 0x7F then
selected_sample_index = i
break
end
end
end
-- Set both instrument and sample
renoise.song().selected_instrument_index = instrument_index
renoise.song().selected_sample_index = selected_sample_index
-- Switch views
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
renoise.app().window.lower_frame_is_visible = true
renoise.app().window.active_lower_frame = renoise.ApplicationWindow.LOWER_FRAME_TRACK_AUTOMATION
renoise.song().selected_track_index = track_indices[track_popup.value]
end
]]--
-- Define the Reverse Button
local reverse_button = vb:button {
text = "Reverse",
notifier = function()
row_elements.select_instrument()
reverse_sample(row_elements)
end
}
-- Define the Row Column Layout
local row = vb:column {
number_buttons_row,
vb:row(checkbox_row_elements), -- Note checkboxes with valuebox and sample name label
vb:row(yxx_checkbox_row_elements), -- Yxx checkboxes with yxx valuebox and label
vb:row {
vb:button {
text = "<",
notifier = function()
if initializing then return end
row_elements.updating_checkboxes = true
row_elements.updating_yxx_checkboxes = true
local first_note_value = checkboxes[1].value
local first_yxx_value = yxx_checkboxes[1].value
for i = 1, 15 do
checkboxes[i].value = checkboxes[i + 1].value
yxx_checkboxes[i].value = yxx_checkboxes[i + 1].value
end
checkboxes[16].value = first_note_value
yxx_checkboxes[16].value = first_yxx_value
row_elements.print_to_pattern()
row_elements.updating_checkboxes = false
row_elements.updating_yxx_checkboxes = false
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
},
vb:button {
text = ">",
notifier = function()
if initializing then return end
row_elements.updating_checkboxes = true
row_elements.updating_yxx_checkboxes = true
local last_note_value = checkboxes[16].value
local last_yxx_value = yxx_checkboxes[16].value
for i = 16, 2, -1 do
checkboxes[i].value = checkboxes[i - 1].value
yxx_checkboxes[i].value = yxx_checkboxes[i - 1].value
end
checkboxes[1].value = last_note_value
yxx_checkboxes[1].value = last_yxx_value
row_elements.print_to_pattern()
row_elements.updating_checkboxes = false
row_elements.updating_yxx_checkboxes = false
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
},
vb:button {
text = "Clear",
notifier = function()
if initializing then return end
row_elements.updating_checkboxes = true
row_elements.updating_yxx_checkboxes = true
for i = 1, 16 do
checkboxes[i].value = false
yxx_checkboxes[i].value = false
end
row_elements.updating_checkboxes = false
row_elements.updating_yxx_checkboxes = false
row_elements.print_to_pattern()
renoise.app():show_status("Wiped all steps of row " .. row_index .. ".")
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
},
vb:button {
text = "Random Steps",
notifier = function()
row_elements.randomize()
renoise.app():show_status("Randomized steps of row " .. row_index .. ".")
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
},
track_popup,
vb:row {
mute_checkbox,
vb:text {text = "Mute", font = "bold", style = "strong", width = 30}
},
instrument_popup,
vb:button {text = "Browse", notifier = row_elements.browse_instrument},
vb:button {text = "RandomLoad", notifier = function()
local track_popup_value = row_elements.track_popup.value
local instrument_popup_value = row_index -- Set instrument based on row number
local track_index = track_indices[track_popup_value]
local instrument_index = instrument_popup_value
renoise.song().selected_track_index = track_index
renoise.song().selected_instrument_index = instrument_index
loadRandomDrumkitSamples(120)
local instrument = renoise.song().instruments[instrument_index]
if not instrument then
renoise.app():show_warning("Selected instrument does not exist.")
return
end
for _, sample in ipairs(instrument.samples) do
sample.sample_mapping.base_note = 48
sample.sample_mapping.note_range = {0, 119}
end
if renoise.song().tracks[track_index] then
-- Preserve the 8120 track name format
local track = renoise.song().tracks[track_index]
if not track.name:match("^8120_%d+%[%d+%]$") then
local base_name = string.format("8120_%02d", track_index)
track.name = string.format("%s[016]", base_name) -- Initialize with 16 steps
end
else
renoise.app():show_warning("Selected track does not exist.")
end
update_instrument_list_and_popups()
row_elements.slider.value = 1
pakettiSampleVelocityRangeChoke(1)
row_elements.update_sample_name_label()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end},
vb:button {text = "Refresh", notifier = row_elements.refresh_instruments},
slider,
vb:button {text = "Random", notifier = row_elements.random_button_pressed},
vb:button {text = "Sample", notifier = row_elements.select_instrument},
vb:button {text = "Automation", notifier = row_elements.show_automation},
-- vb:button {text = "Macros", notifier=row_elements.show_macros},
reverse_button,
},
}
-- Assign Elements to row_elements Table
row_elements.checkboxes = checkboxes
row_elements.yxx_checkboxes = yxx_checkboxes
row_elements.yxx_valuebox = yxx_valuebox
row_elements.valuebox = valuebox
row_elements.slider = slider
row_elements.track_popup = track_popup
row_elements.instrument_popup = instrument_popup
row_elements.mute_checkbox = mute_checkbox
row_elements.output_delay_slider = output_delay_slider
row_elements.output_delay_value_label = output_delay_value_label
-- Initialize the Row
row_elements.initialize_row()
return row, row_elements
end
-- Function to create global controls
function create_global_controls()
play_checkbox = vb:checkbox {value = renoise.song().transport.playing, midi_mapping = "Paketti:Paketti Groovebox 8120:Play Control", notifier = function(value)
if initializing then return end
if value then
renoise.song().transport:start(renoise.Transport.PLAYMODE_RESTART_PATTERN)
else
renoise.song().transport:stop()
end
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end}
follow_checkbox = vb:checkbox {value = renoise.song().transport.follow_player, notifier = function(value)
if initializing then return end
renoise.song().transport.follow_player = value
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end}
groove_enabled_checkbox = vb:checkbox {value = renoise.song().transport.groove_enabled, notifier = function(value)
if initializing then return end
renoise.song().transport.groove_enabled = value
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
renoise.app().window.active_lower_frame = renoise.ApplicationWindow.LOWER_FRAME_TRACK_DSPS
end}
bpm_display = vb:button {text = "BPM: " .. tostring(renoise.song().transport.bpm), width = 60, notifier = update_bpm}
local_groove_sliders = {}
local_groove_labels = {}
local groove_controls = vb:row {}
for i = 1, 4 do
local groove_value = renoise.song().transport.groove_amounts[i] or 0
local_groove_labels[i] = vb:text {text = string.format("%.0f%%", groove_value * 100), style="strong", font="bold", width = 35}
local_groove_sliders[i] = vb:slider {min = 0.0, max = 1.0, value = groove_value, width = 100, notifier = function(value)
if initializing then return end
local_groove_labels[i].text = string.format("%.0f%%", value * 100)
local groove_values = {}
for j = 1, 4 do
groove_values[j] = local_groove_sliders[j].value
end
renoise.song().transport.groove_amounts = groove_values
renoise.song().transport.groove_enabled = true
renoise.song().selected_track_index = renoise.song().sequencer_track_count + 1
end}
groove_controls:add_child(vb:row {local_groove_sliders[i], local_groove_labels[i]})
end
random_gate_button = vb:button{ text="Random Gate", midi_mapping="Paketti:Paketti Groovebox 8120:Random Gate", notifier=function()
if initializing then return end
random_gate()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end}
fill_empty_label = vb:text{ text="Fill Empty Steps: 0%", style="strong", font="bold", width=140 }
fill_empty_slider = vb:slider {min = 0, max = 20, value = 0, width = 150, steps = {0.1, -0.1}, midi_mapping="Paketti:Paketti Groovebox 8120:Fill Empty Steps Slider", notifier = function(value)
if initializing then return end
fill_empty_label.text = "Fill Empty Steps: " .. tostring(math.floor(value)) .. "%"
if value == 0 then
clear_all()
else
fill_empty_steps(value / 100)
renoise.app():show_status("Filled empty steps with " .. tostring(math.floor(value)) .. "% probability.")
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
end}
local reverse_all_button = vb:button {text = "Reverse Samples", midi_mapping="Paketti:Paketti Groovebox 8120:Reverse All", notifier = reverse_all}
local randomize_all_yxx_button = vb:button {
text = "Random Yxx",
notifier = function()
for _, row_elements in ipairs(rows) do
local random_value = math.random(0, 255)
row_elements.yxx_slider.value = random_value
row_elements.yxx_valuebox.value = random_value
row_elements.print_to_pattern()
end
renoise.app():show_status("Randomized Yxx values for all rows.")
end
}
global_controls = vb:column {
vb:row {
play_checkbox, vb:text {text = "Play", font = "bold", style = "strong", width = 30},
follow_checkbox, vb:text {text = "Follow", font = "bold", style = "strong", width = 50},
vb:button {text = "/2", notifier = divide_bpm},
vb:button {text = "-", notifier = decrease_bpm},