-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
124 lines (99 loc) · 4.77 KB
/
Copy pathmain.py
File metadata and controls
124 lines (99 loc) · 4.77 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
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
#!/usr/bin/env python
from __future__ import print_function
import sys
import time
import argparse
import json
import rtmidi
from rtmidi.midiutil import open_midiinput, open_midioutput
from rtmidi.midiconstants import CONTROL_CHANGE, PROGRAM_CHANGE
class MidiInputHandler(object):
def __init__(self, port=0):
super(MidiInputHandler, self).__init__()
self.port = port
self._wallclock = time.time()
with open("config.json") as json_data_file:
data = json.load(json_data_file)
self.QC_TO_MIDI = data["QC_TO_MIDI"]
self.MIDI_TO_QC = data["MIDI_TO_QC"]
def change_mode(message):
midiout_GCP.send_message([CONTROL_CHANGE, message[0], message[2]])
def __call__(self, event, data=None):
message, deltatime = event
self._wallclock += deltatime
print("[%s] @%0.6f %r %s" % (self.port, self._wallclock, \
message, self.MIDI_TO_QC[str(message[1])]))
if self.MIDI_TO_QC[str(message[1])] == "reset":
# CC#0 value 1, CC#32 value 5, Program #1
midiout_GCP.send_message([CONTROL_CHANGE, 0, 0])
midiout_GCP.send_message([CONTROL_CHANGE, 32, 6])
midiout_GCP.send_message([PROGRAM_CHANGE, 0, 1])
midiout_GCP.send_message([CONTROL_CHANGE, 46, 127])
elif self.MIDI_TO_QC[str(message[1])] == "scene":
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "stomp":
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
elif self.MIDI_TO_QC[str(message[1])] == "preset":
MidiInputHandler.change_mode(self.QC_TO_MIDI["preset"])
elif self.MIDI_TO_QC[str(message[1])] == "smpA":
cc = self.QC_TO_MIDI["smpA"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, 0])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpB":
cc = self.QC_TO_MIDI["smpB"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpB"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpC":
cc = self.QC_TO_MIDI["smpC"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpC"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpD":
cc = self.QC_TO_MIDI["smpD"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpD"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpE":
cc = self.QC_TO_MIDI["smpE"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpE"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpF":
cc = self.QC_TO_MIDI["smpF"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpF"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpG":
cc = self.QC_TO_MIDI["smpG"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpG"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
elif self.MIDI_TO_QC[str(message[1])] == "smpH":
cc = self.QC_TO_MIDI["smpH"][0]
MidiInputHandler.change_mode(self.QC_TO_MIDI["stomp"])
midiout_GCP.send_message([CONTROL_CHANGE, cc, self.QC_TO_MIDI["smpH"][2]])
MidiInputHandler.change_mode(self.QC_TO_MIDI["scene"])
with open("config.json") as json_data_file:
data = json.load(json_data_file)
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
print(available_ports)
try:
midiin_GCP, port_name_GCP = open_midiinput(1)
midiout_GCP, port_name_GCP = open_midioutput(1)
except (EOFError, KeyboardInterrupt):
sys.exit()
print("MIDIPilot | Starting")
midiin_GCP.set_callback(MidiInputHandler(port_name_GCP))
print("Waiting for MIDI Input Loopp. Control-C to exit.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print('')
finally:
print("Exit.")
midiin.close_port()
del midiin