music21.musicxml.helpers

Functions

music21.musicxml.helpers.dump(obj)

wrapper around xml.etree.ElementTree that prints a string in every case and indents tags and sorts attributes. (Prints, does not return)

>>> from music21.musicxml.helpers import dump
>>> from xml.etree.ElementTree import Element
>>> e = Element('accidental')
>>> dump(e)
<accidental />
>>> e.text = '∆'
>>> e.text == '∆'
True
>>> dump(e)
<accidental>∆</accidental>
music21.musicxml.helpers.dumpString(obj, *, noCopy=False) str

wrapper around xml.etree.ElementTree that returns a string in every case and indents tags and sorts attributes.

>>> from music21.musicxml.m21ToXml import Element
>>> from music21.musicxml.helpers import dumpString
>>> e = Element('accidental')
>>> dumpString(e)
'<accidental />'
>>> e.text = '∆'
>>> e.text == '∆'
True
>>> dumpString(e)
'<accidental>∆</accidental>'
music21.musicxml.helpers.indent(elem, level=0)

helper method, indent an element in place:

music21.musicxml.helpers.insertBeforeElements(root, insert, tagList=None)

Insert element insert into element root at the earliest position of any instance of a child tag given in tagList. Append the element if tagList is None.

>>> from xml.etree.ElementTree import fromstring as El
>>> from music21.musicxml.helpers import insertBeforeElements, dump
>>> root = El('<clef><sign>G</sign><line>4</line></clef>')
>>> insert = El('<foo/>')
>>> insertBeforeElements(root, insert, tagList=['line'])
>>> dump(root)
<clef>
    <sign>G</sign>
    <foo />
    <line>4</line>
</clef>

Now insert another element at the end by not specifying a tag list:

>>> insert2 = El('<bar/>')
>>> insertBeforeElements(root, insert2)
>>> dump(root)
<clef>
    <sign>G</sign>
    <foo />
    <line>4</line>
    <bar />
</clef>
music21.musicxml.helpers.isFullMeasureRest(r: music21.note.Rest) bool
music21.musicxml.helpers.measureNumberComesBefore(mNum1: str, mNum2: str) bool

Determine whether measureNumber1 strictly precedes measureNumber2 given that they could involve suffixes. Equal values return False.

>>> from music21.musicxml.helpers import measureNumberComesBefore
>>> measureNumberComesBefore('23', '24')
True
>>> measureNumberComesBefore('23', '23')
False
>>> measureNumberComesBefore('23', '23a')
True
>>> measureNumberComesBefore('23a', '23b')
True
>>> measureNumberComesBefore('23b', '23a')
False
>>> measureNumberComesBefore('23b', '24a')
True
>>> measureNumberComesBefore('23b', '23b')
False