Just to give you some insight, i picked instrument 7 which was empty but had a default mapping, then i removed the mapping and did a bound check on its first table, then did the same with instrument 8 where i didn’t removed the mapping yet:
I have created the following function that detects how many sample mappings there are and then deletes them:
function delete_mappings ( ins, sample_index, note_layer )
local mappings = #renoise.song().instruments[ins].sample_mappings[note_layer]
for n = 0, (mappings - 1), 1 do
renoise.song().instruments[ins]:delete_sample_mapping_at( note_layer, sample_index )
Seems to do the job, the only thing I have noticed is that while the ‘sample_index’ is required it doesn’t actually have any effect. The ‘delete_sample_mapping_at’ command will delete all mappings on all samples in an instrument regardless of which sample_index you specify, seems a bit strange!
Also just for my understanding what does the ‘#’ before a command actually do?
EG #renoise.song().tracks how many tracks in the song or #renoise.song().sequencer.pattern_sequence how many patterns there are in the song sequence (think those are real examples but should give you the idea.)
Can’t comment on the rest but it looks very similar to how I did it with my Unison tool, where I needed to clear existing layers when randomly generating new unison settings, otherwise the instrument would get bigger and bigger (well it was the solution I went for out of the possible options anyway.)
Don’t know why you need sample_index I’m afraid.
Are you ever planning on doing this on anything but the current instrument? If not you could remove “instruments[ins]” and replace it with “selected_instrument” also doing away with the variable ins.
OK it’s not sample_index, which is used when generating Keyzones, it’s just index, which is the keyzone number.
Also looking at your code you are going it a weird way. Maybe…
for n=0, mappings-1 – makes sense to get you back to the single layer default.
renoise.song().instruments[ins]:delete_sample_mapping_at( note_layer, sample_index ) – you’re not actually using n anywhere.
I assume you have your sample_index=1 and thus you are always deleting keyzone with an index of 1, which then moves the rest of the keyzones down a level to fill in the hole. No harm in this really, as long as you know the one you will keep will be the last one and not the first one. If you actually want to blank things you may wish to create a keyzone at some point and remove all others anyway… Thing is, if you ever try a sample_index>1 you will find you get an error when it tries to delete a keyzone that doesn’t exist any more.
Think I did:
for n=mappings, 1, -1 do