Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions flapi/__enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def open_port(
attempt to create it
"""
for curr_port_name in port_names: # type: ignore
# In mac, Audio MIDI Setup IAC ports always prepend "IAC Driver"
# So manually created ports will always be named IAC Driver Flaip Request/Response
stripped_curr_port_name = curr_port_name.replace('IAC Driver', '')
if port_name.lower() not in stripped_curr_port_name.lower():
continue

# If the only thing after it is a number, we are free to connect to it
# It seems that something appends these numbers to each MIDI device to
# make them more unique or something
if port_name.lower() not in curr_port_name.lower():
continue
try:
# If this works, it's a match
int(curr_port_name.replace(port_name, '').strip())
except Exception:
numeric_curr_port_name = stripped_curr_port_name.replace(port_name, '').strip()
if numeric_curr_port_name.isdigit():
continue

# Connect to it
Expand Down Expand Up @@ -101,11 +103,11 @@ def enable(

if res is None or req is None:
try:
req = mido.open_output( # type: ignore
req = mido.open_ioport( # type: ignore
name=req_port,
virtual=True,
)
res = mido.open_input( # type: ignore
res = mido.open_ioport( # type: ignore
name=res_port,
virtual=True,
)
Expand Down