Module musx.mxml.part
A class that represents a musical part in a Notation.
Expand source code
"""
A class that represents a musical part in a `musx.mxml.notation.Notation`.
"""
class Part():
    """
    A class that represents a musical part in a `musx.mxml.notation.Notation`.
    A part that has been added to a notation contains a backpointer
    to its owning notation.
    Parameters
    ----------
    id : string
        A string part identifier from the MusicXml file.
    """
    def __init__(self, id, measures=[]):
        self.id = id
        """The string part id from the MusicXml file."""
        self.measures = []
        """The list of measures in the part."""
        for m in measures:
            self.add_measure(m)
    def __iter__(self):     
        return iter(self.measures)
    def __str__(self):
        text = self.id
        return f'<Part: {text}>' #  {hex(id(self))}
    __repr__ = __str__ 
    def add_measure(self, measure):
        """
        Adds a measure to part. Once added, the measure will have a
        backpointer to its owning part.
        """
        measure.part = self  # back link from measure to its part
        self.measures.append(measure)
Classes
class Part (id, measures=[])- 
A class that represents a musical part in a
Notation.A part that has been added to a notation contains a backpointer to its owning notation.
Parameters
id:string- A string part identifier from the MusicXml file.
 
Expand source code
class Part(): """ A class that represents a musical part in a `musx.mxml.notation.Notation`. A part that has been added to a notation contains a backpointer to its owning notation. Parameters ---------- id : string A string part identifier from the MusicXml file. """ def __init__(self, id, measures=[]): self.id = id """The string part id from the MusicXml file.""" self.measures = [] """The list of measures in the part.""" for m in measures: self.add_measure(m) def __iter__(self): return iter(self.measures) def __str__(self): text = self.id return f'<Part: {text}>' # {hex(id(self))} __repr__ = __str__ def add_measure(self, measure): """ Adds a measure to part. Once added, the measure will have a backpointer to its owning part. """ measure.part = self # back link from measure to its part self.measures.append(measure)Instance variables
var id- 
The string part id from the MusicXml file.
 var measures- 
The list of measures in the part.
 
Methods
def add_measure(self, measure)- 
Adds a measure to part. Once added, the measure will have a backpointer to its owning part.
Expand source code
def add_measure(self, measure): """ Adds a measure to part. Once added, the measure will have a backpointer to its owning part. """ measure.part = self # back link from measure to its part self.measures.append(measure)