Function for hide the unused note columns or effect columns

The following function that I share serves to hide note columns or effect columns that are empty (not used). I do not know if someone has made a similar function for a tool. But it seems to me a very interesting and useful function.

Maybe something like that should be native?

function pre_collapse_col_trk()
  local trk = song.selected_track
  local var = 2
  if ( trk.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
    var = 1
  else
    var = 2
  end
  local sti = song.selected_track_index
  if song.selected_effect_column then
    for e_col = 8, var, -1 do
      for seq = #song.sequencer.pattern_sequence, 1, -1 do
        local spq = song:pattern(seq)
        if not ( spq.is_empty ) then
          for lne = spq.number_of_lines, 1, -1 do
            if not ( spq:track(sti):line(lne):effect_column(e_col).is_empty ) then
              trk.visible_effect_columns = e_col
              return
            else
              trk.visible_effect_columns = e_col -1
            end
          end
        else
          if ( seq == 1 ) then
            trk.visible_effect_columns = var -1 
          end
        end
      end
    end
  else
    for n_col = 12, 2, -1 do
      for seq = #song.sequencer.pattern_sequence, 1, -1 do
        local spq = song:pattern(seq)
        if not ( spq.is_empty ) then
          for lne = spq.number_of_lines, 1, -1 do
            if not ( spq:track(sti):line(lne):note_column(n_col).is_empty ) then
              trk.visible_note_columns = n_col
              return
            else
              trk.visible_note_columns = n_col -1
            end
          end
        else
          if ( seq == 1 ) then
            trk.visible_note_columns = 1
          end
        end
      end
    end
  end
end

This function analyzes all the lines within the selected zone (columns of notes or effect of notes) of the whole sequence (all patterns), in search of parameters. If the analyzed column is completely empty, it is hidden, repeating this process iterating between all the columns of the same type.

The final result is that only columns that contain at least one parameter will be visible.First select a note column, to analyze this type. Select an effect column, to analyze this type. It works on any type of track, be it track, group, master or send.I’m sorry not to conform the tool. I only share the function because it is part of a larger tool, and I found it interesting to comment on it.

If you can think of a faster function, you know, share it here…

I think this is what you’re looking for. It should be much faster. https://www.renoise.com/tools/set-track-to-active-columns

I think this is what you’re looking for. It should be much faster. https://www.renoise.com/tools/set-track-to-active-columns

Does this tool analyze the entire line, instead of analyzing all the sub-columns? Is that why it’s faster?

Another doubt. Does this tool contemplate the hidden patterns, not used in the sequence?

_for , pattern in ipairs(rns.patterns) do

I am particularly interested in the analysis of the entire line. For example, for the construction of a piano roll, which should return the written notes, a good way would be to analyze the whole line…

I talk about this:

-- searching for sub-columns in use
            if scan_subcolumns then
              if (not found_vol) then
                for pos = 6, 204, 18 do
                  found_vol = found_vol or match(sub(line_str, pos, pos+1), "[0-Z]")
                end
              end
              
              if (not found_pan) then
                for pos = 8, 206, 18 do
                  found_pan = found_pan or match(sub(line_str, pos, pos+1), "[0-Z]")
                end
              end
              
              if (not found_dly) then
                for pos = 10, 208, 18 do
                  found_dly = found_dly or match(sub(line_str, pos, pos+1), "[0-Z]")
                end
              end
            end
            --          
          
            local ncol_line_str = sub(line_str, 0, 214)

By the way, I think that in the tool, the analysis of the sub-column of sample effects would be missing.

Does this tool analyze the entire line, instead of analyzing all the sub-columns? Is that why it’s faster?

Yes, that’s one of the reasons.

Even more importantly: if you go column by column (like in your example), you will be ‘creating’ a lot of objects (returned by the :line() methods et c) and some overhead on each of these calls. If you iterate more in the way that renoise.song is actually structured, you will have possibility of caching every object when going deeper and deeper into the song structure.

(simply put, having to do something like “spq:track(sti):line(lne):note_column(n_col)” is very suboptimal in this case)

Another doubt. Does this tool contemplate the hidden patterns, not used in the sequence?

_for , pattern in ipairs(rns.patterns) do

Yes, it works on all patterns. If you want it to work on the used patterns only, it’s easy to modify it into using renoise.song().sequencer.pattern_sequence instead. Keep in mind that you’d want to keep track of ‘duplicate sequences’ here in case you want to avoid the risk of scanning the same pattern more than once.

I am particularly interested in the analysis of the entire line. For example, for the construction of a piano roll, which should return the written notes, a good way would be to analyze the whole line…

I talk about this:

Click to view contents
-- searching for sub-columns in use
if scan_subcolumns then
if (not found_vol) then
for pos = 6, 204, 18 do
found_vol = found_vol or match(sub(line_str, pos, pos+1), "[0-Z]")
end
end
              
if (not found_pan) then
for pos = 8, 206, 18 do
found_pan = found_pan or match(sub(line_str, pos, pos+1), "[0-Z]")
end
end
              
if (not found_dly) then
for pos = 10, 208, 18 do
found_dly = found_dly or match(sub(line_str, pos, pos+1), "[0-Z]")
end
end
end
--          
          
local ncol_line_str = sub(line_str, 0, 214)

This is a special case, so I’m not sure if it’s reusable for what you need. This particular routine only aims at finding the right-most column that is used.

My suggestion is to just optimize by using object caching as much as possible (and of course, .is_empty checks whenever possible). If you find this too slow, there COULD (maybe) be options for speeding it up further by using line strings, but that would depend on the specific needs of your tool. It’s case by case. Start simple.

(For an extensive piano roll, I would definitely make a complete cache (mirror) of the song and update it via line notifiers. It’s a drastic measure, but IMO justified. Such a cache is fast like hell, but it’s quite complex to build.)

By the way, I think that in the tool, the analysis of the sub-column of sample effects would be missing.

I don’t think so. Or I’m not sure what you mean. edit: Ah, you’re right. That’s a bug :slight_smile:

Thanks joule!

I don’t think so. Or I’m not sure what you mean.

Shows several sub-columns with the “FX” button of each track (the sample effect column), in the pattern editor. You will see that these sub-columns are not hidden with the tool.I believe that the code is not complete. I would have to iterate for this sub-column. Something like this:

-- searching for sub-columns in use
            if scan_subcolumns then
              if (not found_vol) then
                for pos = 6, 204, 18 do
                  found_vol = found_vol or match(sub(line_str, pos, pos+1), "[0-Z]")
                end
              end
              
              if (not found_pan) then
                for pos = 8, 206, 18 do
                  found_pan = found_pan or match(sub(line_str, pos, pos+1), "[0-Z]")
                end
              end
              
              if (not found_dly) then
                for pos = 10, 208, 18 do
                  found_dly = found_dly or match(sub(line_str, pos, pos+1), "[0-Z]")
                end
              end

              if (not found_sfx) then ------here, maybe called "_sfx"
                --for pos = bla bla bla
              end

            end
            --

Thanks, I’ll try to fix that!

Thanks, I’ll try to fix that!

Ok :slight_smile: