# HG changeset patch # User Josef "Jeff" Sipek # Date 1162614395 18000 # Node ID f97eb9f0c207a69d55093218e61ac8086402050a # Parent 4fba4ccab7230effb77c691d61bacda2158bcea5 Add random song selection for default queue diff -r 4fba4ccab723 -r f97eb9f0c207 vixm/player.py --- a/vixm/player.py Fri Nov 03 23:02:15 2006 -0500 +++ b/vixm/player.py Fri Nov 03 23:26:35 2006 -0500 @@ -6,9 +6,15 @@ Thread.__init__(self) self.shutdown = False + self.playing = False + + self.last = None self.lists = lists + def play(self, s): + print "about to play %s" % (str(s),) + def run(self): while not self.shutdown: time.sleep(0.5) diff -r 4fba4ccab723 -r f97eb9f0c207 vixm/playlist.py --- a/vixm/playlist.py Fri Nov 03 23:02:15 2006 -0500 +++ b/vixm/playlist.py Fri Nov 03 23:26:35 2006 -0500 @@ -6,6 +6,7 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. +import random import xmms, re LIST_PRIO = 0 @@ -15,6 +16,7 @@ def __init__(self, allowrandom=False): self.__list = [] self.__allowrand = allowrandom # allow randomization of this list + self.__cursor = 0 def enqueue(self, song): """ Append a song to the list """ @@ -28,6 +30,19 @@ """ Pop the next song """ return self.__list.pop(0) + def next(self): + """ Get the next song """ + idx = random.randint(0, len(self.__list)-1) + + if not self.__allowrand: + idx = self.__cursor + + self.__cursor += 1 + if self.__cursor >= len(self.__list): + self.__cursor = 0 + + return self.__list[idx] + def __getitem__(self, i): """ Get item at position i """ return self.__list[i] diff -r 4fba4ccab723 -r f97eb9f0c207 vixm/ui.py --- a/vixm/ui.py Fri Nov 03 23:02:15 2006 -0500 +++ b/vixm/ui.py Fri Nov 03 23:26:35 2006 -0500 @@ -42,32 +42,20 @@ ui = uiThread(play, lists) ui.start() - last = None while not play.shutdown: - """ # check which song we are playing now - pos = xmms.control.get_playlist_pos() - current = lists[playlist.LIST_DEFAULT][pos] - - # if it is different from what we played last time we - # checked... - if current != last: + if not play.playing: try: # pop song off the PRIO queue next = lists[playlist.LIST_PRIO].pop() - - # if successful, play the popped song - idx = lists[playlist.LIST_DEFAULT].index(next) - xmms.control.set_playlist_pos(idx) - current = next except IndexError: # no song to pop + next = lists[playlist.LIST_DEFAULT].next() pass except ValueError: print "WTF is going on?!" - # update last played song - last = current""" + play.play(next) # sleep time.sleep(0.5)