test/data/vclamp_jpk/README: Document sample versions
[hooke.git] / hooke / plugin / playlists.py
1 # Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
8 # later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
17
18 """The ``playlists`` module provides :class:`PlaylistsPlugin` and
19 several associated :class:`hooke.command.Command`\s for handling
20 lists of :class:`hooke.playlist.Playlist` classes.
21 """
22
23 from ..command import Command, Argument, Failure
24 from ..playlist import FilePlaylist
25 from . import Builtin
26 from .playlist import PlaylistNameArgument, PlaylistAddingCommand
27
28
29 class PlaylistsPlugin (Builtin):
30     def __init__(self):
31         super(PlaylistsPlugin, self).__init__(name='playlists')
32         self._commands = [
33             NextCommand(self), PreviousCommand(self), JumpCommand(self),
34             IndexCommand(self), PlaylistListCommand(self), NewCommand(self)]
35
36
37 # Define commands
38
39 class NextCommand (Command):
40     """Move `hooke.playlists` to the next playlist.
41     """
42     def __init__(self, plugin):
43         super(NextCommand, self).__init__(
44             name='next playlist',
45             help=self.__doc__, plugin=plugin)
46
47     def _run(self, hooke, inqueue, outqueue, params):
48         hooke.playlists.next()
49
50 class PreviousCommand (Command):
51     """Move `hooke.playlists` to the previous playlist.
52     """
53     def __init__(self, plugin):
54         super(PreviousCommand, self).__init__(
55             name='previous playlist',
56             help=self.__doc__, plugin=plugin)
57
58     def _run(self, hooke, inqueue, outqueue, params):
59         hooke.playlists.previous()
60
61 class JumpCommand (Command):
62     """Move `hooke.playlists` to a given playlist.
63     """
64     def __init__(self, plugin):
65         super(JumpCommand, self).__init__(
66             name='jump to playlist',
67             arguments=[
68                 Argument(name='index', type='int', optional=False, help="""
69 Index of target curve.
70 """.strip()),
71                 ],
72             help=self.__doc__, plugin=plugin)
73
74     def _run(self, hooke, inqueue, outqueue, params):
75         hooke.playlists.jump(params['index'])
76
77 class IndexCommand (Command):
78     """Print the index of the current playlist.
79
80     The first playlist has index 0.
81     """
82     def __init__(self, plugin):
83         super(IndexCommand, self).__init__(
84             name='playlist index',
85             help=self.__doc__, plugin=plugin)
86
87     def _run(self, hooke, inqueue, outqueue, params):
88         outqueue.put(hooke.playlists.index())
89
90 class PlaylistListCommand (Command):
91     """Get the playlists in `hooke.playlists`.
92     """
93     def __init__(self, plugin):
94         super(PlaylistListCommand, self).__init__(
95             name='playlists',
96             help=self.__doc__, plugin=plugin)
97
98     def _run(self, hooke, inqueue, outqueue, params):
99         outqueue.put(list(hooke.playlists))
100
101
102 class NewCommand (PlaylistAddingCommand):
103     """Create a new playlist.
104     """
105     def __init__(self, plugin):
106         super(NewCommand, self).__init__(
107             name='new playlist',
108             arguments=[
109                 Argument(name='file', type='file', optional=True,
110                          help="""
111 Default filename for future saves.
112 """.strip()),
113                 ],
114             help=self.__doc__, plugin=plugin)
115
116     def _run(self, hooke, inqueue, outqueue, params):
117         p = FilePlaylist(
118             drivers=hooke.drivers,
119             path=params['file'],
120             )
121         self._set_playlist(hooke, params, p)
122         outqueue.put(p)