Skip to content

Commit

Permalink
autopep8, replace rtmidi with mido
Browse files Browse the repository at this point in the history
still many things are untested and may not work reliably
  • Loading branch information
Fabian-Robert Stöter committed Apr 11, 2015
1 parent 4daa889 commit 800aa67
Show file tree
Hide file tree
Showing 33 changed files with 3,741 additions and 3,353 deletions.
21 changes: 10 additions & 11 deletions examples/ex-basics.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
#!/usr/bin/python

from isobar import *
import isobar as iso

# create a repeating sequence with scalar transposition:
# [ 36, 38, 43, 39, ... ]
a = PSeq([ 0, 2, 7, 3 ]) + 36
a = iso.PSeq([0, 2, 7, 3]) + 36

# apply pattern-wise transposition
# [ 36, 50, 43, 51, ... ]
a = a + PSeq([ 0, 12 ])
a = a + iso.PSeq([0, 12])

# create a geometric chromatic series, repeated back and forth
b = PSeries(0, 1, 12) + 72
b = PPingPong(b)
b = PLoop(b)
b = iso.PSeries(0, 1, 12) + 72
b = iso.PPingPong(b)
b = iso.PLoop(b)

# create an velocity series, with emphasis every 4th note,
# plus a random walk to create gradual dynamic changes
amp = PSeq([ 50, 35, 25, 35 ]) + PBrown(0, 1, -20, 20)
amp = iso.PSeq([50, 35, 25, 35]) + iso.PBrown(0, 1, -20, 20)

# a Timeline schedules events at a given BPM.
# by default, send these over the first MIDI output.
timeline = Timeline(120, debug = True)
output_device = iso.io.midi.MidiOut("IAC Driver IAC Bus 1")
timeline = iso.Timeline(120, device=output_device, debug=True)

# assign each of our Patterns to particular properties
timeline.sched({ 'note': a, 'dur': 1, 'gate': 2 })
timeline.sched({ 'note': b, 'dur': 0.25, 'amp': amp })
timeline.sched({'note': a, 'dur': 1, 'gate': 2})

timeline.run()
6 changes: 3 additions & 3 deletions examples/ex-lsystem-grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import random
import time

seq = PLSys("N[+N+N]?N[-N]+N", depth = 3)
seq = PLSys("N[+N+N]?N[-N]+N", depth=3)
notes = seq.all()
note_min = min(notes)
note_max = max(notes)

for note in seq:
note = note - note_min
print "#" * note
note = note - note_min
print "#" * note
6 changes: 3 additions & 3 deletions examples/ex-lsystem-rhythm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# - = transpose down one semitone
# [ = enter recursive branch
# ] = leave recursive branch
notes = PLSys("N+[+N+N--N+N]+N[++N]", depth = 4)
notes = PLSys("N+[+N+N--N+N]+N[++N]", depth=4)
notes = notes + 60

# use another l-system to generate time intervals.
# take absolute values so that intervals are always positive.
times = PLSys("[N+[NN]-N+N]+N-N+N", depth = 3)
times = PLSys("[N+[NN]-N+N]+N-N+N", depth=3)
times = PAbs(PDiff(times)) * 0.25
# delay = PDelay(notes, times)

Expand All @@ -32,5 +32,5 @@
velocity = PAbs(velocity)

timeline = Timeline(120)
timeline.sched({ 'note' : notes, 'amp' : velocity, 'dur' : times })
timeline.sched({'note': notes, 'amp': velocity, 'dur': times})
timeline.run()
4 changes: 2 additions & 2 deletions examples/ex-lsystem-stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import random
import time

notes = PLSys("N[+N--?N]+N[+?N]", depth = 4)
notes = PLSys("N[+N--?N]+N[+?N]", depth=4)
notes = PDegree(notes, Scale.majorPenta)
notes = notes % 36 + 52

Expand All @@ -19,5 +19,5 @@
timeline = Timeline(120)
timeline.output(midi)

