-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPakettiExperimental_Verify.lua
4536 lines (3778 loc) · 165 KB
/
PakettiExperimental_Verify.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
local match_editstep_enabled = false
local last_line_index = nil
local tick_counter = 0 -- To track the "tick-tick-tick-skip" cycle
-- Function to find the next valid delay value in the track
local function find_next_delay_line(start_line_index)
local song = renoise.song()
local track = song.selected_pattern_track
local num_lines = song.selected_pattern.number_of_lines
for line_index = start_line_index + 1, num_lines do
local line = track:line(line_index)
if line.note_columns[1] and not line.note_columns[1].is_empty then
local delay_value = line.note_columns[1].delay_value
if delay_value == 0x00 or delay_value == 0x55 or delay_value == 0xAA then
return line_index
end
end
end
-- Wrap around: search from the top if no match is found below
for line_index = 1, start_line_index do
local line = track:line(line_index)
if line.note_columns[1] and not line.note_columns[1].is_empty then
local delay_value = line.note_columns[1].delay_value
if delay_value == 0x00 or delay_value == 0x55 or delay_value == 0xAA then
return line_index
end
end
end
return nil -- No valid delays found
end
-- Main function to dynamically adjust editstep
local function match_editstep_with_delay_pattern()
local song = renoise.song()
local current_line_index = song.selected_line_index
-- Only act when the selected line changes
if last_line_index ~= current_line_index then
last_line_index = current_line_index
-- Cycle through the "tick-tick-tick-skip" pattern
local editstep = 0
tick_counter = (tick_counter % 4) + 1 -- Cycle between 1-4
if tick_counter == 4 then
-- Skip step
local next_line_index = find_next_delay_line(current_line_index)
if next_line_index then
editstep = next_line_index - current_line_index
if editstep <= 0 then
-- Wrap-around case
editstep = (song.selected_pattern.number_of_lines - current_line_index) + next_line_index
end
else
-- No valid delay found, reset to default behavior
editstep = 1
end
else
-- Standard tick step
editstep = 1
end
-- Apply the editstep
song.transport.edit_step = editstep
renoise.app():show_status("EditStep set to " .. tostring(editstep) ..
" (Cycle position: " .. tostring(tick_counter) .. ")")
end
end
-- Toggle the functionality on or off
local function toggle_match_editstep()
match_editstep_enabled = not match_editstep_enabled
if match_editstep_enabled then
if not renoise.tool().app_idle_observable:has_notifier(match_editstep_with_delay_pattern) then
renoise.tool().app_idle_observable:add_notifier(match_editstep_with_delay_pattern)
end
renoise.app():show_status("Match EditStep with Delay Pattern: ENABLED")
else
if renoise.tool().app_idle_observable:has_notifier(match_editstep_with_delay_pattern) then
renoise.tool().app_idle_observable:remove_notifier(match_editstep_with_delay_pattern)
end
renoise.app():show_status("Match EditStep with Delay Pattern: DISABLED")
end
end
-- Add menu entry for toggling
renoise.tool():add_menu_entry{name="Main Menu:Tools:Paketti..:Xperimental/Work in Progress:Match EditStep with Delay Pattern",invoke = function() toggle_match_editstep() end}
renoise.tool():add_keybinding{name="Global:Tools:Toggle Match EditStep with Delay Pattern",invoke = function() toggle_match_editstep() end}
function NoteSpread(num_columns)
if num_columns < 2 or num_columns > 12 then
renoise.app():show_status("Please choose a number of columns between 2 and 12.")
return
end
local song = renoise.song()
local track = song.selected_track
local track_idx = song.selected_track_index
local pattern = song.selected_pattern
local pattern_lines = pattern.number_of_lines
print("Starting NoteSpread with num_columns =", num_columns)
print("Visible note columns before operation:", track.visible_note_columns)
-- Set visible note columns
track.visible_note_columns = num_columns
print("Visible note columns after setting:", track.visible_note_columns)
-- Check if there are notes on more than one note column
local has_notes_on_other_columns = false
for line_idx = 1, pattern_lines do
local line = pattern.tracks[track_idx].lines[line_idx]
for col_idx = 2, track.visible_note_columns do
if not line.note_columns[col_idx].is_empty then
has_notes_on_other_columns = true
break
end
end
if has_notes_on_other_columns then break end
end
if has_notes_on_other_columns then
renoise.app():show_status("Nothing to spread (all notes must be on Note Column 1).")
print("Nothing to spread: Notes detected on other columns.")
return
end
-- Check if there are notes in the first column
local has_notes = false
for line_idx = 1, pattern_lines do
local first_col = pattern.tracks[track_idx].lines[line_idx].note_columns[1]
if not first_col.is_empty then
has_notes = true
break
end
end
if not has_notes then
renoise.app():show_status("No notes on the first note column, doing nothing.")
print("No notes to process in Note Column 1.")
return
end
print("Notes found in the first column. Proceeding.")
-- Gather all notes and ensure NOTE OFF follows its corresponding note
local note_list = {}
local column_counter = 1 -- Tracks the current column for note placement
local last_column = 1 -- Tracks the column of the last note for NOTE OFF placement
for line_idx = 1, pattern_lines do
local first_col = pattern.tracks[track_idx].lines[line_idx].note_columns[1]
if not first_col.is_empty then
local note_copy = {
note_value = first_col.note_value,
instrument_value = first_col.instrument_value,
volume_value = first_col.volume_value,
panning_value = first_col.panning_value,
delay_value = first_col.delay_value,
}
print("Processing line", line_idx, "note_value =", note_copy.note_value)
if first_col.note_value == 120 then -- This is a NOTE OFF
-- Place NOTE OFF in the same column as the last note
table.insert(note_list, {line = line_idx, note = note_copy, target_col = last_column})
print("NOTE OFF found on line", line_idx, "assigning to column", last_column)
else
-- Regular note: Place in the current column and increment column for next note
table.insert(note_list, {line = line_idx, note = note_copy, target_col = column_counter})
print("Note found on line", line_idx, "assigning to column", column_counter)
last_column = column_counter -- Update last note's column
column_counter = (column_counter % num_columns) + 1 -- Move to the next column
end
first_col:clear() -- Clear the original note
end
end
print("Collected notes to move:", #note_list)
for i, note_data in ipairs(note_list) do
print("Note", i, "line =", note_data.line, "target_col =", note_data.target_col, "note_value =", note_data.note.note_value)
end
-- Spread notes across the desired columns
for _, note_data in ipairs(note_list) do
local line = pattern.tracks[track_idx].lines[note_data.line]
local target_col = line.note_columns[note_data.target_col]
-- Move the note or NOTE OFF to the target column
target_col.note_value = note_data.note.note_value
target_col.instrument_value = note_data.note.instrument_value
target_col.volume_value = note_data.note.volume_value
target_col.panning_value = note_data.note.panning_value
target_col.delay_value = note_data.note.delay_value
-- Debugging: Show before and after movement
print(string.format(
"Moved note from line %d to column %d: original value = %d, new value = %d",
note_data.line, note_data.target_col, note_data.note.note_value, target_col.note_value
))
end
renoise.app():show_status("Notes have been spread across " .. num_columns .. " columns.")
print("Operation complete.")
end
-- Helper function to format digits for shortcuts
local function formatDigits(min_digits, number)
return string.format("%0" .. tostring(min_digits) .. "d", number)
end
-- Add keybindings for 2 to 12 note columns dynamically
for i = 2, 12 do
renoise.tool():add_keybinding {name="Global:Paketti:OctaMED Note Spread " .. formatDigits(2, i), invoke=function() NoteSpread(i) end}
end
--NoteSpread(8)
--[[
for i=1,512 do
print ("renoise.tool():add_keybinding{name="Global:Paketti:Set Selected Sample BeatSync Lines to " .. i,invoke=function()SelectedSampleBeatSyncLine(i)end}")
end
]]--
local vb = renoise.ViewBuilder()
local dialog = nil
-- Parameters for the wacky filter
local filter_params = {
chaos = 0.5,
cutoff = 2000,
resonance = 0.7
}
-- Function to close dialog with '!'
local function my_keyhandler_func(dialog_key)
if dialog_key.name == "exclamation" and
not (dialog_key.modifiers == "shift" or dialog_key.modifiers == "control" or dialog_key.modifiers == "alt") then
dialog:close()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
end
-- Function to export, process, and reimport audio
local function process_audio()
local song = renoise.song()
local selection = song.selection_in_pattern
if not selection then
renoise.app():show_status("No audio selection found")
return
end
-- Export selected audio to a WAV file
local sample = song.instruments[1].samples[1]
local output_path = os.tmpname() .. ".wav"
sample.sample_buffer:save_as(output_path, "wav")
-- Run Csound with the wacky filter
local csound_command = string.format(
"csound wacky_filter.csd -o %s -i %s -kcutoff %f -kresonance %f -kchaos %f",
output_path,
output_path,
filter_params.cutoff,
filter_params.resonance,
filter_params.chaos
)
os.execute(csound_command)
-- Load processed file back into Renoise
sample.sample_buffer:load_from(output_path)
renoise.app():show_status("Audio processed and reloaded")
end
-- Create GUI
local function show_dialog()
if dialog and dialog.visible then
dialog:close()
return
end
dialog = renoise.app():show_custom_dialog("Wacky Filter", vb:row {
vb:column {
vb:slider { min = 0, max = 1, value = filter_params.chaos, notifier = function(v) filter_params.chaos = v end },
vb:text { text = "Chaos" },
vb:slider { min = 20, max = 20000, value = filter_params.cutoff, notifier = function(v) filter_params.cutoff = v end },
vb:text { text = "Cutoff" },
vb:slider { min = 0.1, max = 10, value = filter_params.resonance, notifier = function(v) filter_params.resonance = v end },
vb:text { text = "Resonance" },
vb:button { text = "Process Audio", notifier = process_audio }
}
}, my_keyhandler_func)
end
-- Add menu entry to show the dialog
renoise.tool():add_menu_entry {
name = "Main Menu:Tools:Paketti..:Xperimental/Work in Progress:Wacky Filter",
invoke = show_dialog
}
function AutoAssignOutputs()
local song = renoise.song()
local instrument = song.selected_instrument
local samples = instrument.samples
local sample_device_chains = instrument.sample_device_chains
local available_outputs = sample_device_chains[1]
and sample_device_chains[1].available_output_routings
or {}
-- Ensure sufficient output routings exist
if #available_outputs < 2 then
renoise.app():show_status("Not enough available output routings.")
return
end
-- Determine the starting chain index based on pre-existing chains
local pre_existing_chains = #sample_device_chains
local start_chain_index = math.max(pre_existing_chains + 1, 1)
if pre_existing_chains >= 2 then
start_chain_index = 3
elseif pre_existing_chains == 1 then
start_chain_index = 2
end
-- Calculate the required number of chains (one per sample)
local required_chains = start_chain_index + #samples - 1
-- Add new chains if necessary
for i = pre_existing_chains + 1, required_chains do
instrument:insert_sample_device_chain_at(i)
end
-- Assign output routings and name the chains
for i = 1, #samples do
local chain_index = start_chain_index + i - 1
local routing_index = (i - 1) % (#available_outputs - 1) + 2 -- Skip "Current Track"
-- Fetch the chain
local chain = sample_device_chains[chain_index]
if not chain then
renoise.app():show_status("Failed to fetch FX chain at index: " .. tostring(chain_index))
return
end
-- Assign output routing and name the chain
local routing_name = available_outputs[routing_index]
chain.output_routing = routing_name
chain.name = routing_name
end
renoise.app():show_status("FX chains assigned and outputs routed successfully.")
end
--AutoAssignOutputs()
-- Initialize ViewBuilder
local vb = renoise.ViewBuilder()
local dialog = nil -- Initialize dialog as nil
-- Tables to hold references to textfields for XRNT and XRNI slots
local slot_path_views_xrnt = {}
local slot_path_views_xrni = {}
-- Reference to the folder path textfield
local folder_path_view = nil
-- Helper functions to get slot preferences
local function get_slot_preference_xrnt(slot_number)
return preferences.UserDevices["Slot" .. string.format("%02d", slot_number)]
end
local function get_slot_preference_xrni(slot_number)
return preferences.UserInstruments["Slot" .. string.format("%02d", slot_number)]
end
-- Function to select the User XRNT Saving Folder
local function select_user_xrnt_saving_folder()
local selected_folder = renoise.app():prompt_for_path("Select User-defined Saving Folder")
if selected_folder then
preferences.UserDevices.Path.value = selected_folder
if folder_path_view then
folder_path_view.text = preferences.UserDevices.Path.value
end
renoise.app():show_status("Saving folder set to: " .. selected_folder)
end
end
-- Function to save a device chain to a XRNT slot
local function save_device_chain_to_slot(slot_number)
if preferences.UserDevices.Path.value == "" then
renoise.app():show_status("Please set the User XRNT Saving Folder first.")
return
end
local file_name = "Slot" .. string.format("%02d", slot_number) .. ".xrnt"
local full_path = preferences.UserDevices.Path.value .. "/" .. file_name
local success, err = pcall(function()
renoise.app():save_track_device_chain(full_path)
end)
if success then
get_slot_preference_xrnt(slot_number).value = full_path
if slot_path_views_xrnt[slot_number] then
slot_path_views_xrnt[slot_number].text = full_path
end
renoise.app():show_status("Device chain saved to Slot " .. string.format("%02d", slot_number))
else
renoise.app():show_status("Failed to save device chain to Slot " .. string.format("%02d", slot_number) .. ": " .. tostring(err))
end
end
-- Function to load a device chain from a XRNT slot
local function load_device_chain_from_slot(slot_number)
local file_path = get_slot_preference_xrnt(slot_number).value
if file_path == "" then
renoise.app():show_status("No XRNT file set for Slot " .. string.format("%02d", slot_number))
return
end
local file = io.open(file_path, "r")
if not file then
renoise.app():show_status("File not found: " .. file_path)
return
else
file:close()
end
local success, err = pcall(function()
renoise.app():load_track_device_chain(file_path)
end)
if success then
renoise.app():show_status("Device chain loaded from Slot " .. string.format("%02d", slot_number))
else
renoise.app():show_status("Failed to load device chain from Slot " .. string.format("%02d", slot_number) .. ": " .. tostring(err))
end
end
-- Function to select a XRNT file for a slot
local function select_xrnt_file(slot_number)
local file = renoise.app():prompt_for_filename_to_read({"*.xrnt"}, "Select XRNT File")
if file then
get_slot_preference_xrnt(slot_number).value = file
if slot_path_views_xrnt[slot_number] then
slot_path_views_xrnt[slot_number].text = file
end
renoise.app():show_status("XRNT file set for Slot " .. string.format("%02d", slot_number))
end
end
-- Function to save an instrument to a XRNI slot
local function save_instrument_to_slot(slot_number)
if preferences.UserDevices.Path.value == "" then
renoise.app():show_status("Please set the User XRNT Saving Folder first.")
return
end
local file_name = "Slot" .. string.format("%02d", slot_number) .. ".xrni"
local full_path = preferences.UserDevices.Path.value .. "/" .. file_name
local selected_instrument = renoise.song().selected_instrument
if not selected_instrument then
renoise.app():show_status("No instrument selected to save.")
return
end
local success, err = pcall(function()
renoise.app():save_instrument(full_path)
end)
if success then
get_slot_preference_xrni(slot_number).value = full_path
if slot_path_views_xrni[slot_number] then
slot_path_views_xrni[slot_number].text = full_path
end
renoise.app():show_status("Instrument saved to Slot " .. string.format("%02d", slot_number))
else
renoise.app():show_status("Failed to save instrument to Slot " .. string.format("%02d", slot_number) .. ": " .. tostring(err))
end
end
-- Function to load an instrument from a XRNI slot
local function load_instrument_from_slot(slot_number)
local file_path = get_slot_preference_xrni(slot_number).value
if file_path == "" then
renoise.app():show_status("No XRNI file set for Slot " .. string.format("%02d", slot_number))
return
end
local file = io.open(file_path, "r")
if not file then
renoise.app():show_status("File not found: " .. file_path)
return
else
file:close()
end
local success, err = pcall(function()
renoise.song():insert_instrument_at(renoise.song().selected_instrument_index+1)
renoise.song().selected_instrument_index=renoise.song().selected_instrument_index+1
renoise.app():load_instrument(file_path)
end)
if success then
renoise.app():show_status("Instrument loaded from Slot " .. string.format("%02d", slot_number))
else
renoise.app():show_status("Failed to load instrument from Slot " .. string.format("%02d", slot_number) .. ": " .. tostring(err))
end
end
-- Function to select a XRNI file for a slot
local function select_xrni_file(slot_number)
local file = renoise.app():prompt_for_filename_to_read({"*.xrni"}, "Select XRNI File")
if file then
get_slot_preference_xrni(slot_number).value = file
if slot_path_views_xrni[slot_number] then
slot_path_views_xrni[slot_number].text = file
end
renoise.app():show_status("XRNI file set for Slot " .. string.format("%02d", slot_number))
end
end
-- Function to load both XRNI and XRNT from a slot
local function load_both_from_slot(slot_number)
-- Load XRNI
local xrni_path = get_slot_preference_xrni(slot_number).value
if xrni_path == "" then
renoise.app():show_status("No XRNI file set for Slot " .. string.format("%02d", slot_number))
return
end
-- Load XRNT
local xrnt_path = get_slot_preference_xrnt(slot_number).value
if xrnt_path == "" then
renoise.app():show_status("No XRNT file set for Slot " .. string.format("%02d", slot_number))
return
end
-- Validate XRNI file
local xrni_file = io.open(xrni_path, "r")
if not xrni_file then
renoise.app():show_status("XRNI file not found: " .. xrni_path)
return
else
xrni_file:close()
end
-- Validate XRNT file
local xrnt_file = io.open(xrnt_path, "r")
if not xrnt_file then
renoise.app():show_status("XRNT file not found: " .. xrnt_path)
return
else
xrnt_file:close()
end
-- Load XRNI
local success_xrni, err_xrni = pcall(function()
renoise.song():insert_instrument_at(renoise.song().selected_instrument_index+1)
renoise.song().selected_instrument_index=renoise.song().selected_instrument_index+1
renoise.app():load_instrument(xrni_path)
end)
if not success_xrni then
renoise.app():show_status("Failed to load Instrument (.XRNI) from Slot " .. string.format("%02d", slot_number) .. ": " .. tostring(err_xrni))
return
end
-- Load XRNT
local success_xrnt, err_xrnt = pcall(function()
renoise.app():load_track_device_chain(xrnt_path)
end)
if success_xrnt then
renoise.app():show_status("Both Instrument (.XRNI) and Device Chain (.XRNT) loaded from Slot " .. string.format("%02d", slot_number))
else
renoise.app():show_status("Instrument (.XRNI) loaded from Slot " .. string.format("%02d", slot_number) .. " but failed to load Device Chain (.XRNT): " .. tostring(err_xrnt))
end
end
-- Function to show the Paketti Device Chain Dialog with XRNI functionality
local function show_paketti_device_chain_dialog()
if dialog and dialog.visible then
dialog:show()
return
end
-- Reset the references
slot_path_views_xrnt = {}
slot_path_views_xrni = {}
folder_path_view = nil
local slots_rows_xrnt = {}
local slots_rows_xrni = {}
local slots_rows_both = {}
for i = 1, 10 do
local slot_number = string.format("%02d", i)
-- Create XRNT textfield and store it
local textfield_xrnt = vb:textfield {
text = get_slot_preference_xrnt(i).value or "",
width = 900, -- Increased width as per requirement
notifier = function(text)
get_slot_preference_xrnt(i).value = text
end
}
slot_path_views_xrnt[i] = textfield_xrnt
-- XRNT Row
local row_xrnt = vb:row {
-- margin = 2,
vb:text { text = "Load Device Chain (.XRNT) Slot" .. slot_number .. ":", width = 200 },
textfield_xrnt,
vb:button {
text = "Browse",
notifier = function()
select_xrnt_file(i)
end
},
vb:button {
text = "Save",
notifier = function()
save_device_chain_to_slot(i)
end
},
vb:button {
text = "Load",
notifier = function()
load_device_chain_from_slot(i)
end
}
}
slots_rows_xrnt[#slots_rows_xrnt + 1] = row_xrnt
-- Create XRNI textfield and store it
local textfield_xrni = vb:textfield {
text = get_slot_preference_xrni(i).value or "",
width = 900, -- Increased width as per requirement
notifier = function(text)
get_slot_preference_xrni(i).value = text
end
}
slot_path_views_xrni[i] = textfield_xrni
-- XRNI Row
local row_xrni = vb:row {
-- margin = 2,
vb:text { text = "Load Instrument (.XRNI) Slot" .. slot_number .. ":", width = 200 },
textfield_xrni,
vb:button {
text = "Browse",
notifier = function()
select_xrni_file(i)
end
},
vb:button {
text = "Save",
notifier = function()
save_instrument_to_slot(i)
end
},
vb:button {
text = "Load",
notifier = function()
load_instrument_from_slot(i)
end
}
}
slots_rows_xrni[#slots_rows_xrni + 1] = row_xrni
-- Both XRNI&XRNT Row
local row_both = vb:row {
vb:text { text = "Load Both Instrument&Device Chain (.XRNI&.XRNT) Slot" .. slot_number .. ":", width = 200 },
vb:button {
text = "Load Both",
notifier = function()
load_both_from_slot(i)
end
}
}
slots_rows_both[#slots_rows_both + 1] = row_both
end
-- Define the content of the dialog
local content = vb:column {
vb:row {
vb:text { text = "User XRNT/XRNI Save Folder:", width = 200 },
vb:textfield {
text = preferences.UserDevices.Path.value ~= "" and preferences.UserDevices.Path.value or "<Not Set, Please Set>",
width = 900, -- Increased width as per requirement
notifier = function(text)
preferences.UserDevices.Path.value = text
end
},
vb:button {
text = "Browse",
notifier = function()
select_user_xrnt_saving_folder()
end
}
},
vb:column {
vb:text { text = "Load Device Chain (.XRNT) Slots (01-10)", font = "bold" },
unpack(slots_rows_xrnt)
},
vb:column {
vb:text { text = "Load Instrument (.XRNI) Slots (01-10)", font = "bold" },
unpack(slots_rows_xrni)
},
vb:column {
vb:text { text = "Load Both Instrument&Device Chain (.XRNI&.XRNT) Slots (01-10)", font = "bold" },
unpack(slots_rows_both)
},
vb:row {
vb:button {
text = "Close",
notifier = function()
dialog:close()
dialog = nil -- Clear the dialog reference
end
}
}
}
-- Create and show the dialog
dialog = renoise.app():show_custom_dialog("Paketti Device Chain & Instrument Dialog", content, nil, nil)
end
-- Function to add menu entries and key bindings grouped by functionality
local function add_menu_entries_and_keybindings()
-- Load Device Chain (.XRNT) Slots 01-10
for i = 1, 10 do
local slot_number = string.format("%02d", i)
local menu_entry_name_xrnt = "Mixer:Paketti..:Device Chains..:Load Device Chain (.XRNT) Slot" .. slot_number
local menu_entry_name2_xrnt = "DSP Device:Paketti..:Device Chains..:Load Device Chain (.XRNT) Slot" .. slot_number
local key_binding_name_xrnt = "Global:Paketti:Load Device Chain (.XRNT) Slot " .. slot_number
renoise.tool():add_menu_entry { name = menu_entry_name_xrnt, invoke = function() load_device_chain_from_slot(i) end }
renoise.tool():add_menu_entry { name = menu_entry_name2_xrnt, invoke = function() load_device_chain_from_slot(i) end }
renoise.tool():add_keybinding { name = key_binding_name_xrnt, invoke = function() load_device_chain_from_slot(i) end }
end
-- Load Instrument (.XRNI) Slots 01-10
for i = 1, 10 do
local slot_number = string.format("%02d", i)
local menu_entry_name_xrni = "Mixer:Paketti..:Device Chains..:Load Instrument (.XRNI) Slot" .. slot_number
local menu_entry_name2_xrni = "DSP Device:Paketti..:Device Chains..:Load Instrument (.XRNI) Slot" .. slot_number
local key_binding_name_xrni = "Global:Paketti:Load Instrument (.XRNI) Slot " .. slot_number
renoise.tool():add_menu_entry { name = menu_entry_name_xrni, invoke = function() load_instrument_from_slot(i) end }
renoise.tool():add_menu_entry { name = menu_entry_name2_xrni, invoke = function() load_instrument_from_slot(i) end }
renoise.tool():add_keybinding { name = key_binding_name_xrni, invoke = function() load_instrument_from_slot(i) end }
end
-- Load Both Instrument&Device Chain (.XRNI&.XRNT) Slots 01-10
for i = 1, 10 do
local slot_number = string.format("%02d", i)
local menu_entry_name_load_both = "Mixer:Paketti..:Device Chains..:Load Both Instrument&Device Chain (.XRNI&.XRNT) Slot" .. slot_number
local menu_entry_name2_load_both = "DSP Device:Paketti..:Device Chains..:Load Both Instrument&Device Chain (.XRNI&.XRNT) Slot" .. slot_number
local key_binding_name_load_both = "Global:Paketti:Load Both Instrument&Device Chain (.XRNI&.XRNT) Slot " .. slot_number
renoise.tool():add_menu_entry { name = menu_entry_name_load_both, invoke = function() load_both_from_slot(i) end }
renoise.tool():add_menu_entry { name = menu_entry_name2_load_both, invoke = function() load_both_from_slot(i) end }
renoise.tool():add_keybinding { name = key_binding_name_load_both, invoke = function() load_both_from_slot(i) end }
end
end
add_menu_entries_and_keybindings()
renoise.tool():add_menu_entry { name = "--Mixer:Paketti..:Device Chains..:Open Track DSP Device & Instrument Loader...", invoke = function() show_paketti_device_chain_dialog() end }
renoise.tool():add_menu_entry { name = "--DSP Device:Paketti..:Device Chains..:Open Track DSP Device & Instrument Loader...", invoke = function() show_paketti_device_chain_dialog() end }
renoise.tool():add_menu_entry { name = "--Main Menu:Tools:Paketti..:Paketti Track DSP Device & Instrument Loader...", invoke = function() show_paketti_device_chain_dialog() end }
------------------------
local vb = renoise.ViewBuilder()
local dialog = nil
local dialog_content = nil
local function my_keyhandler_func(dialog, key)
local closer = preferences.pakettiDialogClose.value
if key.modifiers == "" and key.name == closer then
dialog:close()
return end
if key.name == "!" then
dialog:close()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
else
return key
end
end
local function update_sample_volumes(x, y)
local instrument = renoise.song().selected_instrument
if #instrument.samples < 4 then
renoise.app():show_status("Selected instrument must have at least 4 samples.")
return
end
-- Calculate volumes based on the x, y position of the xypad
local volumes = {
(1 - x) * y, -- Top-left (Sample 1)
x * y, -- Top-right (Sample 2)
(1 - x) * (1 - y), -- Bottom-left (Sample 3)
x * (1 - y) -- Bottom-right (Sample 4)
}
-- Normalize volumes to range 0.0 - 1.0
for i, volume in ipairs(volumes) do
instrument.samples[i].volume = math.min(1.0, math.max(0.0, volume))
end
renoise.app():show_status(
("Sample volumes updated: S1=%.2f, S2=%.2f, S3=%.2f, S4=%.2f"):
format(volumes[1], volumes[2], volumes[3], volumes[4])
)
end
dialog_content = vb:column {
vb:xypad {
width = 200,
height = 200,
value = {x=0.5, y=0.5},
notifier = function(value)
update_sample_volumes(value.x, value.y)
end
}
}
function showXyPaddialog()
if dialog and dialog.visible then
dialog:close()
else
dialog = renoise.app():show_custom_dialog("XY Pad Sound Mixer", dialog_content, my_keyhandler_func)
end
end
renoise.tool():add_menu_entry {name = "Main Menu:Tools:Paketti..:Xperimental/Work in Progress:XY Pad Sound Mixer",invoke = function() showXyPaddialog() end}
local vb = renoise.ViewBuilder()
local dialog = nil
local monitoring_enabled = false -- Tracks the monitoring state
local active = false
-- Tracks all SB0/SBX pairs in the Master Track
local loop_pairs = {}
-- Scan the Master Track for all SB0/SBX pairs
function analyze_loops()
local song = renoise.song()
local master_track_index = renoise.song().sequencer_track_count + 1
local master_track = song.selected_pattern.tracks[master_track_index]
loop_pairs = {}
for line_idx, line in ipairs(master_track.lines) do
if #line.effect_columns > 0 then
local col = line.effect_columns[1]
if col.number_string == "0S" then
local parameter = col.amount_value - 176 -- Decode by subtracting `B0`
if parameter == 0 then
-- Found SB0 (start)
table.insert(loop_pairs, {start_line = line_idx, end_line = nil, repeat_count = 0, max_repeats = 0})
elseif parameter >= 1 and parameter <= 15 then
-- Found SBX (end) for the last SB0
local last_pair = loop_pairs[#loop_pairs]
if last_pair and not last_pair.end_line then
last_pair.end_line = line_idx
last_pair.max_repeats = parameter
end
end
end
end
end
if #loop_pairs == 0 then
print("Error: No valid SB0/SBX pairs found in the Master Track.")
return false
end
print("Detected SB0/SBX pairs in Master Track:")
for i, pair in ipairs(loop_pairs) do
print("Pair " .. i .. ": Start=" .. pair.start_line .. ", End=" .. pair.end_line .. ", Max Repeats=" .. pair.max_repeats)
end
return true
end
-- Playback Monitoring Function
local function monitor_playback()
local song = renoise.song()
local play_pos = song.transport.playback_pos
local current_line = play_pos.line
local max_row = renoise.song().selected_pattern.number_of_lines - 1 -- Last row in the pattern
-- Reset all repeat counts at the end of the pattern
if current_line == max_row then
for _, pair in ipairs(loop_pairs) do
pair.repeat_count = 0
end
print("Resetting all repeat counts at the end of the pattern.")
return
end
-- Handle looping logic for each pair
for i, pair in ipairs(loop_pairs) do
if current_line == pair.end_line then
if pair.repeat_count < pair.max_repeats then
pair.repeat_count = pair.repeat_count + 1
print("Pair " .. i .. ": Looping back to SB0 (line " .. pair.start_line .. "). Repeat count: " .. pair.repeat_count)
song.transport.playback_pos = renoise.SongPos(play_pos.sequence, pair.start_line)
return
else
print("Pair " .. i .. ": Completed all repeats for this iteration.")
end
end
end
end
--]]
-- Global Reset Function
function reset_repeat_counts()
if not monitoring_enabled then
print("Monitoring is disabled. Reset operation skipped.")
return
end
print("Checking Master Track for SB0/SBX pairs...")
if not analyze_loops() then
print("No valid SB0/SBX pairs found in the Master Track. Reset operation aborted.")
return
end
for i, pair in ipairs(loop_pairs) do
pair.repeat_count = 0
print("Reset Pair " .. i .. ": Start=" .. pair.start_line .. ", End=" .. pair.end_line .. ", Max Repeats=" .. pair.max_repeats)
end
print("All repeat counts reset to 0. Monitoring restarted.")
InitSBx() -- Reinitialize SBX monitoring
end
-- Initialize SBX Monitoring
function InitSBx()
if monitoring_enabled then