Skip to main content

make_notation

Function make_notation 

Source
pub fn make_notation(stream: &mut Stream) -> Result<()>
Expand description

Works out what a score leaves unsaid, as music21’s makeNotation does, changing the stream in place.

A stream holding parts has each part done; any other stream is done as one part. A part with no measures is first cut into them, its overlapping notes put in voices. Then, in music21’s order: accidentals are decided where no accidental in the part has been decided yet, notes running past a barline are cut and tied, tuplets left incomplete by a cut are completed and ones a cut left whole are joined back, the notes are beamed where no note in the part is beamed yet, and each measure’s tuplets are bracketed where none of them is yet.

Spanners stay on the elements they joined; where one of those is cut, on its first piece.

§Errors

A part that cannot be cut into measures, as its meters say.

use music21_rs::makenotation::make_notation;
use music21_rs::{Duration, Note, Stream, StreamKind, TimeSignature};

let mut part = Stream::with_kind(StreamKind::Part);
part.insert(0.0, TimeSignature::new(2, 4)?);
for (place, name) in ["C4", "D4", "E4", "F4"].iter().enumerate() {
    let note = Note::from_name(name)?.with_duration(Duration::eighth());
    part.insert(place as f64 * 0.5, note);
}
part.insert(2.0, Note::from_name("G4")?.with_duration(Duration::half()));
make_notation(&mut part)?;
let measures = part.measures();
assert_eq!(measures.len(), 2);