timeline.sched({ 'note': notes, 'dur': 0.25 })
timeline.sched({'note': notes, 'dur': 0.25})
timeline.run()
13 changes: 6 additions & 7 deletions examples/ex-markov-learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# parallel markov chain learner:
# 1. takes MIDI input, and constructs three markov chains for pitch, duration
# and amplitude.
# and amplitude.
# 2. after receiving a low "C", plays back melodies which are statistically
# similar to the input.
# after francois pachet's "continuator".
Expand All @@ -12,7 +12,7 @@

import time

m_in = MidiIn()
m_in = MidiIn()
m_out = MidiOut()

learner = MarkovLParallel(3)
Expand All @@ -29,7 +29,7 @@
dur = clock - clock0
dur = round(dur, 2)

learner.register([ note.midinote, round(note.velocity, -1), dur ])
learner.register([note.midinote, round(note.velocity, -1), dur])
clock0 = clock

print "----------------------------------------------------"
Expand All @@ -38,12 +38,11 @@

chains = learner.chains()
pitch = PMarkov(chains[0])
amp = PMarkov(chains[1])
dur = PMarkov(chains[2])
amp = PMarkov(chains[1])
dur = PMarkov(chains[2])

t = Timeline(120, m_out)
print " - nodes: %s" % p.markov.nodes
print " - edges: %s" % p.markov.edges
t.sched({ 'note': pitch, 'dur': dur, 'amp': amp, 'channel': 0 })
t.sched({'note': pitch, 'dur': dur, 'amp': amp, 'channel': 0})
t.run()

28 changes: 20 additions & 8 deletions examples/ex-permut-degree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,35 @@
import random

# create a pitch line comprised of multiple permutations on a pelog scale
ppitch = PShuffle([ random.randint(-6, 6) for n in range(6) ])
ppitch = PShuffle([random.randint(-6, 6) for n in range(6)])
ppitch = PPermut(ppitch)
ppitch = PDegree(ppitch, Key("F#", "pelog"))

# create permuted sets of durations and amplitudes
# different lengths mean poly-combinations
pdur = PShuffle([ 1, 1, 2, 2, 4 ], 1)
pdur = PPermut(pdur) * 0.25
pdur = PShuffle([1, 1, 2, 2, 4], 1)
pdur = PPermut(pdur) * 0.25

pamp = PShuffle([ 10, 15, 20, 35 ], 2)
pamp = PPermut(pamp)
pamp = PShuffle([10, 15, 20, 35], 2)
pamp = PPermut(pamp)

# schedule on a 60bpm timeline and send to MIDI output
timeline = Timeline(60)
timeline.sched({ 'note': ppitch + 60, 'dur': pdur, 'channel': 0, 'gate': 1, 'amp': pamp })
timeline.sched({ 'note': ppitch + 24, 'dur': pdur * 4, 'channel': 1, 'gate': 2, 'amp': pamp })
timeline.sched({ 'note': ppitch + 72, 'dur': pdur / 2, 'channel': 1, 'gate': 1, 'amp': pamp / 2 })
timeline.sched({'note': ppitch + 60,
'dur': pdur,
'channel': 0,
'gate': 1,
'amp': pamp})
timeline.sched({'note': ppitch + 24,
'dur': pdur * 4,
'channel': 1,
'gate': 2,
'amp': pamp})
timeline.sched({'note': ppitch + 72,
'dur': pdur / 2,
'channel': 1,
'gate': 1,
'amp': pamp / 2})

# add some continuous warping
warp = PWRamp(2, PBrown(-0.1, 0.01, -0.15, -0.05))
Expand Down
11 changes: 7 additions & 4 deletions examples/ex-piano-phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
from isobar import *

# melody line
seq = PSeq([ -7, -5, 0, 2, 3, -5, -7, 2, 0, -5, 3, 2 ])
seq = PSeq([-7, -5, 0, 2, 3, -5, -7, 2, 0, -5, 3, 2])

# create a timeline at 160BPM
timeline = Timeline(160)

# schedule two identical melodies.
# we must copy the note sequence or else the position will be stepped
# by two every note... try removing the .copy() and see what happens!
timeline.sched({ 'note': seq.copy() + 60, 'dur': 0.5 })
timeline.sched({ 'note': seq.copy() + 72, 'dur': 0.5 * 1.01 })
timeline.sched({'note': seq.copy() + 60, 'dur': 0.5})
timeline.sched({'note': seq.copy() + 72, 'dur': 0.5 * 1.01})

