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

How to get Port Number after calling open_midiinput or open_midioutput? #205

Open
andreaseinsiedler opened this issue Jul 8, 2024 · 4 comments

Comments

@andreaseinsiedler
Copy link

andreaseinsiedler commented Jul 8, 2024

I'm working on a way to save the Midi Setup and want to write the choosen Portnumbers to a txt file and when i recall i just pass it directly to open_midiinput(port) or open_midioutput(port).

I can add port to the return of open_midiport in midiutils.py and get the Portnumber this way. But i really don't want to change anything inside the module installed via pip.

@andreaseinsiedler andreaseinsiedler changed the title Could you add variable port to the return of open_midiport in midiutils.py? How to get Port Number after calling open_midiinput or open_midioutput? Jul 8, 2024
@SpotlightKid
Copy link
Owner

Alas, it doesn't work that way. Port numbers are not guaranteed or even expected to stay the same. They change as MIDI devices get added or disconnected.

That's one of the main flaws of the RtMidi API (it is not alone in having that flaw, though).

The best strategy is probably to save (a substring) of the port name.

@SpotlightKid
Copy link
Owner

BTW, open_midiinput and open_midioutput were always only meant as quick-and-dirty helper functions for MIDI utilities on top of what the core RtMidi C++ API offers.. For more robust applications, you are expected to implement your own way of enumerating, selecting and opening MIDI devices based on the core API in the main rtmidi module.

@andreaseinsiedler
Copy link
Author

Thx for the quick response.

Quick and Dirty if totally fine with me. Programming is just a hobby of mine and i only code if i need a tool for myself. I'm writing a hacky little tool to trick the Mackie Control Implementation of TotalMix from RME to get absolute Midi Mapping for some functions. They say they are currently working on a rewrite of their Midi Implementation. Too long for me to wait, but the script might get suddenly (and hopefully) obsolete when and if they really implement Midi Learn functionality to TotalMix.

My usecase for the quick and dirty saving of the Midi Setup is just, so you don't have to repeat the whole setup procedure when you restart the script and nothing has changed with the Midi Ports.

I also found that on windows you get the Port Number with the namestring of the open_midiport function and on Mac you don't. - Is that expected and stable?

But anyway, as i will use pyinstaller and freeze the source for an one folder distro i might as well hack into midiutils.py.

@SpotlightKid
Copy link
Owner

SpotlightKid commented Jul 8, 2024

I also found that on windows you get the Port Number with the namestring of the open_midiport function and on Mac you don't. - Is that expected and stable?

You mean the name includes some kind of number? That is entirely dependent on the OS-dependant MIDI backend and its USB MIDI driver. Unfortunately this makes MIDI device names change potentially when dis- and reconnecting them. That's one reason why this part of the RtMid API is flawed. python-rtmidi does not (and can't) change that.

But anyway, as i will use pyinstaller and freeze the source for an one folder distro i might as well hack into midiutils.py.

Just copy the implementation of midiutils.open_midiport into your program's package and hack away :-)

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