Allow extra arguments to NoteIndexList.filter's filter_fn
authorW. Trevor King <wking@drexel.edu>
Tue, 18 May 2010 16:35:22 +0000 (12:35 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 18 May 2010 16:35:22 +0000 (12:35 -0400)
hooke/playlist.py
hooke/plugin/playlist.py

index ca38b4e923936c77ff57f807564613a75cae0979..336c344d908d84827f89f44a30ad69b3197f7615 100644 (file)
@@ -62,10 +62,10 @@ class NoteIndexList (list):
     def previous(self):
         self.jump(self._index - 1)
 
-    def filter(self, keeper_fn=lambda item:True):
+    def filter(self, keeper_fn=lambda item:True, *args, **kwargs):
         c = copy.deepcopy(self)
         for item in reversed(c):
-            if keeper_fn(item) != True:
+            if keeper_fn(item, *args, **kwargs) != True:
                 c.remove(item)
         try: # attempt to maintain the same current item
             c._index = c.index(self.current())
index 01d24b77433af9351af16a2567838b340d463d08..21a641953475a90b72faeaf5d4deef847b515706 100644 (file)
@@ -274,7 +274,8 @@ class FilterCommand (Command):
             self.arguments.append(
                 Argument(name='filter', type='function', optional=False,
                          help="""
-Function returning `True` for "good" curves.  `filter(curve) -> True/False`.
+Function returning `True` for "good" curves.
+`filter(curve, hooke, inqueue, outqueue, params) -> True/False`.
 """.strip()))
 
     def _run(self, hooke, inqueue, outqueue, params):
@@ -282,7 +283,8 @@ Function returning `True` for "good" curves.  `filter(curve) -> True/False`.
             filter_fn = params['filter']
         else:
             filter_fn = self.filter_fn
-        p = params['playlist'].filter(filter_fn)
+        p = params['playlist'].filter(filter_fn,
+            hooke=hooke, inqueue=inqueue, outqueue=outqueue, params=params)
         hooke.playlists.add(p)
         outqueue.put(p)
 
@@ -292,5 +294,5 @@ class NoteFilterCommand (FilterCommand):
     def __init__(self, plugin):
         super(NoteFilterCommand, self).__init__(
             plugin, name='note filter playlist',
-            filter_fn=lambda curve : \
+            filter_fn=lambda curve, hooke, inqueue, outqueue, params : \
                 'note' in curve.info and curve.info['note'] != None)