-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
31 lines (28 loc) · 972 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
import rtmidi
import midilistener
def print_message(midi):
if midi.isNoteOn():
print 'ON: ', midi.getMidiNoteName(midi.getNoteNumber()), midi.getVelocity(), midi.getChannel()
elif midi.isNoteOff():
print 'OFF:', midi.getMidiNoteName(midi.getNoteNumber())
elif midi.isController():
print 'CONTROLLER', midi.getControllerNumber(), midi.getControllerValue()
midiListener = midilistener.MidiListener(sys.argv[1])
midiListener.start()
midiin = rtmidi.RtMidiIn()
ports = range(midiin.getPortCount())
if ports:
for i in ports:
print "Port: " + str(i) + " Name: " + midiin.getPortName(i)
print "Select port to use: "
c = sys.stdin.read(1)
midiin.openPort(int(c))
print "Listening on port: " + c
while True:
m = midiin.getMessage(250) # some timeout in ms
if m is not None:
midiListener.receiveMidi(m)
#print_message(m)
else:
print 'NO MIDI INPUT PORTS!'