100% found this document useful (1 vote)
5K views

Algorithmic Composition With Python and Music21 - Tutorial 01

This document provides a tutorial on algorithmic composition using Python and the music21 library. It contains 4 examples: 1) Creating a chromatic scale, 2) Creating a chromatic scale using a sine wave, 3) Creating a mathematical counterpoint between two voices using sine and cosine waves, and 4) Links to the author's social media profiles. The document demonstrates how to programmatically generate musical scales and pieces using basic mathematical functions in Python.

Uploaded by

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

Algorithmic Composition With Python and Music21 - Tutorial 01

This document provides a tutorial on algorithmic composition using Python and the music21 library. It contains 4 examples: 1) Creating a chromatic scale, 2) Creating a chromatic scale using a sine wave, 3) Creating a mathematical counterpoint between two voices using sine and cosine waves, and 4) Links to the author's social media profiles. The document demonstrates how to programmatically generate musical scales and pieces using basic mathematical functions in Python.

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/ 5

Algorithmic Composition with Python and Music21

Oscar Riveros
November 05, 2013
Abstract The most basic, mathematica music, not art at the moment, just take control.

Part I

Tutorial 01
1 Create a chromatic scale from C3 (60) to C4 (72)
from music21 import * In [1]: stream = stream.Stream(); In [2]: noteList = [note.Note(midi=n) for n in range(60, 72)]; In [3]: [stream.append(note) for note in noteList]; In [4]: stream.show(musicxml) In [5]:

2 Create a chromatic scale from C3 to C4 with the form of sin() with 24 notes of length
from music21 import * In [6]: from pylab import * %pylab --no-import-all inline
Populating the interactive namespace from numpy and matplotlib

def discrete_sin(theta, low_note, high_note): return high_note + int(high_note - low_note) * sin(theta) In [7]: stream = stream.Stream(); In [8]: pitchesList = [discrete_sin(n, 60, 72) for n in range(24)]; In [9]: plot(pitchesList) [<matplotlib.lines.Line2D at 0x105a4d6d0>] In [10]: Out [10]:

[stream.append(note.Note(midi=pitch)) for pitch in pitchesList]; In [11]: stream.show(musicxml) In [12]:

3 Create a simple mathematical counterpoint betwen sin( + sin ()) and cos( + cos ()) with 256 notes of length in the rst voice, where = e and = ln(1 + ) and rst voice is 2 times most faster than the second voice and one cotave uper
from music21 import * In [13]: from pylab import * %pylab --no-import-all inline
Populating the interactive namespace from numpy and matplotlib

def psi(theta): return exp(theta) In [14]: def discrete_sin(theta, low_note, high_note): return high_note + int(high_note - low_note) * sin(theta + psi(theta)) def phi(theta): return log(1 + theta) In [15]: def discrete_cos(theta, low_note, high_note): return high_note + int(high_note - low_note) * cos(theta + phi(theta))

stream_sin = stream.Stream(); stream_cos = stream.Stream(); In [16]: pitchesList_sin = [discrete_sin(n, 60, 72) for n in range(256)]; pitchesList_cos = [discrete_cos(n, 48, 60) for n in range(128)]; In [17]: plot(pitchesList_sin) plot(pitchesList_cos) In [18]:
[<matplotlib.lines.Line2D at 0x105a53ed0>]

Out [18]:

[stream_sin.append(note.Note(midi=pitch, quarterLength=0.5)) for pitch in pitchesLi [stream_cos.append(note.Note(midi=pitch, quarterLength=1)) for pitch in pitchesList In [19]: score = stream.Stream() In [20]: score.insert(0, stream_sin) score.insert(0, stream_cos) In [21]: score.show(musicxml) In [22]:

4 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