Skip to content

Instantly share code, notes, and snippets.

@iTerentius
Forked from scztt/PtimeClutch.sc
Created October 15, 2020 16:37
Show Gist options
  • Save iTerentius/6f25fcad1fab7260516bbee094b95866 to your computer and use it in GitHub Desktop.
Save iTerentius/6f25fcad1fab7260516bbee094b95866 to your computer and use it in GitHub Desktop.
// 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