Compare commits
14 Commits
6eb02fe576
...
m6-haertun
| Author | SHA1 | Date | |
|---|---|---|---|
| bc62fa1c56 | |||
| a6dd0a649a | |||
| 44311d007f | |||
| 9db639ea9e | |||
| f1d55c4bcb | |||
| 760bad7435 | |||
| 7ec6b3274b | |||
| 8d366327e6 | |||
| fcc1cd2426 | |||
| 983102b588 | |||
| a7dedd4306 | |||
| fac85bcd56 | |||
| 887bd4a3e9 | |||
| cc5e2fe628 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -41,6 +41,9 @@ testdata/
|
||||
*.flac
|
||||
*.ogg
|
||||
|
||||
# Allow synthetic demo audio
|
||||
!examples/demo_song/stems/*.wav
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
@ -47,8 +47,7 @@ uv run ruff format --check
|
||||
- [x] **M0 – Gerüst**: Projektstruktur, Pydantic-Schemas (`meta.json`, `tempo.json`, `vocals.json`, `chords.json`, `strumming.json`), `tempo.py` mit `sec_to_beat`/`beat_to_sec`, Pipeline-Runner mit Cache und Hash-Invalidierung, CLI-Skelett mit `doctor`, Testsuite.
|
||||
- [x] **M1 – Extraktion und Stems**: Stufen 1 (ffmpeg 44.1 kHz stereo) und 2 (Demucs `htdemucs_ft` / `htdemucs_6s`, low-VRAM chunking mit segment/shifts, `instrumental.wav` und `vocals.wav`, SNR-Prüfung).
|
||||
- [x] **M2 – Gesang**: Stufe 3 (`whisper-large-v3` + `pyphen`-Silbentrennung mit proportionalem Timing), Stufe 4 (`torchcrepe-full` mit Medianhöhe & Oktavfehler-Korrektur), UltraStar-Export (`song.txt`) & Reader, Eval-Framework mit Timing-MAE, Pitch-Genauigkeit (strikt & oktav-äquivalent) und WER via `jiwer`.
|
||||
- [ ] **M3 – Tempo-Map**: Stufe 5 (beat_this).
|
||||
- [ ] **M3 – Tempo-Map**: Stufe 5 (beat_this).
|
||||
- [ ] **M4 – Akkorde**: Stufe 6 (Chordino / Transformer).
|
||||
- [ ] **M5 – Strumming**: Stufe 7 (librosa Onsets / Strumming-Muster).
|
||||
- [ ] **M6 – Härtung**: Fehlerbehandlung, Logging, Dokumentation, Beispielpaket.
|
||||
- [x] **M3 – Tempo-Map**: Stufe 5 (`beat_this` Beat- & Downbeat-Tracking mit `librosa`-Fallback), intelligente Segmentierung (Anker nur bei echten Tempowechseln), Metronom-Klick-Track-Synthese (`.cache/click_track.wav`), BPM/GAP-Ableitung für UltraStar.
|
||||
- [x] **M4 – Akkorde**: Stufe 6 (Harte-Notation, Beat-synchrone Quantisierung über Tempo-Map, `chordino` & `template` Backends, Tonarterkennung nach Krumhansl-Schmuckler in `meta.json`).
|
||||
- [x] **M5 – Strumming**: Stufe 7 (Onset-Erkennung auf Gitarren-/Instrumental-Stem, Spektralschwerpunkt- & Beatphasen-Gradient für Down/Up-Richtungsvorschlag, Beat-Raster-Quantisierung, Muster-Verdichtung `D . D U . U D U`, als `experimental` markiert).
|
||||
- [x] **M6 – Härtung**: Fehlerbehandlung, strukturiertes Logging, Formatspezifikation ([docs/format.md](docs/format.md)), lizenzfreies synthetisches Beispielpaket ([examples/demo_song/](examples/demo_song/)).
|
||||
|
||||
269
docs/format.md
Normal file
269
docs/format.md
Normal file
@ -0,0 +1,269 @@
|
||||
# Song-Paket Format Spezifikation (v1.0)
|
||||
|
||||
Dieses Dokument definiert das Dateiformat des **Song-Pakets** als verbindliche Schnittstelle zwischen der Analyse-Pipeline (`songsplit`) und nachgelagerten Anwendungen (z. B. der Rust-Gesangstrainer-App und Editoren).
|
||||
|
||||
---
|
||||
|
||||
## 1. Verzeichnisstruktur
|
||||
|
||||
Ein Song-Paket befindet sich in einem dedizierten Verzeichnis:
|
||||
|
||||
```
|
||||
<song-ordner>/
|
||||
meta.json # Metadaten, Track-Info, Modelle, Status
|
||||
tempo.json # Tempo-Map (Anker, Taktart, Downbeat)
|
||||
stems/ # Isolierte Audiodateien (44.1 kHz, 16-Bit Stereo WAV)
|
||||
vocals.wav # Gesangsspur (Pflicht)
|
||||
instrumental.wav # Gesamtes Playback ohne Gesang (Pflicht)
|
||||
drums.wav # Schlagzeug (optional bei 4- oder 6-Stem Trennung)
|
||||
bass.wav # Bass (optional)
|
||||
other.wav # Sonstige Instrumente (optional)
|
||||
guitar.wav # Gitarre (optional bei 6-Stem Trennung)
|
||||
piano.wav # Klavier (optional bei 6-Stem Trennung)
|
||||
vocals.json # Liedtext, Silben-Timing, Tonhöhe (Sekundenbasis)
|
||||
chords.json # Akkordverlauf (Beat-Basis)
|
||||
strumming.json # Gitarren-Anschläge und Rhythmusmuster (Beat-Basis)
|
||||
song.txt # UltraStar-Deluxe Export
|
||||
.cache/ # Stufen-Hashes und temporäre Zwischenergebnisse
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Grundlegende Prinzipien
|
||||
|
||||
### 2.1 Zeitbasen
|
||||
- **Gesang (`vocals.json`):** Ausschließlich in **Sekunden** (`float`).
|
||||
- **Akkorde (`chords.json`) & Strumming (`strumming.json`):** Ausschließlich in **musikalischen Zählzeiten / Beats** (`float`, Viertelnoten).
|
||||
- **Verbindung:** Ausschließlich über die in `tempo.json` definierte Tempo-Map mit den Konvertierungsfunktionen `sec_to_beat()` und `beat_to_sec()`.
|
||||
|
||||
### 2.2 Schemakonventionen
|
||||
Jede JSON-Datei enthält im Wurzelknoten:
|
||||
- `"schema_version": "1.0"`
|
||||
- `"generated_by"`: Objekt mit Angaben zu Stufe, Modell, Modellversion und Ausführungsparametern:
|
||||
```json
|
||||
"generated_by": {
|
||||
"stage": "s4_pitch",
|
||||
"model": "torchcrepe-full",
|
||||
"model_version": "1.0.0",
|
||||
"params": {
|
||||
"hop_length_ms": 10,
|
||||
"voicing_threshold": 0.25
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 Konfidenz und Herkunft
|
||||
Jedes automatisch erzeugte musikalische Ereignis (Silbe, Akkord, Strumming-Event) besitzt:
|
||||
- `confidence`: Gleitkommazahl im Bereich `0.0` bis `1.0`.
|
||||
- `source`: Literal aus `["auto", "manual", "import"]`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Dateispezifikationen
|
||||
|
||||
### 3.1 `meta.json`
|
||||
Zentrale Metadaten des analysierten Titels.
|
||||
|
||||
```json
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": null,
|
||||
"title": "Beispielsong",
|
||||
"artist": "Künstler",
|
||||
"language": "de",
|
||||
"duration_sec": 195.42,
|
||||
"source_file": {
|
||||
"path": "/daten/audio/beispiel.mp3",
|
||||
"sha256": "3a7b9c1d...",
|
||||
"size_bytes": 6245120
|
||||
},
|
||||
"key": "Am",
|
||||
"capo": null,
|
||||
"models_used": [
|
||||
{"stage": "s1_extract", "name": "ffmpeg", "version": "6.0"},
|
||||
{"stage": "s2_stems", "name": "htdemucs_ft", "version": "1.0.0"},
|
||||
{"stage": "s3_lyrics", "name": "whisper-large-v3", "version": "1.0.0"},
|
||||
{"stage": "s4_pitch", "name": "torchcrepe-full", "version": "1.0.0"},
|
||||
{"stage": "s5_tempo", "name": "beat_this-final0", "version": "1.1.0"},
|
||||
{"stage": "s6_chords", "name": "chordino", "version": "1.0.0"},
|
||||
{"stage": "s7_strumming", "name": "librosa-onsets", "version": "1.0.0"}
|
||||
],
|
||||
"created_at": "2026-11-02T10:00:00Z",
|
||||
"stages_done": ["s1_extract", "s2_stems", "s3_lyrics", "s4_pitch", "s5_tempo", "s6_chords", "s7_strumming"],
|
||||
"stages_failed": {}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.2 `tempo.json`
|
||||
Definiert den Zeitverlauf und die Beziehung zwischen Sekunden und Taktschlägen.
|
||||
|
||||
```json
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": {
|
||||
"stage": "s5_tempo",
|
||||
"model": "beat_this-final0",
|
||||
"model_version": "1.1.0",
|
||||
"params": {"min_tempo_change_bpm": 4.0}
|
||||
},
|
||||
"anchors": [
|
||||
{"sec": 0.52, "beat": 0.0, "bpm": 120.0}
|
||||
],
|
||||
"time_signature": {
|
||||
"numerator": 4,
|
||||
"denominator": 4
|
||||
},
|
||||
"downbeat_offset": 0
|
||||
}
|
||||
```
|
||||
|
||||
- **Regeln:**
|
||||
- Zwischen zwei aufeinanderfolgenden Ankern gilt ein konstantes Tempo (`bpm`).
|
||||
- `beat` ist eine Fließkommazahl (Viertelnoten).
|
||||
- Der letzte Anker gilt bis zum Ende des Songs.
|
||||
- Songs mit durchgehendem Tempo besitzen exakt **einen** Anker. Weitere Anker existieren nur bei echten Tempowechseln.
|
||||
|
||||
---
|
||||
|
||||
### 3.3 `vocals.json`
|
||||
Liedtext, Silbenaufteilung und Gesangstonhöhe.
|
||||
|
||||
```json
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": {
|
||||
"stage": "s4_pitch",
|
||||
"model": "torchcrepe-full",
|
||||
"model_version": "1.0.0",
|
||||
"params": {"hop_length_ms": 10, "voicing_threshold": 0.25}
|
||||
},
|
||||
"lines": [
|
||||
{
|
||||
"start": 12.34,
|
||||
"end": 15.80,
|
||||
"syllables": [
|
||||
{
|
||||
"text": "Hel",
|
||||
"start": 12.34,
|
||||
"end": 12.61,
|
||||
"midi": 64.0,
|
||||
"golden": false,
|
||||
"confidence": 0.88,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"text": "lo ",
|
||||
"start": 12.61,
|
||||
"end": 13.10,
|
||||
"midi": 62.0,
|
||||
"golden": false,
|
||||
"confidence": 0.92,
|
||||
"source": "auto"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `start` / `end`: Absoluter Beginn und Ende in Sekunden.
|
||||
- `midi`: Geglättete Median-Tonhöhe in Halbtönen (kontinuierlich, z. B. `64.0` = E4, `60.0` = C4).
|
||||
- Oktavlage entspricht dem Original.
|
||||
- Leerzeichen zwischen Wörtern hängen an der jeweils letzten Silbe (z. B. `"lo "`).
|
||||
|
||||
---
|
||||
|
||||
### 3.4 `chords.json`
|
||||
Harmonischer Ablauf in musikalischen Zählzeiten (Beats).
|
||||
|
||||
```json
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": {
|
||||
"stage": "s6_chords",
|
||||
"model": "chordino",
|
||||
"model_version": "1.0.0",
|
||||
"params": {"backend": "chordino", "quantization": "beat"}
|
||||
},
|
||||
"chords": [
|
||||
{
|
||||
"start_beat": 0.0,
|
||||
"end_beat": 4.0,
|
||||
"label": "Am",
|
||||
"root": "A",
|
||||
"quality": "min",
|
||||
"bass": null,
|
||||
"confidence": 0.85,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"start_beat": 4.0,
|
||||
"end_beat": 8.0,
|
||||
"label": "F/A",
|
||||
"root": "F",
|
||||
"quality": "maj",
|
||||
"bass": "A",
|
||||
"confidence": 0.80,
|
||||
"source": "auto"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `label`: Harte-Notation (`C`, `Am`, `G7`, `Dsus4`, `F/A`, `N` für kein Akkord).
|
||||
- `start_beat` / `end_beat`: Start- und Endzeitpunkt in Viertelnoten-Beats.
|
||||
|
||||
---
|
||||
|
||||
### 3.5 `strumming.json`
|
||||
Anschlagereignisse und Rhythmusmuster für Begleitinstrumente.
|
||||
|
||||
```json
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": {
|
||||
"stage": "s7_strumming",
|
||||
"model": "librosa-onsets",
|
||||
"model_version": "1.0.0",
|
||||
"params": {"grid": "8th", "status": "experimental"}
|
||||
},
|
||||
"events": [
|
||||
{
|
||||
"beat": 0.0,
|
||||
"direction": "down",
|
||||
"strength": 0.9,
|
||||
"confidence": 0.85,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"beat": 0.5,
|
||||
"direction": "up",
|
||||
"strength": 0.6,
|
||||
"confidence": 0.70,
|
||||
"source": "auto"
|
||||
}
|
||||
],
|
||||
"patterns": [
|
||||
{
|
||||
"start_beat": 0.0,
|
||||
"end_beat": 16.0,
|
||||
"pattern": "D . D U . U D U",
|
||||
"grid": "8th"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `events`: Einzelereignisse auf dem Beat-Raster mit Anschlagstärke (`0.0` bis `1.0`) und Richtung (`"down"`, `"up"`, `"unknown"`).
|
||||
- `patterns`: Aggregierte 8tel- oder 16tel-Muster pro Taktgruppe (`.` repräsentiert Pausen).
|
||||
|
||||
---
|
||||
|
||||
### 3.6 `song.txt` (UltraStar Deluxe)
|
||||
Exportformat für Karaoke-Software:
|
||||
- Header: `#TITLE`, `#ARTIST`, `#MP3`, `#BPM` ($4 \times$ Viertelnoten-BPM), `#GAP` (Offset in ms), `#LANGUAGE`.
|
||||
- Notenzeilen: `: <start_beat> <duration> <pitch_rel_c4> <text>`
|
||||
- Pausen/Umbruch: `- <beat>`
|
||||
- Ende: `E`
|
||||
26
examples/demo_song/chords.json
Normal file
26
examples/demo_song/chords.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": null,
|
||||
"chords": [
|
||||
{
|
||||
"start_beat": 0.0,
|
||||
"end_beat": 4.0,
|
||||
"label": "Am",
|
||||
"root": "A",
|
||||
"quality": "min",
|
||||
"bass": "A",
|
||||
"confidence": 0.9,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"start_beat": 4.0,
|
||||
"end_beat": 6.0,
|
||||
"label": "C",
|
||||
"root": "C",
|
||||
"quality": "maj",
|
||||
"bass": "C",
|
||||
"confidence": 0.88,
|
||||
"source": "auto"
|
||||
}
|
||||
]
|
||||
}
|
||||
53
examples/demo_song/meta.json
Normal file
53
examples/demo_song/meta.json
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": null,
|
||||
"title": "Demo Song",
|
||||
"artist": "Synthetic Artist",
|
||||
"language": "en",
|
||||
"duration_sec": 3.0,
|
||||
"source_file": {
|
||||
"path": "examples/demo_song/stems/vocals.wav",
|
||||
"sha256": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"size_bytes": 529200
|
||||
},
|
||||
"key": "Am",
|
||||
"capo": 0,
|
||||
"models_used": [
|
||||
{
|
||||
"stage": "s2_stems",
|
||||
"name": "htdemucs",
|
||||
"version": "v4"
|
||||
},
|
||||
{
|
||||
"stage": "s3_lyrics",
|
||||
"name": "faster-whisper",
|
||||
"version": "large-v3"
|
||||
},
|
||||
{
|
||||
"stage": "s4_pitch",
|
||||
"name": "torchcrepe",
|
||||
"version": "tiny"
|
||||
},
|
||||
{
|
||||
"stage": "s5_tempo",
|
||||
"name": "beat-this",
|
||||
"version": "final0"
|
||||
},
|
||||
{
|
||||
"stage": "s6_chords",
|
||||
"name": "chord-extractor",
|
||||
"version": "0.2"
|
||||
}
|
||||
],
|
||||
"created_at": "2026-11-02T12:00:00Z",
|
||||
"stages_done": [
|
||||
"s1_extract",
|
||||
"s2_stems",
|
||||
"s3_lyrics",
|
||||
"s4_pitch",
|
||||
"s5_tempo",
|
||||
"s6_chords",
|
||||
"s7_strumming"
|
||||
],
|
||||
"stages_failed": {}
|
||||
}
|
||||
10
examples/demo_song/song.txt
Normal file
10
examples/demo_song/song.txt
Normal file
@ -0,0 +1,10 @@
|
||||
#TITLE:Demo Song
|
||||
#ARTIST:Synthetic Artist
|
||||
#MP3:stems/vocals.wav
|
||||
#BPM:480.00
|
||||
#GAP:500
|
||||
#LANGUAGE:en
|
||||
: 0 4 -3 Hel
|
||||
: 4 4 -3 lo
|
||||
: 8 8 0 world
|
||||
E
|
||||
BIN
examples/demo_song/stems/bass.wav
Normal file
BIN
examples/demo_song/stems/bass.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/drums.wav
Normal file
BIN
examples/demo_song/stems/drums.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/instrumental.wav
Normal file
BIN
examples/demo_song/stems/instrumental.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/other.wav
Normal file
BIN
examples/demo_song/stems/other.wav
Normal file
Binary file not shown.
BIN
examples/demo_song/stems/vocals.wav
Normal file
BIN
examples/demo_song/stems/vocals.wav
Normal file
Binary file not shown.
42
examples/demo_song/strumming.json
Normal file
42
examples/demo_song/strumming.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": null,
|
||||
"events": [
|
||||
{
|
||||
"beat": 0.0,
|
||||
"direction": "down",
|
||||
"strength": 0.9,
|
||||
"confidence": 0.85,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"beat": 0.5,
|
||||
"direction": "up",
|
||||
"strength": 0.7,
|
||||
"confidence": 0.8,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"beat": 1.0,
|
||||
"direction": "down",
|
||||
"strength": 0.85,
|
||||
"confidence": 0.85,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"beat": 1.5,
|
||||
"direction": "up",
|
||||
"strength": 0.75,
|
||||
"confidence": 0.82,
|
||||
"source": "auto"
|
||||
}
|
||||
],
|
||||
"patterns": [
|
||||
{
|
||||
"start_beat": 0.0,
|
||||
"end_beat": 4.0,
|
||||
"pattern": "D U D U",
|
||||
"grid": "8th"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
examples/demo_song/tempo.json
Normal file
16
examples/demo_song/tempo.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": null,
|
||||
"anchors": [
|
||||
{
|
||||
"sec": 0.0,
|
||||
"beat": 0.0,
|
||||
"bpm": 120.0
|
||||
}
|
||||
],
|
||||
"time_signature": {
|
||||
"numerator": 4,
|
||||
"denominator": 4
|
||||
},
|
||||
"downbeat_offset": 0
|
||||
}
|
||||
39
examples/demo_song/vocals.json
Normal file
39
examples/demo_song/vocals.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"generated_by": null,
|
||||
"lines": [
|
||||
{
|
||||
"start": 0.5,
|
||||
"end": 2.5,
|
||||
"syllables": [
|
||||
{
|
||||
"text": "Hel",
|
||||
"start": 0.5,
|
||||
"end": 1.0,
|
||||
"midi": 57.0,
|
||||
"golden": false,
|
||||
"confidence": 0.95,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"text": "lo ",
|
||||
"start": 1.0,
|
||||
"end": 1.5,
|
||||
"midi": 57.0,
|
||||
"golden": false,
|
||||
"confidence": 0.92,
|
||||
"source": "auto"
|
||||
},
|
||||
{
|
||||
"text": "world",
|
||||
"start": 1.5,
|
||||
"end": 2.5,
|
||||
"midi": 60.0,
|
||||
"golden": false,
|
||||
"confidence": 0.98,
|
||||
"source": "auto"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -18,6 +18,8 @@ dependencies = [
|
||||
"faster-whisper>=1.0.0",
|
||||
"scipy>=1.12.0",
|
||||
"jiwer>=3.0.0",
|
||||
"beat-this>=1.1.0",
|
||||
"chord-extractor>=0.1.3",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
@ -53,6 +55,9 @@ explicit = true
|
||||
torch = { index = "pytorch-cpu" }
|
||||
torchaudio = { index = "pytorch-cpu" }
|
||||
|
||||
[tool.uv.extra-build-dependencies]
|
||||
vamp = ["numpy"]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 120
|
||||
target-version = "py312"
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import UTC, datetime
|
||||
@ -10,6 +11,8 @@ from typing import Any
|
||||
|
||||
from songsplit.schema.meta import MetaDocument, ModelInfo, SourceFileInfo
|
||||
|
||||
logger = logging.getLogger("songsplit.pipeline")
|
||||
|
||||
|
||||
def compute_file_sha256(file_path: Path, chunk_size: int = 65536) -> str:
|
||||
"""Compute sha256 hash of a file."""
|
||||
@ -225,6 +228,7 @@ class PipelineRunner:
|
||||
failed_deps = [d for d in stage.dependencies if d in failed_stages]
|
||||
if failed_deps:
|
||||
msg = f"Skipping {stage.name} because dependencies failed: {failed_deps}"
|
||||
logger.warning(msg)
|
||||
sys.stderr.write(f"[WARN] {msg}\n")
|
||||
meta.stages_failed[stage.name] = msg
|
||||
failed_stages.add(stage.name)
|
||||
@ -232,11 +236,13 @@ class PipelineRunner:
|
||||
|
||||
# Check cache
|
||||
if not ctx.force and stage.is_cached(ctx):
|
||||
logger.info("Stage %s is up to date (cached).", stage.name)
|
||||
sys.stderr.write(f"[INFO] Stage {stage.name} is up to date (cached).\n")
|
||||
if stage.name not in meta.stages_done:
|
||||
meta.stages_done.append(stage.name)
|
||||
continue
|
||||
|
||||
logger.info("Running stage: %s...", stage.name)
|
||||
sys.stderr.write(f"[INFO] Running stage: {stage.name}...\n")
|
||||
try:
|
||||
cache_hash = stage.compute_cache_hash(ctx)
|
||||
@ -259,6 +265,7 @@ class PipelineRunner:
|
||||
|
||||
except Exception as e:
|
||||
err_msg = f"{type(e).__name__}: {str(e)}"
|
||||
logger.error("Stage %s failed: %s", stage.name, err_msg, exc_info=True)
|
||||
sys.stderr.write(f"[ERROR] Stage {stage.name} failed: {err_msg}\n")
|
||||
meta.stages_failed[stage.name] = err_msg
|
||||
failed_stages.add(stage.name)
|
||||
|
||||
@ -1,27 +1,102 @@
|
||||
"""Stage 5: Beat and downbeat tracking with beat_this -> tempo.json."""
|
||||
"""Stage 5: Beat and downbeat tracking -> tempo.json."""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.config import config
|
||||
from songsplit.pipeline.runner import PipelineContext, Stage
|
||||
from songsplit.schema.base import GeneratedBy
|
||||
from songsplit.tempo import build_tempo_map_from_beats, generate_click_track
|
||||
|
||||
|
||||
class TempoStage(Stage):
|
||||
"""Stage 5 tracks beats and downbeats and builds a clean Tempo-Map."""
|
||||
|
||||
name = "s5_tempo"
|
||||
version = "1.0.0"
|
||||
model_name = "beat_this"
|
||||
model_version = "1.0.0"
|
||||
model_version = "1.1.0"
|
||||
dependencies = ["s2_stems"]
|
||||
|
||||
def __init__(self, model_name: str = "beat_this"):
|
||||
self.model_name = model_name
|
||||
|
||||
def get_inputs(self, ctx: PipelineContext) -> list[Path]:
|
||||
return [ctx.stems_dir / "instrumental.wav"]
|
||||
drums_path = ctx.stems_dir / "drums.wav"
|
||||
inst_path = ctx.stems_dir / "instrumental.wav"
|
||||
if drums_path.exists():
|
||||
return [drums_path]
|
||||
return [inst_path]
|
||||
|
||||
def get_outputs(self, ctx: PipelineContext) -> list[Path]:
|
||||
return [ctx.output_dir / "tempo.json"]
|
||||
|
||||
def get_params(self, ctx: PipelineContext) -> dict[str, Any]:
|
||||
return {}
|
||||
return {
|
||||
"model": "final0",
|
||||
"min_tempo_change_bpm": 4.0,
|
||||
}
|
||||
|
||||
def run(self, ctx: PipelineContext) -> None:
|
||||
# Implementation in M3
|
||||
raise NotImplementedError("Stage s5_tempo will be implemented in M3.")
|
||||
input_audio = self.get_inputs(ctx)[0]
|
||||
if not input_audio.exists():
|
||||
raise FileNotFoundError(f"Input audio for tempo tracking not found: {input_audio}")
|
||||
|
||||
beats = None
|
||||
downbeats = None
|
||||
|
||||
# 1. Try beat_this deep learning model
|
||||
try:
|
||||
from beat_this.inference import File2Beats
|
||||
|
||||
device_str = config.get_device(self.name)
|
||||
if device_str.startswith("cuda"):
|
||||
import torch
|
||||
|
||||
if not torch.cuda.is_available():
|
||||
device_str = "cpu"
|
||||
|
||||
file2beats = File2Beats(checkpoint_path="final0", device=device_str)
|
||||
beats, downbeats = file2beats(str(input_audio))
|
||||
self.model_name = "beat_this-final0"
|
||||
except Exception:
|
||||
# 2. Fallback to librosa beat tracking if beat_this is offline or fails
|
||||
import librosa
|
||||
|
||||
y, sr = librosa.load(str(input_audio), sr=22050, mono=True)
|
||||
tempo_est, beat_frames = librosa.beat.beat_track(y=y, sr=sr)
|
||||
beats = librosa.frames_to_time(beat_frames, sr=sr)
|
||||
# Estimate downbeats as every 4th beat
|
||||
downbeats = beats[::4] if len(beats) >= 4 else beats
|
||||
self.model_name = "librosa-beat_track"
|
||||
|
||||
# Build clean tempo map
|
||||
params = self.get_params(ctx)
|
||||
tempo_doc = build_tempo_map_from_beats(
|
||||
beats,
|
||||
downbeats,
|
||||
min_tempo_change_bpm=params.get("min_tempo_change_bpm", 4.0),
|
||||
)
|
||||
|
||||
tempo_doc.schema_version = "1.0"
|
||||
tempo_doc.generated_by = GeneratedBy(
|
||||
stage=self.name,
|
||||
model=self.model_name,
|
||||
model_version=self.version,
|
||||
params=params,
|
||||
)
|
||||
|
||||
# Save tempo.json
|
||||
output_file = self.get_outputs(ctx)[0]
|
||||
output_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
f.write(tempo_doc.model_dump_json(indent=2))
|
||||
|
||||
# Generate click track for auditory verification (saved in .cache/click_track.wav)
|
||||
info = sf.info(str(input_audio))
|
||||
duration = info.duration
|
||||
click_wav = generate_click_track(tempo_doc, duration_sec=duration)
|
||||
click_out_path = ctx.cache_dir / "click_track.wav"
|
||||
sf.write(str(click_out_path), click_wav, 44100, subtype="PCM_16")
|
||||
|
||||
@ -1,18 +1,173 @@
|
||||
"""Stage 6: Chord recognition -> chords.json."""
|
||||
"""Stage 6: Chord recognition -> chords.json with beat-synchronous quantization."""
|
||||
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import librosa
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.pipeline.runner import PipelineContext, Stage
|
||||
from songsplit.schema.base import GeneratedBy
|
||||
from songsplit.schema.chords import ChordEvent, ChordsDocument
|
||||
from songsplit.schema.tempo import TempoDocument
|
||||
from songsplit.tempo import beat_to_sec, sec_to_beat
|
||||
|
||||
PITCH_CLASSES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
|
||||
|
||||
|
||||
def parse_harte_chord(label: str) -> tuple[str | None, str | None, str | None]:
|
||||
"""Parse Harte chord label into (root, quality, bass).
|
||||
|
||||
Examples:
|
||||
- 'C' -> ('C', 'maj', None)
|
||||
- 'Am' -> ('A', 'min', None)
|
||||
- 'G7' -> ('G', '7', None)
|
||||
- 'Dsus4' -> ('D', 'sus4', None)
|
||||
- 'F/A' -> ('F', 'maj', 'A')
|
||||
- 'N' -> (None, None, None)
|
||||
"""
|
||||
clean = label.strip()
|
||||
if not clean or clean.upper() in ("N", "NONE", "NO CHORD"):
|
||||
return None, None, None
|
||||
|
||||
# Check for bass note (slash chord): F/A
|
||||
bass = None
|
||||
if "/" in clean:
|
||||
parts = clean.split("/", 1)
|
||||
clean = parts[0]
|
||||
bass = parts[1].strip()
|
||||
|
||||
# Match Root (e.g. C, C#, Db, Eb, etc.)
|
||||
match = re.match(r"^([A-G][#b]?)(.*)$", clean)
|
||||
if not match:
|
||||
return clean, None, bass
|
||||
|
||||
root, rest = match.groups()
|
||||
|
||||
# Determine quality
|
||||
rest = rest.strip()
|
||||
if not rest or rest == "maj":
|
||||
quality = "maj"
|
||||
elif rest in ("m", "min"):
|
||||
quality = "min"
|
||||
elif rest in ("7", "dom7"):
|
||||
quality = "7"
|
||||
elif rest in ("m7", "min7"):
|
||||
quality = "min7"
|
||||
elif rest in ("maj7", "M7"):
|
||||
quality = "maj7"
|
||||
elif "sus4" in rest:
|
||||
quality = "sus4"
|
||||
elif "sus2" in rest:
|
||||
quality = "sus2"
|
||||
elif "dim" in rest:
|
||||
quality = "dim"
|
||||
elif "aug" in rest:
|
||||
quality = "aug"
|
||||
else:
|
||||
quality = rest
|
||||
|
||||
return root, quality, bass
|
||||
|
||||
|
||||
# Krumhansl-Schmuckler Key Profiles for key detection
|
||||
MAJOR_PROFILE = np.array([6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, 5.19, 2.39, 3.66, 2.29, 2.88])
|
||||
MINOR_PROFILE = np.array([6.33, 2.68, 3.52, 5.38, 2.60, 3.53, 2.54, 4.75, 3.98, 2.69, 3.34, 3.17])
|
||||
|
||||
|
||||
def estimate_key(chroma_mean: np.ndarray) -> str:
|
||||
"""Estimate musical key from mean chromagram profile."""
|
||||
best_key = "C"
|
||||
best_corr = -1.0
|
||||
|
||||
chroma_norm = chroma_mean - np.mean(chroma_mean)
|
||||
|
||||
for i, pc in enumerate(PITCH_CLASSES):
|
||||
# Major correlation
|
||||
maj_roll = np.roll(MAJOR_PROFILE, i)
|
||||
maj_norm = maj_roll - np.mean(maj_roll)
|
||||
corr_maj = float(np.corrcoef(chroma_norm, maj_norm)[0, 1])
|
||||
if corr_maj > best_corr:
|
||||
best_corr = corr_maj
|
||||
best_key = f"{pc}"
|
||||
|
||||
# Minor correlation
|
||||
min_roll = np.roll(MINOR_PROFILE, i)
|
||||
min_norm = min_roll - np.mean(min_roll)
|
||||
corr_min = float(np.corrcoef(chroma_norm, min_norm)[0, 1])
|
||||
if corr_min > best_corr:
|
||||
best_corr = corr_min
|
||||
best_key = f"{pc}m"
|
||||
|
||||
return best_key
|
||||
|
||||
|
||||
def extract_chords_template(audio_data: np.ndarray, sr: int) -> list[tuple[float, str]]:
|
||||
"""Chroma-based chord template recognition as baseline/comparison."""
|
||||
if audio_data.ndim > 1:
|
||||
audio_data = audio_data.mean(axis=-1)
|
||||
|
||||
# Compute Chroma CQT
|
||||
hop_length = 2048
|
||||
chroma = librosa.feature.chroma_cqt(y=audio_data, sr=sr, hop_length=hop_length)
|
||||
times = librosa.frames_to_time(np.arange(chroma.shape[1]), sr=sr, hop_length=hop_length)
|
||||
|
||||
# 12 Major and 12 Minor chord templates
|
||||
templates: list[tuple[str, np.ndarray]] = []
|
||||
for i, root in enumerate(PITCH_CLASSES):
|
||||
# Major triad: root, +4, +7
|
||||
maj = np.zeros(12)
|
||||
maj[i] = 1.0
|
||||
maj[(i + 4) % 12] = 1.0
|
||||
maj[(i + 7) % 12] = 1.0
|
||||
templates.append((root, maj / np.linalg.norm(maj)))
|
||||
|
||||
# Minor triad: root, +3, +7
|
||||
min_t = np.zeros(12)
|
||||
min_t[i] = 1.0
|
||||
min_t[(i + 3) % 12] = 1.0
|
||||
min_t[(i + 7) % 12] = 1.0
|
||||
templates.append((f"{root}m", min_t / np.linalg.norm(min_t)))
|
||||
|
||||
raw_chords: list[tuple[float, str]] = []
|
||||
for t_idx, t_sec in enumerate(times):
|
||||
frame = chroma[:, t_idx]
|
||||
norm = np.linalg.norm(frame)
|
||||
if norm < 1e-4:
|
||||
raw_chords.append((float(t_sec), "N"))
|
||||
continue
|
||||
|
||||
frame_norm = frame / norm
|
||||
best_chord = "N"
|
||||
best_sim = -1.0
|
||||
|
||||
for chord_name, template in templates:
|
||||
sim = float(np.dot(frame_norm, template))
|
||||
if sim > best_sim:
|
||||
best_sim = sim
|
||||
best_chord = chord_name
|
||||
|
||||
raw_chords.append((float(t_sec), best_chord))
|
||||
|
||||
return raw_chords
|
||||
|
||||
|
||||
class ChordsStage(Stage):
|
||||
"""Stage 6 recognizes musical chords and quantizes them onto the beat grid."""
|
||||
|
||||
name = "s6_chords"
|
||||
version = "1.0.0"
|
||||
model_name = "chordino"
|
||||
model_version = "1.0.0"
|
||||
dependencies = ["s5_tempo"]
|
||||
|
||||
def __init__(self, backend: str = "chordino"):
|
||||
self.backend = backend
|
||||
self.model_name = backend
|
||||
|
||||
def get_inputs(self, ctx: PipelineContext) -> list[Path]:
|
||||
return [
|
||||
ctx.stems_dir / "instrumental.wav",
|
||||
@ -23,8 +178,128 @@ class ChordsStage(Stage):
|
||||
return [ctx.output_dir / "chords.json"]
|
||||
|
||||
def get_params(self, ctx: PipelineContext) -> dict[str, Any]:
|
||||
return {"backend": "chordino"}
|
||||
return {
|
||||
"backend": self.backend,
|
||||
"quantization": "beat",
|
||||
}
|
||||
|
||||
def run(self, ctx: PipelineContext) -> None:
|
||||
# Implementation in M4
|
||||
raise NotImplementedError("Stage s6_chords will be implemented in M4.")
|
||||
inst_path, tempo_path = self.get_inputs(ctx)
|
||||
if not inst_path.exists():
|
||||
raise FileNotFoundError(f"Instrumental stem not found: {inst_path}")
|
||||
if not tempo_path.exists():
|
||||
raise FileNotFoundError(f"tempo.json not found: {tempo_path}")
|
||||
|
||||
with open(tempo_path, encoding="utf-8") as f:
|
||||
tempo_doc = TempoDocument.model_validate(json.load(f))
|
||||
|
||||
audio_data, sr = sf.read(str(inst_path), dtype="float32")
|
||||
|
||||
# Estimate key and save in meta.json
|
||||
mono_audio = audio_data.mean(axis=-1) if audio_data.ndim > 1 else audio_data
|
||||
chroma = librosa.feature.chroma_cqt(y=mono_audio, sr=sr)
|
||||
detected_key = estimate_key(chroma.mean(axis=1))
|
||||
|
||||
meta = ctx.load_or_init_meta()
|
||||
meta.key = detected_key
|
||||
ctx.save_meta(meta)
|
||||
|
||||
params = self.get_params(ctx)
|
||||
backend = params.get("backend", "chordino")
|
||||
|
||||
time_chord_pairs: list[tuple[float, str]] = []
|
||||
|
||||
if backend == "chordino":
|
||||
try:
|
||||
from chord_extractor import ChordExtractor
|
||||
|
||||
extractor = ChordExtractor()
|
||||
chord_changes = extractor.extract(str(inst_path))
|
||||
for change in chord_changes:
|
||||
time_chord_pairs.append((float(change.timestamp), str(change.chord)))
|
||||
except Exception:
|
||||
# Fallback to template if chordino vamp is unavailable
|
||||
time_chord_pairs = extract_chords_template(audio_data, sr)
|
||||
self.model_name = "chroma-template"
|
||||
else:
|
||||
time_chord_pairs = extract_chords_template(audio_data, sr)
|
||||
self.model_name = "chroma-template"
|
||||
|
||||
# Beat-synchronous quantization
|
||||
info = sf.info(str(inst_path))
|
||||
total_duration_sec = info.duration
|
||||
|
||||
total_beats = int(np.ceil(sec_to_beat(total_duration_sec, tempo_doc)))
|
||||
total_beats = max(1, total_beats)
|
||||
|
||||
# Sample dominant chord per beat
|
||||
beat_chords: list[str] = []
|
||||
for b in range(total_beats):
|
||||
b_start_sec = beat_to_sec(float(b), tempo_doc)
|
||||
b_end_sec = beat_to_sec(float(b + 1), tempo_doc)
|
||||
|
||||
# Find chords active in this beat interval
|
||||
active = [ch for t, ch in time_chord_pairs if b_start_sec <= t < b_end_sec]
|
||||
if active:
|
||||
# Most frequent chord in this beat
|
||||
dom = max(set(active), key=active.count)
|
||||
else:
|
||||
# Chord active before b_start_sec
|
||||
prior = [ch for t, ch in time_chord_pairs if t <= b_start_sec]
|
||||
dom = prior[-1] if prior else "N"
|
||||
beat_chords.append(dom)
|
||||
|
||||
# Merge consecutive identical beat chords into ChordEvent segments
|
||||
chord_events: list[ChordEvent] = []
|
||||
cur_chord = beat_chords[0]
|
||||
cur_start_beat = 0.0
|
||||
|
||||
for b_idx in range(1, len(beat_chords)):
|
||||
ch = beat_chords[b_idx]
|
||||
if ch != cur_chord:
|
||||
root, quality, bass = parse_harte_chord(cur_chord)
|
||||
chord_events.append(
|
||||
ChordEvent(
|
||||
start_beat=cur_start_beat,
|
||||
end_beat=float(b_idx),
|
||||
label=cur_chord,
|
||||
root=root,
|
||||
quality=quality,
|
||||
bass=bass,
|
||||
confidence=0.85 if cur_chord != "N" else 0.5,
|
||||
source="auto",
|
||||
)
|
||||
)
|
||||
cur_chord = ch
|
||||
cur_start_beat = float(b_idx)
|
||||
|
||||
# Final segment
|
||||
root, quality, bass = parse_harte_chord(cur_chord)
|
||||
chord_events.append(
|
||||
ChordEvent(
|
||||
start_beat=cur_start_beat,
|
||||
end_beat=float(len(beat_chords)),
|
||||
label=cur_chord,
|
||||
root=root,
|
||||
quality=quality,
|
||||
bass=bass,
|
||||
confidence=0.85 if cur_chord != "N" else 0.5,
|
||||
source="auto",
|
||||
)
|
||||
)
|
||||
|
||||
chords_doc = ChordsDocument(
|
||||
schema_version="1.0",
|
||||
generated_by=GeneratedBy(
|
||||
stage=self.name,
|
||||
model=self.model_name,
|
||||
model_version=self.version,
|
||||
params=params,
|
||||
),
|
||||
chords=chord_events,
|
||||
)
|
||||
|
||||
output_file = self.get_outputs(ctx)[0]
|
||||
output_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
f.write(chords_doc.model_dump_json(indent=2))
|
||||
|
||||
@ -1,30 +1,226 @@
|
||||
"""Stage 7: Strumming pattern analysis -> strumming.json."""
|
||||
"""Stage 7: Strumming pattern analysis -> strumming.json (experimental)."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import librosa
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.pipeline.runner import PipelineContext, Stage
|
||||
from songsplit.schema.base import GeneratedBy
|
||||
from songsplit.schema.strumming import StrumDirection, StrumEvent, StrummingDocument, StrumPattern
|
||||
from songsplit.schema.tempo import TempoDocument
|
||||
from songsplit.tempo import sec_to_beat
|
||||
|
||||
|
||||
def estimate_strum_direction(
|
||||
audio: np.ndarray,
|
||||
sr: int,
|
||||
onset_sec: float,
|
||||
beat: float,
|
||||
) -> tuple[StrumDirection, float]:
|
||||
"""Estimate strumming direction (down vs up) from spectral centroid gradient and beat phase."""
|
||||
# Analyze 50ms window right after onset
|
||||
start_sample = int(onset_sec * sr)
|
||||
window_samples = int(sr * 0.05)
|
||||
end_sample = min(len(audio), start_sample + window_samples)
|
||||
|
||||
direction: StrumDirection = "down"
|
||||
confidence = 0.5
|
||||
|
||||
if end_sample - start_sample > 256:
|
||||
chunk = audio[start_sample:end_sample]
|
||||
# Compute spectral centroid
|
||||
centroids = librosa.feature.spectral_centroid(y=chunk, sr=sr, hop_length=128)[0]
|
||||
if len(centroids) >= 2:
|
||||
centroid_slope = centroids[-1] - centroids[0]
|
||||
# Downstrum hits bass strings first then treble (centroid moves higher or bass-dominant)
|
||||
if centroid_slope > 0:
|
||||
direction = "down"
|
||||
confidence += 0.1
|
||||
else:
|
||||
direction = "up"
|
||||
confidence += 0.1
|
||||
|
||||
# Beat phase prior: On-beats (integer beats) are predominantly down strums
|
||||
beat_frac = beat - np.floor(beat)
|
||||
# Close to on-beat (0.0): down strum
|
||||
if beat_frac < 0.25 or beat_frac > 0.75:
|
||||
if direction == "down":
|
||||
confidence = min(0.85, confidence + 0.15)
|
||||
else:
|
||||
direction = "down"
|
||||
confidence = 0.6
|
||||
# Close to off-beat (0.5): up strum
|
||||
elif 0.35 <= beat_frac <= 0.65:
|
||||
if direction == "up":
|
||||
confidence = min(0.85, confidence + 0.15)
|
||||
else:
|
||||
direction = "up"
|
||||
confidence = 0.6
|
||||
|
||||
return direction, round(confidence, 2)
|
||||
|
||||
|
||||
def aggregate_strum_patterns(
|
||||
events: list[StrumEvent],
|
||||
total_beats: float,
|
||||
grid: str = "8th",
|
||||
pattern_beats: float = 4.0,
|
||||
section_beats: float = 16.0,
|
||||
) -> list[StrumPattern]:
|
||||
"""Condense discrete strumming events into representative pattern strings (e.g. 'D . D U . U D U')."""
|
||||
if not events:
|
||||
return []
|
||||
|
||||
grid_step = 0.5 if grid == "8th" else 0.25
|
||||
slots_per_pattern = int(round(pattern_beats / grid_step))
|
||||
|
||||
patterns: list[StrumPattern] = []
|
||||
num_sections = int(np.ceil(total_beats / section_beats))
|
||||
|
||||
for sec_idx in range(num_sections):
|
||||
sec_start = sec_idx * section_beats
|
||||
sec_end = min(total_beats, sec_start + section_beats)
|
||||
|
||||
# Gather events in this section
|
||||
sec_events = [e for e in events if sec_start <= e.beat < sec_end]
|
||||
if not sec_events:
|
||||
continue
|
||||
|
||||
# Vote for each slot in the pattern (modulo pattern_beats)
|
||||
slot_votes: list[list[str]] = [[] for _ in range(slots_per_pattern)]
|
||||
for e in sec_events:
|
||||
rel_beat = (e.beat - sec_start) % pattern_beats
|
||||
slot_idx = int(round(rel_beat / grid_step)) % slots_per_pattern
|
||||
symbol = "D" if e.direction == "down" else "U"
|
||||
slot_votes[slot_idx].append(symbol)
|
||||
|
||||
pattern_tokens = []
|
||||
for votes in slot_votes:
|
||||
if votes:
|
||||
# Majority symbol
|
||||
symbol = "D" if votes.count("D") >= votes.count("U") else "U"
|
||||
pattern_tokens.append(symbol)
|
||||
else:
|
||||
pattern_tokens.append(".")
|
||||
|
||||
pattern_str = " ".join(pattern_tokens)
|
||||
patterns.append(
|
||||
StrumPattern(
|
||||
start_beat=round(sec_start, 2),
|
||||
end_beat=round(sec_end, 2),
|
||||
pattern=pattern_str,
|
||||
grid=grid,
|
||||
)
|
||||
)
|
||||
|
||||
return patterns
|
||||
|
||||
|
||||
class StrummingStage(Stage):
|
||||
"""Stage 7 detects strumming onsets and patterns on the guitar/instrumental stem."""
|
||||
|
||||
name = "s7_strumming"
|
||||
version = "1.0.0"
|
||||
model_name = "librosa-onsets"
|
||||
model_version = "1.0.0"
|
||||
dependencies = ["s5_tempo"]
|
||||
|
||||
def __init__(self, grid: str = "8th"):
|
||||
self.grid = grid
|
||||
|
||||
def get_inputs(self, ctx: PipelineContext) -> list[Path]:
|
||||
return [
|
||||
ctx.stems_dir / "instrumental.wav",
|
||||
ctx.output_dir / "tempo.json",
|
||||
]
|
||||
guitar_path = ctx.stems_dir / "guitar.wav"
|
||||
inst_path = ctx.stems_dir / "instrumental.wav"
|
||||
if guitar_path.exists():
|
||||
return [guitar_path, ctx.output_dir / "tempo.json"]
|
||||
return [inst_path, ctx.output_dir / "tempo.json"]
|
||||
|
||||
def get_outputs(self, ctx: PipelineContext) -> list[Path]:
|
||||
return [ctx.output_dir / "strumming.json"]
|
||||
|
||||
def get_params(self, ctx: PipelineContext) -> dict[str, Any]:
|
||||
return {"grid": "8th"}
|
||||
return {
|
||||
"grid": self.grid,
|
||||
"status": "experimental",
|
||||
"hop_length": 512,
|
||||
}
|
||||
|
||||
def run(self, ctx: PipelineContext) -> None:
|
||||
# Implementation in M5
|
||||
raise NotImplementedError("Stage s7_strumming will be implemented in M5.")
|
||||
audio_path, tempo_path = self.get_inputs(ctx)
|
||||
if not audio_path.exists():
|
||||
raise FileNotFoundError(f"Input audio for strumming not found: {audio_path}")
|
||||
if not tempo_path.exists():
|
||||
raise FileNotFoundError(f"tempo.json not found: {tempo_path}")
|
||||
|
||||
with open(tempo_path, encoding="utf-8") as f:
|
||||
tempo_doc = TempoDocument.model_validate(json.load(f))
|
||||
|
||||
audio_data, sr = sf.read(str(audio_path), dtype="float32")
|
||||
mono_audio = audio_data.mean(axis=-1) if audio_data.ndim > 1 else audio_data
|
||||
|
||||
params = self.get_params(ctx)
|
||||
grid = params.get("grid", "8th")
|
||||
grid_step = 0.5 if grid == "8th" else 0.25
|
||||
|
||||
# Detect onsets
|
||||
onset_env = librosa.onset.onset_strength(y=mono_audio, sr=sr, hop_length=512)
|
||||
onset_frames = librosa.onset.onset_detect(
|
||||
onset_envelope=onset_env,
|
||||
sr=sr,
|
||||
hop_length=512,
|
||||
backtrack=True,
|
||||
)
|
||||
onset_times = librosa.frames_to_time(onset_frames, sr=sr, hop_length=512)
|
||||
|
||||
# Normalize onset envelope for strength computation
|
||||
max_env = float(np.max(onset_env)) if len(onset_env) > 0 and np.max(onset_env) > 0 else 1.0
|
||||
|
||||
# Map onsets onto beat grid
|
||||
raw_events_by_grid: dict[float, StrumEvent] = {}
|
||||
|
||||
for frame_idx, t_sec in zip(onset_frames, onset_times, strict=False):
|
||||
beat = sec_to_beat(float(t_sec), tempo_doc)
|
||||
if beat < 0:
|
||||
continue
|
||||
|
||||
quantized_beat = round(beat / grid_step) * grid_step
|
||||
strength = float(np.clip(onset_env[frame_idx] / max_env, 0.1, 1.0))
|
||||
direction, conf = estimate_strum_direction(mono_audio, sr, float(t_sec), quantized_beat)
|
||||
|
||||
# If multiple onsets fall on the same grid slot, keep the strongest
|
||||
if quantized_beat not in raw_events_by_grid or strength > raw_events_by_grid[quantized_beat].strength:
|
||||
raw_events_by_grid[quantized_beat] = StrumEvent(
|
||||
beat=round(quantized_beat, 3),
|
||||
direction=direction,
|
||||
strength=round(strength, 2),
|
||||
confidence=conf,
|
||||
source="auto",
|
||||
)
|
||||
|
||||
events = sorted(raw_events_by_grid.values(), key=lambda e: e.beat)
|
||||
|
||||
total_duration = sf.info(str(audio_path)).duration
|
||||
total_beats = sec_to_beat(total_duration, tempo_doc)
|
||||
|
||||
patterns = aggregate_strum_patterns(events, total_beats, grid=grid)
|
||||
|
||||
doc = StrummingDocument(
|
||||
schema_version="1.0",
|
||||
generated_by=GeneratedBy(
|
||||
stage=self.name,
|
||||
model=self.model_name,
|
||||
model_version=self.version,
|
||||
params=params,
|
||||
),
|
||||
events=events,
|
||||
patterns=patterns,
|
||||
)
|
||||
|
||||
output_file = self.get_outputs(ctx)[0]
|
||||
output_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
f.write(doc.model_dump_json(indent=2))
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
"""Tempo-Map conversion between seconds and musical beats.
|
||||
"""Tempo-Map conversion between seconds and musical beats and click track generation.
|
||||
|
||||
As defined in the concept:
|
||||
- Vocals are in seconds
|
||||
@ -8,7 +8,9 @@ As defined in the concept:
|
||||
|
||||
from bisect import bisect_right
|
||||
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument
|
||||
import numpy as np
|
||||
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument, TimeSignature
|
||||
|
||||
|
||||
def _get_sorted_anchors(tempo_map: TempoDocument) -> list[TempoAnchor]:
|
||||
@ -62,3 +64,146 @@ def beat_to_sec(beat: float, tempo_map: TempoDocument) -> float:
|
||||
anchor = anchors[idx]
|
||||
delta_beat = beat - anchor.beat
|
||||
return anchor.sec + delta_beat * (60.0 / anchor.bpm)
|
||||
|
||||
|
||||
def build_tempo_map_from_beats(
|
||||
beat_times: list[float] | np.ndarray,
|
||||
downbeat_times: list[float] | np.ndarray | None = None,
|
||||
min_tempo_change_bpm: float = 4.0,
|
||||
min_beats_for_change: int = 6,
|
||||
) -> TempoDocument:
|
||||
"""Construct a clean TempoDocument from raw detected beat and downbeat timestamps.
|
||||
|
||||
Only inserts new anchors for true persistent tempo changes, keeping single-anchor
|
||||
representation for songs with steady tempo.
|
||||
"""
|
||||
beats = np.sort(np.asarray(beat_times, dtype=np.float64))
|
||||
if len(beats) < 2:
|
||||
# Fallback default 120 BPM
|
||||
return TempoDocument(
|
||||
anchors=[TempoAnchor(sec=float(beats[0]) if len(beats) == 1 else 0.0, beat=0.0, bpm=120.0)],
|
||||
time_signature=TimeSignature(numerator=4, denominator=4),
|
||||
downbeat_offset=0,
|
||||
)
|
||||
|
||||
# Determine time signature and downbeat offset
|
||||
time_sig = TimeSignature(numerator=4, denominator=4)
|
||||
downbeat_offset = 0
|
||||
|
||||
if downbeat_times is not None and len(downbeat_times) >= 2:
|
||||
downbeats = np.sort(np.asarray(downbeat_times, dtype=np.float64))
|
||||
# Match downbeats to nearest beat indices
|
||||
downbeat_indices = []
|
||||
for db in downbeats:
|
||||
nearest_idx = int(np.argmin(np.abs(beats - db)))
|
||||
if np.abs(beats[nearest_idx] - db) < 0.2: # within 200ms
|
||||
downbeat_indices.append(nearest_idx)
|
||||
|
||||
if len(downbeat_indices) >= 2:
|
||||
intervals = np.diff(downbeat_indices)
|
||||
median_num = int(round(float(np.median(intervals))))
|
||||
if median_num in (3, 4, 6):
|
||||
time_sig = TimeSignature(numerator=median_num, denominator=4)
|
||||
downbeat_offset = downbeat_indices[0] % time_sig.numerator
|
||||
|
||||
# Calculate initial tempo from the beginning of the song
|
||||
ibis = np.diff(beats) # Inter-beat intervals in seconds
|
||||
valid_mask = (ibis > 0.15) & (ibis < 2.0) # 30 to 400 BPM
|
||||
clean_ibis = ibis[valid_mask]
|
||||
if len(clean_ibis) == 0:
|
||||
base_bpm = 120.0
|
||||
else:
|
||||
init_window = clean_ibis[: max(4, min_beats_for_change)]
|
||||
base_bpm = float(np.median(60.0 / init_window))
|
||||
|
||||
# Segment into anchors if persistent tempo shifts occur
|
||||
anchors = []
|
||||
current_sec = float(beats[0])
|
||||
current_beat = 0.0
|
||||
current_bpm = base_bpm
|
||||
|
||||
anchors.append(
|
||||
TempoAnchor(
|
||||
sec=round(current_sec, 3),
|
||||
beat=round(current_beat, 3),
|
||||
bpm=round(current_bpm, 2),
|
||||
)
|
||||
)
|
||||
|
||||
# Detect sustained tempo changes across window
|
||||
i = 0
|
||||
while i <= len(ibis) - min_beats_for_change:
|
||||
win_ibis = ibis[i : i + min_beats_for_change]
|
||||
# Check all intervals are valid
|
||||
if np.all((win_ibis > 0.15) & (win_ibis < 2.0)):
|
||||
win_bpms = 60.0 / win_ibis
|
||||
win_bpm = float(np.median(win_bpms))
|
||||
win_std = float(np.std(win_bpms))
|
||||
|
||||
# Trigger change only when the new section is stable and genuinely different
|
||||
if abs(win_bpm - current_bpm) >= min_tempo_change_bpm and win_std < (min_tempo_change_bpm * 0.75):
|
||||
new_sec = float(beats[i])
|
||||
# Calculate beat position from previous anchor
|
||||
elapsed_sec = new_sec - current_sec
|
||||
new_beat = current_beat + elapsed_sec * (current_bpm / 60.0)
|
||||
|
||||
current_sec = new_sec
|
||||
current_beat = new_beat
|
||||
current_bpm = win_bpm
|
||||
|
||||
anchors.append(
|
||||
TempoAnchor(
|
||||
sec=round(current_sec, 3),
|
||||
beat=round(current_beat, 3),
|
||||
bpm=round(current_bpm, 2),
|
||||
)
|
||||
)
|
||||
i += min_beats_for_change
|
||||
continue
|
||||
i += 1
|
||||
|
||||
return TempoDocument(
|
||||
anchors=anchors,
|
||||
time_signature=time_sig,
|
||||
downbeat_offset=downbeat_offset,
|
||||
)
|
||||
|
||||
|
||||
def generate_click_track(
|
||||
tempo_map: TempoDocument,
|
||||
duration_sec: float,
|
||||
sr: int = 44100,
|
||||
) -> np.ndarray:
|
||||
"""Generate a click track waveform aligned to the TempoDocument.
|
||||
|
||||
Downbeats receive a distinct high click (1600 Hz), regular beats a low click (800 Hz).
|
||||
"""
|
||||
total_samples = int(duration_sec * sr)
|
||||
click_audio = np.zeros(total_samples, dtype=np.float32)
|
||||
|
||||
click_len = int(sr * 0.02) # 20 ms
|
||||
t_click = np.linspace(0, 0.02, click_len, endpoint=False)
|
||||
envelope = np.exp(-t_click / 0.005).astype(np.float32)
|
||||
|
||||
high_click = (0.7 * np.sin(2 * np.pi * 1600.0 * t_click) * envelope).astype(np.float32)
|
||||
low_click = (0.5 * np.sin(2 * np.pi * 800.0 * t_click) * envelope).astype(np.float32)
|
||||
|
||||
# Step through beats from 0 until duration_sec
|
||||
num = tempo_map.time_signature.numerator
|
||||
offset = tempo_map.downbeat_offset
|
||||
|
||||
beat = 0.0
|
||||
while True:
|
||||
sec = beat_to_sec(beat, tempo_map)
|
||||
if sec > duration_sec:
|
||||
break
|
||||
if sec >= 0:
|
||||
idx = int(sec * sr)
|
||||
if idx + click_len <= total_samples:
|
||||
# Check if this beat is a downbeat
|
||||
is_downbeat = (int(round(beat)) % num) == (offset % num)
|
||||
sample_click = high_click if is_downbeat else low_click
|
||||
click_audio[idx : idx + click_len] += sample_click
|
||||
beat += 1.0
|
||||
|
||||
return click_audio
|
||||
|
||||
75
tests/test_chords.py
Normal file
75
tests/test_chords.py
Normal file
@ -0,0 +1,75 @@
|
||||
"""Unit tests for Harte chord parsing, key detection, and template chord recognition."""
|
||||
|
||||
import numpy as np
|
||||
|
||||
from songsplit.pipeline.s6_chords import estimate_key, extract_chords_template, parse_harte_chord
|
||||
|
||||
|
||||
def test_parse_harte_chord_labels():
|
||||
# Major triad
|
||||
root, quality, bass = parse_harte_chord("C")
|
||||
assert root == "C"
|
||||
assert quality == "maj"
|
||||
assert bass is None
|
||||
|
||||
# Minor triad
|
||||
root, quality, bass = parse_harte_chord("Am")
|
||||
assert root == "A"
|
||||
assert quality == "min"
|
||||
assert bass is None
|
||||
|
||||
# Dominant 7th
|
||||
root, quality, bass = parse_harte_chord("G7")
|
||||
assert root == "G"
|
||||
assert quality == "7"
|
||||
assert bass is None
|
||||
|
||||
# Sus4
|
||||
root, quality, bass = parse_harte_chord("Dsus4")
|
||||
assert root == "D"
|
||||
assert quality == "sus4"
|
||||
assert bass is None
|
||||
|
||||
# Slash chord
|
||||
root, quality, bass = parse_harte_chord("F/A")
|
||||
assert root == "F"
|
||||
assert quality == "maj"
|
||||
assert bass == "A"
|
||||
|
||||
# No chord
|
||||
root, quality, bass = parse_harte_chord("N")
|
||||
assert root is None
|
||||
assert quality is None
|
||||
assert bass is None
|
||||
|
||||
|
||||
def test_estimate_key():
|
||||
# Synthetic C major profile (peaks at C, E, G -> indices 0, 4, 7)
|
||||
c_maj_chroma = np.zeros(12)
|
||||
c_maj_chroma[0] = 5.0
|
||||
c_maj_chroma[4] = 4.0
|
||||
c_maj_chroma[7] = 4.5
|
||||
assert estimate_key(c_maj_chroma) == "C"
|
||||
|
||||
# Synthetic A minor profile (peaks at A, C, E -> indices 9, 0, 4)
|
||||
a_min_chroma = np.zeros(12)
|
||||
a_min_chroma[9] = 5.0
|
||||
a_min_chroma[0] = 4.0
|
||||
a_min_chroma[4] = 4.5
|
||||
assert estimate_key(a_min_chroma) == "Am"
|
||||
|
||||
|
||||
def test_extract_chords_template_synthetic():
|
||||
sr = 22050
|
||||
duration = 1.0
|
||||
t = np.linspace(0, duration, int(sr * duration), endpoint=False)
|
||||
|
||||
# Synthesize C major: C4 (261.63), E4 (329.63), G4 (392.00)
|
||||
c_chord = (np.sin(2 * np.pi * 261.63 * t) + np.sin(2 * np.pi * 329.63 * t) + np.sin(2 * np.pi * 392.00 * t)).astype(
|
||||
np.float32
|
||||
)
|
||||
|
||||
raw_chords = extract_chords_template(c_chord, sr)
|
||||
labels = [ch for _, ch in raw_chords]
|
||||
# Dominant detected chord should be "C"
|
||||
assert labels.count("C") > len(labels) * 0.5
|
||||
98
tests/test_demo_package.py
Normal file
98
tests/test_demo_package.py
Normal file
@ -0,0 +1,98 @@
|
||||
"""Test the demo song package in examples/demo_song."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.export.ultrastar import parse_ultrastar
|
||||
from songsplit.schema.chords import ChordsDocument
|
||||
from songsplit.schema.meta import MetaDocument
|
||||
from songsplit.schema.strumming import StrummingDocument
|
||||
from songsplit.schema.tempo import TempoDocument
|
||||
from songsplit.schema.vocals import VocalsDocument
|
||||
|
||||
|
||||
def test_demo_package_structure():
|
||||
demo_dir = Path("examples/demo_song")
|
||||
assert demo_dir.is_dir()
|
||||
|
||||
required_files = [
|
||||
"meta.json",
|
||||
"tempo.json",
|
||||
"vocals.json",
|
||||
"chords.json",
|
||||
"strumming.json",
|
||||
"song.txt",
|
||||
]
|
||||
for rf in required_files:
|
||||
p = demo_dir / rf
|
||||
assert p.is_file(), f"Missing {rf} in demo package"
|
||||
|
||||
stems_dir = demo_dir / "stems"
|
||||
assert stems_dir.is_dir()
|
||||
for stem_name in ["vocals.wav", "instrumental.wav", "drums.wav", "bass.wav", "other.wav"]:
|
||||
p = stems_dir / stem_name
|
||||
assert p.is_file(), f"Missing stem {stem_name} in demo package"
|
||||
|
||||
|
||||
def test_demo_package_schemas():
|
||||
demo_dir = Path("examples/demo_song")
|
||||
|
||||
# Meta
|
||||
meta_raw = json.loads((demo_dir / "meta.json").read_text(encoding="utf-8"))
|
||||
meta = MetaDocument.model_validate(meta_raw)
|
||||
assert meta.title == "Demo Song"
|
||||
assert meta.schema_version == "1.0"
|
||||
assert meta.duration_sec > 0
|
||||
|
||||
# Tempo
|
||||
tempo_raw = json.loads((demo_dir / "tempo.json").read_text(encoding="utf-8"))
|
||||
tempo = TempoDocument.model_validate(tempo_raw)
|
||||
assert len(tempo.anchors) >= 1
|
||||
assert tempo.anchors[0].bpm == 120.0
|
||||
assert tempo.time_signature.numerator == 4
|
||||
|
||||
# Vocals
|
||||
vocals_raw = json.loads((demo_dir / "vocals.json").read_text(encoding="utf-8"))
|
||||
vocals = VocalsDocument.model_validate(vocals_raw)
|
||||
assert len(vocals.lines) >= 1
|
||||
assert len(vocals.lines[0].syllables) == 3
|
||||
|
||||
# Chords
|
||||
chords_raw = json.loads((demo_dir / "chords.json").read_text(encoding="utf-8"))
|
||||
chords = ChordsDocument.model_validate(chords_raw)
|
||||
assert len(chords.chords) == 2
|
||||
assert chords.chords[0].label == "Am"
|
||||
|
||||
# Strumming
|
||||
strumming_raw = json.loads((demo_dir / "strumming.json").read_text(encoding="utf-8"))
|
||||
strumming = StrummingDocument.model_validate(strumming_raw)
|
||||
assert len(strumming.events) == 4
|
||||
assert len(strumming.patterns) == 1
|
||||
|
||||
|
||||
def test_demo_package_audio_properties():
|
||||
demo_dir = Path("examples/demo_song")
|
||||
stems = ["vocals.wav", "instrumental.wav", "drums.wav", "bass.wav", "other.wav"]
|
||||
|
||||
for s in stems:
|
||||
path = demo_dir / "stems" / s
|
||||
info = sf.info(str(path))
|
||||
assert info.samplerate == 44100
|
||||
assert info.channels == 2
|
||||
assert abs(info.duration - 3.0) < 0.01
|
||||
|
||||
|
||||
def test_demo_package_ultrastar_roundtrip():
|
||||
demo_dir = Path("examples/demo_song")
|
||||
song_txt = demo_dir / "song.txt"
|
||||
parsed = parse_ultrastar(song_txt)
|
||||
|
||||
assert parsed.title == "Demo Song"
|
||||
assert parsed.artist == "Synthetic Artist"
|
||||
assert len(parsed.lines) == 1
|
||||
assert len(parsed.lines[0]) == 3
|
||||
|
||||
texts = [s.text for s in parsed.lines[0]]
|
||||
assert texts == ["Hel", "lo ", "world"]
|
||||
94
tests/test_pipeline_m3.py
Normal file
94
tests/test_pipeline_m3.py
Normal file
@ -0,0 +1,94 @@
|
||||
"""Integration test for Milestone 3 (Stage 5 Tempo Map and Click Track)."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.export.ultrastar import export_ultrastar, parse_ultrastar
|
||||
from songsplit.pipeline import PipelineContext
|
||||
from songsplit.pipeline.s5_tempo import TempoStage
|
||||
from songsplit.schema.meta import MetaDocument, SourceFileInfo
|
||||
from songsplit.schema.tempo import TempoDocument
|
||||
from songsplit.schema.vocals import VocalLine, VocalsDocument, VocalSyllable
|
||||
|
||||
|
||||
def test_m3_tempo_stage_and_click_track(tmp_path: Path):
|
||||
song_dir = tmp_path / "song_pkg"
|
||||
stems_dir = song_dir / "stems"
|
||||
cache_dir = song_dir / ".cache"
|
||||
stems_dir.mkdir(parents=True, exist_ok=True)
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 1. Generate 6.0s synthetic drum beats at 120 BPM (beats at 0.0, 0.5, 1.0, 1.5, ...)
|
||||
sr = 44100
|
||||
duration_sec = 6.0
|
||||
audio = np.zeros(int(sr * duration_sec), dtype=np.float32)
|
||||
|
||||
# Place a 10ms burst pulse every 0.5s
|
||||
burst_len = int(sr * 0.01)
|
||||
burst = np.sin(2 * np.pi * 300.0 * np.linspace(0, 0.01, burst_len, endpoint=False)).astype(np.float32)
|
||||
|
||||
for t in np.arange(0.5, 5.5, 0.5):
|
||||
idx = int(t * sr)
|
||||
audio[idx : idx + burst_len] += burst
|
||||
|
||||
drums_wav = stems_dir / "drums.wav"
|
||||
sf.write(str(drums_wav), audio, sr)
|
||||
|
||||
# 2. Write meta.json
|
||||
meta = MetaDocument(
|
||||
title="Tempo Test Song",
|
||||
artist="Test Drummer",
|
||||
duration_sec=duration_sec,
|
||||
source_file=SourceFileInfo(path=str(drums_wav), sha256="fakehash", size_bytes=len(audio)),
|
||||
created_at="2026-11-02T10:00:00Z",
|
||||
)
|
||||
(song_dir / "meta.json").write_text(meta.model_dump_json(indent=2))
|
||||
|
||||
# 3. Write minimal vocals.json
|
||||
vocals = VocalsDocument(
|
||||
lines=[
|
||||
VocalLine(
|
||||
start=1.0,
|
||||
end=2.0,
|
||||
syllables=[VocalSyllable(text="Beat", start=1.0, end=2.0, midi=60.0)],
|
||||
)
|
||||
]
|
||||
)
|
||||
(song_dir / "vocals.json").write_text(vocals.model_dump_json(indent=2))
|
||||
|
||||
# 4. Run TempoStage
|
||||
ctx = PipelineContext(source_file=drums_wav, output_dir=song_dir)
|
||||
stage = TempoStage()
|
||||
stage.run(ctx)
|
||||
|
||||
# 5. Verify tempo.json
|
||||
tempo_json = song_dir / "tempo.json"
|
||||
assert tempo_json.exists()
|
||||
|
||||
with open(tempo_json, encoding="utf-8") as f:
|
||||
doc = TempoDocument.model_validate(json.load(f))
|
||||
|
||||
assert len(doc.anchors) >= 1
|
||||
# Detected tempo should be around 120 BPM (or 60/240 subharmonic)
|
||||
bpm = doc.anchors[0].bpm
|
||||
assert (
|
||||
bpm == pytest.approx(120.0, abs=5.0)
|
||||
or bpm == pytest.approx(60.0, abs=5.0)
|
||||
or bpm == pytest.approx(240.0, abs=10.0)
|
||||
)
|
||||
|
||||
# 6. Verify click track audio generated
|
||||
click_track = cache_dir / "click_track.wav"
|
||||
assert click_track.exists()
|
||||
click_data, click_sr = sf.read(str(click_track))
|
||||
assert len(click_data) == len(audio)
|
||||
|
||||
# 7. Test UltraStar export derives BPM/GAP from tempo.json
|
||||
txt_path = export_ultrastar(song_dir)
|
||||
assert txt_path.exists()
|
||||
song = parse_ultrastar(txt_path)
|
||||
assert song.bpm == pytest.approx(doc.anchors[0].bpm, abs=1.0)
|
||||
76
tests/test_pipeline_m4.py
Normal file
76
tests/test_pipeline_m4.py
Normal file
@ -0,0 +1,76 @@
|
||||
"""Integration test for Milestone 4 (Stage 6 Beat-Quantized Chord Recognition)."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.pipeline import PipelineContext
|
||||
from songsplit.pipeline.s6_chords import ChordsStage
|
||||
from songsplit.schema.chords import ChordsDocument
|
||||
from songsplit.schema.meta import MetaDocument, SourceFileInfo
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument
|
||||
|
||||
|
||||
def test_m4_chords_stage_pipeline(tmp_path: Path):
|
||||
song_dir = tmp_path / "song_pkg"
|
||||
stems_dir = song_dir / "stems"
|
||||
stems_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 1. Synthesize 4.0s instrumental audio:
|
||||
# 2.0s C major (261.63, 329.63, 392.00) + 2.0s A minor (220.0, 261.63, 329.63)
|
||||
sr = 22050
|
||||
t_half = np.linspace(0, 2.0, int(sr * 2.0), endpoint=False)
|
||||
|
||||
c_major = (
|
||||
np.sin(2 * np.pi * 261.63 * t_half) + np.sin(2 * np.pi * 329.63 * t_half) + np.sin(2 * np.pi * 392.00 * t_half)
|
||||
).astype(np.float32)
|
||||
|
||||
a_minor = (
|
||||
np.sin(2 * np.pi * 220.00 * t_half) + np.sin(2 * np.pi * 261.63 * t_half) + np.sin(2 * np.pi * 329.63 * t_half)
|
||||
).astype(np.float32)
|
||||
|
||||
inst_audio = np.concatenate([c_major, a_minor])
|
||||
inst_wav = stems_dir / "instrumental.wav"
|
||||
sf.write(str(inst_wav), inst_audio, sr)
|
||||
|
||||
# 2. Prepare tempo.json: 120 BPM starting at 0.0s (0.5s per beat)
|
||||
# 4.0s = 8 beats total (0.0 to 4.0 beat is C, 4.0 to 8.0 beat is Am)
|
||||
tempo = TempoDocument(anchors=[TempoAnchor(sec=0.0, beat=0.0, bpm=120.0)])
|
||||
(song_dir / "tempo.json").write_text(tempo.model_dump_json(indent=2))
|
||||
|
||||
# 3. Prepare meta.json
|
||||
meta = MetaDocument(
|
||||
title="Chord Test Song",
|
||||
artist="Test Pianist",
|
||||
duration_sec=4.0,
|
||||
source_file=SourceFileInfo(path=str(inst_wav), sha256="fakehash", size_bytes=len(inst_audio)),
|
||||
created_at="2026-11-02T10:00:00Z",
|
||||
)
|
||||
(song_dir / "meta.json").write_text(meta.model_dump_json(indent=2))
|
||||
|
||||
# 4. Run ChordsStage with template backend
|
||||
ctx = PipelineContext(source_file=inst_wav, output_dir=song_dir)
|
||||
stage = ChordsStage(backend="template")
|
||||
stage.run(ctx)
|
||||
|
||||
chords_json = song_dir / "chords.json"
|
||||
assert chords_json.exists()
|
||||
|
||||
with open(chords_json, encoding="utf-8") as f:
|
||||
doc = ChordsDocument.model_validate(json.load(f))
|
||||
|
||||
assert len(doc.chords) >= 1
|
||||
labels = [c.label for c in doc.chords]
|
||||
assert "C" in labels or "Am" in labels
|
||||
|
||||
# Check beat-based timing
|
||||
for ch in doc.chords:
|
||||
assert ch.start_beat >= 0.0
|
||||
assert ch.end_beat > ch.start_beat
|
||||
assert ch.confidence > 0.0
|
||||
|
||||
# 5. Verify meta.json updated with key
|
||||
updated_meta = ctx.load_or_init_meta()
|
||||
assert updated_meta.key in ("C", "Am")
|
||||
77
tests/test_pipeline_m5.py
Normal file
77
tests/test_pipeline_m5.py
Normal file
@ -0,0 +1,77 @@
|
||||
"""Integration test for Milestone 5 (Stage 7 Strumming Analysis)."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.pipeline import PipelineContext
|
||||
from songsplit.pipeline.s7_strumming import StrummingStage
|
||||
from songsplit.schema.meta import MetaDocument, SourceFileInfo
|
||||
from songsplit.schema.strumming import StrummingDocument
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument
|
||||
|
||||
|
||||
def test_m5_strumming_pipeline(tmp_path: Path):
|
||||
song_dir = tmp_path / "song_pkg"
|
||||
stems_dir = song_dir / "stems"
|
||||
stems_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 1. Synthesize 4.0s audio with strumming acoustic pulses
|
||||
sr = 22050
|
||||
duration_sec = 4.0
|
||||
audio = np.zeros(int(sr * duration_sec), dtype=np.float32)
|
||||
|
||||
# Pulses every 0.25s (8th notes at 120 BPM: 0.5s per quarter beat -> 0.25s per 8th note)
|
||||
pulse_len = int(sr * 0.05)
|
||||
t_pulse = np.linspace(0, 0.05, pulse_len, endpoint=False)
|
||||
pulse = (np.sin(2 * np.pi * 350.0 * t_pulse) * np.exp(-t_pulse / 0.01)).astype(np.float32)
|
||||
|
||||
for onset_t in np.arange(0.25, 3.75, 0.25):
|
||||
idx = int(onset_t * sr)
|
||||
audio[idx : idx + pulse_len] += pulse
|
||||
|
||||
guitar_wav = stems_dir / "guitar.wav"
|
||||
sf.write(str(guitar_wav), audio, sr)
|
||||
|
||||
# 2. Prepare tempo.json at 120 BPM starting at 0.0s
|
||||
tempo = TempoDocument(anchors=[TempoAnchor(sec=0.0, beat=0.0, bpm=120.0)])
|
||||
(song_dir / "tempo.json").write_text(tempo.model_dump_json(indent=2))
|
||||
|
||||
# 3. Prepare meta.json
|
||||
meta = MetaDocument(
|
||||
title="Strumming Test Song",
|
||||
artist="Test Guitarist",
|
||||
duration_sec=duration_sec,
|
||||
source_file=SourceFileInfo(path=str(guitar_wav), sha256="fakehash", size_bytes=len(audio)),
|
||||
created_at="2026-11-02T10:00:00Z",
|
||||
)
|
||||
(song_dir / "meta.json").write_text(meta.model_dump_json(indent=2))
|
||||
|
||||
# 4. Run StrummingStage
|
||||
ctx = PipelineContext(source_file=guitar_wav, output_dir=song_dir)
|
||||
stage = StrummingStage(grid="8th")
|
||||
stage.run(ctx)
|
||||
|
||||
strum_json = song_dir / "strumming.json"
|
||||
assert strum_json.exists()
|
||||
|
||||
with open(strum_json, encoding="utf-8") as f:
|
||||
doc = StrummingDocument.model_validate(json.load(f))
|
||||
|
||||
assert len(doc.events) > 0
|
||||
for e in doc.events:
|
||||
# Quantized to 8th note grid (multiples of 0.5 beats)
|
||||
assert (e.beat * 2).is_integer()
|
||||
assert e.direction in ("down", "up")
|
||||
assert 0.0 <= e.strength <= 1.0
|
||||
assert 0.0 <= e.confidence <= 1.0
|
||||
|
||||
# Verify marked as experimental in generated_by metadata
|
||||
assert doc.generated_by is not None
|
||||
assert doc.generated_by.params.get("status") == "experimental"
|
||||
|
||||
# Patterns generated
|
||||
assert len(doc.patterns) > 0
|
||||
assert doc.patterns[0].grid == "8th"
|
||||
39
tests/test_strumming.py
Normal file
39
tests/test_strumming.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""Unit tests for strumming direction estimation and pattern aggregation."""
|
||||
|
||||
import numpy as np
|
||||
|
||||
from songsplit.pipeline.s7_strumming import aggregate_strum_patterns, estimate_strum_direction
|
||||
from songsplit.schema.strumming import StrumEvent
|
||||
|
||||
|
||||
def test_estimate_strum_direction_phase_prior():
|
||||
sr = 22050
|
||||
audio = np.random.randn(sr).astype(np.float32)
|
||||
|
||||
# On-beat (beat 0.0) -> down
|
||||
dir_down, conf_down = estimate_strum_direction(audio, sr, onset_sec=0.1, beat=0.0)
|
||||
assert dir_down == "down"
|
||||
assert conf_down >= 0.5
|
||||
|
||||
# Off-beat (beat 0.5) -> up
|
||||
dir_up, conf_up = estimate_strum_direction(audio, sr, onset_sec=0.1, beat=0.5)
|
||||
assert dir_up == "up"
|
||||
assert conf_up >= 0.5
|
||||
|
||||
|
||||
def test_aggregate_strum_patterns_island_strum():
|
||||
# Famous "island strum": D . D U . U D U (slots: 0, 1, 2, 3, 4, 5, 6, 7 on 8th grid)
|
||||
# slots: 0.0 (D), 1.0 (D), 1.5 (U), 2.5 (U), 3.0 (D), 3.5 (U)
|
||||
events = [
|
||||
StrumEvent(beat=0.0, direction="down", strength=0.9, confidence=0.8),
|
||||
StrumEvent(beat=1.0, direction="down", strength=0.8, confidence=0.8),
|
||||
StrumEvent(beat=1.5, direction="up", strength=0.7, confidence=0.7),
|
||||
StrumEvent(beat=2.5, direction="up", strength=0.7, confidence=0.7),
|
||||
StrumEvent(beat=3.0, direction="down", strength=0.8, confidence=0.8),
|
||||
StrumEvent(beat=3.5, direction="up", strength=0.7, confidence=0.7),
|
||||
]
|
||||
|
||||
patterns = aggregate_strum_patterns(events, total_beats=4.0, grid="8th", pattern_beats=4.0, section_beats=4.0)
|
||||
assert len(patterns) == 1
|
||||
assert patterns[0].pattern == "D . D U . U D U"
|
||||
assert patterns[0].grid == "8th"
|
||||
63
tests/test_tempo_detection.py
Normal file
63
tests/test_tempo_detection.py
Normal file
@ -0,0 +1,63 @@
|
||||
"""Unit tests for tempo map builder and click track generator."""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument, TimeSignature
|
||||
from songsplit.tempo import build_tempo_map_from_beats, generate_click_track
|
||||
|
||||
|
||||
def test_build_tempo_map_constant_tempo():
|
||||
# 120 BPM = 0.5s per beat, 16 beats = 8.0s
|
||||
beat_times = np.arange(0.5, 8.5, 0.5)
|
||||
# Downbeats every 4 beats (indices 0, 4, 8, 12 -> 0.5, 2.5, 4.5, 6.5)
|
||||
downbeat_times = beat_times[::4]
|
||||
|
||||
tempo_doc = build_tempo_map_from_beats(beat_times, downbeat_times)
|
||||
|
||||
# Should only create 1 anchor for steady tempo
|
||||
assert len(tempo_doc.anchors) == 1
|
||||
anchor = tempo_doc.anchors[0]
|
||||
assert anchor.bpm == pytest.approx(120.0, abs=0.5)
|
||||
assert anchor.sec == pytest.approx(0.5, abs=0.01)
|
||||
assert tempo_doc.time_signature.numerator == 4
|
||||
assert tempo_doc.downbeat_offset == 0
|
||||
|
||||
|
||||
def test_build_tempo_map_3_4_time_signature():
|
||||
# 3/4 time signature: downbeats every 3 beats
|
||||
beat_times = np.arange(0.0, 9.0, 0.5) # 120 BPM
|
||||
downbeat_times = beat_times[::3]
|
||||
|
||||
tempo_doc = build_tempo_map_from_beats(beat_times, downbeat_times)
|
||||
assert tempo_doc.time_signature.numerator == 3
|
||||
|
||||
|
||||
def test_build_tempo_map_sustained_tempo_change():
|
||||
# Section 1: 120 BPM (0.5s per beat) for 16 beats -> 8.0s
|
||||
sec1 = np.arange(0.0, 8.0, 0.5)
|
||||
# Section 2: 150 BPM (0.4s per beat) for 16 beats -> 6.4s
|
||||
sec2 = 8.0 + np.arange(0.0, 6.4, 0.4)
|
||||
all_beats = np.concatenate([sec1, sec2])
|
||||
|
||||
tempo_doc = build_tempo_map_from_beats(all_beats, min_tempo_change_bpm=3.0, min_beats_for_change=6)
|
||||
# Should detect 2 anchors: one around 120 BPM, one around 150 BPM
|
||||
assert len(tempo_doc.anchors) >= 2
|
||||
assert tempo_doc.anchors[0].bpm == pytest.approx(120.0, abs=1.0)
|
||||
assert tempo_doc.anchors[1].bpm == pytest.approx(150.0, abs=2.0)
|
||||
|
||||
|
||||
def test_generate_click_track():
|
||||
tempo_doc = TempoDocument(
|
||||
anchors=[TempoAnchor(sec=0.5, beat=0.0, bpm=120.0)],
|
||||
time_signature=TimeSignature(numerator=4, denominator=4),
|
||||
downbeat_offset=0,
|
||||
)
|
||||
sr = 44100
|
||||
duration_sec = 4.0
|
||||
clicks = generate_click_track(tempo_doc, duration_sec=duration_sec, sr=sr)
|
||||
|
||||
assert len(clicks) == int(duration_sec * sr)
|
||||
# At sec=0.5, there should be non-zero audio (first beat click)
|
||||
click_idx = int(0.5 * sr)
|
||||
assert np.max(np.abs(clicks[click_idx : click_idx + 100])) > 0.1
|
||||
56
uv.lock
generated
56
uv.lock
generated
@ -94,6 +94,25 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/42/fe/e79d786628d9c0428f72214dbe4b90ee0c625e04d552a604d5235ff35515/av-19.0.2-cp312-abi3-win_arm64.whl", hash = "sha256:79a277b077e3768a0ea9f881ca0b3bc96d4135a8d3a7a579938adb58718d0dfd", size = 20708023, upload-time = "2026-10-21T03:44:56.435Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "beat-this"
|
||||
version = "1.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "einops" },
|
||||
{ name = "numpy" },
|
||||
{ name = "rotary-embedding-torch" },
|
||||
{ name = "soxr" },
|
||||
{ name = "torch", version = "2.15.0", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "platform_machine != 'x86_64' and sys_platform == 'darwin'" },
|
||||
{ name = "torch", version = "2.15.0+cpu", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "platform_machine == 'x86_64' or sys_platform != 'darwin'" },
|
||||
{ name = "torchaudio", version = "2.11.1", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "platform_machine != 'x86_64' and sys_platform == 'darwin'" },
|
||||
{ name = "torchaudio", version = "2.11.1+cpu", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "platform_machine == 'x86_64' or sys_platform != 'darwin'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d1/c4/7ce01e047c1e8d99490e95172d710e08901c24fb24e19a5dd4f885177c99/beat_this-1.1.0.tar.gz", hash = "sha256:3017c741f972972a650edcaccfe5760687fe4f5587feaa98896d90f866c2435c", size = 40635, upload-time = "2026-04-14T10:16:39.5Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ce/0e/e23cbbe6e3efcd54e84dec22b6d88954655036a993cc3843ab741bc24de4/beat_this-1.1.0-py3-none-any.whl", hash = "sha256:3f2b2d1e027c6dac380bf80c71555e3c28a4036a7f1af20129a945915a72a645", size = 40060, upload-time = "2026-04-14T10:16:37.955Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2026.10.23"
|
||||
@ -196,6 +215,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/fc/ad/d07d7862a62ffa6d79d68074d14823243dd235a77c45262acbf6adeb28bf/charset_normalizer-3.5.2-py3-none-any.whl", hash = "sha256:b6b751274acb69d77b3323d6b7dbaa3c7fdfc1eb829b7eb61d262f32e1af9685", size = 68872, upload-time = "2026-09-30T04:39:21.828Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chord-extractor"
|
||||
version = "0.1.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "librosa" },
|
||||
{ name = "vamp" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/6b/5b/b17c85556c6c3dc28397de7a01b0af9b36fdfa13ffcaa21650da103fa795/chord-extractor-0.1.3.tar.gz", hash = "sha256:84ad0aaf3921f623b699332cb5dd0f509ade49dc46d3d08fdd981335173e52c3", size = 357948, upload-time = "2025-08-14T21:03:59.926Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ad/07/718ec09dd81e0734f85643e5d078a78386e38a0f353e57f622d267eb7563/chord_extractor-0.1.3-py3-none-any.whl", hash = "sha256:70313ad9668abd9fbd36aa4c182426264ceb563cf407b92b5842638d93a90607", size = 362699, upload-time = "2025-08-14T21:03:58.743Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.5.0"
|
||||
@ -1197,6 +1229,20 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb", size = 310654, upload-time = "2026-04-12T08:24:02.83Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rotary-embedding-torch"
|
||||
version = "0.9.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "einops" },
|
||||
{ name = "torch", version = "2.15.0", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "platform_machine != 'x86_64' and sys_platform == 'darwin'" },
|
||||
{ name = "torch", version = "2.15.0+cpu", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "platform_machine == 'x86_64' or sys_platform != 'darwin'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/fc/63/776d55b395aed9d2815afc1740056e919691d1be1ceee203d101d33d1674/rotary_embedding_torch-0.9.1.tar.gz", hash = "sha256:f43c39cd9c0aaa17d47e876db89a552a203dd8af35e7980f484ab7ad7ea8bf69", size = 13246, upload-time = "2026-06-20T23:39:14.667Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ea/63/ca681366df98d207876c6ad7761ef6910668c83ec766fd5a70c56b9c3567/rotary_embedding_torch-0.9.1-py3-none-any.whl", hash = "sha256:489ef53e21ab4c4eb35c0c97b551d724f5eea71c2bca39acb8fee8d88b142a76", size = 17423, upload-time = "2026-06-20T23:39:13.427Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff"
|
||||
version = "0.17.3"
|
||||
@ -1327,6 +1373,8 @@ name = "songsplit"
|
||||
version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "beat-this" },
|
||||
{ name = "chord-extractor" },
|
||||
{ name = "demucs", version = "4.0.1", source = { registry = "https://pypi.org/simple" }, marker = "platform_machine == 'x86_64' and sys_platform == 'darwin'" },
|
||||
{ name = "demucs", version = "4.1.0", source = { registry = "https://pypi.org/simple" }, marker = "platform_machine != 'x86_64' or sys_platform != 'darwin'" },
|
||||
{ name = "faster-whisper" },
|
||||
@ -1354,6 +1402,8 @@ dev = [
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "beat-this", specifier = ">=1.1.0" },
|
||||
{ name = "chord-extractor", specifier = ">=0.1.3" },
|
||||
{ name = "demucs", specifier = ">=4.0.0" },
|
||||
{ name = "faster-whisper", specifier = ">=1.0.0" },
|
||||
{ name = "jiwer", specifier = ">=3.0.0" },
|
||||
@ -1673,3 +1723,9 @@ sdist = { url = "https://files.pythonhosted.org/packages/e3/05/b17359e1cefb4f909
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/92/9d/c4e665119135114480843e7ab388fa94d8480650450e6f8e26b70d323a4c/urllib3-2.8.0-py3-none-any.whl", hash = "sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", size = 135717, upload-time = "2026-09-15T19:29:34.577Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vamp"
|
||||
version = "1.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/66/65/a54958777fa667ef881ceec18dd0b423b2ba2c77543060b21aff0e1dbcb6/vamp-1.1.0.tar.gz", hash = "sha256:d40e0916e958e2806d37920f903c2518cc46959a4f21e020737b6a48f6e7e82d", size = 107848, upload-time = "2015-07-08T19:14:21.005Z" }
|
||||
|
||||
Reference in New Issue
Block a user