7 *new { | func, stackSize=64 |
8 ^super.new.init( func, stackSize)
12 priorityQ.removeValue(stream);
19 init { | func, stackSize |
20 priorityQ = PriorityQueue.new;
21 genStream = Routine({func.value(this) }, stackSize);
23 priorityQ.put(now, genStream);
26 par { | pattern, delta = 0 |
27 var stream = pattern.asStream;
28 priorityQ.put(now + delta, stream);
33 pat.embedInStream(event)
37 Event.silent(dur, event).yield
40 embedInStream { | inevent, cleanup|
42 var outevent, stream, nexttime;
43 event = inevent; // gives genStream access to the event
44 cleanup ?? { cleanup = EventStreamCleanup.new };
49 stream = priorityQ.pop;
50 outevent = stream.next(event).asEvent;
53 nexttime = priorityQ.topPriority;
54 if (nexttime.notNil, {
55 // that child stream ended, so rest until next one
56 outevent = Event.silent(nexttime - now, event);
57 event = outevent.yield;
64 cleanup.update(outevent);
66 priorityQ.put(now + outevent.delta, stream);
67 nexttime = priorityQ.topPriority;
68 outevent.put(\delta, nexttime - now);
70 event = outevent.yield;
80 ^Routine({ | ev | this.embedInStream(ev) })
82 embedInStream { | inevent, cleanup |
83 ^Spawner(routineFunc).embedInStream(inevent, cleanup ?? { EventStreamCleanup.new });
87 Pspawn : FilterPattern {
88 var <>spawnProtoEvent;
90 *new { |pattern, spawnProtoEvent|
92 .spawnProtoEvent_(spawnProtoEvent ?? { Event.default });
95 embedInStream { |inevent, cleanup|
97 var event, stream = pattern.asStream,
99 while { (event = stream.next(spawnProtoEvent.copy.put(\spawner, sp))).notNil } {
101 { event.method == \wait } {
102 event.spawner.wait(event.delta)
104 { #[seq, par].includes(event.method) } {
105 child = event.pattern;
106 if(child.isKindOf(Symbol)) {
107 child = (event[\dict] ? Pdef).at(child);
109 event.spawner.perform(event.method, child.value);
110 if(event.delta > 0) {
111 event.spawner.wait(event.delta)
114 // suspend requires access to the specific stream
115 // don't know how to get it... maybe implement later
116 { event.method == \suspendAll } {
117 event.spawner.suspendAll
119 { "Unrecognized method % in spawner event."
120 .format(event.method.asCompileString).warn;
123 }).embedInStream(inevent, cleanup ?? { EventStreamCleanup.new })
132 sp.par(Pbind(*[degree: Pwhite(0,12), dur: 0.1, db: -30]) );
133 sp.seq(Pbind(*[degree: Pseq((0..4).mirror.mirror, 1) + [-3, 0,2], ctranspose: -12, dur: 0.2 ]) );
142 sp.par(Pbind(*[degree: Pwhite(0,12), dur: 0.2, ctranspose: -12]) );
151 a = Spawner({ |sp | 100.do{ sp.wait(1) } });
153 b = a.par(Pbind(*[degree: Pwhite(0, 10), dur: 0.2]));
160 octave: (5.rand + 3).postln,
161 degree: Pwhite(0,12), dur: 0.1, db: -30