Skip to main content

analyze

Function analyze 

Source
pub fn analyze(
    request: &AnalyzeRequest<'_>,
    transcriber: &Transcriber,
) -> Result<Analysis, AnalyzeError>
Expand description

Analyses a stem and writes layers.json, spectrogram.png and, when the stem has notes, the final notes.mid into the output folder, creating it.

The tempo is refined from the stem unless the request says bpm_exact. Without a note list the stem runs through transcribe_stem once, with transcriber; with one, the model never runs, but the f0 track of transcriber still reads the stem for the pitch layer.

The files are replaced; nothing else in the folder changes. The stem is read once, for its checksum and for the decoder. Each file goes to a hidden temporary sibling and is renamed into place, notes.mid first and layers.json last. The old report moves aside before any file changes, so a layers.json that exists always belongs to the files next to it, and a failure puts the old files back. The final notes.mid replaces the first one of notes.

§Errors

Returns an AnalyzeError when the stem gives no folder name and no out is given, when the output folder is a file, or, without force, when it holds a report or notes of another stem, a report of the same name with other content, a layers.json or notes.mid that is not this tool’s, a spectrogram.png without a report, or the backup that a killed run left; when the note list or the stem cannot be read, when the notes step fails, or when an output file cannot be written.