Tone.Pattern Playback Patterns in Tone.js
This article provides a clear guide to the playback patterns
supported by the Tone.Pattern class in Tone.js. It explains
how each pattern traverses an array of values—such as musical notes—to
help you build dynamic arpeggios, generative melodies, and structured
sequences in your web audio applications.
The Tone.Pattern class in Tone.js is designed to cycle
through an array of values using a specified playback mathematical
pattern. By default, it uses the "up" pattern, but you can
configure it with several other built-in pattern types to change how the
array is traversed.
Below are the supported playback patterns you can pass into the
pattern parameter of a Tone.Pattern
instance.
Standard Directional Patterns
"up": Cycles through the array in ascending order (from index0to the end of the array, then loops back to the start)."down": Cycles through the array in descending order (from the last index down to index0, then loops back to the end).
Bounce Patterns (With Repeat Endpoints)
"upDown": Traverses the array from start to end, and then back from end to start. This pattern repeats the boundary elements. For example, an array of[1, 2, 3]will play as1, 2, 3, 3, 2, 1."downUp": Traverses the array from end to start, and then from start to end. Like"upDown", it repeats the boundary elements. An array of[1, 2, 3]will play as3, 2, 1, 1, 2, 3.
Alternate Patterns (Without Repeat Endpoints)
"alternateUp": Traverses the array up and down without repeating the boundary values. For example, an array of[1, 2, 3]will play as1, 2, 3, 2."alternateDown": Traverses the array down and up without repeating the boundary values. For example, an array of[1, 2, 3]will play as3, 2, 1, 2.
Random and Algorithmic Patterns
"random": Selects a completely random index from the array at each step. Because selections are independent, the same value can be played multiple times in immediate succession."randomOnce": Shuffles the array randomly and plays through every element exactly once. Once the shuffled array has been fully traversed, it shuffles again and repeats the process. This prevents consecutive duplicates and ensures every note in your set is heard before a repetition."randomWalk": Starts at a random index and randomly steps either one index forward or one index backward on each tick. This creates a constrained, organic movement through your array values.