FMMT666 / launchpad.py

Novation Launchpad (and Midi Fighter) control suite for Python
Other
350 stars 59 forks source link

Needs root? #24

Closed MartinPaulEve closed 7 years ago

MartinPaulEve commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Hi,

Thanks for reply.

The device is detected just fine by the kernel and when I run, say, example.py as root everything works as expected. It's just that, as a normal user, the script can't connect.

It's Ubuntu 17.04. User is a member of the audio and plugdev groups. Any advice much appreciated - and thanks so much for your great work with this library.

Martin

On Thu, 7 Sep 2017, 18:13 FMMT666 notifications@github.com wrote:

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?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FMMT666/launchpad.py/issues/24#issuecomment-327864807, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_ot2lAEcqbV4nDjtCv8F9pnjlWroCiks5sgCQzgaJpZM4PP60f .

FMMT666 commented 7 years ago

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

MartinPaulEve commented 7 years ago

No Jack in this install. Pulse audio...

On Thu, 7 Sep 2017, 21:55 FMMT666 notifications@github.com wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FMMT666/launchpad.py/issues/24#issuecomment-327924975, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_ot9WJt_DUMRPj3gVIZ1OWqraUHkuFks5sgFgtgaJpZM4PP60f .

FMMT666 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

No worries!

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

FMMT666 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

Thanks!

MartinPaulEve commented 7 years ago

That's great -- thanks so much!

On 11/09/17 22:10, FMMT666 wrote:

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

Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FMMT666/launchpad.py/issues/24#issuecomment-328659559, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_ot1PWP2uljJMZgzVgUIwKJq9ZEkZLks5shaHBgaJpZM4PP60f.

-- Professor Martin Paul Eve Chair of Literature, Technology and Publishing Birkbeck, University of London

T: 0203 073 8420 E: martin.eve@bbk.ac.uk W: https://www.martineve.com R: 416, 43 Gordon Square, London, WC1H 0PD

Books: https://www.martineve.com/books/ Articles: https://www.martineve.com/c-v/

Series Editor: New Horizons in Contemporary Writing (Bloomsbury) Director, Birkbeck Centre for Technology and Publishing Founder, Open Library of the Humanities (https://www.openlibhums.org) Chief Editor, Orbit (https://www.pynchon.net) Senior Online Editor, Alluvium, (http://www.alluvium-journal.org)

ewpratten commented 4 months ago

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