feat: version song analysis contract and preserve lyric lines
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
//! Version 1 of `schemas/song-analysis-v1/`, with seconds relative to the normalized mix.
|
||||
//! Versions 1 and 2 of the song-analysis contract, with seconds relative to the source origin.
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -10,8 +10,12 @@ use std::path::{Path, PathBuf};
|
||||
pub struct Meta {
|
||||
pub title: String,
|
||||
pub bpm: Option<f64>,
|
||||
#[serde(default)]
|
||||
pub bpm_source: Option<String>,
|
||||
pub key: Option<String>,
|
||||
pub duration: f64,
|
||||
#[serde(default)]
|
||||
pub source_offset_s: Option<f64>,
|
||||
pub schema_version: u32,
|
||||
pub errors: BTreeMap<String, String>,
|
||||
}
|
||||
@ -52,8 +56,14 @@ pub struct Word {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Line {
|
||||
pub start: f64,
|
||||
pub end: f64,
|
||||
pub start: Option<f64>,
|
||||
pub end: Option<f64>,
|
||||
#[serde(default)]
|
||||
pub source_line: Option<u32>,
|
||||
#[serde(default)]
|
||||
pub section: Option<String>,
|
||||
#[serde(default)]
|
||||
pub alignment_conf: Option<f64>,
|
||||
pub words: Vec<Word>,
|
||||
}
|
||||
|
||||
@ -101,12 +111,18 @@ pub fn load_analysis(dir: &Path) -> Result<Analysis> {
|
||||
let meta: Meta = serde_json::from_slice(
|
||||
&std::fs::read(&path).with_context(|| format!("{} lesen", path.display()))?,
|
||||
)?;
|
||||
if meta.schema_version != 1 {
|
||||
if meta.schema_version != 1 && meta.schema_version != 2 {
|
||||
bail!(
|
||||
"Unbekannte song-analysis schema_version {}",
|
||||
meta.schema_version
|
||||
);
|
||||
}
|
||||
if meta.schema_version == 2
|
||||
&& (meta.source_offset_s != Some(0.0)
|
||||
|| !matches!(meta.bpm_source.as_deref(), Some("automatic" | "manual")))
|
||||
{
|
||||
bail!("Ungültige v2-Metadaten: bpm_source oder source_offset_s fehlt");
|
||||
}
|
||||
let pitch: Option<Pitch> = read_optional(dir, "pitch.json")?;
|
||||
if pitch
|
||||
.as_ref()
|
||||
|
||||
Reference in New Issue
Block a user