Patterns
Melodic pattern generators and walker
Pattern generators produce degree sequences (number[] arrays) that describe melodic exercises. The pattern walker resolves these abstract degrees into concrete fretted notes on the guitar.
Pattern Generators
All generators are pure functions that return number[] degree sequences. These sequences can be passed to walkPattern or applySequence.
ascendingIntervals
ascendingIntervals(scaleLength: number, interval: number, octaves?: number) => number[]
Generate ascending interval pairs across a scale:
descendingIntervals
descendingIntervals(scaleLength: number, interval: number, startDegree?: number) => number[]
Generate descending interval pairs:
ascendingLinear
ascendingLinear(from: number, to: number) => number[]
Simple ascending degree sequence:
descendingLinear
descendingLinear(from: number, to: number) => number[]
Simple descending degree sequence:
grouping
grouping(scaleLength: number, groupSize: number, step?: number) => number[]
Generate overlapping groups where each group starts one step higher:
Convenience Wrappers
Pattern Walker
walkPattern
walkPattern(scale: FrettedScale, pattern: number[], options?: WalkOptions) => FrettedNote[]
Walk a degree pattern through a fretted scale, picking concrete notes from the available positions. The walker intelligently selects notes in the correct octave and direction.
Direction Options
-
"auto"(default) -- Detects direction from consecutive degrees in the pattern. Whencurrent > prev, picks ascending; whencurrent < prev, picks descending. Handles mixed patterns like[1,3,5,7,6,5,4,3,2,1]which ascends then descends. -
"up"-- Always pick the next higher note for each degree. -
"down"-- Always pick the next lower note for each degree. -
"nearest"-- Pick the closest note by MIDI number regardless of direction.
How Auto-Direction Works
The walker compares each degree to the previous one:
The first step defaults to ascending unless the first degree is greater than the second. This lets you write a single pattern that naturally ascends and descends without manually specifying directions.
Negative and out-of-range degrees are normalized: ((deg - 1) % scaleLen + scaleLen) % scaleLen + 1.