# start playing, and block forever.
# alternatively, use timeline.background() to retain foreground control.
timeline.run()
timeline.background()

while True:
pass
21 changes: 13 additions & 8 deletions examples/ex-subsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@

from isobar import *

scale = Scale([ 0, 2, 3, 6, 7 ])
scale = Scale([0, 2, 3, 6, 7])
scale = Scale.pelog
seq = PDegree(PBrown(0, 3, -12, 12, repeats = False), scale)
seq = PDegree(PBrown(0, 3, -12, 12, repeats=False), scale)

offset = PStutter(PWhite(0, 4), 2)
seq = PSubsequence(seq, offset, 4)
seq = PPermut(seq)
seq = seq + 64
seq = PReset(seq, PImpulse(24))

amp = PSeq([ 45, 35, 25, 40 ]) + PBrown(0, 1, -15, 10)
amp = PSeq([ 45, 35, 35, 40 ]) + PBrown(0, 1, -15, 10)
amp = PSeq([45, 35, 25, 40]) + PBrown(0, 1, -15, 10)
amp = PSeq([45, 35, 35, 40]) + PBrown(0, 1, -15, 10)

gate = PBrown(1.5, 0.01, 0.6, 2.5)

timeline = Timeline(120)
timeline.sched({ 'note': seq, 'amp': amp, 'dur': 0.25, 'gate': gate })
timeline.sched({ 'note': seq.copy() + 24, 'amp': amp.copy(), 'dur': 0.5, 'gate': gate.copy() })
timeline.sched({ 'note': seq.copy() - 24, 'amp': 10 + amp.copy() * 0.5, 'dur': PChoice([ 4, 4, 6, 8 ]), 'gate': gate.copy() })
timeline.sched({'note': seq, 'amp': amp, 'dur': 0.25, 'gate': gate})
timeline.sched({'note': seq.copy() + 24,
'amp': amp.copy(),
'dur': 0.5,
'gate': gate.copy()})
timeline.sched({'note': seq.copy() -
24, 'amp': 10 +
amp.copy() *
0.5, 'dur': PChoice([4, 4, 6, 8]), 'gate': gate.copy()})
timeline.run()

8 changes: 4 additions & 4 deletions examples/ex-walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#------------------------------------------------------------------------
# walk up and down a minor scale
#------------------------------------------------------------------------
scale = Scale([ 0, 2, 3, 7, 9, 11 ])
degree = PBrown(0, 2, -8, 16, repeats = False)
scale = Scale([0, 2, 3, 7, 9, 11])
degree = PBrown(0, 2, -8, 16, repeats=False)
notes = PDegree(degree, scale) + 60

#------------------------------------------------------------------------
# add a slight 4/4 emphasis and moderate variation in velocity
#------------------------------------------------------------------------
amp = PSeq([ 40, 30, 20, 25 ]) + PBrown(0, 2, -10, 10)
amp = PSeq([40, 30, 20, 25]) + PBrown(0, 2, -10, 10)

timeline = Timeline(170)
timeline.sched({ 'note': notes, 'dur': 0.25, 'gate': 0.9, 'amp' : amp })
timeline.sched({'note': notes, 'dur': 0.25, 'gate': 0.9, 'amp': amp})
timeline.run()
16 changes: 8 additions & 8 deletions isobar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
__version__ = "0"
__author__ = "Daniel Jones <http://www.erase.net/>"

from isobar.pattern import *
from isobar.note import *
from isobar.scale import *
from isobar.chord import *
from isobar.key import *
from isobar.util import *
from isobar.timeline import *
from pattern import *
from note import *
from scale import *
from chord import *
from key import *
from util import *
from timeline import *

import sys

FOREVER = sys.maxint
FOREVER = sys.maxsize

# REST = -sys.maxint - 1
# END = -sys.maxint + 1
Loading

0 comments on commit 800aa67

Please sign in to comment.