Dear list,
is there a way to set a path to load files from a directory not by their names, just by their index?
trying to be able to load files from folders that have unspecified names in a Pproto setup ( i know its shortcomings but still need it;)).
e.g. when using \allocread:
~buffiles=[1,5,7].collect { |x| ( ( type: \allocRead, path:"…/folder/%.wav".format(x)).yield)}
this way it’ll presuppose the numbers in the names’ characters to find it. im rather looking to load the 1st, 5th, 7th file in the folder into buffers.
thanks,
jan
~buffiles=[1,5,7].collect { |x| ( ( type: \allocRead, path:“…/folder/%.wav”.format(x)).yield)}
this way it’ll presuppose the numbers in the names’ characters to find it. im rather looking to load the 1st, 5th, 7th file in the folder into buffers.
i can recommend .patchMatch.
here’s your example using it…
~buffiles=[1,5,7].collect { |x| ( ( type: \allocRead, path:"…/folder/*.wav".pathMatch[x]).yield)}
although this way it’s a bit inefficient (multiple calls to pathMatch). so perhaps like this instead…
(
var paths= "~/Documents/soundfiles/*.wav".pathMatch; //edit path
~buffers.do{|b| b.free}; //make sure to free any previous buffers
~buffers= List.new;
[1, 5, 7].do{|i| //select which files to load by index
if(i<paths.size, {
~buffers.add(Buffer.read(s, paths[i]));
}, {
"index % out of range".format(i).warn;
});
};
)
~buffers.do{|b| b.postln}
now pathMatch is only called once and there’s also a check if you try to pick an index that’s larger than then number of found soundfiles.
_f
#|
fredrikolofsson.com musicalfieldsforever.com
thank you fredrik, this works really well!