[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Re: Background server processing



stefan kersten writes:
 > On Sun, Mar 05, 2006 at 01:25:33AM +0100, Andrzej Kopec wrote:
 > > These ideas make sense. In first case the problem is how do 
 > > I know if processing is finished?
 > 
 > getLine returns nil on EOF.
 > 
 > > 	Task( {
 > > 		"1st Task".postln;
 > > 		p = Pipe.new("sleep 4; echo 'this goes to stdout'", "r"); 
 > > 		//c = p.getLine.debug("from stdout");
 > > 		//u = p.close.debug("result");
 > > 		//how to check if Pipe is finished?
 > > 		//anyone of above commented commands makes sclang frozen.
 > > 	}).play;
 > 
 > this works for me (see also the Pipe help file):
 > 
 > Task({
 > 	var p = Pipe.new("sleep 4; echo 'this goes to stdout'", "r"); 
 > 	var c;
 > 	"1st Task".postln;
 > 	while { (c = p.getLine).notNil } {
 > 		c.postln;
 > 	};
 > 	p.close;
 > }).play;
 > 
 > <sk>

But the problem is (in my case at least) the interpreter seems be frozen when it waits for
Pipe to finish. Maybe I'm missing, but my example doesn't work: the second task is stopped
until Pipe is not finished:
the strange thing is that after Pipe has finished the second task "throws out" all overdue
events (here: dots in Post and synths on server) at once. 

here goes the code with correction:

(
SynthDef(\test_gr, { 
	Out.ar(0, 
		(SinOsc.ar(440,0,0.4)
		*EnvGen.ar(Env.sine(0.1,1), doneAction: 2))!2 ) 
}).send(s);
)


(
u = p = c = nil;
value { 
	Task( {
		"2nd Task".postln;
			loop { 
				".".post; 
				Synth.grain(\test_gr).play;
				1.wait;
			}; 
	}).play;

	Task({
		var p = Pipe.new("sleep 4; echo 'this goes to stdout'", "r"); 
		var c;
		"1st Task".postln;
		while { (c = p.getLine).notNil } {
			c.postln;
		};
		p.close;
	}).play;
	
	
};
)

 
/ak/