🎯 Overview
The Rhythm Pattern Explorer is a sophisticated web application that bridges the gap between mathematical music theory and practical rhythm creation. It implements cutting-edge algorithms from researchers like Andrew Milne, Godfried Toussaint, and Clarence Barlow to provide musicians, composers, researchers, and curious minds with powerful tools for understanding and creating rhythmic patterns.
🔢 Mathematical Foundation
Built on peer-reviewed research in mathematical music theory, providing rigorous analytical tools for rhythm analysis.
🎵 Universal Pattern Support
Parse 20+ different rhythm notation formats including Euclidean rhythms, regular polygons, and custom patterns.
🎛️ Interactive Analysis
Real-time mathematical analysis with perfect balance theory, syncopation measurement, and geometric visualization.
🔄 Intelligent Transformations
Advanced pattern transformations using Barlow indispensability theory and progressive offset systems.
📐 Mathematical Theory
Andrew Milne's Perfect Balance Theory
Andrew Milne's work on perfect balance provides the mathematical foundation for understanding rhythmic equilibrium. A pattern is perfectly balanced when the sum of its onset vectors equals zero in the complex plane.
Key Insights from Milne's Theory:
- Perfect balance creates perceptually stable rhythms
- Can be achieved through polygon combinations and strategic subtraction
- Relates to symmetry and geometric distribution
- Provides objective measure of rhythmic "centeredness"
Balance Magnitude Calculation
Normalized Balance Score
Center of Gravity Analysis
The center of gravity represents the geometric centroid of the rhythm pattern in the complex plane, providing insight into the pattern's spatial distribution.
Clarence Barlow's Indispensability Theory
Barlow's indispensability theory quantifies the metric importance of each position in a rhythmic cycle, providing a mathematical foundation for understanding syncopation and metric hierarchy.
Indispensability Calculation
For a position $p$ in a meter of $n$ steps:
- If $p = 0$ (downbeat): $\text{indispensability} = 1.0$
- If $p = n-1$ (pickup beat): $\text{indispensability} = 0.75$
- Otherwise: $\text{indispensability} = \frac{1}{\prod \text{prime factors of } \frac{n}{\gcd(p, n)}}$
⚙️ Core Algorithms
Euclidean Rhythm Algorithm (Bjorklund's Algorithm)
Based on Godfried Toussaint's research, the Euclidean algorithm distributes onsets as evenly as possible across a given number of steps.
Euclidean Distribution Algorithm
To distribute $k$ onsets across $n$ steps:
- Start with $k$ groups of "1" (onset) and $(n-k)$ groups of "0" (rest)
- Repeatedly pair groups from opposite ends until no more pairs can be formed
- Continue until only one or two distinct group types remain
- Concatenate the final groups to form the rhythm pattern
Mathematical Properties
Regular Polygon Generator
Regular polygons provide a geometric approach to rhythm generation, where vertices of polygons inscribed in a circle correspond to onset positions.
Polygon Combination Mathematics
Random Pattern Generator with Bell Curve Distribution
Random patterns provide stochastic rhythm generation with musical intelligence through bell curve distribution, avoiding musically uninteresting extremes.
Bell Curve Distribution Algorithm
For R(r,n) patterns, onset counts are generated using normal distribution:
- Apply Box-Muller transformation to generate normal distribution
- Map to range [1, n-1] to avoid empty or full patterns
- Center distribution around n/2 for optimal musical density
- Use 3-sigma rule: 99.7% of values within musical range
Musical Benefits
- Avoids Empty Patterns: Rarely generates 0 onsets (musically uninteresting)
- Avoids Full Patterns: Rarely generates all onsets (rhythmically static)
- Favors Musical Densities: Most likely to generate moderate onset counts
- Maintains Unpredictability: Still provides sufficient randomness for variation
🔄 Pattern Transformers
Barlow Transformer
The Barlow Transformer uses indispensability theory to intelligently add or remove onsets while preserving rhythmic coherence.
Dilution Process (Onset Removal)
- Calculate indispensability for all current onset positions
- Sort onsets by indispensability (ascending for dilution)
- Remove onsets with lowest indispensability values first
- Continue until target onset count is reached
Concentration Process (Onset Addition)
- Calculate indispensability for all positions without onsets
- Sort empty positions by indispensability (descending for concentration)
- Add onsets to positions with highest indispensability values
- Continue until target onset count is reached
Progressive Offsets
Progressive offsets provide systematic pattern rotation with customizable step increments.
Progressive Pattern Lengthening
Progressive lengthening extends patterns by appending random steps with intelligent bell curve onset distribution.
Progressive Extension Process
- User specifies number of steps to add per extension
- Calculate onset count using bell curve distribution (same as R(r,n))
- Generate random onset positions within extension section
- Append extension to current pattern
- Update pattern length and extension count
Musical Intelligence Features
- Bell Curve Distribution: Uses same logic as R(r,n) to avoid musical extremes
- Progressive Building: Each Enter press adds another extension for live composition
- Universal Compatibility: Works with any pattern type or length
- Intelligent Randomness: Favors musically interesting onset densities
🎨 Pattern Creation
The Pattern Creation module provides an intuitive interface for generating rhythmic patterns using five different algorithmic approaches. This streamlined tool allows musicians and researchers to quickly create and explore various rhythmic structures.
Interface Overview
Mode Selection (Radio Buttons)
- Euclidean: Even distribution using Euclidean algorithm
- Dilcue: Anti-Euclidean patterns for syncopated effects
- Barlow: Indispensability theory for intelligent placement
- Wolrab: Anti-Barlow for groove-oriented patterns
- Random: Distribution-based randomness with musical intelligence
- Polygon: Geometric patterns using regular polygons with combination support
Parameters (Inline Controls)
- Onsets: Number of active beats in the pattern
- Steps: Total length of the pattern
- Offset: Rotation offset for pattern start position
- Target: Optional target onset count for progressive mode
Progressive Mode
When a target value is specified, the system automatically enables progressive mode, allowing you to step through transformations from the current onset count to the target count using the Enter key.
Keyboard Interface
- Enter: Generate pattern or step to next in progressive sequence
- Cmd/Ctrl+Enter: Add current pattern to database
- Parameter Changes: Automatically reset progressive state
Design Philosophy
This module focuses on pattern generation rather than transformation. Unlike the Pattern Transformers that modify existing patterns, Pattern Creation generates new rhythmic structures from algorithmic foundations. The streamlined interface prioritizes quick experimentation and iterative creation.
Random Mode Distributions
Distribution Types
- Uniform: Equal probability for all positions - pure randomness
- Bell Curve: Favors middle positions for balanced, musical patterns
- Syncopated: Emphasizes off-beat positions for rhythmic tension
- Balanced: Even spacing with controlled randomness variation
- Clustered: Groups onsets together with varying cluster density
Intensity Control
The intensity slider (0-100%) controls how strongly the distribution pattern is applied:
- Low Intensity (0-30%): Subtle distribution effects, more uniform
- Medium Intensity (40-60%): Balanced distribution characteristics
- High Intensity (70-100%): Strong distribution effects, more pronounced patterns
Random Mode Behavior
- Each Generation: Produces a completely different pattern
- Parameters: Only Onsets and Steps (offset not applicable)
- Random Onsets: Enter 'r' for random onset count using bell curve distribution
- Progressive Mode: Not available for random generation
- Enter Key: Generates new random variation each time
Polygon Mode Interface
Polygon Builder
The Polygon mode provides a visual interface for combining up to 3 regular polygons with addition and subtraction operations:
- Vertices: 2-32 vertices (bipoint to 32-gon)
- Offset: Optional rotation offset for each polygon
- Multiplier: Optional expansion factor (1-8x)
- Operations: + (addition) or - (subtraction) between polygons
- Visual Icons: Dynamic polygon symbols update based on vertex count
Polygon Combination Mathematics
When combining multiple polygons, the system:
- LCM Expansion: Automatically expands all polygons to their least common multiple
- Addition: Combines patterns using logical OR (union of onsets)
- Subtraction: Removes onsets where both patterns have beats
- Perfect Balance: Strategic subtraction can achieve perfect balance patterns
Polygon Mode Features
- Add/Remove Terms: + Add Polygon button and × remove buttons
- Formula Display: Shows combined formula like P(3,1)+P(5,0)-P(2,0)
- Progressive Mode: Not available (polygons define their own structure)
- Bipoint Support: 2-vertex patterns create alternating rhythms
- Geometric Names: Visual icons show triangle, pentagon, etc.
🎹 MIDI Output System
The Rhythm Pattern Explorer includes comprehensive real-time MIDI output capabilities, enabling direct integration with DAWs, hardware synthesizers, and MIDI-enabled applications. The system provides cross-browser compatibility and professional-grade timing accuracy.
Supported Browsers & Methods
🚀 Brave/Chrome/Edge - WebMIDI
Status: ✅ Recommended
Direct MIDI output using native WebMIDI API. No additional software required.
Setup: Click MIDI toggle → Grant permission → Done!
🖥️ Safari (Mac) - WebSocket Bridge
Status: ✅ Working (Local HTTP only)
WebSocket bridge converts messages to MIDI output via Python script.
Setup: Run Python bridge → Serve app locally → Enable MIDI
Note: HTTPS hosted version blocked by browser security
📱 Safari (iOS/iPad)
Status: ❌ Limited
Browser security restrictions prevent direct MIDI output.
Alternative: Use native iOS MIDI apps
🦊 Firefox
Status: 🟡 Experimental
OSC bridge support for MIDI output via external tools.
Setup: Requires OSC-to-MIDI bridge software
Quick Start Guide
Brave Browser (Easiest Method)
- Open Brave Browser
- Click the MIDI toggle (🎹 icon) in the app interface
- Grant MIDI permission when prompted by browser
- Play patterns → MIDI outputs to your default MIDI device
Requirements: None - works immediately with any MIDI-capable device or software
Safari (Mac) with Python Bridge
- Download bridge script:
minimal-midi-bridge.py
- Install dependencies:
pip install websockets mido python-rtmidi
- Run bridge:
python3 minimal-midi-bridge.py
- Serve app locally:
python3 serve-app.py --port 3000
- Open Safari:
http://localhost:3000/app/
(not HTTPS version) - Enable MIDI in app → connects to bridge automatically
MIDI Configuration
Common MIDI Note Assignments
- 36 (C2): Kick drum (default)
- 38 (D2): Snare drum
- 42 (F#2): Hi-hat
- 60 (C4): Middle C
- 69 (A4): A440 reference tone
DAW Integration Setup
Mac Setup (IAC Driver)
- Open Audio MIDI Setup (/Applications/Utilities/)
- Window → Show MIDI Studio
- Double-click IAC Driver
- Check "Device is online"
- Set Ports to at least 1 port
- Click Apply
Windows Setup (Virtual MIDI)
- Install loopMIDI (free virtual MIDI port software)
- Create virtual port for DAW communication
- Configure your DAW to receive from virtual port
Popular DAW Configuration
GarageBand
- Create Software Instrument track
- Set Input: IAC Driver Bus 1
- Choose drum kit or instrument
- Record-enable track
Logic Pro
- Create Software Instrument track
- Set MIDI Input: IAC Driver Bus 1
- Load desired instrument
- Record-enable and test
Ableton Live
- Preferences → MIDI
- Control Surface: IAC Driver Bus 1
- Create MIDI track
- Set input to IAC Driver
Hardware Synths
- Connect MIDI interface
- Set synth MIDI channel
- Route through interface in DAW
- Direct hardware output
Technical Implementation
Timing Accuracy
- WebMIDI: Sub-millisecond accuracy, direct hardware access
- WebSocket Bridge: ~5-10ms latency, excellent for most applications
- Audio Sync: Perfect synchronization with visual sequencer
- Scheduling: Lookahead buffering prevents timing jitter
Troubleshooting
No MIDI Permission (Brave/Chrome)
- Ensure you click the MIDI toggle button
- Try starting pattern playback first (audio context requirement)
- Check Site Settings → MIDI → Allow
- Restart browser if permission issues persist
Safari Bridge Not Connecting
- HTTPS Security Block: Hosted version (enkerli.github.io) cannot access localhost HTTP services
- Solution: Use local HTTP version:
python3 serve-app.py --port 3000
- Verify Python bridge shows "server listening" message
- Check localhost access: try
http://localhost:3000/app/
- Ensure ports 8080 (bridge) and 3000 (app) are available
- Restart bridge: Ctrl+C and run
python3 minimal-midi-bridge.py
No MIDI in DAW
- Check IAC Driver enabled (Mac) or virtual MIDI port (Windows)
- Verify DAW input settings: Set to IAC Driver Bus 1
- Record-enable track in DAW
- Test with MIDI monitoring software to verify output
Advanced Features
Multiple MIDI Outputs
- Mac: Create multiple IAC Driver buses for routing
- DAW Routing: Use internal MIDI routing to multiple instruments
- Hardware: Connect multiple devices via USB MIDI hub
Custom MIDI Mapping
🚀 Getting Started
Quick Start Guide
- Open the Application: Load the Rhythm Pattern Explorer in a modern web browser
- Parse Your First Pattern: Enter
E(3,8)
in the Universal Pattern Input - Explore Analysis: View the mathematical breakdown and circular visualization
- Try Transformations: Use the Barlow Transformer to dilute/concentrate onsets
- Generate Variations: Create mutated patterns with the Rhythm Mutator
- Save to Database: Add interesting patterns for later exploration
📝 Universal Pattern Input (UPI) System
The UPI system provides a comprehensive notation for rhythm patterns, supporting everything from simple binary patterns to complex progressive transformations with accent layers.
Basic Pattern Generation
Algorithmic Patterns
Binary and Numeric Patterns
Progressive Transformations
Manual Control (Plugin ">" Syntax)
Automatic Advancement (WebApp "@#" Syntax)
Accent Pattern System (v0.03c+)
Curly Bracket Notation
Accent Pattern Features
- Polyrhythmic Cycling: Accents cycle when different length from rhythm
- MIDI Enhancement: Accented notes have pitch offset and higher velocity
- Visual Indication: Red for accented onsets, green for regular
- Universal Support: Works with all pattern types (E, B, W, D, P, R)
- Position Flexible: {accent}pattern or pattern{accent}
Scene Cycling
Pipe Separator (|)
Pattern Combinations
Addition and Subtraction
Combination Mathematics
- LCM Expansion: Patterns expanded to least common multiple
- Addition (+): Logical OR - union of all onsets
- Subtraction (-): Remove onsets where both patterns have beats
- Perfect Balance: Strategic subtraction can achieve perfect balance
Quick Reference
Pattern Types
- E(n,s): Euclidean
- B(n,s): Barlow
- W(n,s): Wolrab
- D(n,s): Dilcue
- P(v,s,o): Polygon
- R(n,s,seed): Random
Operators
- +: Combine patterns
- -: Subtract patterns
- |: Scene cycling
- @: Offset rotation
- >: Progressive (manual)
- @#: Progressive (auto)
Accent Notation
- {101}pattern: Binary accents
- {E(2,5)}pattern: Euclidean accents
- {P(3,0)}pattern: Polygon accents
- pattern{101}: Postfix notation
Number Systems
- 101010: Binary
- 0x2A:8: Hexadecimal
- 0o52:8: Octal
- 42:8: Decimal
- [0,2,4]:8: Onset array
💡 Usage Examples
Perfect Balance Discovery
Cultural Rhythm Analysis
Progressive Transformation Workflow
🏗️ Technical Architecture
Modular Design
Mathematical Rendering System
- MathJax Integration: Professional mathematical notation rendering
- LaTeX Support: Full LaTeX equation syntax for complex expressions
- Dynamic Rendering: Real-time equation rendering for interactive content
- Cross-Platform Compatibility: Consistent display across all browsers
- Responsive Design: Adaptive sizing for mobile and desktop
Audio & MIDI Systems
- Web Audio API: Precise timing with lookahead scheduling
- WebMIDI Integration: Direct MIDI output for Chrome, Edge, Opera, Brave
- WebSocket Bridge: Safari MIDI support via Python bridge
- Cross-Browser Compatibility: Automatic method detection and fallback
- Professional Timing: Sub-millisecond accuracy for studio use
Performance Optimizations
- Efficient Parsing: Single-pass pattern recognition
- Caching Systems: Store analysis results to avoid recalculation
- Lazy Loading: Defer non-critical calculations
- Equation Rendering: On-demand MathJax rendering
- MIDI Buffering: Optimized scheduling prevents timing jitter