Previous topic

music21.analysis.metrical

Next topic

music21.musedata.base

music21.musicxml.translate

Low-level conversion routines between MusicXML and music21.

music21.musicxml.translate.durationToMusicXML(d)
Translate a music21 Duration into a complete MusicXML representation.
music21.musicxml.translate.durationToMx(d)

Translate a music21 Duration object to a list of one or more MusicXML Note objects. All rhythms and ties necessary in the MusicXML Notes are configured. The returned mxNote objects are incompletely specified, lacking full representation and information on pitch, etc.

>>> from music21 import *
>>> a = duration.Duration()
>>> a.quarterLength = 3
>>> b = musicxml.translate.durationToMx(a)
>>> len(b) == 1
True
>>> isinstance(b[0], musicxmlMod.Note)
True
>>> a = duration.Duration()
>>> a.quarterLength = .33333333
>>> b = musicxml.translate.durationToMx(a)
>>> len(b) == 1
True
>>> isinstance(b[0], musicxmlMod.Note)
True
music21.musicxml.translate.generalNoteToMusicXML(n)

Translate a music21 Note into a complete MusicXML representation.

>>> from music21 import *
>>> n = note.Note('c3')
>>> n.quarterLength = 3
>>> post = musicxml.translate.generalNoteToMusicXML(n)
>>> post[-100:].replace('\n', '')
'/type>        <dot/>        <notations/>      </note>    </measure>  </part></score-partwise>'
music21.musicxml.translate.lyricToMx(l)
Translate a music21 Lyric object to a MusicXML Lyric object.
music21.musicxml.translate.measureToMusicXML(m)

Translate a music21 Measure into a complete MusicXML string representation. Note: this method is called for complete MusicXML representation of a Measure, not for partial solutions in Part or Stream production.

>>> from music21 import *
>>> m = stream.Measure()
>>> m.repeatAppend(note.Note('g3'), 4)
>>> post = musicxml.translate.measureToMusicXML(m)
>>> post[-100:].replace('\n', '')
' <type>quarter</type>        <notations/>      </note>    </measure>  </part></score-partwise>'
music21.musicxml.translate.measureToMx(m, spannerBundle=None)
Translate a Measure to a MusicXML Measure object.
music21.musicxml.translate.mxToDuration(mxNote, inputM21)

Translate a MusicXML Note object to a music21 Duration object.

>>> from music21 import *
>>> a = musicxml.Note()
>>> a.setDefaults()
>>> m = musicxml.Measure()
>>> m.setDefaults()
>>> a.external['measure'] = m # assign measure for divisions ref
>>> a.external['divisions'] = m.external['divisions']
>>> c = duration.Duration()
>>> musicxml.translate.mxToDuration(a, c)
<music21.duration.Duration 1.0>
>>> c.quarterLength
1.0
music21.musicxml.translate.mxToLyric(mxLyric, inputM21=None)
Translate a MusicXML Lyric object to a music21 Lyric object.
music21.musicxml.translate.mxToMeasure(mxMeasure, spannerBundle=None, inputM21=None)
Translate an mxMeasure (a MusicXML Measure object) into a music21 Measure. If an inputM21 object reference is provided, this object will be configured and returned; otherwise, a new Measure object is created.
music21.musicxml.translate.mxToNote(mxNote, spannerBundle=None, inputM21=None)
Translate a MusicXML Note to a Note. The spanners parameter can be a list or a Stream for storing and processing Spanner objects.
music21.musicxml.translate.mxToRest(mxNote, inputM21=None)
Translate a MusicXML Note object to a Rest. If an inputM21 object reference is provided, this object will be configured; otherwise, a new Rest object is created and returned.
music21.musicxml.translate.mxToStream(mxScore, spannerBundle=None, inputM21=None)
Translate an mxScore into a music21 Score object.
music21.musicxml.translate.mxToStreamPart(mxScore, partId, spannerBundle=None, inputM21=None)
Load a part into a new Stream or one provided by inputM21 given an mxScore and a part name.
music21.musicxml.translate.mxToTie(mxNote, inputM21=None)
Translate a MusicXML Note to a music21 Tie object.
music21.musicxml.translate.noteToMxNotes(n, spannerBundle=None)
Translate a music21 Note into a list of Note objects.
music21.musicxml.translate.restToMxNotes(r)
Translate a Rest to a MusicXML Note object configured with a Rest.
music21.musicxml.translate.streamPartToMx(s, instObj=None, meterStream=None, refStreamOrTimeRange=None, spannerBundle=None)
If there are Measures within this stream, use them to create and return an MX Part and ScorePart. An instObj may be assigned from caller; this Instrument is pre-collected from this Stream in order to configure id and midi-channel values. The meterStream, if provides a template of meters.
music21.musicxml.translate.streamToMx(s, spannerBundle=None)

Create and return a musicxml Score object.

>>> from music21 import *
>>> n1 = note.Note()
>>> measure1 = stream.Measure()
>>> measure1.insert(n1)
>>> s1 = stream.Stream()
>>> s1.insert(measure1)
>>> mxScore = musicxml.translate.streamToMx(s1)
>>> mxPartList = mxScore.get('partList')
music21.musicxml.translate.tieToMx(t)
Translate a music21 Tie object to MusicXML Tie and Tied objects as two component lists.