Pattern Guide 06b: Time Based Patterns:
Filter:
Tutorials/A-Practical-Guide | Streams-Patterns-Events > A-Practical-Guide

Pattern Guide 06b: Time Based Patterns

Patterns using time as the basis for their evaluation

Time-based patterns

"Time-based patterns" here are value patterns that use time as part of their calculation. Event patterns are naturally time-driven when played on a clock. (Technically it's possible to request events from an event stream without running it in an EventStreamPlayer, but this is not typical usage.)

Most of these patterns work by remembering the clock's current time at the moment the pattern is embedded into a value stream. The time value used for calculation is, then, the clock's time at the moment of evaluation minus the starting time -- that is, the number of beats elapsed since the patterns started embedding. If the pattern is embedded several times, the starting time is also reset so that the pattern begins again from the beginning.

There is nothing to prevent using these patterns outside of a scheduling context. In these documents, that context would be an event pattern played on a clock, but streams made from these patterns can be used in scheduled routines or functions as well. Only a scheduling context can ensure precise timing of requests for values.

Ptime(repeats)
Returns the amount of time elapsed since embedding. One nice trick with this pattern is to stop a value stream/pattern after a certain amount of time.

This Pif pattern uses Ptime to get values from the true branch for exactly 4 beats after the first value is requested. After that, the condition will be false and Pif reverts to the false branch, which is nil. That causes the stream to stop. (This is like Pfindur for event patterns, but Pif/Ptime works for value patterns as well.)

Pstep(levels, durs, repeats)
Repeat a level value for its corresponding duration, then move to the next.
Pseg(levels, durs, curves, repeats)
Similar to Pstep, but interpolates to the next value instead of stepping abruptly at the end of the duration. Interpolation is linear by default, but any envelope segment curve can be used. levels, durs and curves should be patterns.

Using envelopes as patterns

Env supports the stream protocol: asStream turns an Env into a stream, and timed values can be obtained from it using next. The envelope stream returns the value the envelope would have at the elapsed time, in the same way .at(time) returns the envelope value at the specified time.

The releaseNode and loopNode envelope parameters do not take effect, because they are meaningful only when used in a Synth with a gated EnvGen.

When the envelope ends, the stream will hold the final level indefinitely. The Pif(Ptime(inf) < totalTime, Env(...)) trick can make it stop instead.

Previous: Pattern Guide 06a: Repetition Constraint Patterns

Next: Pattern Guide 06c: Composition of Patterns