Created
March 28, 2011 17:50
-
-
Save bzztbomb/890920 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/python | |
import OSC | |
import pygame.midi as pgm | |
import sys | |
midiIn = None | |
midiOut = None | |
# Opens our midi in connection | |
def initMidi(): | |
pgm.init() | |
for i in range(pgm.get_count()): | |
print pgm.get_device_info(i) | |
devId = pgm.get_default_input_id() | |
if (devId == -1): | |
print "No MIDI input device!" | |
quit(-1) | |
print "Using this input device:" | |
print pgm.get_device_info(devId) | |
global midiIn | |
midiIn = pgm.Input(devId) | |
devId = pgm.get_default_output_id() | |
if (devId == -1): | |
print "No MIDI output device!" | |
quit(-1) | |
print "Using this output device:" | |
print pgm.get_device_info(devId) | |
global midiOut | |
midiOut = pgm.Output(devId) | |
#enterBytes = [ 0xF0, 0x7D, 0x4D, 0x4C, 0x4E, 0x4B, 1, 0xF7 ] | |
enterBytes = [ 0xF0, 0x7D, 0x4D, 0x4C, 0x4E, 0x4B, 3, 0xF7 ] | |
#enterBytes = [ 0xF0, 0x7D, 0x4D, 0x4C, 0x4E, 0x4B, 0, 0xF7 ] | |
queryBytes = [0xF0, 0x7D, 120, 51, 55, 118, 98, 111, 111, 116, 2, 0xF7]; | |
initMidi() | |
last = pgm.time() | |
while (pgm.time() - last < 1000): | |
if (midiIn.poll()): | |
m = midiIn.read(1) | |
print m | |
midiOut.write_sys_ex(pgm.time(), enterBytes) | |
last = pgm.time() | |
while (True): | |
if (pgm.time() - last > 2000): | |
midiOut.write_sys_ex(pgm.time(), queryBytes) | |
last = pgm.time() | |
print queryBytes | |
if (midiIn.poll()): | |
m = midiIn.read(1) | |
print m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment