Skip to main content

Module musicxml

Module musicxml 

Source
Available on crate feature musicxml only.
Expand description

MusicXML import and export: music21’s musicxml.xmlToM21 and musicxml.m21ToXml. MusicXML export: music21’s musicxml.m21ToXml.

to_musicxml writes a score as a score-partwise document, element for element as music21’s ScoreExporter writes it with makeNotation=False: the score is taken as already notated, so its measures, beams, ties and the accidentals it shows are written as they stand rather than worked out again. A score is parts holding measures, a measure may hold voices, and a stream holding no parts is written as one part.

ExportOptions::make_notation asks for the notation to be worked out first, as music21’s exporter does by default: a part of loose notes, or a score whose lengths no single note value writes, is then written as music21 writes it.

The writer does no file IO; it hands back the document as a string.

Modules§

step
music21’s per-element steps of reading MusicXML: what its MeasureParser makes of one <clef>, one <note>, one <measure>.

Structs§

ExportOptions
What a document says about how it was made, where the score does not say.
Joined
A spanner joining an element written alone, and where among the spanner’s elements the element stands.
StaffDifferences
Which marks the staves of a group start with differently: music21’s isMultiAttribute for keys and meters.
Surroundings
Where an element written alone stands: the measure holding it, its offset there, and the spanners joining it, which mark the element as they mark it in a score (a slur’s end on a note, a pedal’s change at a bounce); the directions a spanner opens and closes with are not the element’s and are left out. By default it stands at the start of a measure of its own, joined by none.

Enums§

Across
Whether the staves of a group start in the same key, or meter.
JoinableGroups
Which of a score’s staff groups are written as one part each.
SpannerEnd
Which end of a spanner is written.
SpannerParameter
A value of spanner_parameters: text, or a number music21 keeps as one.

Constants§

CSS_COLORSDeprecated
The CSS3 colour names: moved to the style module.
DIVISIONS_PER_QUARTER
How many divisions of a quarter note durations are counted in: music21’s defaults.divisionsPerQuarter, 32 * 3 * 3 * 5 * 7, which counts every tuplet music21 writes in whole numbers.
DYNAMIC_MARKS
music21’s xmlObjects.DYNAMIC_MARKS: the marks MusicXML writes as a <dynamics> element of their own name.
MUSICXML_VERSION
The MusicXML version written.
STAFF_TAGGED
The children of a measure told their staff when staves are joined.

Traits§

XmlTree
An XML element the joining steps can read and change: its tag, attributes, text and children, counted as ElementTree counts them, comments included.

Functions§

add_staff_tags
music21’s addStaffTags: a <staff> in each child of a measure whose tag is one of tags, before its beams, notations, lyrics and sound.
add_staff_tags_to_staves
music21’s addStaffTagsMultiStaffParts: add_staff_tags over every measure of each staff, the first staff numbered one.
chord_with_fret_board_xml
What music21’s chordWithFretBoardToXml writes for a chord symbol with a diagram: the symbol’s <harmony> with the <frame> at its end.
css_color_hexDeprecated
The hex value of a CSS3 colour name: moved to the style module.
divider_text
The text of the comment music21’s addDividerComment writes: the comment centred in signs that pad it out to sixty characters.
element_xml
The MusicXML music21’s MeasureExporter writes for one element, each top-level element as a document of its own.
fraction_to_percent
music21’s xmlObjects.fractionToPercent: a share as a whole percent, truncated.
frame_note_xml
What music21’s fretNoteToXml writes for one stopped string: its <frame-note>.
frame_xml
What music21’s fretBoardToXml writes for a chord diagram: its <frame>, the notes lowest string first; None for a board with no notes.
from_musicxml
Reads a MusicXML document – the text of a .musicxml file, or of the score inside a compressed .mxl – into a score: music21’s converter.parse for the format.
instrument_xml
What music21’s instrumentToXmlScoreInstrument and instrumentToXmlMidiInstrument write for an instrument: its <score-instrument> and its <midi-instrument>.
is_valid_xsd_id
music21’s xmlObjects.isValidXSDID: whether text is an xsd:ID, an XML name with no colon, which an element’s id attribute has to be.
join_staves
music21’s movePartStaffMeasureContents, setEarliestAttributesAndClefs and the staff tags before them: the staves of parts, first to last, joined into the first.
joinable_staff_groups
music21’s joinableGroups for a whole score: the staff groups whose staves are written as one <part>.
layout_xml
The element music21 writes a page, system or staff layout as: <page-layout>, <system-layout> or <staff-layout>, as pageLayoutToXmlPageLayout and its neighbours write them. None for a score layout, which is written as the parts of <defaults>.
make_notation
A copy of a stream, or of an element put in one, with the notation it leaves unsaid worked out, as ExportOptions::make_notation works it out before writing: music21’s GeneralObjectExporter.fromGeneralObject and the score’s makeNotation. What comes back is a score.
measure_number_comes_before
music21’s measureNumberComesBefore: whether one measure number comes strictly before another, suffixes and all.
move_measure_contents
music21’s moveMeasureContents: the contents of measure moved into other behind a <backup> to the start, with voices numbered on from other’s, mid-measure clefs told their staff, and a barline replacing the one at the same end.
move_part_staff_contents
music21’s movePartStaffMeasureContents: every later staff’s measures moved into the first’s, a measure the first lacks put in where it falls.
musicxml_octave
An octave as MusicXML can say it: music21’s moveOctaveIntoMusicxmlRange, new in v11, which moves an octave outside the format’s 0 to 9 to the nearest end of that range rather than writing a number no reader will take.
normalize_color
music21’s normalizeColor: a hex colour upper-cased, and a CSS colour name written as its hex value.
part_group_xml
What music21’s staffGroupToXmlPartGroup writes for a staff group: the <part-group type="start">, its number left for the part list to give it.
process_subsequent_part_staff
music21’s processSubsequentPartStaff: each measure of source moved into the measure of target with the same number, and the measures target has no number for gathered, with their divider comments, to be inserted where they fall.
score_header_xml
What music21’s ScoreExporter writes before a score’s parts, element by element: the work and movement titles, <identification>, <defaults>, a <credit> for each text box and the <part-list>.
set_earliest_attributes_and_clefs
music21’s setEarliestAttributesAndClefsPartStaff: the first staff’s first <attributes> told how many staves there are, given a clef for each, and, where they differ across the staves, a key and a meter for each.
sound_tempo
music21’s setSoundTempo: the quarters a minute a <sound>’s tempo attribute plays at, or None for one that is nought or no number, which sets no tempo.
spanner_parameters
music21’s _spannerStartParameters and _spannerEndParameters: the attributes an octave line, a bracket line, a hairpin or a pedal mark writes where it starts or stops. Every other spanner has only its type.
staff_details_xml
What music21’s staffLayoutToXmlStaffDetails writes for a staff layout: its <staff-details>.
staff_differences
Which marks a group’s staves start with differently: music21’s isMultiAttribute for keys and for meters.
to_musicxml
Writes a score as a MusicXML document.
transpose_xml
What music21’s intervalToXmlTranspose writes for an interval a part is transposed by: its <transpose>.
type_to_musicxml
music21’s typeToMusicXMLType: the MusicXML <type> for a music21 duration type, which is the type itself but for longa, written long. The types MusicXML has no value for are refused.