Пример #1
0
    def __init__(self, input_mei_paths):
        '''
        PARAMETERS
        ----------
        input_mei_paths {list}: list of mei paths to combine
        '''

        self._input_mei_paths = input_mei_paths
        if len(self._input_mei_paths):
            self._meidoc = pymei.read(self._input_mei_paths[0])
        else:
            self._meidoc = None
Пример #2
0
    def combine(self):
        if self._meidoc and len(self._input_mei_paths) > 1:
            base_facsimile = self._meidoc.getElementsByName('facsimile')[0]
            base_section = self._meidoc.getElementsByName('section')[0]
            for f in self._input_mei_paths[1:]:
                mei = pymei.read(f)

                # combine surface
                surface = mei.getElementsByName('surface')
                if len(surface):
                    # have to remove the child from the old document in memory
                    # or else pymei segfaults ...
                    surface[0].getParent().removeChild(surface[0])
                    base_facsimile.addChild(surface[0])

                # combine measures
                pb = MeiElement('pb')
                base_section.addChild(pb)

                # get last measure number
                measures = base_section.getChildrenByName('measure')
                last_measure_n = int(measures[-1].getAttribute('n').value)

                new_section = mei.getElementsByName('section')[0]
                music_elements = new_section.getChildren()

                for e in music_elements:
                    if e.getName() == 'measure':
                        last_measure_n += 1
                        e.addAttribute('n', str(last_measure_n))

                    base_section.addChild(e)

                # remove all musical elements from the old document or else pymei segfaults
                new_section.getParent().deleteAllChildren()

            self._add_revision()