Skip to main content

from_mei

Function from_mei 

Source
pub fn from_mei(document: &str) -> Result<Stream>
Expand description

Reads an MEI document into a score: music21’s converter.parse of one.

Every <staffDef> number is a part. A measure holds a voice for each <layer>; a part with no staff in a measure rests through it, and a measure rest lasts what the longest staff of its measure lasts. Beams, tuplets, ties and slurs are read where they are written on the notes and where they stand apart and name the notes by xml:id.

The text is the document’s own, already decoded: the library opens no file. A barline written inside a layer is passed over.

use music21_rs::mei::from_mei;

let score = from_mei(
    r#"<mei xmlns="http://www.music-encoding.org/ns/mei"><music><score>
    <scoreDef meter.count="2" meter.unit="4">
      <staffGrp><staffDef n="1" clef.shape="G" clef.line="2"/></staffGrp>
    </scoreDef>
    <section><measure n="1"><staff n="1"><layer n="1">
      <note pname="c" oct="4" dur="4"/><note pname="e" oct="4" dur="4" accid="f"/>
    </layer></staff></measure></section>
    </score></music></mei>"#,
)?;
let names: Vec<String> = score.parts()[0]
    .pitches()
    .iter()
    .map(|pitch| pitch.name_with_octave())
    .collect();
assert_eq!(names, ["C4", "Eb4"]);