2 initStreams { arg priorityQ;
3 list.do({ arg pattern, i;
4 priorityQ.put(0.0, pattern.asStream);
8 embedInStream { arg inval;
10 var priorityQ = PriorityQueue.new;
12 repeats.value(inval).do({ arg j;
13 var outval, stream, nexttime, now = 0.0;
15 this.initStreams(priorityQ);
17 // if first event not at time zero
18 if (priorityQ.notEmpty and: { (nexttime = priorityQ.topPriority) > 0.0 }) {
19 outval = Event.silent(nexttime, inval);
24 while { priorityQ.notEmpty } {
25 stream = priorityQ.pop;
26 outval = stream.next(inval).asEvent;
28 nexttime = priorityQ.topPriority;
29 if (nexttime.notNil, {
30 // that child stream ended, so rest until next one
31 outval = Event.silent(nexttime - now, inval);
39 priorityQ.put(now + outval.delta, stream);
40 nexttime = priorityQ.topPriority;
41 outval.put(\delta, nexttime - now);
44 // inval ?? { this.purgeQueue(priorityQ); ^nil.yield };
54 initStreams { arg priorityQ;
55 forBy(0, list.size-1, 2, { arg i;
56 priorityQ.put(list.at(i).value, list.at(i+1).asStream);
63 embedInStream { arg inevent;
64 var server, ids, patterns, event, ingroup, cleanup, stream;
65 var lag = 0, clock = thisThread.clock,
66 groupReleaseTime = inevent[\groupReleaseTime] ? 0.1;
68 server = inevent[\server] ?? { Server.default };
69 ingroup = inevent[\group];
70 ids = { server.nextNodeID } ! this.numberOfGroups;
73 event[\addAction] = 1;
74 event[\type] = \group;
77 event[\group] = ingroup;
79 inevent = event.yield.copy;
80 cleanup = EventStreamCleanup.new;
81 cleanup.addFunction(inevent, { | flag |
83 ( lag: lag - clock.beats + groupReleaseTime,
84 type: \kill, id: ids, server: server
89 patterns = this.wrapPatterns(ids);
90 stream = this.class.implClass.new(patterns, repeats).asStream;
92 inevent !? { inevent = inevent.copy; inevent[\group] = ingroup };
94 event = stream.next(inevent) ?? { ^cleanup.exit(inevent) };
95 cleanup.update(event);
96 lag = max(lag, clock.beats + event.use { ~sustain.value });
97 inevent = event.yield;
101 numberOfGroups { ^list.size }
102 wrapPatterns { arg ids;
103 ^ids.collect { |id, i| Psetpre(\group, id, list[i]) };
110 numberOfGroups { ^list.size div: 2 }
112 wrapPatterns { arg ids;
113 var patterns = list.copy;
114 ids.do { |id, i| patterns[((i << 1) + 1)] = Psetpre(\group, id, patterns[(i << 1) + 1]) };
118 *implClass { ^Ptpar }