Skip to content

Conversation

@alexzobi
Copy link
Contributor

@alexzobi alexzobi commented Jan 5, 2026

Prevent Unnecessary Reconnects

Description

This PR stems from the issue I reported around input connections. See the issue for steps to recreate the bug. To fix this, I added a port name to the input manager and check that the port names match before deciding whether or not i should try to reconnect. as well, I added logic to explicitly drop previous connections before attempting to reconnect. Doing these things has led to more stable input manager connections.

Key Changes

MIDI input connection lifecycle

  • prevent unnecessary reconnects by checking if current connection matches desired connection
  • track currently connected input port

Improved MIDI port Identity

  • rely on stable ids via port name instead of connection state
  • add port index mapping to handle multiple ports with identical names

Testing

  1. Start the app
  2. Select a midi file to play
  3. hit the "play" button // inputs should work as expected
  4. hit the "back" button to return to the main menu
  5. hit the "play" button to again return to the playing scene.
  6. if keyboard inputs still work as expected, you win.

Comment on lines 31 to 34
// Skip reconnect if already connected to same port
if self.current_connection.is_some()
&& self.current_port_name.as_deref() == Some(port_name.as_str())
{ return; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably depend on a platform used, but what will happen if I connect to a keyboard, then physically unplug it, and plug it back again, will it still have the same name and therefore stay unconnected because of the initial unplug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked and you are correct, based on previous code, no connection was reformed. I have updated the code to ensure that input connections reform on scene change. I was considering changing the location of the checks outside of the menu_scene/state.rs which would prevent users from having to navigate back to the main menu and then back to the playing menu upon disconnect/reconnect, but didn't want to add polling logic to the main event loop without your consideration, so as for now, it operates as before, from the menu_scene only.

@alexzobi alexzobi marked this pull request as draft January 5, 2026 20:28
@alexzobi alexzobi marked this pull request as ready for review January 5, 2026 21:04
@alexzobi alexzobi requested a review from PolyMeilex January 5, 2026 21:06
@PolyMeilex
Copy link
Owner

Sadly there are way too many LLM hallucinations in this diff, could you try my fix for this and let me know if it works for you: #357 ?

Seems to work fine on my Win11 test setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants