Skip to content

Port uniqueness #21

@mat1jaczyyy

Description

@mat1jaczyyy

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

Metadata

Metadata

Assignees

Labels

impeededImpeeded by something

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions