A Replacement For Hard-Coded For-Loops?

Hi, I’ve recently taken to mucking around with the pattern effect column. So wrote this:

function delete_effect_column()  
local s=renoise.song()  
local currTrak = s.selected_track_index  
local currPatt = s.selected_pattern_index  
local reksult = s.selected_pattern.number_of_lines  
for i=1,8 do  
for s=1,reksult do  
renoise.tool():add_keybinding {name = "Global:Paketti:Delete effectcolumn content from current track", invoke = function() delete_effect_column() end }  

It wipes all the effect_column contents for the 8 effect_columns, no matter if they’re shown or not. But it does it sslloowwllyy. I’m wondering how this could be optimized?

Hi, I can think of two things that would ensure better performance:

  1. Use a pattern iterator for looping through lines. There are many different iterators to choose from, but for this purpose the “effect_columns_in_pattern_track” would be the one to go with.
  2. Use API methods for clearing the line / checking if the line needs to be cleared

So your example could become like this:

local s = renoise.song()  
local track_index = s.selected_track_index  
local patt_index = s.selected_pattern_index  
local iter = renoise.song().pattern_iterator:effect_columns_in_pattern_track(patt_index,track_index)  
for _,line in iter do  
 if not line.is_empty then  

These were amazing suggestions. Thank you very much. This makes me believe that if examples like this can be called from the pattern_iterator, that I’ll be able to use these bits of code from you to learn what other functions the pattern_iterator can have. cheers! :)

Well, there isn’t much to them really, they just represent different ways of looping through the song/pattern/track/columns.
In essence, they can be more efficient than a manual loop, but in practice it really depends on what you want to achieve. For instance, it wouldn’t be very clever to use a pattern iterator if we just wanted to change a single line!!

I suspect the real time-saver in the example above is the check for whether the line is empty, and the use of the clear() command.

yeah, pretty quickly realized that the pattern_iterator isn’t an automation_iterator :)