Copy/paste 1/4 Of A Track To The Other 3/4?

I have a track with 0x40 lines.

I want to copy/paste the first 0x10 lines, 3 times. Pasted at t 0x10, 0x20, and 0x30. I want the copy to include notes, vol/pan/dly/effect columns and automations.

How can I do this with Lua? I’m looking for speed. Has anyone else done this before?

I would guess that the fastest way is to use[].tracks[].lines[]:copy_from(other_line object)

(The ‘for ipairs’ iteration loop you know how to handle, I suppose?)

Ya, I was hoping someone would dump a code snippet I could use. Like, maybe someone had already done this and could share. :)


Not exactly what you need, but maybe helps to get started:
pattern_line_tools.lua (from com.Renoise.PatternRotate.xrnx)

Here is an example. I haven’t included the automation. You might wanna try to use[].tracks[].automation[]:copy_from for that (I suppose).

local selected_track =  
function copy_line(from_line, to_line)[selected_track].lines[to_line]:copy_from([selected_track].lines[from_line])  
function copy_first_quarter(pattern, track)  
 local source_range = / 4  
 for i=1, source_range, 1 do  
 copy_line(i, i+source_range)  
 copy_line(i, i+source_range*2)  
 copy_line(i, i+source_range*3)  
copy_first_quarter(, selected_track)  

Ok thanks guys, based on your examples I came up with this:

function copy_and_expand(source_pattern, dest_pattern, track_idx)  
 if source_pattern ~= dest_pattern then  
 if dest_pattern.number_of_lines <= source_pattern.number_of_lines then  
 local multiplier = math.floor(dest_pattern.number_of_lines / source_pattern.number_of_lines) - 1  
 local to_line = 1  
 for i=1, source_pattern.number_of_lines do  
 for j=1, multiplier do  
 to_line = i + source_pattern.number_of_lines * j  
 if not dest_pattern.tracks[track_idx].lines[i].is_empty then  
 for k,automation in pairs(dest_pattern.tracks[track_idx].automation) do  
 local points = table.create(table.rcopy(automation.points))  
 for _,point in pairs(points) do  
 if math.floor(point.time) == i then  
 local decimals = explode(".", point.time)  
 if (decimals[2] ~= nil) then decimals = tonumber("0." .. decimals[2])  
 else decimals = 0 end  
 dest_pattern.tracks[track_idx].automation[k]:add_point_at(to_line + decimals, point.value)  
 elseif math.floor(point.time) > i then  

This will copy a track into a new pattern and if the new pattern is bigger, will fill it out. I’m using it in conjunction with a bunch of other sanity checks so you’re mileage may vary. Requires explode function:

Click to view contents

function explode(div,str)
if (div==’’) then return false end
local pos,arr = 0,table.create()
– for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) – Attach chars left of current divider
pos = sp + 1 – Jump past current divider
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr

Well even the indents in [lua] doesn’t work properly in all cases, but that depends from which editor the snippet was copied and pasted into the editor.
Unfortunately, the Renoise Lua Editor isn’t one amongst the efficients here.