-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunchpad_wrapper.py
More file actions
56 lines (44 loc) · 1.83 KB
/
Copy pathlaunchpad_wrapper.py
File metadata and controls
56 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import launchpad_py as launchpad
from typing import Callable
class LaunchpadWrapper:
lp: launchpad.Launchpad
button_press_callbacks: list[list[int, int, Callable]] = []
button_release_callbacks: list[list[int, int, Callable]] = []
def __init__(self, launchpad_instance) -> None:
self.lp = launchpad_instance
def update(self):
button = self.lp.ButtonStateXY()
if len(button) == 0:
return
if button[2] > 10:
for [x, y, callback] in self.button_press_callbacks:
if button[0] == x and button[1] == y or (x == None and y == None):
callback()
else:
for [x, y, callback] in self.button_release_callbacks:
if (button[0] == x and button[1] == y) or (x == None and y == None):
callback()
def add_button_press_callback(self, x: int, y: int, callback: Callable):
self.button_press_callbacks.append([x, y, callback])
def add_button_release_callback(self, x: int, y: int, callback: Callable):
self.button_release_callbacks.append([x, y, callback])
def on_button_press(self, x: int, y: int):
def decorator(func):
self.add_button_press_callback(x, y, func)
return func
return decorator
# def on_button_press(self):
# def decorator(func):
# self.add_button_press_callback(None, None, func)
# return func
# return decorator
def on_button_release(self, x: int, y: int):
def decorator(func):
self.add_button_release_callback(x, y, func)
return func
return decorator
# def on_button_release(self):
# def decorator(func):
# self.add_button_release_callback(None, None, func)
# return func
# return decorator