def testRealizeVolumeA(self): from music21 import stream, dynamics, note, volume s = stream.Stream() s.repeatAppend(note.Note('g3'), 16) # before insertion of dynamics match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, [ '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71' ]) for i, d in enumerate(['pp', 'p', 'mp', 'f', 'mf', 'ff', 'ppp', 'mf']): s.insert(i * 2, dynamics.Dynamic(d)) # cached will be out of date in regard to new dynamics match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, [ '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71', '0.71' ]) # calling realize will set all to new cached values volume.realizeVolume(s) match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, [ '0.35', '0.35', '0.5', '0.5', '0.64', '0.64', '0.99', '0.99', '0.78', '0.78', '1.0', '1.0', '0.21', '0.21', '0.78', '0.78' ]) # we can get the same results without using realizeVolume, though # this uses slower context searches s = stream.Stream() s.repeatAppend(note.Note('g3'), 16) for i, d in enumerate(['pp', 'p', 'mp', 'f', 'mf', 'ff', 'ppp', 'mf']): s.insert(i * 2, dynamics.Dynamic(d)) match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, [ '0.35', '0.35', '0.5', '0.5', '0.64', '0.64', '0.99', '0.99', '0.78', '0.78', '1.0', '1.0', '0.21', '0.21', '0.78', '0.78' ]) # loooking at raw velocity values match = [n.volume.velocity for n in s.notes] self.assertEqual(match, [ None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None ]) # can set velocity with realized values volume.realizeVolume(s, setAbsoluteVelocity=True) match = [n.volume.velocity for n in s.notes] self.assertEqual(match, [ 45, 45, 63, 63, 81, 81, 126, 126, 99, 99, 127, 127, 27, 27, 99, 99 ])
def testRealizeVolumeA(self): from music21 import stream, dynamics, note, volume s = stream.Stream() s.repeatAppend(note.Note('g3'), 16) # before insertion of dynamics match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, ['0.71'] * 16) for i, d in enumerate(['pp', 'p', 'mp', 'f', 'mf', 'ff', 'ppp', 'mf']): s.insert(i * 2, dynamics.Dynamic(d)) # cached will be out of date in regard to new dynamics match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, ['0.71'] * 16) # calling realize will set all to new cached values volume.realizeVolume(s) match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, ['0.35', '0.35', '0.5', '0.5', '0.64', '0.64', '0.99', '0.99', '0.78', '0.78', '1.0', '1.0', '0.21', '0.21', '0.78', '0.78']) # we can get the same results without using realizeVolume, though # this uses slower context searches s = stream.Stream() s.repeatAppend(note.Note('g3'), 16) for i, d in enumerate(['pp', 'p', 'mp', 'f', 'mf', 'ff', 'ppp', 'mf']): s.insert(i * 2, dynamics.Dynamic(d)) match = [n.volume.cachedRealizedStr for n in s.notes] self.assertEqual(match, ['0.35', '0.35', '0.5', '0.5', '0.64', '0.64', '0.99', '0.99', '0.78', '0.78', '1.0', '1.0', '0.21', '0.21', '0.78', '0.78']) # loooking at raw velocity values match = [n.volume.velocity for n in s.notes] self.assertEqual(match, [None] * 16) # can set velocity with realized values volume.realizeVolume(s, setAbsoluteVelocity=True) match = [n.volume.velocity for n in s.notes] self.assertEqual(match, [45, 45, 63, 63, 81, 81, 126, 126, 99, 99, 127, 127, 27, 27, 99, 99])