Ejemplo 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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)