SpotlightKid / python-rtmidi

Python bindings for the cross-platform MIDI I/O library RtMidi
https://spotlightkid.github.io/python-rtmidi/
Other
356 stars 65 forks source link

1.5.7 seems to have an issue with Pipewire implementing JACK #189

Closed EternityForest closed 11 months ago

EternityForest commented 11 months ago

On Ubuntu, I get:

File "/home/daniel/Projects/KaithemAutomation/kaithem/src/rtmidimanager.py", line 111, in doScan m = rtmidi.RtMidiIn(rtapi=rtmidi.API_UNIX_JACK) File "/home/daniel/Projects/KaithemAutomation/kaithem/src/tweaks.py", line 136, in mget m = rtmidi.MidiIn(*a, **k) File "_rtmidi.pyx", line 821, in _rtmidi.MidiIn.cinit _rtmidi.SystemError: MidiInJack::initialize: JACK server not running?

And I do not get this issue with 1.4.7. It could be my mistake or an issue in Pipewire though.

SpotlightKid commented 11 months ago

Thanks for the report. Unfortunately the error message does not give enough information to know what the problem is. Can you give more background?

SpotlightKid commented 11 months ago

Closing due to no further feedback. Assuming user error.

Feel free to re-open if you have additional information.

EternityForest commented 6 months ago

Sorry for the delay, I got super busy with some volunteer stuff!

On version 1.5.8 the following gives an error on Ubuntu 22.04.3 LTS x86_64, running pipewire when just ran interactively in the console

rtmidi.MidiIn(rtmidi.API_UNIX_JACK)

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Traceback (most recent call last):
  File "_rtmidi.pyx", line 810, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInJack::initialize: JACK server not running?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_rtmidi.pyx", line 812, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInJack::initialize: JACK server not running?

Downgrading to 1.5.0 works the second time you attempt to create the port but fails the first time

>>> rtmidi.MidiIn(rtmidi.API_UNIX_JACK)

RtMidiIn: no compiled support for specified API argument!

ALSA lib conf.c:4005:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib64/alsa-lib/libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Traceback (most recent call last):
  File "_rtmidi.pyx", line 814, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInAlsa::initialize: error creating ALSA sequencer client object.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_rtmidi.pyx", line 816, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInAlsa::initialize: error creating ALSA sequencer client object.
>>> rtmidi.MidiIn(rtmidi.API_UNIX_JACK)

RtMidiIn: no compiled support for specified API argument!

<_rtmidi.MidiIn object at 0x7f20ea4d4a90>
SpotlightKid commented 6 months ago

I can only repeat, what I already said. I need more information to even start beginning to understand what the problem might be.

* How did you install python-rtmidi? If possible give a full copy of the commands you used and the full output?

* Where is it installed? Are you sure your program is using the new version?

* Have you tested any of the python-rtmidi examples from this repo? Do they exhibit the same problem?
EternityForest commented 6 months ago

Installed with pip install python-rtmidi or pip install -u python-rtmidi==1.5.0

Running midiin_callback.py produces an error. I also tried modifiying it with the lines

import rtmidi
print(rtmidi.__version__)

To confirm the version.

From what I can tell the TLDR of testing is:

Old version: The default API fails. api=rtmidi.API_UNIX_JACK fails.
However wrapping the JACK API call in a try block and just trying it again on failure works, it works the second time.

New version: The default API works perfectly. The JACK API fails, and retrying does not help.

I don't know how well it works with non-PipeWire systems on a real JACK server.

Test logs

1.5.0
DEBUG:rtmidi.midiutil:Creating MidiIn object.
ALSA lib conf.c:4005:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib64/alsa-lib/libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Traceback (most recent call last):
  File "_rtmidi.pyx", line 814, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInAlsa::initialize: error creating ALSA sequencer client object.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/Toilet/midiin_callback.py", line 38, in <module>
    midiin, port_name = open_midiinput(port)
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 272, in open_midiinput
    return open_midiport(port, "input", api, use_virtual, interactive,
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 203, in open_midiport
    midiobj = midiclass_(api, name=client_name)
  File "_rtmidi.pyx", line 816, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInAlsa::initialize: error creating ALSA sequencer client object.

Running pip3 install python-rtmidi==1.5.8 and retrying, surprisingly it works correctly

>>> python3 midiin_callback.py 
1.5.8
DEBUG:rtmidi.midiutil:Creating MidiIn object.
Do you want to create a virtual MIDI input port? (y/N) y
INFO:rtmidi.midiutil:Opening virtual MIDI input port.
Attaching MIDI input callback handler.
Entering main loop. Press Control-C to exit.

Changing the code to:

midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)

