-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPakettiStacker.lua
518 lines (443 loc) · 21.3 KB
/
PakettiStacker.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
function returnpe()
renoise.app().window.active_middle_frame=renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Instrument Transpose -24",invoke=function() renoise.song().selected_instrument.transpose=renoise.song().selected_instrument.transpose-24 end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Instrument Transpose -12",invoke=function() renoise.song().selected_instrument.transpose=renoise.song().selected_instrument.transpose-12 end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Instrument Transpose 0",invoke=function() renoise.song().selected_instrument.transpose=0 end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Instrument Transpose +12",invoke=function() renoise.song().selected_instrument.transpose=renoise.song().selected_instrument.transpose+12 end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Instrument Transpose +24",invoke=function() renoise.song().selected_instrument.transpose=renoise.song().selected_instrument.transpose+24 end}
-- Function to set loop mode for all samples in the selected instrument
local function set_loop_mode_for_selected_instrument(loop_mode)
local song = renoise.song()
local instrument = song.selected_instrument
if not instrument then
renoise.app():show_status("No instrument selected.")
return
end
local samples = instrument.samples
local num_samples = #samples
if num_samples < 1 then
renoise.app():show_status("No samples in the selected instrument.")
return
end
-- Create a lookup table for human-readable loop mode names
local loop_mode_names = {
[renoise.Sample.LOOP_MODE_OFF] = "Off",
[renoise.Sample.LOOP_MODE_FORWARD] = "Forward",
[renoise.Sample.LOOP_MODE_REVERSE] = "Reverse",
[renoise.Sample.LOOP_MODE_PING_PONG] = "PingPong"
}
for i = 1, num_samples do
samples[i].loop_mode = loop_mode
end
local mode_name = loop_mode_names[loop_mode] or "Unknown"
renoise.app():show_status("Loop mode set to " .. mode_name .. " for " .. num_samples .. " samples.")
returnpe()
end
-- Menu entries for setting loop modes
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Loop Mode to Off",invoke=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_OFF) end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Loop Mode to Forward",invoke=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_FORWARD) end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Loop Mode to PingPong",invoke=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_PING_PONG) end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Set Loop Mode to Reverse",invoke=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_REVERSE) end}
-- Fix velocity mappings of all samples in the selected instrument and disable vel->vol
local function fix_sample_velocity_mappings()
local song = renoise.song()
local instrument = song.selected_instrument
if not instrument then
renoise.app():show_status("No instrument selected.")
return
end
-- Check if the instrument has slices
if instrument.samples[1].slice_markers ~= nil then
renoise.app():show_status("Slices detected, isolating slices to individual instruments.")
PakettiIsolateSlicesToInstrument()
end
local instrument = renoise.song().selected_instrument
local samples = instrument.samples
local num_samples = #samples
if num_samples < 1 then
renoise.app():show_status("No samples found in the selected instrument.")
return
end
-- Define the velocity range (01 to 127)
local velocity_min = 1
local velocity_max = 127
local velocity_step = math.floor((velocity_max - velocity_min + 1) / num_samples)
-- Base note and note range to apply to all samples
local base_note = 48 -- Default to C-4
local note_range = {base_note, base_note} -- Restrict to a single key
for i = 1, num_samples do
local sample = samples[i]
local start_velocity = velocity_min + (i - 1) * velocity_step
local end_velocity = start_velocity + velocity_step - 1
-- Adjust for the last sample to ensure it ends exactly at 127
if i == num_samples then
end_velocity = velocity_max
end
-- Disable vel->vol
sample.sample_mapping.map_velocity_to_volume = false
-- Update sample mapping
sample.sample_mapping.base_note = base_note
sample.sample_mapping.note_range = note_range
sample.sample_mapping.velocity_range = {start_velocity, end_velocity}
end
renoise.app():show_status("Velocity mappings updated, vel->vol set to OFF for " .. num_samples .. " samples.")
end
function jump_to_pattern_segment(segment_number)
local song = renoise.song()
song.transport.follow_player = false
local pattern_length = song.selected_pattern.number_of_lines
local segment = math.floor(pattern_length / 8)
song.selected_line_index = segment * (segment_number - 1) + 1 -- Added +1 to start from first row
returnpe()
end
-- Write notes with ramp-up velocities (01 to 127)
function write_velocity_ramp_up()
local song = renoise.song()
local pattern = song.selected_pattern
local start_line_index = song.selected_line_index
local patterntrack = pattern.tracks[renoise.song().selected_track_index]
local line_index = song.selected_line_index
local instrument_index = song.selected_instrument_index
if not song.selected_note_column then
renoise.app():show_status("No note column selected.")
return
end
-- Get unique velocity ranges
local velocity_ranges = {}
local samples = renoise.song().selected_instrument.samples
for _, sample in ipairs(samples) do
local range_key = table.concat(sample.sample_mapping.velocity_range, "-")
velocity_ranges[range_key] = sample.sample_mapping.velocity_range
end
-- Convert to array and sort by lower velocity bound
local unique_ranges = {}
for _, range in pairs(velocity_ranges) do
table.insert(unique_ranges, range)
end
table.sort(unique_ranges, function(a, b) return a[1] < b[1] end)
local num_ranges = #unique_ranges
if num_ranges < 1 then
renoise.app():show_status("No velocity mappings found.")
return
end
local base_note = 48 -- C-4
-- Write notes using the actual velocity ranges
for i, range in ipairs(unique_ranges) do
local velocity = range[1] -- Use the lower bound of each range
local line = patterntrack:line(line_index + i - 1)
local note_col = line.note_columns[1]
note_col.note_value = base_note
note_col.instrument_value = instrument_index - 1
note_col.volume_value = velocity
end
-- Create selection
song.selection_in_pattern = {
start_line = start_line_index,
end_line = start_line_index + num_ranges - 1,
start_track = song.selected_track_index,
end_track = song.selected_track_index,
start_column = 1,
end_column = 1
}
renoise.app():show_status("Ramp-up velocities written based on " .. num_ranges .. " unique velocity ranges.")
end
-- Write notes with ramp-down velocities starting from the last sample's upper velocity bound
-- Write notes with ramp-down velocities starting from the last sample's lower velocity bound
function write_velocity_ramp_down()
local song = renoise.song()
local pattern = song.selected_pattern
local patterntrack = pattern.tracks[renoise.song().selected_track_index]
local start_line_index = song.selected_line_index -- Store starting line for selection
local instrument_index = song.selected_instrument_index
if not song.selected_note_column then
renoise.app():show_status("No note column selected.")
return
end
-- Get unique velocity ranges
local velocity_ranges = {}
local samples = renoise.song().selected_instrument.samples
for _, sample in ipairs(samples) do
local range_key = table.concat(sample.sample_mapping.velocity_range, "-")
velocity_ranges[range_key] = sample.sample_mapping.velocity_range
end
-- Convert to array and sort by lower velocity bound (descending)
local unique_ranges = {}
for _, range in pairs(velocity_ranges) do
table.insert(unique_ranges, range)
end
table.sort(unique_ranges, function(a, b) return a[1] > b[1] end)
local num_ranges = #unique_ranges
if num_ranges < 1 then
renoise.app():show_status("No velocity mappings found.")
return
end
local base_note = 48
-- Write notes using the actual velocity ranges in descending order
for i, range in ipairs(unique_ranges) do
local velocity = range[1] -- Use the lower bound of each range
local line = patterntrack:line(start_line_index + i - 1)
local note_col = line.note_columns[1]
note_col.note_value = base_note
note_col.instrument_value = instrument_index - 1
note_col.volume_value = velocity
end
-- Create selection
song.selection_in_pattern = {
start_line = start_line_index,
end_line = start_line_index + num_ranges - 1,
start_track = song.selected_track_index,
end_track = song.selected_track_index,
start_column = 1,
end_column = 1
}
renoise.app():show_status("Ramp-down velocities written based on " .. num_ranges .. " unique velocity ranges.")
end
-- Write notes with random velocities, respecting the last sample's velocity range
function write_random_velocity_notes()
local song = renoise.song()
local pattern = song.selected_pattern
local patterntrack = pattern.tracks[renoise.song().selected_track_index]
local start_line_index = song.selected_line_index -- Store starting line for selection
local instrument_index = song.selected_instrument_index
if not song.selected_note_column then
renoise.app():show_status("No note column selected.")
return
end
-- Get unique velocity ranges
local velocity_ranges = {}
local samples = renoise.song().selected_instrument.samples
for _, sample in ipairs(samples) do
local range_key = table.concat(sample.sample_mapping.velocity_range, "-")
velocity_ranges[range_key] = sample.sample_mapping.velocity_range
end
-- Convert to array
local unique_ranges = {}
for _, range in pairs(velocity_ranges) do
table.insert(unique_ranges, range)
end
local num_ranges = #unique_ranges
if num_ranges < 1 then
renoise.app():show_status("No velocity mappings found.")
return
end
local base_note = 48
-- Write notes with random velocities within the available ranges
for i, range in ipairs(unique_ranges) do
local velocity = range[1] -- Use the lower bound of each range
local line = patterntrack:line(start_line_index + i - 1)
local note_col = line.note_columns[1]
note_col.note_value = base_note
note_col.instrument_value = instrument_index - 1
note_col.volume_value = velocity
end
-- Create selection
song.selection_in_pattern = {
start_line = start_line_index,
end_line = start_line_index + num_ranges - 1,
start_track = song.selected_track_index,
end_track = song.selected_track_index,
start_column = 1,
end_column = 1
}
renoise.app():show_status("Random velocities written based on " .. num_ranges .. " unique velocity ranges.")
end
renoise.tool():add_keybinding{name="Global:Paketti:Stack All Samples in Instrument with Velocity Mapping Split",invoke=function() fix_sample_velocity_mappings() end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Stack All Samples in Instrument with Velocity Mapping Split",invoke=function() fix_sample_velocity_mappings() end}
renoise.tool():add_menu_entry{name="Sample Mappings:Paketti..:Stack All Samples in Instrument with Velocity Mapping Split",invoke=function() fix_sample_velocity_mappings() end}
renoise.tool():add_keybinding{name="Global:Paketti:Write Velocity Ramp Up for Stacked Instrument",invoke=function() write_velocity_ramp_up() end}
renoise.tool():add_keybinding{name="Global:Paketti:Write Velocity Ramp Down for Stacked Instrument",invoke=function() write_velocity_ramp_down() end}
renoise.tool():add_keybinding{name="Global:Paketti:Write Velocity Random for Stacked Instrument",invoke=function() write_random_velocity_notes() end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Paketti Stacker..:Write Velocity Ramp Up for Stacked Instrument",invoke=function() write_velocity_ramp_up() end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Paketti Stacker..:Write Velocity Ramp Down for Stacked Instrument",invoke=function() write_velocity_ramp_down() end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Paketti Stacker..:Write Velocity Random for Stacked Instrument",invoke=function() write_random_velocity_notes() end}
--
function Stackerkeyhandlerfunc(dialog,key)
local closer = preferences.pakettiDialogClose.value
if key.modifiers == "" and key.name == closer then
dialog:close()
dialog=nil
return nil
else
return key
end
end
function on_switch_changed(selected_value)
local instrument = renoise.song().selected_instrument
local num_samples = #instrument.samples
-- Check if the first sample has slices
local has_slices = false
if num_samples > 0 and instrument.samples[1].slice_markers ~= nil then
has_slices = #instrument.samples[1].slice_markers > 0
end
if has_slices then
-- Already have slices
--f wipeslices()
if selected_value ~= "OFF" then
slicerough(selected_value)
renoise.app():show_status("Slices updated to " .. tostring(selected_value) .. " divisions.")
else
renoise.app():show_status("Slices cleared. No further slicing performed.")
end
else
-- No slices currently
if num_samples == 1 then
-- Single sample, no slices
if selected_value ~= "OFF" then
slicerough(selected_value)
renoise.app():show_status("Sample sliced into " .. tostring(selected_value) .. " divisions.")
else
renoise.app():show_status("Slice function is OFF. No slicing performed.")
end
else
-- Multiple samples, no slices
renoise.app():show_status("Multiple samples detected. No slicing performed.")
end
end
end
function showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument)
local vb = renoise.ViewBuilder()
local dialog = nil
local switch_values = {"OFF", "2", "4", "8", "16", "32", "64", "128"}
local switch_index = 1 -- Default to "OFF"
-- Function to close the dialog
local function close_dialog()
if dialog then
dialog:close()
dialog = nil
end
end
-- Dialog Content Definition
local dialog_content = vb:column {
vb:row{vb:button{text="Browse",notifier=function() pitchBendMultipleSampleLoader() end}},
vb:row {vb:text {text = "Set Slice Count",width=100,style = "strong",font = "bold"},
vb:switch {
id="wipeslice",
items = switch_values,
width = 250,
value = switch_index,
notifier = function(index)
local selected_value = switch_values[index]
if selected_value ~= "OFF" then
-- Do not revert to OFF here. Just call on_switch_changed.
on_switch_changed(tonumber(selected_value))
renoise.app().window.active_middle_frame=renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
else
wipeslices()
on_switch_changed("OFF")
end
end}},
vb:row{vb:button {
text = "Proceed with Stacking",
notifier = function()
proceed_with_stacking()
returnpe() end}},
vb:row {vb:text {text = "Stack Ramp",width=100,font = "bold",style = "strong",},
vb:button {text = "Up",notifier = function() write_velocity_ramp_up()
returnpe() end},
vb:button {
text = "Down",
notifier = function() write_velocity_ramp_down()
returnpe() end},
vb:button {
text = "Random",
notifier = function() write_random_velocity_notes()
returnpe() end}},
vb:row{vb:text{text="Set Loop Mode",width=100, style="strong",font="bold"},
vb:button{text="Off",notifier=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_OFF) end},
vb:button{text="Forward",notifier=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_FORWARD) end},
vb:button{text="PingPong",notifier=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_PING_PONG) end},
vb:button{text="Reverse",notifier=function() set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_REVERSE)end }
},
vb:row{vb:text{text="PitchStepper",width=100,font="bold",style="strong"},
vb:button{text="+12 -12",width=50,notifier=function() PakettiFillPitchStepper() end},
vb:button{text="+24 -24",width=50,notifier=function() PakettiFillPitchStepperTwoOctaves() end},
vb:button{text="0",width=50,notifier=function() PakettiClearPitchStepper() end},
},
vb:row{
vb:text{text="Instrument Pitch",width=100,font="bold",style="strong"},
vb:switch {
width = 250,
id = "instrument_pitch",
items = {"-24", "-12", "0", "+12", "+24"},
value = 3,
notifier = function(index)
-- Convert the selected index to the corresponding pitch value
local pitch_values = {-24, -12, 0, 12, 24}
local selected_pitch = pitch_values[index] -- Lua uses 1-based indexing for tables
-- Update the instrument transpose
renoise.song().selected_instrument.transpose = selected_pitch
end
}},
vb:row{
vb:button{
text = "Follow Pattern",
notifier = function()
if renoise.song().transport.follow_player then
renoise.song().transport.follow_player = false
else
renoise.song().transport.follow_player = true
end
returnpe() end},
vb:button{text = "1/8", notifier = function() jump_to_pattern_segment(1) end},
vb:button{text = "2/8", notifier = function() jump_to_pattern_segment(2) end},
vb:button{text = "3/8", notifier = function() jump_to_pattern_segment(3) end},
vb:button{text = "4/8", notifier = function() jump_to_pattern_segment(4) end},
vb:button{text = "5/8", notifier = function() jump_to_pattern_segment(5) end},
vb:button{text = "6/8", notifier = function() jump_to_pattern_segment(6) end},
vb:button{text = "7/8", notifier = function() jump_to_pattern_segment(7) end},
vb:button{text = "8/8", notifier = function() jump_to_pattern_segment(8) end}}}
-- Show the dialog
dialog = renoise.app():show_custom_dialog("Paketti Stacker", dialog_content,Stackerkeyhandlerfunc)
end
function proceed_with_stacking()
PakettiIsolateSlicesToInstrument()
local instrument = renoise.song().selected_instrument
local samples = instrument.samples
local num_samples = #samples
-- Define the velocity range (1 to 127)
local velocity_min = 1
local velocity_max = 127
local velocity_step = math.floor((velocity_max - velocity_min + 1) / num_samples)
-- Base note and note range to apply to all samples
local base_note = 48 -- Default to C-4
local note_range = {0, 119} -- Restrict to a single key
for i = 1, num_samples do
local sample = samples[i]
local start_velocity = velocity_min + (i - 1) * velocity_step
local end_velocity = start_velocity + velocity_step - 1
if i == num_samples then
end_velocity = velocity_max
end
sample.sample_mapping.map_velocity_to_volume = false
sample.sample_mapping.base_note = base_note
sample.sample_mapping.note_range = note_range
sample.sample_mapping.velocity_range = {start_velocity, end_velocity}
end
--showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument)
end
function LoadSliceIsolateStack()
-- Initial Operations
pitchBendMultipleSampleLoader()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
-- renoise.app():show_status("Velocity mappings updated, vel->vol set to OFF for " .. num_samples .. " samples.")
renoise.song().selected_line_index = 1
showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument)
set_loop_mode_for_selected_instrument(renoise.Sample.LOOP_MODE_FORWARD)
-- selectedInstrumentAllAutoseekControl(1) -- this shouldn't be included in the mix.
selectedInstrumentAllAutofadeControl(1)
setSelectedInstrumentInterpolation(4)
loadnative("Audio/Effects/Native/*Instr. Macros")
renoise.app():show_status("The Slices have been turned to Samples. The Samples have been Stacked together. The Velocity controls the Sample Selection. The Pattern now has a ramp up for the samples.")
end
renoise.tool():add_keybinding {name = "Global:Paketti:Load&Slice&Isolate&Stack Sample",invoke = function() LoadSliceIsolateStack() end}
renoise.tool():add_keybinding{name="Global:Paketti:Paketti Stacker Dialog...",invoke=function()
showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument) end}
renoise.tool():add_menu_entry{name="Main Menu:Tools:Paketti..:Paketti Stacker...",invoke=function()
showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument) end}
renoise.tool():add_menu_entry{name="Instrument Box:Paketti..:Paketti Stacker Dialog...",invoke=function()
showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument) end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Paketti Stacker Dialog...",invoke=function()
showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument) end}
renoise.tool():add_menu_entry{name="Pattern Editor:Paketti..:Paketti Stacker..:Paketti Stacker Dialog...",invoke=function()
showStackingDialog(proceed_with_stacking, on_switch_changed, PakettiIsolateSlicesToInstrument) end}