-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PakettiInstrumentBox.lua
280 lines (227 loc) · 13.1 KB
/
PakettiInstrumentBox.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
function DuplicateInstrumentAndSelectNewInstrument()
local rs=renoise.song()
if renoise.app().window.active_middle_frame==3 then
local i=rs.selected_instrument_index;rs:insert_instrument_at(i+1):copy_from(rs.selected_instrument);rs.selected_instrument_index=i+1
renoise.app().window.active_middle_frame=3
else
if renoise.app().window.active_middle_frame == 9 then
local i=rs.selected_instrument_index;rs:insert_instrument_at(i+1):copy_from(rs.selected_instrument);rs.selected_instrument_index=i+1
renoise.app().window.active_middle_frame=9
else
local i=rs.selected_instrument_index;rs:insert_instrument_at(i+1):copy_from(rs.selected_instrument);rs.selected_instrument_index=i+1
end
end
end
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Instrument and Select New Instrument",invoke=function() DuplicateInstrumentAndSelectNewInstrument() end}
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Instrument and Select New Instrument (2nd)",invoke=function() DuplicateInstrumentAndSelectNewInstrument() end}
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Instrument and Select New Instrument (3rd)",invoke=function() DuplicateInstrumentAndSelectNewInstrument() end}
renoise.tool():add_menu_entry{name="--Instrument Box:Paketti..:Duplicate Instrument and Select New Instrument",invoke=function() DuplicateInstrumentAndSelectNewInstrument() end}
function duplicateSelectInstrumentToLastInstrument()
local rs=renoise.song()
local n_instruments = #rs.instruments
local src_inst_i = rs.selected_instrument_index
local src_inst = rs:instrument(src_inst_i)
rs:insert_instrument_at(n_instruments)
rs.selected_instrument_index = n_instruments
rs.selected_instrument:copy_from(src_inst)
end
renoise.tool():add_keybinding{name="Global:Paketti:Duplicate Instrument and Select Last Instrument",invoke=function() duplicateSelectInstrumentToLastInstrument() end}
renoise.tool():add_menu_entry{name="Instrument Box:Paketti..:Duplicate Instrument and Select Last Instrument",invoke=function() duplicateSelectInstrumentToLastInstrument() end}
renoise.tool():add_menu_entry{name="Instrument Box:Paketti..:Duplicate and Reverse Instrument", invoke=function() PakettiDuplicateAndReverseInstrument() end}
-- auto-suspend plugin off:
function autosuspendOFF()
renoise.song().instruments[renoise.song().selected_instrument_index].plugin_properties.auto_suspend=false
end
renoise.tool():add_menu_entry{name="--Instrument Box:Paketti..:Switch Plugin AutoSuspend Off",invoke=function() autosuspendOFF() end}
renoise.tool():add_menu_entry{name="--Main Menu:Tools:Paketti..:Plugins/Devices..:Switch Plugin AutoSuspend Off",invoke=function() autosuspendOFF() end}
-------------------------
function selectplay(number)
local s=renoise.song()
local currPatt=renoise.song().selected_pattern_index
local currTrak=renoise.song().selected_track_index
local currColumn=renoise.song().selected_note_column_index
local currLine=renoise.song().selected_line_index
local currSample=nil
local resultant=nil
s.selected_instrument_index=number+1
if renoise.song().transport.edit_mode==false then return end
-- Check if a note column is selected
if currColumn==0 then
renoise.app():show_status("Please Select a Note Column.")
return
end
currSample=s.selected_instrument_index-1
s.patterns[currPatt].tracks[currTrak].lines[currLine].note_columns[currColumn].note_string="C-4"
s.patterns[currPatt].tracks[currTrak].lines[currLine].note_columns[currColumn].instrument_value=currSample
if renoise.song().transport.follow_player==false
then
resultant=renoise.song().selected_line_index+renoise.song().transport.edit_step
if renoise.song().selected_pattern.number_of_lines<resultant
then renoise.song().selected_line_index=renoise.song().selected_pattern.number_of_lines
else renoise.song().selected_line_index=renoise.song().selected_line_index+renoise.song().transport.edit_step
end
else return
end
end
for i = 0,9 do
renoise.tool():add_keybinding{name="Global:Paketti:Numpad SelectPlay " .. i,invoke=function() selectPlay(i) end}
end
------------------------------------------------------------------------------------------------------
--cortex.scripts.CaptureOctave v1.1 by cortex
renoise.tool():add_keybinding{name="Global:Paketti:Capture Nearest Instrument and Octave (nojump)", invoke=function(repeated) capture_ins_oct("no") end}
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Capture Nearest Instrument and Octave (nojump)", invoke=function(repeated) capture_ins_oct("no") end}
renoise.tool():add_keybinding{name="Mixer:Paketti:Capture Nearest Instrument and Octave (nojump)", invoke=function(repeated) capture_ins_oct("no") end}
renoise.tool():add_keybinding{name="Global:Paketti:Capture Nearest Instrument and Octave (jump)", invoke=function(repeated) capture_ins_oct("yes") end}
renoise.tool():add_keybinding{name="Pattern Editor:Paketti:Capture Nearest Instrument and Octave (jump)", invoke=function(repeated) capture_ins_oct("yes") end}
renoise.tool():add_keybinding{name="Mixer:Paketti:Capture Nearest Instrument and Octave (jump)", invoke=function(repeated) capture_ins_oct("yes") end}
function capture_ins_oct(state)
local closest_note = {}
local current_track = renoise.song().selected_track_index
local current_pattern = renoise.song().selected_pattern_index
for pos, line in renoise.song().pattern_iterator:lines_in_pattern_track(current_pattern, current_track) do
if (not line.is_empty) then
local t = {}
if (renoise.song().selected_note_column_index == 0) then
for i = 1, renoise.song().tracks[current_track].visible_note_columns do
table.insert(t, i)
end
else
table.insert(t, renoise.song().selected_note_column_index)
end
for _, v in ipairs(t) do
local notecol = line.note_columns[v]
if (not notecol.is_empty and notecol.note_string ~= "OFF") then
if (closest_note.oct == nil) then
closest_note.oct = math.min(math.floor(notecol.note_value / 12), 8)
closest_note.line = pos.line
closest_note.ins = notecol.instrument_value + 1
closest_note.note = notecol.note_value
elseif (math.abs(pos.line - renoise.song().transport.edit_pos.line) < math.abs(closest_note.line - renoise.song().transport.edit_pos.line)) then
closest_note.oct = math.min(math.floor(notecol.note_value / 12), 8)
closest_note.line = pos.line
closest_note.ins = notecol.instrument_value + 1
closest_note.note = notecol.note_value
end
end
end
end
end
-- If no instrument is found, stop
if not closest_note.ins then
renoise.app():show_status("No nearby instrument found.")
return
end
-- Step 1: If the nearest instrument is not selected, select it
if renoise.song().selected_instrument_index ~= closest_note.ins then
renoise.song().selected_instrument_index = closest_note.ins
renoise.song().transport.octave = closest_note.oct
renoise.app():show_status("Instrument captured. Run the script again to jump to the sample.")
return
end
-- Step 2: If in the Sample Editor, toggle back to the Pattern Editor
if renoise.app().window.active_middle_frame == renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR then
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
renoise.app():show_status("Back to Pattern Editor.")
return
end
-- Step 3: If instrument is selected, jump to the nearest sample in the Sample Editor
if state == "yes" then
local instrument = renoise.song().instruments[closest_note.ins]
if instrument and #instrument.samples > 0 then
-- Determine the first sample's root note using sample_mappings
local sample_mapping = instrument.sample_mappings[1][1] -- First sample mapping
local first_sample_note = sample_mapping and sample_mapping.note_range[1] or 0 -- Default to C-0 (0)
-- Calculate the sample index based on the closest note
local sample_index = 1
for i, sample_map in ipairs(instrument.sample_mappings[1]) do
if closest_note.note >= sample_map.note_range[1] and closest_note.note <= sample_map.note_range[2] then
sample_index = i
break
end
end
-- Set the selected sample index and switch to the sample editor
renoise.song().selected_sample_index = sample_index
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
renoise.app():show_status("Instrument and sample captured, jumping to Sample Editor.")
return
else
renoise.app():show_status("No samples available in the instrument.")
return
end
end
end
-----------------------------------------------------------------------------------------------------------
--[[function emptyslices()
local w=renoise.app().window
local si=renoise.song().selected_instrument
local ss=renoise.song().selected_sample
local ssi=renoise.song().selected_sample_index
ssi=1
for i=1,64 do si:insert_sample_at(i) end
for i=1,64 do renoise.song().selected_instrument.samples[i].name="empty_sampleslot" .. i end
renoise.song().selected_instrument.name=("Empty Sample Slices" .. renoise.song().selected_instrument_index)
w.active_middle_frame= 3 end
renoise.tool():add_menu_entry{name="Instrument Box:Paketti..:Initialize..:Create 64 Empty Sample Slots", invoke=function() emptyslices() end}
renoise.tool():add_menu_entry{name="Sample List:Paketti..:Create 64 Empty Sample Slots", invoke=function() emptyslices() end}
renoise.tool():add_menu_entry{name="Sample Navigator:Paketti..:Create 64 Empty Sample Slots", invoke=function() emptyslices() end}
]]--
--------------------------------------------------------------------------------------------------------------------------------------------------------
-- Helper function to ensure the required number of instruments exist, with a max limit of 255 (FE)
local function ensure_instruments_count(count)
local song = renoise.song()
local max_instruments = 255 -- Allow creation up to 255 instruments (FE in hex)
while #song.instruments < count and #song.instruments <= max_instruments do
song:insert_instrument_at(#song.instruments + 1)
end
end
-- Function to select the next chunk, properly handling the maximum chunk of FE
local function select_next_chunk()
local song = renoise.song()
local current_index = song.selected_instrument_index
local next_chunk_index = math.floor((current_index - 1) / 16) * 16 + 16 + 1 -- Calculate the next chunk, ensuring alignment
-- Ensure the next chunk index does not exceed the maximum of 256 (index 255)
next_chunk_index = math.min(next_chunk_index, 255)
ensure_instruments_count(next_chunk_index)
song.selected_instrument_index = next_chunk_index
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
-- Function to select the previous chunk, properly handling lower bounds and correct chunk stepping
local function select_previous_chunk()
local song = renoise.song()
local current_index = song.selected_instrument_index
-- Correctly calculate the previous chunk, ensuring it does not get stuck or fail to decrement
local previous_chunk_index = math.max(1, math.floor((current_index - 2) / 16) * 16 + 1)
song.selected_instrument_index = previous_chunk_index
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
-- Function to directly select a specific chunk, limited to FE as the maximum chunk
local function select_chunk(chunk_index)
local target_index = chunk_index + 1
ensure_instruments_count(target_index)
renoise.song().selected_instrument_index = target_index
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_PATTERN_EDITOR
end
-- Keybindings and MIDI mappings for chunk navigation with your exact naming convention
renoise.tool():add_keybinding { name = "Global:Paketti:Select Next Chunk (00..F0)", invoke = select_next_chunk }
renoise.tool():add_keybinding { name = "Global:Paketti:Select Previous Chunk (00..F0)", invoke = select_previous_chunk }
renoise.tool():add_midi_mapping {
name = "Paketti:Select Next Chunk (00..FE)",
invoke = function(message) if message:is_trigger() then select_next_chunk() end end
}
renoise.tool():add_midi_mapping {
name = "Paketti:Select Previous Chunk (00..FE)",
invoke = function(message) if message:is_trigger() then select_previous_chunk() end end
}
-- Keybindings and MIDI mappings for selecting specific chunks (00 to F0), with FE as the max chunk
for i = 0, 15 do
local chunk_hex = string.format("%02X", i * 16)
local chunk_index = i * 16
renoise.tool():add_keybinding {
name = "Global:Paketti:Select Chunk " .. chunk_hex,
invoke = function() select_chunk(chunk_index) end
}
renoise.tool():add_midi_mapping {
name = "Paketti:Select Chunk " .. chunk_hex,
invoke = function(message) if message:is_trigger() then select_chunk(chunk_index) end end
}
end