Gives the following:

python3 midiin_callback.py 
1.5.8
DEBUG:rtmidi.midiutil:Creating MidiIn object.
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Traceback (most recent call last):
  File "_rtmidi.pyx", line 810, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInJack::initialize: JACK server not running?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/Toilet/midiin_callback.py", line 38, in <module>
    midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 272, in open_midiinput
    return open_midiport(port, "input", api, use_virtual, interactive,
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 203, in open_midiport
    midiobj = midiclass_(api, name=client_name)
  File "_rtmidi.pyx", line 812, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInJack::initialize: JACK server not running?

That code with the old version instead gives:

1.5.0
DEBUG:rtmidi.midiutil:Creating MidiIn object.

RtMidiIn: no compiled support for specified API argument!

ALSA lib conf.c:4005:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib64/alsa-lib/libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Traceback (most recent call last):
  File "_rtmidi.pyx", line 814, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInAlsa::initialize: error creating ALSA sequencer client object.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/Toilet/midiin_callback.py", line 38, in <module>
    midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 272, in open_midiinput
    return open_midiport(port, "input", api, use_virtual, interactive,
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 203, in open_midiport
    midiobj = midiclass_(api, name=client_name)
  File "_rtmidi.pyx", line 816, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInAlsa::initialize: error creating ALSA sequencer client object.

Finally, using this code on the old version:

try:
    try:
        midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)
    except Exception:
        midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)
except (EOFError, KeyboardInterrupt):
    sys.exit()

Gives nuisance errors but does work:

1.5.0
DEBUG:rtmidi.midiutil:Creating MidiIn object.

RtMidiIn: no compiled support for specified API argument!

ALSA lib conf.c:4005:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib64/alsa-lib/libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
DEBUG:rtmidi.midiutil:Creating MidiIn object.

RtMidiIn: no compiled support for specified API argument!

Do you want to create a virtual MIDI input port? (y/N) y
INFO:rtmidi.midiutil:Opening virtual MIDI input port.
Attaching MIDI input callback handler.
Entering main loop. Press Control-C to exit.

However the trying twice does not work on the new version:

 pw-jack python3 midiin_callback.py 
1.5.8
DEBUG:rtmidi.midiutil:Creating MidiIn object.
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
DEBUG:rtmidi.midiutil:Creating MidiIn object.
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Traceback (most recent call last):
  File "_rtmidi.pyx", line 810, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInJack::initialize: JACK server not running?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/Toilet/midiin_callback.py", line 39, in <module>
    midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 272, in open_midiinput
    return open_midiport(port, "input", api, use_virtual, interactive,
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 203, in open_midiport
    midiobj = midiclass_(api, name=client_name)
  File "_rtmidi.pyx", line 812, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInJack::initialize: JACK server not running?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "_rtmidi.pyx", line 810, in _rtmidi.MidiIn.__cinit__
RuntimeError: MidiInJack::initialize: JACK server not running?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/Toilet/midiin_callback.py", line 41, in <module>
    midiin, port_name = open_midiinput(port, api=rtmidi.API_UNIX_JACK)
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 272, in open_midiinput
    return open_midiport(port, "input", api, use_virtual, interactive,
  File "/home/daniel/.local/lib/python3.10/site-packages/rtmidi/midiutil.py", line 203, in open_midiport
    midiobj = midiclass_(api, name=client_name)
  File "_rtmidi.pyx", line 812, in _rtmidi.MidiIn.__cinit__
_rtmidi.SystemError: MidiInJack::initialize: JACK server not running?