Filtering Samples by directory

I’ve been getting started with Sonic Pi for the past week and was looking for ways to make it easier to access my sample libraries I would typically use in music production.

I’ve found that I can pre-define functions to resolve to paths to get a similar experience I’ve seen Sam use in .sonic-pi/init.rb

def sample_lib
  "~/Music/samples"
end

def tech
  "#{sample_lib}/Studio_Essentials_Tech_House-Zenhiser/**"
end

def berlin
  "#{sample_lib}/PABLO_DECODER_PRESENTS_PEAK_TIME_BERLIN/**"
end

However, these sample libraries are organized into many categorical subfolders. Sometimes the filenames do not contain the same organizational data as the directories. For example:

I’ve noticed that the documentation regarding managing sample libraries explicitly states that all of the filters explicitly operate against the file basename, without extension. (https://github.com/samaaron/sonic-pi/blob/ba9635c50b7c46067d6cec3f2f21e0b736860bfb/app/server/ruby/lib/sonicpi/sample_loader.rb#L59)

I keep wishing I could filter by full path, instead of just File.basename such as:

sample tech, 'loops', 'bass', 1
sample berlin, 'top_loops', '_124_', 3

Being new to SonicPi in general, there may be excellent reasons for this to not be the default behaviour that aren’t clear to me. The SampleLoader class looks really straightforward, so I’m curious if it would be reasonable to add this type of option in?

It seems that an alternative would be to do something that returns a lambda with a custom filter:

def path_filter(*pths)
  ->(candidates) {
    pths.reduce(candidates) do |out, path|
      candidates.keep_if do |cand|
        cand.downcase.include? path.downcase
      end
    end
  }
end

This allows me to use:

sample berlin, path_filter('loops', 'drum')

But would this be something that could be (or is) better supported by default?

As an aside, what’s in play that allows me to use #define in my init.rb to persist vars, but I can’t just define a var like berlin = "sample_path..."