Optimizing a method for wiping effect amount in selected columns

Hi, I have this, that used to work ( a function for wiping effect amounts and effect values in selection) and I’ve tried to optimize it so that it won’t cause a “tool became unresponsive” when working with 512 row patterns.

I’m wondering why doesn’t this actually do anything?

local ecvisible=nil

if renoise.song().selection_in_pattern==nil then return else end

ecvisible=renoise.song():track(renoise.song().selected_track_index).visible_effect_columns

for i=renoise.song().selection_in_pattern.start_line,renoise.song().selection_in_pattern.end_line do renoise.song():pattern(renoise.song().selected_pattern_index):track(renoise.song().selected_track_index):line(i):effect_column(ecvisible).number_string=".." 
renoise.song():pattern(renoise.song().selected_pattern_index):track(renoise.song().selected_track_index):line(i):effect_column(ecvisible).amount_string=".."
end
end

so at first i’m defining that ecvisible will be nill from start, but then read that the visible effect column number will be in ecvisible.

then I start a for-loop, where you start from start_line selection in pattern, and then you end in end_line selection in pattern.

then you do, to that specific pattern index, to that specific track index, to those lines between start_line and end_line, and to those available effect columns, the set of setting number_string be “…”. Then for the amount_string the amount_string will be set to “…”.

I run this script, see no errors, but nothing actually happens. so, what am i missing?

i put a print between ecvisible and for-loop, and i get the correct amount (2 effect columns). so there should be, in theory, no issues, right?

I’ve been instructed to use : because it is faster, but what might i be doing wrong in this after all?

This would only clear the very last effect column. You forgot to iterate effect columns.

Using methods ( : ) is a good start, but your iteration block will get a lot faster if you localize (“cache”) any object that is to be used more than once. More correctly, you’ll then be caching the call/lookup for the object/table.

Also, using the effect_column:clear() method seems to be slightly faster than setting the values to “…”

local song = renoise.song()

if song.selection_in_pattern==nil then return end

local ecvisible = song:track(song.selected_track_index).visible_effect_columns
local pattern_track = song:pattern(song.selected_pattern_index):track(song.selected_track_index)

for line_index = song.selection_in_pattern.start_line, song.selection_in_pattern.end_line do
  local line = pattern_track:line(line_index)
  for effect_column_index = 1, ecvisible do
    line:effect_column(effect_column_index):clear()
  end
end

PS1. You keep writing “else end”. The else is redundant there :slight_smile:

PS2. I have not localized the selection_in_pattern table since the minimal speed gain doesn’t justify creating an extra variable.

if song.selection_in_pattern==nil then return end

PS1. You keep writing “else end”. The else is redundant there :slight_smile:

cool, so then return end is possible! :slight_smile:
i was wondering about that. i’ll try and optimize it

I forgot something that will typically speed up things a lot.

Given that you have a lot of empty lines, this should execute faster in most cases:

local song = renoise.song()

if song.selection_in_pattern==nil then return end

local ecvisible = song:track(song.selected_track_index).visible_effect_columns
local pattern_track = song:pattern(song.selected_pattern_index):track(song.selected_track_index)

for line_index = song.selection_in_pattern.start_line, song.selection_in_pattern.end_line do
  local line = pattern_track:line(line_index)
  if not line.is_empty then
    for effect_column_index = 1, ecvisible do
      line:effect_column(effect_column_index):clear()
    end
  end
end

Making a similar check on effect_column.is_empty doesn’t show any additional speed benefits here. I’m guessing that the :clear() method does some kind of check like that internally already, or at least that it’s already blazingly fast.

PS. This function has numerous bugs. What happens when your selection spans several tracks? What happens when your selection is not in the selected_track?

PS. This function has numerous bugs. What happens when your selection spans several tracks? What happens when your selection is not in the selected_track?

Well, if your selection is not in the selected track, nothing happens - exactly as it should be. destructive editing should (well, in myopinion) only happen in the track_index the cursor is on, otherwise you run the risk of actually destroying stuff really badly - and with no undo :slight_smile:
So, it does work as should, currently. :slight_smile: