-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPakettiStretch.lua
1530 lines (1314 loc) · 55.2 KB
/
PakettiStretch.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
-- At the very start of the file
local view_switch
local write_to_master = false -- State for master track writing
local vb=renoise.ViewBuilder()
local step_size = 1
local fill_all = true
-- Declare variables first
local step_slider
local step_stepper
-- Helper Functions (all defined before usage)
local function set_view_frame(vb)
renoise.app().window.active_middle_frame =
vb.views.switchmode and
(vb.views.switchmode.value == 1 and 1 or -- Pattern Editor
vb.views.switchmode.value == 2 and 5 or -- Sample Editor
vb.views.switchmode.value == 3 and 6) -- Modulation Matrix
or 1 -- Default to Pattern Editor if switchmode doesn't exist
end
-- Add this new function
local function fill_pattern_with_steps(pattern_index, instrument_index, use_512, note_value, reverse_s, step_size, fill_all)
local song = renoise.song()
local pattern = song.patterns[pattern_index]
local track = pattern:track(song.selected_track_index)
local base_length = 256
-- Set pattern length
pattern.number_of_lines = use_512 and 512 or 256
-- Function to fill a 256-line segment
local function fill_segment(start_line)
-- Calculate total number of steps
local total_steps = math.floor(base_length / step_size)
for i = 1, base_length do
local current_line = start_line + i - 1
local should_fill = fill_all or ((i-1) % step_size == 0)
if should_fill then
-- Calculate step position (0 to total_steps-1)
local step_position = math.floor((i-1) / step_size)
-- Calculate S-value (ensure it stays within 0-255)
local s_value
if reverse_s then
-- For reverse, start at 255 and step down
s_value = math.max(0, math.min(255, 255 - (step_position * (255 / (total_steps - 1)))))
else
-- For normal, start at 0 and step up
s_value = math.max(0, math.min(255, step_position * (255 / (total_steps - 1))))
end
-- Debug print
print(string.format("Line %d: Step %d of %d, S-value: %d", i, step_position, total_steps, s_value))
track:line(current_line).note_columns[1].note_value = note_value
track:line(current_line).note_columns[1].instrument_value = instrument_index
track:line(current_line).effect_columns[1].number_string = "0S"
track:line(current_line).effect_columns[1].amount_value = math.floor(s_value)
else
track:line(current_line).note_columns[1].note_value = 121
track:line(current_line).note_columns[1].instrument_value = 255
track:line(current_line).effect_columns[1].number_string = "00"
track:line(current_line).effect_columns[1].amount_value = 0
end
end
end
fill_segment(1)
if use_512 then
fill_segment(257)
end
end
local function ensure_master_track_effects()
local song = renoise.song()
local master_track_index = song.sequencer_track_count + 1
local master_track = song:track(master_track_index)
if master_track.visible_effect_columns < 2 then
master_track.visible_effect_columns = 2
end
end
local function write_tempo_commands(bpm, lpb, from_line)
if not write_to_master then return end
local song = renoise.song()
local master_track_index = song.sequencer_track_count + 1
local pattern = song.patterns[song.selected_pattern_index]
local master_track = pattern:track(master_track_index)
local start_line = from_line or 1
-- Convert BPM to hex for ZT
local zt_value = math.min(255, math.floor(bpm))
-- Convert LPB to hex for ZL
local zl_value = math.min(255, math.floor(lpb))
-- Write from current line to end of pattern
for i = start_line, pattern.number_of_lines do
master_track:line(i).effect_columns[1].number_string = "ZT"
master_track:line(i).effect_columns[1].amount_value = zt_value
master_track:line(i).effect_columns[2].number_string = "ZL"
master_track:line(i).effect_columns[2].amount_value = zl_value
end
end
local function check_and_set_uniform_note()
local song = renoise.song()
local pattern = song.patterns[current_pattern_index]
local track = pattern:track(song.selected_track_index)
local length = pattern.number_of_lines
local first_note = track:line(1).note_columns[1].note_value
if first_note == 121 then return end -- Skip if first note is OFF
-- Check if all notes are the same
for i = 2, length do
local current_note = track:line(i).note_columns[1].note_value
if current_note ~= first_note and current_note ~= 121 then -- 121 is note OFF
return -- Notes are different, exit
end
end
-- If we get here, all notes are the same (excluding OFFs)
note_slider.value = first_note
end
local function check_and_set_envelope_status(vb)
-- First check if vb exists and has views
if not vb or not vb.views or not vb.views.envelope_checkbox then
return false
end
-- Safely get song object
local song = nil
pcall(function() song = renoise.song() end)
if not song then
return false
end
-- Rest of the function with safe checks
if not song.selected_instrument then
return false
end
local instrument = song.selected_instrument
if not instrument.sample_modulation_sets or
#instrument.sample_modulation_sets == 0 or
not instrument.sample_modulation_sets[1] or
not instrument.sample_modulation_sets[1].devices or
not instrument.sample_modulation_sets[1].devices[3] then
return false
end
local device = instrument.sample_modulation_sets[1].devices[3]
if not device or device.name ~= "Volume AHDSR" then
return false
end
if device.enabled then
vb.views.envelope_checkbox.value = true
return true
end
return false
end
local function update_timing_displays()
-- Safely get song object
local song = nil
pcall(function() song = renoise.song() end)
if not song then
return
end
local bpm = song.transport.bpm
local lpb = song.transport.lpb
local lines_per_sec = (bpm * lpb) / 60
local ms_per_line = 1000 / lines_per_sec
if lines_per_sec_display then
lines_per_sec_display.text = string.format("%.2f", lines_per_sec)
end
if ms_per_line_display then
ms_per_line_display.text = string.format("%.2f", ms_per_line)
end
end
local function calculate_timing_values(slider_value)
-- Convert 0-1000 to 0-1 range
local normalized = slider_value / 1000
-- Calculate total range of possible speeds
local min_speed = 20 * 1 -- Slowest: 20 BPM at LPB 1
local max_speed = 256 * 256 -- Fastest: 256 BPM at LPB 256
-- Calculate target speed using exponential scaling
local target_speed = min_speed * math.pow(max_speed/min_speed, normalized)
-- Start with LPB 1 and calculate required BPM
local lpb = 1
local bpm = target_speed
-- While BPM is too high, double LPB and halve BPM
while bpm > 256 and lpb < 256 do
lpb = lpb * 2
bpm = bpm / 2
end
-- Ensure we stay within limits
bpm = math.max(20, math.min(256, bpm))
lpb = math.max(1, math.min(256, lpb))
-- Snap LPB to powers of 2
local common_lpbs = {1, 2, 4, 8, 16, 32, 64, 128, 256}
local snap_threshold = 0.1 -- 10% tolerance
for _, common_lpb in ipairs(common_lpbs) do
if math.abs(lpb - common_lpb) / lpb < snap_threshold then
lpb = common_lpb
break
end
end
return math.floor(bpm), lpb
end
-- Helper function to fill pattern with ONLY effects (not touching notes)
local function fill_pattern(pattern_index, instrument_index, use_512, note_value, reverse_s)
fill_pattern_with_steps(pattern_index, instrument_index, use_512, note_value, reverse_s, step_size, fill_all)
end
-- Key handler function
local function Timekeyhandlerfunc(dialog, key)
if key.name == "esc" then
dialog:close()
end
return key
end
-- Dialog creation and pattern manipulation for timestretching
local function create_timestretch_dialog()
local song = renoise.song()
local selected_track = song:track(song.selected_track_index)
render_context.source_track = song.selected_track_index -- Store the track index
local original_seq_pos = song.selected_sequence_index -- Store original position
-- Check if we're on a proper note track and switch to first track if not
if selected_track.type ~= renoise.Track.TRACK_TYPE_SEQUENCER then
song.selected_track_index = 1 -- Switch to first track which is always a sequencer track
end
local current_pattern_index = song.sequencer:pattern(song.selected_sequence_index)
local current_pattern = song.patterns[current_pattern_index]
-- Ensure pattern is at least 256 rows
if current_pattern.number_of_lines < 256 then
current_pattern.number_of_lines = 256
end
local current_pattern_length = current_pattern.number_of_lines
local vb = renoise.ViewBuilder()
-- 1. Declare ALL variables we'll need upfront
local note_slider
local pattern_512_mode
local record_mode
local reverse_checkbox
local bpm_slider
local lpb_slider
local bpm_display
local lpb_display
local note_display
local instrument_index_display
local instrument_name_text
local lines_per_sec_display
local ms_per_line_display
local lpb_stepper
local note_stepper
local step_slider
local step_display
local fill_all_checkbox
-- Declare these variables before creating the row
local scale_value_text = vb:text { -- Create the text elements first
width = 40,
text = "1.00"
}
local release_time_text = vb:text { -- Create the text elements first
width = 50,
text = "480ms"
}
-- 2. Create basic displays
bpm_display = vb:text {
width = 50,
text = tostring(song.transport.bpm)
}
lpb_display = vb:text {width = 30, text = tostring(song.transport.lpb)}
note_display = vb:text {width = 50, text = "C-4", style="strong", font="bold"}
-- Add integer step valueboxes next to the displays
lpb_stepper = vb:valuebox {
min = -1,
max = 1,
value = 0,
width = 30,
tonumber = function(str)
return math.floor(tonumber(str) or 0)
end,
tostring = function(value)
return tostring(value)
end,
notifier = function(new_value)
local current_lpb = song.transport.lpb
local new_lpb = math.max(1, math.min(256, current_lpb + new_value))
song.transport.lpb = new_lpb
lpb_display.text = tostring(new_lpb)
lpb_slider.value = new_lpb
update_timing_displays()
if write_to_master then
write_tempo_commands(song.transport.bpm, new_lpb,
song.transport.playing and song.transport.playback_pos.line or 1)
end
lpb_stepper.value = 0 -- Reset the stepper
end
}
note_stepper = vb:valuebox {
min = -1,
max = 1,
value = 0,
width = 30,
tonumber = function(str)
return math.floor(tonumber(str) or 0)
end,
tostring = function(value)
return tostring(value)
end,
notifier = function(new_value)
local current_note = note_slider.value
local new_note = math.max(0, math.min(119, current_note + new_value))
update_note_value(new_note)
note_stepper.value = 0 -- Reset the stepper
end
}
-- 3. Create instrument controls
instrument_index_display = vb:valuebox {
min = 0,
max = 254,
value = song.selected_instrument_index - 1,
width = 50,
tostring = function(value) return string.format("%02X", value) end,
tonumber = function(str) return tonumber(str, 16) end,
notifier = function(new_value)
-- Update all notes in the pattern with the new instrument value
local pattern = song.patterns[current_pattern_index]
local track = pattern:track(song.selected_track_index)
for i = 1, pattern.number_of_lines do
local note_column = track:line(i).note_columns[1]
if note_column.note_value ~= 121 then -- Only update if there's a note
note_column.instrument_value = new_value
end
end
-- Update selected instrument in Renoise
song.selected_instrument_index = new_value + 1
-- Update instrument name display
instrument_name_text.text = song.instruments[new_value + 1].name
end
}
instrument_name_text = vb:text {
text = song.instruments[song.selected_instrument_index].name,
width = 200,
style = "strong",
font = "bold"
}
-- 5. Pattern fill function
local function fill_pattern(pattern_index, instrument_index, use_512, note_value, reverse_s)
local song = renoise.song()
local pattern = song.patterns[pattern_index]
local track = pattern:track(song.selected_track_index)
local length = use_512 and 512 or 256
-- Set pattern length
pattern.number_of_lines = length
-- Only modify effect columns, preserve notes
for i = 1, length do
local s_value
if reverse_s then
s_value = math.floor(255 - ((i - 1) % 256) * 255 / 255) -- SFF to S00
else
s_value = math.floor(((i - 1) % 256) * 255 / 255) -- S00 to SFF
end
track:line(i).effect_columns[1].number_string = "0S"
track:line(i).effect_columns[1].amount_value = s_value
end
end
-- 6. Create checkboxes
pattern_512_mode = vb:checkbox {
value = current_pattern_length == 512,
width = 20,
notifier = function(new_value)
print("512 Mode - New value:", new_value)
print("Current step_size:", step_size)
print("Current fill_all:", fill_all)
local song = renoise.song()
local pattern = song.patterns[current_pattern_index]
if new_value and pattern.number_of_lines ~= 512 then
-- Store the note from line 255 before expanding
local note_255 = pattern:track(song.selected_track_index):line(255).note_columns[1].note_value
local inst_255 = pattern:track(song.selected_track_index):line(255).note_columns[1].instrument_value
-- Set pattern length
pattern.number_of_lines = 512
-- Fill lines 256-512 with the same note
for i = 256, 512 do
pattern:track(song.selected_track_index):line(i).note_columns[1].note_value = note_255
pattern:track(song.selected_track_index):line(i).note_columns[1].instrument_value = inst_255
end
end
-- Fill pattern with effects using current step_size and fill_all settings
fill_pattern_with_steps(current_pattern_index,
instrument_index_display.value,
new_value,
note_slider.value,
reverse_checkbox.value,
step_size,
fill_all)
set_view_frame(vb)
end
}
record_mode = vb:checkbox {
value = false,
width = 20
}
reverse_checkbox = vb:checkbox {
value = false,
width = 20,
notifier = function(new_value)
print("Reverse - New value:", new_value)
print("Current step_size:", step_size)
print("Current fill_all:", fill_all)
fill_pattern_with_steps(current_pattern_index,
instrument_index_display.value,
pattern_512_mode.value,
note_slider.value,
new_value,
step_size,
fill_all)
set_view_frame(vb)
end
}
-- In the dialog content creation
view_switch = vb:switch {
width = 300,
items = {"Pattern Editor", "Sample Editor", "Modulation Matrix"},
value = 1,
notifier = function(new_value)
-- 1 = Pattern Editor
-- 2 = Sample Editor
-- 3 = Modulation Matrix
if new_value == 1 then
renoise.app().window.active_middle_frame = 1 -- Pattern Editor
elseif new_value == 2 then
renoise.app().window.active_middle_frame = 5 -- Sample Editor
else
renoise.app().window.active_middle_frame = 6 -- Modulation Matrix
end
end
}
-- 7. Create note slider
note_slider = vb:slider {
min = 0,
max = 119,
value = 48,
width = 300,
steps = {1, 12}, -- Small steps = 1, large steps = 12 (one octave)
notifier = function(new_value)
new_value = math.floor(new_value) -- Ensure whole number
local song = renoise.song()
new_value = math.floor(new_value)
local pattern = song.patterns[current_pattern_index]
local track = pattern:track(song.selected_track_index)
if record_mode.value and song.transport.playing then
-- Record mode ON: Write from current position downward
local start_line = song.transport.playback_pos.line
for i = start_line, pattern.number_of_lines do
if fill_all or ((i-1) % step_size == 0) then
track:line(i).note_columns[1].note_value = new_value
track:line(i).note_columns[1].instrument_value = instrument_index_display.value
end
end
else
-- Record mode OFF: Write to ALL rows or step rows
for i = 1, pattern.number_of_lines do
if fill_all or ((i-1) % step_size == 0) then
track:line(i).note_columns[1].note_value = new_value
track:line(i).note_columns[1].instrument_value = instrument_index_display.value
end
end
end
-- Update note display
local note = new_value % 12
local octave = math.floor(new_value / 12)
local note_names = {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}
note_display.text = note_names[note + 1] .. tostring(octave)
-- Always ensure playback
song.transport.playing = true
song.transport.loop_pattern = true
song.transport.follow_player = true
set_view_frame(vb)
end
}
-- Function to update timing displays
local function update_timing_displays()
local bpm = song.transport.bpm
local lpb = song.transport.lpb
local lines_per_sec = (bpm * lpb) / 60
local ms_per_line = 1000 / lines_per_sec
lines_per_sec_display.text = string.format("%.2f", lines_per_sec)
ms_per_line_display.text = string.format("%.2f", ms_per_line)
end
-- Create BPM and LPB sliders (add these before the dialog content creation)
bpm_slider = vb:slider {
min = 20,
max = 256,
value = math.min(256, song.transport.bpm),
width = 300,
steps = {1, 10}, -- Small steps = 1, large steps = 10
notifier = function(new_value)
new_value = math.floor(new_value) -- Ensure whole number
song.transport.bpm = new_value
bpm_display.text = tostring(new_value)
update_timing_displays()
if write_to_master then
write_tempo_commands(new_value, song.transport.lpb,
song.transport.playing and song.transport.playback_pos.line or 1)
end
end
}
lpb_slider = vb:slider {
min = 1,
max = 256,
value = math.min(256, song.transport.lpb),
width = 300,
steps = {1, 16}, -- Small steps = 1, large steps = 16
notifier = function(new_value)
new_value = math.floor(new_value) -- Ensure whole number
song.transport.lpb = new_value
lpb_display.text = tostring(new_value)
update_timing_displays()
if write_to_master then
write_tempo_commands(song.transport.bpm, new_value,
song.transport.playing and song.transport.playback_pos.line or 1)
end
end
}
-- Create BPM buttons array
local bpm_buttons = {}
for bpm = 50, 900, 50 do
table.insert(bpm_buttons, vb:button {
text = tostring(bpm),
width = 30,
notifier = function()
song.transport.bpm = bpm
bpm_display.text = tostring(bpm)
end
})
end
-- Create step controls
local step_values = {1,2,3,4,6,8,12,16,24,32,48,64}
step_display = vb:text { width = 40, text = "1" }
step_slider = vb:slider {
min = 1,
max = 12, -- 12 steps total
value = 1,
width = 200,
notifier = function(new_value)
-- Force to nearest integer
new_value = math.max(1, math.min(12, math.floor(new_value + 0.5)))
print("Step Slider - Value:", new_value)
print("Corresponding step_value:", step_values[new_value])
step_size = step_values[new_value]
step_display.text = tostring(step_size)
fill_pattern_with_steps(current_pattern_index,
instrument_index_display.value,
pattern_512_mode.value,
note_slider.value,
reverse_checkbox.value,
step_size,
fill_all)
end
}
-- Create the stepper
step_stepper = vb:valuebox {
min = 1,
max = 12,
value = 1,
width = 30,
notifier = function(new_value)
step_slider.value = new_value
end
}
fill_all_checkbox = vb:checkbox {
value = true,
width = 20,
notifier = function(new_value)
fill_all = new_value
-- Refill pattern with new fill_all setting
fill_pattern_with_steps(current_pattern_index,
instrument_index_display.value,
pattern_512_mode.value,
note_slider.value,
reverse_checkbox.value,
step_size,
fill_all)
end
}
-- Create timing displays after other displays
lines_per_sec_display = vb:text {
width = 50,
text = "0.00",
style = "strong",
font = "bold"
}
ms_per_line_display = vb:text {
width = 50,
text = "0.00",
style = "strong",
font = "bold"
}
-- Add function to update timing displays
local function update_timing_displays()
local bpm = song.transport.bpm
local lpb = song.transport.lpb
local lines_per_sec = (bpm * lpb) / 60
local ms_per_line = 1000 / lines_per_sec
lines_per_sec_display.text = string.format("%.2f", lines_per_sec)
ms_per_line_display.text = string.format("%.2f", ms_per_line)
end
-- Store the switch as a variable so we can access it throughout the dialog
local view_switch
-- Define the update_note_value function BEFORE creating the dialog content
local function update_note_value(new_value)
-- Clamp the note value between 0 and 119 (C-0 to B-9)
new_value = math.max(0, math.min(119, new_value))
local song = renoise.song()
local pattern = song.patterns[current_pattern_index]
local track = pattern:track(song.selected_track_index)
if record_mode.value and song.transport.playing then
-- Record mode ON: Write from current position downward
local start_line = song.transport.playback_pos.line
for i = start_line, pattern.number_of_lines do
if fill_all or ((i-1) % step_size == 0) then
track:line(i).note_columns[1].note_value = new_value
track:line(i).note_columns[1].instrument_value = instrument_index_display.value
end
end
else
-- Record mode OFF: Write to ALL rows or step rows
for i = 1, pattern.number_of_lines do
if fill_all or ((i-1) % step_size == 0) then
track:line(i).note_columns[1].note_value = new_value
track:line(i).note_columns[1].instrument_value = instrument_index_display.value
end
end
end
note_slider.value = new_value
set_view_frame(vb)
end
-- At the start of dialog creation, before creating other UI elements
local master_write_checkbox = vb:checkbox {
value = write_to_master,
width = 20,
notifier = function(new_value)
write_to_master = new_value
if new_value then
ensure_master_track_effects()
-- Write current values immediately
write_tempo_commands(song.transport.bpm, song.transport.lpb)
end
end
}
-- Create dialog content
local dialog_content = vb:column {
-- Instrument row
vb:row {
instrument_index_display,
instrument_name_text
},
-- Pattern type and checkboxes row
vb:row {
pattern_512_mode,
vb:text { text = "512 rows mode", font = "bold" },
vb:space { width = 20 },
record_mode,
vb:text { text = "Record notes below cursor", font = "bold" },
vb:space { width = 20 },
reverse_checkbox,
vb:text { text = "Reversed", font = "bold" }
},
-- BPM row
vb:row {
vb:text { text = "BPM", width = 85, style = "strong", font = "bold" },
bpm_slider,
bpm_display
},
-- BPM buttons row
vb:row {
spacing = 2,
unpack(bpm_buttons)
},
-- LPB row with preset buttons
vb:row {
vb:text { text = "LPB", width = 85, style = "strong", font = "bold" },
lpb_slider,
lpb_display,
vb:space { width = 10 },
vb:button { text = "2", width = 30, notifier = function() song.transport.lpb = 2 lpb_display.text = "2" lpb_slider.value = 2 end },
vb:button { text = "4", width = 30, notifier = function() song.transport.lpb = 4 lpb_display.text = "4" lpb_slider.value = 4 end },
vb:button { text = "8", width = 30, notifier = function() song.transport.lpb = 8 lpb_display.text = "8" lpb_slider.value = 8 end },
vb:button { text = "16", width = 30, notifier = function() song.transport.lpb = 16 lpb_display.text = "16" lpb_slider.value = 16 end },
vb:button { text = "32", width = 30, notifier = function() song.transport.lpb = 32 lpb_display.text = "32" lpb_slider.value = 32 end },
vb:button { text = "64", width = 30, notifier = function() song.transport.lpb = 64 lpb_display.text = "64" lpb_slider.value = 64 end },
vb:button { text = "128", width = 30, notifier = function() song.transport.lpb = 128 lpb_display.text = "128" lpb_slider.value = 128 end }
},
-- ComboTempo row
vb:row {
vb:text { text = "ComboTempo", width = 85, style = "strong", font = "bold" },
vb:slider {
min = 0,
max = 1000,
value = 500,
width = 555,
notifier = function(new_value)
-- Calculate BPM and LPB values
local bpm, lpb = calculate_timing_values(new_value)
-- Update transport values (these will be clamped automatically)
song.transport.lpb = lpb
song.transport.bpm = bpm
-- Update slider values (ensure within valid ranges)
lpb_slider.value = math.min(256, math.max(1, lpb))
bpm_slider.value = math.min(256, math.max(20, bpm))
-- Update displays
lpb_display.text = tostring(lpb)
bpm_display.text = tostring(bpm)
update_timing_displays()
-- Ensure playback
song.transport.playing = true
song.transport.loop_pattern = true
song.transport.follow_player = true
-- Write to master if enabled
if write_to_master then
write_tempo_commands(bpm, lpb,
song.transport.playing and song.transport.playback_pos.line or 1)
end
set_view_frame(vb)
end
}
},
-- Lines/sec and ms/line row
vb:row {
vb:text { text = "Lines/sec:", style = "strong", font = "bold" },
lines_per_sec_display,
vb:text { text = "ms/line:", style = "strong", font = "bold" },
ms_per_line_display
},
-- Note row
vb:row {
vb:text { text = "Note", width = 85, style = "strong", font = "bold" },
note_slider,
note_display,
vb:button {
text = "-24",
width = 40,
notifier = function()
update_note_value(note_slider.value - 24)
end
},
vb:button {
text = "-12",
width = 40,
notifier = function()
update_note_value(note_slider.value - 12)
end
},
vb:button {
text = "C-4",
width = 40,
notifier = function()
update_note_value(48) -- C-4 is note value 48
end
},
vb:button {
text = "+12",
width = 40,
notifier = function()
update_note_value(note_slider.value + 12)
end
},
vb:button {
text = "+24",
width = 40,
notifier = function()
update_note_value(note_slider.value + 24)
end
}
},
-- Render buttons row
vb:row {
vb:button {
text = "Render",
width = 100,
notifier = function()
local current_bpm = song.transport.bpm
render_context.current_bpm = current_bpm
StrRender()
song.selected_sequence_index = original_seq_pos
set_view_frame(vb)
end
}
},
vb:row {
vb:text { text = "Force View:", width = 85, style = "strong", font = "bold" },
vb:switch {
id = "switchmode", -- Give it a proper ID
width = 354,
items = {"Pattern Editor", "Sample Editor", "Modulation Matrix"},
value = 1,
notifier = function(new_value)
-- 1 = Pattern Editor
-- 2 = Sample Editor
-- 3 = Modulation Matrix
if new_value == 1 then
renoise.app().window.active_middle_frame = 1 -- Pattern Editor
elseif new_value == 2 then
renoise.app().window.active_middle_frame = 5 -- Sample Editor
else
renoise.app().window.active_middle_frame = 6 -- Modulation Matrix
end
end
}
},
vb:row {
vb:checkbox {
id = "envelope_checkbox",
value = false,
width = 20,
notifier = function(new_value)
local instrument = renoise.song().selected_instrument
-- Check if sample modulation sets exist
if not instrument.sample_modulation_sets or #instrument.sample_modulation_sets == 0 then
renoise.app():show_status("Please Pakettify the Instrument to enable envelopes")
vb.views.envelope_checkbox.value = false
return
end
-- Check if device exists and is Volume AHDSR
local device = instrument.sample_modulation_sets[1].devices[3]
if not device or device.name ~= "Volume AHDSR" then
renoise.app():show_status("Please Pakettify the Instrument to enable envelopes")
vb.views.envelope_checkbox.value = false
return
end
if new_value then
renoise.song().selected_sample.new_note_action = 2
device.operator = 3
device.enabled = true
device.parameters[8].value = 1
device.parameters[3].value = 0
device.parameters[4].value = 1
-- Convert initial Release slider value (480ms) to 0-1 range
local initial_ms = 480
local renoise_value = initial_ms / 20000
renoise_value = math.max(0, math.min(1, renoise_value))
device.parameters[5].value = renoise_value
-- Check if loop mode is OFF and set it to ON
if renoise.song().selected_sample.loop_mode == 1 then
renoise.song().selected_sample.loop_mode = 2
end
else
renoise.song().selected_sample.new_note_action = 1
if renoise.song().selected_sample.loop_mode == 2 then
renoise.song().selected_sample.loop_mode = 1
end
device.operator = 1
device.enabled = false
end
end
},
vb:text { text = "Enable Envelopes", font = "bold" },
vb:space { width = 10 },
-- Release Value scaling slider (0.00-1.00)
vb:text { text = "Scale:", font = "bold" },
vb:slider {
min = 0,
max = 100,
value = 100,
width = 100,
notifier = function(new_value)
local scaled_value = new_value / 100
renoise.song().selected_instrument.sample_modulation_sets[1].devices[3].parameters[8].value = scaled_value
scale_value_text.text = string.format("%.2f", scaled_value)
end
},
scale_value_text,
vb:space { width = 10 },
-- Release Time slider
vb:text { text = "Release:", font = "bold" },
vb:slider {
min = 0,
max = 100,
value = 20,
width = 300,
notifier = function(new_value)
local instrument = renoise.song().selected_instrument
-- Check if sample modulation sets exist
if not instrument.sample_modulation_sets or #instrument.sample_modulation_sets == 0 then
renoise.app():show_status("Please Pakettify the Instrument in order to use this feature. Doing nothing for now.")
return
end
-- Check if device exists and is Volume AHDSR
local device = instrument.sample_modulation_sets[1].devices[3]
if not device or device.name ~= "Volume AHDSR" then
renoise.app():show_status("Please Pakettify the Instrument in order to use this feature. Doing nothing for now.")