Skip to content

Commit 3bd3638

Browse files
committed
added XY pressure events for the X
1 parent 628722f commit 3bd3638

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Successfully tested with Ubuntu 18.04-LTS+. Requires compiling your own PyGame t
9494
- added Pro Mk3 ButtonStateXY() pressure events
9595
- added demo file "launchpad_pressure_xy()" for new XY pressure events (Pro Mk3, so far)
9696
- fixed MF64 minor init flaw
97+
- added X ButtonStateXY() pressure events
98+
- updated pressure xy demo file for X and also fixed an error for the Pro Mk3
9799

98100

99101
### CHANGES 2020/08/XX:

examples/launchpad_pressure_xy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
#
33
# Quick demo of the new, optional "pressure events" for supported Launchpads.
4-
# Works with: Pro Mk3
4+
# Works with: Pro Mk3, X
55
#
66
#
77
# FMMT666(ASkr) 7/2013..9/2020
@@ -31,10 +31,10 @@ def main():
3131
# lp = launchpad.LaunchpadPro()
3232
# if lp.Open( 0 ):
3333
# mode = "pro"
34-
# elif launchpad.LaunchpadLPX().Check ( 1 ):
35-
# lp = launchpad.LaunchpadLPX()
36-
# if lp.Open( 1 ):
37-
# mode = "lpx"
34+
elif launchpad.LaunchpadLPX().Check ( 1 ):
35+
lp = launchpad.LaunchpadLPX()
36+
if lp.Open( 1 ):
37+
mode = "lpx"
3838

3939
if mode is None:
4040
print("no compatible Launchpad found ...")
@@ -60,7 +60,7 @@ def main():
6060
if mode == "pro" or mode == "promk3":
6161
print(" PRESSURE: " + str(events[2]) )
6262
else:
63-
print(" PRESSURE: " + str(events[0]-255) + " " + str(events[1]) )
63+
print(" PRESSURE: " + str(events[0]-255) + " " + str(events[1]-255) + " " + str(events[2]) )
6464

6565
else:
6666
# the standard button events
@@ -69,7 +69,7 @@ def main():
6969
else:
7070
print(" RELEASED: ", end='')
7171
# TODO
72-
print( str(events[0]) + " " + str(events[2]) )
72+
print( str(events[0]) + " " + str(events[1]) + " " + str(events[2]) )
7373

7474

7575
if __name__ == '__main__':

launchpad_py/launchpad.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ def ButtonStateRaw( self, returnPressure = False ):
27602760
#-- Compatibility would require checking via "== True" and not "is True".
27612761
#-------------------------------------------------------------------------------------
27622762
# Overrides "LaunchpadPro" method
2763-
def ButtonStateXY( self, mode = "classic" ):
2763+
def ButtonStateXY( self, mode = "classic", returnPressure = False ):
27642764
if self.midi.ReadCheck():
27652765
a = self.midi.ReadRaw()
27662766

@@ -2770,22 +2770,28 @@ def ButtonStateXY( self, mode = "classic" ):
27702770
# very long lags...
27712771
# 8/2020: Copied from the Pro.
27722772
# Try to mitigate that a bit (yep, seems to work fine!)
2773-
while a[0][0][0] == 160:
2774-
a = self.midi.ReadRaw()
2775-
if a == []:
2776-
return []
2773+
# 9/2020: now also _with_ pressure :)
2774+
if returnPressure == False:
2775+
while a[0][0][0] == 160:
2776+
a = self.midi.ReadRaw()
2777+
if a == []:
2778+
return []
27772779

2778-
if a[0][0][0] == 144 or a[0][0][0] == 176:
2780+
if a[0][0][0] == 144 or a[0][0][0] == 176 or a[0][0][0] == 160:
27792781

27802782
if mode.lower() != "pro":
27812783
x = (a[0][0][1] - 1) % 10
27822784
else:
27832785
x = a[0][0][1] % 10
27842786
y = ( 99 - a[0][0][1] ) // 10
2785-
2786-
return [ x, y, a[0][0][2] ]
2787+
2788+
# now with pressure events (9/2020)
2789+
if a[0][0][0] == 160 and returnPressure == True:
2790+
return [ x+255, y+255, a[0][0][2] ]
2791+
else:
2792+
return [ x, y, a[0][0][2] ]
27872793
else:
2788-
return []
2794+
return []
27892795
else:
27902796
return []
27912797

0 commit comments

Comments
 (0)