Mini-Notation¶
kr.p() parses a compact string notation into a pattern. It is a shorthand
for building patterns without chaining Python calls.
Syntax¶
Returns a Pattern object -- composable like any other pattern.
Tokens¶
| Token | Meaning | Equivalent |
|---|---|---|
x or X |
Hit (percussive trigger) | kr.hit() |
. |
Rest | kr.rest() |
~ |
Rest (alternative) | kr.rest() |
- |
Rest (alternative) | kr.rest() |
C4, Cs4, C#4 |
Note by pitch name | kr.note("C4") |
Grouping: []¶
Square brackets play tokens simultaneously (stacked):
kr.p("[C4 E4] G4 B4") # C4 and E4 together, then G4, then B4
kr.p("[x x] . x .") # double hit, rest, hit, rest
Repeat: *N¶
Repeat a token N times:
Examples¶
Drum patterns¶
# Basic 4/4 kick
kr.play("kick", kr.p("x . . . x . . . x . . . x . . ."))
# Shorter: 4 hits with rests between
kr.play("kick", kr.p("x . x . x . . x"))
# Hi-hat 8ths
kr.play("hat", kr.p("x x x x x x x x"))
Melodic patterns¶
# Simple melody
kr.play("lead", kr.p("C4 E4 G4 ~ C5"))
# With simultaneous notes
kr.play("pad", kr.p("[C4 E4] [D4 F4] [E4 G4] ~"))
Composable¶
Mini-notation patterns support all the same transforms: