aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--notifier.py2
-rw-r--r--notifier_unittest.py36
-rw-r--r--playlist.py3
-rw-r--r--playlist_unittest.py18
-rw-r--r--solo_tool.py24
-rw-r--r--solo_tool_integrationtest.py91
6 files changed, 157 insertions, 17 deletions
diff --git a/notifier.py b/notifier.py
index 99be1ce..fc91e8c 100644
--- a/notifier.py
+++ b/notifier.py
@@ -3,6 +3,8 @@ class Notifier:
PLAYING_STATE_EVENT = 0
PLAYBACK_VOLUME_EVENT = 1
PLAYBACK_RATE_EVENT = 2
+ CURRENT_SONG_EVENT = 3
+ CURRENT_AB_EVENT = 4
def __init__(self, player):
self._callbacks = dict()
diff --git a/notifier_unittest.py b/notifier_unittest.py
index 9f37992..13f2285 100644
--- a/notifier_unittest.py
+++ b/notifier_unittest.py
@@ -11,34 +11,36 @@ def mockPlayer():
def uut(mockPlayer):
return Notifier(mockPlayer)
-def checkEvent(uut, event):
- callbacks = 2
- calledFlags = [False] * 2
+def test_allEvents(uut):
+ def checkEvent(uut, event):
+ callbacks = 2
+ calledFlags = [False] * 2
- def createCallback(i):
- def cb():
- nonlocal calledFlags
- calledFlags[i] = True
- return cb
+ def createCallback(i):
+ def cb():
+ nonlocal calledFlags
+ calledFlags[i] = True
+ return cb
- for i in range(0, callbacks):
- uut.registerCallback(event, createCallback(i))
+ for i in range(0, callbacks):
+ uut.registerCallback(event, createCallback(i))
- assert not any(calledFlags)
- uut.notify(event)
- assert all(calledFlags)
+ assert not any(calledFlags)
+ uut.notify(event)
+ assert all(calledFlags)
-def test_allEvents(uut):
checkEvent(uut, Notifier.PLAYING_STATE_EVENT)
checkEvent(uut, Notifier.PLAYBACK_VOLUME_EVENT)
checkEvent(uut, Notifier.PLAYBACK_RATE_EVENT)
+ checkEvent(uut, Notifier.CURRENT_SONG_EVENT)
+ checkEvent(uut, Notifier.CURRENT_AB_EVENT)
def test_eventWithoutRegisteredCallbacks(uut):
uut.notify(Notifier.PLAYING_STATE_EVENT)
# expect no crash
def test_eventsWithMockPlayer(uut, mockPlayer):
- def testEvent(eventCode, simulateEvent):
+ def checkEvent(eventCode, simulateEvent):
called = False
def callback():
nonlocal called
@@ -50,8 +52,8 @@ def test_eventsWithMockPlayer(uut, mockPlayer):
simulateEvent()
assert called
- testEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged)
- testEvent(Notifier.PLAYBACK_VOLUME_EVENT, mockPlayer.simulatePlaybackVolumeChanged)
+ checkEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged)
+ checkEvent(Notifier.PLAYBACK_VOLUME_EVENT, mockPlayer.simulatePlaybackVolumeChanged)
def test_singleEventNotification(uut):
playingStateCalled = False
diff --git a/playlist.py b/playlist.py
index 2880733..5dad711 100644
--- a/playlist.py
+++ b/playlist.py
@@ -17,6 +17,9 @@ class Playlist:
index = self._currentSong
return self._songList[index] if index is not None else None
+ def getCurrentSongIndex(self):
+ return self._currentSong
+
def getSongs(self):
return self._songList
diff --git a/playlist_unittest.py b/playlist_unittest.py
index 24d3a59..815a05f 100644
--- a/playlist_unittest.py
+++ b/playlist_unittest.py
@@ -14,6 +14,7 @@ def test_addAndSelectOneSong():
assert songAddedByUser == songSetByCallback
assert uut.getCurrentSong() == songAddedByUser
+ assert uut.getCurrentSongIndex() == 0
assert uut.getSongs() == [songAddedByUser]
def test_addTwoSongsAndSelectBoth():
@@ -32,10 +33,12 @@ def test_addTwoSongsAndSelectBoth():
uut.setCurrentSong(0)
assert songAddedByUser[0] == songSetByCallback
assert uut.getCurrentSong() == songAddedByUser[0]
+ assert uut.getCurrentSongIndex() == 0
uut.setCurrentSong(1)
assert songAddedByUser[1] == songSetByCallback
assert uut.getCurrentSong() == songAddedByUser[1]
+ assert uut.getCurrentSongIndex() == 1
def test_firstAddedSongIsNotSelected():
songAddedByUser = "/path/to/song"
@@ -50,6 +53,7 @@ def test_firstAddedSongIsNotSelected():
assert songSetByCallback == None
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
assert uut.getSongs() == [songAddedByUser]
def test_invalidSongSelection():
@@ -63,15 +67,18 @@ def test_invalidSongSelection():
uut = Playlist(testCallback)
assert songSetByCallback == None
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
uut.setCurrentSong(10)
assert songSetByCallback == None
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
uut.addSong(songAddedByUser)
uut.setCurrentSong(10)
assert songSetByCallback == None
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
assert uut.getSongs() == [songAddedByUser]
def test_clearPlaylist():
@@ -87,11 +94,13 @@ def test_clearPlaylist():
assert uut.getSongs() == songAddedByUser
assert uut.getCurrentSong() == songAddedByUser[0]
+ assert uut.getCurrentSongIndex() == 0
uut.clear()
assert uut.getSongs() == []
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
def test_nextSong():
songAddedByUser = ["/path/to/song", "/path/to/second/song"]
@@ -100,15 +109,19 @@ def test_nextSong():
for s in songAddedByUser:
uut.addSong(s)
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
uut.nextSong()
assert uut.getCurrentSong() == songAddedByUser[0]
+ assert uut.getCurrentSongIndex() == 0
uut.nextSong()
assert uut.getCurrentSong() == songAddedByUser[1]
+ assert uut.getCurrentSongIndex() == 1
uut.nextSong()
assert uut.getCurrentSong() == songAddedByUser[1]
+ assert uut.getCurrentSongIndex() == 1
def test_previousSong():
songAddedByUser = ["/path/to/song", "/path/to/second/song"]
@@ -117,14 +130,19 @@ def test_previousSong():
for s in songAddedByUser:
uut.addSong(s)
assert uut.getCurrentSong() == None
+ assert uut.getCurrentSongIndex() == None
uut.previousSong()
assert uut.getCurrentSong() == songAddedByUser[0]
+ assert uut.getCurrentSongIndex() == 0
uut.previousSong()
assert uut.getCurrentSong() == songAddedByUser[0]
+ assert uut.getCurrentSongIndex() == 0
uut.setCurrentSong(1)
assert uut.getCurrentSong() == songAddedByUser[1]
+ assert uut.getCurrentSongIndex() == 1
uut.previousSong()
assert uut.getCurrentSong() == songAddedByUser[0]
+ assert uut.getCurrentSongIndex() == 0
diff --git a/solo_tool.py b/solo_tool.py
index bca5146..fee7e4a 100644
--- a/solo_tool.py
+++ b/solo_tool.py
@@ -30,13 +30,22 @@ class SoloTool:
self._sessionManager.addSong(path)
def setSong(self, index):
+ changed = index != self._playlist.getCurrentSongIndex()
self._playlist.setCurrentSong(index)
+ if changed:
+ self._notifier.notify(Notifier.CURRENT_SONG_EVENT)
def nextSong(self):
+ previous = self._playlist.getCurrentSongIndex()
self._playlist.nextSong()
+ if previous != self._playlist.getCurrentSongIndex():
+ self._notifier.notify(Notifier.CURRENT_SONG_EVENT)
def previousSong(self):
+ previous = self._playlist.getCurrentSongIndex()
self._playlist.previousSong()
+ if previous != self._playlist.getCurrentSongIndex():
+ self._notifier.notify(Notifier.CURRENT_SONG_EVENT)
def getSongs(self):
return self._playlist.getSongs()
@@ -45,7 +54,10 @@ class SoloTool:
self._abController.storeLimits(aLimit, bLimit)
def loadAbLimits(self, index):
+ changed = index != self._abController.getLoadedIndex()
self._abController.loadLimits(index)
+ if changed:
+ self._notifier.notify(Notifier.CURRENT_AB_EVENT)
def setAbLimits(self, aLimit, bLimit):
self._abController.setLimits(aLimit, bLimit)
@@ -61,10 +73,16 @@ class SoloTool:
self._abController.setEnable(enable)
def nextStoredAbLimits(self):
+ previous = self._abController.getLoadedIndex()
self._abController.nextStoredAbLimits()
+ if previous != self._abController.getLoadedIndex():
+ self._notifier.notify(Notifier.CURRENT_AB_EVENT)
def previousStoredAbLimits(self):
+ previous = self._abController.getLoadedIndex()
self._abController.previousStoredAbLimits()
+ if previous != self._abController.getLoadedIndex():
+ self._notifier.notify(Notifier.CURRENT_AB_EVENT)
def jumpToA(self):
a = self._abController.getCurrentLimits()[0]
@@ -121,3 +139,9 @@ class SoloTool:
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)
+
diff --git a/solo_tool_integrationtest.py b/solo_tool_integrationtest.py
index 98dd31b..386cb26 100644
--- a/solo_tool_integrationtest.py
+++ b/solo_tool_integrationtest.py
@@ -407,3 +407,94 @@ def test_playbackRateNotification(uut, mockPlayer):
uut.setPlaybackRate(0.5)
assert not called
+
+def test_currentSongNotification(uut):
+ called = False
+ def callback():
+ nonlocal called
+ called = True
+
+ uut.registerCurrentSongCallback(callback)
+ assert not called
+
+ songs = [
+ "test.flac",
+ "test.mp3"
+ ]
+ uut.addSong(songs[0])
+ assert not called
+
+ uut.setSong(0)
+ assert called
+ called = False
+
+ uut.addSong(songs[1])
+ assert not called
+
+ uut.setSong(0)
+ assert not called
+
+ uut.setSong(1)
+ assert called
+ called = False
+
+ uut.previousSong()
+ assert called
+ called = False
+
+ uut.previousSong()
+ assert not called
+
+ uut.nextSong()
+ assert called
+ called = False
+
+ uut.nextSong()
+ assert not called
+
+def test_currentAbNotification(uut):
+ called = False
+ def callback():
+ nonlocal called
+ called = True
+
+ uut.registerCurrentAbLimitsCallback(callback)
+ assert not called
+
+ song = "test.flac"
+ uut.addSong(song)
+ uut.setSong(0)
+
+ abLimits = [
+ (0.2, 0.3),
+ (0.4, 0.5)
+ ]
+ uut.storeAbLimits(abLimits[0][0], abLimits[0][1])
+ assert not called
+ uut.storeAbLimits(abLimits[1][0], abLimits[1][1])
+ assert not called
+
+ uut.loadAbLimits(0)
+ assert called
+ called = False
+
+ uut.loadAbLimits(0)
+ assert not called
+
+ uut.loadAbLimits(1)
+ assert called
+ called = False
+
+ uut.previousStoredAbLimits()
+ assert called
+ called = False
+
+ uut.previousStoredAbLimits()
+ assert not called
+
+ uut.nextStoredAbLimits()
+ assert called
+ called = False
+
+ uut.nextStoredAbLimits()
+ assert not called