Hi all
feeling lazy today - I know how to print a list of samples in a folder, for Sonic Piβs built in samples, using the sample_names function;
n = sample_groups.length #16
n.times do |i|
puts sample_groups[i]
sleep 0.125
end
x = sample_names(:vinyl)
puts x
sample x.choose
can I also do this for my own samples please?
PD-Pi
emlyn
June 2, 2024, 6:02pm
2
You can use sample_paths
for this - give it a folder (you can drag the folder into Sonic Pi to get the path) and it will return a ring of all samples in that folder. Look in the docs for more options (like you can limit it to samples with a particular string in the name).
3 Likes
thx so much @emlyn I can filter by string <3
Further to emlynβs answer if youj just want the filenames without the path you can use this
slist= Dir.children "/Users/rbn/Desktop/samples/Chimes/"
puts slist.length
slist.each do
puts slist[tick]
end
in teh example directgoryh gives output below
=>
ββ 13
ββ "chimes_c5.wav"
ββ "chimes_c4.wav"
ββ "chimes_c6.wav"
ββ "chimes_c3.wav"
ββ "chimes_a4.wav"
ββ "chimes_a5.wav"
ββ "chimes_fs3.wav"
ββ "chimes_ds3.wav"
ββ "chimes_fs4.wav"
ββ "chimes_a3.wav"
ββ "chimes_fs5.wav"
ββ "chimes_ds5.wav"
ββ "chimes_ds4.wav"
You can drag in the folder you want after slist=Dir.children
1 Like
Oooh, thatβs handy Robin, thanks
(got a little blues scale going there?)