Skip to content

Instantly share code, notes, and snippets.

@scztt
Created July 9, 2019 19:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scztt/c96bb31aad6d1b8ca8cc0b0881612422 to your computer and use it in GitHub Desktop.
Save scztt/c96bb31aad6d1b8ca8cc0b0881612422 to your computer and use it in GitHub Desktop.
PtimeClutch
// Only pull a value once per clock time - else, return the previous value
PtimeClutch : FilterPattern {
var <>delta;
*new {
|pattern, delta=0.0|
^super.new(pattern).delta_(delta);
}
embedInStream {
|input|
var lastTime, lastVal;
var stream = pattern.asStream;
loop {
var thisTime = thisThread.beats;
if (lastTime.isNil or: { (thisTime - lastTime) > delta }) {
lastVal = stream.next(input);
lastTime = thisTime;
};
input = lastVal.copy.yield;
}
}
}
+Pattern {
timeClutch {
|delta=0.0|
^PtimeClutch(this, delta)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment