Skip to content

Instantly share code, notes, and snippets.

@munshkr
Created June 16, 2017 23:41
Show Gist options
  • Save munshkr/d65d7e7e5624f305a2301cd6b12566d6 to your computer and use it in GitHub Desktop.
Save munshkr/d65d7e7e5624f305a2301cd6b12566d6 to your computer and use it in GitHub Desktop.
Pdefc / Pbindefc / Pkeyc classes
// Same as Pdef, but it collects last event on global `allEvents` dictionary
Pdefc : Pdef {
classvar <>allEvents;
*initClass {
allEvents = IdentityDictionary.new;
}
*new { arg key, item;
// Replace Pbind source for a Pcollect that stores
// currently played event on allEvents dictionary.
item = item.collect { |e|
allEvents.put(key, e);
e
}
^super.new(key, item)
}
}
// Same as Pbindef, but it collects last event on Pdef.allEvents dictionary
Pbindefc : Pbindef {
*new { arg key ... pairs;
var pat, pbind;
pat = super.new(key, *pairs);
pbind = pat.source.source;
// Do the same thing as in Pdefc.new
pbind.source = pbind.source.collect { |e|
Pdefc.allEvents.put(key, e);
e
};
^pat
}
}
// Same as Pkey, but it accepts a Pdefc/Pbindefc key as first argument
Pkeyc : Pattern {
var <>defKey, <>key;
*new { arg defKey, key;
^super.newCopyArgs(defKey, key)
}
storeArgs { ^[key] }
asStream {
^FuncStream({ this.currentEvent[key] })
}
currentEvent {
var dict;
dict = Pdefc.allEvents[defKey];
dict.isNil.if{dict = ()};
^dict
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment