Example #1
0
    def getET(self, obj):
        from music21.musicxml.m21ToXml import ScoreExporter

        SX = ScoreExporter(obj)
        mxScore = SX.parse()
        helpers.indent(mxScore)
        return mxScore
Example #2
0
 def getET(self, obj):
     '''
     Return a <score-partwise> ElementTree.
     Does NOT call makeNotation() like most calls to show() and write().
     '''
     SX = ScoreExporter(obj)
     mxScore = SX.parse()
     helpers.indent(mxScore)
     return mxScore
Example #3
0
    def testSimple(self):
        # b = converter.parse(corpus.corpora.CoreCorpus().getWorkList('cpebach')[0],
        #    format='musicxml', forceSource=True)
        b = corpus.parse('cpebach')
        # b.show('text')
        # n = b[note.NotRest].first()
        # print(n.expressions)
        # return

        SX = ScoreExporter(b)
        mxScore = SX.parse()

        helpers.indent(mxScore)

        sio = io.BytesIO()

        sio.write(SX.xmlHeader())

        et = ElementTree(mxScore)
        et.write(sio, encoding='utf-8', xml_declaration=False)
        v = sio.getvalue()
        sio.close()

        v = v.decode('utf-8')
        # v = v.replace(' />', '/>')  # normalize

        # b2 = converter.parse(v)
        fp = b.write('musicxml')
        if self.show:
            print(fp)

        with io.open(fp, encoding='utf-8') as f:
            v2 = f.read()
        differ = list(difflib.ndiff(v.splitlines(), v2.splitlines()))
        for i, l in enumerate(differ):
            if l.startswith('-') or l.startswith('?') or l.startswith('+'):
                if 'id=' in l:
                    continue
                if self.show:
                    print(l)
                    # for j in range(i - 1,i + 1):
                    #    print(differ[j])
                    # print('------------------')
        import os
        os.remove(fp)