Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / SCClassLibrary / Common / Streams / Rest.sc
blob4fc40404289da8cf40ba33da23645e085c174f40
1 Rest {
2         var <>dur = 1;
3         *new { |dur(1)|
4                 ^super.newCopyArgs(dur)
5         }
6         // for use by Pfunc and Pfuncn
7         *processRest { |inval|
8                 inval.put(\isRest, true);
9                 ^1
10         }
11         processRest { |inval|
12                 inval.put(\isRest, true);
13                 ^dur
14         }
15         // for use e.g. in ListPatterns
16         *embedInStream { |inval|
17                 ^this.processRest(inval).yield;  // the actual return value is the next inval
18         }
19         embedInStream { |inval|
20                 ^this.processRest(inval).yield;
21         }
22         *asStream {
23                 ^Routine({ |inval|
24                         loop {
25                                 inval = this.embedInStream(inval);
26                         }
27                 })
28         }
29         asStream {
30                 ^Routine({ |inval|
31                         loop {
32                                 inval = this.embedInStream(inval);
33                         }
34                 })
35         }
38 + Object {
39         processRest { ^this }
42 + Collection {
43         processRest { |inval|
44                 this.do(_.processRest(inval))
45         }
49 + SimpleNumber {
50         // Some patterns call .delta on the eventstream's yield value
51         // since a SimpleNumber is a valid rest, it must answer 'delta' with itself
52         delta {}
53         // but Ppar and several other patterns do "put(\delta, ...)"
54         // so they need to convert the simplenumber into a real rest event
55         asEvent { ^Event.silent(this) }
58 + Event {
59         asEvent {}
62 + Nil {
63         // Ppar etc. need stream.next(event).asEvent to be nil when the stream ends
64         asEvent {}