Thanks 4Tey and Joule!
I was thinking this was going to be a drastic code optimization exercise.
Finally, I have stolen much of the code of the Ledger/Joule tool.So I can use 2 separate buttons to shoot:
For close empty note_columns inside selected track:
--close empty note columns in selected track
function gtc_note_column_close_empty_individual( song, sti )
song = renoise.song()
sti = renoise.song().selected_track_index
if not (renoise.song():track(sti).type == renoise.Track.TRACK_TYPE_SEQUENCER) then
return
end
local sub = string.sub
local reverse = string.reverse
local match = string.match
local max = math.max
local max_note_column = 1
local floor = math.floor
local find = string.find
for _, pattern in ipairs( song.patterns ) do
local patterntrack = pattern:track( sti )
if not patterntrack.is_empty then
local lines = patterntrack:lines_in_range( 1, pattern.number_of_lines )
for _, line in ipairs( lines ) do
if not line.is_empty then
local line_str = sub( tostring( line ), 0, 214 )
line_str = reverse( line_str )
local first_match = match( line_str, "%d.[1-G]" )
max_note_column = ( first_match and max( max_note_column, 12 - floor( find( line_str, first_match ) / 18 ) ) ) or max_note_column
end
end
end
end
song:track( sti ).visible_note_columns = max_note_column
end
For close empty note_columns in all the song:
--close empty note columns in entire song
function gtc_note_column_close_empty( song )
song = renoise.song()
for sti = 1, song.sequencer_track_count do
local sub = string.sub
local reverse = string.reverse
local match = string.match
local find = string.find
local max = math.max
local floor = math.floor
local max_note_column = 1
local has_note_columns = song:track( sti ).type == renoise.Track.TRACK_TYPE_SEQUENCER
for _, pattern in ipairs( song.patterns ) do
local patterntrack = pattern:track( sti )
if not patterntrack.is_empty then
local lines = patterntrack:lines_in_range( 1, pattern.number_of_lines )
for _, line in ipairs( lines ) do
if not line.is_empty then
local line_str = tostring( line )
if has_note_columns then
local ncol_line_str = sub( line_str, 0, 214 )
ncol_line_str = reverse( ncol_line_str )
local ncol_first_match = match( ncol_line_str, "%d.[1-G]" )
max_note_column = ( ncol_first_match and math.max(max_note_column, 12 - floor( find( ncol_line_str, ncol_first_match ) / 18 ) ) ) or max_note_column
end
end
end
end
end
if has_note_columns then
song:track( sti ).visible_note_columns = max_note_column
end
end
end
…
I suppose it is valid for any range of lines according to each pattern…
local line_str = sub( tostring( line ), 0, 214 )
line_str = reverse( line_str )
local first_match = match( line_str, "%d.[1-G]" )
max_note_column = ( first_match and max( max_note_column, 12 - floor( find( line_str, first_match ) / 18 ) ) ) or max_note_column
Why these numbers 214, and /18 are used?This allows you to check several note_columns at a time?Mathematics is magic here!!!