0% found this document useful (0 votes)
2K views

Algorithmic Composition With Python and Music21 - Tutorial 02 - The Sound of Lorenz Attractor

This document summarizes a tutorial on algorithmically composing music based on the Lorenz attractor using Python and the music21 library. It shows the code used to generate the Lorenz attractor data and map it to musical notes, producing a 3-voice MIDI file. The final video and author's online profiles are also listed.

Uploaded by

Oscar Riveros
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Algorithmic Composition With Python and Music21 - Tutorial 02 - The Sound of Lorenz Attractor

This document summarizes a tutorial on algorithmically composing music based on the Lorenz attractor using Python and the music21 library. It shows the code used to generate the Lorenz attractor data and map it to musical notes, producing a 3-voice MIDI file. The final video and author's online profiles are also listed.

Uploaded by

Oscar Riveros
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Algorithmic Composition with Python and Music21

Oscar Riveros
November 05, 2013
Abstract Basic musicalization of the Lorenz attractor.

Part I

Tutorial 02
1 The Sound of Lorenz Attractor
from music21 import * In [738]: from qutip import * from pylab import * from mpl_toolkits.mplot3d import Axes3D %pylab --no-import-all inline
Populating the interactive namespace from numpy and matplotlib

def lorenz(x, y, z, s=10, r=28, b=2.667) : In [739]: x_dot = s*(y - x) y_dot = r*x - y - x*z z_dot = x*y - b*z return x_dot, y_dot, z_dot dt = 0.01 stepCnt = 1024 # Need one more for the initial values xs = np.empty((stepCnt + 1,)) ys = np.empty((stepCnt + 1,)) zs = np.empty((stepCnt + 1,)) # Setting initial values xs[0], ys[0], zs[0] = (0., 1., 1.05) # Stepping through "time". for i in range(stepCnt) : # Derivatives of the X, Y, Z state x_dot, y_dot, z_dot = lorenz(xs[i], ys[i], zs[i]) xs[i + 1] = xs[i] + (x_dot * dt) ys[i + 1] = ys[i] + (y_dot * dt) zs[i + 1] = zs[i] + (z_dot * dt) fig = figure() ax = fig.gca(projection=3d) ax.plot(xs, ys, zs)

ax.set_xlabel("X Axis") ax.set_ylabel("Y Axis") ax.set_zlabel("Z Axis") ax.set_title("Lorenz Attractor") show()

stream_x = stream.Stream(); stream_y = stream.Stream(); In [740]: stream_z = stream.Stream(); def discrete_sin(theta, low_note, high_note): In [741]: return high_note + int(high_note - low_note) pitchesList_xaxis = map(lambda x: discrete_sin(x pitchesList_yaxis = map(lambda x: discrete_sin(x In [742]: pitchesList_zaxis = map(lambda x: discrete_sin(x * , , , sin(theta) 72, 84), xs) 60, 72), ys) 48, 60), zs)

[stream_x.append(note.Note(midi=pitch, quarterLength=0.25)) for pitch in flatten(pi In [743]: [stream_y.append(note.Note(midi=pitch, quarterLength=0.5)) for pitch in flatten(pit In [744]: [stream_z.append(note.Note(midi=pitch, quarterLength=1.)) for pitch in flatten(pitc In [745]: score = stream.Stream() score.insert(0, stream_x) In [746]: score.insert(0, stream_y) score.insert(0, stream_z) score.write(midi) /var/folders/4t/54tv_bvd6kz28x8zwhy3mcp80000gn/T/music21/tmpMG4HIY.mi In [747]: Out [747]: d

In []:

2 Final Result
http://youtu.be/yJe8RoWNyeY

3 About Me
1. 2. 3. 4. http://twitter.com/maxtuno http://soundcloud.com/maxtuno http://www.reverbnation.com/maxtuno http://mx-clojure.blogspot.com

You might also like