-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPakettiCCizerLoader.lua
More file actions
1118 lines (939 loc) · 45.7 KB
/
PakettiCCizerLoader.lua
File metadata and controls
1118 lines (939 loc) · 45.7 KB
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 CCizer Loader Dialog
-- Scans ccizer folder and allows selection/loading of MIDI control configuration files
local dialog = nil
local separator = package.config:sub(1,1)
local bottomButtonWidth = 120
local MAX_CC_LIMIT = 35 -- Maximum CC mappings for MIDI Control device
-- Get path to ccizer folder
local function get_ccizer_folder()
return renoise.tool().bundle_path .. "ccizer" .. separator
end
-- Scan for available CCizer files
local function scan_ccizer_files()
local ccizer_path = get_ccizer_folder()
local files = {}
-- Try to get .txt files from the ccizer folder
local success, result = pcall(function()
return os.filenames(ccizer_path, "*.txt")
end)
if success and result then
for _, filename in ipairs(result) do
-- Extract just the filename without path
local clean_name = filename:match("[^"..separator.."]+$")
if clean_name then
table.insert(files, {
name = clean_name,
display_name = clean_name:gsub("%.txt$", ""), -- Remove .txt extension for display
full_path = ccizer_path .. clean_name
})
end
end
end
-- Sort files alphabetically
table.sort(files, function(a, b) return a.display_name:lower() < b.display_name:lower() end)
return files
end
-- Load and parse a CCizer file
local function load_ccizer_file(filepath)
local file = io.open(filepath, "r")
if not file then
renoise.app():show_error("Cannot open CCizer file: " .. filepath)
return nil
end
local mappings = {}
local line_count = 0
local valid_cc_count = 0
for line in file:lines() do
line_count = line_count + 1
line = line:match("^%s*(.-)%s*$") -- Trim whitespace
if line and line ~= "" and not line:match("^#") then -- Skip empty lines and comments
-- Check for Pitchbend first
local pb_name = line:match("^PB%s+(.+)$")
if pb_name then
valid_cc_count = valid_cc_count + 1
-- Check if we're exceeding the MIDI Control device limit
if valid_cc_count > MAX_CC_LIMIT then
print(string.format("-- CCizer: Warning - CC mapping #%d exceeds MIDI Control device limit of %d CCs, ignoring excess mappings", valid_cc_count, MAX_CC_LIMIT))
break
end
table.insert(mappings, {
cc = -1,
name = pb_name,
type = "PB"
})
print(string.format("-- CCizer: Valid PB mapping #%d: PB -> %s", valid_cc_count, pb_name))
else
-- Regular CC parsing
local cc_number, parameter_name = line:match("^(%d+)%s+(.+)$")
if cc_number and parameter_name then
local cc_num = tonumber(cc_number)
if cc_num and cc_num >= 0 and cc_num <= 127 then
valid_cc_count = valid_cc_count + 1
-- Check if we're exceeding the MIDI Control device limit
if valid_cc_count > MAX_CC_LIMIT then
print(string.format("-- CCizer: Warning - CC mapping #%d exceeds MIDI Control device limit of %d CCs, ignoring excess mappings", valid_cc_count, MAX_CC_LIMIT))
break
end
table.insert(mappings, {
cc = cc_num,
name = parameter_name,
type = "CC"
})
print(string.format("-- CCizer: Valid CC mapping #%d: CC %d -> %s", valid_cc_count, cc_num, parameter_name))
else
print(string.format("-- CCizer: Warning - invalid CC number %d on line %d (must be 0-127)", cc_num or -1, line_count))
end
else
print(string.format("-- CCizer: Warning - could not parse line %d: %s", line_count, line))
end
end
end
end
file:close()
local status_message = string.format("-- CCizer: Loaded %d valid MIDI CC mappings from %s", #mappings, filepath)
if #mappings == MAX_CC_LIMIT then
status_message = status_message .. string.format(" (reached maximum limit of %d CCs)", MAX_CC_LIMIT)
elseif #mappings > 0 then
status_message = status_message .. string.format(" (can add %d more CCs)", MAX_CC_LIMIT - #mappings)
end
print(status_message)
return mappings
end
-- Helper function to clean parameter names by removing "CC XX " prefix
-- e.g., "CC 1 (Mod Wheel)" becomes "Mod Wheel"
function paketti_clean_cc_parameter_name(param_name)
if not param_name then
return param_name
end
-- Remove "CC XX " pattern (e.g., "CC 54 (Cutoff)" becomes "(Cutoff)")
local cleaned = param_name:gsub("^CC %d+ ", "")
-- Remove parentheses if the entire remaining string is wrapped in them
-- e.g., "(Cutoff)" becomes "Cutoff"
if cleaned:match("^%((.+)%)$") then
cleaned = cleaned:match("^%((.+)%)$")
end
return cleaned
end
-- SHARED: Helper function to generate the MIDI Control device XML
-- This function is used by both CCizer Loader and MIDI Populator
function paketti_generate_midi_control_xml(cc_mappings)
local xml_lines = {}
-- Calculate visible pages based on number of mappings
-- Each page typically shows ~5 controllers, so we calculate needed pages
local num_mappings = #cc_mappings
local controllers_per_page = 5
local visible_pages = math.max(1, math.ceil(num_mappings / controllers_per_page))
-- Ensure we don't exceed reasonable page limits for the MIDI Control device
visible_pages = math.min(visible_pages, 8)
-- XML header
table.insert(xml_lines, '<?xml version="1.0" encoding="UTF-8"?>')
table.insert(xml_lines, '<FilterDevicePreset doc_version="12">')
table.insert(xml_lines, ' <DeviceSlot type="MidiControlDevice">')
table.insert(xml_lines, ' <IsMaximized>true</IsMaximized>')
-- Generate 35 controllers (0-34)
for i = 0, 34 do
local mapping = cc_mappings[i + 1] -- Lua is 1-based, controllers are 0-based
if mapping then
-- Use the mapping from CCizer file
table.insert(xml_lines, string.format(' <ControllerValue%d>', i))
if mapping.type == "PB" then
table.insert(xml_lines, ' <Value>63.5</Value>') -- Center value for pitchbend
else
table.insert(xml_lines, ' <Value>0.0</Value>')
end
table.insert(xml_lines, string.format(' </ControllerValue%d>', i))
-- For pitchbend, use controller number 0 instead of -1 to enable it
local controller_number = (mapping.type == "PB") and 0 or mapping.cc
table.insert(xml_lines, string.format(' <ControllerNumber%d>%d</ControllerNumber%d>', i, controller_number, i))
table.insert(xml_lines, string.format(' <ControllerName%d>%s</ControllerName%d>', i, paketti_clean_cc_parameter_name(mapping.name), i))
table.insert(xml_lines, string.format(' <ControllerType%d>%s</ControllerType%d>', i, mapping.type or "CC", i))
table.insert(xml_lines, string.format(' <ControllerEnabled%d>true</ControllerEnabled%d>', i, i))
else
-- Default empty controller
table.insert(xml_lines, string.format(' <ControllerValue%d>', i))
table.insert(xml_lines, ' <Value>0.0</Value>')
table.insert(xml_lines, string.format(' </ControllerValue%d>', i))
table.insert(xml_lines, string.format(' <ControllerNumber%d>-1</ControllerNumber%d>', i, i))
table.insert(xml_lines, string.format(' <ControllerName%d>Untitled</ControllerName%d>', i, i))
table.insert(xml_lines, string.format(' <ControllerType%d>CC</ControllerType%d>', i, i))
table.insert(xml_lines, string.format(' <ControllerEnabled%d>false</ControllerEnabled%d>', i, i))
end
end
-- XML footer with calculated visible pages
table.insert(xml_lines, string.format(' <VisiblePages>%d</VisiblePages>', visible_pages))
table.insert(xml_lines, ' </DeviceSlot>')
table.insert(xml_lines, '</FilterDevicePreset>')
return table.concat(xml_lines, '\n')
end
-- Create MIDI Control device from CCizer mappings
local function apply_ccizer_mappings(mappings, filename)
if not mappings or #mappings == 0 then
renoise.app():show_warning("No valid MIDI CC mappings found in file")
return
end
local song = renoise.song()
print("-- CCizer: Creating MIDI Control device from CCizer mappings")
print(string.format("-- CCizer: Using %d / %d CC mappings", #mappings, MAX_CC_LIMIT))
-- Load the MIDI Control device SILENTLY
print("-- CCizer: Loading *Instr. MIDI Control device silently...")
loadnative("Audio/Effects/Native/*Instr. MIDI Control", nil, nil, nil, true)
-- Give the device a moment to load, then apply XML and open parameter editor
renoise.app():show_status("Loading MIDI Control device...")
-- Generate the XML preset with our CC mappings
local xml_content = paketti_generate_midi_control_xml(mappings)
local name_without_ext = filename:match("^(.+)%..+$") or filename
-- Using anonymous timer functions prevents multiple registrations
local function apply_xml_and_open_editor()
-- Find the device that was just loaded
local device = nil
if renoise.app().window.active_middle_frame == 7 or renoise.app().window.active_middle_frame == 6 then
-- Sample FX chain
device = song.selected_sample_device
else
-- Track DSP chain
device = song.selected_device
end
if device and device.name == "*Instr. MIDI Control" then
device.active_preset_data = xml_content
device.display_name = name_without_ext
print("-- CCizer: Successfully applied CC mappings to device with name: " .. name_without_ext)
-- Create status message with CC count information
local status_message = string.format("MIDI Control device '%s' created with %d/%d CC mappings", name_without_ext, #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
status_message = status_message .. " (max reached)"
else
status_message = status_message .. string.format(" (%d slots available)", MAX_CC_LIMIT - #mappings)
end
renoise.app():show_status(status_message)
-- Wait a tick, then open parameter editor and remove timer
local didiRun = false
local timer_func
timer_func = function()
didiRun = true
if didiRun == true then
renoise.tool():remove_timer(timer_func)
end
if PAKETTI_HAS_CANVAS then
PakettiCanvasExperimentsInit()
end
end
renoise.tool():add_timer(timer_func, 100)
else
renoise.app():show_error("Failed to find or load MIDI Control device")
end
end
-- Wait for device to load before applying XML
local didiRun = false
local device_timer_func
device_timer_func = function()
didiRun = true
if didiRun == true then
renoise.tool():remove_timer(device_timer_func)
end
apply_xml_and_open_editor()
end
renoise.tool():add_timer(device_timer_func, 200)
end
-- Create the CCizer loader dialog
function PakettiCCizerLoader()
if dialog and dialog.visible then
dialog:close()
return
end
local vb = renoise.ViewBuilder()
local files = scan_ccizer_files()
if #files == 0 then
renoise.app():show_error("No CCizer files found in: " .. get_ccizer_folder())
return
end
-- Create file list for popup
local file_items = {}
for _, file in ipairs(files) do
table.insert(file_items, file.display_name)
end
local selected_file_index = 1
local selected_file_info = vb:text{
text = "Loading...",
width = 400
}
-- Function to update file info with CC count
local function update_selected_file_info(file_index)
if files[file_index] then
local mappings = load_ccizer_file(files[file_index].full_path)
if mappings then
local info_text = string.format("%s (%d/%d CCs)",
files[file_index].display_name, #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
info_text = info_text .. " - MAX REACHED"
elseif #mappings > 0 then
info_text = info_text .. string.format(" - %d slots available", MAX_CC_LIMIT - #mappings)
end
selected_file_info.text = info_text
else
selected_file_info.text = files[file_index].display_name .. " - ERROR LOADING"
end
else
selected_file_info.text = "None"
end
end
local content = vb:column{
margin = 10,
vb:row{
vb:text{text = "CCizer File", width = 100, font = "bold", style = "strong"},
vb:popup{
id = "ccizer_file_popup",
items = file_items,
value = selected_file_index,
width = 300,
notifier = function(value)
selected_file_index = value
update_selected_file_info(value)
end
},
vb:button{
text = "Browse",
width = 80,
notifier = function()
local selected_textfile = renoise.app():prompt_for_filename_to_read({"*.txt"}, "Load CCizer Text File")
if selected_textfile and selected_textfile ~= "" then
local mappings = load_ccizer_file(selected_textfile)
if mappings then
local filename = selected_textfile:match("([^/\\]+)$")
local name_without_ext = filename:match("^(.+)%..+$") or filename
apply_ccizer_mappings(mappings, name_without_ext)
dialog:close()
dialog = nil
end
end
end
}
},
vb:row{
vb:text{text = "Selected", width = 100, font = "bold", style = "strong"},
selected_file_info
},
vb:text{
text = "CCizer files contain MIDI CC to parameter mappings.",
width = 400
},
vb:horizontal_aligner{
vb:button{
text = "Open Path",
width = bottomButtonWidth,
notifier = function()
renoise.app():open_path(get_ccizer_folder())
end
},
vb:button{
text = "Preview",
width = bottomButtonWidth,
notifier = function()
if files[selected_file_index] then
local mappings = load_ccizer_file(files[selected_file_index].full_path)
if mappings then
local preview = string.format("Preview of %s\n", files[selected_file_index].display_name)
preview = preview .. string.format("Valid CC mappings: %d / %d (max for MIDI Control device)\n\n", #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
preview = preview .. "Reached maximum CC limit for MIDI Control device\n\n"
elseif #mappings > 0 then
preview = preview .. string.format("Can add %d more CC mappings\n\n", MAX_CC_LIMIT - #mappings)
end
for i, mapping in ipairs(mappings) do
if mapping.type == "PB" then
preview = preview .. string.format("PB -> %s\n", mapping.name)
else
preview = preview .. string.format("CC %d -> %s\n", mapping.cc, mapping.name)
end
end
renoise.app():show_message(preview)
end
end
end
},
vb:button{
text = "Create MIDI Control",
width = bottomButtonWidth,
notifier = function()
if files[selected_file_index] then
local mappings = load_ccizer_file(files[selected_file_index].full_path)
if mappings then
apply_ccizer_mappings(mappings, files[selected_file_index].display_name)
end
end
end
},
vb:button{
text = "Cancel",
width = bottomButtonWidth,
notifier = function()
dialog:close()
dialog = nil
end
}
}
}
-- Update the selected file info for the default selection
update_selected_file_info(selected_file_index)
dialog = renoise.app():show_custom_dialog("CCizer TXT->CC Loader", content, my_keyhandler_func)
end
renoise.tool():add_keybinding{name = "Global:Paketti:CCizer Loader...", invoke = PakettiCCizerLoader}
-- Function to create MIDI Control device from text file with CC mappings
function PakettiCreateMIDIControlFromTextFile()
local song = renoise.song()
print("-- MIDI Control Text: Starting MIDI Control device creation from text file")
-- First, prompt for the text file
local selected_textfile = renoise.app():prompt_for_filename_to_read({"*.txt"}, "Load Textfile with CC Mappings")
if not selected_textfile or selected_textfile == "" then
renoise.app():show_status("No text file selected, cancelling operation")
return
end
print("-- MIDI Control Text: Selected file: " .. selected_textfile)
-- Read and parse the text file
local cc_mappings = {}
local file = io.open(selected_textfile, "r")
if not file then
renoise.app():show_error("Could not open text file: " .. selected_textfile)
return
end
local line_count = 0
local valid_cc_count = 0
for line in file:lines() do
line_count = line_count + 1
line = line:match("^%s*(.-)%s*$") -- Trim whitespace
if line and line ~= "" and not line:match("^#") then -- Skip empty lines and comments
-- Check for Pitchbend first
local pb_name = line:match("^PB%s+(.+)$")
if pb_name then
valid_cc_count = valid_cc_count + 1
-- Check if we're exceeding the MIDI Control device limit
if valid_cc_count > MAX_CC_LIMIT then
print(string.format("-- MIDI Control Text: Warning - CC mapping #%d exceeds MIDI Control device limit of %d CCs, ignoring excess mappings", valid_cc_count, MAX_CC_LIMIT))
break
end
table.insert(cc_mappings, {cc = -1, name = pb_name, type = "PB"})
print(string.format("-- MIDI Control Text: Valid PB mapping #%d: PB -> %s", valid_cc_count, pb_name))
else
-- Parse line format: "54 Cutoff" or "127 SomethingElse"
local cc_number, cc_name = line:match("^(%d+)%s+(.+)$")
if cc_number and cc_name then
cc_number = tonumber(cc_number)
if cc_number and cc_number >= 0 and cc_number <= 127 then
valid_cc_count = valid_cc_count + 1
-- Check if we're exceeding the MIDI Control device limit
if valid_cc_count > MAX_CC_LIMIT then
print(string.format("-- MIDI Control Text: Warning - CC mapping #%d exceeds MIDI Control device limit of %d CCs, ignoring excess mappings", valid_cc_count, MAX_CC_LIMIT))
break
end
table.insert(cc_mappings, {cc = cc_number, name = cc_name, type = "CC"})
print(string.format("-- MIDI Control Text: Valid CC mapping #%d: CC %d -> %s", valid_cc_count, cc_number, cc_name))
else
print(string.format("-- MIDI Control Text: Warning - invalid CC number %d on line %d (must be 0-127)", cc_number or -1, line_count))
end
else
print(string.format("-- MIDI Control Text: Warning - could not parse line %d: %s", line_count, line))
end
end
end
end
file:close()
if #cc_mappings == 0 then
renoise.app():show_error("No valid CC mappings found in text file")
return
end
local status_message = string.format("-- MIDI Control Text: Successfully parsed %d valid CC mappings", #cc_mappings)
if #cc_mappings == MAX_CC_LIMIT then
status_message = status_message .. string.format(" (reached maximum limit of %d CCs)", MAX_CC_LIMIT)
elseif #cc_mappings > 0 then
status_message = status_message .. string.format(" (can add %d more CCs)", MAX_CC_LIMIT - #cc_mappings)
end
print(status_message)
-- Load the MIDI Control device SILENTLY
print("-- MIDI Control Text: Loading *Instr. MIDI Control device silently...")
loadnative("Audio/Effects/Native/*Instr. MIDI Control", nil, nil, nil, true)
-- Give the device a moment to load, then apply XML
renoise.app():show_status("Loading MIDI Control device...")
-- Generate the XML preset with our CC mappings
local xml_content = paketti_generate_midi_control_xml(cc_mappings)
-- Extract filename without path and extension
local filename = selected_textfile:match("([^/\\]+)$") -- Get filename from path
local name_without_ext = filename:match("^(.+)%..+$") or filename -- Remove extension, fallback to full filename
local function apply_xml_and_finish()
-- Apply the XML to the device
local device = nil
if renoise.app().window.active_middle_frame == 7 or renoise.app().window.active_middle_frame == 6 then
-- Sample FX chain
device = song.selected_sample_device
else
-- Track DSP chain
device = song.selected_device
end
if device and device.name == "*Instr. MIDI Control" then
device.active_preset_data = xml_content
device.display_name = name_without_ext
print("-- MIDI Control Text: Successfully applied CC mappings to device with name: " .. name_without_ext)
-- Create status message with CC count information
local status_message = string.format("MIDI Control device '%s' created with %d/%d CC mappings", name_without_ext, #cc_mappings, MAX_CC_LIMIT)
if #cc_mappings == MAX_CC_LIMIT then
status_message = status_message .. " (max reached)"
else
status_message = status_message .. string.format(" (%d slots available)", MAX_CC_LIMIT - #cc_mappings)
end
renoise.app():show_status(status_message)
else
renoise.app():show_error("Failed to find or load MIDI Control device")
end
end
-- Wait for device to load before applying XML
local didiRun = false
local device_timer_func
device_timer_func = function()
didiRun = true
if didiRun == true then
renoise.tool():remove_timer(device_timer_func)
end
apply_xml_and_finish()
end
renoise.tool():add_timer(device_timer_func, 200)
end
--[[
-- Menu entries for the new function
PakettiAddMenuEntry{name="Main Menu:Tools:Paketti:Xperimental:Create MIDI Control from Text File", invoke=function() PakettiCreateMIDIControlFromTextFile() end}
PakettiAddMenuEntry{name="DSP Device:Paketti:Experimental:Create MIDI Control from Text File", invoke=function() PakettiCreateMIDIControlFromTextFile() end}
PakettiAddMenuEntry{name="Sample FX Mixer:Paketti:Experimental:Create MIDI Control from Text File", invoke=function() PakettiCreateMIDIControlFromTextFile() end}
PakettiAddMenuEntry{name="Mixer:Paketti:Experimental:Create MIDI Control from Text File", invoke=function() PakettiCreateMIDIControlFromTextFile() end}
renoise.tool():add_keybinding{name="Global:Paketti:Create MIDI Control from Text File", invoke=function() PakettiCreateMIDIControlFromTextFile() end}
]]--
-- Function to apply CCizer mappings to the currently selected device (or create new one if needed)
local function apply_ccizer_to_selected_device(mappings, filename)
if not mappings or #mappings == 0 then
renoise.app():show_warning("No valid MIDI CC mappings found in file")
return
end
local song = renoise.song()
local selected_device = song.selected_device
-- Check if we have a selected MIDI Control device
if selected_device and selected_device.name == "*Instr. MIDI Control" then
print("-- CCizer: Applying CCizer mappings to existing selected device")
print(string.format("-- CCizer: Using %d / %d CC mappings", #mappings, MAX_CC_LIMIT))
-- Generate the XML preset with our CC mappings
local xml_content = paketti_generate_midi_control_xml(mappings)
-- Apply the XML to the selected device
selected_device.active_preset_data = xml_content
selected_device.display_name = filename
print("-- CCizer: Successfully applied CC mappings to selected device with name: " .. filename)
-- Create status message with CC count information
local status_message = string.format("Applied CCizer '%s' with %d/%d CC mappings to selected device", filename, #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
status_message = status_message .. " (max reached)"
else
status_message = status_message .. string.format(" (%d slots available)", MAX_CC_LIMIT - #mappings)
end
renoise.app():show_status(status_message)
-- Wait a tick, then open parameter editor and remove timer
local didiRun = false
local timer_func
timer_func = function()
didiRun = true
if didiRun == true then
renoise.tool():remove_timer(timer_func)
end
if PAKETTI_HAS_CANVAS then
PakettiCanvasExperimentsInit()
end
end
renoise.tool():add_timer(timer_func, 100)
else
-- No device selected or wrong device type - create new MIDI Control device
print("-- CCizer: No MIDI Control device selected, creating new one")
print(string.format("-- CCizer: Using %d / %d CC mappings", #mappings, MAX_CC_LIMIT))
-- Load the MIDI Control device SILENTLY
print("-- CCizer: Loading *Instr. MIDI Control device silently...")
loadnative("Audio/Effects/Native/*Instr. MIDI Control", nil, nil, nil, true)
-- Give the device a moment to load, then apply XML and open parameter editor
renoise.app():show_status("Loading MIDI Control device...")
-- Generate the XML preset with our CC mappings
local xml_content = paketti_generate_midi_control_xml(mappings)
-- Using anonymous timer functions prevents multiple registrations
local function apply_xml_and_open_editor()
-- Find the device that was just loaded
local device = nil
if renoise.app().window.active_middle_frame == 7 or renoise.app().window.active_middle_frame == 6 then
-- Sample FX chain
device = song.selected_sample_device
else
-- Track DSP chain
device = song.selected_device
end
if device and device.name == "*Instr. MIDI Control" then
device.active_preset_data = xml_content
device.display_name = filename
print("-- CCizer: Successfully applied CC mappings to new device with name: " .. filename)
-- Create status message with CC count information
local status_message = string.format("Created MIDI Control device '%s' with %d/%d CC mappings", filename, #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
status_message = status_message .. " (max reached)"
else
status_message = status_message .. string.format(" (%d slots available)", MAX_CC_LIMIT - #mappings)
end
renoise.app():show_status(status_message)
-- Wait a tick, then open parameter editor and remove timer
local didiRun = false
local timer_func
timer_func = function()
didiRun = true
if didiRun == true then
renoise.tool():remove_timer(timer_func)
end
if PAKETTI_HAS_CANVAS then
PakettiCanvasExperimentsInit()
end
end
renoise.tool():add_timer(timer_func, 100)
else
renoise.app():show_error("Failed to find or load MIDI Control device")
end
end
-- Wait for device to load before applying XML
local didiRun = false
local device_timer_func
device_timer_func = function()
didiRun = true
if didiRun == true then
renoise.tool():remove_timer(device_timer_func)
end
apply_xml_and_open_editor()
end
renoise.tool():add_timer(device_timer_func, 200)
end
end
-- Function to load a specific CCizer file to selected device (or create new one if needed)
local function load_ccizer_file_to_selected_device(ccizer_filename)
local ccizer_files = scan_ccizer_files()
local target_file = nil
for _, file in ipairs(ccizer_files) do
if file.name == ccizer_filename then
target_file = file
break
end
end
if not target_file then
renoise.app():show_status("CCizer file '" .. ccizer_filename .. "' not found in ccizer folder")
return
end
local mappings = load_ccizer_file(target_file.full_path)
if mappings then
apply_ccizer_to_selected_device(mappings, target_file.display_name)
end
end
-- Function to show CCizer dialog that targets selected device (or creates new one if needed)
function PakettiCCizerLoaderToSelectedDevice()
local selected_device = renoise.song().selected_device
if dialog and dialog.visible then
dialog:close()
return
end
local vb = renoise.ViewBuilder()
local files = scan_ccizer_files()
if #files == 0 then
renoise.app():show_error("No CCizer files found in: " .. get_ccizer_folder())
return
end
-- Create file list for popup
local file_items = {}
for _, file in ipairs(files) do
table.insert(file_items, file.display_name)
end
local selected_file_index = 1
local selected_file_info = vb:text{
text = "Loading...",
width = 400
}
-- Function to update file info with CC count
local function update_selected_file_info(file_index)
if files[file_index] then
local mappings = load_ccizer_file(files[file_index].full_path)
if mappings then
local info_text = string.format("%s (%d/%d CCs)",
files[file_index].display_name, #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
info_text = info_text .. " - MAX REACHED"
elseif #mappings > 0 then
info_text = info_text .. string.format(" - %d slots available", MAX_CC_LIMIT - #mappings)
end
selected_file_info.text = info_text
else
selected_file_info.text = files[file_index].display_name .. " - ERROR LOADING"
end
else
selected_file_info.text = "None"
end
end
local content = vb:column{
margin = 10,
vb:text{
text = "Loading CCizer file to MIDI Control device:",
font = "bold",
style = "strong"
},
vb:text{
text = selected_device and selected_device.name == "*Instr. MIDI Control" and
("Selected Device: " .. selected_device.display_name) or
"Will create new MIDI Control device",
font = "bold"
},
vb:row{
vb:text{text = "CCizer File", width = 100, font = "bold", style = "strong"},
vb:popup{
id = "ccizer_file_popup",
items = file_items,
value = selected_file_index,
width = 300,
notifier = function(value)
selected_file_index = value
update_selected_file_info(value)
end
},
vb:button{
text = "Browse",
width = 80,
notifier = function()
local selected_textfile = renoise.app():prompt_for_filename_to_read({"*.txt"}, "Load CCizer Text File to MIDI Control Device")
if selected_textfile and selected_textfile ~= "" then
local mappings = load_ccizer_file(selected_textfile)
if mappings then
local filename = selected_textfile:match("([^/\\]+)$")
local name_without_ext = filename:match("^(.+)%..+$") or filename
apply_ccizer_to_selected_device(mappings, name_without_ext)
dialog:close()
dialog = nil
end
end
end
}
},
vb:row{
vb:text{text = "Selected", width = 100, font = "bold", style = "strong"},
selected_file_info
},
vb:text{
text = "CCizer files contain MIDI CC to parameter mappings.",
width = 400
},
vb:horizontal_aligner{
vb:button{
text = "Open Path",
width = bottomButtonWidth,
notifier = function()
renoise.app():open_path(get_ccizer_folder())
end
},
vb:button{
text = "Preview",
width = bottomButtonWidth,
notifier = function()
if files[selected_file_index] then
local mappings = load_ccizer_file(files[selected_file_index].full_path)
if mappings then
local preview = string.format("Preview of %s\n", files[selected_file_index].display_name)
preview = preview .. string.format("Valid CC mappings: %d / %d (max for MIDI Control device)\n\n", #mappings, MAX_CC_LIMIT)
if #mappings == MAX_CC_LIMIT then
preview = preview .. "Reached maximum CC limit for MIDI Control device\n\n"
elseif #mappings > 0 then
preview = preview .. string.format("Can add %d more CC mappings\n\n", MAX_CC_LIMIT - #mappings)
end
for i, mapping in ipairs(mappings) do
if mapping.type == "PB" then
preview = preview .. string.format("PB -> %s\n", mapping.name)
else
preview = preview .. string.format("CC %d -> %s\n", mapping.cc, mapping.name)
end
end
renoise.app():show_message(preview)
end
end
end
},
vb:button{
text = "Apply to Device",
width = bottomButtonWidth + 20,
notifier = function()
if files[selected_file_index] then
local mappings = load_ccizer_file(files[selected_file_index].full_path)
if mappings then
apply_ccizer_to_selected_device(mappings, files[selected_file_index].display_name)
dialog:close()
dialog = nil
end
end
end
},
vb:button{
text = "Cancel",
width = bottomButtonWidth,
notifier = function()
dialog:close()
dialog = nil
end
}
}
}
-- Update the selected file info for the default selection
update_selected_file_info(selected_file_index)
dialog = renoise.app():show_custom_dialog("CCizer TXT->MIDI Control Loader", content, my_keyhandler_func)
end
-- Generate menu entries for actual CCizer files found in ccizer folder
local function create_ccizer_menu_entries()
local ccizer_files = scan_ccizer_files()
-- Limit to first 10 files to avoid menu bloat
local max_files = math.min(#ccizer_files, 10)
for i = 1, max_files do
local file = ccizer_files[i]
local display_name = file.display_name -- Already has .txt removed
local filename = file.name -- Full filename with .txt
PakettiAddMenuEntry{name = "DSP Device:Paketti:CCizer:Load " .. display_name, invoke = function() load_ccizer_file_to_selected_device(filename) end}
PakettiAddMenuEntry{name = "Sample FX Mixer:Paketti:CCizer:Load " .. display_name, invoke = function() load_ccizer_file_to_selected_device(filename) end}
PakettiAddMenuEntry{name = "Mixer:Paketti:CCizer:Load " .. display_name, invoke = function() load_ccizer_file_to_selected_device(filename) end}
renoise.tool():add_keybinding{name = "Global:Paketti:CCizer Load " .. display_name, invoke = function() load_ccizer_file_to_selected_device(filename) end}
end
end
-- Create the dynamic menu entries
create_ccizer_menu_entries()
-- Function to load any CCizer file to selected device via file browser (or create new one if needed)
local function load_ccizer_file_browse_to_selected_device()
local selected_textfile = renoise.app():prompt_for_filename_to_read({"*.txt"}, "Load CCizer Text File to MIDI Control Device")
if selected_textfile and selected_textfile ~= "" then
local mappings = load_ccizer_file(selected_textfile)
if mappings then
local filename = selected_textfile:match("([^/\\]+)$")
local name_without_ext = filename:match("^(.+)%..+$") or filename
apply_ccizer_to_selected_device(mappings, name_without_ext)
end
end
end
PakettiAddMenuEntry{name = "DSP Device:Paketti:CCizer:Open CCizer Dialog", invoke = PakettiCCizerLoaderToSelectedDevice}
PakettiAddMenuEntry{name = "Sample FX Mixer:Paketti:CCizer:Open CCizer Dialog", invoke = PakettiCCizerLoaderToSelectedDevice}
PakettiAddMenuEntry{name = "Mixer:Paketti:CCizer:Open CCizer Dialog", invoke = PakettiCCizerLoaderToSelectedDevice}
PakettiAddMenuEntry{name = "DSP Device:Paketti:CCizer:Load from File", invoke = load_ccizer_file_browse_to_selected_device}
PakettiAddMenuEntry{name = "Sample FX Mixer:Paketti:CCizer:Load from File", invoke = load_ccizer_file_browse_to_selected_device}
PakettiAddMenuEntry{name = "Mixer:Paketti:CCizer:Load from File", invoke = load_ccizer_file_browse_to_selected_device}
-- COMPREHENSIVE RECURSIVE RENOISE API EXPLORER
-- This explores EVERY SINGLE subobject, property, method in the entire Renoise API
function paketti_debug_dump_complete_renoise_api()
print("=== COMPREHENSIVE RECURSIVE RENOISE API EXPLORATION ===")
local explored_count = 0
local max_objects = 500 -- Prevent runaway
local visited = {} -- Prevent circular references
-- Function to recursively explore any object using oprint()
local function explore_object(obj, path, max_depth, current_depth)
current_depth = current_depth or 0
max_depth = max_depth or 8
if current_depth >= max_depth or explored_count >= max_objects then
return
end
if visited[obj] then
return
end
visited[obj] = true
explored_count = explored_count + 1
print(string.format("\n%s==== %s ====", string.rep(" ", current_depth), path))
oprint(obj)
-- Try to find and explore all sub-objects
local obj_type = type(obj)