Skip to main content

element_xml

Function element_xml 

Source
pub fn element_xml(
    element: &StreamElement,
    around: &Surroundings<'_>,
) -> Result<Vec<String>>
Available on crate feature musicxml only.
Expand description

The MusicXML music21’s MeasureExporter writes for one element, each top-level element as a document of its own.

The element stands at offset in measure, whose meter and clefs are what decide, as they do for music21, whether a rest fills its bar and where it is displayed; with no measure it stands alone in one of its own. The writer has written nothing of the measure before it.

A note is one <note>, a chord a <note> for each of its pitches, a dynamic or a text mark a <direction>; a clef, a key or a meter is the <clef>, <key> or <time> that goes in a measure’s <attributes>, a barline is its <barline> with no location, and a text box the <credit> a score writes for it. What a measure writes nothing for, such as an instrument, writes nothing here.

use music21::{Duration, Note, StreamElement};
use music21::musicxml::{Surroundings, element_xml};

let note = Note::from_name("D#4")?.with_duration(Duration::half());
let written = element_xml(&StreamElement::from(note), &Surroundings::default())?;
assert_eq!(written.len(), 1);
assert!(written[0].starts_with("<note>"));
assert!(written[0].contains("<type>half</type>"));

§Errors

What the measure writer refuses for the element: a duration no single note value writes, a stream, a colour CSS has no name for.