Debian Codegraph @

xl/player/engine.py

raw
1 # Copyright (C) 2008-2010 Adam Olsen
2 # Copyright (C) 2014-2015 Dustin Spicuzza
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 #
19 # The developers of the Exaile media player hereby grant permission
20 # for non-GPL compatible GStreamer and Exaile plugins to be used and
21 # distributed together with GStreamer and Exaile. This permission is
22 # above and beyond the permissions granted by the GPL license by which
23 # Exaile is covered. If you modify this code, you may extend this
24 # exception to your version of the code, but you are not obligated to
25 # do so. If you do not wish to do so, delete this exception statement
26 # from your version.
27
28
29 class ExaileEngine:
30 """
31 Interface that the ExailePlayer uses to control the engines. Other
32 parts of Exaile should never interact directly with the engines, but
33 interact with the ExailePlayer instead.
34
35 Engines should not call play/stop/pause/unpause on itself directly,
36 should call through the player object instead.
37
38 All public functions are assumed to be called from the Glib main
39 thread, or bad things will happen.
40
41 The ExailePlayer object provides a common API that engines must use
42 to indicate the current playback status, or retrieve things such as
43 the next track to be played.
44
45 Player API: Playback status:
46
47 * engine_notify_track_start: Called when a track begins playback
48 * engine_notify_track_end: Called when a track has stopped playing
49 * engine_notify_error: Call this to notify the user of an error
50
51 Player API: Auto-advance
52
53 * engine_autoadvance_get_next_track: Call this to determine whether
54 a new track should be played after the current track
55 * engine_autoadvance_notify_next: Call when the auto advance track is
56 actually played.
57
58 Player API: misc
59
60 * engine_notify_user_volume_change: Call this when something inside
61 of the engine causes the user volume to change.
62
63 Engines are expected to honor the value of the __startoffset and
64 __stopoffset flags to start/stop tracks at the appropriate offsets.
65 """
66
67 def __init__(self, name, player):
68 self.name = name
69 self.player = player
70
71 def initialize(self):
72 """
73 Initialize the engine.
74
75 The engine should call `player.engine_load_volume` when
76 initialization has been completed.
77 """
78 raise NotImplementedError
79
80 def destroy(self):
81 """
82 Closes all resources associated with this engine
83 """
84 raise NotImplementedError
85
86 def get_current_track(self):
87 """
88 :returns: the current track that is playing, or None
89 """
90 raise NotImplementedError
91
92 def get_position(self):
93 """
94 Gets the current playback position of the playing track
95
96 :returns: the playback position in nanoseconds
97 :rtype: int
98 """
99 raise NotImplementedError
100
101 def get_state(self):
102 """
103 Gets the player state
104
105 :returns: one of *playing*, *paused* or *stopped*
106 :rtype: string
107 """
108 raise NotImplementedError
109
110 def get_volume(self):
111 """
112 Gets the current engine volume
113
114 :returns: the volume percentage (0..1)
115 :type: float
116 """
117 raise NotImplementedError
118
119 def on_track_stopoffset_changed(self, track):
120 """
121 Called when the stop offset of a track has been changed by the
122 user. Engines should adjust the playing time of the track.
123 """
124
125 def pause(self):
126 """
127 Pauses the playback, does not toggle it
128 """
129 raise NotImplementedError
130
131 def play(self, track, start_at, paused):
132 """
133 Starts the playback with the provided track or stops the playback
134 immediately if none. If the __startoffset tag is set, then
135 start_at will be set to that value.
136
137 Calls self.player.engine_notify_track_end if a prior track was playing.
138
139 Calls self.player.engine_notify_track_start when the track has started.
140
141 :param track: the track to play
142 :type track: :class:`xl.trax.Track`
143 :param start_at: The offset to start playback at, in seconds; or None
144 :param paused: If True, start the track in 'paused' mode
145 """
146 raise NotImplementedError
147
148 def seek(self, value):
149 """
150 Seek to a position in the currently playing stream
151
152 :param value: the position in seconds
153 :type value: float
154 """
155 raise NotImplementedError
156
157 def set_volume(self, volume):
158 """
159 Sets the volume on this engine
160
161 :param volume: the volume percentage (0..1)
162 :type volume: float
163 """
164 raise NotImplementedError
165
166 def stop(self):
167 """
168 Stops playback, and calls self.player.engine_notify_track_end
169 """
170 raise NotImplementedError
171
172 def unpause(self):
173 """
174 Unpauses the playback, does not toggle it
175 """
176 raise NotImplementedError