I believe it’s simplest to use note_column:copy_from().
Here is the simple principle (edge cases not included) showing how to copy a selection to the selected line position.
function copy_block_to_cursor()
local selection = rns.selection_in_pattern
local selection_data = {
start_line = selection.start_line,
end_line = selection.end_line,
track_index = selection.start_track,
ncol_index = selection.start_column,
range = selection.end_line - selection.start_line
}
local patterntrack = rns.selected_pattern:track(selection_data.track_index)
-- destination index minus source index
local offset = rns.selected_line_index - selection_data.start_line
for pos = selection_data.start_line, selection_data.end_line do
local src_ncol = patterntrack:line(pos):note_column(selection_data.ncol_index)
local dest_ncol = patterntrack:line(pos + offset):note_column(selection_data.ncol_index)
dest_ncol:copy_from(src_ncol)
end
end
Hi joue. Thanks!
I tried the following with two buttons:
- button for selection
function amic_CH05_1A( song, spi, sti, sli, snci, sii ) --Select a block in track
song = renoise.song()
spi, sti, sli, snci, sii = song.selected_pattern_index, song.selected_track_index, song.selected_line_index, song.selected_note_column_index, song.selected_instrument_index
song.selection_in_pattern = { start_line = sli, start_track = sti, end_line = sli + 16, end_track = sti }
end
- button for copy&paste, the previous selection in the new selected position of cursor (your function)
function amic_CH05_2A() --function copy_block_to_cursor()
local song = renoise.song()
local selection = song.selection_in_pattern -- does this detect the previous button selection?
local selection_data = {
start_line = selection.start_line,
end_line = selection.end_line,
track_index = selection.start_track,
ncol_index = selection.start_column,
range = selection.end_line - selection.start_line
}
local patterntrack = song.selected_pattern:track(selection_data.track_index)
-- destination index minus source index
local offset = song.selected_line_index - selection_data.start_line
for pos = selection_data.start_line, selection_data.end_line do
local src_ncol = patterntrack:line(pos):note_column(selection_data.ncol_index)
local dest_ncol = patterntrack:line(pos + offset):note_column(selection_data.ncol_index)
dest_ncol:copy_from(src_ncol)
end
end
I do not know if I’m doing the right steps:
- Press button of selection ( function amic_CH05_1A() ).The function selects 16 lines of the selected track.
- select a new position of cursor (without deselecting the previous selection). I select the track 01, line 01, same pattern.
- Press button of copy/paste ( function amic_CH05_2A(), your function ).
But it does nothing.Have I understood the operation correctly?Where is the error?Is the initial selection?
…
I have tried other simple functions with " :copy_from() ", as the following simple function (and others):
function amic_CH05_6B( song, a, b ) --copy first line in consecutive track (same position)
song = renoise.song()
a = song.selected_pattern:track(1):line(1) --first track
b = song.selected_pattern:track(2):line(1) --consecutive track
b:copy_from(a)
end
This is another much simpler history (it helps me understand how works the :copy_front() ). I understand that " :copy_from() " does not allow to separate in two buttons, first for copy and last for paste.The function solves everything at once.Perhaps the initial problem is the detection of the initial selection (which will be variable according to the user’s selection).