class library: Volume - remove debug message
[supercollider.git] / SCClassLibrary / Common / Streams / BasicOpsStream.sc
blobe2913b00604fe0cdece8d4a2a69ca5bedcbb10fa
1 // These Streams are instantiated by math operations on other Streams
3 UnaryOpStream : Stream {
4         var >operator, >a;
6         *new { arg operator, a;
7                 ^super.newCopyArgs(operator, a)
8         }
9         next { arg inval;
10                 var vala;
11                 vala = a.next(inval);
12                 if (vala.isNil, { ^nil },{ ^vala.perform(operator); });
13         }
14         reset { a.reset }
15         storeOn { arg stream; stream <<< a << "." << operator }
19 BinaryOpStream : Stream {
20         var >operator, >a, >b;
22         *new { arg operator, a, b;
23                 ^super.newCopyArgs(operator, a, b)
24         }
25         next { arg inval;
26                 var vala, valb;
27                 vala = a.next(inval);
28                 if (vala.isNil, { ^nil });
29                 valb = b.next(inval);
30                 if (valb.isNil, { ^nil });
31                 ^vala.perform(operator, valb);
32         }
33         reset { a.reset; b.reset }
35         storeOn { arg stream;
36                         stream << "(" <<< a << " " << operator.asBinOpString << " " <<< b << ")"
37         }
41 BinaryOpXStream : Stream {
42         var operator, a, b, vala;
44         *new { arg operator, a, b;
45                 ^super.newCopyArgs(operator, a, b)
46         }
47         next { arg inval;
48                 var valb;
49                 if (vala.isNil) {
50                         vala = a.next(inval);
51                         if (vala.isNil) { ^nil };
52                         valb = b.next(inval);
53                         if (valb.isNil, { ^nil });
54                 }{
55                         valb = b.next(inval);
56                         if (valb.isNil) {
57                                 vala = a.next(inval);
58                                 if (vala.isNil) { ^nil };
59                                 b.reset;
60                                 valb = b.next(inval);
61                                 if (valb.isNil) { ^nil };
62                         };
63                 };
64                 ^vala.perform(operator, valb);
65         }
66         reset { vala = nil; a.reset; b.reset }
67         storeOn { arg stream;
68                         stream << "(" <<< a << " " << operator.asBinOpString;
69                         stream << ".x";
70                         stream << " " <<< b << ")"
71         }
76 NAryOpStream : Stream {
77         var >operator, >a, arglist;
78         var isNumeric;
80         *new { arg operator, a, arglist;
81                 ^super.newCopyArgs(operator, a).arglist_(arglist)
82         }
83         arglist_ { arg list;
84                 // optimization
85                 isNumeric = list.every({ arg item; item.isNumber or: {item.class === Symbol} });                arglist = list;
86         }
87         next { arg inval;
88                 var vala, values;
89                 vala = a.next(inval);
90                 if (vala.isNil, { ^nil });
91                 values = if (isNumeric) { arglist } {
92                                 arglist.collect({ arg item; var res;
93                                         res = item.next(inval);
94                                         if(res.isNil) { ^nil };
95                                         res
96                                 })
97                                 };
98                 ^vala.performList(operator, values);
99         }
100         reset { a.reset; arglist.do({ arg item; item.reset }) }
102         storeOn { arg stream; stream <<< a << "." << operator << "(" <<<* arglist << ")" }