diff --git a/midimech.py b/midimech.py index 2db8b2d..c2d366c 100755 --- a/midimech.py +++ b/midimech.py @@ -52,13 +52,23 @@ def main(): try: core = Core() core() - except SystemExit: - pass + except SystemExit as e: + if e.code != 0: + print(f"midimech exited with code {e.code}") except: print(traceback.format_exc()) - del core - pygame.midi.quit() - pygame.display.quit() + try: + del core + except: + pass + try: + pygame.midi.quit() + except: + pass + try: + pygame.display.quit() + except: + pass os._exit(0) # pygame.quit() diff --git a/src/constants.py b/src/constants.py index a8c4b66..abf6ecd 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,6 +1,9 @@ from glm import ivec2, vec2, ivec3, vec3 -TITLE = "midimech" +# Window title must not exactly match the "midimech" MIDI loopback device name. +# On some Windows setups, SDL fatally terminates the process when the window +# title matches a MIDI device name (case-insensitive). Exact cause unknown. +TITLE = "midimech app" # FOCUS = False NOTES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] WHOLETONE = True diff --git a/src/core.py b/src/core.py index 930d754..c61fd5e 100644 --- a/src/core.py +++ b/src/core.py @@ -924,6 +924,15 @@ def note_off(self, data, timestamp, width=None, mpe=None, octave=0, transpose=0, def cb_midi_in(self, data, timestamp, force_channel=None): """LinnStrument MIDI Callback""" + if not hasattr(self, 'board'): + return # not fully initialized yet + try: + self._cb_midi_in(data, timestamp, force_channel) + except Exception as e: + print(f"MIDI callback error: {e}") + + def _cb_midi_in(self, data, timestamp, force_channel=None): + """LinnStrument MIDI Callback (inner)""" # d4 = None # if len(data)==4: # d4 = data[3]