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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
import os
from playlist import Playlist
from abcontroller import ABController
from session_manager import SessionManager
from notifier import Notifier
from player_vlc import Player
class SoloTool:
def __init__(self, playerOverride=None):
self._player = Player() if playerOverride is None else playerOverride
self._playlist = Playlist(self._playlistCallback)
self._abController = ABController(enabled=False, callback=self._abControllerCallback)
self._sessionManager = SessionManager(self._playlist, self._abController)
self._notifier = Notifier(self._player)
def _playlistCallback(self, path):
self._player.setCurrentSong(path)
self._abController.setCurrentSong(path)
def _abControllerCallback(self, position):
self._player.setPlaybackPosition(position)
def tick(self):
position = self._player.getPlaybackPosition()
self._abController.positionChanged(position)
def addSong(self, path):
if os.path.isfile(path):
self._sessionManager.addSong(path)
def setSong(self, index):
previous = self._playlist.getCurrentSongIndex()
self._playlist.setCurrentSong(index)
new = self._playlist.getCurrentSongIndex()
if previous != new:
self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
def nextSong(self):
previous = self._playlist.getCurrentSongIndex()
self._playlist.nextSong()
new = self._playlist.getCurrentSongIndex()
if previous != new:
self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
def previousSong(self):
previous = self._playlist.getCurrentSongIndex()
self._playlist.previousSong()
new = self._playlist.getCurrentSongIndex()
if previous != new:
self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
def getSongs(self):
return self._playlist.getSongs()
def storeAbLimits(self, aLimit, bLimit):
self._abController.storeLimits(aLimit, bLimit)
def loadAbLimits(self, index):
previous = self._abController.getLoadedIndex()
self._abController.loadLimits(index)
new = self._abController.getLoadedIndex()
if previous != new:
self._notifier.notify(Notifier.CURRENT_AB_EVENT, new)
def setAbLimits(self, aLimit, bLimit):
self._abController.setLimits(aLimit, bLimit)
def getStoredAbLimits(self):
currentSong = self._playlist.getCurrentSong()
if currentSong is not None:
return self._abController.getStoredLimits(currentSong)
else:
return list()
def setAbLimitEnable(self, enable):
previous = self._abController.isEnabled()
self._abController.setEnable(enable)
new = self._abController.isEnabled()
if previous != new:
self._notifier.notify(Notifier.AB_LIMIT_ENABLED_EVENT, new)
def isAbLimitEnabled(self):
return self._abController.isEnabled()
def nextStoredAbLimits(self):
previous = self._abController.getLoadedIndex()
self._abController.nextStoredAbLimits()
new = self._abController.getLoadedIndex()
if previous != new:
self._notifier.notify(Notifier.CURRENT_AB_EVENT, new)
def previousStoredAbLimits(self):
previous = self._abController.getLoadedIndex()
self._abController.previousStoredAbLimits()
new = self._abController.getLoadedIndex()
if previous != new:
self._notifier.notify(Notifier.CURRENT_AB_EVENT, new)
def jumpToA(self):
a = self._abController.getCurrentLimits()[0]
# XXX assumes that player.setPlaybackPosition is thread-safe!
self._player.setPlaybackPosition(a)
def loadSession(self, path):
with open(path, "r") as f:
self._sessionManager.loadSession(f)
def saveSession(self, path):
with open(path, "w") as f:
self._sessionManager.saveSession(f)
def play(self):
self._player.play()
def pause(self):
self._player.pause()
def stop(self):
self._player.stop()
def isPlaying(self):
return self._player.isPlaying()
def setPlaybackRate(self, rate):
previous = self._player.getPlaybackRate()
self._player.setPlaybackRate(rate)
new = self._player.getPlaybackRate()
if previous != new:
self._notifier.notify(Notifier.PLAYBACK_RATE_EVENT, new)
def getPlaybackRate(self):
return self._player.getPlaybackRate()
def setPlaybackPosition(self, position):
self._player.setPlaybackPosition(position)
def getPlaybackPosition(self):
return self._player.getPlaybackPosition()
def setPlaybackVolume(self, volume):
self._player.setPlaybackVolume(volume)
def getPlaybackVolume(self):
return self._player.getPlaybackVolume()
def registerPlayingStateCallback(self, callback):
self._notifier.registerCallback(Notifier.PLAYING_STATE_EVENT, callback)
def registerPlaybackVolumeCallback(self, callback):
self._notifier.registerCallback(Notifier.PLAYBACK_VOLUME_EVENT, callback)
def registerPlaybackRateCallback(self, callback):
self._notifier.registerCallback(Notifier.PLAYBACK_RATE_EVENT, callback)
def registerCurrentSongCallback(self, callback):
self._notifier.registerCallback(Notifier.CURRENT_SONG_EVENT, callback)
def registerCurrentAbLimitsCallback(self, callback):
self._notifier.registerCallback(Notifier.CURRENT_AB_EVENT, callback)
def registerAbLimitEnabledCallback(self, callback):
self._notifier.registerCallback(Notifier.AB_LIMIT_ENABLED_EVENT, callback)
|