Created
July 9, 2019 19:43
-
-
Save scztt/c96bb31aad6d1b8ca8cc0b0881612422 to your computer and use it in GitHub Desktop.
PtimeClutch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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