Skip to content
This repository
Browse code

Pattern cleanups:

Consistently allow functions for e.g. repeats.do --> repeats.value(inval).do -- this also passes in 'inval'

Minor formatting fixes

git-svn-id: https://supercollider.svn.sourceforge.net/svnroot/supercollider/trunk@9921 a380766d-ff14-0410-b294-a243070f3f08
  • Loading branch information...
commit 08fcf098c87d27c2eb12ab784bc8d89563abe876 1 parent 888c32b
James Harkins authored

Showing 19 changed files with 257 additions and 545 deletions. Show diff stats Hide diff stats

  1. +0 2  common/build/SCClassLibrary/Common/Streams/BasicOpsStream.sc
  2. +26 25 common/build/SCClassLibrary/Common/Streams/ControlPatterns.sc
  3. +43 56 common/build/SCClassLibrary/Common/Streams/FilterPatterns.sc
  4. +6 2 common/build/SCClassLibrary/Common/Streams/FuncStreamAsRoutine.sc
  5. +59 79 common/build/SCClassLibrary/Common/Streams/ListPatterns.sc
  6. +37 41 common/build/SCClassLibrary/Common/Streams/Patterns.sc
  7. +0 3  common/build/SCClassLibrary/Common/Streams/Penv.sc
  8. +3 17 common/build/SCClassLibrary/Common/Streams/Pfx.sc
  9. +1 1  common/build/SCClassLibrary/Common/Streams/Plambda.sc
  10. +5 6 common/build/SCClassLibrary/Common/Streams/PmonoStreams.sc
  11. +13 55 common/build/SCClassLibrary/Common/Streams/Ppar.sc
  12. +4 4 common/build/SCClassLibrary/Common/Streams/Ppatmod.sc
  13. +2 9 common/build/SCClassLibrary/Common/Streams/Pproto.sc
  14. +1 10 common/build/SCClassLibrary/Common/Streams/Pspawner.sc
  15. +28 25 common/build/SCClassLibrary/Common/Streams/RandomDistPatterns.sc
  16. +5 80 common/build/SCClassLibrary/Common/Streams/Stream.sc
  17. +7 114 common/build/SCClassLibrary/Common/Streams/TabFileReader.sc
  18. +12 12 common/build/SCClassLibrary/Common/Streams/TimePatterns.sc
  19. +5 4 common/build/SCClassLibrary/Common/Streams/extEnv.sc
2  common/build/SCClassLibrary/Common/Streams/BasicOpsStream.sc
@@ -101,7 +101,5 @@ NAryOpStream : Stream {
101 101 reset { a.reset; arglist.do({ arg item; item.reset }) }
102 102
103 103 storeOn { arg stream; stream <<< a << "." << operator << "(" <<<* arglist << ")" }
104   -
105   -
106 104 }
107 105
51 common/build/SCClassLibrary/Common/Streams/ControlPatterns.sc
@@ -11,32 +11,33 @@ Phid : Pattern {
11 11 storeArgs { ^[element,locID,repeats] }
12 12 embedInStream { arg event;
13 13 var all, device, spec, elements, deviceName, min, max;
  14 +
  15 + all = HIDDeviceService.devices;
  16 + if(all.isNil, {
  17 + HIDDeviceService.buildDeviceList;
14 18 all = HIDDeviceService.devices;
15   - if(all.isNil, {
16   - HIDDeviceService.buildDeviceList;
17   - all = HIDDeviceService.devices;
18   - });
19   - device = all.at(locID);
20   - if(device.isNil, { "device not found".error; ^nil });
21   - if(element.isNumber.not, {
22   - element = HIDDeviceService.keyToIndex(element, locID);
23   - if(element.isNil, { "key not found".error; ^nil });
24   - });
25   - elements = device.elements;
26   - min = elements.at(element).min;
27   - max = elements.at(element).max;
28   - spec = ControlSpec.new(min, max, 'lin', 1);
29   - if((min === 0) and: {max === 1}, {
30   - repeats.value.do({
31   - event = device.value(element).yield
32   - });
33   - ^event
34   - }, {
35   - repeats.value.do({
36   - event = spec.unmap(device.value(element)).yield
37   - });
38   - ^event;
39   - })
  19 + });
  20 + device = all.at(locID);
  21 + if(device.isNil, { "device not found".error; ^nil });
  22 + if(element.isNumber.not, {
  23 + element = HIDDeviceService.keyToIndex(element, locID);
  24 + if(element.isNil, { "key not found".error; ^nil });
  25 + });
  26 + elements = device.elements;
  27 + min = elements.at(element).min;
  28 + max = elements.at(element).max;
  29 + spec = ControlSpec.new(min, max, 'lin', 1);
  30 + if((min === 0) and: {max === 1}, {
  31 + repeats.value(event).do({
  32 + event = device.value(element).yield
  33 + });
  34 + ^event
  35 + }, {
  36 + repeats.value(event).do({
  37 + event = spec.unmap(device.value(element)).yield
  38 + });
  39 + ^event;
  40 + })
40 41 }
41 42 }
42 43
99 common/build/SCClassLibrary/Common/Streams/FilterPatterns.sc
@@ -14,7 +14,7 @@ Pn : FilterPattern {
14 14 }
15 15 storeArgs { ^[pattern,repeats] }
16 16 embedInStream { arg event;
17   - repeats.value.do { event = pattern.embedInStream(event) };
  17 + repeats.value(event).do { event = pattern.embedInStream(event) };
18 18 ^event;
19 19 }
20 20 }
@@ -177,8 +177,6 @@ Pset : FilterPattern {
177 177
178 178 this.filterEvent(inEvent, val);
179 179 event = inEvent.yield;
180   -
181   -
182 180 }
183 181 }
184 182 }
@@ -291,18 +289,16 @@ Pstretchp : Pstretch {
291 289 }
292 290
293 291
  292 +// needs testing - hjh
