Skip to main content

Module ornament_recognizer

Module ornament_recognizer 

Source
Expand description

Ornaments recognized from the notes they are played as: music21’s alpha.analysis.ornamentRecognizer.

The notes an ornament is played as are its busy notes; the note it is written on, where one is given, is its simple note. A recognizer answers the ornament the busy notes play, or nothing where they play none.

use music21_rs::alpha::analysis::ornament_recognizer::TrillRecognizer;
use music21_rs::expressions::OrnamentKind;
use music21_rs::{Duration, Note, StreamElement};

let played: Vec<StreamElement> = ["G4", "A4", "G4", "A4"]
    .iter()
    .map(|name| Ok(Note::from_name(name)?.with_duration(Duration::new(0.25)?).into()))
    .collect::<music21_rs::Result<_>>()?;
let trill = TrillRecognizer::default().recognize(&played, &[])?.expect("a trill");
assert_eq!(trill.kind(), OrnamentKind::Trill);
assert_eq!(trill.quarter_length(), 0.25);

Structs§

TrillRecognizer
Recognizes busy notes as a trill: music21’s TrillRecognizer.
TurnRecognizer
Recognizes busy notes as a turn: music21’s TurnRecognizer.

Functions§

ornament_note_quarter_length
How long each ornamental note lasts, the busy notes taken as one ornament: music21’s calculateOrnamentNoteQl.
ornament_total_quarter_length
How long all the busy notes last together: the first simple note’s length where one is given, else the busy notes’ lengths added up. music21’s calculateOrnamentTotalQl.