GUI window displaying audio files

hello I have made the following code:


// Tu código original
d = Dictionary.new;
d.add(\folders -> PathName(thisProcess.nowExecutingPath.dirname ++"/Biblioteca Audio" ).entries);

(
for(
	0, d[\folders].size -1,
	{|i|
		d.add(d[\folders][i].folderName -> d[\folders][i].entries.collect({
		|sf|
		Buffer.read(s, sf.fullPath);
		});
	)});
)
(
// Código para crear la ventana GUI
w = Window.new("Biblioteca Sonidos", Rect(100, 100, 300, 200)); // Crear una ventana con un título y un tamaño
w.background = "blue";
w.layout = VLayout( // Asignar un diseño vertical a la ventana
	HLayout( // Crear un diseño horizontal para los botones
		Button(w, "Mostrar carpetas").action_({ // Crear un botón para mostrar las carpetas
			d[\folders].do({|f| f.folderName.postln}); // Mostrar los nombres de las carpetas en la consola
		}),
		Button(w, "Reproducir sonido"
		).action_({ // Crear un botón para reproducir un sonido
			var carpeta = d[\folders][rrand(0, d[\folders].size - 1)].folderName; // Elegir una carpeta al azar
			var sonido = d[carpeta][rrand(0, d[carpeta].size - 1)]; // Elegir un sonido al azar de la carpeta
			sonido.play; // Reproducir el sonido
			("Carpeta: " ++ carpeta ++ ", Sonido: " ++ sonido.bufnum).postln; // Mostrar el nombre de la carpeta y el sonido en la consola
		})
	)
);
)
w.front; // Mostrar la ventana
Window.closeAll
//////////////////////////////////////

up to here I managed to create a window that with two buttons, one shows me the folders that I have of audio in my library and the other one selects me to randomly sounds of some of them and makes them sound. Now I would like to improve this script a little more, for example that it can show me all the audio files when I select a folder, to be able to listen to them, and finally if I find the audio that I like, to be able to use it in the script with its path address.
Does anyone have any idea how to implement these ideas to improve the script?

I actually have pretty much exactly this script, but I’m in transit now, could share it a few hours later.

hjh

1 Like

Great, I look forward to it
thank you!!!

OK, here’s the script. I made it when I got tired of right-click → Audacity repeatedly for drum samples or breaks.

sample-audition.scd (9.4 KB)

(BTW if you have ffmpeg on mac or linux, it will automatically decode mp3s too.)

hjh

Thank you very much,
one doubt, how do you work with this .scd document in practice. Do you make a ‘.loadRelative’, or do you execute it directly?

Either way should be fine – it shouldn’t matter whether you execute the whole file in an editor window, or loading from disk.

hjh

I have already checked it, very useful. Thank you very much for the contribution!

Hello!! A question. The truth is that it is very useful this script to have a quick access to the files in an audio folder. But would it be possible to copy or drag any of these files that we are interested in from the window of your script to the SC IDE window ?

It’s just a standard ListView – the catch is that it seems to be undocumented, how to drag an item out of a ListView.

  • Mac: cmd-drag
  • Linux, Windows: ctrl-drag

hjh

Great, now is very useful!!! Thank You!!!