Don't load curves becore clearing their command stack.
authorW. Trevor King <wking@drexel.edu>
Fri, 27 Aug 2010 22:44:01 +0000 (18:44 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 27 Aug 2010 22:44:01 +0000 (18:44 -0400)
Loading a curve (which would happen if it had been unloaded before
being summoned by current_curve_callback) executes its command stack.
Since 'clear curve command stack' is only trying to remove the stack,
that stack execution is a waste of time.  With the unloaded callback,
we can remove the command stack without ever loading the curve.

hooke/playlist.py
hooke/plugin/curve.py

index 80d60fb462f78ceff0cdf419a5e3a5751e78bcce..79f785c5305b35415af5651da7e4f2d25ae0b86c 100644 (file)
@@ -91,11 +91,12 @@ class NoteIndexList (list):
             return self._index
         return super(NoteIndexList, self).index(value, *args, **kwargs)
 
-    def current(self):
+    def current(self, load=True):
         if len(self) == 0:
             return None
         item = self[self._index]
-        self._setup_item(item)
+        if load == True:
+            self._setup_item(item)
         return item
 
     def jump(self, index):
index 931dca3e69ef6e033da4d034ea28467c32263ec2..d51ddfdef1681851bb0e4fbcaffb688054af4699 100644 (file)
@@ -41,15 +41,20 @@ from .playlist import current_playlist_callback
 
 # Define common or complicated arguments
 
-def current_curve_callback(hooke, command, argument, value):
+def current_curve_callback(hooke, command, argument, value, load=True):
     if value != None:
         return value
     playlist = current_playlist_callback(hooke, command, argument, value)
-    curve = playlist.current()
+    curve = playlist.current(load=load)
     if curve == None:
         raise Failure('No curves in %s' % playlist)
     return curve
 
+def unloaded_current_curve_callback(hooke, command, argument, value):
+    return current_curve_callback(
+        hooke=hooke, command=command, argument=argument, value=value,
+        load=False)
+
 CurveArgument = Argument(
     name='curve', type='curve', callback=current_curve_callback,
     help="""
@@ -634,6 +639,11 @@ class ClearStackCommand (CurveCommand):
         super(ClearStackCommand, self).__init__(
             name='clear curve command stack',
             help=self.__doc__, plugin=plugin)
+        i,arg = [(i,arg) for i,arg in enumerate(self.arguments)
+                 if arg.name == 'curve'][0]
+        arg = copy.copy(arg)
+        arg.callback = unloaded_current_curve_callback
+        self.arguments[i] = arg
 
     def _run(self, hooke, inqueue, outqueue, params):
         curve = self._curve(hooke, params)