-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.py
62 lines (49 loc) · 1.92 KB
/
transport.py
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
56
57
58
59
60
61
62
import Live
import typing
from ableton.v3.control_surface.components import (
TransportComponent as TransportComponentBase,
)
from ableton.v3.control_surface.controls import ButtonControl
TEMPO_MIN = 20.0
TEMPO_MAX = 999.0
# Ignore triplet quantizations.
IGNORED_QUANTIZATIONS = [
Live.Song.Quantization.q_half_triplet,
Live.Song.Quantization.q_quarter_triplet,
Live.Song.Quantization.q_eight_triplet,
Live.Song.Quantization.q_sixtenth_triplet,
]
class TransportComponent(TransportComponentBase):
tempo_up_button: typing.Any = ButtonControl(
color="DefaultButton.Off", pressed_color="DefaultButton.On"
)
tempo_down_button: typing.Any = ButtonControl(
color="DefaultButton.Off", pressed_color="DefaultButton.On"
)
clip_trigger_quantization_button: typing.Any = ButtonControl(
color="DefaultButton.Off", pressed_color="DefaultButton.On"
)
@tempo_up_button.pressed
def tempo_up_button(self, _):
self._adjust_tempo(1)
@tempo_down_button.pressed
def tempo_down_button(self, _):
self._adjust_tempo(-1)
@clip_trigger_quantization_button.pressed
def clip_trigger_quantization_button(self, _):
assert self.song
self.song.clip_trigger_quantization = self._get_next_clip_trigger_quantization(
self.song.clip_trigger_quantization
)
def _adjust_tempo(self, amount):
assert self.song
self.song.tempo = max(TEMPO_MIN, min(TEMPO_MAX, self.song.tempo + amount))
def _get_next_clip_trigger_quantization(self, start):
new_index = int(start) + 1
if new_index not in Live.Song.Quantization.values:
new_index = 0
result = Live.Song.Quantization.values[new_index]
# Skip to the next value if the result is in the blacklist.
if result in IGNORED_QUANTIZATIONS:
result = self._get_next_clip_trigger_quantization(result)
return result