-"""Defines :class:`PlaylistPlugin` several associated
-:class:`hooke.plugin.Command`\s for handling :mod:`hooke.playlist`
-classes.
+# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+#
+# 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 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
+# <http://www.gnu.org/licenses/>.
+
+"""The `playlist` module provides :class:`PlaylistPlugin` several
+associated :class:`hooke.command.Command`\s for handling
+:mod:`hooke.playlist` classes.
"""
import glob
def commands(self):
return [NextCommand(), PreviousCommand(), JumpCommand(),
+ IndexCommand(), CurveListCommand(),
SaveCommand(), LoadCommand(),
AddCommand(), AddGlobCommand(),
- RemoveCommand(), FilterCommand()]
+ RemoveCommand(), FilterCommand(), NoteFilterCommand()]
# Define common or complicated arguments
def current_playlist_callback(hooke, command, argument, value):
+ if value != None:
+ return value
playlist = hooke.playlists.current()
if playlist == None:
raise Failure('No playlists loaded')
Name of the new playlist (defaults to an auto-generated name).
""".strip())
+def all_drivers_callback(hooke, command, argument, value):
+ return hooke.drivers
+
# Define commands
def _run(self, hooke, inqueue, outqueue, params):
params['playlist'].jump(params['index'])
+class IndexCommand (Command):
+ """Print the index of the current curve.
+
+ The first curve has index 0.
+ """
+ def __init__(self):
+ super(IndexCommand, self).__init__(
+ name='curve index',
+ arguments=[
+ PlaylistArgument,
+ ],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ outqueue.put(params['playlist']._index)
+
+class CurveListCommand (Command):
+ """Get the curves in a playlist.
+ """
+ def __init__(self):
+ super(CurveListCommand, self).__init__(
+ name='playlist curves',
+ arguments=[
+ PlaylistArgument,
+ ],
+ help=self.__doc__)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ outqueue.put([c for c in params['playlist']])
+
class SaveCommand (Command):
"""Save a playlist.
"""
help="""
File name for the input playlist.
""".strip()),
- Argument(name='drivers', type='driver', optional=False,
- count=-1,
+ Argument(name='drivers', type='driver', optional=True,
+ count=-1, callback=all_drivers_callback,
help="""
Drivers for loading curves.
""".strip()),
p = params['playlist'].filter(params['filter'])
hooke.playlists.add(p)
outqueue.put(p)
+
+class NoteFilterCommand (FilterCommand):
+ """Create a subset playlist of curves with `.info['note'] != None`.
+ """
+ def __init__(self):
+ super(NoteFilterCommand, self).__init__()
+ self.name = 'note filter playlist'
+ self.arguments = [a for a in self.arguments if a.name != 'filter']
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ params['filter'] = lambda curve : \
+ 'note' in curve.info and curve.info['note'] != None
+ return super(NoteFilterCommand, self)._run(
+ hooke, inqueue, outqueue, params)