Remove Empty Samples

Hi

Can you add new option in right mouse button [pop up] menu [when you are in sample slots] to
Remove empty sample slots?

You can put it at the bottom of the popup menu, so it will look like this:


Rename Instrument

Delete Unreferenced Instruments
Remove Empty Sample Slots
Delete All Instruments

It will speed up a lot of time sorting instruments instead moving sample by sample up or down and sort manually.

Maybe you can create “Remove Empty Samples And Sort by Name” instead?

*2

I miss the “delete unused samples” option as well ;)

YES, i ALSO FELT THE NEED FOR THIS <= (sorry I was tracking :rolleyes:)

yes, and the sorting thing is also a nice idea, while I often have huge gabs between the slots.

EDIT: I was thinking a bit about the sorting stuff.
sorting on name is not a good Idea I think, because you may have grouped your samples already like:pads,percussion,ect.
instead just get rid of the gabs like this:

BEFORE:
Piano
Drumkit
–empty–
cowbell
–empty–
–empty)–
grandma farting

AFTER:
Piano
Drumkit
cowbell
grandma farting

You are right! But it could help if someone really wants to sort samples, so menu will look like…:


Rename Instrument

Delete Unreferenced Instruments
Remove Empty Sample Slots
Sort Samples by Name
Delete All Instruments

B)

Bump!

It seems crazy to have to write a tool just to sort samples by name. Is there already a tool that does this?

Here’s something I hacked together, which you could in theory use to sort samples by any available sample property. Just write your own comparator and call sort_samples() with that function name as an argument:

-- Comparator functions
-----------------------
local comparator_name_asc = function (s1, s2)
  return s1.name < s2.name
end

local comparator_name_desc = function (s1, s2)
  return comparator_name_asc(s1, s2) == false
end

--
local comparator_length_asc = function (s1, s2)
  if s1.sample_buffer.has_sample_data == true and s2.sample_buffer.has_sample_data == false then
    return false
  elseif s2.sample_buffer.has_sample_data == true and s1.sample_buffer.has_sample_data == false then
    return true
  elseif s1.sample_buffer.has_sample_data == true and s2.sample_buffer.has_sample_data == true then
    return s1.sample_buffer.number_of_frames < s2.sample_buffer.number_of_frames
  else
    return false
  end
end

local comparator_length_desc = function (s1, s2)
  return comparator_length_asc(s1, s2) == false
end


-- Primary sort function
------------------------
function sort_samples( comparator )
  
  local tbl = renoise.song().selected_instrument.samples
  local num_swaps = 0
  
  --[[ INSERTION SORT ]]
  for i = 2, #tbl do
    local k = i
    while ( k > 1 and comparator(tbl[k], tbl[k-1]) ) do
      renoise.song().selected_instrument:swap_samples_at(k, (k-1))
      tbl = renoise.song().selected_instrument.samples
      num_swaps = num_swaps + 1
      k = k-1
    end
  end
  
  -- iterate if needed
  if num_swaps > 0 then sort_samples(comparator) end
  
end



-- Calling
----------
-- By name, ascending
sort_samples( comparator_name_asc )

-- By name, descending
-- sort_samples( comparator_name_desc )

-- By sample length, shortest to longest
-- sort_samples( comparator_length_asc )

-- By sample length, longest to shortest
-- sort_samples( comparator_length_desc )

It uses the insertion sort algorithm, which may not be the fastest in the world, but it gets the job done. If enough people care enough, I might put together a tool to add items to the right-click menu in the instrument’s sample list.

Cheers, and enjoy!

Thanks! Just noticed reply, I didn`t have opportunity to login here due to malware I had since March 2020. Now seems I’m back on a Track :wink: