«Re: Load and play samples from GUI (Qt GUI only), adapted to use SoundFile:cue» by LFSaw

on 30 Apr'12 07:07 in guisamplercode forkloadersoundfile

Needs Qt GUI (VLayout)

Basic GUI for loading samples and playing them via button presses. Differences to the original version by rukano:

  • adapted to use SoundFile:cue
  • you can start and stop playing the samples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//samplePlayerGUI

var make;
var dialog = Dialog.openPanel({ |list| make.(list) }, nil, true);
var win = Window("Sample Player 3001").front;
var samples = ();
var buttons = ();
var players = ();

make = { |paths|
	{
		paths.do{ |path|
			[\loaded, path.basename].postln;
			samples[path] = SoundFile.collect(path).first;
			buttons[path] = Button()
				.states_([[path.basename], [path.basename, Color.red]])
				.action_{|me| 
					(me.value == 1).if({
						players[path] = samples[path].cue((amp: 1, server: Server.default), true)
					}, {
						players[path].release;
					});
				};
		};
		win.layout = VLayout(*buttons.asArray);
		win.onClose_{
			samples.do{ |player|
				player.release;
			};
		};
	}.fork(AppClock);
};
raw 759 chars (focus & ctrl+a+c to copy)
reception
comments
LFSaw user 30 Apr'12 19:53

you can also stop the samples from playing with this version.

rukano user 30 Apr'12 20:54

Nice, I never used SoundFile before... looks simple and easy to use! :)

LFSaw user 01 May'12 12:16

It is to my knowledge the easiest way to play back soundfiles while still being able to control playback parameters (by the environment argument you give at cueing...)