-
Notifications
You must be signed in to change notification settings - Fork 2
/
teslamidi.py
34 lines (32 loc) · 1.09 KB
/
teslamidi.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
import mido
class TeslaCoilMidi:
def __init__(self):
self.inport = None
self.outport = None
self.break_flag = False
def set_input(self, port_name):
self.inport = mido.open_input(port_name)
def set_output(self, port_name):
self.outport = mido.open_output(port_name)
def passthrough(self):
if self.inport is not None and self.outport is not None:
self.outport.reset()
while True:
try:
m = self.inport.receive()
self.outport.send(m)
except KeyboardInterrupt:
self.outport.reset()
break
if self.break_flag:
break;
else:
raise TeslaCoilMidiException("An input port is required to use passthrough mode")
def stop(self):
self.break_flag = True
self.inport.close()
self.outport.reset()
self.outport.close()
class TeslaCoilMidiException(Exception):
def __init__(self,*args,**kwargs):
Exception.__init__(self,*args,**kwargs)