-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunchkey.py
More file actions
50 lines (40 loc) · 1.5 KB
/
Copy pathlaunchkey.py
File metadata and controls
50 lines (40 loc) · 1.5 KB
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
import mido
# device name
output_name = "MIDIOUT2 (Launchkey Mini) 2"
# led id's
row1 = (96, 97, 98, 99, 100, 101, 102, 103)
row2 = (112, 113, 114, 115, 116, 117, 118, 119)
# round led id's
top_rled = 104
bottom_rled = 120
# wrapper for launchkey midi communication
# (only implements what's currently needed by the scripts)
class Launchkey:
def __init__(self):
print("connecting to launchkey")
self.midi_out = mido.open_output(output_name)
self.midi_out.send(mido.Message.from_bytes([0x90, 0x0C, 0x7F]))
print("connected")
self.rows = [row1, row2]
self.leds = row1 + row2
self.top_rled = top_rled
self.bottom_rled = bottom_rled
def disconnect(self):
print("disconnecting from launchkey")
self.midi_out.send(mido.Message.from_bytes([0x90, 0x0C, 0x00]))
self.midi_out.close()
# light up a led with a color ID
def led(self, id, color):
self.midi_out.send(mido.Message('note_on', channel=0,
note=id, velocity=color))
# light up a led given two color amounts
def led_green_red(self, id, green, red):
green = min(green, 4)
red = min(red, 4)
color = red + (green * 16)
self.midi_out.send(mido.Message('note_on', channel=0,
note=id, velocity=color))
# turn off all leds
def clear_leds(self):
for led in self.leds:
self.led(led, 0)