-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionNavigationComponent.py
120 lines (100 loc) · 4.43 KB
/
SessionNavigationComponent.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
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
# Embedded file name: /Applications/Ableton Live 9 Suite.app/Contents/App-Resources/MIDI Remote Scripts/Axiom_AIR_Mini32/SessionNavigationComponent.py
from _Framework.ControlSurface import ControlSurface
from _Framework.CompoundComponent import CompoundComponent
from _Framework.ScrollComponent import ScrollComponent
from _Framework import Task
### Added by Naenyn 2013-11-05
from Push.ViewControlComponent import TrackScroller, BasicSceneScroller
###
def is_recording_clip(tracks, check_arrangement):
found_recording_clip = False
for track in tracks:
if track.can_be_armed and track.arm:
if check_arrangement:
found_recording_clip = True
break
else:
playing_slot_index = track.playing_slot_index
if playing_slot_index in range(len(track.clip_slots)):
slot = track.clip_slots[playing_slot_index]
if slot.has_clip and slot.clip.is_recording:
found_recording_clip = True
break
return found_recording_clip
class ArmingTrackScrollComponent(ScrollComponent):
"""
ScrollComponent that arms the last visited MIDI track
"""
def __init__(self, parent, *a, **k):
super(ArmingTrackScrollComponent, self).__init__(*a, **k)
self._parent = parent
self._arming_task = self._tasks.add(Task.sequence(Task.delay(1), self._arm_task))
self._arming_task.kill()
def scroll_up(self):
super(ArmingTrackScrollComponent, self).scroll_up()
self._start_arming_task()
def scroll_down(self):
super(ArmingTrackScrollComponent, self).scroll_down()
self._start_arming_task()
def _start_arming_task(self):
if self._arming_task.is_killed:
self._arming_task.restart()
@property
def is_scrolling(self):
return not self._scroll_task_up.is_killed or not self._scroll_task_down.is_killed
def _track_to_arm(self):
track = self.song().view.selected_track
can_arm_track = track != None and track.has_midi_input and track.can_be_armed and not track.arm
return track if can_arm_track else None
def _try_arm(self):
track_to_arm = self._track_to_arm()
if track_to_arm != None:
song = self.song()
tracks = song.tracks
### Modified by Naenyn 2013-11-05
# if song.is_playing:
check_arrangement = song.record_mode
if is_recording_clip(tracks, check_arrangement) or song.exclusive_arm:
for track in tracks:
if track.can_be_armed and track != track_to_arm:
track.arm = False
track_to_arm.arm = True
track_to_arm.view.select_instrument()
###
return
def _arm_task(self, delta):
result_state = Task.KILLED
if self.is_enabled():
if self.is_scrolling:
result_state = Task.RUNNING
else:
self._try_arm()
return result_state
class SessionNavigationComponent(CompoundComponent):
"""
Component that controls the session selection 'crosshair'
"""
### Modified by Naenyn 2013-11-05
# Added support for self._parent.log_message()
def __init__(self, parent, *a, **k):
super(SessionNavigationComponent, self).__init__(*a, **k)
self._parent = parent
self._scroll_tracks, self._scroll_scenes = self.register_components(ArmingTrackScrollComponent(parent, TrackScroller()), ScrollComponent(BasicSceneScroller()))
###
song = self.song()
view = song.view
self.register_slot(song, self._scroll_tracks.update, 'visible_tracks')
self.register_slot(song, self._scroll_tracks.update, 'return_tracks')
self.register_slot(song, self._scroll_scenes.update, 'scenes')
self.register_slot(view, self._scroll_tracks.update, 'selected_track')
self.register_slot(view, self._scroll_scenes.update, 'selected_scene')
def set_next_track_button(self, button):
self._scroll_tracks.set_scroll_down_button(button)
def set_prev_track_button(self, button):
self._scroll_tracks.set_scroll_up_button(button)
def set_next_scene_button(self, button):
self._scroll_scenes.set_scroll_down_button(button)
def set_prev_scene_button(self, button):
self._scroll_scenes.set_scroll_up_button(button)
def update(self):
pass