Column By Column Iterator

Personally I have been using the :line(line_index) method with nested loops i.e.

  
--selected pattern and track values   
local pattern_index = renoise.song().selected_pattern_index  
local track_index = renoise.song().selected_track_index  
local pattern_length = renoise.song().patterns[pattern_index].number_of_lines  
  
  
--track in pattern object  
local current_pattern_track = renoise.song().patterns[pattern_index].tracks[track_index]  
  
  
 --nested for loop   
for columns = 1,12 do   
  
 for line_index = 1, pattern_length do  
  
 print(current_pattern_track:line(line_index).note_columns[columns].note_string)  
  
 end  
end  
  

but an iterator might be nice aswell, as you need to add another for loop if you want to do each column in song which starts to get messy.

Hi Ledger,

Thanks for the snippet. I don’t think this does what I want, though. My working scenario:

10 Patterns, all unique, numbered 1 to 10 in the Pattern Sequencer.
Iterate over column 1, starting from pattern 1, ending at pattern 10.
Iterate over column 2, starting from pattern 1, ending at pattern 10.
Iterate over column 3, starting from pattern 1, ending at pattern 10.
[…]

Your code snippet iterates over the columns of a single pattern. In general, all available iterators already do this.

The difference is i’m trying to treat each column as a continuous time line.

Cheers.

Yes it needs the other nested “for loop” for that:

EDIT: UPDATED WITH WORKING CODE

--selected pattern and track values  
  
local track_index = renoise.song().selected_track_index  
local total_sequence = #renoise.song().sequencer.pattern_sequence  
  
--column  
for columns = 1,12 do  
--pattern  
 for sequence_index = 1,total_sequence do  
  
 local pattern_index = renoise.song().sequencer.pattern_sequence[sequence_index]  
 local current_pattern_track = renoise.song().patterns[pattern_index].tracks[track_index]  
 local pattern_length = renoise.song().patterns[pattern_index].number_of_lines  
  
 --line  
 for line_index = 1, pattern_length do  
 print(current_pattern_track:line(line_index).note_columns[columns].note_string)  
 end  
 end  
end  
  

note the " current_pattern_track" needs to be reset in the second “for loop” in order to update the pattern number correctly.

Hi Ledger,

Your code snippet doesn’t work. Or, more to the point, your code snippet does exactly what I already do with .pattern_iterator:lines_in_track(), except it’s a bit buggy as I type this.

Look at this screenshot (each Pattern is 8 lines, made them small for the purposes of this example)

Attachment 1643 not found.

For my request, print should output in this order…

  
C-4  
---  
C-4  
---  
C-4  
---  
C-4  
---  
E-5  
---  
E-5  
---  
E-5  
---  
E-5  
---  
D-5  
---  
D-5  
[... etc ..]  
  

Your code, instead does C-4, D-5, (then fails to iterate the rest?)

It works perfectly for the way you described here?? I did do a couple of edits on that code just after posting so it might be worth recopying and pasting with all the variables to try again

EDIT: UPDATED WITH WORKING CODE

--selected pattern and track values  
  
local track_index = renoise.song().selected_track_index  
local total_sequence = #renoise.song().sequencer.pattern_sequence  
  
--column  
for columns = 1,12 do  
--pattern  
 for sequence_index = 1,total_sequence do  
  
 local pattern_index = renoise.song().sequencer.pattern_sequence[sequence_index]  
 local current_pattern_track = renoise.song().patterns[pattern_index].tracks[track_index]  
 local pattern_length = renoise.song().patterns[pattern_index].number_of_lines  
  
 --line  
 for line_index = 1, pattern_length do  
 print(current_pattern_track:line(line_index).note_columns[columns].note_string)  
 end  
 end  
end  
  

for this xrns I get

1645 column iterator demo.xrns

1646 iterate.PNG
prints:

1647 printout.PNG

Hi Ledger,

column iterator demo.xrns is a very weak test case ;)

Please download my slightly modified version ,see if you get the same results :)

If you do get it working, add a second track…

Cheers.

Renoises pattern iterators are written in Lua. See GitHub - renoise/xrnx: The official Renoise Lua Scripting repository for the source

Should be relatively easy to copy and/or adopt to fit your needs?

Sorry my fault, with a wrong incrementor,

try:

EDIT: UPDATED TO WORKING CODE

--selected pattern and track values  
  
local track_index = renoise.song().selected_track_index  
local total_sequence = #renoise.song().sequencer.pattern_sequence  
  
--column  
for columns = 1,12 do  
--pattern  
 for sequence_index = 1,total_sequence do  
  
 local pattern_index = renoise.song().sequencer.pattern_sequence[sequence_index]  
 local current_pattern_track = renoise.song().patterns[pattern_index].tracks[track_index]  
 local pattern_length = renoise.song().patterns[pattern_index].number_of_lines  
  
 --line  
 for line_index = 1, pattern_length do  
 print(current_pattern_track:line(line_index).note_columns[columns].note_string)  
 end  
 end  
end  
  

interesting thanks!

Hey, this works. Thanks man!

No probs, its nice to be helping you out for a change! (albeit longwindedly :) )

:)

There are still a few flaws.

  • Different pattern lengths
  • Current sequence of patterns assumed to be 1, 2, 3… What if it’s 99, 3, 99, 3, 3, 1…

But you for sure proved, conceptually, it can be done.

Would be great if someone (maybe me, but will not have time today) could make a generic working version like Taktik has linked.

Maybe try:

--selected pattern and track values  
  
local track_index = renoise.song().selected_track_index  
local total_sequence = #renoise.song().sequencer.pattern_sequence  
  
--column  
for columns = 1,12 do  
--pattern  
 for sequence_index = 1,total_sequence do  
  
 local pattern_index = renoise.song().sequencer.pattern_sequence[sequence_index]  
 local current_pattern_track = renoise.song().patterns[pattern_index].tracks[track_index]  
 local pattern_length = renoise.song().patterns[pattern_index].number_of_lines  
  
 --line  
 for line_index = 1, pattern_length do  
 print(current_pattern_track:line(line_index).note_columns[columns].note_string)  
 end  
 end  
end  

Nope, didn’t work. But, this does:

  
local rns = renoise.song()  
local total_sequence = #rns.sequencer.pattern_sequence  
for track_index = 1,#rns.tracks do  
 if  
 rns.tracks[track_index].type ~= renoise.Track.TRACK_TYPE_MASTER and  
 rns.tracks[track_index].type ~= renoise.Track.TRACK_TYPE_SEND  
 then  
 for columns = 1,rns.tracks[track_index].visible_note_columns do  
 for sequence_index = 1,total_sequence do  
  
 local pattern_index = rns.sequencer.pattern_sequence[sequence_index]  
 local pattern_length = rns.patterns[pattern_index].number_of_lines   
 local current_pattern_track = rns.patterns[pattern_index].tracks[track_index]  
  
 for line_index = 1,pattern_length do  
 local note_col = current_pattern_track:line(line_index).note_columns[columns]  
 -- Money shot  
 print(track_index, columns, note_col.note_string)  
 end  
 end  
 end  
 end  
end  
  

Thanks for your help.

No probs, glad you got a solution,

and now we have the opportunity to add to the standard iterators to avoid all the nesting.