-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixer.py
75 lines (57 loc) · 2.19 KB
/
mixer.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import typing
from ableton.v3.base import depends
from ableton.v3.control_surface.components import (
MixerComponent as MixerComponentBase,
)
from ableton.v3.control_surface.components import (
Scrollable,
ScrollComponent,
SendIndexManager,
)
class SendIndexScrollable(Scrollable):
def __init__(self, send_index_manager: SendIndexManager):
super().__init__()
self._send_index_manager = send_index_manager
def can_scroll_up(self):
return self._can_scroll(-1)
def can_scroll_down(self):
return self._can_scroll(1)
def scroll_up(self):
self._do_scroll(-1)
def scroll_down(self):
self._do_scroll(1)
def _can_scroll(self, delta):
num_sends = self._send_index_manager.num_sends
current_index = self._send_index_manager.send_index
def is_in_range(index):
return index >= 0 and index < num_sends
# Always allow scrolling if we're out of bounds, e.g. if sends
# were removed.
if not is_in_range(current_index):
return True
target_index = current_index + delta
return is_in_range(target_index)
def _do_scroll(self, delta):
self._send_index_manager.send_index = (
self._send_index_manager.send_index + delta
)
class MixerComponent(MixerComponentBase):
@depends(show_message=None)
def __init__(
self, *a, show_message: typing.Optional[typing.Callable[[str], typing.Any]], **k
):
super().__init__(*a, **k)
assert show_message
self._show_message = show_message
send_index_scrollable = SendIndexScrollable(self._send_index_manager)
self._send_index_scroll = ScrollComponent(
parent=self, scrollable=send_index_scrollable
)
def set_selected_track_arm_button(self, button):
self._target_strip.arm_button.set_control_element(button)
self._target_strip.update()
def set_send_index_encoder(self, encoder):
self._send_index_scroll.scroll_encoder.set_control_element(encoder)
def _on_send_index_changed(self):
self._show_message(f"Controlling Send {self.send_index+ 1}")
return super()._on_send_index_changed()