Pyknon
Pyknon is a simple music library for Python hackers. With Pyknon you can generate Midi files quickly and reason about musical proprieties. It works with Python 2.7 and 3.2.
It's a library intended for teaching and demonstrating, so you should have no problems reading the source code. On the other hand, it doesn't do a lot of checking, so it's easy to break (and if you break it, you buy it). If you find bugs, please report at our issue tracking system.
You can install Pyknon using pip:
pip install pyknon
Pyknon is very simple to use, here's a basic example to create 4 notes and save into a MIDI file::
from pyknon.genmidi import Midi
from pyknon.music import NoteSeq
notes1 = NoteSeq("D4 F#8 A Bb4")
midi = Midi(1, tempo=90)
midi.seq_notes(notes1, track=0)
midi.write("demo.mid")
And because we write Python code, we can generate more complex things easily. In the next example we convert the first 30 rows in Pascal's triangle to notes:
from __future__ import division
from itertools import chain
from pyknon.genmidi import Midi
from pyknon.music import Note, NoteSeq
def pascals_triangle(n):
x = [1]
yield x
for i in range(n - 1):
x = [sum(i) for i in zip([0] + x, x + [0])]
yield x
seq = chain.from_iterable(pascals_triangle(30))
midi = Midi(tempo=120)
midi.seq_notes(NoteSeq([Note(x%12, 4, 1/16) for x in seq]))
midi.write("pascal.mid")
You can listen to the result here.
About the Name
In case you are wondering, Pyknon is a term from ancient Greek music theory: "Intervallically dense region of non-diatonic, i.e., chromatic or enharmonic, genera." (http://tonalsoft.com/enc/p/pyknon.aspx)
Documentation
You can download this free chapter from Music for Geeks and Nerds that explains how to use Pyknon.Learn More!
If you like this, you may be interested in my book, Music for Geeks and Nerds