deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / Streams / Plambda.sc
blob72480dd6055261a0fcd67dd0efd076b75d5fc466
1 Plambda : FilterPattern {
2         var <>scope;
4         *new { arg pattern, scope;
5                 ^super.new(pattern).scope_(scope)
6         }
8         embedInStream { arg inval;
9                 var embedScope, stream, outval, parentScope;
11                 stream = pattern.asStream;
12                 inval !? { parentScope = inval[\eventScope] };
13                 embedScope = (scope.copy ? ()).parent_(parentScope);
15                 while {
16                         inval = inval.copy ? ();
17                         inval[\eventScope] = embedScope;
18                         outval = stream.next(inval);
19                         outval.notNil
20                 } {
21                         // return outer scope
22                         outval = outval.copy;
23                         outval[\eventScope] = outval[\eventScope].eventAt(\parent);
24                         inval = outval.yield
25                 };
27                 ^inval
28         }
29         storeArgs {
30                 ^if(scope.notNil) { [pattern, scope] } { [pattern] }
31         }
35 Plet : Pattern {
36         var <>pattern, <>key, <>return;
37         *new { arg key, pattern, return;
38                 ^super.newCopyArgs(pattern, key, return)
39         }
41         embedInStream { arg inval;
42                 var str = pattern.asStream, val, sval, outval, scope;
43                 var returnStr = return.asStream, returnVal;
44                 while {
45                         outval = str.next(inval);
46                         returnVal = returnStr.next(inval);
47                         outval.notNil
48                 } {
49                         scope = inval[\eventScope];
50                         if(scope.isNil) { Error("no scope defined in event").throw };
52                         // don't transmit scope
53                         val = outval.copy;
54                         if(val.eventAt(\eventScope).notNil) { val[\eventScope] = nil };
55                         scope[key] = val;
57                         inval = (returnVal ? outval).yield;
58                 }
59         }
61         silent { return = Event.silent }
63         storeArgs { ^[key, pattern] ++ return }
68 Pget : Pattern {
69         var <>key, <>default, <>repeats;
71         *new { arg key, default, repeats = 1;
72                 ^super.newCopyArgs(key, default, repeats)
73         }
75         embedInStream { arg inval;
76                         var scope = inval[\eventScope], outval;
77                         if(scope.isNil) { Error("no scope defined in event").throw };
78                         repeats.value(inval).do {
79                                 outval = scope[key] ? default;
80                                 if(outval.isNil) { ^inval };
81                                 outval.yield
82                         };
83                         ^inval
84         }
86         storeArgs {
87                 var list = [key];
88                 if(repeats != 1) { ^[key, default, repeats] };
89                 if(default.notNil) { ^[key, default] }
90                 ^[key]
91         }