Skip to content

Commit 03e67dc

Browse files
committed
Fixes in implementation of animations
1 parent d4deb01 commit 03e67dc

File tree

6 files changed

+63
-30
lines changed

6 files changed

+63
-30
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Utils to interface with [Ableton's Push 2](https://www.ableton.com/en/push/) fro
44

55
These utils follow Ableton's [Push 2 MIDI and Display Interface Manual](https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc) for comunicating with Push 2. I recommend reading Ableton's manual before using this tool.
66

7-
So far I only implemented some utils to **interface with the display** and some utils for **basic interaction with pads, buttons, encoders and the touchstrip**. More detailed interaction with each of these elements (e.g. changing color palettes, support for led blinking, advanced touchstrip configuration, etc.) has not been implemented. Contributions are welcome :)
8-
*EDIT*: customization of color palettes is now implemented!
7+
So far I only implemented some utils to **interface with the display** and some utils for **interaction with pads, buttons, encoders and the touchstrip**. More detailed interaction with each of these elements (e.g. changing color palettes, support for led blinking, advanced touchstrip configuration, etc.) has not been implemented. Contributions are welcome :)
8+
*EDIT*: customization of color palettes and led animations is now implemented!
99

1010
I only testd the package in **Python 3** and **macOS**. Some things will not work on Python 2 but it should be easy to port. I don't know how it will work on Windows/Linux. ~~It is possible that MIDI port names (see [push2_python/constants.py](https://github.com/ffont/push2-python/blob/master/push2_python/constants.py#L12-L13)) need to be changed to correctly reach Push2 in Windows/Linux~~. **UPDATE**: MIDI port names should now be cross-platform, but I have not tested them on Linux/Windows.
1111

