forked from actlaboratory/LAMP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shuffle_ctrl.py
66 lines (60 loc) · 2.35 KB
/
shuffle_ctrl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import random
import globalVars
#シャッフルコントロール(プレイリストオブジェクト)
class shuffle():
def __init__(self, list):
self.list = list #シャッフルする元オブジェクト
self.history = [] #再生履歴
self.playIndex = 0
def previous(self):
# プレイリスト再生中であれば
get = self.getNow()
if get[1] == globalVars.eventProcess.playingDataNo or get[1] == None:
#1曲前を再生
get = self.getPrevious()
globalVars.eventProcess.play(globalVars.playlist, get)
elif get[0] != None:
# キューなどからの復帰
globalVars.eventProcess.play(globalVars.playlist, get)
def next(self):
# キューを確認
get = globalVars.queue.getNext()
if get[0] == None:
# キューが空の時はシャッフルを進める
get = self.getNext()
if get[0] != None:
globalVars.eventProcess.play(globalVars.playlist, get)
else: #再生終了後に次がなければ停止とする
if globalVars.play.getChannelState() == player.state.STOPED:
globalVars.eventProcess.stop()
else: #キューの再生
globalVars.eventProcess.play(globalVars.queue, get)
def getNow(self):
if len(self.history) == 0:
return (None, None)
else:
return self.history[self.playIndex]
def getPrevious(self):
if len(self.list.lst) == 0:
return (None, None)
elif self.playIndex == 0:
rtn = random.choice(self.list.lst)
self.history.insert(0, rtn)
return rtn
else:
self.playIndex -= 1
return self.history[self.playIndex]
def getNext(self):
if len(self.history) == 0 and self.playIndex == 0: #初期の場合
self.playIndex = -1
if len(self.list.lst) == 0:
rtn = (None, None)
elif self.playIndex == len(self.history)-1:
rtn = random.choice(self.list.lst)
self.history.append(rtn)
self.playIndex += 1
else:
self.playIndex += 1
rtn = self.history[self.playIndex]
if rtn == (None, None) and self.playIndex == -1: self.playIndex = 0
return rtn