Skip to content

Commit 07ad5e1

Browse files
committed
cleaner exit that closes ports
1 parent 0bcadb9 commit 07ad5e1

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
# mcupython
2-
Smarter mackie controller abstraction layer in python
2+
Documentation will be updated with instructions on how to run, and how to install.
3+
4+
To run, launch the hackiemackie.py, which is the main program
5+
6+
example
7+
python3.10 hackiemackie.py
8+
9+
Settings are available in midiconfig.py, edit the file as needed to match your configuration.
10+
11+
Requirements:
12+
python3.10 (might work with some earlier versions of 3)
13+
mido module
14+
python-rtmidi
15+
16+
How to install needed modules:
17+
pip3 install python-rtmidi
18+
pip3 install mido

hackiemackie.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import signal
55
import sys
66
import mido
7+
import atexit
78
from time import perf_counter
89
import time
910
from dataclasses import asdict, dataclass
@@ -27,6 +28,20 @@ def print_debug(text:str,print_time=True, debug:bool=False):
2728
text = f"{timestamp()}{text}"
2829
print(text)
2930

31+
def close_and_quit(outport, outportVirt, multiPorts):
32+
# outport.close()
33+
print(f"Closing outputs: {outport}, {outportVirt}")
34+
print(f"Closing inputs: {multiPorts}")
35+
outport.close()
36+
outportVirt.close()
37+
for port in multiPorts:
38+
port.close()
39+
40+
print(f"{outport} closed: {outport.closed}")
41+
print(f"{outportVirt} closed: {outportVirt.closed}")
42+
print(f"{multiPorts} closed: {multiPorts}")
43+
#sys.exit(0)
44+
3045

3146
@dataclass
3247
class AutoBankHandler:
@@ -72,6 +87,10 @@ def bank_change_direction(self,reset=False):
7287
def bank_search(self):
7388
"""Logic for starting search mode"""
7489
self.bank_search_time = perf_counter()
90+
self.bank_queued = True
91+
self.bank_running = True
92+
self.bank_direction = 0
93+
7594
print_debug(f"Bank searching started...")
7695
pass
7796
def bank_found(self):
@@ -154,6 +173,8 @@ def main()->None:
154173
# dict for lookup/validation for mackie commands
155174
MCDict = {x:x for x in MCKeys}
156175

176+
atexit.register(close_and_quit,outport, outportVirt, multiPorts)
177+
157178
print_debug("HackieMackie Starting...Ctrl-C to terminate.", debug = True)
158179
# MAIN LOOP
159180
#
@@ -280,11 +301,13 @@ def main()->None:
280301
else:
281302
banker.bank_search()
282303
# should be method
283-
banker.bank_queued = True
284-
banker.bank_running = True
285-
banker.bank_direction = 0
304+
# banker.bank_queued = True
305+
# banker.bank_running = True
306+
# banker.bank_direction = 0
286307

287308
banker.bank_queued = True
309+
310+
288311
# bankingRunning = True
289312

290313
# PING PONG Logic

0 commit comments

Comments
 (0)