What’s the best way of iterating through a pattern?
If I do the following to insert an effect on every line it will be very erratic, and not on every line.
local function process_pattern(option)
local song = renoise.song()
local new_pos = song.transport.playback_pos
new_pos.line = 1
song.transport.playback_pos = new_pos
for pos, line in song.pattern_iterator:lines_in_pattern_track(1, 1) do
if new_pos.line < song.selected_pattern.number_of_lines then
new_pos.line = new_pos.line + 1
song.transport.playback_pos = new_pos
-- print(new_pos.line) -- prints properly
-- print(song.transport.playback_pos.line) -- prints erratically
insert_fx(option)
end
end
end
(printing new_pos.line results in a perfect iteration in the terminal, but printing song.transport.playback_pos.line gives very erratic results (instead of 1,2,3,4,5,6,7,…,64 it becomes 24,24,24,24,24,…,53,53,53,53,53,53,53))
Thanks I was curious about that.
It seemed like you can’t actually change renoise.song().transport.playback_pos.line directly, but have to overwrite
the whole object, so I thought maybe it was a copy (this new_pos stuff is basically taken from the
custom pattern navigation tool).
Just changed the code to
local function process_pattern(option)
local song = renoise.song()
local new_pos = renoise.SongPos()
new_pos.sequence = 1
new_pos.line = 1
song.transport.playback_pos = new_pos
for pos, line in song.pattern_iterator:lines_in_pattern_track(1, 1) do
if new_pos.line < song.selected_pattern.number_of_lines then
new_pos.line = new_pos.line + 1
song.transport.playback_pos = new_pos
-- print(new_pos.line) -- prints properly
-- print(song.transport.playback_pos.line) -- prints erratically
insert_fx(option)
end
end
end
and it still has the same erratic behavior.
I guess there must be some other way of manipulating lines in the pattern where you’re not using playback_pos.
Or maybe I can slow the iteration speed down so the playback_pos gets properly updated every time.
local song = renoise.song()
local new_pos = renoise.SongPos()
new_pos.sequence = 1
new_pos.line = 1
song.transport.edit_pos = new_pos
for pos, line in song.pattern_iterator:lines_in_pattern_track(1, 1) do
if new_pos.line < song.selected_pattern.number_of_lines then
new_pos.line = new_pos.line + 1
song.transport.edit_pos = new_pos
print(song.transport.edit_pos)
end
end
Using print instead of oprint or rprint actually doesn’t matter (tried all three in all configurations… same results).
This doesn’t just happen when printing to the terminal, it happens when executing a function call (i.e. look at the original code),
I’m just using print for brevity.
Ok thanks, that explains it. I was wondering if I could do that because it didn’t seem intuitive to use the pos.