Esempio n. 1
0
    def testFreezeThawSimpleVariant(self):
        from music21 import freezeThaw
        from music21 import variant
        from music21 import stream
        from music21 import note

        s = stream.Stream()
        m = stream.Measure()
        m.append(note.Note(type='whole'))
        s.append(m)

        s2 = stream.Stream()
        m2 = stream.Measure()
        n2 = note.Note('D#4')
        n2.duration.type = 'whole'
        m2.append(n2)
        s2.append(m2)
        v = variant.Variant(s2)

        s.insert(0, v)

        sf = freezeThaw.StreamFreezer(s)
        d = sf.writeStr()

        st = freezeThaw.StreamThawer()
        st.openStr(d)
        s = st.stream
Esempio n. 2
0
def testMIDIParse():
    from music21 import converter, common
    from music21 import freezeThaw

    #a = 'https://github.com/ELVIS-Project/vis/raw/master/test_corpus/prolationum-sanctus.midi'
    #c = converter.parse(a)
#     c = corpus.parse('bwv66.6', forceSource=True)
#     v = freezeThaw.StreamFreezer(c)
#     v.setupSerializationScaffold()
#     return v.writeStr() # returns a string
    import os
    a = os.path.join(common.getSourceFilePath(),
                     'midi',
                     'testPrimitive',
                     'test03.mid')

    #a = 'https://github.com/ELVIS-Project/vis/raw/master/test_corpus/prolationum-sanctus.midi'
    c = converter.parse(a)
    v = freezeThaw.StreamFreezer(c)
    v.setupSerializationScaffold()


    mockType = lambda x: x.__class__.__name__ == 'weakref'
    ty = TreeYielder(mockType)
    for val in ty.run(c):
        print(val, ty.currentLevel())
Esempio n. 3
0
    def x_testSimplePickle(self):
        from music21 import freezeThaw
        from music21 import corpus

        c = corpus.parse('bwv66.6').parts[0].measure(0).notes
        #  c.show('t')
        #
        # for el in c:
        #     storedIds.append(el.id)
        #     storedSitesIds.append(id(el.sites))
        #
        # return

        n1 = c[0]
        n2 = c[1]
        sf = freezeThaw.StreamFreezer(c, fastButUnsafe=True)
        sf.setupSerializationScaffold()
        for dummy in n1.sites.siteDict:
            pass
            # print(idKey)
            # print(n1.sites.siteDict[idKey]['obj'])
        for dummy in n2.sites.siteDict:
            pass
            # print(idKey)
            # print(n2.sites.siteDict[idKey]['obj'])

        dummy = pickle.dumps(c, protocol=-1)
Esempio n. 4
0
    def fromStream(self, thisStream, mode=None):
        if mode is None:
            mode = self.mode

        if (thisStream.metadata is not None
                and thisStream.metadata.title != ""):
            title = thisStream.metadata.title
        else:
            title = "Music21 Fragment"
        sf = freezeThaw.StreamFreezer(thisStream)

        ## recursive data structures will be expanded up to a high depth -- make sure there are none...
        data = sf.writeStr(fmt='jsonpickle')
        dataSplit = self.splitLongJSON(data)
        if mode == 'json':
            return data
        elif mode == 'jsonSplit':
            return dataSplit
        elif mode == 'jsbody':
            return self.getJSBody(dataSplit)
        elif mode == 'jsbodyScript':
            return self.getJSBodyScript(dataSplit)
        elif mode == 'html':
            return self.getHTML(dataSplit, title)
        else:
            raise VexflowToM21JException("Cannot deal with mode: %r" % mode)
Esempio n. 5
0
    def testBigCorpus(self):
        from music21 import corpus, converter
        #import time
        #print time.time()  # 8.3 sec from pickle; 10.3 sec for forceSource...
        s = corpus.parse('beethoven/opus133')  #, forceSource = True)
        #print time.time()  # purePython: 33! sec; cPickle: 25 sec
        #data = converter.freezeStr(s, fmt='pickle')
        #print time.time()  # cPickle: 5.5 sec!
        sf = freezeThaw.StreamFreezer(s, fastButUnsafe=True)
        data = sf.writeStr()

        #print time.time() # purePython: 9 sec; cPickle: 3.8 sec!
        unused_s2 = converter.thawStr(data)
Esempio n. 6
0
def testMIDIParse():
    from music21 import converter
    from music21 import freezeThaw

    a = 'https://github.com/ELVIS-Project/vis/raw/master/test_corpus/prolationum-sanctus.midi'
    c = converter.parse(a)
    v = freezeThaw.StreamFreezer(c)
    v.setupSerializationScaffold()
    #return v.writeStr() # returns a string

    mockType = lambda x: x.__class__.__name__ == 'weakref'
    ty = TreeYielder(mockType)
    for val in ty.run(v):
        print(val, ty.currentLevel())
Esempio n. 7
0
    def testSerializationScaffoldA(self):
        from music21 import note, stream
        from music21 import freezeThaw

        n1 = note.Note()

        s1 = stream.Stream()
        s2 = stream.Stream()

        s1.append(n1)
        s2.append(n1)

        sf = freezeThaw.StreamFreezer(s2, fastButUnsafe=False)
        sf.setupSerializationScaffold()

        # test safety
        self.assertTrue(s2.hasElement(n1))
        self.assertTrue(s1.hasElement(n1))
Esempio n. 8
0
    def x_testFreezeThawPickle(self):
        from music21 import freezeThaw
        from music21 import corpus

        c = corpus.parse('luca/gloria')
        # c.show('t')

        sf = freezeThaw.StreamFreezer(c, fastButUnsafe=True)
        d = sf.writeStr()
        # print(d)

        st = freezeThaw.StreamThawer()
        st.openStr(d)
        s = st.stream

        # test to see if we can find everything
        for dummy in s.recurse():
            pass
Esempio n. 9
0
    def testFreezeThawVariant(self):
        from music21 import freezeThaw
        from music21 import corpus
        from music21 import variant
        from music21 import stream
        from music21 import note

        c = corpus.parse('luca/gloria')

        data2M2 = [('f', 'eighth'), ('c', 'quarter'), ('a', 'eighth'),
                   ('a', 'quarter')]
        stream2 = stream.Stream()
        m = stream.Measure()
        for pitchName, durType in data2M2:
            n = note.Note(pitchName)
            n.duration.type = durType
            m.append(n)
#            stream2.append(n)
        stream2.append(m)
        # c.show('t')
        variant.addVariant(c.parts[0],
                           6.0,
                           stream2,
                           variantName='rhythmic_switch',
                           replacementDuration=3.0)

        # test Variant is in stream
        unused_v1 = c.parts[0].getElementsByClass('Variant')[0]

        sf = freezeThaw.StreamFreezer(c, fastButUnsafe=True)
        # sf.v = v
        d = sf.writeStr()
        # print(d)

        # print('thawing.')

        st = freezeThaw.StreamThawer()
        st.openStr(d)
        s = st.stream
        # s.show('lily.pdf')
        p0 = s.parts[0]
        variants = p0.getElementsByClass('Variant')
        v2 = variants[0]
        self.assertEqual(v2._stream[0][1].offset, 0.5)