pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
827 stars 133 forks source link

pygame.midi not accessing devices properly on linux #2155

Open JiffyRob opened 1 year ago

JiffyRob commented 1 year ago

Environment:

Current behavior:

pygame.midi.get_count() will always return 0, even if I have multiple virtual and physical devices connected.

Expected behavior:

No errors and it sees my devices. This is how the versions that "worked" behaved.

Test code

import pygame.midi
pygame.midi.init() # causes warning
print(pygame.midi.get_count())

Stack trace/error output/other error logs

ALSA lib conf.c:4555:
(snd_config_update_r) Cannot access file /usr/local/share/alsa/alsa.conf
ALSO lib seq.c:935:
(snd_seq_open_noupdate) Unknown SEQ default
Starbuck5 commented 1 year ago

(pygame up through 2.1.2 worked, CE did not)

... Because pygame-ce didn't exist in those versions?

So this broke between pygame 2.1.2 and pygame 2.1.3? Well that narrows it down to a 14 month period... Not exactly ideal. What about the pygame 2.1.3 dev releases? dev2,dev4,dev6,dev8.

PurityLake commented 1 year ago

I have some time today, I can look into this

PurityLake commented 1 year ago

@JiffyRob

What version of Alsa are you using? Please give me the result of cat /proc/asound/version

PurityLake commented 1 year ago

ALso since you are running Ubuntu you should reinstall your audio libraries like so:

sudo apt-get install --reinstall libasound2 libasound2-data libasound2-plugins

It seems you alsa.conf is missing and this should fix it, restart your machine and try pygame-ce again.

JiffyRob commented 1 year ago

@PurityLake Thanks for the work, I'll look into that as soon as I have time.
@Starbuck5 maybe I was unclear - No versions of pygame-ce worked, but pygame versions up to that point did. At any rate, I'll get to that as well when I have time. Finals are coming up, so it might be a little bit.

JiffyRob commented 1 year ago

@PurityLake the given apt command did not fix the problem. Output of cat /proc/asound/version is Advanced Linux Sound Architecture Driver Version k5.10.0-22-rt-amd64

JiffyRob commented 1 year ago

@Starbuck5 I only have dev6 and dev8 available for my current version of python (3.9). Both of those showed the bug. I'll try a couple of other versions floating around on my system and see if those will get closer in.

Starbuck5 commented 1 year ago

I looked into it and the binary releases of pygame 2.1.3.dev2 and dev4 have been deleted off of pypi. You can still get the releases by navigating to the pygame repo's releases page and downloading the artifacts directly from there.

PurityLake commented 1 year ago

@JiffyRob may I ask what midi device you have plugged in? Do you have the correct drivers installed for it? I am seeing no real issues in the pygame code for it as it basically outsources the code to portmidi. Unfortunately I don't have a midi keyboard with me for the next while.

Currently looking through some of the code from portmidi to see what some of these issues might be.

PurityLake commented 1 year ago

Also what could you post you alsa.conf? Use cat /usr/share/alsa/alsa.conf

I have a feeling that for some reason ubuntu did not add the file again.

JiffyRob commented 1 year ago

@PurityLake Sorry once again for the late reply, the output is very long so I will only post the top:

#
#  ALSA library configuration file
#

# pre-load the configuration files

@hooks [
        {
                func load
                files [

At any rate, there is stuff in it, so the file is there. Also for devices I have a Midi Thru on mmy computer that pygame sees when it doesn't err out, as well as a Nektar LX49+ connected via USB. I presume I have the correct drivers set up for it because I have used it with other programs like LMMS.