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

Needs root? #24

Closed
MartinPaulEve opened this issue Sep 7, 2017 · 16 comments
Closed

Needs root? #24

MartinPaulEve opened this issue Sep 7, 2017 · 16 comments

Comments

@MartinPaulEve
Copy link

OK, this is probably a silly question, but is there a way to avoid the need for root on Linux systems? My device isn't detected unless I run with sudo...

I added the following udev rule, but no luck:

ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="1235", ATTRS{idProduct}=="0036", MODE="660", GROUP="plugdev"

This is a Launchpad Mini Mk2

@FMMT666
Copy link
Owner

FMMT666 commented Sep 7, 2017

So "isn't detected" means that "lp.ListAll()" does not see anything
or do you mean the kernel messages (e.g. output from "dmesg")?

Are you member of a group that allows access to audio (and MIDI) devices,
something like "audio", etc...
What distro are you using?

@MartinPaulEve
Copy link
Author

MartinPaulEve commented Sep 7, 2017 via email

@FMMT666
Copy link
Owner

FMMT666 commented Sep 7, 2017

Will check that this weekend...
Do you have Jack installed?

@MartinPaulEve
Copy link
Author

MartinPaulEve commented Sep 7, 2017 via email

@FMMT666
Copy link
Owner

FMMT666 commented Sep 9, 2017

Mhh, that even works w/o being a member of audio/plugdev/orwhatever
(on my 16.04 systems).

Did you eventually install any driver for the Launchpads?
That's usually not necessary and might cause problems.

What exactly does happen? What does lp.ListAll() print?
Do at least the Midi through ports appear?

('ALSA', 'Midi Through Port-0', 0, 1, 0)
('ALSA', 'Midi Through Port-0', 1, 0, 0)

You can also check your permissions or installation with "aconnect -i":

Client 0: 'System' [Typ=Kernel]
    0 'Timer           '
    1 'Announce        '
Client 14: 'Midi Through' [Typ=Kernel]
    0 'Midi Through Port-0'
Client 20: 'Launchpad Mini' [Typ=Kernel]
    0 'Launchpad Mini MIDI 1'

and later with that number of the device above (here it's "20"):
"aseqdump -p 20":

Waiting for data. Press Ctrl+C to end.
Source  Event                  Ch  Data
 20:0   Note on                 0, note 36, velocity 127
 20:0   Note off                0, note 36
 20:0   Note on                 0, note 36, velocity 127
 20:0   Note off                0, note 36
 20:0   Note on                 0, note 52, velocity 127
 20:0   Note off                0, note 52

Does that work? Can you access the Launchpad that way?

@MartinPaulEve
Copy link
Author

MartinPaulEve commented Sep 10, 2017

OK, so:

Running this:

lp = launchpad.Launchpad()
print(lp.ListAll())
return

returns

None
ALSA lib conf.c:3009:(snd_config_update_r) Cannot access file /etc/alsa/alsa.conf
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Exception AttributeError: "'NoneType' object has no attribute 'quit'" in <bound method __Midi.del of <launchpad_py.launchpad.__Midi instance at 0x7fdccef4b2d8>> ignored

Does it need an alsa config file in /etc/alsa/alsa.conf?

When I do aconnect -i:

[ martin: ~ ]$ aconnect -i
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 24: 'M-Track 2X2M' [type=kernel,card=2]
0 'M-Track 2X2M MIDI 1'
client 28: 'Launchpad Mini' [type=kernel,card=3]
0 'Launchpad Mini MIDI 1'

When I do aseqdump -p 28:

[ martin: ~ ]$ aseqdump -p 28
Waiting for data. Press Ctrl+C to end.
Source Event Ch Data
28:0 Note on 0, note 39, velocity 127
28:0 Note off 0, note 39
28:0 Note on 0, note 49, velocity 127
28:0 Note off 0, note 49

So that all seems to work. It's just that the python script can't seem to access the device without root. (Script is being run under the same user account -- martin -- as was aseqdump)

@MartinPaulEve
Copy link
Author

Here's a comparison of them running with root and without:

(launchControl) [ martin: ~/Documents/Programming/launchPadControl ]$ sudo python ./launcher.py [sudo] password for martin: ('ALSA', 'Midi Through Port-0', 0, 1, 0) ('ALSA', 'Midi Through Port-0', 1, 0, 0) ('ALSA', 'M-Track 2X2M MIDI 1', 0, 1, 0) ('ALSA', 'M-Track 2X2M MIDI 1', 1, 0, 0) ('ALSA', 'Launchpad Mini MIDI 1', 0, 1, 0) ('ALSA', 'Launchpad Mini MIDI 1', 1, 0, 0) None (launchControl) [ martin: ~/Documents/Programming/launchPadControl ]$ python ./launcher.py ALSA lib conf.c:3009:(snd_config_update_r) Cannot access file /etc/alsa/alsa.conf ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default None Exception AttributeError: "'NoneType' object has no attribute 'quit'" in <bound method __Midi.__del__ of <launchpad_py.launchpad.__Midi instance at 0x7fe9cf482320>> ignored

@MartinPaulEve
Copy link
Author

Right, solved it!

I added an alsa config file that reads:

`seq.default {
type hw
}

seq.hw {
type hw
}
`

Now it works without root. Perhaps adding this to an FAQ/the docs in case anyone else hits it?

Thanks so much again for your work on this library!

@FMMT666
Copy link
Owner

FMMT666 commented Sep 10, 2017

Great work, thanks!

Seems identical to #21.
PyGame was obviously built with an older Alsa version...

If you have got a little time, could you please do me a favour
and create a symbolic link from /etc/alsa/also.conf to your already existing
alsa.conf in /usr/share/alsa/alsa.conf and test whether that works?

sudo ln -s /usr/share/alsa/alsa.conf /etc/alsa/alsa.conf

(I assume you know how to do that. Just posting that for
the sake of completeness ;-)

I also just installed Ubuntu 17.04 in a VM (skipping localization ragequits here)
for a further analysis (although I guess, the best solution is just to move
over to rtmidi/2 and drop PyGame).

@MartinPaulEve
Copy link
Author

No worries!

I can confirm that symlinking the default alsa configuration does not work. (No launchpads detected.)

@FMMT666
Copy link
Owner

FMMT666 commented Sep 10, 2017

Thanks a lot!
Yep, same on my VM setup, but as it seems, that worked
for others (though I don't know whether they were using
an Ubuntu flavoured OS).

@MartinPaulEve
Copy link
Author

Yeah, sorry for not spotting the alsa output error earlier when I first made this post.

Is there a way to provide alsa parameters to pygame? That could solve it without wholesale replacing the library...

@FMMT666
Copy link
Owner

FMMT666 commented Sep 10, 2017

PyGame uses PortMidi (which itself uses Alsa under Linux, Core MIDI under macOS and
MME in Windoze) and actually I'm quite surprised that it still works on 2017's HW
and OSs :-). It was last (officially) updated somewhere around 2010...

@FMMT666 FMMT666 mentioned this issue Sep 11, 2017
@FMMT666
Copy link
Owner

FMMT666 commented Sep 11, 2017

Added your solution to the doc, including a mention.
Hope you're ok with that...

Thanks!

@MartinPaulEve
Copy link
Author

MartinPaulEve commented Sep 12, 2017 via email

@ewpratten
Copy link

ewpratten commented May 9, 2024

For Fedora users: This seems to work on F39

sudo mkdir -p /usr/local/share/alsa
sudo ln -s /usr/share/alsa/alsa.conf /usr/local/share/alsa/alsa.conf

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

3 participants