Skip to content

Instantly share code, notes, and snippets.

@hecanjog
Created December 16, 2016 19:46
Show Gist options
  • Save hecanjog/ceafd7aad84f464d25687ddaac3a63bf to your computer and use it in GitHub Desktop.
Save hecanjog/ceafd7aad84f464d25687ddaac3a63bf to your computer and use it in GitHub Desktop.
guitar rainbows
import mido
from pippi import dsp, tune
out = mido.open_output('UltraLite AVB MIDI 1')
channel = 0
def play(freqs, length=44100):
if dsp.rand() > 0.5:
freqs.reverse()
for freq in freqs:
amp = dsp.rand(0.01, 1)
velocity = int(round(amp * 127.0))
freq *= 2**dsp.randint(0,3)
note = int(round(tune.ftom(freq)))
bit = dsp.mstf(10, 160)
length -= bit
out.send(mido.Message('note_on', note=note, velocity=velocity))
dsp.delay(bit)
dsp.delay(length)
for freq in freqs:
if dsp.rand() > 0.25:
note = int(round(tune.ftom(freq)))
out.send(mido.Message('note_off', note=note, velocity=0))
chords = ['IV', 'IV6', 'IV6', 'iii', 'III', 'vii*'] * 4
for chord in chords:
freqs = tune.chord(chord, octave=2, key='e')
print chord, freqs
play(freqs * dsp.randint(1, 4), dsp.stf(0.75, 1.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment