Skip to content

Commit 3a361c7

Browse files
committed
added MF64 LED-mode for LedCtrlXY; added demo
1 parent df34cd4 commit 3a361c7

File tree

4 files changed

+166
-1
lines changed

4 files changed

+166
-1
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ Successfully tested with Ubuntu 18.04-LTS+. Requires compiling your own PyGame t
112112
- added MF64 LED-mode settings: brightness, toggling, flashing and animation settings
113113
- updated MF64 LedCtrlRaw() to accept LED-mode settings
114114
- updated MF64 LedAllOn() to optionally accept LED-mode settings
115+
- updated MF64 LedCtrlXY() to optionally accept LED-mode settings
116+
- added MF64 "constants" for easier LED-mode settings
117+
- added MF64 LED-mode example file "midifighter_led_modes.py"
115118

116119

117120
### CHANGES 2020/05/XX:
@@ -2272,6 +2275,28 @@ There is no possibility to control the RGB LEDs individually.
22722275
---
22732276
## Detailed description of Midi Fighter specific methods
22742277

2278+
### Constants
2279+
2280+
#### LED Modes
2281+
2282+
The following constants can be used instead of using integer values for the LED modes.
2283+
2284+
MODE_BRIGHT[0..15] instead of 18..33 for brightness
2285+
MODE_TOGGLE[0..7] instead of 34..41 for toggling
2286+
MODE_PULSE[0..7] instead of 42..49 for pulsing
2287+
MODE_ANIM_SQUARE instead of 50
2288+
MODE_ANIM_CIRCLE instead of 51
2289+
MODE_ANIM_STAR instead of 52
2290+
MODE_ANIM_TRIANGLE instead of 53
2291+
2292+
Some examples:
2293+
lp.LedAllOn( 5, 18 ) becomes lp.LedAllOn( 5, lp.MODE_BRIGHT[0] ); LED RED BUT OFF
2294+
lp.LedAllOn( 5, 33 ) becomes lp.LedAllOn( 5, lp.MODE_BRIGHT[15] ); LED RED FULLY ON
2295+
lp.LedAllOn( 5, 33 ) becomes lp.LedAllOn( 5, lp.MODE_BRIGHT[15] ); LED RED FULLY ON
2296+
2297+
Accessing "out of bounds" list values will of course crash your app.
2298+
2299+
22752300
### ButtonStateRaw()
22762301

22772302
Returns the state of the buttons in RAW mode.
@@ -2318,6 +2343,17 @@ There is no possibility to control the RGB LEDs individually.
23182343
(*) This might be an error in the manual, as it does not contain an 1/4 setting
23192344
and starts at 1/32. Need to check ...
23202345

2346+
As an alternative and instead of using the numbers above, these constants can be used.
2347+
E.g. "LedAllOn( 5, lp.MODE_BRIGHT[5] )" for an intensity value of 5, from 0..15
2348+
2349+
MODE_BRIGHT[0..15]
2350+
MODE_TOGGLE[0..7]
2351+
MODE_PULSE[0..7]
2352+
MODE_ANIM_SQUARE
2353+
MODE_ANIM_CIRCLE
2354+
MODE_ANIM_STAR
2355+
MODE_ANIM_TRIANGLE
2356+
23212357
PARAMS: <led> 36..99; number of the LED to control
23222358
<colorcode> 0..127; color code
23232359
<mode> [OPTIONAL] 18..53, see above
@@ -2341,6 +2377,17 @@ There is no possibility to control the RGB LEDs individually.
23412377
(*) This might be an error in the manual, as it does not contain an 1/4 setting
23422378
and starts at 1/32. Need to check ...
23432379

2380+
As an alternative and instead of using the numbers above, these constants can be used.
2381+
E.g. "LedAllOn( 5, lp.MODE_BRIGHT[5] )" for an intensity value of 5, from 0..15
2382+
2383+
MODE_BRIGHT[0..15]
2384+
MODE_TOGGLE[0..7]
2385+
MODE_PULSE[0..7]
2386+
MODE_ANIM_SQUARE
2387+
MODE_ANIM_CIRCLE
2388+
MODE_ANIM_STAR
2389+
MODE_ANIM_TRIANGLE
2390+
23442391
PARAMS: <led> 36..99; number of the LED to control
23452392
<mode> 18..53; see above
23462393
RETURN:
@@ -2426,6 +2473,17 @@ There is no possibility to control the RGB LEDs individually.
24262473
(*) This might be an error in the manual, as it does not contain an 1/4 setting
24272474
and starts at 1/32. Need to check ...
24282475

