1 Plambda : FilterPattern {
4 *new { arg pattern, scope;
5 ^super.new(pattern).scope_(scope)
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);
16 inval = inval.copy ? ();
17 inval[\eventScope] = embedScope;
18 outval = stream.next(inval);
23 outval[\eventScope] = outval[\eventScope].eventAt(\parent);
30 ^if(scope.notNil) { [pattern, scope] } { [pattern] }
36 var <>pattern, <>key, <>return;
37 *new { arg key, pattern, return;
38 ^super.newCopyArgs(pattern, key, return)
41 embedInStream { arg inval;
42 var str = pattern.asStream, val, sval, outval, scope;
43 var returnStr = return.asStream, returnVal;
45 outval = str.next(inval);
46 returnVal = returnStr.next(inval);
49 scope = inval[\eventScope];
50 if(scope.isNil) { Error("no scope defined in event").throw };
52 // don't transmit scope
54 if(val.eventAt(\eventScope).notNil) { val[\eventScope] = nil };
57 inval = (returnVal ? outval).yield;
61 silent { return = Event.silent }
63 storeArgs { ^[key, pattern] ++ return }
69 var <>key, <>default, <>repeats;
71 *new { arg key, default, repeats = 1;
72 ^super.newCopyArgs(key, default, repeats)
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 };
88 if(repeats != 1) { ^[key, default, repeats] };
89 if(default.notNil) { ^[key, default] }