Skip to content

Commit 0941c38

Browse files
committed
oops, forgot the pressure event files
1 parent 054ff8e commit 0941c38

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
!launchpad_rgb-fire.py
88
!launchpad_rgb.py
99
!launchpad_rgb-pulse.py
10+
!launchpad_pressure.py
11+

examples/launchpad_pressure.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
#
3+
# Quick demo of the new, optional "pressure events" for supported Launchpads.
4+
# Works with: Pro
5+
#
6+
#
7+
# FMMT666(ASkr) 7/2013..8/2020
8+
# www.askrprojects.net
9+
#
10+
11+
import sys
12+
13+
try:
14+
import launchpad_py as launchpad
15+
except ImportError:
16+
try:
17+
import launchpad
18+
except ImportError:
19+
sys.exit("error loading launchpad.py")
20+
21+
22+
def main():
23+
24+
# only the original Pro for now
25+
lp = launchpad.LaunchpadPro()
26+
lp.Open( 0 )
27+
28+
while(True):
29+
# enable the "pressure" feature by calling ButtonStateRaw with
30+
# "returnPressure" set to True
31+
events = lp.ButtonStateRaw( returnPressure = True )
32+
if events != []:
33+
# a dummy button code of 255 indicates that this is a pressure value
34+
if events[0] == 255:
35+
# Notice that the pressure value is not related to a specific button.
36+
# If you hold two buttons at the same time, the bigger value will be returned.
37+
print(" PRESSURE: " + str(events[1]) )
38+
else:
39+
# the standard button events
40+
if events[1] > 0:
41+
print(" PRESSED: ", end='')
42+
else:
43+
print(" RELEASED: ", end='')
44+
print( str(events[0]) + " " + str(events[1]) )
45+
46+
47+
if __name__ == '__main__':
48+
main()
49+

launchpad_py/launchpad.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ def Reset( self ):
11341134
#-- method in the "Classic" Launchpad, which only returned [ <button>, <True/False> ].
11351135
#-- Compatibility would require checking via "== True" and not "is True".
11361136
#-------------------------------------------------------------------------------------
1137-
def ButtonStateRaw( self ):
1137+
def ButtonStateRaw( self, returnPressure = False ):
11381138
if self.midi.ReadCheck():
11391139
a = self.midi.ReadRaw()
11401140

@@ -1154,11 +1154,32 @@ def ButtonStateRaw( self ):
11541154
# Additionally, it's interrupted by a read failure.
11551155
# The 2nd one is simply cut. Notice that that these are commands usually send TO the
11561156
# Launchpad...
1157+
#
1158+
# Reminder for the "pressure event issue":
1159+
# The pressure events do not send any button codes, it's really just the pressure,
1160+
# everytime a value changes:
1161+
# [[[144, 55, 5, 0], 654185]] button hit ("NoteOn with vel > 0")
1162+
# [[[208, 24, 0, 0], 654275]] button hold
1163+
# [[[208, 127, 0, 0], 654390]] ...
1164+
# [[[208, 122, 0, 0], 654506] ...
1165+
# [[[208, 65, 0, 0], 654562]] ...
1166+
# [[[208, 40, 0, 0], 654567]] ...
1167+
# [[[208, 0, 0, 0], 654573]] ...
1168+
# [[[144, 55, 0, 0], 654614]] button released ("NoteOn with vel == 0")
1169+
# When multiple buttons are pressed (hold), the biggest number will be returned.
1170+
#
1171+
11571172

11581173
if a[0][0][0] == 144 or a[0][0][0] == 176:
11591174
return [ a[0][0][1], a[0][0][2] ]
11601175
else:
1161-
return []
1176+
if returnPressure:
1177+
if a[0][0][0] == 208:
1178+
return [ 255, a[0][0][1] ]
1179+
else:
1180+
return []
1181+
else:
1182+
return []
11621183
else:
11631184
return []
11641185

0 commit comments

Comments
 (0)