forked from Silhm/motu-mcu-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
195 lines (157 loc) · 5.77 KB
/
setup.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import sys
import argparse
import mido
from modules.midiHelper import *
allStrips = []
class Setup:
def __init__(self, ipAddr=None, port=80):
print("new setup")
self.ipAddr = ipAddr
self.port = port
midiPort = mido.get_input_names()[0]
self.midiIN = mido.open_input(midiPort)
def setupInterface(self):
print("Setup the MOTU: use 4 first vPot to set IP, validate with F1, cancel with F2")
# listen to midi event
vPotCC = [16, 17, 18, 19]
ip = [0, 0, 0, 0]
msg = self.midiIN.receive()
while msg:
if msg.type == "control_change":
direction = 1 if msg.value == 1 else -1
potId = vPotCC.index(msg.control)
ip[potId] = ip[potId] + direction
sys.stdout.write("\r\x1b[K"+ip.__str__())
sys.stdout.flush()
if msg.type == "note_on":
print("")
midiFullNote = midiNumberToFullNote(msg.note)
if midiFullNote == "G2":
print("Validated MOTU IP: {}.{}.{}.{}".format(ip[0], ip[1], ip[2], ip[3]))
self.ipAddr = "{}.{}.{}.{}".format(ip[0], ip[1], ip[2], ip[3])
break
if midiFullNote == "G2":
print("Cancel ")
break
msg = self.midiIN.receive()
def setupController(debug):
print("=== This will drop all configuration an make a factory reset ===")
print("=== It will use the MIDI learn system ===")
print("")
print("** Strips **")
if debug:
faderCount = 8
print("=== It will use BCF settings to debug ===")
else:
faderCount = input('Enter the number of strips your controller can handle (8) : ')
faderCount = faderCount if faderCount else 8
for stripId in range(1, faderCount+1):
stripAddrDef = {
"id": stripId,
"fader" : False,
"vPot": False,
"mute": False,
"solo": False,
}
print(">> Strip ", stripId)
print(" Move the Fader ", end='')
stripAddrDef['fader'] = ""
if debug:
stripAddrDef['fader'] = mido.Message('pitchwheel', pitch=0, channel=stripId)
print(" OK")
print(" Click solo button ", end='')
stripAddrDef['solo'] = ""
if debug:
note = ["E0", "F0", "F#0", "G0", "G#0", "A0", "A#0", "B0"][stripId-1]
stripAddrDef['solo'] = mido.Message('note_on', note=midiFullNoteToNumber(note), velocity=127)
print(" OK")
print(" Click mute button ", end='')
stripAddrDef['mute'] = ""
if debug:
note = ["C1", "C#1", "D1", "D#1", "E1", "F1", "F#1", "G1"][stripId-1]
stripAddrDef['mute'] = mido.Message('note_on', note=midiFullNoteToNumber(note), velocity=127)
print(" OK")
print(" Move the vPot ", end='')
stripAddrDef['vPot'] = ""
if debug:
cc = [16, 17, 18, 19, 20, 21, 22, 23][stripId-1]
stripAddrDef['mute'] = mido.Message('control_change', control=cc, value=1)
print(" OK")
print(" Click the vPot ", end='')
stripAddrDef['vPotClick'] = ""
if debug:
note = ["G#1", "A1", "A#1", "B1", "C2", "C#2", "D2", "D#2"][stripId-1]
stripAddrDef['vPotClick'] = mido.Message('note_on', note=midiFullNoteToNumber(note), velocity=127)
print(" OK")
allStrips.append(stripAddrDef)
print("** Function Keys **")
print(" Click F1", end='')
f1 = ""
if debug:
f1 = mido.Message('note_on', note=midiFullNoteToNumber("G2"), velocity=127)
print(" OK")
print(" Click F2", end='')
f2 = ""
if debug:
f2 = mido.Message('note_on', note=midiFullNoteToNumber("G#2"), velocity=127)
print(" OK")
print(" Click F3", end='')
f3 = ""
if debug:
f3 = mido.Message('note_on', note=midiFullNoteToNumber("F2"), velocity=127)
print(" OK")
print(" Click F4", end='')
f4 = ""
if debug:
f4 = mido.Message('note_on', note=midiFullNoteToNumber("F#2"), velocity=127)
print(" OK")
print(" Click F5", end='')
f5 = ""
if debug:
f5 = mido.Message('note_on', note=midiFullNoteToNumber("G6"), velocity=127)
print(" OK")
print(" Click F6", end='')
f6 = ""
if debug:
f6 = mido.Message('note_on', note=midiFullNoteToNumber("A6"), velocity=127)
print(" OK")
print(" Click F7", end='')
f7 = ""
if debug:
f7 = mido.Message('note_on', note=midiFullNoteToNumber("G#6"), velocity=127)
print(" OK")
print(" Click F8", end='')
f8 = ""
if debug:
f8 = mido.Message('note_on', note=midiFullNoteToNumber("A#6"), velocity=127)
print(" OK")
print("** Misc **")
print(" Click Bank +", end='')
bankUp = ""
if debug:
bankUp = mido.Message('note_on', note=midiFullNoteToNumber("A#2"), velocity=127)
print(" OK")
print(" Click Bank -", end='')
bankDown = ""
if debug:
bankDown = mido.Message('note_on', note=midiFullNoteToNumber("B2"), velocity=127)
print(" OK")
return {
"global": {
"f1": f1,
"f2": f2,
"f3": f3,
"f4": f4,
"f5": f5,
"f6": f6,
"f7": f7,
"f8": f8
},
"strips": allStrips
}
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--debug", default=False, help="Put some default data")
args = parser.parse_args()
setupController(args.debug)
print(allStrips)