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