This development deserves a new version number!
[pylooper.git] / player.py
blobacf6bc0b2ec1beafd7a99716c4ad67607cbcf01d
1 def isblank(s):
2 return s is None or len(s) is 0 or s.isspace()
4 class Player(object):
5 """Provides an interface for the program to produce audio output.
6 Implementations should subclass this and do whatever is needed for their
7 intended architecture."""
9 def __init__(self):
10 """button_callback is called with True to set the playpause button to
11 active (pushed in with pause showing) and with False to set it to
12 inactive (pushed out with play showing)"""
14 self.timer = None
15 self.status = self.Status()
17 def __str__(self):
18 """Return a string to use as the label for the current playing song."""
19 raise NotImplementedError()
21 def play(self):
22 raise NotImplementedError()
24 def pause(self):
25 raise NotImplementedError()
27 def stop(self):
28 """Stop playing and set the current position to status.begin."""
29 raise NotImplementedError()
31 def load(self):
32 """Load status.filename to prepare for playback."""
33 raise NotImplementedError()
35 def check_status(self):
36 """Check internal status struct and set timer for looper if needed."""
37 raise NotImplementedError()
39 @property
40 def isplaying(self):
41 """Are we currently playing?"""
42 raise NotImplementedError()
44 @property
45 def ispaused(self):
46 """Are we currently paused?"""
47 raise NotImplementedError()
49 @property
50 def position(self):
51 """Get the current position."""
52 raise NotImplementedError()
54 @property
55 def duration(self):
56 """Get the length of the current song."""
57 raise NotImplementedError()
59 class Status(object):
60 """Struct class to hold the filename and start and end positions."""
61 def __init__(self):
62 self.filepath = None
63 self.begin = self.end = 0
65 def _get_interval(self):
66 return self.begin, self.end
68 def _set_interval(self, interval):
69 self.begin, self.end = interval
71 interval = property(_get_interval, _set_interval)