I asked chatgpt to come up with a solution for adding to your sort instrument tool (Updated Tool (3.1): Sort Instruments), and if you paste and execute the following in the script editor, it’ll add a feature to count the amount of times an instrument is used and will prepend the amount to the sample name;
-- Count the number of times a sample is used in the song and prepend the count to the sample name
function prepend_sample_usage_to_name()
-- Create a table to track usage counts for each instrument
local usage_counts = {}
for i = 1, #renoise.song().instruments do
usage_counts[i] = 0
end
-- Scan through all patterns, tracks, and note columns to count usage
for _, pattern_index in ipairs(renoise.song().sequencer.pattern_sequence) do
local pattern = renoise.song():pattern(pattern_index)
for track_index = 1, renoise.song().sequencer_track_count do
local track = pattern:track(track_index)
for line_index, line in ipairs(track.lines) do
if not line.is_empty then
for note_column_index = 1, renoise.song():track(track_index).visible_note_columns do
local note_column = line:note_column(note_column_index)
if not note_column.is_empty and note_column.instrument_value ~= 255 then
-- Increment the count for the instrument used in this note column
usage_counts[note_column.instrument_value + 1] = usage_counts[note_column.instrument_value + 1] + 1
end
end
end
end
end
end
-- Update the instrument names to prepend the usage count
for i, instrument in ipairs(renoise.song().instruments) do
if usage_counts[i] > 0 then
-- Remove any existing usage count from the name before prepending the updated count
local new_name = instrument.name:gsub("^%d+%s%-%s", "")
-- Prepend the usage count to the instrument name
new_name = usage_counts[i] .. " - " .. new_name
instrument.name = new_name
end
end
end
-- Add the function to the tool menu
renoise.tool():add_menu_entry {
name = "Instrument Box:Sort Instruments...:Update Sample Usage Count",
invoke = function() prepend_sample_usage_to_name() end
}