-
Notifications
You must be signed in to change notification settings - Fork 0
/
drum_group_component.py
73 lines (56 loc) · 3.59 KB
/
drum_group_component.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
# Embedded file name: c:\Jenkins\live\output\win_64_static\Release\midi-remote-scripts\Push2\drum_group_component.py
from __future__ import absolute_import
from itertools import ifilter, izip
from ableton.v2.base import flatten, liveobj_valid
from pushbase.device_chain_utils import find_instrument_devices
from pushbase.drum_group_component import DrumGroupComponent as DrumGroupComponentBase, DrumPadCopyHandler as DrumPadCopyHandlerBase
from .decoration import find_decorated_object
from .device_decoration import SimplerDecoratedPropertiesCopier
def find_simplers(chain):
return ifilter(lambda i: hasattr(i, 'playback_mode'), find_instrument_devices(chain))
def find_all_simplers_on_pad(drum_pad):
simplers = []
for chain in drum_pad.chains:
simplers.append(find_simplers(chain))
return list(flatten(simplers))
class DrumPadCopyHandler(DrumPadCopyHandlerBase):
def __init__(self, decorator_factory = None, song = None, *a, **k):
super(DrumPadCopyHandler, self).__init__(*a, **k)
self._song = song
self._decorator_factory = decorator_factory
def _finish_copying(self, drum_group_device, destination_pad):
notification_reference = super(DrumPadCopyHandler, self)._finish_copying(drum_group_device, destination_pad)
if self._source_pad.note != destination_pad.note and len(destination_pad.chains) > 0:
source_simplers = find_all_simplers_on_pad(self._source_pad)
destination_simplers = find_all_simplers_on_pad(destination_pad)
for source, destination in izip(source_simplers, destination_simplers):
decorated = find_decorated_object(source, self._decorator_factory)
if decorated:
self._copy_simpler_properties(decorated, destination)
return notification_reference
def _copy_simpler_properties(self, source_simpler, destination_simpler):
copier = SimplerDecoratedPropertiesCopier(source_simpler, self._decorator_factory)
copier.apply_properties(destination_simpler, song=self._song)
class DrumGroupComponent(DrumGroupComponentBase):
def __init__(self, tracks_provider = None, device_decorator_factory = None, *a, **k):
raise tracks_provider is not None or AssertionError
self._decorator_factory = device_decorator_factory
super(DrumGroupComponent, self).__init__(*a, **k)
self.mute_button.color = 'DefaultButton.Transparent'
self.solo_button.color = 'DefaultButton.Transparent'
self._tracks_provider = tracks_provider
return
def select_drum_pad(self, drum_pad):
if len(drum_pad.chains) > 0 and self.song.view.selected_track.is_showing_chains:
self._tracks_provider.scroll_into_view(drum_pad.chains[0])
def _on_selected_drum_pad_changed(self):
super(DrumGroupComponent, self)._on_selected_drum_pad_changed()
chain = self._selected_drum_pad.chains[0] if self._selected_drum_pad and len(self._selected_drum_pad.chains) > 0 else None
if self.song.view.selected_track.is_showing_chains and liveobj_valid(chain):
self._tracks_provider.set_selected_item_without_updating_view(self._selected_drum_pad.chains[0])
return
def delete_drum_pad_content(self, drum_pad):
self._tracks_provider.synchronize_selection_with_live_view()
super(DrumGroupComponent, self).delete_drum_pad_content(drum_pad)
def _make_copy_handler(self, notification_formatter):
return DrumPadCopyHandler(show_notification=self.show_notification, notification_formatter=notification_formatter, decorator_factory=self._decorator_factory, song=self.song)