Skip to content

Instantly share code, notes, and snippets.

@kroger
Last active August 29, 2015 14:03
Show Gist options
  • Save kroger/72760dd2db51dc78c88f to your computer and use it in GitHub Desktop.
Save kroger/72760dd2db51dc78c88f to your computer and use it in GitHub Desktop.
pascal-triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
>>> list(pascals_triangle(5))
>>> [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]
def play_list(pitch_list, octave_list, duration,
volume=120):
result = NoteSeq()
for pitch in pitch_list:
note = pitch % 12
octave = choice_if_list(octave_list)
dur = choice_if_list(duration)
vol = choice_if_list(volume)
result.append(Note(note, octave, dur, vol))
return result
def random1():
chromatic = range(0, 12)
durations = [1/64, 1/32, 1/16, 1/8, 1/4, 1/2, 1]
notes1 = random_notes(chromatic,
range(0, 9),
durations,
100,
range(0, 128, 20))
gen_midi("random1.mid", notes1)
def random2():
chromatic = range(0, 12)
notes2 = random_notes(chromatic,
range(3, 7),
[1/16, 1/8],
100)
gen_midi("random2.mid", notes2)
def random3():
pentatonic = [0, 2, 4, 7, 9]
notes = random_notes(pentatonic,
range(5, 7),
1/16,
100)
gen_midi("random3.mid", notes)
def random_fib():
octave = range(5, 7)
fib = fibonacci(100000000000)
pascal = flatten(pascals_triangle(30))
n1 = play_list(fib, octave, 1/16)
n2 = play_list(pascal, 4, 1/16)
n3 = play_list(pascal, octave, 1/16)
gen_midi("fibonnacci.mid", n1)
gen_midi("pascal.mid", n2)
gen_midi("pascal_octaves.mid", n3)
def random_notes(pitch_list, octave, duration,
number_of_notes, volume=120):
result = NoteSeq()
for x in range(0, number_of_notes):
pitch = choice(pitch_list)
octave = choice_if_list(octave)
dur = choice_if_list(duration)
vol = choice_if_list(volume)
result.append(Note(pitch, octave, dur, vol))
return result
>>> random_notes(range(0, 12), range(5, 7), [0.25, 0.5, 1], 5)
<Seq: [<A>, <B>, <C#>, <A#>, <F#>]>
>>> random_notes([0, 2, 4, 7, 9], 5, 0.5, 5)
<Seq: [<C>, <A>, <D>, <A>, <G>]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment