-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi.py
37 lines (28 loc) · 764 Bytes
/
midi.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
import rtmidi
import time
class UsbMidiController:
MidiChannel = 1
midiConnection = None
display = None
def init(self, displayIn):
self.display = displayIn
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
logStr = "[i] MIDI Ports = " + str(len(available_ports))
self.display.logText(logStr)
self.display.update()
if available_ports:
print("Port found")
midiout.open_port(2)
with midiout:
note_on = [0x90, 60, 112] # channel 1, middle C, velocity 112
note_off = [0x80, 60, 0]
midiout.send_message(note_on)
time.sleep(0.5)
midiout.send_message(note_off)
time.sleep(0.1)
midiout.send_message(note_on)
time.sleep(0.5)
midiout.send_message(note_off)
time.sleep(0.1)
del midiout