Close parenthesis on column append in DifferenceCommand
[hooke.git] / hooke / plugin / playlist.py
index 980123cd39482ffac9f52e7a65563b26f5c13a53..9f0d9e15674abdd79c21a3587ebae183aa18b18e 100644 (file)
@@ -2,15 +2,15 @@
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-# Hooke is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with Hooke.  If not, see
@@ -22,6 +22,7 @@ several associated :class:`hooke.command.Command`\s for handling
 """
 
 import glob
+import os.path
 
 from ..command import Command, Argument, Failure
 from ..playlist import FilePlaylist
@@ -33,7 +34,7 @@ class PlaylistPlugin (Builtin):
         super(PlaylistPlugin, self).__init__(name='playlist')
         self._commands = [
             NextCommand(self), PreviousCommand(self), JumpCommand(self),
-            IndexCommand(self), CurveListCommand(self),
+            GetCommand(self), IndexCommand(self), CurveListCommand(self),
             SaveCommand(self), LoadCommand(self),
             AddCommand(self), AddGlobCommand(self),
             RemoveCommand(self), FilterCommand(self), NoteFilterCommand(self)]
@@ -57,6 +58,8 @@ playlist.
 """.strip())
 
 def playlist_name_callback(hooke, command, argument, value):
+    if value != None:
+        return value
     i = 0
     names = [p.name for p in hooke.playlists]
     while True:
@@ -132,7 +135,19 @@ class IndexCommand (Command):
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-       outqueue.put(params['playlist']._index)
+       outqueue.put(params['playlist'].index())
+
+class GetCommand (Command):
+    """Return a :class:`hooke.playlist.Playlist`.
+    """
+    def __init__(self, plugin):
+        super(GetCommand, self).__init__(
+            name='get playlist',
+            arguments=[PlaylistArgument],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        outqueue.put(params['playlist'])
 
 class CurveListCommand (Command):
     """Get the curves in a playlist.
@@ -140,13 +155,11 @@ class CurveListCommand (Command):
     def __init__(self, plugin):
         super(CurveListCommand, self).__init__(
             name='playlist curves',
-            arguments=[
-                PlaylistArgument,
-                ],
+            arguments=[PlaylistArgument],
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-       outqueue.put([c for c in params['playlist']])
+       outqueue.put(list(params['playlist']))
 
 class SaveCommand (Command):
     """Save a playlist.
@@ -159,7 +172,8 @@ class SaveCommand (Command):
                 Argument(name='output', type='file',
                          help="""
 File name for the output playlist.  Defaults to overwriting the input
-playlist.
+playlist.  If the playlist does not have an input file (e.g. it was
+created from scratch with 'new playlist'), this option is required.
 """.strip()),
                 ],
             help=self.__doc__, plugin=plugin)
@@ -227,7 +241,7 @@ class AddGlobCommand (Command):
             name='glob curves to playlist',
             arguments=[
                 PlaylistArgument,
-                Argument(name='input', type='glob', optional=False,
+                Argument(name='input', type='string', optional=False,
                          help="""
 File name glob for the input :class:`hooke.curve.Curve`.
 """.strip()),
@@ -258,7 +272,7 @@ Index of target curve.
 
     def _run(self, hooke, inqueue, outqueue, params):
         params['playlist'].pop(params['index'])
-        params['playlist'].jump(params._index)
+        params['playlist'].jump(params.index())
 
 class FilterCommand (Command):
     """Create a subset playlist via a selection function.
@@ -300,7 +314,10 @@ Function returning `True` for "good" curves.
             filter_fn = self.filter
         p = params['playlist'].filter(filter_fn,
             hooke=hooke, inqueue=inqueue, outqueue=outqueue, params=params)
-        hooke.playlists.add(p)
+        p.name = params['name']
+        if hasattr(p, 'path') and p.path != None:
+            p.set_path(os.path.join(os.path.dirname(p.path), p.name))
+        hooke.playlists.append(p)
         outqueue.put(p)
 
 class NoteFilterCommand (FilterCommand):