Пример #1
0
    def systemFromSystem(self, systemElement, systemObj=None):
        r'''
        returns a :class:`~music21.stream.System` object from a <system> tag.
        The System object will contain :class:`~music21.stream.Part` objects
        which will have the notes, etc. contained in it.  

        TODO: Handle multiple <voices>
        '''
        if systemObj is None:
            systemObj = stream.System()

        stavesList = self.getChildrenByTag(systemElement, 'staves')
        if len(stavesList) == 0:
            raise CapellaImportException(
                "No <staves> tag found in this <system> element")
        elif len(stavesList) > 1:
            raise CapellaImportException(
                "More than one <staves> tag found in this <system> element")
        stavesElement = stavesList[0]
        staffList = self.getChildrenByTag(stavesElement, 'staff')
        if len(stavesList) == 0:
            raise CapellaImportException(
                "No <staff> tag found in the <staves> element for this <system> element"
            )
        for thisStaffElement in staffList:
            # do something with defaultTime
            partId = "UnknownPart"
            if 'layout' in thisStaffElement._attrs:
                partId = thisStaffElement._attrs['layout'].value
            partObj = stream.Part()
            partObj.id = partId

            voicesList = self.getChildrenByTag(thisStaffElement, 'voices')
            if len(voicesList) == 0:
                raise CapellaImportException(
                    "No <voices> tag found in the <staff> tag for the <staves> element for this <system> element"
                )
            voicesElement = voicesList[0]
            voiceList = self.getChildrenByTag(voicesElement, 'voice')
            if len(voiceList) == 0:
                raise CapellaImportException(
                    "No <voice> tag found in the <voices> tag for the <staff> tag for the <staves> element for this <system> element"
                )
            if len(voiceList) == 1:  # single voice staff... perfect!
                thisVoiceElement = voiceList[0]
                noteObjectsList = self.getChildrenByTag(
                    thisVoiceElement, 'noteObjects')
                if len(noteObjectsList) == 0:
                    raise CapellaImportException(
                        "No <noteObjects> tag found in the <voice> tag found in the <voices> tag for the <staff> tag for the <staves> element for this <system> element"
                    )
                elif len(noteObjectsList) > 1:
                    raise CapellaImportException(
                        "More than one <noteObjects> tag found in the <voice> tag found in the <voices> tag for the <staff> tag for the <staves> element for this <system> element"
                    )
                thisNoteObject = noteObjectsList[0]
                self.streamFromNoteObjects(thisNoteObject, partObj)
            systemObj.insert(0, partObj)
        return systemObj
Пример #2
0
    def systemFromSystem(self, systemElement, systemObj=None):
        r'''
        returns a :class:`~music21.stream.System` object from a <system> tag.
        The System object will contain :class:`~music21.stream.Part` objects
        which will have the notes, etc. contained in it.

        TODO: Handle multiple <voices>
        '''
        if systemObj is None:
            systemObj = stream.System()

        stavesList = systemElement.findall('staves')
        if not stavesList:
            raise CapellaImportException('No <staves> tag found in this <system> element')
        if len(stavesList) > 1:
            raise CapellaImportException(
                'More than one <staves> tag found in this <system> element')
        stavesElement = stavesList[0]
        staffList = stavesElement.findall('staff')
        if not stavesList:
            raise CapellaImportException(
                'No <staff> tag found in the <staves> element for this <system> element')
        for thisStaffElement in staffList:
            # do something with defaultTime
            partId = 'UnknownPart'
            if 'layout' in thisStaffElement.attrib:
                partId = thisStaffElement.attrib['layout']
            partObj = stream.Part()
            partObj.id = partId

            voicesList = thisStaffElement.findall('voices')
            if not voicesList:
                raise CapellaImportException(
                    'No <voices> tag found in the <staff> tag for the <staves> element '
                    + 'for this <system> element')
            voicesElement = voicesList[0]
            voiceList = voicesElement.findall('voice')
            if not voiceList:
                raise CapellaImportException(
                    'No <voice> tag found in the <voices> tag for the <staff> tag for the '
                    + '<staves> element for this <system> element')
            if len(voiceList) == 1:  # single voice staff... perfect!
                thisVoiceElement = voiceList[0]
                noteObjectsList = thisVoiceElement.findall('noteObjects')
                if not noteObjectsList:
                    raise CapellaImportException(
                        'No <noteObjects> tag found in the <voice> tag found in the '
                        + '<voices> tag for the <staff> tag for the <staves> element for '
                        + 'this <system> element')
                if len(noteObjectsList) > 1:
                    raise CapellaImportException(
                        'More than one <noteObjects> tag found in the <voice> tag found '
                        + 'in the <voices> tag for the <staff> tag for the <staves> element '
                        + 'for this <system> element')
                thisNoteObject = noteObjectsList[0]
                self.streamFromNoteObjects(thisNoteObject, partObj)
            systemObj.insert(0, partObj)
        return systemObj