-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PakettiExperimental_Verify.lua
4613 lines (3817 loc) · 169 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 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:Wacky Filter",
invoke = show_dialog
}
function overlayModeCycle()
--renoise.song().selected_instrument.sample_mapping_overlap_mode=0,1,2
end
function SelectionToNewPattern()
--[[
>>> rprint (renoise.song().selection_in_pattern)
[end_column] => 2
[end_line] => 4
[end_track] => 2
[start_column] => 1
[start_line] => 1
[start_track] => 2
]]--
renoise.song().selected_pattern_index = 1
end
function XOPointCloud()
for i=1,#renoise.song().instruments do
if renoise.song().instruments[i].plugin_properties.plugin_device ~= nil then
if renoise.song().instruments[i].plugin_properties.plugin_device.name == "AU: XLN Audio: XO" or
renoise.song().instruments[i].plugin_properties.plugin_device.name == "VST3: XLN Audio: XO" or
renoise.song().instruments[i].plugin_properties.plugin_device.name == "VST: XLN Audio: XO"
then
if renoise.song().instruments[i].plugin_properties.plugin_device.external_editor_visible~=false then
renoise.song().instruments[i].plugin_properties.plugin_device.external_editor_visible=false
else
renoise.song().instruments[i].plugin_properties.plugin_device.external_editor_visible=true
return end
-- TODO add "if not there, add it to a new instrument"
end
end
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Show XO Plugin External Editor",invoke=function() XOPointCloud() end}
function toggleCurrentTrackDSPs()
for i=2,#renoise.song().selected_track.devices do
if renoise.song().selected_track.devices[i].external_editor_available then
if renoise.song().selected_track.devices[i].external_editor_visible then
renoise.song().selected_track.devices[i].external_editor_visible=false else
renoise.song().selected_track.devices[i].external_editor_visible=true
end
end
end
end
-- TODO set it when switching tracks
--renoise.song().selected_track_observable:add_notifier(toggleCurrentTrackDSPs())
function AutoAssignOutputs(number)
-- TODO: fix the for logic so the amount of samples creates the amount of sample device chains
-- and then sorts the output routings
if #renoise.song().selected_instrument.sample_device_chains == #renoise.song().selected_instrument.samples then end
for i=1,#renoise.song().selected_instrument.samples do
renoise.song().selected_instrument:insert_sample_device_chain_at(i)
end
for i=2,#renoise.song().selected_instrument.sample_device_chains[1].available_output_routings do
for y=1,#renoise.song().selected_instrument.samples do
renoise.song().selected_instrument.sample_device_chains[y].output_routing=i
end
end
end
renoise.tool():add_midi_mapping{name="Paketti:Clear Current Track in Pattern",invoke=function()
renoise.song().selected_pattern.tracks[renoise.song().selected_track_index]:clear()
end}
function DrumKitToOverlay(overlaymode)
for i=1,#renoise.song().selected_instrument.sample_mappings[1] do
renoise.song().selected_instrument.sample_mappings[1][i].note_range={0,119}
renoise.song().selected_instrument.sample_mappings[1][i].base_note=48
renoise.song().selected_instrument.sample_mappings[1][i].velocity_range = {0, 127}
end
renoise.song().selected_instrument.sample_mapping_overlap_mode=overlaymode
renoise.app():show_status("The instrument " .. renoise.song().selected_instrument.name .. " has been formatted to Overlap Random.")
end
renoise.tool():add_keybinding{name="Global:Paketti:Set DrumKit to Overlap Random",invoke=function() DrumKitToOverlay(2) end}
renoise.tool():add_menu_entry{name="Sample Mappings:Paketti..:Set DrumKit to Overlap Random",invoke=function() DrumKitToOverlay(2) end}
renoise.tool():add_keybinding{name="Global:Paketti:Load DrumKit with Overlap Random",invoke=function()
pitchBendDrumkitLoader()
DrumKitToOverlay(2) end}
renoise.tool():add_menu_entry{name="Instrument Box:Paketti..:Load DrumKit with Overlap Random",invoke=function()
pitchBendDrumkitLoader()
DrumKitToOverlay(2) end}
renoise.tool():add_keybinding{name="Global:Paketti:Load DrumKit with Overlap Cycle",invoke=function()
pitchBendDrumkitLoader()
DrumKitToOverlay(1) end}
renoise.tool():add_menu_entry{name="Instrument Box:Paketti..:Load DrumKit with Overlap Cycle",invoke=function()
pitchBendDrumkitLoader()
DrumKitToOverlay(1) end}
function normalize_and_reduce(scope, db_reduction)
local function process_sample(sample, reduction_factor)
if not sample then return false, "No sample provided!" end
local buffer = sample.sample_buffer
if not buffer or not buffer.has_sample_data then return false, "Sample has no data!" end
buffer:prepare_sample_data_changes()
local max_amplitude = 0
for channel = 1, buffer.number_of_channels do
for frame = 1, buffer.number_of_frames do
local sample_value = math.abs(buffer:sample_data(channel, frame))
if sample_value > max_amplitude then max_amplitude = sample_value end
end
end
if max_amplitude > 0 then
local normalization_factor = 1 / max_amplitude
for channel = 1, buffer.number_of_channels do
for frame = 1, buffer.number_of_frames do
local sample_value = buffer:sample_data(channel, frame)
buffer:set_sample_data(channel, frame, sample_value * normalization_factor * reduction_factor)
end
end
end
buffer:finalize_sample_data_changes()
return true, "Sample processed successfully!"
end
local reduction_factor = 10 ^ (db_reduction / 20)
if scope == "current_sample" then
local sample = renoise.song().selected_sample
if not sample then renoise.app():show_error("No sample selected!") return end
local success, message = process_sample(sample, reduction_factor)
renoise.app():show_status(message)
elseif scope == "all_samples" then
local instrument = renoise.song().selected_instrument
if not instrument or #instrument.samples == 0 then renoise.app():show_error("No samples in the selected instrument!") return end
for _, sample in ipairs(instrument.samples) do
local success, message = process_sample(sample, reduction_factor)
if not success then renoise.app():show_status(message) end
end
renoise.app():show_status("All samples in the selected instrument processed.")
elseif scope == "all_instruments" then
for _, instrument in ipairs(renoise.song().instruments) do
if #instrument.samples > 0 then
for _, sample in ipairs(instrument.samples) do
local success, message = process_sample(sample, reduction_factor)
if not success then renoise.app():show_status("Instrument skipped: " .. message) end
end
end
end
renoise.app():show_status("All instruments processed.")
else
renoise.app():show_error("Invalid processing scope!")
end
end
renoise.tool():add_menu_entry{name="Sample Editor:Paketti..:Normalize Selected Sample -12dB",invoke=function() normalize_and_reduce("current_sample", -12) end}
renoise.tool():add_menu_entry{name="Sample Editor:Paketti..:Normalize Selected Instrument -12dB (All Samples & Slices)",invoke=function() normalize_and_reduce("all_samples", -12) end}
renoise.tool():add_menu_entry{name="Sample Editor:Paketti..:Normalize All Instruments -12dB",invoke=function() normalize_and_reduce("all_instruments", -12) end}
renoise.tool():add_keybinding{name="Sample Editor:Paketti:Normalize Selected Sample to -12dB",invoke=function() normalize_and_reduce("current_sample", -12) end}
renoise.tool():add_keybinding{name="Sample Editor:Paketti:Normalize Selected Instrument to -12dB",invoke=function() normalize_and_reduce("all_samples", -12) end}
renoise.tool():add_keybinding{name="Sample Editor:Paketti:Normalize All Instruments to -12dB",invoke=function() normalize_and_reduce("all_instruments", -12) end}
renoise.tool():add_midi_mapping{name="Paketti:Normalize Selected Sample to -12dB",invoke=function(message) if message:is_trigger() then normalize_and_reduce("current_sample", -12) end end}
renoise.tool():add_midi_mapping{name="Paketti:Normalize Selected Instrument to -12dB",invoke=function(message) if message:is_trigger() then normalize_and_reduce("all_samples", -12) end end}
renoise.tool():add_midi_mapping{name="Paketti:Normalize All Instruments to -12dB",invoke=function(message) if message:is_trigger() then normalize_and_reduce("all_instruments", -12) end end}
function setPanning(where,position)
local routing = nil
if where == "current" then
routing=renoise.song().selected_track
end
if where == "master" then
routing=renoise.song().tracks[renoise.song().sequencer_track_count+1]
end
routing.postfx_panning.value=position
end
renoise.tool():add_keybinding{name="Global:Paketti:Set Current Track Pan to Left",invoke=function() setPanning("current",0) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Current Track Pan to Center",invoke=function() setPanning("current",0.5) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Current Track Pan to Right",invoke=function() setPanning("current",1) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Master Track Pan to Left",invoke=function() setPanning("master",0) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Master Track Pan to Center",invoke=function() setPanning("master",0.5) end}
renoise.tool():add_keybinding{name="Global:Paketti:Set Master Track Pan to Right",invoke=function() setPanning("master",1) end}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Set Current Track Pan to Left",invoke=function() setPanning("current",0) end}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Set Current Track Pan to Center",invoke=function() setPanning("current",0.5) end}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Set Current Track Pan to Right",invoke=function() setPanning("current",1) end}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Set Master Track Pan to Left",invoke=function() setPanning("master",0) end}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Set Master Track Pan to Center",invoke=function() setPanning("master",0.5) end}
renoise.tool():add_menu_entry{name="Mixer:Paketti..:Set Master Track Pan to Right",invoke=function() setPanning("master",1) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Set Current Track Pan to Left",invoke=function() setPanning("current",0) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Set Current Track Pan to Center",invoke=function() setPanning("current",0.5) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Set Current Track Pan to Right",invoke=function() setPanning("current",1) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Set Master Track Pan to Left",invoke=function() setPanning("master",0) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Set Master Track Pan to Center",invoke=function() setPanning("master",0.5) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Set Master Track Pan to Right",invoke=function() setPanning("master",1) end}
local function switch_upper_frame()
local app_window=renoise.app().window
-- Check if the upper frame is visible; make it visible if not
if not app_window.upper_frame_is_visible then
app_window.upper_frame_is_visible=true
end
-- Toggle the upper frame between Track Scopes and Master Spectrum
if app_window.active_upper_frame==renoise.ApplicationWindow.UPPER_FRAME_TRACK_SCOPES then
app_window.active_upper_frame=renoise.ApplicationWindow.UPPER_FRAME_MASTER_SPECTRUM
else
app_window.active_upper_frame=renoise.ApplicationWindow.UPPER_FRAME_TRACK_SCOPES
end
-- Provide user feedback
renoise.app():show_status("Switched Upper Frame to "..app_window.active_upper_frame)
end
-- Run the function
renoise.tool():add_keybinding{name="Global:Paketti:Switch Upper Frame (Track Scopes/Master Spectrum)",invoke=function()
switch_upper_frame() end}
-- Function to duplicate the selected track and rename it
local function duplicate_selected_track()
local song=renoise.song()
local selected_track_index=song.selected_track_index
local selected_track=song.tracks[selected_track_index]
-- Prevent duplication of master, send, or group tracks
if selected_track.type~=1 then -- 1 represents a sequencer track
renoise.app():show_status("Cannot duplicate master, group, or send tracks.")
return
end
-- Extract the name of the selected track
local original_name=selected_track.name
local new_name=original_name -- Default to original name if no number is found
-- Check if the name ends with a number, e.g., "drum1"
local base_name, number=original_name:match("^(.-)(%d+)$")
if number then
local incremented_number=tonumber(number)+1
new_name=base_name..incremented_number
else
-- If no number exists, append " Copy" to the name
new_name=original_name.." Copy"
end
-- Insert a new track and copy properties/settings
local new_track_index=selected_track_index+1
song:insert_track_at(new_track_index)
local new_track=song.tracks[new_track_index]
-- Copy basic properties
new_track.name=new_name
new_track.color=selected_track.color
-- Copy visibility settings
new_track.visible_note_columns=selected_track.visible_note_columns
new_track.visible_effect_columns=selected_track.visible_effect_columns
new_track.volume_column_visible=selected_track.volume_column_visible
new_track.panning_column_visible=selected_track.panning_column_visible
new_track.delay_column_visible=selected_track.delay_column_visible
new_track.sample_effects_column_visible=selected_track.sample_effects_column_visible
-- Copy pattern data from the original track to the new track
for pattern_index,pattern in ipairs(song.patterns) do
local original_pattern_track=pattern.tracks[selected_track_index]
local new_pattern_track=pattern.tracks[new_track_index]
new_pattern_track:copy_from(original_pattern_track)
end
-- Provide feedback to the user
renoise.app():show_status("Duplicated track '"..original_name.."' as '"..new_name.."'.")
end
-- Trigger the function
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Selected Track & Name",invoke=function()
duplicate_selected_track() end}
function HideAllEffectColumns()
for i=1,renoise.song().sequencer_track_count do
if renoise.song().tracks[i].type==1 then
print (i)
renoise.song().tracks[i].visible_effect_columns=0
else end
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Hide All Effect Columns",invoke=function() HideAllEffectColumns() end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Hide All Effect Columns",invoke=function() HideAllEffectColumns() end}
-- 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..:Load Device Chain (.XRNT) Slot" .. slot_number
local menu_entry_name2_xrnt = "DSP Device:Paketti..: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..:Load Instrument (.XRNI) Slot" .. slot_number
local menu_entry_name2_xrni = "DSP Device:Paketti..: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..:Load Both Instrument&Device Chain (.XRNI&.XRNT) Slot" .. slot_number
local menu_entry_name2_load_both = "DSP Device:Paketti..: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..:Open Device & Instrument Dialog...", invoke = function() show_paketti_device_chain_dialog() end }
renoise.tool():add_menu_entry { name = "DSP Device:Paketti..:Open Device & Instrument Dialog...", invoke = function() show_paketti_device_chain_dialog() end }
renoise.tool():add_menu_entry { name = "Main Menu:Tools:Paketti..:Paketti Device & Instrument Dialog...", 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: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
local 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