diff options
-rw-r--r-- | abcontroller.py | 9 | ||||
-rw-r--r-- | abcontroller_unittest.py | 25 | ||||
-rw-r--r-- | known-issues | 4 | ||||
-rw-r--r-- | playlist.py | 3 | ||||
-rw-r--r-- | playlist_unittest.py | 19 | ||||
-rw-r--r-- | session_manager.py | 3 | ||||
-rw-r--r-- | session_manager_unittest.py | 23 | ||||
-rw-r--r-- | solo_tool_qt.py | 1 |
8 files changed, 78 insertions, 9 deletions
diff --git a/abcontroller.py b/abcontroller.py index e9eace4..2e08936 100644 --- a/abcontroller.py +++ b/abcontroller.py @@ -4,7 +4,7 @@ _AB = namedtuple("_AB", ["a", "b"]) class ABController: def __init__(self, enabled=True, callback=None): - self.setPositionCallback = callback + self._setPositionCallback = callback self._limits = dict() # dictionary of all songs self._songLimits = None # list of limits for selected song self._currentLimits = None # a/b positions of selected limit @@ -42,11 +42,14 @@ class ABController: def positionChanged(self, position): if not self._currentLimits: return - if position > self._currentLimits.b and self.setPositionCallback and self._enabled: - self.setPositionCallback(self._currentLimits.a) + if position > self._currentLimits.b and self._setPositionCallback and self._enabled: + self._setPositionCallback(self._currentLimits.a) def setEnable(self, enable): self._enabled = enable def getLimits(self, song): return self._limits.get(song) + + def clear(self): + self.__init__(enabled=self._enabled, callback=self._setPositionCallback) diff --git a/abcontroller_unittest.py b/abcontroller_unittest.py index ea377b7..8eb401a 100644 --- a/abcontroller_unittest.py +++ b/abcontroller_unittest.py @@ -19,14 +19,14 @@ def checkLimits(uut, aLimit, bLimit, fail=False): nonlocal requestedPosition requestedPosition = newPosition - originalCallback = uut.setPositionCallback - uut.setPositionCallback = callback + originalCallback = uut._setPositionCallback + uut._setPositionCallback = callback for t in tests: uut.positionChanged(t.currentPosition) assert requestedPosition == t.requestedPosition - uut.setPositionCallback = originalCallback + uut._setPositionCallback = originalCallback def test_oneSetOfLimits(): song = "/path/to/song" @@ -141,3 +141,22 @@ def test_getLimitsOfInexistentSong(): song = "/path/to/song" uut = ABController() assert uut.getLimits(song) == None + +def test_clearAbController(): + songsWithLimits = [ + ("/path/to/song", AB(0.2, 0.4)), + ("/path/to/another/song", AB(0.3, 0.5)) + ] + + uut = ABController() + for s in songsWithLimits: + uut.addLimits(s[1].a, s[1].b, s[0]) + + for i, s in enumerate(songsWithLimits): + assert uut.getLimits(s[0]) == [s[1]] + + uut.clear() + + for i, s in enumerate(songsWithLimits): + assert uut.getLimits(s[0]) == None + diff --git a/known-issues b/known-issues index 35ebdff..2b63f65 100644 --- a/known-issues +++ b/known-issues @@ -1,4 +1,4 @@ * Moving AB sliders does not set AB limit. Instead need to save AB limit and then select it to apply -* Loading session is additive, should clear the state first +* (done) Loading session is additive, should clear the state first * AB limits are displayed as p.u., should be timestamps -* Songs are displayed as full path, should be file name or ideally title from metadata +* (done) Songs are displayed as full path, should be file name or ideally title from metadata diff --git a/playlist.py b/playlist.py index 084fd21..d25395b 100644 --- a/playlist.py +++ b/playlist.py @@ -19,3 +19,6 @@ class Playlist: def getSongs(self): return self._songList + + def clear(self): + self.__init__(self._setSongCallback) diff --git a/playlist_unittest.py b/playlist_unittest.py index ff5a79c..9dd3700 100644 --- a/playlist_unittest.py +++ b/playlist_unittest.py @@ -74,3 +74,22 @@ def test_invalidSongSelection(): assert uut.getCurrentSong() == None assert uut.getSongs() == [songAddedByUser] +def test_clearPlaylist(): + songAddedByUser = ["/path/to/song", "/path/to/second/song"] + + def dummy(index): + pass + + uut = Playlist(dummy) + for s in songAddedByUser: + uut.addSong(s) + uut.setCurrentSong(0) + + assert uut.getSongs() == songAddedByUser + assert uut.getCurrentSong() == songAddedByUser[0] + + uut.clear() + + assert uut.getSongs() == [] + assert uut.getCurrentSong() == None + diff --git a/session_manager.py b/session_manager.py index 52742c8..fd6b4ad 100644 --- a/session_manager.py +++ b/session_manager.py @@ -15,6 +15,9 @@ class SessionManager: jsonStr = file.read() session = json.loads(jsonStr) + self._playlist.clear() + self._abController.clear() + for entry in session: songPath = entry["path"] abLimits = entry["ab_limits"] diff --git a/session_manager_unittest.py b/session_manager_unittest.py index 7fb8c55..532ae75 100644 --- a/session_manager_unittest.py +++ b/session_manager_unittest.py @@ -33,6 +33,9 @@ class PlaylistMock: def getSongs(self): return self.songs + def clear(self): + self.__init__() + class ABControllerMock: def __init__(self): self.limits = dict() @@ -45,6 +48,9 @@ class ABControllerMock: def getLimits(self, song): return self.limits.get(song) + def clear(self): + self.__init__() + class MockFile: def __init__(self, init=""): self.contents = init @@ -138,3 +144,20 @@ def test_loadAndSaveEmptySession(): assert songs == list() for s in songs: assert abControllerMock.getLimits(s) == None + +def test_loadSessionNotAdditive(): + playlistMock = PlaylistMock() + abControllerMock = ABControllerMock() + uut = SessionManager(playlistMock, abControllerMock) + + sessionFile = MockFile(dumps(testSession)) + uut.loadSession(sessionFile) + uut.loadSession(sessionFile) + + songs = playlistMock.getSongs() + assert len(songs) == len(set(songs)) + for s in songs: + abLimits = abControllerMock.getLimits(s) + if abLimits is not None: + abLimitStr = [f"[{l[0]}, {l[1]}] " for l in abLimits] + assert len(abLimitStr) == len(set(abLimitStr)) diff --git a/solo_tool_qt.py b/solo_tool_qt.py index 71e2f82..9f4b7aa 100644 --- a/solo_tool_qt.py +++ b/solo_tool_qt.py @@ -19,7 +19,6 @@ class PlaylistModel(QAbstractListModel): path = Path(self.soloTool.getSongs()[index.row()]) return path.name - def rowCount(self, index): return len(self.soloTool.getSongs()) |