use crate::models::{LineInfo, LyricsAlignment};
pub fn downgrade_to_line_synced(lines: &mut [LineInfo]) {
for line in lines.iter_mut() {
downgrade_line(line);
}
}
pub fn downgrade_line(line: &mut LineInfo) {
if let Some(sub) = line.sub_line_mut() {
downgrade_line(sub);
}
if !line.is_syllable() {
return;
}
let placeholder = LineInfo::Line {
text: String::new(),
start_time: None,
end_time: None,
alignment: LyricsAlignment::Unspecified,
sub_line: None,
};
let owned = std::mem::replace(line, placeholder);
let (syllables, alignment, sub_line, translations, pronunciation) = match owned {
LineInfo::Syllable {
syllables,
alignment,
sub_line,
..
} => (syllables, alignment, sub_line, None, None),
LineInfo::FullSyllable {
syllables,
alignment,
sub_line,
translations,
pronunciation,
} => (
syllables,
alignment,
sub_line,
Some(translations),
pronunciation,
),
other => {
*line = other;
return;
}
};
if syllables.is_empty() {
*line = match translations {
Some(translations) => LineInfo::FullSyllable {
syllables,
alignment,
sub_line,
translations,
pronunciation,
},
None => LineInfo::Syllable {
syllables,
alignment,
sub_line,
},
};
return;
}
let text = LineInfo::text_from_syllables(&syllables);
let start_time = syllables.first().map(|s| s.start_time());
let end_time = syllables.last().map(|s| s.end_time());
*line = match translations {
Some(translations) => LineInfo::FullLine {
text,
start_time,
end_time,
alignment,
sub_line,
translations,
pronunciation,
},
None => LineInfo::Line {
text,
start_time,
end_time,
alignment,
sub_line,
},
};
}