Medium-level conversion routines to take music21 Streams and other objects and get a full MusicXML String from them. In general do not use this module. Instead call:
>>> s = converter.parse('tinyNotation: 3/4 C4 D E r2.').makeMeasures()
>>> s.show('musicxml')
But you might need this routine if you want to check that the musicxml string returned has certain features:
>>> musicxmlStr = musicxml.m21ToString.fromMusic21Object(s)
>>> '<rest' in musicxmlStr
True
This module is an intermediate level of complexity for working with musicxml between the standard music21 objects and musicxml.toMxObjects
Return a complete musicxml of the DiatonicScale
Overrides the general scale behavior to highlight the tonic and dominant.
Translate a music21 Duration into a complete MusicXML representation.
Rarely rarely used. Only if you call .show() on a duration object
>>> d = duration.Duration(4.0)
>>> dxml = musicxml.m21ToString.fromDuration(d)
>>> print(dxml)
<?xml version="1.0" ...?>
<!DOCTYPE score-partwise
PUBLIC '-//Recordare//DTD MusicXML 2.0 Partwise//EN'
'http://www.musicxml.org/dtds/partwise.dtd'>
<score-partwise>
<movement-title>Music21 Fragment</movement-title>
<identification>
<creator type="composer">Music21</creator>
</identification>
<defaults>
<scaling>
<millimeters>7</millimeters>
<tenths>40</tenths>
</scaling>
</defaults>
<part-list>
...
</part-list>
<part id="...">
<measure number="1">
<attributes>
<divisions>10080</divisions>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>40320</duration>
<type>whole</type>
<notations/>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
Or, more simply
>>> d.show('musicxml')
Provide a complete MusicXML string from a single dynamic by putting it into a Stream first.
Translate a music21 Note into a complete MusicXML representation.
>>> n = note.Note('c3')
>>> n.quarterLength = 3
>>> post = musicxml.m21ToString.fromGeneralNote(n)
>>> #print post
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.
>>> m = stream.Measure()
>>> m.repeatAppend(note.Note('g3'), 4)
>>> post = musicxml.m21ToString.fromMeasure(m)
>>> len(post) > 1000
True
Translate an arbitrary music21 object to a musicxml string and return it
This function is called by music21.base.write() and is the most important function here.
Generate the pitches from this scale and put it into a stream.Measure, then call fromMeasure on it
return a complete musicxml string from a music21 Stream object
return a single TimeSignature as a musicxml document