294 293 Pplayer : FilterPattern {
295   - var <>playerPattern, <>subPattern;
296   - // this is broken:
  294 + var <>subPattern;
297 295 *new { arg playerPattern, subPattern;
298   - // super new copy args puts it in pattern, playerPattern
299   - // -cx
300 296 ^super.newCopyArgs(playerPattern, subPattern)
301 297 }
302   - storeArgs { ^[ playerPattern, subPattern ] }
  298 + storeArgs { ^[ pattern, subPattern ] }
303 299 embedInStream { arg event;
304 300 var player, inevent;
305   - var playerStream = playerPattern.asStream;
  301 + var playerStream = pattern.asStream;
306 302 var stream = subPattern.asStream;
307 303 loop{
308 304 inevent = stream.next(event);
@@ -313,6 +309,9 @@ Pplayer : FilterPattern {
313 309 event = yield(inevent);
314 310 }
315 311 }
  312 + // backward compatibility: unnecessary var playerPattern was removed
  313 + playerPattern { ^pattern }
  314 + playerPattern_ { |playerPattern| pattern = playerPattern }
316 315 }
317 316
318 317
@@ -327,7 +326,7 @@ Pdrop : FilterPattern {
327 326 var inevent;
328 327 var stream = pattern.asStream;
329 328
330   - count.value.do {
  329 + count.value(event).do {
331 330 inevent = stream.next(event);
332 331 if (inevent.isNil, { ^event });
333 332 };
@@ -351,7 +350,7 @@ Pfin : FilterPattern {
351 350 var inevent;
352 351 var stream = pattern.asStream;
353 352 cleanup ?? { cleanup = EventStreamCleanup.new };
354   - count.value.do({
  353 + count.value(event).do({
355 354 inevent = stream.next(event) ?? { ^event };
356 355 cleanup.update(inevent);
357 356 event = inevent.yield;
@@ -364,13 +363,14 @@ Pfin : FilterPattern {
364 363
365 364 // it is not correct to call stream.next(nil) on a value stream
366 365 // but there is no good way to distinguish in Pfin so we need a subclass
  366 +// might be ok to deprecate this now
367 367
368 368 Pfinval : Pfin {
369 369 embedInStream { arg event;
370 370 var inevent;
371 371 var stream = pattern.asStream;
372 372
373   - count.value.do({
  373 + count.value(event).do({
374 374 inevent = stream.next(event);
375 375 if (inevent.isNil, { ^event });
376 376 event = inevent.yield;
@@ -388,19 +388,20 @@ Pfindur : FilterPattern {
388 388 asStream { | cleanup| ^Routine({ arg inval; this.embedInStream(inval, cleanup) }) }
389 389
390 390 embedInStream { arg event, cleanup;
391   - var item, delta, elapsed = 0.0, nextElapsed, inevent;
392   -
  391 + var item, delta, elapsed = 0.0, nextElapsed, inevent,
  392 + localdur = dur.value(event);
393 393 var stream = pattern.asStream;
  394 +
394 395 cleanup ?? { cleanup = EventStreamCleanup.new };
395 396 loop {
396 397 inevent = stream.next(event) ?? { ^event };
397 398 cleanup.update(inevent);
398 399 delta = inevent.delta;
399 400 nextElapsed = elapsed + delta;
400   - if (nextElapsed.roundUp(tolerance) >= dur) {
  401 + if (nextElapsed.roundUp(tolerance) >= localdur) {
401 402 // must always copy an event before altering it.
402 403 // fix delta time and yield to play the event.
403   - inevent = inevent.copy.put(\delta, dur - elapsed).yield;
  404 + inevent = inevent.copy.put(\delta, localdur - elapsed).yield;
404 405 ^cleanup.exit(inevent);
405 406 };
406 407
@@ -409,7 +410,6 @@ Pfindur : FilterPattern {
409 410
410 411 }
411 412 }
412   -
413 413 }
414 414
415 415 Psync : FilterPattern {
@@ -421,6 +421,7 @@ Psync : FilterPattern {
421 421
422 422 embedInStream { arg event;
423 423 var item, stream, delta, elapsed = 0.0, nextElapsed, clock, inevent;
  424 + var localquant = quant.value(event), localmaxdur = maxdur.value(event);
424 425 var cleanup = EventStreamCleanup.new;
425 426
426 427 stream = pattern.asStream;
@@ -428,8 +429,8 @@ Psync : FilterPattern {
428 429 loop {
429 430 inevent = stream.next(event);
430 431 if(inevent.isNil) {
431   - if(quant.notNil) {
432   - event = Event.silent(elapsed.roundUp(quant) - elapsed, event);
  432 + if(localquant.notNil) {
  433 + event = Event.silent(elapsed.roundUp(localquant) - elapsed, event);
433 434 ^cleanup.exit(event).yield;
434 435 };
435 436 };
@@ -438,20 +439,17 @@ Psync : FilterPattern {
438 439 delta = inevent.delta;
439 440 nextElapsed = elapsed + delta;
440 441
441   - if (maxdur.notNil and: { nextElapsed.round(tolerance) >= maxdur })
442   - {
  442 + if (localmaxdur.notNil and: { nextElapsed.round(tolerance) >= localmaxdur }) {
443 443 inevent = inevent.copy;
444   - inevent.put(\delta, maxdur - elapsed);
  444 + inevent.put(\delta, localmaxdur - elapsed);
445 445 event = inevent.yield;
446 446 ^cleanup.exit(event);
447   - }
448   - {
  447 + } {
449 448 elapsed = nextElapsed;
450 449 event = inevent.yield;
451 450 };
452 451 };
453 452 }
454   -
455 453 }
456 454
457 455
@@ -463,23 +461,23 @@ Pconst : FilterPattern {
463 461 storeArgs { ^[sum,pattern,tolerance] }
464 462
465 463 embedInStream { arg inval;
466   - var delta, elapsed = 0.0, nextElapsed, str=pattern.asStream,
467   - localSum = sum.value(inval);
468   - loop ({
469   - delta = str.next(inval);
470   - if(delta.isNil) {
471   - (localSum - elapsed).yield;
472   - ^inval
473   - };
474   - nextElapsed = elapsed + delta;
475   - if (nextElapsed.round(tolerance) >= localSum) {
476   - (localSum - elapsed).yield;
477   - ^inval
478   - }{
479   - elapsed = nextElapsed;
480   - inval = delta.yield;
481   - };
482   - });
  464 + var delta, elapsed = 0.0, nextElapsed, str=pattern.asStream,
  465 + localSum = sum.value(inval);
  466 + loop ({
  467 + delta = str.next(inval);
  468 + if(delta.isNil) {
  469 + (localSum - elapsed).yield;
  470 + ^inval
  471 + };
  472 + nextElapsed = elapsed + delta;
  473 + if (nextElapsed.round(tolerance) >= localSum) {
  474 + (localSum - elapsed).yield;
  475 + ^inval
  476 + }{
  477 + elapsed = nextElapsed;
  478 + inval = delta.yield;
  479 + };
  480 + });
483 481 }
484 482 }
485 483
@@ -494,9 +492,8 @@ Plag : FilterPattern {
494 492 var stream = pattern.asStream;
495 493 var inevent = event.copy;
496 494
497   - inevent.put('freq', \rest);
498   - inevent.put('dur', lag);
499   - event = inevent.yield;
  495 + event = Event.silent(lag.value(event), event).yield;
  496 +
500 497 loop {
501 498 inevent = stream.next(event);
502 499 if (inevent.isNil) { ^event};
@@ -622,7 +619,6 @@ Pclutch : FilterPattern {
622 619 clutch = clutchStream.next(inval);
623 620 clutch.notNil
624 621 } {
625   -
626 622 if(clutch === true or: { clutch == 1 }) {
627 623 outval = stream.next(inval);
628 624 if(outval.isNil) { ^inval };
@@ -631,15 +627,13 @@ Pclutch : FilterPattern {
631 627 outval ?? { outval = stream.next(inval) };
632 628 inval = outval.copy.yield;
633 629 };
634   -
635   -
636 630 }
637 631 }
638 632 }
639 633
640 634 Pwhile : FuncFilterPattern {
641 635 embedInStream {arg event;
642   - while({ func.value },{
  636 + while({ func.value(event) },{
643 637 event = pattern.embedInStream(event);
644 638 });
645 639 ^event;
@@ -702,9 +696,7 @@ Ptrace : FilterPattern {
702 696 }
703 697 };
704 698 ^collected.embedInStream(inval)
705   -
706 699 }
707   -
708 700 }
709 701
710 702 Pclump : FilterPattern {
@@ -759,7 +751,6 @@ Pdiff : FilterPattern {
759 751 embedInStream { arg event;
760 752 var stream = pattern.asStream;
761 753 var next, prev = stream.next(event);
762   - //prev !? { prev.yield };
763 754 while {
764 755 next = stream.next(event);
765 756 next.notNil;
@@ -829,9 +820,5 @@ Pavaroh : FilterPattern {
829 820 inval = me.degreeToKey(scale, stepVal).yield
830 821 };
831 822 ^inval
832   -
833 823 }
834   -
835 824 }
836   -
837   -
8 common/build/SCClassLibrary/Common/Streams/FuncStreamAsRoutine.sc
@@ -3,8 +3,12 @@ FuncStreamAsRoutine : Routine {
3 3 var <>resetFunc;
4 4
5 5 *new { arg nextFunc, resetFunc;
6   - ^super.new({arg inval; loop { inval = yield(thisThread.nextFunc.value(inval)) } })
7   - .nextFunc_(nextFunc).resetFunc_(resetFunc)
  6 + ^super.new({ arg inval;
  7 + loop {
  8 + inval = yield(thisThread.nextFunc.value(inval))
  9 + }
  10 + })
  11 + .nextFunc_(nextFunc).resetFunc_(resetFunc)
8 12 }
9 13
10 14 reset { ^resetFunc.value }
138 common/build/SCClassLibrary/Common/Streams/ListPatterns.sc
@@ -7,7 +7,7 @@ Pindex : Pattern {
7 7 embedInStream { arg inval;
8 8 var indexStream, index, item, itemCount;
9 9 var listStream = listPat.asStream;
10   - repeats.do {
  10 + repeats.value(inval).do {
11 11 var list = listStream.next(inval);
12 12 if (list.isNil) { ^inval };
13 13 indexStream = indexPat.asStream;
@@ -52,14 +52,14 @@ Pseq : ListPattern {
52 52 var item, offsetValue;
53 53 offsetValue = offset.value;
54 54 if (inval.eventAt('reverse') == true, {
55   - repeats.value.do({ arg j;
  55 + repeats.value(inval).do({ arg j;
56 56 list.size.reverseDo({ arg i;
57 57 item = list.wrapAt(i + offsetValue);
58 58 inval = item.embedInStream(inval);
59 59 });
60 60 });
61 61 },{
62   - repeats.value.do({ arg j;
  62 + repeats.value(inval).do({ arg j;
63 63 list.size.do({ arg i;
64 64 item = list.wrapAt(i + offsetValue);
65 65 inval = item.embedInStream(inval);
@@ -76,12 +76,12 @@ Pser : Pseq {
76 76 var item;
77 77 var offsetValue = offset.value;
78 78 if (inval.eventAt('reverse') == true, {
79   - repeats.value.reverseDo({ arg i;
  79 + repeats.value(inval).reverseDo({ arg i;
80 80 item = list.wrapAt(i + offsetValue);
81 81 inval = item.embedInStream(inval);
82 82 });
83 83 },{
84   - repeats.value.do({ arg i;
  84 + repeats.value(inval).do({ arg i;
85 85 item = list.wrapAt(i + offsetValue);
86 86 inval = item.embedInStream(inval);
87 87 });
@@ -93,9 +93,9 @@ Pser : Pseq {
93 93 Pshuf : ListPattern {
94 94 embedInStream { arg inval;
95 95 var item, stream;
96   -
97 96 var localList = list.copy.scramble;
98   - repeats.value.do({ arg j;
  97 +
  98 + repeats.value(inval).do({ arg j;
99 99 localList.size.do({ arg i;
100 100 item = localList.wrapAt(i);
101 101 inval = item.embedInStream(inval);
@@ -109,7 +109,7 @@ Prand : ListPattern {
109 109 embedInStream { arg inval;
110 110 var item;
111 111
112   - repeats.value.do({ arg i;
  112 + repeats.value(inval).do({ arg i;
113 113 item = list.at(list.size.rand);
114 114 inval = item.embedInStream(inval);
115 115 });
@@ -121,7 +121,7 @@ Pxrand : ListPattern {
121 121 embedInStream { arg inval;
122 122 var item, size;
123 123 var index = list.size.rand;
124   - repeats.value.do({ arg i;
  124 + repeats.value(inval).do({ arg i;
125 125 size = list.size;
126 126 index = (index + (size - 1).rand + 1) % size;
127 127 item = list.at(index);
@@ -139,7 +139,7 @@ Pwrand : ListPattern {
139 139 embedInStream { arg inval;
140 140 var item, wVal;
141 141 var wStr = weights.asStream;
142   - repeats.value.do({ arg i;
  142 + repeats.value(inval).do({ arg i;
143 143 wVal = wStr.next(inval);
144 144 if(wVal.isNil) { ^inval };
145 145 item = list.at(wVal.windex);
@@ -155,7 +155,7 @@ Pfsm : ListPattern {
155 155 embedInStream { arg inval;
156 156 var item, index=0;
157 157 var maxState = ((list.size - 1) div: 2) - 1;
158   - repeats.value.do({
  158 + repeats.value(inval).do({
159 159 index = 0;
160 160 while({
161 161 index = list.at(index).choose.clip(0, maxState) * 2 + 2;
@@ -170,14 +170,16 @@ Pfsm : ListPattern {
170 170 }
171 171
172 172 Pdfsm : ListPattern {
173   - var >startState;
  173 + var <>startState;
174 174 *new { arg list, startState=0, repeats=1;
175   - ^super.new( list, repeats ).startState_(startState) }
  175 + ^super.new( list, repeats ).startState_(startState)
  176 + }
  177 +
176 178 embedInStream { arg inval;
177 179 var currState, sigStream;
178 180 var sig, state, stream;
179 181 var numStates = list.size - 1;
180   - repeats.value.do({
  182 + repeats.value(inval).do({
181 183
182 184 currState = startState;
183 185 sigStream = list[0].asStream;
@@ -223,9 +225,9 @@ Pswitch : Pattern {
223 225 Pswitch1 : Pswitch {
224 226 embedInStream { arg inval;
225 227 var index, outval;
226   -
227 228 var streamList = list.collect({ arg pattern; pattern.asStream; });
228 229 var indexStream = which.asStream;
  230 +
229 231 loop {
230 232 if ((index = indexStream.next(inval)).isNil) { ^inval };
231 233 outval = streamList.wrapAt(index.asInteger).next(inval);
@@ -235,35 +237,11 @@ Pswitch1 : Pswitch {
235 237 }
236 238 }
237 239
238   -//Pswitch1 : Pattern {
239   -// var <>list, <>which=0;
240   -// *new { arg list, which=0;
241   -// ^super.new.list_(list).which_(which)
242   -// }
243   -//
244   -// asStream {
245   -// var streamList, indexStream;
246   -//
247   -// streamList = list.collect({ arg pattern; pattern.asStream; });
248   -// indexStream = which.asStream;
249   -//
250   -// ^FuncStream.new({ arg inval;
251   -// var index;
252   -// if ((index = indexStream.next).notNil, {
253   -// streamList.wrapAt(index.asInteger).next(inval);
254   -// });
255   -// },{
256   -// streamList.do({ arg stream; stream.reset; });
257   -// });
258   -// }
259   -// storeArgs { ^[ list, which ] }
260   -//}
261   -
262 240 Ptuple : ListPattern {
263 241 embedInStream { arg inval;
264 242 var item, streams, tuple, outval;
265 243
266   - repeats.value.do({ arg j;
  244 + repeats.value(inval).do({ arg j;
267 245 var sawNil = false;
268 246 streams = list.collect({ arg item; item.asStream });
269 247
@@ -286,10 +264,10 @@ Ptuple : ListPattern {
286 264 Place : Pseq {
287 265 embedInStream { arg inval;
288 266 var item;
289   -
290 267 var offsetValue = offset.value;
  268 +
291 269 if (inval.eventAt('reverse') == true, {
292   - repeats.value.do({ arg j;
  270 + repeats.value(inval).do({ arg j;
293 271 list.size.reverseDo({ arg i;
294 272 item = list.wrapAt(i + offsetValue);
295 273 if (item.isSequenceableCollection, {
@@ -299,7 +277,7 @@ Place : Pseq {
299 277 });
300 278 });
301 279 },{
302   - repeats.value.do({ arg j;
  280 + repeats.value(inval).do({ arg j;
303 281 list.size.do({ arg i;
304 282 item = list.wrapAt(i + offsetValue);
305 283 if (item.isSequenceableCollection, {
@@ -319,24 +297,26 @@ Ppatlace : Pseq {
319 297 var consecutiveNils = 0, index, repeat, item;
320 298 var streamList = list.collect({ |item| item.asStream });
321 299 var offsetValue = offset.value;
  300 + var localRepeats = repeats.value(inval);
  301 +
322 302 index = repeat = 0;
323   - { (repeat < repeats) and: { consecutiveNils < list.size } }.while({
324   - (inval.eventAt(\reverse) == true).if({
  303 + while { (repeat < localRepeats) and: { consecutiveNils < list.size } } {
  304 + if(inval.eventAt(\reverse) == true) {
325 305 item = streamList.wrapAt(offsetValue - index - 1);
326   - }, {
  306 + } {
327 307 item = streamList.wrapAt(offsetValue + index);
328   - });
329   - (item = item.next(inval)).notNil.if({
  308 + };
  309 + if((item = item.next(inval)).notNil) {
330 310 consecutiveNils = 0;
331 311 inval = item.embedInStream(inval);
332   - }, {
  312 + } {
333 313 consecutiveNils = consecutiveNils + 1;
334   - });
335   - ((index = index + 1) == list.size).if({
  314 + };
  315 + if((index = index + 1) == list.size) {
336 316 index = 0;
337 317 repeat = repeat + 1;
338   - });
339   - });
  318 + };
  319 + };
340 320 ^inval;
341 321 }
342 322 }
@@ -355,33 +335,33 @@ Pslide : ListPattern {
355 335 .wrapAtEnd_(wrapAtEnd);
356 336 }
357 337 embedInStream { arg inval;
358   - var item;
359   - var pos = start;
360   - var stepStr = step.asStream, stepVal;
361   - var lenghtStr = len.asStream, lengthVal;
362   -
363   - repeats.value.do {
364   - lengthVal = lenghtStr.next(inval);
365   - if(lengthVal.isNil) { ^inval };
366   - if(wrapAtEnd) {
367   - lengthVal.do { |j|
368   - item = list.wrapAt(pos + j);
  338 + var item;
  339 + var pos = start;
  340 + var stepStr = step.asStream, stepVal;
  341 + var lengthStr = len.asStream, lengthVal;
  342 +
  343 + repeats.value(inval).do {
  344 + lengthVal = lengthStr.next(inval);
  345 + if(lengthVal.isNil) { ^inval };
  346 + if(wrapAtEnd) {
  347 + lengthVal.do { |j|
  348 + item = list.wrapAt(pos + j);
  349 + inval = item.embedInStream(inval);
  350 + }
  351 +
  352 + } {
  353 + lengthVal.do { |j|
  354 + item = list.at(pos + j);
  355 + if(item.notNil) {
369 356 inval = item.embedInStream(inval);
370   - }
371   -
372   - } {
373   - lengthVal.do { |j|
374   - item = list.at(pos + j);
375   - if(item.notNil) {
376   - inval = item.embedInStream(inval);
377   - } {
378   - ^inval
379   - };
380   - }
381   - };
382   - stepVal = stepStr.next(inval);
383   - if(stepVal.isNil) { ^inval };
384   - pos = pos + stepVal;
  357 + } {
  358 + ^inval
  359 + };
  360 + }
  361 + };
  362 + stepVal = stepStr.next(inval);
  363 + if(stepVal.isNil) { ^inval };
  364 + pos = pos + stepVal;
385 365 };
386 366
387 367 ^inval;
78 common/build/SCClassLibrary/Common/Streams/Patterns.sc
@@ -93,10 +93,8 @@ Pfunc : Pattern {
93 93 }
94 94 storeArgs { ^[nextFunc] ++ resetFunc }
95 95 asStream {
96   -// ^FuncStreamAsRoutine.new(nextFunc, resetFunc)
97   - ^FuncStream.new(nextFunc, resetFunc)
  96 + ^FuncStream.new(nextFunc, resetFunc)
98 97 }
99   -// embedInStream { arg inval; loop { inval = yield(nextFunc.value(inval)) } }
100 98 }
101 99
102 100 Prout : Pattern {
@@ -125,7 +123,7 @@ Pfuncn : Pattern {
125 123 }
126 124 storeArgs { ^[func,repeats] }
127 125 embedInStream { arg inval;
128   - repeats.value.do({
  126 + repeats.value(inval).do({
129 127 inval = func.value(inval).yield;
130 128 });
131 129 ^inval
@@ -153,8 +151,7 @@ Punop : Pattern {
153 151 }
154 152
155 153 asStream {
156   - var stream = a.asStream;
157   - ^UnaryOpStream.new(operator, stream);
  154 + ^UnaryOpStream.new(operator, a.asStream);
158 155 }
159 156 }
160 157
@@ -171,13 +168,11 @@ Pbinop : Pattern {
171 168 }
172 169
173 170 asStream {
174   - var streamA = a.asStream;
175   - var streamB = b.asStream;
176 171 if (adverb.isNil) {
177   - ^BinaryOpStream.new(operator, streamA, streamB);
  172 + ^BinaryOpStream.new(operator, a.asStream, b.asStream);
178 173 };
179 174 if (adverb == 'x') {
180   - ^BinaryOpXStream.new(operator, streamA, streamB);
  175 + ^BinaryOpXStream.new(operator, a.asStream, b.asStream);
181 176 };
182 177 ^nil
183 178 }
@@ -193,8 +188,10 @@ Pnaryop : Pattern {
193 188 embedInStream { arg inval;
194 189 var streamA, streamlist, vala, values, isNumeric;
195 190 streamA = a.asStream;
  191 + // optimization
196 192 isNumeric = arglist.every { arg item;
197   - item.isNumber or: {item.class === Symbol} }; // optimization
  193 + item.isNumber or: {item.class === Symbol}
  194 + };
198 195
199 196 if (isNumeric) {
200 197 loop {
@@ -218,9 +215,7 @@ Pnaryop : Pattern {
218 215 }
219 216
220 217 asStream {
221   - var streamA = a.asStream;
222   - var streamlist = arglist.collect({ arg item; item.asStream });
223   - ^NAryOpStream.new(operator, streamA, streamlist);
  218 + ^NAryOpStream.new(operator, a.asStream, arglist.collect({ arg item; item.asStream }));
224 219 }
225 220 }
226 221
@@ -361,8 +356,8 @@ Pseries : Pattern { // arithmetic series
361 356
362 357 embedInStream { arg inval;
363 358 var outval, counter = 0;
364   - var cur = start.value;
365   - var len = length.value;
  359 + var cur = start.value(inval);
  360 + var len = length.value(inval);
366 361 var stepStr = step.asStream, stepVal;
367 362 while { counter < len } {
368 363 stepVal = stepStr.next(inval);
@@ -384,8 +379,8 @@ Pgeom : Pattern { // geometric series
384 379 storeArgs { ^[start,grow,length] }
385 380 embedInStream { arg inval;
386 381 var outval, counter = 0;
387   - var cur = start.value;
388   - var len = length.value;
  382 + var cur = start.value(inval);
  383 + var len = length.value(inval);
389 384 var growStr = grow.asStream, growVal;
390 385
391 386 while { counter < len } {
@@ -422,7 +417,7 @@ Pbrown : Pattern {
422 417 cur = rrand(loVal, hiVal);
423 418 if(loVal.isNil or: { hiVal.isNil } or: { stepVal.isNil }) { ^inval };
424 419
425   - length.value.do {
  420 + length.value(inval).do {
426 421 loVal = loStr.next(inval);
427 422 hiVal = hiStr.next(inval);
428 423 stepVal = stepStr.next(inval);
@@ -455,7 +450,7 @@ Pwhite : Pattern {
455 450 var loStr = lo.asStream;
456 451 var hiStr = hi.asStream;
457 452 var hiVal, loVal;
458   - length.value.do({
  453 + length.value(inval).do({
459 454 hiVal = hiStr.next(inval);
460 455 loVal = loStr.next(inval);
461 456 if(hiVal.isNil or: { loVal.isNil }) { ^inval };
@@ -485,12 +480,12 @@ Pprob : Pattern {
485 480 var hiStr = hi.asStream;
486 481 var hiVal, loVal;
487 482
488   - length.value.do {
  483 + length.value(inval).do {
489 484 loVal = loStr.next(inval);
490 485 hiVal = hiStr.next(inval);
491 486 if(hiVal.isNil or: { loVal.isNil }) { ^inval };
492   - inval = ((table.tableRand * (hiVal - loVal)) + loVal).yield; };
493   -
  487 + inval = ((table.tableRand * (hiVal - loVal)) + loVal).yield;
  488 + };
494 489 ^inval;
495 490 }
496 491 }
@@ -562,19 +557,20 @@ PstepNfunc : Pattern {
562 557 var max = size - 1;
563 558 var streams = Array.newClear(size);
564 559 var vals = Array.newClear(size);
  560 + // this variable is needed because of recursion
565 561 var f = { arg inval, level=0;
566   - var val;
567   - streams[level] = patterns[level].asStream;
568   - while{
569   - vals[level] = val = streams[level].next(inval);
570   - val.notNil;
  562 + var val;
  563 + streams[level] = patterns[level].asStream;
  564 + while{
  565 + vals[level] = val = streams[level].next(inval);
  566 + val.notNil;
  567 + }{
  568 + if(level < max) {
  569 + inval = f.value(inval, level + 1)
571 570 }{
572   - if(level < max) {
573   - inval = f.value(inval, level + 1)
574   - }{
575   - inval = yield(function.value(vals));
576   - }
577   - };
  571 + inval = yield(function.value(vals));
  572 + }
  573 + };
578 574 inval;
579 575 };
580 576 ^f.value(inval);
@@ -599,7 +595,7 @@ Ptime : Pattern {
599 595 storeArgs { ^[repeats] }
600 596 embedInStream { arg inval;
601 597 var start = thisThread.beats;
602   - repeats.value.do { inval = (thisThread.beats - start).yield };
  598 + repeats.value(inval).do { inval = (thisThread.beats - start).yield };
603 599 ^inval
604 600 }
605 601 }
@@ -653,15 +649,15 @@ Pif : Pattern {
653 649
654 650 ^FuncStream({ |inval|
655 651 var test;
656   - (test = condStream.next(inval)).isNil.if({
  652 + if((test = condStream.next(inval)).isNil) {
657 653 nil
658   - }, {
659   - test.if({
  654 + } {
  655 + if(test) {
660 656 trueStream.next(inval) ? default
661   - }, {
  657 + } {
662 658 falseStream.next(inval) ? default
663   - });
664   - });
  659 + };
  660 + };
665 661 }, { // reset func
666 662 condStream.reset;
667 663 trueStream.reset;
3  common/build/SCClassLibrary/Common/Streams/Penv.sc
... ... @@ -1,6 +1,5 @@
1 1
2 2 Penv : Env {
3   -
4 3 embedInStream { arg inval;
5 4 var startTime;
6 5 startTime = thisThread.endBeat ? thisThread.beats;
@@ -10,6 +9,4 @@ Penv : Env {
10 9 { inval = yield(this.at(thisThread.beats - startTime))};
11 10 ^inval
12 11 }
13   -
14   -
15 12 }
20 common/build/SCClassLibrary/Common/Streams/Pfx.sc
@@ -67,8 +67,6 @@ Pfx : FilterPattern {
67 67 }
68 68 }
69 69 }
70   -
71   -
72 70 }
73 71
74 72 Pfxb : Pfx {
@@ -104,9 +102,8 @@ Pgroup : FilterPattern {
104 102 inevent = event.yield;
105 103
106 104 inevent !? { inevent = inevent.copy; inevent[\group] = ingroup };
107   -// ^this.class.embedLoop(inevent, pattern.asStream, groupID, ingroup, cleanup);
108 105 stream = pattern.asStream;
109   - loop {
  106 + loop {
110 107 event = stream.next(inevent) ?? { ^cleanup.exit(inevent) };
111 108 lag = max(lag, clock.beats + event.use { ~sustain.value });
112 109 inevent = event.yield;
@@ -117,13 +114,12 @@ Pgroup : FilterPattern {
117 114 *embedLoop { arg inevent, stream, groupID, ingroup, cleanup;
118 115 var event, lag;
119 116 loop {
120   - event = stream.next(inevent) ?? { ^cleanup.exit(inevent) }; lag = event[\dur];
  117 + event = stream.next(inevent) ?? { ^cleanup.exit(inevent) };
  118 + lag = event[\dur];
121 119 inevent = event.yield;
122 120 inevent.put(\group, groupID);
123 121 }
124 122 }
125   -
126   -
127 123 }
128 124
129 125 Pbus : FilterPattern {
@@ -187,26 +183,16 @@ Pbus : FilterPattern {
187 183 // doneAction = 3;
188 184 // remove and deallocate both this synth and the preceeding node
189 185 // (which is the group).
190   -
191 186 inevent = event.yield;
192 187
193 188
194 189 // now embed the pattern
195   -
196 190 stream = Pchain(pattern, (group: groupID, out: bus)).asStream;
197   -
198   -
199 191 loop {
200   -
201   -
202 192 event = stream.next(inevent) ?? { ^cleanup.exit(inevent) };
203 193 cleanup.update(event);
204 194 inevent = event.yield;
205   -
206   -
207 195 }
208 196 }
209   -
210   -
211 197 }
212 198
2  common/build/SCClassLibrary/Common/Streams/Plambda.sc
@@ -75,7 +75,7 @@ Pget : Pattern {
75 75 embedInStream { arg inval;
76 76 var scope = inval[\eventScope], outval;
77 77 if(scope.isNil) { Error("no scope defined in event").throw };
78   - repeats.value.do {
  78 + repeats.value(inval).do {
79 79 outval = scope[key] ? default;
80 80 if(outval.isNil) { ^inval };
81 81 outval.yield
11 common/build/SCClassLibrary/Common/Streams/PmonoStreams.sc
@@ -66,13 +66,13 @@ PmonoStream : Stream {
66 66 server = argServer;
67 67 schedBundleArray = ~schedBundleArray;
68 68 schedBundle = ~schedBundle;
69   -
70 69 };
71 70 cleanup.addFunction(event, currentCleanupFunc = { | flag |
72 71 if (flag) { (id: id, server: server, type: \off,
73   - hasGate: hasGate,
74   - schedBundleArray: schedBundleArray,
75   - schedBundle: schedBundle).play }
  72 + hasGate: hasGate,
  73 + schedBundleArray: schedBundleArray,
  74 + schedBundle: schedBundle).play
  75 + }
76 76 });
77 77 }
78 78 };
@@ -133,5 +133,4 @@ PmonoArticStream : PmonoStream {
133 133 }
134 134 }
135 135 }
136   -
137   -}
  136 +}
68 common/build/SCClassLibrary/Common/Streams/Ppar.sc
@@ -11,44 +11,32 @@ Ppar : ListPattern {
11 11 var assn;
12 12 var priorityQ = PriorityQueue.new;
13 13
14   - repeats.value.do({ arg j;
  14 + repeats.value(inval).do({ arg j;
15 15 var outval, stream, nexttime, now = 0.0;
16 16
17 17 this.initStreams(priorityQ);
18 18
19 19 // if first event not at time zero
20   - if (priorityQ.notEmpty and: { (nexttime = priorityQ.topPriority) > 0.0 }, {
21   -// outval = inval.copy;
22   -// outval.put(\freq, \rest);
23   -// outval.put(\delta, nexttime);
24   -
  20 + if (priorityQ.notEmpty and: { (nexttime = priorityQ.topPriority) > 0.0 }) {
25 21 outval = Event.silent(nexttime, inval);
26 22 inval = outval.yield;
27 23 now = nexttime;
28   - });
29   -
30   - //inval ?? { this.purgeQueue(priorityQ); ^nil.yield };
  24 + };
31 25
32   - while({
33   - priorityQ.notEmpty
34   - },{
  26 + while { priorityQ.notEmpty } {
35 27 stream = priorityQ.pop;
36 28 outval = stream.next(inval);
37   - if (outval.isNil, {
  29 + if (outval.isNil) {
38 30 nexttime = priorityQ.topPriority;
39 31 if (nexttime.notNil, {
40 32 // that child stream ended, so rest until next one
41   -// outval = inval.copy;
42   -// outval.put(\freq, \rest);
43   -// outval.put(\delta, nexttime - now);
44 33 outval = Event.silent(nexttime - now, inval);
45 34 inval = outval.yield;
46   - // inval ?? { this.purgeQueue(priorityQ); ^nil.yield };
47 35 now = nexttime;
48 36 },{
49 37 priorityQ.clear;
50 38 });
51   - },{
  39 + } {
52 40 // requeue stream
53 41 priorityQ.put(now + outval.delta, stream);
54 42 nexttime = priorityQ.topPriority;
@@ -57,17 +45,11 @@ Ppar : ListPattern {
57 45 inval = outval.yield;
58 46 // inval ?? { this.purgeQueue(priorityQ); ^nil.yield };
59 47 now = nexttime;
60   - });
61   - });
  48 + };
  49 + };
62 50 });
63 51 ^inval;
64 52 }
65   -
66   - /*
67   - purgeQueue { arg priorityQ;
68   - while { priorityQ.notEmpty } { priorityQ.pop }
69   - }*/
70   -
71 53 }
72 54
73 55 Ptpar : Ppar {
@@ -78,34 +60,8 @@ Ptpar : Ppar {
78 60 }
79 61 }
80 62
81   -//Ppar : ListPattern {
82   -// initStreams { arg priorityQ;
83   -// list.do({ arg pattern, i;
84   -// priorityQ.put(0.0, pattern.asStream);
85   -// });
86   -// }
87   -// asStream {
88   -// ^Routine({ arg inval;
89   -// var count = 0, join, cond;
90   -// join = list.size;
91   -// cond = Condition({ count >= join });
92   -// list.do({ arg func;
93   -// Routine({ arg time;
94   -// inval.
95   -// pattern.embedInStream(inval.copy);
96   -// count = count + 1;
97   -// cond.signal;
98   -// }).play;
99   -// });
100   -// cond.wait;
101   -// });
102   -// }
103   -//}
104   -
105   -
106 63
107 64 Pgpar : Ppar {
108   -
109 65 embedInStream { arg inevent;
110 66 var server, ids, patterns, event, ingroup, cleanup, stream;
111 67 var lag = 0, clock = thisThread.clock,
@@ -125,8 +81,11 @@ Pgpar : Ppar {
125 81 inevent = event.yield.copy;
126 82 cleanup = EventStreamCleanup.new;
127 83 cleanup.addFunction(inevent, { | flag |
128   - if (flag) { ( lag: lag - clock.beats + groupReleaseTime,
129   - type: \kill, id: ids, server: server).play };
  84 + if (flag) {
  85 + ( lag: lag - clock.beats + groupReleaseTime,