-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanager.py
143 lines (113 loc) · 5.11 KB
/
manager.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
import mido,json,argparse,os
from mido import Message
from mido.ports import multi_receive
from os import path
parser = argparse.ArgumentParser(description='''-r or --reset 1 will delete the previous config file
0 will do nothing ''')
parser.add_argument('-r','--reset', type=int,default=0)
arguments = parser.parse_args()
outCh = 6
lcontrolCH = 2
midiInputs = mido.get_input_names()
midiOutputs = mido.get_output_names()
inputList = []
inputPort = 0
to_Axoloti = "Axoloti Core MIDI 1"
to_Keyboard = 'MicroBrute MIDI 1'
to_LControl = 'Launch Control XL MIDI 1'
from_axoloti = 'Axoloti Core MIDI 1'
axoPort = mido.open_input(from_axoloti)
style1 = "\x1b[4;37;40m"
greenS = "\x1b[6;30;42m"
redS = "\x1b[1;36;41m"
greenLetters = "\x1b[1;33;40m"
def loggit(text,style):
return print(style + text + " \x1b[0m ")
if arguments.reset == 1 :
if path.exists("stored_midiIO.json"):
loggit("RESETTING!!",greenS)
os.remove("stored_midiIO.json")
else:
loggit('Config file is not in the folder or has been removed',redS)
def choose(text):
return int(input(text))
def startMenu():
loggit("----------- . -----------",greenS)
print("\x1b[6;30;42m STARTING I/0 SETTUP \x1b[0m ----------- \x1b[1;33;40m < this settings will be stored in stored_midiIO.json > \x1b[0m")
loggit("----------- . -----------",greenS)
loggit("----------- . -----------",greenS)
loggit("----------- INPUTS -----------",greenS)
for name in mido.get_input_names():
loggit("Input : "+ name,greenLetters)
loggit("\n ----------- OUTPUTS -----------",greenS)
for name in mido.get_output_names():
loggit("Output : " +name,greenLetters)
print("----------- . ----------- \n")
for input in midiInputs:
inIndex = midiInputs.index(input)
print(midiInputs[inIndex])
addOrNot = choose("Add "+str(midiInputs[inIndex]) +" To inputs ? (1.- Yes 2.- No : ")
if addOrNot == 1:
inputList.append(midiInputs[inIndex])
elif addOrNot != 1:
pass
else:
pass
print("ADDED CHANNELS TO MERGE")
print("-------------- . ------------- \n")
for name in midiOutputs:
print(name, midiOutputs.index(name), "\x1b[1;36;41m <--SELECT \x1b[0m ")
outnumPort = choose(" \n []Choose an output port[] : ")
to_Axoloti = midiOutputs[outnumPort]
print("INPUT ",midiInputs," OUTPUT ",midiOutputs[outnumPort])
loggit('\n ----- \n READY \n ROUTIG STARTING... \n -----\n',greenLetters)
#store new data in json file
config = {'input': midiInputs, 'output': to_Axoloti}
with open('stored_midiIO.json', 'w') as f:
json.dump(config, f)
loggit('\n ----- PREFERECES SAVED IN .\stored_midiIO.json -----\n',greenLetters)
if path.exists("stored_midiIO.json"): #load data from the previously choosen settings
with open('stored_midiIO.json', 'r') as f:
config = json.load(f)
inputPort = config["input"]
inputList = inputPort
to_Axoloti = config["output"]
print("\x1b[6;30;42m LAST USED CONFIGURATION LOADED \x1b[0m \n")
print("INPUT ",inputPort," OUTPUT ",to_Axoloti)
print("\x1b[4;37;40m Success! \x1b[0m")
pass
else:
startMenu()
pass
ports = [mido.open_input(name) for name in inputList]
############# send custom CC local off for keyboard
local_off = Message('control_change',channel=13,control=122,value=0)
with mido.open_output(to_Keyboard, autoreset=True) as kb:
kb.send(local_off)
####################################
try:
with mido.open_output(str(to_Axoloti), autoreset=True) as port:
for message in multi_receive(ports):
if hasattr(message, "note"):
print(message)
if message.type == 'note_on':
on = Message('note_on',channel=outCh,velocity=message.velocity,note=message.note)
port.send(on)
if message.type == 'note_off':
off = Message('note_off',channel=outCh,note=message.note)
port.send(off)
if message.type == 'control_change' :
cc = Message('control_change',channel=outCh,control=message.control,value=message.value)
port.send(cc)
print("Sending : ", cc)
print("----------------------")
# To receive led CC data to show in the Launch Control XL
with mido.open_output(to_LControl) as port2:
print("Opened out to lx and axo listener " ,to_LControl, port2)
for message in multi_receive(axoPort):
if message.type == 'control_change' :
ledCC = Message('control_change',channel=lcontrolCH,control=message.control,value=message.value)
port2.send(ledCC)
print("Sending LED CC VALUES FROM AXO TO LXL")
except KeyboardInterrupt:
pass