I’m adding features to an instrument sorting tool from Joule and right now I’m trying to collect housekeeping info from the used sample instruments inside of the song comments window;
Here are snippits of the added code;
function append_housekeeping_info_to_song_comments()
local comments = renoise.song().comments
-- Start with the song title and artist
local song_title = renoise.song().name
local artist_name = renoise.song().artist
local housekeeping_info = string.format("Title: %s\nArtist: %s\n\nSample Housekeeping Info:\n", song_title, artist_name)
for i, instrument in ipairs(renoise.song().instruments) do
if #instrument.samples > 0 then
local instrument_info = string.format("Instrument %d: %s\n", i, instrument.name)
-- Append bit depth and sample rate
local sample = instrument.samples[1]
if sample.sample_buffer.has_sample_data then
local bit_depth = sample.sample_buffer.bit_depth
local sample_rate = sample.sample_buffer.sample_rate
instrument_info = instrument_info .. string.format(" Bit Depth: %d-bit, Sample Rate: %d Hz\n", bit_depth, sample_rate)
-- Append total sample duration
local total_duration = 0
for _, sample in ipairs(instrument.samples) do
if sample.sample_buffer.has_sample_data then
total_duration = total_duration + (sample.sample_buffer.number_of_frames / sample.sample_buffer.sample_rate)
end
end
instrument_info = instrument_info .. string.format(" Total Duration: %.2f s\n", total_duration)
-- Append stereo/mono info
local channels = sample.sample_buffer.number_of_channels
local stereo_mono = (channels == 2) and "Stereo" or "Mono"
instrument_info = instrument_info .. string.format(" Channels: %s\n", stereo_mono)
-- Append sample memory size
local total_size = 0
for _, sample in ipairs(instrument.samples) do
if sample.sample_buffer.has_sample_data then
total_size = total_size + (sample.sample_buffer.number_of_frames * sample.sample_buffer.number_of_channels * (sample.sample_buffer.bit_depth / 8))
end
end
instrument_info = instrument_info .. string.format(" Memory Size: %.2f KB\n", total_size / 1024)
-- Append loop points if looping is enabled
if sample.loop_mode ~= renoise.Sample.LOOP_MODE_OFF then
local loop_start = sample.loop_start / sample.sample_buffer.sample_rate
local loop_end = sample.loop_end / sample.sample_buffer.sample_rate
instrument_info = instrument_info .. string.format(" Loop Points: %.2fs - %.2fs\n", loop_start, loop_end)
end
end
-- Append the info to the housekeeping summary
housekeeping_info = housekeeping_info .. instrument_info .. "\n"
end
end
-- Update the song comments with the housekeeping info
table.insert(comments, housekeeping_info)
renoise.song().comments = comments
end
renoise.tool():add_menu_entry {
name = "Instrument Box:Sample Info...:Update Housekeeping Info in Song Comments",
invoke = function() append_housekeeping_info_to_song_comments() end
}
Using it does add info into the song comments window, but it seems to be capped at a certain amount of characters. At first I thought this was just a limitation of how much can be written down there, but when manually inserting characters I can add much more then what can be inserted from the tool. Also after generating the content for it, I can’t seem to delete, select or edit any of the text.
Is this a renoise bug or expected behavior?