Package _Framework :: Module ControlSurfaceComponent
[hide private]
[frames] | no frames]

Source Code for Module _Framework.ControlSurfaceComponent

  1  #Embedded file name: /Users/versonator/Hudson/live/Projects/AppLive/Resources/MIDI Remote Scripts/_Framework/ControlSurfaceComponent.py 
  2  import Live 
  3  from Dependency import dependency, depends 
  4  from SubjectSlot import SlotManager, Subject 
  5  from Util import lazy_attribute 
  6  import Task 
7 8 -class ControlSurfaceComponent(SlotManager, Subject):
9 """ 10 Base class for all classes encapsulating functions in Live 11 """ 12 name = '' 13 canonical_parent = None 14 is_private = False 15 _show_msg_callback = dependency(show_message=None) 16 _has_task_group = False 17 _layer = None 18 19 @depends(register_component=None, song=None)
20 - def __init__(self, name = '', register_component = None, song = None, *a, **k):
21 raise callable(register_component) or AssertionError 22 super(ControlSurfaceComponent, self).__init__(*a, **k) 23 self.name = name 24 self._is_enabled = True 25 self._explicit_is_enabled = True 26 self._recursive_is_enabled = True 27 self._allow_updates = True 28 self._update_requests = 0 29 self._song = song 30 register_component(self)
31
32 - def disconnect(self):
33 if self._has_task_group: 34 self._tasks.kill() 35 self._tasks.clear() 36 super(ControlSurfaceComponent, self).disconnect()
37
39 if self._layer: 40 if self.is_enabled(): 41 grabbed = self._layer.grab(self) 42 if not grabbed: 43 raise AssertionError, 'Only one component can use a layer at atime' 44 else: 45 self._layer.release(self) 46 if self._has_task_group: 47 self.is_enabled() and self._tasks.resume() 48 else: 49 self._tasks.pause()
50
51 - def on_enabled_changed(self):
52 self.update()
53
54 - def update(self):
55 raise NotImplementedError, self.__class__
56
57 - def update_all(self):
58 self.update()
59
60 - def set_enabled(self, enable):
61 self._explicit_is_enabled = bool(enable) 62 self._update_is_enabled()
63
64 - def _set_enabled_recursive(self, enable):
65 self._recursive_is_enabled = bool(enable) 66 self._update_is_enabled()
67
68 - def _update_is_enabled(self):
69 if self._recursive_is_enabled: 70 is_enabled = self._explicit_is_enabled 71 self._is_enabled = is_enabled != self._is_enabled and is_enabled 72 self._internal_on_enabled_changed() 73 self.on_enabled_changed()
74
75 - def set_allow_update(self, allow_updates):
76 allow = bool(allow_updates) 77 if self._allow_updates != allow: 78 self._allow_updates = allow 79 if self._allow_updates and self._update_requests > 0: 80 self._update_requests = 0 81 self.update()
82
83 - def application(self):
84 return Live.Application.get_application()
85
86 - def song(self):
87 return self._song
88 89 @lazy_attribute 90 @depends(parent_task_group=None)
91 - def _tasks(self, parent_task_group = None):
92 tasks = parent_task_group.add(Task.TaskGroup()) 93 if not self._is_enabled: 94 tasks.pause() 95 self._has_task_group = True 96 return tasks
97
98 - def _get_layer(self):
99 return self._layer
100
101 - def _set_layer(self, new_layer):
102 if self._layer != new_layer: 103 self._layer and self._layer.release(self) 104 self._layer = new_layer 105 if new_layer and self.is_enabled(): 106 grabbed = new_layer.grab(self) 107 if not grabbed: 108 raise AssertionError, 'Only one component can use a layer at atime'
109 110 layer = property(_get_layer, _set_layer) 111
112 - def is_enabled(self, explicit = False):
113 """ 114 Returns whether the component is enabled. 115 If 'explicit' is True the parent state is ignored. 116 """ 117 return self._is_enabled if not explicit else self._explicit_is_enabled
118
119 - def on_track_list_changed(self):
120 """ 121 Called by the control surface if tracks are added/removed, 122 to be overridden 123 """ 124 pass
125
126 - def on_scene_list_changed(self):
127 """ 128 Called by the control surface if scenes are added/removed, to 129 be overridden 130 """ 131 pass
132
134 """ 135 Called by the control surface when a track is selected, to be 136 overridden 137 """ 138 pass
139
141 """ 142 Called by the control surface when a scene is selected, to be 143 overridden 144 """ 145 pass
146 147 @depends(parent_task_group=None)
148 - def _register_timer_callback(self, callback, parent_task_group = None):
149 """ 150 DEPRECATED. Use tasks instead 151 """ 152 raise callable(callback) or AssertionError 153 raise parent_task_group.find(callback) is None or AssertionError 154 155 def wrapper(delta): 156 callback() 157 return Task.RUNNING
158 159 parent_task_group.add(Task.FuncTask(wrapper, callback))
160 161 @depends(parent_task_group=None)
162 - def _unregister_timer_callback(self, callback, parent_task_group = None):
163 """ 164 DEPRECATED. Use tasks instead 165 """ 166 raise callable(callback) or AssertionError 167 task = parent_task_group.find(callback) 168 raise task is not None or AssertionError 169 parent_task_group.remove(task)
170