-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidi_interface.py
More file actions
91 lines (74 loc) · 2.34 KB
/
Copy pathmidi_interface.py
File metadata and controls
91 lines (74 loc) · 2.34 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import mido, argparse
from time import sleep
from random import choice, randrange
try:
out = mido.open_output('Conspiracy 4')
except RuntimeError:
print(str(e))
outs = mido.get_output_names()
for o in outs:
print(o)
colormap = {'off': '1C', 'red': '15', 'yellow': '13', 'green': '16', 'blue': '18', 'purple': '19', 'light blue': '1A', 'white': '1B' }
colors = list(colormap.values())
boardindexes = range(0x0, 0x2F)
board = [format(b, '02X') for b in boardindexes]
pads = board[:25]
banks = board[25:33]
#bankcolors =
def spot_on(loc, hexcolor):
#print(str(loc))
msg = "90 "+ loc + " " + hexcolor
m = mido.Message.from_hex(msg)
out.send(m)
def pads_on(hexcolor):
[spot_on(loc, hexcolor) for loc in board[:25]]
def board_on(hexcolor):
#hexcolor = format(hexint, 'X')
bank1x = ["90 0" + format(x, 'X') + " " + hexcolor for x in range(0x0, 0x10)]
bank1x += ["90 " + format(x, 'X') + " " + hexcolor for x in range(0x10, 0x2F)]
#for b in bank1x:
#print(b)
bank1 = [mido.Message.from_hex(x) for x in bank1x]
for b in bank1:
out.send(b)
#print(str(bank1[0]))
def iterate_col():
for c in range(0, 128):
if (c < 0x10):
col = "0" + format(c, 'X')
else:
col = format(c, 'X')
input('col was ' + str(col) + " == " + format(c, 'b'))
board_on(col)
def party():
c = choice(colors)
board_on(c)
while True:
l = choice(board)
c = choice(colors)
spot_on(l, c)
sleep(0.02)
# if running directly, provide menu of test functions
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Midi interface testing tool")
parser.add_argument("-b", "--board", action="store_true")
parser.add_argument("-p", "--pads", action="store_true")
parser.add_argument("-w", "--wild", action="store_true")
args = parser.parse_args()
if args.board:
board_on(colormap['purple'])
sleep(0.5)
if args.pads:
pads_on(colormap['light blue'])
sleep(0.5)
if args.wild:
party()
try:
pads_on(colormap['white'])
while True:
h = input('hex to send: ')
out.send(mido.Message.from_hex(str(h)))
except ValueError:
print("Value Error.")
out.close()
print("Closed port")