curds: Push playlists to the front of the current list
And when we've played all the tracks, remove it. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
b22ffbf5aa
commit
b1521c3d35
|
@ -97,20 +97,36 @@ class PlaylistManager(PlaylistManagerBase):
|
|||
|
||||
def next(self):
|
||||
self.track = self.current[0].next()
|
||||
while self.track == None and len(self.current) > 1:
|
||||
self.current = self.current[1:]
|
||||
self.track = self.current[0].next()
|
||||
self.lookup("Previous").add(self.track)
|
||||
return self.track
|
||||
|
||||
def __peek_pl(self, plist, n):
|
||||
cur = plist.current
|
||||
res = [ ]
|
||||
|
||||
for i in range(n):
|
||||
t = plist.next()
|
||||
if t == None:
|
||||
break
|
||||
res.append(t)
|
||||
|
||||
plist.current = cur
|
||||
return res
|
||||
|
||||
def peek(self, n):
|
||||
cur = self.current[0].current
|
||||
state = random.getstate()
|
||||
res = [ ]
|
||||
|
||||
for i in range(n):
|
||||
t = self.current[0].next()
|
||||
if t != None:
|
||||
res.append(t)
|
||||
for pl in self.current:
|
||||
tracks = self.__peek_pl(pl, n)
|
||||
res += tracks
|
||||
n -= len(tracks)
|
||||
if n == 0:
|
||||
break
|
||||
|
||||
self.current[0].current = cur
|
||||
random.setstate(state)
|
||||
return res
|
||||
|
||||
|
@ -129,4 +145,10 @@ class PlaylistManager(PlaylistManagerBase):
|
|||
def reset(self):
|
||||
for plist in self:
|
||||
plist.reset()
|
||||
self.track = None
|
||||
self.current = [ self.lookup("Collection") ]
|
||||
self.track = None
|
||||
|
||||
def select(self, plist):
|
||||
if plist in self.current:
|
||||
self.current.remove(plist)
|
||||
self.current.insert(0, plist)
|
||||
|
|
|
@ -31,6 +31,7 @@ class TestPlaylistManager(unittest.TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
notify.cancel("new-track", self.playman.lookup("Collection").add)
|
||||
notify.cancel("new-track", self.playman.lookup("Genre").add_track)
|
||||
notify.cancel("new-playlist", self.on_new_playlist)
|
||||
library.stop()
|
||||
|
||||
|
@ -228,5 +229,32 @@ class TestPlaylistManager(unittest.TestCase):
|
|||
clist = self.playman.lookup("Collection")
|
||||
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
|
||||
library.join()
|
||||
glist = self.playman.lookup("Genre").lookup("Test Genre 1")
|
||||
|
||||
self.assertEqual(self.playman.current, [ clist ])
|
||||
|
||||
self.playman.select(plist)
|
||||
self.assertEqual(self.playman.current, [ plist, clist ])
|
||||
|
||||
self.playman.select(glist)
|
||||
self.assertEqual(self.playman.current, [ glist, plist, clist ])
|
||||
|
||||
self.playman.select(plist)
|
||||
self.assertEqual(self.playman.current, [ plist, glist, clist ])
|
||||
|
||||
plist.current = 1247
|
||||
peek = self.playman.peek(4)
|
||||
self.assertEqual(len(peek), 4)
|
||||
self.assertEqual(peek[0], plist[-2])
|
||||
self.assertEqual(peek[1], plist[-1])
|
||||
self.assertEqual(peek[2], glist[ 0])
|
||||
self.assertEqual(peek[3], glist[ 1])
|
||||
|
||||
self.assertEqual(self.playman.next(), plist[-2])
|
||||
self.assertEqual(self.playman.next(), plist[-1])
|
||||
self.assertEqual(self.playman.current, [ plist, glist, clist ])
|
||||
self.assertEqual(self.playman.next(), glist[0])
|
||||
self.assertEqual(self.playman.current, [ glist, clist ])
|
||||
|
||||
self.playman.reset()
|
||||
self.assertEqual(self.playman.current, [ clist ])
|
||||
|
|
Loading…
Reference in New Issue