diff options
author | jerous <jerous@gmail.com> | 2008-06-19 20:16:19 +0200 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-06-19 20:16:19 +0200 |
commit | ac0fd5b0b576ec65b30492b4c25d513dac0e173b (patch) | |
tree | 8eafe36187362917758e4e641ac77d52aa340b76 /plugins/PlayControl.py | |
parent | 3397101a88d76b4dfe700df1323e1b1b5b35279b (diff) |
all random and repeat modes are implemented
Diffstat (limited to 'plugins/PlayControl.py')
-rw-r--r-- | plugins/PlayControl.py | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/plugins/PlayControl.py b/plugins/PlayControl.py index 50cd2a0..abe4547 100644 --- a/plugins/PlayControl.py +++ b/plugins/PlayControl.py @@ -3,12 +3,18 @@ from PyQt4 import QtGui, QtSvg, QtCore from misc import * from clMonty import monty from clPlugin import * +from thread import start_new_thread +from random import randint -PC_RANDOM_NO=0 # no randomness +# Some predefined constants. +# Note that REPEAT precedes RANDOM. E.g. if repeat +# is ALBUM, and random is SONG, then it'll take a random song +# from the current album ... +PC_RANDOM_NO=0 # no randomness PC_RANDOM_SONG=1 # choose a song random from the playlist PC_RANDOM_ALBUM=2 # choose a random album, and play that fully -PC_REPEAT_NO=0 # no repeat +PC_REPEAT_NO=0 # no repeat PC_REPEAT_SONG=1 # repeat current song PC_REPEAT_ALBUM=2 # repeat current album PC_REPEAT_PLAYLIST=3 # repeat playlist @@ -32,6 +38,9 @@ class wgPlayControl(QtGui.QWidget): cmbRepeat=None cmbShuffle=None + + " contains the songs of the album the current song is playing. None, if the album is not set" + curAlbumSongs=None def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) @@ -141,18 +150,68 @@ class wgPlayControl(QtGui.QWidget): self.slrTime.setEnabled(True) except: pass + # look in another thread for the songs in the current album! + params=() + start_new_thread(self.findAlbumSongs, params) def beforeSongChange(self, params): nextID=None + song=monty.getCurrentSong() # decide here what next song to play! - if self.cmbRepeat.currentIndex()==PC_REPEAT_SONG: + repeat=self.cmbRepeat.currentIndex() + random=self.cmbShuffle.currentIndex() + # is the current song the last of the album? + eofAlbum=int(song.getTrack())==int(self.curAlbumSongs[-1].getTrack()) + if repeat==PC_REPEAT_NO: + # no repeat, nothing to see here! Pass on! + pass + elif repeat==PC_REPEAT_SONG: # we must repeat the previous song! nextID=params['curSongID'] + elif repeat==PC_REPEAT_ALBUM: + # check if we are at the last track, if it is, we must start a new! + if eofAlbum: + nextID=self.curAlbumSongs[0].getID() + elif repeat==PC_REPEAT_PLAYLIST: + # repeating the playlist is handled by monty itself; + # it is set in onCmbRepeatChanged. + pass + + if random==PC_RANDOM_NO: + # just follow our leader Monty. + pass + elif random==PC_RANDOM_SONG: + # pick a random song! This depends on what repeat-mode we're in. + if repeat==PC_REPEAT_NO or repeat==PC_REPEAT_PLAYLIST: + # we don't repeat anything, so we can just let monty pick the + # next random one! + pass + elif repeat==PC_REPEAT_SONG: + # song repeat; don't choose the next one! + nextID=params['curSongID'] + elif repeat==PC_REPEAT_ALBUM and self.curAlbumSongs: + # pick random song from current album + nextID=self.curAlbumSongs[randint(0,len(self.curAlbumSongs)-1)].getID() + elif random==PC_RANDOM_ALBUM: + # pick a random album! This means, we pick the first song of a random + # album. + if eofAlbum and (repeat==PC_REPEAT_PLAYLIST or repeat==PC_REPEAT_NO): + # all first songs of an album + albums=filter(lambda s: s.getAlbum() and s.getTrack()==1, monty.listPlaylist()) + nextID=albums[randint(0,len(albums)-1)].getID() - if nextID: + if nextID!=None: monty.play(nextID) - + def findAlbumSongs(self): + """This method looks for the songs in the album of current playing song.""" + song=monty.getCurrentSong() + self.curAlbumSongs=None + if not song or not song.getAlbum(): + return + self.curAlbumSongs=filter(lambda s: s.getArtist()==song.getArtist() + and s.getAlbum()==song.getAlbum(), monty.listPlaylist()) + self.curAlbumSongs.sort(numeric_compare) def onBtnPlayPauseClick(self): status=monty.getStatus() |