-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIDI_player.py
70 lines (46 loc) · 1.49 KB
/
MIDI_player.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import mido
from mido import MidiFile, MetaMessage
from mido.ports import MultiPort
import time
port = mido.open_input('nanoKEY2 0')
def counter(message):
print('Made it to counter')
msg = port.poll()
print(msg)
while(msg != 'None'):
print('Waiting...')
time.sleep(1)
msg = port.poll()
#Callback definition
def route_midi(message):
print('Made it to route midi')
if message.type == 'note_on':
if message.note == 72:
print('Key 72')
elif message.note == 71:
counter(message)
port.callback = route_midi
#SCRATCH
import mido
from mido import MidiFile, MetaMessage
from mido.ports import MultiPort
port = mido.open_input('nanoKEY2 0')
outport = mido.open_output('Microsoft GS Wavetable Synth 0')
############################################################
while True:
for msg in port.iter_pending():
print(msg)
do_other_stuff()
######################################################
###DIS IS IT - PLAY IT TILL I QUIT
#timeCounter = 0.0
for msg in MidiFile("Movie_Themes_-_Jurassic_Park.mid").play():
outport.send(msg)
incomingMsg = port.poll()
if (incomingMsg):
print(incomingMsg.type)
if incomingMsg.note == 70 and incomingMsg.type == 'note_off':
outport.reset()
break
#timeCounter += msg.time
#print(timeCounter)