~ubuntu-branches/ubuntu/karmic/quodlibet/karmic

« back to all changes in this revision

Viewing changes to quodlibet/player/_base.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-01-30 23:55:34 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090130235534-l4e72ulw0vqfo17w
Tags: 2.0-1ubuntu1
* Merge from Debian experimental (LP: #276856), remaining Ubuntu changes:
  + debian/patches/40-use-music-profile.patch:
    - Use the "Music and Movies" pipeline per default.
* Refresh the above patch for new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import gobject
 
2
import gtk
 
3
 
 
4
class BasePlayer(gtk.Object):
 
5
    """Interfaces between a QL PlaylistModel and a GSt playbin.
 
6
 
 
7
    Attributes:
 
8
    paused -- True or False, set to pause/unpause the player
 
9
    volume -- current volume, 0.0 to 1.0
 
10
 
 
11
    song -- current song, or None if not playing
 
12
    info -- current stream information, or None if not playing. This is
 
13
            usually the same as song, unless the user is listening to
 
14
            a stream with multiple songs in it.
 
15
 
 
16
    If you're going to show things, use .info. If you're going to
 
17
    change things, use .song.
 
18
    """
 
19
 
 
20
    _paused = False
 
21
    paused = False
 
22
    song = None
 
23
    info = None
 
24
    # Replay Gain profiles are a list of values to be tried in order;
 
25
    # Three things can set them: play order, browser, and a default.
 
26
    replaygain_profiles = [None, None, ["none"]]
 
27
    _length = 1
 
28
    _volume = 1.0
 
29
 
 
30
    _gsignals_ = {
 
31
        'song-started':
 
32
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (object,)),
 
33
        'song-ended':
 
34
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (object, bool)),
 
35
        'seek':
 
36
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (object, int)),
 
37
        'paused': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
 
38
        'unpaused': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
 
39
        'error': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
 
40
                  (object, str, bool)),
 
41
        }
 
42
 
 
43
    _gproperties_ = {
 
44
        'volume': (float, 'player volume', 'the volume of the player',
 
45
                   0.0, 1.0, 1.0, gobject.PARAM_READWRITE)
 
46
        }
 
47
 
 
48
    def __init__(self, *args, **kwargs):
 
49
        super(BasePlayer, self).__init__()
 
50
 
 
51
    def do_song_started(self, song):
 
52
        # Reset Replay Gain levels based on the new song.
 
53
        self.volume = self.volume
 
54
 
 
55
    def do_song_ended(self, song, stopped):
 
56
        self.volume = self.volume
 
57
 
 
58
    def do_get_property(self, property):
 
59
        if property.name == 'volume':
 
60
            return self._volume
 
61
        else: raise AttributeError
 
62
 
 
63
    def _set_volume(self, v):
 
64
        self.props.volume = min(1.0, max(0.0, v))
 
65
    volume = property(lambda s: s._volume, _set_volume)
 
66
 
 
67
    def setup(self, source, song):
 
68
        """Connect to a PlaylistModel, and load a song."""
 
69
        self._source = source
 
70
        self.go_to(song)
 
71
 
 
72
    def remove(self, song):
 
73
        if self.song is song:
 
74
            self._end(False)
 
75
 
 
76
    def stop(self):
 
77
        self.paused = True
 
78
        self.seek(0)
 
79
 
 
80
    def reset(self):
 
81
        self._source.reset()
 
82
        if self._source.current is not None:
 
83
            self._end(True)
 
84
            if self.song:
 
85
                self.paused = False
 
86
 
 
87
    def next(self):
 
88
        self._source.next()
 
89
        self._end(True)
 
90
        if self.song:
 
91
            self.paused = False
 
92
 
 
93
    def previous(self):
 
94
        # Go back if standing at the beginning of the song,
 
95
        # otherwise restart the current song.
 
96
        if self.get_position() < 500:
 
97
            self._source.previous()
 
98
            self._end(True)
 
99
        else:
 
100
            self.seek(0)
 
101
        if self.song:
 
102
            self.paused = False
 
103
 
 
104
    def go_to(self, song):
 
105
        print_d("Going to %r" % song, context=self)
 
106
        self._source.go_to(song)
 
107
        self._end(True)
 
108
 
 
109
    def destroy(self):
 
110
        self.go_to(None)
 
111
        super(BasePlayer, self).destroy()