Skip to content

Commit 62cd37e

Browse files
committed
fix: update MIDI connections and improve event handling/debugging
1 parent 5c2b8d2 commit 62cd37e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

alsa.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# This list is the "source of truth" for your MIDI setup.
1111
# Use the format "Client Name:Port Name" or "Client Number:Port Number".
1212
DESIRED_CONNECTIONS = [
13-
("Midi Through:Midi Through Port-0", "Pure Data:Pure Data Midi-In 1"),
13+
("a2j:Midi Through", "Midi Fighter Twister:Midi Fighter Twister MIDI 1"),
1414
# Example: ("20:0", "128:0"),
1515
]
1616

@@ -63,7 +63,17 @@ class snd_seq_event(ctypes.Structure):
6363
SND_SEQ_PORT_TYPE_APPLICATION = 1
6464

6565
# Event types that trigger a reconciliation
66-
RELEVANT_EVENTS = {60, 61, 62, 63, 64, 65, 66, 67}
66+
# Include client/port creation, deletion, and change events
67+
RELEVANT_EVENTS = {
68+
60, # SND_SEQ_EVENT_CLIENT_START
69+
61, # SND_SEQ_EVENT_CLIENT_EXIT
70+
62, # SND_SEQ_EVENT_CLIENT_CHANGE
71+
63, # SND_SEQ_EVENT_PORT_START
72+
64, # SND_SEQ_EVENT_PORT_EXIT
73+
65, # SND_SEQ_EVENT_PORT_CHANGE
74+
66, # SND_SEQ_EVENT_PORT_SUBSCRIBED
75+
67, # SND_SEQ_EVENT_PORT_UNSUBSCRIBED
76+
}
6777

6878
# --- ALSA Function Prototypes ---
6979
# Suppress the default ALSA error handler
@@ -402,6 +412,7 @@ class pollfd(ctypes.Structure):
402412
while alsalib.snd_seq_event_input(seq, ctypes.byref(event_ptr)) >= 0:
403413
event = event_ptr.contents
404414
if event and event.type in RELEVANT_EVENTS:
415+
print(f" [EVENT] Received ALSA event type {event.type}")
405416
reconciliation_needed = True
406417

407418
if reconciliation_needed:
@@ -415,11 +426,4 @@ class pollfd(ctypes.Structure):
415426

416427

417428
if __name__ == "__main__":
418-
# # Define a no-op handler to suppress ALSA's default error messages
419-
# @SND_ERROR_HANDLER_T
420-
# def py_error_handler(filename, line, function, err, fmt):
421-
# pass
422-
423-
# alsalib.snd_lib_error_set_handler(py_error_handler)
424-
425429
main()

0 commit comments

Comments
 (0)