Skip to content

Instantly share code, notes, and snippets.

@hyperobject
Last active November 8, 2015 03:55
Show Gist options
  • Save hyperobject/7a50a9f9185a87330006 to your computer and use it in GitHub Desktop.
Save hyperobject/7a50a9f9185a87330006 to your computer and use it in GitHub Desktop.
Creating music with absolutely anything
import random, music
m = music.MIDI()
notes = [61, 63, 66, 68, 70] #pentatonic scale so it sounds pretty
while True: #Yes, infinite loop. No one cares.
m.send(random.choice(notes), 0.125, 100) #Assuming 120BPM, this sends an eigth note
#You need to include everything up to the example for your stuff
import time, rtmidi #`pip install rtmidi`
class MIDI:
_version = "1.0"
def __init__(self):
print "music.py version %s" % self._version
self.out = rtmidi.MidiOut()
self.out.open_virtual_port('music.py')
def send(self, note, length, velocity):
self.out.send_message([0x90, note, velocity])
time.sleep(length)
self.out.send_message([0x80, note, 0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment