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?
Here is an example. I haven’t included the automation. You might wanna try to use renoise.song().patterns[].tracks[].automation[]:copy_from for that (I suppose).
local selected_track = renoise.song().selected_track_index
function copy_line(from_line, to_line)
renoise.song().selected_pattern.tracks[selected_track].lines[to_line]:copy_from(renoise.song().selected_pattern.tracks[selected_track].lines[from_line])
end
function copy_first_quarter(pattern, track)
local source_range = renoise.song().selected_pattern.number_of_lines / 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)
end
end
copy_first_quarter(renoise.song().selected_pattern_index, 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
dest_pattern.tracks[track_idx]:copy_from(source_pattern.tracks[track_idx])
end
if dest_pattern.number_of_lines <= source_pattern.number_of_lines then
return
end
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
dest_pattern.tracks[track_idx].lines[to_line]:copy_from(dest_pattern.tracks[track_idx].lines[i])
end
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
break
end
end
end
end
end
end
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
end
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr
end
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.