-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshuffle_ctrl.py
58 lines (53 loc) · 2.29 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
# shuffle controler for LAMP
# Copyright (C) 2020 Hiroki Fujii <[email protected]>
import random, math
import globalVars, constants, listManager, errorCodes
#シャッフルコントロール(プレイリストオブジェクト)
class shuffle():
def __init__(self, list):
self.list = list #シャッフルする元オブジェクト
self.history = [] #再生履歴
self.playIndex = -1
def previous(self, lstConstant):
# プレイリスト再生中であれば
if lstConstant == constants.PLAYLIST:
#1曲前を再生
if self.playIndex <= 0:
return errorCodes.END
else:
self.playIndex -= 1
if self.history[self.playIndex] in self.list:
self.list.setPointer(self.list.index(self.history[self.playIndex]))
return globalVars.eventProcess.play()
else:
self.history.pop(self.playIndex)
self.previous(lstConstant)
else:
# キューなどからの復帰
if self.history[elf.playIndex] in self.list:
self.list.setPointer(self.list.index(self.history[self.playIndex]))
return globalVars.eventProcess.play()
else:
self.history.pop(self.playIndex)
self.previous(constants.PLAYLIST)
def next(self):
# キューを確認
t = globalVars.app.hMainView.queueView.get()
if t != None: return globalVars.eventProcess.play(constants.QUEUE)
# キューが空の時はシャッフルを進める
self.playIndex += 1
if self.playIndex < len(self.history):
if self.history[self.playIndex] in self.list:
self.list.setPointer(self.list.index(self.history[self.playIndex]))
return globalVars.eventProcess.play()
else:
self.next()
else:
if len(self.list) == 0: return errorCodes.END
else:
rnd = math.floor(random.random() * len(self.list))
self.list.setPointer(rnd)
if globalVars.eventProcess.play():
self.history.append(self.list[rnd])
return True
else: return False