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.
A stream that would take more than MAX_MEASURES measures is refused
with an error. A few bytes of a file can say a note lasts hundreds of
millions of quarters, and that many measures do not fit in memory.
use music21::makenotation::make_measures;
use music21::{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);