Skip to content

Commit f2eeb20

Browse files
committed
Add methods to adjust pads sensitivity
1 parent 3601fe1 commit f2eeb20

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,13 @@ to each pad as defined in [Push 2 MIDI and Display Interface Manual](https://git
140140
Pad and button colors can be set using methods provided by the `Push2` object. For example you can set pad colors using the following code:
141141

142142
```python
143-
push = push2_python.Push2()
144143
pad_ij = (0, 3) # Fourth pad of the top row
145144
push.pads.set_pad_color(pad_ij, 'green')
146145
```
147146

148147
You set button colors in a similar way:
149148

150149
```python
151-
push = push2_python.Push2()
152150
push.buttons.set_button_color(push2_python.constants.BUTTON_PLAY, 'green')
153151
```
154152

@@ -158,6 +156,18 @@ All pads support RGB colors, and some buttons do as well. However, some buttons
158156
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.
159157

160158

159+
### Adjust pad sensitivity
160+
161+
`push2-python` implements methods to adjust Push2 pads sensitivity, in particualr it incorporates methods to adjust the velocity curve (which applies to
162+
note on velocities and to poolyphonic aftertouch sensistivity), and the channel aftertouch range. You can do that using the methods `set_channel_aftertouch_range`
163+
and `set_velocity_curve` from the `pads` section. Below are two examples of adjusting sensitivity. Please check methods' documentation for more information.
164+
165+
```python
166+
push.pads.set_channel_aftertouch_range(range_start=401, range_end=800) # Configure channel after touch to be quite sensitive
167+
push.pads.set_velocity_curve(velocities=[int(i * 127/40) if i < 40 else 127 for i in range(0,128)]) # Map full velocity range to the first 40 pressure values
168+
```
169+
170+
161171
### Interface with the display
162172

163173
You interface with Push2's display by senidng frames to be display using the `push.display.display_frame` method as follows:

push2_python/pads.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@ def set_channel_aftertouch(self):
6161
msg = mido.Message.from_bytes(PUSH2_SYSEX_PREFACE_BYTES + [0x1E, 0x00] + PUSH2_SYSEX_END_BYTES)
6262
self.push.send_midi_to_push(msg)
6363

64+
65+
def set_channel_aftertouch_range(self, range_start=401, range_end=2048):
66+
"""Configures the sensitivity of channel aftertouch by defining at what "range start" pressure value the aftertouch messages
67+
start to be triggered and what "range end" pressure value corresponds to the aftertouch value 127. I'm not sure about the meaning
68+
of the pressure values, but according to the documentation must be between 400 and 2048.
69+
See https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#282-pad-parameters
70+
"""
71+
assert type(range_start) == int and type(range_end) == int, "range_start and range_end must be int"
72+
assert range_start < range_end, "range_start must be lower than range_end"
73+
assert 400 < range_start < range_end, "wrong range_start value, must be in range [401, range_end]"
74+
assert range_start < range_end <= 2048, "wrong range_end value, must be in range [range_start + 1, 2048]"
75+
lower_range_bytes = [range_start % 2**7, range_start // 2**7]
76+
upper_range_bytes = [range_end % 2**7, range_end // 2**7]
77+
msg = mido.Message.from_bytes(PUSH2_SYSEX_PREFACE_BYTES + [0x1B, 0x00, 0x00, 0x00, 0x00] + lower_range_bytes + upper_range_bytes + PUSH2_SYSEX_END_BYTES)
78+
self.push.send_midi_to_push(msg)
79+
80+
81+
def set_velocity_curve(self, velocities):
82+
"""Configures Push pad's velocity curve which will determine i) the velocity values triggered when pressing pads; and ii) the
83+
sensitivity of the aftertouch when in polyphonic aftertouch mode. Push uses a map of physical pressure values [0g..4095g]
84+
to MIDI velocity values [0..127]. This map is quantized into 128 steps which Push then interpolates. This method expects a list of
85+
128 velocity values which will be assigned to each of the 128 quantized steps of the physical pressure range [0g..4095g].
86+
See hhttps://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#281-velocity-curve
87+
"""
88+
assert type(velocities) == list and len(velocities) == 128 and type(velocities[0] == int), "velocities must be a list with 128 int values"
89+
for start_index in range(0, 128, 16):
90+
msg = mido.Message.from_bytes(PUSH2_SYSEX_PREFACE_BYTES + [0x20] + [start_index] + velocities[start_index:start_index + 16] + PUSH2_SYSEX_END_BYTES)
91+
self.push.send_midi_to_push(msg)
92+
93+
6494
def pad_ij_to_pad_n(self, i, j):
6595
return pad_ij_to_pad_n(i, j)
6696

0 commit comments

Comments
 (0)