MIDI hold re-adds a peer stuck half-connected
After the network test SuperRack sat in NA Ingest's session as
"initializing"; the hold saw it listed and did nothing ("already").
connect_peer now drops a listed-but-not-live peer and adds it back,
building the second write from the first so a slow re-read cannot leave
it dropped. Tested live today: DVS x4, APPS and INGEST holds, NET clear,
CAPTIONS and BRIDGE restart keys.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+28
-2
@@ -160,9 +160,35 @@ def _edit_session(session_name, edit):
|
||||
raise LookupError("no network MIDI session named %r on this Mac" % session_name)
|
||||
|
||||
|
||||
def connect_peer(session_name, peer_name, address):
|
||||
LIVE_STATES = ("running", "connected") # "connected" for ~6 s while a peer joins, then "running"
|
||||
|
||||
|
||||
def stuck_peer(sess, peer_name):
|
||||
"""True if the peer is listed but not live (e.g. stuck "initializing" after a network drop)."""
|
||||
return any(p.get("name") == peer_name and p.get("state") not in LIVE_STATES for p in sess.get("peers", []))
|
||||
|
||||
|
||||
def connect_peer(session_name, peer_name, address, settle=time.sleep):
|
||||
"""Ask macOS to connect `peer_name` at `address` ("10.1.10.206:5004") to the named session,
|
||||
like Audio MIDI Setup's Connect. Returns "already" (it is in the session) or "asked"."""
|
||||
like Audio MIDI Setup's Connect. Returns "already" (it is in the session and live), "asked",
|
||||
or "kicked" (it was listed but stuck: dropped, then connected again)."""
|
||||
with _lock:
|
||||
found = [(e, s) for e, s in _session_entities()
|
||||
if (s.get("dns-sd-name") or _string_prop(e, "name")) == session_name]
|
||||
if found and stuck_peer(found[0][1], peer_name):
|
||||
ent, sess = found[0]
|
||||
dropped = without_peer(sess, peer_name)
|
||||
with _lock:
|
||||
err = _set_dict_prop(ent, "apple.midirtp.session", dropped)
|
||||
if err:
|
||||
raise OSError("MIDIObjectSetDictionaryProperty failed: %d" % err)
|
||||
settle(1.0)
|
||||
# Built from what was just written, not a fresh read that may still list the old entry.
|
||||
with _lock:
|
||||
err = _set_dict_prop(ent, "apple.midirtp.session", with_peer(dropped, peer_name, address))
|
||||
if err:
|
||||
raise OSError("MIDIObjectSetDictionaryProperty failed: %d" % err)
|
||||
return "kicked"
|
||||
result = _edit_session(session_name, lambda sess: with_peer(sess, peer_name, address))
|
||||
return "already" if result == "unchanged" else result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user