pub fn from_capella(document: &str) -> Result<Stream>Expand description
Reads the text of a Capella score.xml into a score, as music21’s
CapellaImporter.scoreFromFile reads a .capx.
The score is read system by system, each staff of a system being a part’s share of it, and a part’s shares are put end to end, each system starting where the longest staff of the one before ended. A staff of one voice is read: clefs, key signatures, meters, rests, notes and chords with their accidentals, ties, triplets and other tuplets and lyrics, and barlines. A clef or key signature restating the one before is dropped, and each part is then cut into measures by its meters.
music21’s limits are kept: a staff of more than one voice is read as empty, a barline is a mark standing in the measure rather than the measure’s own (where a MusicXML writer passes it over).
use music21_rs::capella::from_capella;
let score = from_capella(
"<score><systems><system><staves><staff layout=\"S\"><voices><voice><noteObjects>\
<clefSign clef=\"treble\"/><timeSign time=\"2/4\"/>\
<chord><duration base=\"1/4\"/><heads><head pitch=\"C5\"/></heads></chord>\
<chord><duration base=\"1/4\"/><heads><head pitch=\"E5\"/></heads></chord>\
</noteObjects></voice></voices></staff></staves></system></systems></score>",
)?;
let pitches = score.pitches();
assert_eq!(pitches[0].name_with_octave(), "C4");§Errors
A document that is not XML, one with no systems or with a system, staff or voice missing what music21 asks for, a chord with no heads or with more than one duration, a head with no pitch, a barline or meter music21 does not know, or a number that is not one.