Rhythm analysis engine and rehearsal instrument.
Upload a track. Get back meter inference, subdivision graphs, groove profiling, drum hit classification, click tracks, and MIDI β with continuous confidence scoring across every dimension.
ββββββββββββββββ ββββββββββββββββ ββββββββββββββ
β Next.js 14 ββββββΆβ FastAPI ββββββΆβ PostgreSQL β
β port 3000 β β port 8000 β β port 5432 β
ββββββββββββββββ ββββββββ¬ββββββββ ββββββββββββββ
β
ββββββββΌβββββββ
β Redis β
β port 6379 β
ββββββββ¬βββββββ
β
βββββββββββΌββββββββββ
β Celery Worker β
β β
β Engine v2 β
β Pipeline β
βββββββββββ¬ββββββββββ
β
βββββββββββΌββββββββββ
β File Storage β
β local / S3 β
βββββββββββββββββββββ
| Layer | Technology |
|---|---|
| Frontend | Next.js 14, TypeScript, Tailwind CSS |
| API | FastAPI, SQLAlchemy (async), Pydantic |
| Task queue | Celery + Redis |
| Engine | Python, librosa, madmom, Demucs v4 |
| Database | PostgreSQL 16 |
| Audio extraction | FFmpeg |
Pure-function pipeline with zero database or Celery dependencies. The worker calls in and handles persistence.
Upload
β
ββ 1. Separation ββββ FFmpeg extract β Demucs v4 stem isolation
β
ββ 2. Signal ββββββββ Onset detection β sample-level transient refinement
β
ββ 3. Temporal ββββββ Beat tracking β downbeats β tempo octave correction β sections
β
ββ 3b. Metrical βββββ Multi-resolution periodicity β hypothesis generation β
β Inference scoring β temporal tracking β modulation detection
β
ββ 3c. Subdivision ββ Persistent subdivision graph β multi-layer rhythm grid β
β Graph phase relations between layers
β
ββ 4. Groove ββββββββ Swing detection β microtiming β accent profiling
β
ββ 5. Hits ββββββββββ Multi-feature drum hit classification (k/s/h/t/c)
β
ββ 6. Export ββββββββ MIDI (multi-track) β click track β waveform peaks
β
ββ Confidence βββββββ Metric-vector scoring (6 dimensions + overall)
| Stage | Module | Description |
|---|---|---|
| 1 | stages/separation.py |
FFmpeg audio extraction, Demucs v4 stem isolation, spectral SNR |
| 2 | stages/signal.py |
Frame-level onset detection + sample-level transient refinement |
| 3 | stages/temporal.py |
Beat tracking, downbeat detection, tempo octave correction, sections |
| 3b | stages/metrical_inference.py |
Periodicity β hypothesis generation β scoring β tracking |
| 3c | stages/subdivision_graph.py |
Persistent multi-layer subdivision graph with phase relations |
| 4 | stages/groove.py |
Swing, microtiming, accent profiling, groove classification |
| 5 | stages/hits.py |
Drum hit classification (kick/snare/hat/tom/cymbal) |
| 6 | stages/export.py |
MIDI export, click track generation, waveform peaks |
| β | confidence.py |
Continuous [0,1] metric-vector confidence scoring |
| β | versioning.py |
Engine version tracking, artifact caching, stale-stage invalidation |
~2400 lines. Handles complex rhythmic structures: math rock, polymeter, tempo changes, metric modulations.
Onset Impulse Train
β
βΌ
Multi-Resolution Periodicity Analysis
(autocorrelation + spectral, sliding windows, 4 resolutions)
β
βΌ
Hypothesis Generator
(period Γ beat_count Γ grouping β MeterHypothesis candidates)
β
βΌ
Hypothesis Scorer
(accent alignment, IOI consistency, prediction error,
structural repetition, harmonic penalty, bar-level accent
periodicity, downbeat-anchored meter scoring)
β
βΌ
Hypothesis Tracker
(EMA smoothing, hierarchical resolution, dominant tracking,
modulation detection, ambiguity flagging, polyrhythm buffer)
β
βΌ
InferenceResult
βββ window_inferences[]
βββ detected_modulations[]
βββ persistent_polyrhythms[]
βββ global_dominant
PersistentSubdivisionGraphBuilder β windowed analysis of onset data against the beat grid. Detects simultaneous subdivision ratios (2, 3, 5, 7, etc.), tracks layer persistence across time, and computes pairwise phase relationships between layers.
Output: RhythmGraph with SubdivisionLayer[] + PhaseRelation[].
Continuous [0,1] metric-vector. Geometric mean ensures a single weak dimension drags overall score.
| Dimension | Measures |
|---|---|
tempo_stability_score |
Tempo coefficient of variation |
downbeat_alignment_score |
Downbeat proximity to beat grid |
meter_consistency_score |
Meter consistency across sections |
section_contrast_score |
Feature contrast at boundaries |
groove_consistency_score |
Groove pattern consistency |
hit_classification_score |
Hit classification confidence |
overall_confidence_score |
Weighted geometric mean |
Next.js 14 (App Router), TypeScript, Tailwind CSS. Three routes:
| Route | Component | Description |
|---|---|---|
/ |
page.tsx |
Upload console with rhythm scope visualization |
/projects |
projects/page.tsx |
Project list |
/projects/[id] |
projects/[id]/page.tsx |
Analysis dashboard |
Key components:
| Component | Description |
|---|---|
AudioEngine.tsx |
Multi-stem Web Audio API mixer (mute/solo/volume per stem) |
WaveformDisplay.tsx |
Canvas waveform renderer |
ArrangementMap.tsx |
Section arrangement view |
TimelinePanel.tsx |
Timeline visualization |
RhythmPreviewHero.tsx |
Analytical subdivision scope (landing page) |
SubdivisionGraphPanel.tsx |
Subdivision graph debug panel |
RhythmDebugPanel.tsx |
Metrical inference debug view |
ProcessingView.tsx |
Processing status display |
ConfidenceBadge.tsx |
Confidence level indicator |
SessionGrid/
βββ apps/
β βββ api/
β β βββ main.py # API routes
β β βββ config.py # Settings
β β βββ models.py # SQLAlchemy models
β β βββ schemas.py # Pydantic schemas
β β βββ database.py # DB sessions
β β βββ engine/
β β β βββ __init__.py # ENGINE_VERSION
β β β βββ pipeline.py # Pipeline orchestrator
β β β βββ confidence.py # Metric-vector scoring
β β β βββ versioning.py # Version tracking + caching
β β β βββ stages/
β β β β βββ separation.py # FFmpeg + Demucs
β β β β βββ signal.py # Onset detection
β β β β βββ temporal.py # Beats, downbeats, sections
β β β β βββ metrical_inference.py # Periodicity β hypotheses
β β β β βββ subdivision_graph.py # Multi-layer rhythm graph
β β β β βββ groove.py # Swing, microtiming
β β β β βββ hits.py # Drum hit classification
β β β β βββ export.py # MIDI, click, waveforms
β β β βββ evaluation/
β β β βββ ground_truth.py # Ground-truth data model
β β β βββ transcript_parser.py # JSON loading + validation
β β β βββ metrics.py # Metric computation
β β β βββ evaluator.py # Evaluation pipeline
β β βββ workers/
β β β βββ celery_app.py # Celery config
β β β βββ tasks.py # Pipeline task + persistence
β β βββ alembic/ # Migrations
β β βββ Dockerfile
β β βββ requirements.txt
β β
β βββ web/
β βββ app/
β β βββ page.tsx # Upload console
β β βββ layout.tsx # Root layout
β β βββ globals.css # Styles
β β βββ projects/
β β βββ page.tsx # Project list
β β βββ [id]/page.tsx # Analysis dashboard
β βββ components/
β β βββ analysis/
β β β βββ ArrangementMap.tsx
β β β βββ ExportPanel.tsx
β β β βββ PracticeDeck.tsx
β β β βββ ProcessingView.tsx
β β β βββ ProjectSidebar.tsx
β β β βββ RhythmDebugPanel.tsx
β β β βββ RhythmPreviewHero.tsx
β β β βββ SubdivisionGraphPanel.tsx
β β β βββ TimelinePanel.tsx
β β βββ player/
β β β βββ AudioEngine.tsx
β β β βββ WaveformDisplay.tsx
β β βββ ui/
β β βββ ConfidenceBadge.tsx
β βββ lib/
β β βββ api.ts # API client
β β βββ types.ts # TypeScript models
β βββ Dockerfile
β βββ package.json
β
βββ docs/
β βββ PRD.md
β βββ ARCHITECTURE.md
β βββ VALIDATION.md
β
βββ storage/
βββ docker-compose.yml
βββ .gitignore
git clone https://github.com/acLebert/SessionGrid.git
cd SessionGrid
docker compose up --build| Service | Port |
|---|---|
| web | 3000 |
| api | 8000 |
| worker | β |
| postgres | 5432 |
| redis | 6379 |
Frontend: http://localhost:3000 API docs: http://localhost:8000/docs
Backend:
cd apps/api
python -m venv .venv
.venv/Scripts/activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8000
# separate terminal:
celery -A workers.celery_app worker --loglevel=infoFrontend:
cd apps/web
npm install
npm run dev| Method | Endpoint | Description |
|---|---|---|
GET |
/api/health |
Health check |
GET |
/api/projects |
List projects |
POST |
/api/projects |
Create + upload |
GET |
/api/projects/:id |
Project details |
GET |
/api/projects/:id/status |
Poll status |
POST |
/api/projects/:id/analyze |
Trigger analysis |
GET |
/api/projects/:id/audio |
Stream audio |
GET |
/api/projects/:id/stems/:type |
Download stem |
GET |
/api/projects/:id/click |
Download click |
GET |
/api/projects/:id/waveform |
Waveform data |
GET |
/api/projects/:id/midi |
Download MIDI |
POST |
/api/projects/:id/midi/quantize |
Re-quantize MIDI |
GET |
/api/projects/:id/drum-hits |
Drum hits |
GET |
/api/projects/:id/groove |
Groove profile |
GET |
/api/projects/:id/confidence |
Confidence vector |
GET |
/api/projects/:id/rhythm-debug |
Metrical inference data |
GET |
/api/projects/:id/subdivision-debug |
Subdivision graph data |
PATCH |
/api/projects/:id/sections/:sid |
Edit section |
GET |
/api/projects/:id/export/json |
Full analysis JSON |
DELETE |
/api/projects/:id |
Delete project |
Synthetic test pipeline for metrical inference. No audio required.
| Module | Purpose |
|---|---|
ground_truth.py |
Immutable ground-truth dataclasses |
transcript_parser.py |
JSON loading + schema validation |
metrics.py |
Metric computation (meter accuracy, modulation P/R, polyrhythm recall) |
evaluator.py |
Pipeline + 5 synthetic test scenarios |
Metrics: meter accuracy, grouping accuracy, modulation precision/recall/timing, polyrhythm recall, ambiguity alignment, confidence calibration.
- Engine version semver tracked per run
- Stage-level sub-versioning β only stale stages re-run
- Intermediate artifacts cached as
.npz - Input hash + engine version + model weights + seeds β deterministic output
- Drums-focused analysis pipeline
- Click track generation
- Section detection with confidence
- Engine v2 staged pipeline
- Multi-resolution periodicity detection
- Metrical inference (hypothesis generation, scoring, tracking)
- Hierarchical meter resolution + modulation persistence
- Bar-level accent periodicity scoring
- Downbeat-anchored meter scoring
- Persistent subdivision graph builder
- Metric modulation and polyrhythm detection
- Drum hit classification
- Groove profiling (swing, microtiming, accents)
- MIDI export with quantization control
- Continuous confidence vector
- Multi-stem Web Audio API mixer
- Evaluation framework with synthetic tests
- Engine versioning and artifact caching
- Subdivision graph debug UI
- Metrical inference debug panel
- Speed adjustment for practice
- Count-in before loop playback
- Bass/guitar stem analysis
- Multi-instrument arrangement maps
- Manual section boundary editing
- User accounts & project history
Private β All rights reserved.