pub fn make_measures(stream: &Stream) -> Result<Stream>Expand description
Cuts a stream into measures by the meters it holds: music21’s
makeMeasures.
A stream holding parts has each of them cut. Otherwise the stream is
flattened, unless it holds voices, which are kept as the voices of each
measure. A stream with no meter at its start is in 4/4 until it says
otherwise. The first measure takes the clef standing at the start, or the
one that fits the notes best; each measure where the meter changes states
it; the last ends with a final barline. A note is put in the measure it
starts in and is not cut where it runs past the barline.
Spanners are not carried across, as the places they name move.
use music21_rs::makenotation::make_measures;
use music21_rs::{Duration, Note, Stream, TimeSignature};
let mut line = Stream::new();
line.insert(0.0, TimeSignature::new(3, 4)?);
for (place, name) in ["C4", "D4", "E4", "F4"].iter().enumerate() {
let note = Note::from_name(name)?.with_duration(Duration::quarter());
line.insert(place as f64, note);
}
let measured = make_measures(&line)?;
assert_eq!(measured.measures().len(), 2);
assert_eq!(measured.measures()[1].number(), 2);