@@ -156,6 +156,21 @@ All pads support RGB colors, and some buttons do as well. However, some buttons
156156
For a list of avilable RGB colors check the `DEFAULT_COLOR_PALETTE` dictionary in [push2_python/constants.py](https://github.com/ffont/push2-python/blob/master/push2_python/constants.py). First item of each color entry corresponds to the RGB color name while second item corresponds to the BW color name. The color palette can be customized using the `set_color_palette_entry`, `update_rgb_color_palette_entry` and `reapply_color_palette` of Push2 object. See the documentation of these methods for more details.
157157

158158

159+
### Set pad and button animations
160+
161+
Animations (e.g. led blinking) can be configured similarly to colors. To configiure an animation you need to define the *starting color* by sending a "set color" message with an animation code corresponding to "static", and then set the *second color* by sending another "set color" message with an animation code corresponding to the desired animation. For example, to condfigure the
162+
play button with a pulsing animation from white to green:
163+
164+
```python
165+
push.buttons.set_button_color(push2_python.constants.BUTTON_PLAY, 'white')
166+
push.buttons.set_button_color(push2_python.constants.BUTTON_PLAY, 'green', animation=push2_python.constants.ANIMATION_PULSING_QUARTER)
167+
```
168+
169+
By default, animations are synced to a clock of 120bpm. It is possible to change that tempo by sending MIDI clock messages to the Push2 device, but `push2-python` currently does not support that. Should be easy to implement though by sending MIDI clock messages using the `push.send_midi_to_push(msg)` method.
170+
171+
For a list of available animations, check the variables names `ANIMATION_*` dictionary in [push2_python/constants.py](https://github.com/ffont/push2-python/blob/master/push2_python/constants.py). Also, see the animations section of the [Push 2 MIDI and Display Interface Manual](https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#268-led-animation) for more information about animations.
172+
173+
159174
### Adjust pad sensitivity
160175

161176
`push2-python` implements methods to adjust Push2 pads sensitivity, in particualr it incorporates methods to adjust the velocity curve (which applies to

push2_python/buttons.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mido
2-
from .constants import ANIMATIONS, ANIMATIONS_DEFAULT, MIDO_CONTROLCHANGE, ACTION_BUTTON_PRESSED, ACTION_BUTTON_RELEASED
2+
from .constants import ANIMATION_DEFAULT, MIDO_CONTROLCHANGE, ACTION_BUTTON_PRESSED, ACTION_BUTTON_RELEASED
33
from .classes import AbstractPush2Section
44

55

@@ -33,11 +33,13 @@ def button_name_to_button_n(self, button_name):
3333
"""
3434
return self.button_names_index.get(button_name, None)
3535

36-
def set_button_color(self, button_name, color='white', animation='static'):
36+
def set_button_color(self, button_name, color='white', animation=ANIMATION_DEFAULT):
3737
"""Sets the color of the button with given name.
3838
'color' must be a valid RGB or BW color name present in the color palette. See push2_python.constants.DEFAULT_COLOR_PALETTE for default color names.
3939
If the button only acceps BW colors, the color name will be matched against the BW palette, otherwise it will be matched against RGB palette.
40-
'animation' must be an existing key of push2_python.contants.ANIMATIONS dictionary.
40+
'animation' must be a valid animation name from those defined in push2_python.contants.ANIMATION_*. Note that to configure an animation, both the 'start' and 'end'
41+
colors of the animation need to be defined. The 'start' color is defined by setting a color with 'push2_python.contants.ANIMATION_STATIC' (the default).
42+
The second color is set setting a color with whatever ANIMATION_* type is desired.
4143
See https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#setting-led-colors
4244
"""
4345
button_n = self.button_name_to_button_n(button_name)
@@ -47,15 +49,16 @@ def set_button_color(self, button_name, color='white', animation='static'):
4749
color_idx = self.push.get_rgb_color(color)
4850
else:
4951
color_idx = self.push.get_bw_color(color)
50-
animation = ANIMATIONS.get(animation, ANIMATIONS_DEFAULT)
5152
msg = mido.Message(MIDO_CONTROLCHANGE, control=button_n, value=color_idx, channel=animation)
5253
self.push.send_midi_to_push(msg)
5354

54-
def set_all_buttons_color(self, color='white', animation='static'):
55+
def set_all_buttons_color(self, color='white', animation=ANIMATION_DEFAULT):
5556
"""Sets the color of all buttons in Push2 to the given color.
5657
'color' must be a valid RGB or BW color name present in the color palette. See push2_python.constants.DEFAULT_COLOR_PALETTE for default color names.
5758
If the button only acceps BW colors, the color name will be matched against the BW palette, otherwise it will be matched against RGB palette.
58-
'animation' must be an existing key of push2_python.contants.ANIMATIONS dictionary.
59+
'animation' must be a valid animation name from those defined in push2_python.contants.ANIMATION_*. Note that to configure an animation, both the 'start' and 'end'
60+
colors of the animation need to be defined. The 'start' color is defined by setting a color with 'push2_python.contants.ANIMATION_STATIC' (the default).
61+
The second color is set setting a color with whatever ANIMATION_* type is desired.
5962
See https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#setting-led-colors
6063
"""
6164
for button_name in self.available_names:

push2_python/constants.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,23 @@ def is_push_midi_out_port_name(port_name, use_user_port=False):
117117
# Because push2-python does not send MIDI clock messages to push, all animations will run synced to a 120bpm tempo
118118
# See https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#268-led-animation
119119
# for more info on what animation names mean
120-
ANIMATIONS = {
121-
'static': 1,
122-
'pulsing_slow': 10,
123-
'pulsing': 9,
124-
'pulsing_fast': 8,
125-
'blinking_slow': 15,
126-
'blinking': 14,
127-
'blinking_fast': 13
128-
}
129-
ANIMATIONS_DEFAULT = 1
120+
ANIMATION_STATIC = 0
121+
ANIMATION_ONESHOT_24TH = 1
122+
ANIMATION_ONESHOT_16TH = 2
123+
ANIMATION_ONESHOT_8TH = 3
124+
ANIMATION_ONESHOT_QUARTER = 4
125+
ANIMATION_ONESHOT_HALF = 5
126+
ANIMATION_PULSING_24TH = 6
127+
ANIMATION_PULSING_16TH = 7
128+
ANIMATION_PULSING_8TH = 8
129+
ANIMATION_PULSING_QUARTER = 9
130+
ANIMATION_PULSING_HALF = 10
131+
ANIMATION_BLINKING_24TH = 11
132+
ANIMATION_BLINKING_16TH = 12
133+
ANIMATION_BLINKING_8TH = 13
134+
ANIMATION_BLINKING_QUARTER = 14
135+
ANIMATION_BLINKING_HALF = 15
136+
ANIMATION_DEFAULT = ANIMATION_STATIC
130137

131138
# Push2 actions
132139
ACTION_PAD_PRESSED = 'on_pad_pressed'

push2_python/encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mido
2-
from .constants import ANIMATIONS, ANIMATIONS_DEFAULT, MIDO_CONTROLCHANGE, \
2+
from .constants import ANIMATION_DEFAULT, MIDO_CONTROLCHANGE, \
33
MIDO_NOTEON, MIDO_NOTEOFF, ACTION_ENCODER_ROTATED, ACTION_ENCODER_TOUCHED, ACTION_ENCODER_RELEASED
44
from .classes import AbstractPush2Section
55

push2_python/pads.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mido
2-
from .constants import ANIMATIONS, ANIMATIONS_DEFAULT, MIDO_NOTEON, MIDO_NOTEOFF, \
2+
from .constants import ANIMATION_DEFAULT, MIDO_NOTEON, MIDO_NOTEOFF, \
33
MIDO_POLYAT, MIDO_AFTERTOUCH, ACTION_PAD_PRESSED, ACTION_PAD_RELEASED, ACTION_PAD_AFTERTOUCH, PUSH2_SYSEX_PREFACE_BYTES, \
44
PUSH2_SYSEX_END_BYTES
55
from .classes import AbstractPush2Section
@@ -97,18 +97,20 @@ def pad_ij_to_pad_n(self, i, j):
9797
def pad_n_to_pad_ij(self, n):
9898
return pad_n_to_pad_ij(n)
9999

100-
def set_pad_color(self, pad_ij, color='white', animation='static', optimize_num_messages=True):
100+
def set_pad_color(self, pad_ij, color='white', animation=ANIMATION_DEFAULT, optimize_num_messages=True):
101101
"""Sets the color of the pad at the (i,j) coordinate.
102102
'color' must be a valid RGB color name present in the color palette. See push2_python.constants.DEFAULT_COLOR_PALETTE for default color names.
103-
'animation' must be an existing key of push2_python.contants.ANIMATIONS dictionary.
103+
'animation' must be a valid animation name from those defined in push2_python.contants.ANIMATION_*. Note that to configure an animation, both the 'start' and 'end'
104+
colors of the animation need to be defined. The 'start' color is defined by setting a color with 'push2_python.contants.ANIMATION_STATIC' (the default).
105+
The second color is set setting a color with whatever ANIMATION_* type is desired.
106+
104107
This funtion will keep track of the latest color/animation values set for each specific pad. If 'optimize_num_messages' is
105108
set to True, set_pad_color will only actually send the MIDI message to push if either the color or animation that should
106109
be set differ from those stored in the state.
107110
See https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#261-setting-led-colors
108111
"""
109112
pad = self.pad_ij_to_pad_n(pad_ij[0], pad_ij[1])
110113
color = self.push.get_rgb_color(color)
111-
animation = ANIMATIONS.get(animation, ANIMATIONS_DEFAULT)
112114
if optimize_num_messages and pad in self.current_pads_state and self.current_pads_state[pad]['color'] == color and self.current_pads_state[pad]['animation'] == animation:
113115
# If pad's recorded state already has the specified color and animation, return method before sending the MIDI message
114116
return
@@ -130,29 +132,35 @@ def set_pads_color(self, color_matrix, animation_matrix=None):
130132
if animation_matrix is not None:
131133
assert len(animation_matrix[i]) == 8, 'Wrong number of animation values in line ({0})'.format(len(animation_matrix[i]))
132134
for j, color in enumerate(line):
133-
animation = None
135+
animation = ANIMATION_DEFAULT
134136
if animation_matrix is not None:
135137
animation = animation_matrix[i][j]
136138
self.set_pad_color((i, j), color=color, animation=animation)
137139

138-
def set_all_pads_to_color(self, color='white', animation='static'):
140+
def set_all_pads_to_color(self, color='white', animation=ANIMATION_DEFAULT):
139141
"""Set all pads to the given color/animation.
140142
'color' must be a valid RGB color name present in the color palette. See push2_python.constants.DEFAULT_COLOR_PALETTE for default color names.
143+
'animation' must be a valid animation name from those defined in push2_python.contants.ANIMATION_*. Note that to configure an animation, both the 'start' and 'end'
144+
colors of the animation need to be defined. The 'start' color is defined by setting a color with 'push2_python.contants.ANIMATION_STATIC' (the default).
145+
The second color is set setting a color with whatever ANIMATION_* type is desired.
141146
"""
142147
color_matrix = [[color for _ in range(0, 8)] for _ in range(0, 8)]
143148
animation_matrix = [[animation for _ in range(0, 8)] for _ in range(0, 8)]
144149
self.set_pads_color(color_matrix, animation_matrix)
145150

146-
def set_all_pads_to_white(self, animation='static'):
151+
def set_all_pads_to_black(self, animation=ANIMATION_DEFAULT):
152+
self.set_all_pads_to_color('black', animation=animation)
153+
154+
def set_all_pads_to_white(self, animation=ANIMATION_DEFAULT):
147155
self.set_all_pads_to_color('white', animation=animation)
148156

149-
def set_all_pads_to_red(self, animation='static'):
157+
def set_all_pads_to_red(self, animation=ANIMATION_DEFAULT):
150158
self.set_all_pads_to_color('red', animation=animation)
151159

152-
def set_all_pads_to_green(self, animation='static'):
160+
def set_all_pads_to_green(self, animation=ANIMATION_DEFAULT):
153161
self.set_all_pads_to_color('green', animation=animation)
154162

155-
def set_all_pads_to_blue(self, animation='static'):
163+
def set_all_pads_to_blue(self, animation=ANIMATION_DEFAULT):
156164
self.set_all_pads_to_color('blue', animation=animation)
157165

158166
def on_midi_message(self, message):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33
setup(name='push2-python',
4-
version='0.2',
4+
version='0.3',
55
description='Utils to interface with Ableton\'s Push 2 from Python',
66
url='https://github.com/ffont/push2-python',
77
author='Frederic Font',

0 commit comments

Comments
 (0)