-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_parameter_bank_with_options.py
43 lines (34 loc) · 1.8 KB
/
device_parameter_bank_with_options.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
# Embedded file name: c:\Jenkins\live\output\win_64_static\Release\midi-remote-scripts\Push2\device_parameter_bank_with_options.py
from __future__ import absolute_import
from ableton.v2.base import listenable_property, liveobj_valid, find_if
from .custom_bank_definitions import OPTIONS_KEY, SHOW_WAVEFORM_KEY
from .device_parameter_bank import create_device_bank, DescribedDeviceParameterBank
OPTIONS_PER_BANK = 7
class DescribedDeviceParameterBankWithOptions(DescribedDeviceParameterBank):
_options = []
@listenable_property
def options(self):
return self._options
@property
def wants_waveform_shown(self):
bank = self._definition.value_by_index(self.index)
return bool(bank.get(SHOW_WAVEFORM_KEY))
def _current_option_slots(self):
bank = self._definition.value_by_index(self.index)
return bank.get(OPTIONS_KEY) or ('',) * OPTIONS_PER_BANK
def _content_slots(self):
return self._current_option_slots() + super(DescribedDeviceParameterBankWithOptions, self)._content_slots()
def _collect_options(self):
option_slots = self._current_option_slots()
options = getattr(self._device, 'options', [])
return [ find_if(lambda o: o.name == str(slot_definition), options) for slot_definition in option_slots ]
def _update_parameters(self):
super(DescribedDeviceParameterBankWithOptions, self)._update_parameters()
self._options = self._collect_options()
self.notify_options()
def create_device_bank_with_options(device, banking_info):
if liveobj_valid(device) and banking_info.device_bank_definition(device) is not None:
bank = DescribedDeviceParameterBankWithOptions(device=device, size=8, banking_info=banking_info)
else:
bank = create_device_bank(device, banking_info)
return bank