comparison vixm/playlist.py @ 32:f97eb9f0c207 master

Add random song selection for default queue
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Fri, 03 Nov 2006 23:26:35 -0500
parents dfcf1a46fc56
children 99983189d4b2
comparison
equal deleted inserted replaced
31:4fba4ccab723 32:f97eb9f0c207
4 # 4 #
5 # This program is free software; you can redistribute it and/or modify 5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as 6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation. 7 # published by the Free Software Foundation.
8 8
9 import random
9 import xmms, re 10 import xmms, re
10 11
11 LIST_PRIO = 0 12 LIST_PRIO = 0
12 LIST_DEFAULT = 1 13 LIST_DEFAULT = 1
13 14
14 class playlist: 15 class playlist:
15 def __init__(self, allowrandom=False): 16 def __init__(self, allowrandom=False):
16 self.__list = [] 17 self.__list = []
17 self.__allowrand = allowrandom # allow randomization of this list 18 self.__allowrand = allowrandom # allow randomization of this list
19 self.__cursor = 0
18 20
19 def enqueue(self, song): 21 def enqueue(self, song):
20 """ Append a song to the list """ 22 """ Append a song to the list """
21 self.__list.append(song) 23 self.__list.append(song)
22 24
25 self.__list.remove(song) 27 self.__list.remove(song)
26 28
27 def pop(self): 29 def pop(self):
28 """ Pop the next song """ 30 """ Pop the next song """
29 return self.__list.pop(0) 31 return self.__list.pop(0)
32
33 def next(self):
34 """ Get the next song """
35 idx = random.randint(0, len(self.__list)-1)
36
37 if not self.__allowrand:
38 idx = self.__cursor
39
40 self.__cursor += 1
41 if self.__cursor >= len(self.__list):
42 self.__cursor = 0
43
44 return self.__list[idx]
30 45
31 def __getitem__(self, i): 46 def __getitem__(self, i):
32 """ Get item at position i """ 47 """ Get item at position i """
33 return self.__list[i] 48 return self.__list[i]
34 49