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

Port uniqueness #21

Open
mat1jaczyyy opened this issue Aug 8, 2019 · 8 comments
Open

Port uniqueness #21

mat1jaczyyy opened this issue Aug 8, 2019 · 8 comments
Assignees
Labels
impeeded Impeeded by something
Projects

Comments

@mat1jaczyyy
Copy link
Contributor

mat1jaczyyy commented Aug 8, 2019

Stumbled upon this problem. I need to support a use case where two identical MIDI controllers are connected to my application. The port names are the exact same in RtMidi.Core, however I see other applications appending a number to the port name where necessary. This leaves me unable to differentiate between the two ports, and while they both show up because of that I can only talk to one of these at a time.

Trying to implement this number appending on my side, while debugging I noticed a port id hidden in the private vars of MidiDeviceInfo, I could well use it by adding it to the name and ensure the ports are unique. I was gonna submit a PR which adds a get property for the id, however I found this instead:

// RtMidi may add port number to end of name to ensure uniqueness
Name = name.EndsWith(port.ToString())
? name.Substring(0, name.LastIndexOf(port.ToString(), StringComparison.Ordinal))
: name;

It seems you're already stripping the number out when RtMidi provides it? You mention RtMidi may add it, I assume it does this only in cases when a port with the same name exists already? If so, I think this code could be simplified and you should simply use the name provided by RtMidi. If not, you could write some code that checks if a port with the same name already exists, and if it does keep the number or replace it with our own number.

Unsure how to proceed myself on implementing this, would love to hear what you think is the best course of action for resolving this issue. Thanks

@mat1jaczyyy
Copy link
Contributor Author

Here are a few screenshots to help better describe the problem:

image

image

image

I can only differentiate by name, but the names are the same.

@mat1jaczyyy
Copy link
Contributor Author

@micdah ?

@mat1jaczyyy
Copy link
Contributor Author

RtMidi adds port number on Windows to "ensure uniqueness".

While it does succeed in ensuring it, disconnecting/reconnecting devices will change other devices' port numbers, so now it's impossible to tell who's who.

Additionally, on Windows, Microsoft GS Wavetable Synth is always assigned port number 0, so device in/out port names will always mismatch. On macOS they at least match, but the issue above remains unsolved.

It seems to go all the way to the OS' APIs, but Ableton Live somehow solved this... libusb?

https://github.com/micdah/rtmidi/blob/473ddc10aafd935d6d5d16e8876a566aa7c55a20/RtMidi.cpp#L2638-L2643

99% sure this is unsolvable but I'm leaving it here.

@micdah
Copy link
Owner

micdah commented Oct 27, 2020

@mat1jaczyyy Would it help to expose the port number as provided by the underlying rtmidi library, in the IMidiDeviceInfo and implementing interfaces?

As you mention we do have this information available - it's just not exposed.

I would prefer leaving the names "clean" and adding the Port property to device infos - consumer applications could format a display name based on this, for better presentation if needed.

@micdah micdah added this to To do in Development Oct 27, 2020
@micdah micdah self-assigned this Oct 27, 2020
@micdah micdah added enhancement impeeded Impeeded by something and removed enhancement labels Oct 27, 2020
@mat1jaczyyy
Copy link
Contributor Author

the Port isn't unique either, since it merely represents the "index" of a connected midi port. say there are 3 devices 0,1,2 and device 1 disconnects, device 2 will now become device 1 to rtmidi.

@micdah
Copy link
Owner

micdah commented Oct 27, 2020

the Port isn't unique either, since it merely represents the "index" of a connected midi port. say there are 3 devices 0,1,2 and device 1 disconnects, device 2 will now become device 1 to rtmidi.

I see, well that of course makes it yes usefull.

Seeing with what we are given by rtmidi i don't see any good way to fix this issue.

We would need lower level support to present us with a more stable identifier, which is cross-platform applicable - or at least one that could be provided by all platforms, not necessarily the same between platforms.

But from a RtMidi.Core perspective, I don't see much more we can do.

@mat1jaczyyy
Copy link
Contributor Author

@micdah haven't you already modified rtmidi to fit RtMidi.Core's needs? is there anything available in each platform's native API that we could expose to rtmidi, subsequently to RtMidi.Core?

@micdah
Copy link
Owner

micdah commented Sep 4, 2023

I think the same issue has propped up here, but with a suggested solution tested on mac and Windows: #30

Sounds like if we make the change suggested, it should work on both mac and Windows, sounds very much like the same thing we are seeing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impeeded Impeeded by something
Projects
Development

No branches or pull requests

2 participants