Last active
November 8, 2015 03:55
-
-
Save hyperobject/7a50a9f9185a87330006 to your computer and use it in GitHub Desktop.
Creating music with absolutely anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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