Unused patterns not lost on save

Shouldn’t the unused patterns get lost on save? I have a project were only the first 0-32 patterns are used, still api gives me 145 patterns, and I can switch through all the 145…

Tend to prefer explicity verses implicity.

The ‘Remove Unused Patterns’ function seems ideal for the task.

The save function perhaps should not assume pattern or instrument cleanup
options but it could be that a ‘save with options’ function would be helpful.

1 Like

Oh wow, never realized that before! :sweat_smile: First time used “delete unused patterns” in my life!

1 Like

Ok, but #sng.patterns maybe should return the value of highest used pattern number…

Perhaps you are looking for the highest number in the sequence.

#renoise.song().sequencer.pattern_sequence

You can also insert into a table all the patterns used in the sequence and:

  1. clean the not inserted.
  2. sort the table from smallest to largest and return the last value in the table (highest index of pattern used).
--to 1
renoise.song().patterns[]:clear()
--2
local function return_highest_pattern_index_used()
  local PATTERN_SEQUENCE_TABLE={}
  local song=renoise.song()
  for seq=1,#song.sequencer.pattern_sequence do
    PATTERN_SEQUENCE_TABLE[seq]=song.sequencer:pattern(seq)
  end
  --rprint(PATTERN_SEQUENCE_TABLE)  --real
  table.sort(PATTERN_SEQUENCE_TABLE)
  --rprint(PATTERN_SEQUENCE_TABLE)  --sorted
  print(PATTERN_SEQUENCE_TABLE[#PATTERN_SEQUENCE_TABLE])
  return PATTERN_SEQUENCE_TABLE[#PATTERN_SEQUENCE_TABLE]
end
return_highest_pattern_index_used()

The interesting thing is not the highest number of the used pattern, but the unused patterns (if they are not empty, clear them).


max = 0;
sng = renoise.song()
for pos = 1,#sng.sequencer.pattern_sequence do 
  max = math.max(max,  sng.sequencer:pattern(pos))
end
rprint(max-1)

I think I will use this in eq helper, might improve performance in some edge cases. Still, I wish that the target instrument of a track was selectable in the first input device at index 1…

1 Like