logo
Création de musique avec Pyknon)

Exemple 1

#!/usr/bin/env python

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")	

Exemple 2

from pyknon.genmidi import Midi
from pyknon.music import NoteSeq

notes1 = NoteSeq("C4 D E F G A B C''")
notes2 = NoteSeq("r1 r1 C4 D E F G A B C''")

m = Midi(2, tempo=120)
m.seq_notes(notes1, track=0)
m.seq_notes(notes2, track=1)

m.write("micro.mid")	

Exemple 3

from pyknon.genmidi import Midi
from pyknon.music import NoteSeq

# Notes on two tracks using the defaults

notes1 = NoteSeq("C4.'' B8' A4 D")
notes2 = NoteSeq("E4 F G4. A8")

m = Midi(2, tempo=100, instrument=[12, 14])
m.seq_notes(notes1, track=0)
m.seq_notes(notes2, track=1)
m.write("tracks.mid")

Exemple 4

from pyknon.genmidi import Midi
from pyknon.music import NoteSeq

# Chords on two tracks using the defaults

chords1 = [NoteSeq("C2 E G"), NoteSeq("G2 B D")]
chords2 = [NoteSeq("C,4 E"), NoteSeq("E, G"), NoteSeq("G, B"), NoteSeq("B, D'")]

midi = Midi(2, tempo=60, instrument=[40, 20])
midi.seq_chords(chords1, track=0)
midi.seq_chords(chords2, track=1)
midi.write("chords.mid")

Exemple 5

from pyknon.genmidi import Midi
from pyknon.music import NoteSeq

# In the MIDI library, the tracks and channels are numbered from 0,
# While the MIDI Standard is numbered from 1,
# So to use percussion you must use channel 9 in the library

n1 = NoteSeq("C4 D E F")
n2 = NoteSeq("C8 C G, G C' C G, G")

m2 = Midi(2, tempo=123, channel=[0, 9], instrument=[20, 40])
m2.seq_notes(n1, track=0, channel=0)
m2.seq_notes(n2, track=1, channel=9)
m2.write("percussion.mid")	
	

Exemple 6

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")	

Ressources :

https://github.com/eric-brechemier/music-for-geeks-exercises