remove a crufty folder that's done nothing for quite a while...
[supercollider.git] / build / SCClassLibrary / JITLib / Patterns / Psym.sc
blobf50b0314c4143c57a987e2ff0c1401b1887c8571
1 Psym : FilterPattern {
2         var <>dict;
3         
4         *new { arg pattern, dict;
5                 ^super.new(pattern).dict_(dict)
6         }
7         storeArgs { ^[pattern,dict] }
8         
9         lookupClass { ^Pdef }
10         lookUp { arg key;
11                 ^(dict ?? { this.lookupClass.all }).at(key) ?? { this.lookupClass.default }
12         }
13         
14         embedInStream { arg inval;
15                 var str, outval, pat;
16                 str = pattern.asStream;
17                 while {
18                         outval = str.next(inval);
19                         outval.notNil
20                 } {
21                         
22                         pat = this.getPattern(outval);
23                         inval = pat.embedInStream(inval);
24                 };
25                 ^inval
26         
27         }
28         
29         getPattern { arg key;
30                 ^if(key.isSequenceableCollection) {
31                         this.lookupClass.parallelise(
32                                 key.collect {|each|
33                                         this.lookUp(each.asSymbol)
34                                 }
35                         );
36                 } {
37                         this.lookUp(key.asSymbol)
38                 };
39         }
40         
41         
42         
45 Pnsym : Psym {
46         lookupClass { ^Pdefn }
50 Ptsym : Psym {
51         var <>quant, <>dur, <>tolerance;
52         
53         *new { arg pattern, dict, quant, dur, tolerance = 0.001;
54                 ^super.newCopyArgs(pattern, dict, quant, dur, tolerance)
55         }
56         storeArgs { ^[ pattern, dict, quant, dur, tolerance ] }
57         embedInStream { arg inval;
58                 var str, outval, pat, quantVal, quantStr, durVal, durStr;
59                 str = pattern.asStream;
60                 quantStr = quant.asStream;
61                 durStr = dur.asStream;
62                 
63                 while {
64                         outval = str.next(inval);
65                         quantVal = quantStr.next(inval) ? quantVal;
66                         durVal = durStr.next(inval) ? durVal;
67                         outval.notNil
68                 } {
69                         pat = Psync(this.getPattern(outval), quantVal, durVal, tolerance);
70                         inval = pat.embedInStream(inval);
71                 };
72                 ^inval
73         
74         }
77 Pnsym1 : Pnsym {
78         embedInStream { arg inval;
79                 var str, which, streams, outval, pat, currentStream;
80                 str = pattern.asStream;
81                 streams = IdentityDictionary.new;
82                 while {
83                         which = str.next(inval);
84                         which.notNil
85                 } {
86                         pat = this.getPattern(which);
87                         currentStream = streams.at(pat);
88                         if(currentStream.isNil) {
89                                 currentStream = pat.asStream;
90                                 streams.put(pat, currentStream);
91                         };
92                         outval = currentStream.next(inval);
93                         outval ?? { ^inval };
94                         inval = outval.yield
95                 };
96                 ^inval
97         
98         }
101 Psym1 : Psym {
102         embedInStream { arg inval, cleanup;
103                 var str, which, streams, outval, pat, currentStream;
104                 str = pattern.asStream;
105                 streams = IdentityDictionary.new;
106                 cleanup ?? { cleanup = EventStreamCleanup.new };
107                 
108                 while {
109                         which = str.next(inval);
110                         which.notNil
111                 } {
112                         pat = this.getPattern(which);
113                         currentStream = streams.at(pat);
114                         if(currentStream.isNil) {
115                                 currentStream = pat.asStream;
116                                 streams.put(pat, currentStream);
117                         };
118                         outval = currentStream.next(inval);
119                         if(outval.isNil) { ^cleanup.exit(inval) };
120                         
121                         cleanup.update(outval);
122                         inval = outval.yield
123                 };
124                 
125                 ^cleanup.exit(inval);
126         }