Audio/AudioControl: Add Metronome
[audiocontrol.git] / Joyboard.py
index be8af89..ef06b87 100644 (file)
@@ -118,11 +118,13 @@ class Controller(Views.View):
         self._parameter = None
         self._keylist = keylist
         self._keymap = Bindings.KeyMap()
-        self._keymap.add( Bindings.Binding(Events.Event(source.context(), 'p%d' % controller), '',
-                                           Actions.Command('controllerChanged',
-                                                           self._controllerChanged)) )
+        if source:
+            self._keymap.add( Bindings.Binding(Events.Event(source.context(), 'p%d' % controller), '',
+                                               Actions.Command('controllerChanged',
+                                                               self._controllerChanged)) )
         self._keylist.prepend(self._keymap)
-        source.registerController(controller, low, high)
+        if source:
+            source.registerController(controller, low, high)
         self._dispatcher = dispatcher
         self._min = None
         self._max = None
@@ -148,12 +150,16 @@ class Controller(Views.View):
         self._min = min
         self._max = max
         self._stops = stops
-        self._keymap.add( Bindings.Binding( self._valueEvent, '',
-                                            Actions.Command('updateValue',
-                                                            self._updateValue)) )
+        if self._valueEvent:
+            self._keymap.add( Bindings.Binding( self._valueEvent, '',
+                                                Actions.Command('updateValue',
+                                                                self._updateValue)) )
         self._keylist.prepend(self._keymap)
         self._value = None
-        self._valueCommand()
+        if self._valueEvent:
+            self._valueCommand()
+        else:
+            self._value = self._valueCommand()
         self._redraw()
 
     def _updateValue(self, binding):
@@ -166,16 +172,18 @@ class Controller(Views.View):
         Logger.log('ctl',"value = %d" % event.value)
         self._controlValue = event.value
         if self._controlValue >= 999 or self._controlValue <= 1:
-            self._dispatcher.setIdleCallback(self._changeValue,50)
+            self._dispatcher.setIdleCallback(self._changeValue,75)
+        elif self._controlValue >= 700 or self._controlValue <= 200:
+            self._dispatcher.setIdleCallback(self._changeValue,200)
         else:
             self._dispatcher.unsetIdleCallback()
         self._redrawController()
 
     def _changeValue(self):
         if self._value is None: return
-        if self._controlValue >= 999:
+        if self._controlValue > 500:
             self.stepValue(+1)
-        elif self._controlValue <= 1:
+        else:
             self.stepValue(-1)
 
     def stepValue(self, direction):
@@ -198,7 +206,11 @@ class Controller(Views.View):
             self._redrawValue()
         else:
             self._setCommand(newValue)
-            self._valueCommand()
+            if self._valueEvent:
+                self._valueCommand()
+            else:
+                self._value = self._valueCommand()
+                self._redrawValue()
 
     def _redraw(self):
         height, width = self.win().getmaxyx()
@@ -241,11 +253,11 @@ class Controller(Views.View):
 
     def _redrawController(self, refresh=True):
         height, width = self.win().getmaxyx()
-        if self._controlValue is not None and self._controlValue >= 999:
+        if self._controlValue is not None and self._controlValue >= 700:
             self.win().addch(3,3,curses.ACS_UARROW)
         else:
             self.win().addch(3,3,curses.ACS_TTEE)
-        if self._controlValue is not None and self._controlValue <= 1:
+        if self._controlValue is not None and self._controlValue <= 200:
             self.win().addch(height-3,3,curses.ACS_DARROW)
         else:
             self.win().addch(height-3,3,curses.ACS_BTEE)
@@ -279,8 +291,10 @@ def register( viewmanager,
               bits = None,
               controllers = []):
     viewmanager.registerView( View(context, label, numeric_switches, alpha_switches, x, y, dx, size) )
-    source = Source(device, context, bits)
-    dispatcher.registerSource( source )
+    source = None
+    if device is not None:
+        source = Source(device, context, bits)
+        dispatcher.registerSource( source )
     return source
 
 def registerController( viewmanager, dispatcher, keylist, source, context, name, x, y, dx, dy,