Tuesday, June 15, 2010

Mensural Canons and Other Applications of Stream Transformations

We have a number of powerful Stream transformation methods available now, including transpose() and augmentOrDiminish(). My favorite task with such utilities is creating mensural canons. The example below does just that, using a Bach soprano line as the melodic source.

Further explanation can be found here.


from music21 import *
src = corpus.parse('bach/bwv323.xml')
ex = src.getElementById('Soprano').flatten().notes

s = stream.Score()
for scalar, t in [(1, 'p1'), (2, 'p-5'), (.5, 'p-11'), (1.5, -24)]:
    part = ex.augmentOrDiminish(scalar, inPlace=False)
    part.transpose(t, inPlace=True)
    s.insert(0, part)
s.show()


(Updated 2026-Feb: update links and let example to work with modern music21 -- parse for parseWork, and flatten() for flat.)

No comments:

Post a Comment