pub fn n_pvi(stream: &Stream) -> Result<FloatType>Expand description
The normalized pairwise variability index of a stream’s rhythm (Low,
Grabe and Nolan, 2000): music21’s nPVI.
Each element the stream holds itself is compared with the one before by how long it lasts – the difference of the two lengths over their mean – and the comparisons are averaged and scaled by a hundred. A pair in which either lasts no time adds nothing, but still counts. Every element counts, clefs and meters included, so a stream of the notes and rests alone is usually what is meant.
use music21_rs::Stream;
use music21_rs::analysis::patel::n_pvi;
use music21_rs::stream::{StreamElement, StreamEvent};
use music21_rs::tinynotation::from_tiny_notation;
let line = from_tiny_notation("4/4 C4 D8 C4 D8 C4")?.flatten();
let notes = Stream::from_events(line.events().iter().cloned().filter(|event| {
matches!(event.element(), StreamElement::Note(_) | StreamElement::Rest(_))
}));
assert!((n_pvi(¬es)? - 66.666_666_666_666_67).abs() < 1e-9);§Errors
A stream holding fewer than two elements.