feat(schema): implement songpack v1.0 schemas (manifest, tracks, vocals_f0, editable items)
This commit is contained in:
@ -1,24 +1,58 @@
|
||||
"""Song-Paket data schemas."""
|
||||
"""Songpack data schemas."""
|
||||
|
||||
from songsplit.schema.base import DataSource, GeneratedBy, SongPackageBase
|
||||
from songsplit.schema.base import DataSource, EditableItem, GeneratedBy, SongPackageBase
|
||||
from songsplit.schema.chords import ChordEvent, ChordsDocument
|
||||
from songsplit.schema.meta import MetaDocument, ModelInfo, SourceFileInfo
|
||||
from songsplit.schema.manifest import (
|
||||
FileRole,
|
||||
GeneratorInfo,
|
||||
ManifestDocument,
|
||||
ManifestFileInfo,
|
||||
ManifestStageInfo,
|
||||
StageStatus,
|
||||
StemName,
|
||||
)
|
||||
from songsplit.schema.meta import (
|
||||
AudioRefInfo,
|
||||
CapoSuggestion,
|
||||
KeyInfo,
|
||||
MetaDocument,
|
||||
ModelInfo,
|
||||
SourceFileInfo,
|
||||
)
|
||||
from songsplit.schema.strumming import StrumDirection, StrumEvent, StrummingDocument, StrumPattern
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument, TimeSignature
|
||||
from songsplit.schema.tempo import TempoAnchor, TempoDocument, TimeSignatureEntry
|
||||
from songsplit.schema.tracks import DrumEvent, DrumPiece, NoteEvent, TrackDocument, TrackKind
|
||||
from songsplit.schema.vocals import VocalLine, VocalsDocument, VocalSyllable
|
||||
from songsplit.schema.vocals_f0 import VocalsF0Document
|
||||
|
||||
# Backward compatibility alias
|
||||
TimeSignature = TimeSignatureEntry
|
||||
|
||||
__all__ = [
|
||||
"DataSource",
|
||||
"EditableItem",
|
||||
"GeneratedBy",
|
||||
"SongPackageBase",
|
||||
"SourceFileInfo",
|
||||
"AudioRefInfo",
|
||||
"KeyInfo",
|
||||
"CapoSuggestion",
|
||||
"ModelInfo",
|
||||
"MetaDocument",
|
||||
"ManifestDocument",
|
||||
"ManifestFileInfo",
|
||||
"ManifestStageInfo",
|
||||
"FileRole",
|
||||
"StemName",
|
||||
"StageStatus",
|
||||
"GeneratorInfo",
|
||||
"VocalSyllable",
|
||||
"VocalLine",
|
||||
"VocalsDocument",
|
||||
"VocalsF0Document",
|
||||
"TempoAnchor",
|
||||
"TimeSignature",
|
||||
"TimeSignatureEntry",
|
||||
"TempoDocument",
|
||||
"ChordEvent",
|
||||
"ChordsDocument",
|
||||
@ -26,4 +60,9 @@ __all__ = [
|
||||
"StrumEvent",
|
||||
"StrumPattern",
|
||||
"StrummingDocument",
|
||||
"NoteEvent",
|
||||
"DrumEvent",
|
||||
"DrumPiece",
|
||||
"TrackDocument",
|
||||
"TrackKind",
|
||||
]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
"""Base classes and shared types for Song-Paket schemas."""
|
||||
"""Base classes and shared types for Songpack schemas."""
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
@ -18,8 +18,19 @@ class GeneratedBy(BaseModel):
|
||||
params: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class EditableItem(BaseModel):
|
||||
"""Base model for editable items carrying identity, provenance, and lock state."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str
|
||||
source: DataSource = "auto"
|
||||
confidence: float | None = Field(default=None, ge=0.0, le=1.0)
|
||||
locked: bool = False
|
||||
|
||||
|
||||
class SongPackageBase(BaseModel):
|
||||
"""Base schema for all Song-Paket JSON files with schema version and generation info."""
|
||||
"""Base schema for all Songpack JSON files with schema version and generation info."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
@ -1,27 +1,26 @@
|
||||
"""Schema for chords.json."""
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic import ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import DataSource, SongPackageBase
|
||||
from songsplit.schema.base import EditableItem, SongPackageBase
|
||||
|
||||
|
||||
class ChordEvent(BaseModel):
|
||||
"""A chord segment defined in beats."""
|
||||
class ChordEvent(EditableItem):
|
||||
"""A chord segment defined in musical beats."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "c_0001"
|
||||
start_beat: float
|
||||
end_beat: float
|
||||
label: str
|
||||
root: str | None = None
|
||||
quality: str | None = None
|
||||
bass: str | None = None
|
||||
confidence: float = Field(default=1.0, ge=0.0, le=1.0)
|
||||
source: DataSource = "auto"
|
||||
|
||||
|
||||
class ChordsDocument(SongPackageBase):
|
||||
"""Song-Paket chords document (chords.json)."""
|
||||
"""Songpack chords document (chords.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
83
src/songsplit/schema/manifest.py
Normal file
83
src/songsplit/schema/manifest.py
Normal file
@ -0,0 +1,83 @@
|
||||
"""Schema for manifest.json."""
|
||||
|
||||
from typing import Any, Literal
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
FileRole = Literal[
|
||||
"meta",
|
||||
"tempo",
|
||||
"vocals",
|
||||
"vocals_f0",
|
||||
"chords",
|
||||
"track",
|
||||
"stem",
|
||||
"ultrastar",
|
||||
"cover",
|
||||
]
|
||||
|
||||
StemName = Literal[
|
||||
"vocals",
|
||||
"instrumental",
|
||||
"drums",
|
||||
"bass",
|
||||
"guitar",
|
||||
"piano",
|
||||
"other",
|
||||
]
|
||||
|
||||
StageStatus = Literal["done", "failed", "stale", "skipped"]
|
||||
|
||||
|
||||
class GeneratorInfo(BaseModel):
|
||||
"""Information about generator tool."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
name: str = "songsplit"
|
||||
version: str = "0.1.0"
|
||||
|
||||
|
||||
class ManifestFileInfo(BaseModel):
|
||||
"""Entry describing a file inside the songpack."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
path: str
|
||||
role: FileRole
|
||||
schema_version: str | None = None
|
||||
sha256: str
|
||||
size: int
|
||||
stem: StemName | None = None
|
||||
|
||||
|
||||
class ManifestStageInfo(BaseModel):
|
||||
"""Execution status and metadata for a pipeline stage."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
status: StageStatus
|
||||
input_hash: str | None = None
|
||||
model: str | None = None
|
||||
params: dict[str, Any] = Field(default_factory=dict)
|
||||
finished: str | None = None
|
||||
error: str | None = None
|
||||
|
||||
|
||||
class ManifestDocument(BaseModel):
|
||||
"""Songpack manifest document (manifest.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
format: Literal["songpack"] = "songpack"
|
||||
schema_version: str = "1.0"
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
created: str
|
||||
modified: str
|
||||
generator: GeneratorInfo = Field(default_factory=GeneratorInfo)
|
||||
variant: Literal["full", "data"] = "full"
|
||||
audio_included: bool = True
|
||||
license: str | None = None
|
||||
files: list[ManifestFileInfo] = Field(default_factory=list)
|
||||
stages: dict[str, ManifestStageInfo] = Field(default_factory=dict)
|
||||
@ -1,5 +1,7 @@
|
||||
"""Schema for meta.json."""
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import SongPackageBase
|
||||
@ -10,9 +12,40 @@ class SourceFileInfo(BaseModel):
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
path: str
|
||||
sha256: str
|
||||
size_bytes: int
|
||||
filename: str = ""
|
||||
path: str = ""
|
||||
kind: Literal["audio", "video"] = "audio"
|
||||
sha256: str = ""
|
||||
size_bytes: int = 0
|
||||
|
||||
|
||||
class AudioRefInfo(BaseModel):
|
||||
"""Audio reference information for fingerprinting and alignment."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
duration_sec: float = Field(ge=0.0)
|
||||
samplerate: int = 44100
|
||||
pcm_sha256: str = ""
|
||||
|
||||
|
||||
class KeyInfo(BaseModel):
|
||||
"""Estimated musical key."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
tonic: str
|
||||
mode: str = "major"
|
||||
confidence: float | None = None
|
||||
|
||||
|
||||
class CapoSuggestion(BaseModel):
|
||||
"""Capo suggestion and chord shape root."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
capo: int = 0
|
||||
shapes_in: str | None = None
|
||||
|
||||
|
||||
class ModelInfo(BaseModel):
|
||||
@ -26,18 +59,29 @@ class ModelInfo(BaseModel):
|
||||
|
||||
|
||||
class MetaDocument(SongPackageBase):
|
||||
"""Song-Paket metadata document (meta.json)."""
|
||||
"""Songpack metadata document (meta.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
title: str | None = None
|
||||
artist: str | None = None
|
||||
album: str | None = None
|
||||
year: int | None = None
|
||||
language: str | None = None
|
||||
duration_sec: float = Field(ge=0.0)
|
||||
source_file: SourceFileInfo
|
||||
key: str | None = None
|
||||
duration_sec: float = Field(default=0.0, ge=0.0)
|
||||
source: SourceFileInfo = Field(default_factory=SourceFileInfo)
|
||||
audio_ref: AudioRefInfo | None = None
|
||||
audio_offset_sec: float = 0.0
|
||||
key: KeyInfo | str | None = None
|
||||
capo: int | None = None
|
||||
capo_suggestion: CapoSuggestion | None = None
|
||||
ultrastar: dict[str, str] = Field(default_factory=dict)
|
||||
models_used: list[ModelInfo] = Field(default_factory=list)
|
||||
created_at: str
|
||||
created_at: str | None = None
|
||||
stages_done: list[str] = Field(default_factory=list)
|
||||
stages_failed: dict[str, str] = Field(default_factory=dict)
|
||||
|
||||
# Backward compatibility helper
|
||||
@property
|
||||
def source_file(self) -> SourceFileInfo:
|
||||
return self.source
|
||||
|
||||
@ -1,41 +1,17 @@
|
||||
"""Schema for strumming.json."""
|
||||
"""Backward-compatible re-export of strumming types from tracks."""
|
||||
|
||||
from typing import Literal
|
||||
from songsplit.schema.tracks import (
|
||||
StrumDirection,
|
||||
StrumEvent,
|
||||
StrumGrid,
|
||||
StrummingDocument,
|
||||
StrumPattern,
|
||||
)
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import DataSource, SongPackageBase
|
||||
|
||||
StrumDirection = Literal["down", "up", "unknown"]
|
||||
|
||||
|
||||
class StrumEvent(BaseModel):
|
||||
"""A single strumming event."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
beat: float
|
||||
direction: StrumDirection
|
||||
strength: float = Field(default=1.0, ge=0.0, le=1.0)
|
||||
confidence: float = Field(default=1.0, ge=0.0, le=1.0)
|
||||
source: DataSource = "auto"
|
||||
|
||||
|
||||
class StrumPattern(BaseModel):
|
||||
"""An aggregated strumming pattern over a beat range."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
start_beat: float
|
||||
end_beat: float
|
||||
pattern: str
|
||||
grid: str = "8th"
|
||||
|
||||
|
||||
class StrummingDocument(SongPackageBase):
|
||||
"""Song-Paket strumming document (strumming.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
events: list[StrumEvent] = Field(default_factory=list)
|
||||
patterns: list[StrumPattern] = Field(default_factory=list)
|
||||
__all__ = [
|
||||
"StrumDirection",
|
||||
"StrumEvent",
|
||||
"StrumGrid",
|
||||
"StrumPattern",
|
||||
"StrummingDocument",
|
||||
]
|
||||
|
||||
@ -1,34 +1,43 @@
|
||||
"""Schema for tempo.json."""
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic import ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import SongPackageBase
|
||||
from songsplit.schema.base import EditableItem, SongPackageBase
|
||||
|
||||
|
||||
class TempoAnchor(BaseModel):
|
||||
class TempoAnchor(EditableItem):
|
||||
"""A tempo anchor defining constant BPM starting from a given time/beat."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "t_0001"
|
||||
sec: float
|
||||
beat: float
|
||||
bpm: float = Field(gt=0.0)
|
||||
|
||||
|
||||
class TimeSignature(BaseModel):
|
||||
"""Musical time signature, e.g. 4/4."""
|
||||
class TimeSignatureEntry(EditableItem):
|
||||
"""Musical time signature starting at a given beat."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "ts_0001"
|
||||
beat: float = 0.0
|
||||
numerator: int = Field(default=4, gt=0)
|
||||
denominator: int = Field(default=4, gt=0)
|
||||
|
||||
|
||||
class TempoDocument(SongPackageBase):
|
||||
"""Song-Paket tempo document (tempo.json)."""
|
||||
"""Songpack tempo document (tempo.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
anchors: list[TempoAnchor] = Field(default_factory=list)
|
||||
time_signature: TimeSignature = Field(default_factory=TimeSignature)
|
||||
time_signatures: list[TimeSignatureEntry] = Field(default_factory=list)
|
||||
downbeat_offset: int = 0
|
||||
|
||||
@property
|
||||
def time_signature(self) -> TimeSignatureEntry:
|
||||
if self.time_signatures:
|
||||
return self.time_signatures[0]
|
||||
return TimeSignatureEntry(beat=0.0, numerator=4, denominator=4)
|
||||
|
||||
90
src/songsplit/schema/tracks.py
Normal file
90
src/songsplit/schema/tracks.py
Normal file
@ -0,0 +1,90 @@
|
||||
"""Schema for instrument tracks (tracks/<name>.json)."""
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import EditableItem, SongPackageBase
|
||||
|
||||
TrackKind = Literal["strumming", "notes", "drums"]
|
||||
StrumDirection = Literal["down", "up", "mute", "unknown"]
|
||||
StrumGrid = Literal["quarter", "8th", "triplet", "16th"]
|
||||
DrumPiece = Literal[
|
||||
"kick",
|
||||
"snare",
|
||||
"hihat_closed",
|
||||
"hihat_open",
|
||||
"tom",
|
||||
"crash",
|
||||
"ride",
|
||||
"other",
|
||||
]
|
||||
|
||||
|
||||
class StrumEvent(EditableItem):
|
||||
"""A single strumming event."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "e_0001"
|
||||
beat: float
|
||||
direction: StrumDirection
|
||||
strength: float = Field(default=1.0, ge=0.0, le=1.0)
|
||||
|
||||
|
||||
class StrumPattern(EditableItem):
|
||||
"""An aggregated strumming pattern over a beat range."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "p_0001"
|
||||
start_beat: float
|
||||
end_beat: float
|
||||
grid: StrumGrid = "8th"
|
||||
pattern: str
|
||||
|
||||
|
||||
class NoteEvent(EditableItem):
|
||||
"""A single musical note event (e.g. for bass, piano, lead guitar)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "n_0001"
|
||||
start_beat: float
|
||||
end_beat: float
|
||||
midi: int
|
||||
velocity: float = Field(default=0.8, ge=0.0, le=1.0)
|
||||
|
||||
|
||||
class DrumEvent(EditableItem):
|
||||
"""A single drum hit event."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "d_0001"
|
||||
beat: float
|
||||
piece: DrumPiece
|
||||
strength: float = Field(default=1.0, ge=0.0, le=1.0)
|
||||
|
||||
|
||||
class TrackDocument(SongPackageBase):
|
||||
"""Instrument track document (tracks/<name>.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
name: str
|
||||
instrument: str
|
||||
kind: TrackKind
|
||||
stem: str | None = None
|
||||
events: list[Any] = Field(default_factory=list)
|
||||
patterns: list[StrumPattern] = Field(default_factory=list)
|
||||
|
||||
|
||||
# Backward-compatible alias
|
||||
class StrummingDocument(SongPackageBase):
|
||||
"""Backward compatibility wrapper for strumming."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
events: list[StrumEvent] = Field(default_factory=list)
|
||||
patterns: list[StrumPattern] = Field(default_factory=list)
|
||||
@ -1,36 +1,49 @@
|
||||
"""Schema for vocals.json."""
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from typing import Literal
|
||||
|
||||
from songsplit.schema.base import DataSource, SongPackageBase
|
||||
from pydantic import ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import EditableItem, SongPackageBase
|
||||
|
||||
SyllableType = Literal["normal", "golden", "freestyle", "rap"]
|
||||
|
||||
|
||||
class VocalSyllable(BaseModel):
|
||||
"""A single syllable with timing, pitch, and confidence."""
|
||||
class VocalSyllable(EditableItem):
|
||||
"""A single syllable with timing, pitch, type, and word boundary."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "s_0001"
|
||||
text: str
|
||||
start: float = Field(ge=0.0)
|
||||
end: float = Field(ge=0.0)
|
||||
midi: float
|
||||
midi: float | None = None
|
||||
type: SyllableType = "normal"
|
||||
word_end: bool = False
|
||||
golden: bool = False
|
||||
confidence: float = Field(default=1.0, ge=0.0, le=1.0)
|
||||
source: DataSource = "auto"
|
||||
|
||||
def model_post_init(self, __context: object) -> None:
|
||||
if self.golden and self.type == "normal":
|
||||
self.type = "golden"
|
||||
elif self.type == "golden":
|
||||
self.golden = True
|
||||
|
||||
|
||||
class VocalLine(BaseModel):
|
||||
class VocalLine(EditableItem):
|
||||
"""A line of lyrics consisting of one or more syllables."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: str = "l_0001"
|
||||
voice: int = 0
|
||||
start: float = Field(ge=0.0)
|
||||
end: float = Field(ge=0.0)
|
||||
syllables: list[VocalSyllable] = Field(default_factory=list)
|
||||
|
||||
|
||||
class VocalsDocument(SongPackageBase):
|
||||
"""Song-Paket vocals document (vocals.json)."""
|
||||
"""Songpack vocals document (vocals.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
16
src/songsplit/schema/vocals_f0.py
Normal file
16
src/songsplit/schema/vocals_f0.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""Schema for vocals_f0.json."""
|
||||
|
||||
from pydantic import ConfigDict, Field
|
||||
|
||||
from songsplit.schema.base import SongPackageBase
|
||||
|
||||
|
||||
class VocalsF0Document(SongPackageBase):
|
||||
"""Raw fundamental frequency track of the vocal stem (vocals_f0.json)."""
|
||||
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
hop_sec: float = 0.01
|
||||
start_sec: float = 0.0
|
||||
hz: list[float | None] = Field(default_factory=list)
|
||||
confidence: list[float] = Field(default_factory=list)
|
||||
Reference in New Issue
Block a user