Music Pipeline Architecture - Placement & Integration Strategy
``` comp-core/ ├── core/ │ ├── cc-core/ # JAX/Flax equilibrium algorithms (motion processing) │ ├── cc-ml/ # ML models & data pipeline ← MUSIC ALREADY HERE │ │ └── data_pipeline/ │ │ ├── downloaders/ # YouTube, music list processing │ │ ├── pipeline/ # music_pipeline.py, parallel_pipeline.py │ │ ├── processors/ # Audio processing │ │ └── storage/ # Local music database │ └── cc-trajectory/ # Trajectory prediction (4GB) │ ├── apps/ │ └── desktop/ │ └── cc-echelon/ # Rust music control (879MB) │ └── crates/ # 20+ Rus
Full Public Reader
Music Pipeline Architecture - Placement & Integration Strategy
Date: 2025-12-17
Decision: Where should the music analysis pipeline live?
---
Current Architecture Analysis
Existing Structure
comp-core/
├── core/
│ ├── cc-core/ # JAX/Flax equilibrium algorithms (motion processing)
│ ├── cc-ml/ # ML models & data pipeline ← MUSIC ALREADY HERE
│ │ └── data_pipeline/
│ │ ├── downloaders/ # YouTube, music list processing
│ │ ├── pipeline/ # music_pipeline.py, parallel_pipeline.py
│ │ ├── processors/ # Audio processing
│ │ └── storage/ # Local music database
│ └── cc-trajectory/ # Trajectory prediction (4GB)
│
├── apps/
│ └── desktop/
│ └── cc-echelon/ # Rust music control (879MB)
│ └── crates/ # 20+ Rust crates
│ ├── audio-engine/
│ ├── media/
│ ├── phrase-intelligence/
│ └── ...
│
└── tools/
└── music-pipeline/ # Current location (scripts only)Key Observation
You already have music infrastructure in two places:
1. Python (cc-ml/data_pipeline): Download, conversion, storage
2. Rust (cc-echelon): Real-time audio engine, media handling, phrase intelligence
Current tools/music-pipeline is just scripts - not a proper library.
---
Architectural Decision: Three-Tier Hybrid System
Recommended Architecture
┌─────────────────────────────────────────────────────────────────┐
│ TIER 1: Python Core (cc-ml/data_pipeline) │
│ Purpose: Heavy ML/DSP analysis, batch processing │
├─────────────────────────────────────────────────────────────────┤
│ • Download & ingestion (existing) │
│ • Audio analysis (NEW - Phase 2) │
│ - librosa/essentia (key, BPM, energy) │
│ - ML classification (genre, mood) │
│ - Spectral analysis │
│ • Database management (existing) │
│ • Batch operations │
└─────────────────────────────────────────────────────────────────┘
↓ FFI / IPC
┌─────────────────────────────────────────────────────────────────┐
│ TIER 2: Rust Engine (cc-echelon/crates/music-brain) │
│ Purpose: Real-time playback, low-latency analysis │
├─────────────────────────────────────────────────────────────────┤
│ • Real-time BPM detection (NEW) │
│ • Beatmatching (NEW) │
│ • Harmonic mixing logic (NEW) │
│ • Playlist generation (NEW) │
│ • Audio playback (existing in audio-engine) │
│ • Export to DJ software (NEW) │
└─────────────────────────────────────────────────────────────────┘
↓ WebSocket / IPC
┌─────────────────────────────────────────────────────────────────┐
│ TIER 3: UI Layer (cc-dashboard / cc-echelon-tauri) │
│ Purpose: User interaction, visualization │
├─────────────────────────────────────────────────────────────────┤
│ • Music library browser │
│ • Collection management │
│ • Playlist builder UI │
│ • Real-time visualizer │
│ • DJ control interface │
└─────────────────────────────────────────────────────────────────┘---
Recommended Placement: Hybrid Python + Rust
Phase 2 (Music Analysis) → `core/cc-ml/data_pipeline/analysis/`
Why Python:
- librosa, essentia, aubio are Python libraries
- Heavy DSP/ML computation (not latency-critical)
- Easy integration with existing download pipeline
- Rich ecosystem for audio analysis
Structure:
core/cc-ml/data_pipeline/
├── analysis/ # NEW MODULE
│ ├── __init__.py
│ ├── key_detector.py # librosa key detection
│ ├── bpm_analyzer.py # librosa BPM
│ ├── energy_calculator.py # RMS + spectral energy
│ ├── structure_analyzer.py # Intro/outro detection
│ ├── spectral_analyzer.py # MFCC, chroma features
│ └── ai_classifier.py # Genre/mood ML
│
├── downloaders/ # EXISTING
├── processors/ # EXISTING
├── storage/ # EXISTING
└── pipeline/ # EXISTING
├── music_pipeline.py
└── batch_analyzer.py # NEW - orchestrates analysisPhase 3-4 (Smart Organization & Playlists) → `apps/desktop/cc-echelon/crates/music-brain/`
Why Rust:
- Real-time playlist generation (latency-critical)
- Integration with existing audio-engine
- Efficient data structures (BTreeMap for key lookups)
- Multi-threading for playlist search
- Export to binary DJ software formats
Structure:
apps/desktop/cc-echelon/crates/
├── music-brain/ # NEW CRATE
│ ├── src/
│ │ ├── lib.rs
│ │ ├── camelot.rs # Camelot wheel logic
│ │ ├── beatmatch.rs # BPM matching
│ │ ├── energy_flow.rs # Energy curve planning
│ │ ├── playlist_gen.rs # Playlist generation
│ │ └── dj_export.rs # Rekordbox/Serato export
│ └── Cargo.toml
│
├── audio-engine/ # EXISTING - integrates with music-brain
├── phrase-intelligence/ # EXISTING - could use music-brain
└── media/ # EXISTING - track metadata---
Benefits of Rust + Python Hybrid
1. Performance Where It Matters
Python (Batch Analysis):
- Analyze 340 tracks: ~30 minutes (acceptable for batch)
- Rich ML/DSP libraries
- Easy prototyping
Rust (Real-Time):
- Generate 60-min playlist: <100ms (instant)
- Find compatible tracks: <10ms
- Beatmatch calculation: <1ms
- Export to Rekordbox: <50ms
2. Best Tool for the Job
| Task | Language | Why |
|---|---|---|
| Key detection | Python | librosa is state-of-the-art |
| BPM analysis | Python | essentia is proven |
| Harmonic mixing | Rust | Lookup tables, fast search |
| Playlist generation | Rust | Graph algorithms, multi-threading |
| Real-time BPM sync | Rust | Low-latency required |
| DJ export formats | Rust | Binary format parsing |
3. Integration with Existing Systems
Python side:
- Already has `music_pipeline.py` and `parallel_pipeline.py`
- Storage layer exists (`LocalMusicDatabase`)
- Download infrastructure ready
Rust side:
- cc-echelon already handles audio
- `phrase-intelligence` can use music analysis
- Perfect for live DJ performance mode
4. Data Flow
Python (cc-ml): Rust (cc-echelon):
┌─────────────────┐ ┌─────────────────┐
│ Download track │ │ │
│ ↓ │ │ │
│ Analyze track │ │ │
│ • Key: 5A │ │ │
│ • BPM: 128 │ → Save JSON →│ Load analysis │
│ • Energy: 0.7 │ │ ↓ │
│ ↓ │ │ Generate │
│ Save to DB │ │ playlist │
│ │ │ ↓ │
│ │ │ Export to │
│ │ │ Rekordbox │
└─────────────────┘ └─────────────────┘Communication: JSON files (simple, language-agnostic)
- Python writes: `track_id.analysis.json`
- Rust reads: Load into efficient data structures
- No FFI complexity needed!
---
Migration Plan
Step 1: Move Analysis to cc-ml (Week 1)
# Move from tools/ to core/cc-ml/
mv tools/music-pipeline/analysis core/cc-ml/data_pipeline/
# Update imports
# Old: from analysis import key_detector
# New: from data_pipeline.analysis import key_detectorStep 2: Create Rust music-brain Crate (Week 2)
cd apps/desktop/cc-echelon
cargo new --lib crates/music-brain
# Add to Cargo.toml workspace.membersStep 3: Connect Python → Rust (Week 3)
Python writes:
# In cc-ml/data_pipeline/storage/local_music_database.py
def save_analysis(self, track_id, analysis):
analysis_path = self.get_analysis_path(track_id)
with open(analysis_path, 'w') as f:
json.dump(analysis, f)Rust reads:
// In cc-echelon/crates/music-brain/src/lib.rs
#[derive(Deserialize)]
struct TrackAnalysis {
key: String, // "5A"
bpm: f32, // 128.0
energy: f32, // 0.75
mood: Vec<String>,
genre: Vec<String>,
}
fn load_track_analysis(path: &Path) -> Result<TrackAnalysis> {
let json = fs::read_to_string(path)?;
Ok(serde_json::from_str(&json)?)
}---
Alternative: Pure Python (Not Recommended)
If you want everything in Python:
core/cc-ml/
├── data_pipeline/
│ ├── analysis/ # Phase 2
│ ├── organization/ # Phase 3 (pure Python)
│ └── playlists/ # Phase 4 (pure Python)Downsides:
- Slower playlist generation (Python graph search)
- Can't integrate with cc-echelon audio engine
- Harder to export to binary DJ formats
- No real-time capabilities
Use if: You only want offline analysis and simple M3U playlists.
---
Alternative: Pure Rust (Harder but Possible)
If you want everything in Rust:
cc-echelon/crates/
├── music-brain/
│ ├── analysis/ # Port librosa to Rust (hard!)
│ ├── organization/
│ └── playlists/Downsides:
- No good Rust libraries for key/BPM detection (would need to port librosa)
- Heavy lifting for ML classification
- Slower development
Use if: You want maximum performance and can invest time in porting Python ML libs.
---
Recommendation: Hybrid (Best of Both Worlds) ✅
Why Hybrid Wins
Phase 2 (Python in cc-ml):
- ✅ Use battle-tested libraries (librosa, essentia)
- ✅ Fast development (1 week vs 1 month in Rust)
- ✅ Easy ML integration
- ✅ Batch processing is fine with Python speed
Phase 3-4 (Rust in cc-echelon):
- ✅ Real-time playlist generation
- ✅ Integration with existing audio engine
- ✅ Low-latency for live DJ mode
- ✅ Efficient binary exports
Implementation Path
1. This Week: Move analysis to `core/cc-ml/data_pipeline/analysis/`
2. Week 2-3: Implement Python analysis (librosa, essentia)
3. Week 4: Create Rust `music-brain` crate
4. Week 5-6: Implement Rust playlist generation
5. Week 7: Connect everything via JSON
---
Final Structure
comp-core/
├── core/cc-ml/
│ └── data_pipeline/
│ ├── analysis/ ← NEW (Python ML/DSP)
│ ├── downloaders/ ← EXISTING
│ ├── processors/ ← EXISTING
│ ├── storage/ ← EXISTING (+ analysis storage)
│ └── pipeline/ ← EXISTING (+ batch analyzer)
│
├── apps/desktop/cc-echelon/
│ └── crates/
│ ├── music-brain/ ← NEW (Rust real-time logic)
│ ├── audio-engine/ ← EXISTING (integrates)
│ └── phrase-intelligence/← EXISTING (benefits from analysis)
│
└── tools/music-pipeline/ ← KEEP (CLI scripts only)
├── download_music_to_gcs.py
└── batch_analyze.py ← NEW (wrapper script)---
Summary
Decision: Hybrid Python + Rust
Python (core/cc-ml): Heavy analysis, batch processing, ML
Rust (cc-echelon): Real-time playback, playlist generation, DJ exports
Why:
- Best tool for each job
- Integrates with existing infrastructure
- Fast development (use proven libraries)
- Production-ready performance (Rust where it matters)
Next Step: Start with Python analysis in `core/cc-ml/data_pipeline/analysis/`
Ready to proceed? 🎵
Promotion Decision
Promote into a technical note or architecture paper with implementation anchors.
Source Anchor
projects/Documentation/01-architecture/MUSIC_PIPELINE_ARCHITECTURE.md
Detected Structure
Method · Evaluation · Code Anchors · Architecture