pub fn realize_chord_symbol_durations(stream: &mut Stream)Expand description
Gives every chord symbol in a stream the time it holds for: music21’s
realizeChordSymbolDurations.
A symbol holds until the next one, wherever in the nesting that is, and the last holds to the end of the stream – so a single symbol over many notes holds for all of them. A stream with no symbols is left alone.
music21 hands back the flattened stream, its symbols being the same
objects as the score’s. A stream here owns what it holds, so the symbols
are changed where they sit and Stream::flatten is there for a caller
who wants the flat reading.
use music21_rs::{ChordSymbol, Note, Stream, realize_chord_symbol_durations};
let mut stream = Stream::new();
stream.insert(0.0, ChordSymbol::parse("C")?);
stream.insert(2.0, ChordSymbol::parse("G7")?);
for beat in 0..8 {
stream.insert(f64::from(beat), Note::from_name("C4")?);
}
realize_chord_symbol_durations(&mut stream);
let held: Vec<f64> = stream
.events()
.iter()
.filter(|event| matches!(event.element(), music21_rs::StreamElement::ChordSymbol(_)))
.map(|event| event.element().quarter_length())
.collect();
assert_eq!(held, [2.0, 6.0]);