«ScoreClock, Patterns, RT/NRT and server-side resources» by jamshark70

on 12 Nov'11 03:20 in patternsnrtnonrealtimesync

A quick demo of one way to allocate server-side resources (SynthDefs, Buffers) that works in RT/NRT with minimal modification.

You'll need Jonatan Liljedahl's ScoreClock quark:

// Mac OSX / Linux

Quarks.install("ScoreClock");

// Windows, see http://swiki.hfbk-hamburg.de/MusicTechnology/883

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(
p = Pbind(
	\instrument, \bufGrainPan,
	\bufnum, b,
	\time, Pwhite(0.1, 0.3, inf),
	\start, Pwhite(0.0, b.duration - Pkey(\time), inf) * b.sampleRate,
	\pan, Pwhite(-1.0, 1.0, inf),
	\delta, Pkey(\time) * Pexprand(0.8, 1.25, inf)
);

q = Pseq([
	(play: {
		// initialization event
		SynthDef(\bufGrainPan, { |start, time, bufnum, pan, rate = 1, amp = 1,
			attack = 0.001, decay = 0.02, outbus|
			var sig;
			sig = PlayBuf.ar(1, bufnum, rate * BufRateScale.kr(bufnum), 1, start, 0)
			* EnvGen.kr(Env.linen(attack, time, decay), doneAction:2);
			Out.ar(outbus, Pan2.ar(sig, pan, amp));
		}).add;

// NOTE: Mac OSX/Windows users need to change this for the actual location

		b = Buffer.read(s, Platform.systemAppSupportDir +/+ "sounds/a11wlk01.wav");

		s.sync
	}, delta: 0),
	p
]);

f = {  // cleanup func
	b.debug("freeing").free
};
)


s.reboot;

// RT
(
r = q.play;
c = SimpleController(r).put(\stopped, { c.remove; f.value });
)

r.stop;  // should free the buffer



// NRT
(
ScoreClock.beginScore;
Pfindur(10, q).play(ScoreClock);  // cleanup not needed since NRT server dies anyway

ScoreClock.makeScore.recordNRT(PathName.tmp +/+ "osc.osc", thisProcess.platform.recordingsDir +/+ "test2.aiff", options: ServerOptions.new.numOutputBusChannels_(2), duration: 10, action: { "done".postln });
)
descendants
«Tamara» by anonymous (private)
«ijyaivpo» by anonymous (private)
«futkcu» by anonymous (private)
full graph
raw 1357 chars (focus & ctrl+a+c to copy)
comments