1 unstable release
Uses new Rust 2024
| 0.2.0 | Oct 11, 2026 |
|---|---|
| 0.1.1 |
|
| 0.1.0 |
|
#898 in Parser implementations
27 downloads per month
Used in 4 crates
(3 directly)
1.5MB
28K
SLoC
strudel-mini
Mini notation parser and evaluator for Strudel patterns.
Overview
strudel-mini provides parsing, formatting, and evaluation of Strudel's mini notation - a concise syntax for expressing
rhythmic patterns - along with pattern extraction from .strudel files, a pretty-printing formatter, and a verified
rewriter/compressor for condensing patterns without changing what they sound like.
bd sd [cp cp] ~
bd*2 [sd cp]*3 <hh oh>
{bd sd, hh oh cp}(3,8)
Features
- Complete Mini Notation Parser: Supports all Strudel mini notation syntax
- AST Evaluation: Convert parsed patterns to executable
strudel-corepatterns - Pattern Extraction: Extract mini notation from
.strudelJavaScript files - Formatter: Pretty-print parsed patterns back to mini notation
- Verified Rewriter: Condense repetitive patterns while checking musical parity over many cycles
- CLI Tool: Validate, parse, evaluate, and play patterns from the command line
Installation
As a Library
[dependencies]
strudel-mini = "0.2"
As a CLI Tool
cargo install strudel-mini
Quick Start (Library)
use strudel_mini::{parse, evaluate};
fn main() {
// Parse mini notation
let ast = parse("bd sd [cp cp] ~").unwrap();
// Evaluate to a pattern
let pattern = evaluate(&ast).unwrap();
// Query the pattern
let events = pattern.first_cycle();
for event in events {
println!("{:?}", event.value);
}
// Format back to mini notation
let formatted = strudel_mini::format(&ast);
println!("{}", formatted);
}
Extracting Patterns from .strudel Files
use strudel_mini::{extract_patterns, combine_patterns, CombineStrategy};
fn main() {
let source = r#"
setcpm(120/4)
$: note(`bd sd hh cp`).sound()
$: note(`c3 e3 g3`).sound("piano")
"#;
let patterns = extract_patterns(source);
let combined = combine_patterns(&patterns, CombineStrategy::Stack);
println!("{}", combined);
}
Verified Rewriting / Compression
use strudel_mini::{rewrite_str, verify_roundtrip, RewriteOptions};
fn main() {
let original = "bd bd bd bd sd sd [cp cp] hh hh hh hh";
let opts = RewriteOptions {
verify: true,
verify_cycles: 8,
..Default::default()
};
let rewritten = rewrite_str(original, &opts).unwrap();
println!("{}", rewritten); // e.g. "bd!4 sd sd [cp cp] hh!4"
verify_roundtrip(original, &rewritten, 8).unwrap();
}
Mini Notation Syntax
Basic Elements
a b c # Space-separated sequence (fastcat)
[a b c] # Grouped sub-pattern
~ # Silence/rest
a!3 # Replication (a a a)
Operators
a,b,c # Stack (play simultaneously)
a|b|c # Random choice
a.b.c # Feet/dot operator
{a b, c d e} # Polymeter
<a b c> # Polymeter slowcat
Euclidean Rhythms
bd(3,8) # 3 pulses over 8 steps
bd(3,8,2) # With rotation of 2
Ranges
0..7 # Ascending range [0,1,2,3,4,5,6,7]
7..0 # Descending range [7,6,5,4,3,2,1,0]
Elongation
a@2 b c # 'a' takes twice as long
Weights
a|b%2|c # 'b' is twice as likely to be chosen
CLI Usage
Validate a Pattern
strudel-mini validate "bd sd hh cp"
Parse and Show AST
strudel-mini ast "bd [sd cp]" --output-format json
Evaluate and Show Events
strudel-mini eval "bd sd hh cp" --from 0 --duration 1
Format a Pattern
strudel-mini fmt "bd sd [ cp cp ]"
# Output: bd sd [cp cp]
Extract from .strudel Files
# Extract and show separately
strudel-mini extract myfile.strudel --strategy separate
# Extract and stack all patterns
strudel-mini extract myfile.strudel --strategy stack
# Extract and sequence all patterns
strudel-mini extract myfile.strudel --strategy sequence
Rewrite and Condense a Pattern
strudel-mini rewrite "bd bd bd bd sd sd [cp cp] hh hh hh hh" --style live --cycles 8
Play Patterns (with audio feature)
# Play a simple pattern
strudel-mini play "bd sd hh cp" --tempo 120 --duration 10
# Play from a file
strudel-mini play pattern.txt --tempo 140
# Play from a .strudel file
strudel-mini play song.strudel --combine stack
Runnable Examples
The examples/ directory contains small, self-contained programs. Run any of them with
cargo run -p strudel-mini --example <name>:
mini_basic_pattern- parse, evaluate, and query a pattern across cyclesextract_and_combine- extract mini notation from.strudel-style source and recombine itrewrite_pattern- verified rewriting/condensing with semantic parity checksmini_play_pattern- play a pattern through the native audio backend (requires--features audio)
cargo run -p strudel-mini --example mini_basic_pattern
cargo run -p strudel-mini --example extract_and_combine
cargo run -p strudel-mini --example rewrite_pattern
cargo run -p strudel-mini --example mini_play_pattern --features audio
Feature Flags
audio- Enable audio playback support (requiresstrudel-audio)
[dependencies]
strudel-mini = { version = "0.2", features = ["audio"] }
Error Handling
use strudel_mini::{parse, ParseError};
fn main() {
match parse("bd [ sd") {
Ok(ast) => println!("Parsed: {:?}", ast),
Err(ParseError::UnexpectedEof { expected, .. }) => {
eprintln!("Unexpected end of input, expected: {}", expected);
}
Err(e) => eprintln!("Parse error: {}", e),
}
}
License
AGPL-3.0-or-later. See LICENSE. Copyright and attribution terms are in the repository README.
Links
Dependencies
~2–37MB
~504K SLoC