PraatPbind — Declarative Pattern Engine — User Guide
Integrates a SuperCollider-style event pattern system (Pbind syntax) into Praat's analysis–resynthesis workflow. Define event-based control structures using compact one-line expressions, compiled into PitchTier and IntensityTier control curves.
What this does
This script implements PraatPbind — a declarative pattern engine that integrates a SuperCollider-style event pattern system into Praat's analysis–resynthesis workflow. Users define event-based control structures using compact one-line Pbind expressions, which are interpreted by a Python engine and compiled into time-aligned PitchTier and IntensityTier control curves. These curves are then applied to the source sound via Manipulation-based resynthesis.
🎛️ What is Pbind?
In SuperCollider, Pbind is a pattern that binds symbolic keys to patterns of values. This implementation supports a subset of the SuperCollider pattern syntax:
- Pitch keys:
degree(major scale index),midinote(MIDI note),freq(Hz) - Temporal keys:
dur(event spacing),legato(segment scaling) - Dynamic key:
amp(linear amplitude, 0-1) - Pattern types:
Pseq,Prand,Pwrand,Pwhite,Pexprand,Pstutter, constants
The result is an event stream that drives pitch and amplitude over time, resynthesized from the source sound.
Key Features:
- 8 Preset Patterns — MajorUp to Stutter, plus Custom
- SuperCollider-Style Syntax — Familiar to SuperCollider users
- 3 Pitch Domains — degree (major scale), midinote, freq
- 6 Pattern Types — Pseq, Prand, Pwrand, Pwhite, Pexprand, Pstutter
- Legato Control — Staccato (<1) to legato (>1) phrasing
- Pure Python Implementation — No external ML libraries, just stdlib
- Resynthesis via Manipulation — PitchTier + IntensityTier applied to source
- Comprehensive Visualization — 5-panel display with waveforms, pitch contour, amplitude bars, stats
Technical Implementation: (1) Analysis: Extract source duration and sample rate. (2) Pbind Parsing: Python parses the Pbind expression into pattern descriptors. (3) Event Generation: Iterate patterns to generate event list (time, dur, pitch, amp, legato). (4) Tier Construction: Convert events to stepwise PitchTier and IntensityTier points. (5) Resynthesis: Apply tiers via Manipulation. (6) Visualization: 5-panel display.
Quick start
- In Praat, select exactly one Sound object (any duration, any content).
- Run script… → select
PraatPbind.praat. - Choose Preset (2-9 for specific patterns, 1 for custom).
- Edit the Pbind expression if using custom mode.
- Set base frequency (Hz) for degree scaling and seed for reproducibility.
- Enable Draw_visualization for analysis display.
- Click OK — engine parses pattern, generates events, resynthesizes.
Pbind Theory & Syntax
Basic Syntax
Pattern Types
📊 Supported Pattern Generators
| Pattern | Syntax | Description | Example |
|---|---|---|---|
| Pseq | Pseq([list], repeats) | Cycles through list in order | Pseq([0,2,4,5], 3) |
| Prand | Prand([list], count) | Random picks from list | Prand([60,62,64], 10) |
| Pwrand | Pwrand([vals], [weights], count) | Weighted random picks | Pwrand([0,4,7], [0.5,0.3,0.2], inf) |
| Pwhite | Pwhite(lo, hi, count) | Uniform random float | Pwhite(0.1, 0.5, inf) |
| Pexprand | Pexprand(lo, hi, count) | Exponentially distributed float | Pexprand(0.05, 0.5, inf) |
| Pstutter | Pstutter(pattern, count) | Repeats each value count times | Pstutter(Pseq([0,4,7],inf), 3) |
| Constant | number | Fixed value | 0.3 |
Repeats/Count: Use inf for infinite (until duration ends) or an integer for finite length.
Pitch Conversion
🎵 From Patterns to Frequency
Major scale degrees: [0, 2, 4, 5, 7, 9, 11]
Examples: degree=0 → root, degree=2 → 3rd, degree=4 → 5th, degree=7 → octave, degree=9 → 9th (octave+2nd), etc.
Event Timing
Stopping Rules
Preset Patterns
Preset 2: MajorUp
🎵 Major Scale Ascending
Pbind(degree=Pseq([0,1,2,4,7],inf), dur=0.25, amp=Pwhite(0.1,0.5,inf))
Character: Major scale degrees [0,1,2,4,7] (root, 2nd, 3rd, 5th, octave) repeating, random amplitude
Use on: General purpose, melodic exploration
Preset 3: RandomWalk
🎲 Chromatic Walk
Pbind(degree=Pseq([0,1,2,3,4,5,6],inf), dur=0.15, amp=Pwhite(0.2,0.6,inf))
Character: Chromatic scale degrees, faster dur, wider amplitude range
Use on: Random-walk textures
Preset 4: Pulses
⚡ Rhythmic Pulses
Pbind(degree=Pseq([0,0,7,0,0,4],inf), dur=0.10, amp=Pwhite(0.05,0.9,inf))
Character: Repeating rhythmic pattern (root, root, octave, root, root, fifth), fast
Use on: Rhythmic textures, pulses
Preset 5: MidiMelody
🎹 MIDI Note Sequence
Pbind(midinote=Pseq([60,62,64,65,67,69],inf), dur=0.2, amp=Pwhite(0.3,0.7,inf))
Character: C major scale in MIDI notes, moderate amplitude
Use on: Melodic phrases, explicit pitch control
Preset 6: RawFreq
📊 Frequency Sweep
Pbind(freq=Pwhite(200,800,inf), dur=0.1, amp=0.4)
Character: Random frequencies between 200-800 Hz, constant amplitude
Use on: Spectral exploration, noise-based material
Preset 7: LegatoPhrase
🎻 Legato Articulation
Pbind(degree=Pseq([0,2,4,7],inf), dur=0.3, amp=Pwhite(0.3,0.7,inf), legato=0.6)
Character: Major triad degrees, legato=0.6 creates staccato phrasing
Use on: Articulation exploration
Preset 8: WeightedChord
⚖️ Weighted Random
Pbind(degree=Pwrand([0,4,7],[0.5,0.3,0.2],inf), dur=0.2, amp=Pwhite(0.2,0.6,inf))
Character: Weighted random chord tones (root 50%, third 30%, fifth 20%)
Use on: Probability-based textures
Preset 9: Stutter
🔁 Stutter Effect
Pbind(degree=Pstutter(Pseq([0,4,7],inf),3), dur=0.1, amp=Pwhite(0.2,0.7,inf))
Character: Each chord tone repeated 3 times before moving to next
Use on: Stutter effects, repeated patterns
Parameters & Controls
Pbind Parameters
| Parameter | Default | Description |
|---|---|---|
| Pbind | MajorUp preset | One-line Pbind expression (see syntax guide) |
Global Parameters
| Parameter | Default | Description |
|---|---|---|
| BaseHz | 220 | Base frequency for degree scaling (A3 = 220 Hz) |
| Seed | 42 | Random seed for deterministic results |
Output
| Parameter | Default | Description |
|---|---|---|
| Draw_visualization | 1 | Generate 5-panel analysis display |
| Play_result | 1 | Audition after processing |
Visualization & Analysis
5-Panel Display
Reading the Pitch Contour
- Colored step lines: Each horizontal segment represents one event, at constant pitch
- Color gradient: Blue = low pitch, red = high pitch — shows register
- Brightness: Brighter = lower amplitude, darker = higher amplitude
- Onset dots: Red dots mark event start times
- Connecting lines: Thin gray lines connect consecutive events, showing pitch jumps
- Grid lines: Thick = octaves (C), medium = perfect fifths, thin = other notes — helps reading pitch
Interpreting the Amplitude Bars
- Bar height: Amplitude in dB (higher on y-axis = louder)
- Bar color: Matches pitch contour color — helps correlate pitch and amplitude
- Horizontal line: Mean dB level across all events
- Duration: Bar width = event duration × legato (may leave gaps if legato < 1)
Applications
Electroacoustic Composition
Use case: Creating algorithmic pitch/amplitude structures from any source
Technique: Custom Pbind patterns on sustained sounds
Workflow:
- Select a sustained source (pad, drone, vocal sustain)
- Write a Pbind pattern expressing desired pitch/dynamic structure
- Run to generate the transformed version
- Export and use as material in larger work
Algorithmic Composition
Use case: Generating note sequences with probability and repetition
Technique: WeightedChord or RandomWalk presets
Examples:
- Stochastic melodies: Prand with chromatic scale
- Weighted chord tones: Pwrand for harmonic probability
- Stutter effects: Pstutter for repeated notes
Sound Design for Media
Use case: Creating rhythmic pulses, frequency sweeps, articulated textures
Technique: Pulses or RawFreq presets
Applications:
- Risers: Pseq with increasing degree values
- Rhythmic beds: Pulses with varying legato
- Random sweeps: RawFreq with Pwhite
Research & Education
Use case: Teaching pattern-based composition, SuperCollider concepts
Technique: Compare presets on same source, examine pitch contours
Learning outcomes:
- Understand Pbind syntax and pattern generators
- See how patterns map to pitch/amplitude curves
- Explore relationship between legato and articulation
- Learn about resynthesis via Manipulation
Practical Workflow Examples
🎬 Film Scene: Tension Riser
Goal: Create 30-second tension riser from pad
Settings:
- Source: 30-second synth pad
- Custom Pbind:
Pbind(degree=Pseq([0,1,2,3,4,5,6,7,8,9,10,11],1), dur=2.5, amp=0.5) - BaseHz = 110 (A2)
Result: Chromatic scale over 30 seconds, rising in pitch — classic riser
🎚️ Electronic Music: Generative Melody
Goal: Generate infinite melody from single note
Settings:
- Source: 20-second cello note
- Pbind:
Pbind(degree=Prand([0,2,4,5,7,9,11],inf), dur=Pexprand(0.1,0.5,inf), amp=Pwhite(0.2,0.8,inf))
Result: Randomly wandering melody with varied durations and dynamics
🎙️ Voice Processing: Expressive Phrasing
Goal: Apply rhythmic phrasing to vocal sample
Settings:
- Source: 10-second vocal phrase
- Pbind:
Pbind(degree=Pseq([0,2,4,5],inf), dur=0.3, amp=0.5, legato=0.5)
Result: Staccato articulation (legato=0.5) creates gaps between notes
Troubleshooting Common Issues
Cause: Python not installed or not in PATH
Solution: Install Python 3 and ensure it's in PATH
Cause: Syntax error in Pbind expression
Solution: Check parentheses, commas, pattern syntax — use examples as reference
Cause: Patterns empty or dur too large
Solution: Check pattern lists are non-empty, reduce dur
Cause: legato < 1 creating gaps, or overlaps with no crossfade
Solution: Use legato=1 for continuous, or accept that gaps may click
Cause: baseHz inappropriate for source, or degree values too extreme
Solution: Adjust baseHz, or use midinote/freq for direct control
Advanced Techniques
Pstutter can wrap any pattern, creating complex repetition structures. For example: Pstutter(Prand([0,2,4],inf), 3) repeats each random note 3 times.
Use finite repeats (e.g., Pseq([0,1,2], 5)) to create patterns that stop before the duration ends — useful for sectional forms.
Only one pitch key can be used per Pbind. Choose degree for scale-based, midinote for exact MIDI, freq for raw Hz.
Script converts to mono. For stereo, modify to process each channel separately or sum to mono.