2476+
As an alternative and instead of using the numbers above, these constants can be used.
2477+
E.g. "LedAllOn( 5, lp.MODE_BRIGHT[5] )" for an intensity value of 5, from 0..15
2478+
2479+
MODE_BRIGHT[0..15]
2480+
MODE_TOGGLE[0..7]
2481+
MODE_PULSE[0..7]
2482+
MODE_ANIM_SQUARE
2483+
MODE_ANIM_CIRCLE
2484+
MODE_ANIM_STAR
2485+
MODE_ANIM_TRIANGLE
2486+
24292487
PARAMS: <colorcode> 0..127; color code
24302488
RETURN:
24312489

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
!launchpad_pressure.py
1111
!launchpad_pro_mk3_reset.py
1212
!midifighter_text.py
13+
!midifighter_led_modes.py
1314
!midi_events.py
1415
!buttons_raw.py
1516
!buttons_xy.py

examples/midifighter_led_modes.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python
2+
#
3+
# Just a quick LED mode example.
4+
# Works with Midi Figther 64
5+
#
6+
#
7+
# FMMT666(ASkr) 7/2013..8/2020
8+
# www.askrprojects.net
9+
#
10+
11+
import sys
12+
import random
13+
from pygame import time
14+
15+
16+
try:
17+
import launchpad_py as launchpad
18+
except ImportError:
19+
try:
20+
import launchpad
21+
except ImportError:
22+
sys.exit("error loading launchpad.py")
23+
24+
25+
def main():
26+
27+
mode = None
28+
29+
if launchpad.MidiFighter64().Check( 0 ):
30+
lp = launchpad.MidiFighter64()
31+
if lp.Open( 0 ):
32+
print("Midi Fighter 64")
33+
mode = "F64"
34+
35+
if mode is None:
36+
print("Did not find any devices, meh...")
37+
return
38+
39+
40+
# all red but off
41+
for x in range(8):
42+
for y in range(8):
43+
44+
# Additionally there are these vars which can be used to change the animation:
45+
# MODE_SQUARE
46+
# MODE_CIRCLE
47+
# MODE_STAR
48+
# MODE_TRIANGLE
49+
50+
# using if/elifs for better visibility:
51+
52+
# --- BRIGHTNESS 0..15
53+
if y == 0:
54+
color = 5
55+
mode = lp.MODE_BRIGHT[1]
56+
elif y == 1:
57+
mode = lp.MODE_BRIGHT[5]
58+
elif y == 2:
59+
mode = lp.MODE_BRIGHT[10]
60+
elif y == 3:
61+
mode = lp.MODE_BRIGHT[15]
62+
# --- TOGGLING 0..7
63+
elif y == 4:
64+
color = 25
65+
mode = lp.MODE_TOGGLE[4]
66+
elif y == 5:
67+
mode = lp.MODE_TOGGLE[x]
68+
# --- PULSING 0..7
69+
elif y == 6:
70+
color = 78
71+
mode = lp.MODE_PULSE[5]
72+
elif y == 7:
73+
mode = lp.MODE_PULSE[x]
74+
75+
lp.LedCtrlXY( x, y, color, mode )
76+
77+
78+
print("bye ...")
79+
80+
lp.Reset() # turn all LEDs off
81+
lp.Close() # close the Launchpad (will quit with an error due to a PyGame bug)
82+
83+
84+
if __name__ == '__main__':
85+
main()
86+

launchpad_py/launchpad.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,23 @@ class MidiFighter64( LaunchpadBase ):
28422842
#
28432843

28442844

2845+
#-------------------------------------------------------------------------------------
2846+
#-- Add some LED mode "constants" for better usability.
2847+
#-------------------------------------------------------------------------------------
2848+
def __init__( self ):
2849+
2850+
self.MODE_BRIGHT = [ i+18 for i in range(16) ]
2851+
self.MODE_TOGGLE = [ i+34 for i in range(8) ]
2852+
self.MODE_PULSE = [ i+42 for i in range(8) ]
2853+
self.MODE_ANIM_SQUARE = 50
2854+
self.MODE_ANIM_CIRCLE = 51
2855+
self.MODE_ANIM_STAR = 52
2856+
self.MODE_ANIM_TRIANGLE = 53
2857+
2858+
return super( MidiFighter64, self ).__init__( )
2859+
2860+
2861+
28452862
#-------------------------------------------------------------------------------------
28462863
#-- Opens one of the attached Launchpad MIDI devices.
28472864
#-- Uses search string "Fighter 64", by default.
@@ -2904,7 +2921,7 @@ def LedCtrlRawMode( self, number, mode ):
29042921
#-- <x>/<y> 0..7
29052922
#-- <color> 0..127 from color table
29062923
#-------------------------------------------------------------------------------------
2907-
def LedCtrlXY( self, x, y, color ):
2924+
def LedCtrlXY( self, x, y, color, mode = None ):
29082925

29092926
if x < 0 or x > 7:
29102927
return
@@ -2921,6 +2938,9 @@ def LedCtrlXY( self, x, y, color ):
29212938
number += (7-y) * 4
29222939

29232940
self.midi.RawWrite( 146, number, color )
2941+
# set the mode if required; faster than calling LedCtrlRawMode()
2942+
if mode is not None and mode > 17 and mode < 54:
2943+
self.midi.RawWrite( 147, number - 3*12, mode )
29242944

29252945

29262946
#-------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)