FMMT666 / launchpad.py

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

Detect button presses? (LaunchpadPro) #74

Closed Xd-pro closed 2 years ago

Xd-pro commented 2 years ago

I don't see any clear answer looking through the source code. I've tried using lp.ButtonStateXY() and lp.ButtonStateRaw(), but they both return empty arrays, even when buttons are held.

FMMT666 commented 2 years ago

You can check the "button[...].py", "hello.py" and probably some other code files in the example folder on how to use those.

Assuming you are talking about the Mk3 variant of the Pro, did you upgrade the FW, are using the correct "+1 number" in lp.Open(), have it set to the "correct" [tm], MIDI channel and deactivated the "Transmit Clock" in the Launchpad settings?

Xd-pro commented 2 years ago

I'm using the Mk1 pro. All of the other features are working, it's only the button presses that aren't working. I'm running Windows.

FMMT666 commented 2 years ago

Could you post the outputs of the "information.py" and "midi_events.py" examples? In case you are using PyGame 1.9.2, please try using a different version.

And just to make sure, your issue is not something like this here, https://github.com/FMMT666/launchpad.py/issues/54, right?

Xd-pro commented 2 years ago

Information.py

D:\projects\launchpad>python test.py
pygame 2.1.0 (SDL 2.0.16, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html

Running...
 - OS      : nt
 - Platform: Windows
 - Release : 10
 - Arch    : 64bit
 - struct  : 64
 - Python  : 3.9.2
 - PyGame  : 2.1.0

Available MIDI devices:
Microsoft GS Wavetable Synth 0 1 0
Party Mix MIDI 1 1 0
Launchpad Pro 2 1 0
MIDIOUT2 (Launchpad Pro) 3 1 0
MIDIOUT3 (Launchpad Pro) 4 1 0
Party Mix MIDI 0 0 1
Launchpad Pro 1 0 1
MIDIIN2 (Launchpad Pro) 2 0 1
MIDIIN3 (Launchpad Pro) 3 0 1

goodbye ...

(I have tried without the other midi devices plugged in)

midi_events.py:

D:\projects\launchpad>python test.py
===
Available MIDI devices:
Microsoft GS Wavetable Synth 0 1 0
Party Mix MIDI 1 1 0
Launchpad Pro 2 1 0
MIDIOUT2 (Launchpad Pro) 3 1 0
MIDIOUT3 (Launchpad Pro) 4 1 0
Party Mix MIDI 0 0 1
Launchpad Pro 1 0 1
MIDIIN2 (Launchpad Pro) 2 0 1
MIDIIN3 (Launchpad Pro) 3 0 1
===
Enter a part of the device name, that shall be monitored.
The string needs to cover the in- and output channels of a device!
Otherwise, opening only one input or one output channel will result in an error.
The search string is case-insensitive.
  search string:Launchpad Pro
===
Microsoft GS Wavetable Synth 0 1 0
Party Mix MIDI 1 1 0
Launchpad Pro 2 1 0
MIDIOUT2 (Launchpad Pro) 3 1 0
MIDIOUT3 (Launchpad Pro) 4 1 0
Party Mix MIDI 0 0 1
Launchpad Pro 1 0 1
MIDIIN2 (Launchpad Pro) 2 0 1
MIDIIN3 (Launchpad Pro) 3 0 1
===
  ENTER to continue or new search string:
===
Now hit the keys, turn the knobs or push the buttons:
([144, 81, 97], 0.0)
([144, 81, 0], 0.084)
Xd-pro commented 2 years ago

EventRaw() does work (in my script). This seems to be an issue with the abstraction you've created on top of the midi data.

FMMT666 commented 2 years ago

Upgraded to your configuration, PyGame 2.1, etc. All working fine.

A stock Launchpad Pro does not return values as you described them. Also there's absolutely nothing in the code that would return parenthesis. In addition nothing in here would ever return floats as a MIDI time.

The output of a Pro, with this repo and PyGame looks like this:

[[[160, 36, 32, 0], 57747]]
[[[160, 36, 8, 0], 57752]]
[[[160, 36, 0, 0], 57757]]
[[[144, 36, 0, 0], 57804]]
[[[144, 36, 65, 0], 58631]]
[[[144, 36, 0, 0], 58704]]
[[[144, 36, 56, 0], 59325]]
[[[144, 36, 0, 0], 59440]]
[[[144, 36, 63, 0], 59914]]
[[[160, 36, 81, 0], 60003]]
[[[160, 36, 69, 0], 60014]]
[[[160, 36, 61, 0], 60019]]
[[[160, 36, 53, 0], 60024]]
[[[160, 36, 32, 0], 60030]]
[[[160, 36, 8, 0], 60035]]
[[[160, 36, 0, 0], 60040]]
[[[144, 36, 0, 0], 60077]]

If the pressure events are turned off, you'll only see 144 (Note On/Off). If the aftertouch is set to CHANNEL rather than POLY, you'll get 208 instead of 160.

Not sure if your printout is just a Github copy and paste issue or something else, but the "info" output usually looks like this:

Available MIDI devices:
 0 (b'MMSystem', b'Microsoft MIDI Mapper', 0, 1, 0)
 1 (b'MMSystem', b'Launchpad Pro 2', 1, 0, 0)
 2 (b'MMSystem', b'MIDIIN2 (Launchpad Pro 2)', 1, 0, 0)
 3 (b'MMSystem', b'MIDIIN3 (Launchpad Pro 2)', 1, 0, 0)
 4 (b'MMSystem', b'Microsoft GS Wavetable Synth', 0, 1, 0)
 5 (b'MMSystem', b'Launchpad Pro 2', 0, 1, 0)
 6 (b'MMSystem', b'MIDIOUT2 (Launchpad Pro 2)', 0, 1, 0)
 7 (b'MMSystem', b'MIDIOUT3 (Launchpad Pro 2)', 0, 1, 0)

The three numbers on the right mean, in order of appearance: IS_INPUT, IS_OUTPUT, IS_OPENED. They can only be 0 or 1. Your Pad returns 2, 3, 4.

To me this looks like that you're either running a completely different FW, using a different fork of this repo or something that is super old.


EDIT:

Did you install PyGame via pip?

Xd-pro commented 2 years ago

Fixed the issue. Turns out I was using a very old fork of the library (pip module novation_launchpad) which still linked to this GitHub page because it had not been changed. Apologies for the trouble.

FMMT666 commented 2 years ago

no worries