-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEncoderDeviceComponent.py
More file actions
executable file
·147 lines (119 loc) · 5.47 KB
/
EncoderDeviceComponent.py
File metadata and controls
executable file
·147 lines (119 loc) · 5.47 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# http://remotescripts.blogspot.com
"""
Customized APC40 control surface script
Copyright (C) 2010 Hanz Petrov <hanz.petrov@gmail.com>
Additional modification for Ableton Live 9 - Fabrizio Poce 2013 - <http://www.fabriziopoce.com/>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# emacs-mode: -*- python-*-
import Live
from _Framework.ControlSurfaceComponent import ControlSurfaceComponent
from _Framework.ButtonElement import ButtonElement
from _Framework.EncoderElement import EncoderElement
from _Framework.MixerComponent import MixerComponent
from _Framework.DeviceComponent import DeviceComponent
class EncoderDeviceComponent(ControlSurfaceComponent):
__module__ = __name__
__doc__ = " Class representing encoder Device component "
def __init__(self, mixer, device, parent):
ControlSurfaceComponent.__init__(self)
assert isinstance(mixer, MixerComponent)
self._param_controls = None
self._mixer = mixer
self._buttons = []
self._lock_button = None
self._last_mode = 0
self._is_locked = False
self._ignore_buttons = False
self._track = None
self._strip = None
self._parent = parent
self._device = device
self._alt_device = DeviceComponent()
self._alt_device.name = 'Alt_Device_Component'
self.song().add_appointed_device_listener(self._on_device_changed)
def disconnect(self):
self.song().remove_appointed_device_listener(self._on_device_changed)
self._param_controls = None
self._mixer = None
self._buttons = None
self._lock_button = None
self._track = None
self._strip = None
self._parent = None
self._device = None
self._alt_device = None
def update(self):
pass
#self._show_msg_callback("EncoderDeviceComponent update called")
def set_controls_and_buttons(self, controls, buttons):
assert ((controls == None) or (isinstance(controls, tuple) and (len(controls) == 8)))
self._param_controls = controls
assert ((buttons == None) or (isinstance(buttons, tuple)) or (len(buttons) == 4))
self._buttons = buttons
self.set_lock_button(self._buttons[0])
if self._is_locked == True:
self._alt_device.set_parameter_controls(self._param_controls)
self._alt_device.set_bank_nav_buttons(self._buttons[2], self._buttons[3])
self._alt_device.set_on_off_button(self._buttons[1])
else:
self.on_selected_track_changed()
def _on_device_changed(self):
if self.is_enabled():
if self._is_locked != True:
selected_device= self.song().appointed_device
self._alt_device.set_device(selected_device)
self._setup_controls_and_buttons()
def on_selected_track_changed(self):
if self.is_enabled():
if self._is_locked != True:
track = self.song().view.selected_track
selected_device = track.view.selected_device
self._alt_device.set_device(selected_device)
self._setup_controls_and_buttons()
def _setup_controls_and_buttons(self):
if self._buttons != None and self._param_controls != None:
if self._alt_device != None:
self._alt_device.set_parameter_controls(self._param_controls)
self._alt_device.set_bank_nav_buttons(self._buttons[2], self._buttons[3])
self._alt_device.set_on_off_button(self._buttons[1])
self._alt_device._on_on_off_changed()
#self._rebuild_callback()
def on_enabled_changed(self):
self.update()
def set_lock_button(self, button):
assert ((button == None) or isinstance(button, ButtonElement))
if (self._lock_button != None):
self._lock_button.remove_value_listener(self._lock_value)
self._lock_button = None
self._lock_button = button
if (self._lock_button != None):
self._lock_button.add_value_listener(self._lock_value)
if self._is_locked:
self._lock_button.turn_on()
else:
self._lock_button.turn_off()
def _lock_value(self, value):
assert (self._lock_button != None)
assert (value != None)
assert isinstance(value, int)
if ((not self._lock_button.is_momentary()) or (value is not 0)):
if self._ignore_buttons == False:
if self._is_locked:
self._is_locked = False
self._lock_button.turn_off()
self.on_selected_track_changed()
else:
self._is_locked = True
self._lock_button.turn_on()
# local variables:
# tab-width: 4