-
Notifications
You must be signed in to change notification settings - Fork 0
/
midiProcess.py
74 lines (67 loc) · 1.74 KB
/
midiProcess.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
def MSCconvertToHex(numASCII):
'''lookup table to convert numbers to ASCII Hex Values for Midi Show Control'''
if numASCII == '0':
return 48
elif numASCII == '1':
return 49
elif numASCII == '2':
return 50
elif numASCII == '3':
return 51
elif numASCII == '4':
return 52
elif numASCII == '5':
return 53
elif numASCII == '6':
return 54
elif numASCII == '7':
return 55
elif numASCII == '8':
return 56
elif numASCII == '9':
return 57
elif numASCII == '.':
return 46
elif numASCII == '-':
return 0
elif numASCII == ' ':
return 32
def MSCCmdTypeLookup(cmd):
''' Command MSC Hex Value Lookup table'''
cmd = cmd.upper()
if cmd == 'OPEN':
return 27
elif cmd == 'GO':
return 1
elif cmd == 'STOP':
return 2
elif cmd == 'RESUME':
return 3
elif cmd == 'CLOSE':
return 28
elif cmd == 'ALL_OFF':
return 8
elif cmd == 'GO_OFF':
return 11
else:
print("Command not Supported")
return None
def buildMscList(cmd, number, devId, cmdFormat):
'''returns a list of hex values in MSC Sysex order. Calls MSCCmdTypeLookup() and
#MSCconvertToHex().'''
mscData = []
mscData.append(240) #Start
mscData.append(127) #ALL-CALL
mscData.append(int(devId))#Device ID.
mscData.append(2)#MSC
mscData.append(cmdFormat)#Msc Data Format
mscData.append(MSCCmdTypeLookup(cmd)) #Command
for char in number: #Number, seperated by character
mscData.append(MSCconvertToHex(char))
mscData.append(247) #End
return mscData
def processAndSend(data, devID, cmdFormat):
''' Takes properly formatted command string and splits the command and number,
then calls buildMscList(), and returns that message'''
cmdType, cmdNumber = data.split(":") #Split data into command and numbers
return(buildMscList(cmdType, cmdNumber, devID, cmdFormat))