class library: Volume - remove debug message
[supercollider.git] / SCClassLibrary / Common / Streams / Prewrite.sc
blob430413f2969579adfb0060d9a335e9945fe9b703
1 Prewrite : FilterPattern {
2         var <>dict, <>levels;
3         *new { arg pattern, dict, levels=1;
4                 ^super.new(pattern).dict_(dict).levels_(levels)
5         }
6         storeArgs { ^[ pattern, dict, levels ] }
7         rewriteList { arg list, inval, level;
8                 var newlist;
9                 if (level == 0, {
10                         // if at bottom level, then embed all items in the stream
11                         if (list.isSequenceableCollection, {
12                                 // isKindOf is necessary because Integer.do would do the wrong thing..
13                                 list.do({ arg item;
14                                         inval = item.embedInStream(inval);
15                                 });
16                         },{
17                                 inval = list.embedInStream(inval);
18                         });
19                 },{
20                         if (list.isSequenceableCollection, {
21                                 // isKindOf is necessary because Integer.do would do the wrong thing..
22                                 list.do({ arg item;
23                                         // lookup item in rewrite dictionary
24                                         newlist = dict.at(item);
26                                         // found an entry ?
27                                         if (newlist.notNil, {
28                                                 // do another level of rewriting
29                                                 inval = this.rewriteList( newlist, inval, level - 1 );
30                                         },{
31                                                 // has no dictionary entry, so embed in stream
32                                                 inval = item.embedInStream(inval);
33                                         });
34                                 });
35                         },{
36                                 // lookup item in rewrite dictionary
37                                 newlist = dict.at(list);
39                                 // found an entry ?
40                                 if (newlist.notNil, {
41                                         // do another level of rewriting
42                                         inval = this.rewriteList( newlist, inval, level - 1 );
43                                 },{
44                                         // has no dictionary entry, so embed in stream
45                                         inval = list.embedInStream(inval);
46                                 });
47                         });
48                 });
49                 ^inval;
50         }
51         embedInStream {  arg inval;
52                 var outval;
53                 var stream;
55                 stream = pattern.asStream;
56                 while({
57                         outval = stream.next(inval);
58                         outval.notNil;
59                 },{
60                         inval = this.rewriteList(outval, inval, levels);
61                 });
62                 ^inval
63         }