Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with port names ending with a number. #30

Open
GuruGurra opened this issue Sep 3, 2023 · 3 comments
Open

Problems with port names ending with a number. #30

GuruGurra opened this issue Sep 3, 2023 · 3 comments

Comments

@GuruGurra
Copy link

GuruGurra commented Sep 3, 2023

If a port name ends with a number that coincides with the port number, the number is stripped from the name.

Example:

If I have two ports named (their real names) "Port 1" and "Port 2", they will both be reported as "Port" in the port list and hence cannot be used.

Edit: The problem seems to be a macOS problem only. I can't see that port names have any numbers appended on macOS, causing the real port name to be truncated if it ends with the same number as the internal port number.

@micdah
Copy link
Owner

micdah commented Sep 4, 2023

The name is resolved using rtmidi actually, so I suspect either rtmidi or the underlying macOS specific API might be doing some truncations, I simple use a provided GetPortName(...) method in the underlying library.

But rtmidi enumerates devices by a unique port number (uint) which is currently not exposed in RtMidi.Core, which might help in this case?

I suspect you are storing the name of the device you want to connect to, and then using MidiDeviceManager to find it?

MidiDeviceManager.Default.InputDevices.SingleOrDefault(dev => dev.Name == "Name");

If the port number is exposed, this may help disambiguating two devices with the same name (albeit it, having it not being truncated would be preferred). I'm just unsure whether the port number is persistent across restarts, I suspect it's just tied to whichever order the devices are enumerated. I.e. connecting / disconnecting devices may change device numbering I suspect.

My best suggestion would be to have a look over in rtmidi and see if you can figure out where the truncation happens

@GuruGurra
Copy link
Author

...I simple use a provided GetPortName(...) method in the underlying library.

No, you don't. In RtMidiDeviceInfo, you set the name to:

Name = name.EndsWith(port.ToString())
    ? name.Substring(0, name.LastIndexOf(port.ToString(), StringComparison.Ordinal))
    : name;

If I change that like this, it works on both Windows and macOS.

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
{
    Name = name.EndsWith(port.ToString())
    ? name.Substring(0, name.LastIndexOf(port.ToString(), StringComparison.Ordinal))
    : name;
}
else { Name = name; }

@micdah
Copy link
Owner

micdah commented Sep 4, 2023

My bad, you are correct. 👍

I see you have also identified the changes needed, a PR would be much appreciated - I'll have a look shortly at reviving the build pipeline as the current isn't active anymore and then I can merge your PR and get a new build out.

Great find. 🚀

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

No branches or pull requests

2 participants