diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2021-12-26 23:05:46 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2021-12-26 23:05:46 +0100 |
commit | bf232d2f3fa94f374d82464eb66bcc7d72adc3ed (patch) | |
tree | 48daafadce6d643a7fb342178c161ecec5be53fb | |
parent | 8622638f99277b43d40b61029dc3c56164d06cae (diff) |
Added temporary AB limit functionality to back end
-rw-r--r-- | abcontroller.py | 5 | ||||
-rw-r--r-- | abcontroller_unittest.py | 30 | ||||
-rw-r--r-- | solo_tool.py | 5 | ||||
-rw-r--r-- | solo_tool_integrationtest.py | 36 |
4 files changed, 64 insertions, 12 deletions
diff --git a/abcontroller.py b/abcontroller.py index b67d38a..0a10078 100644 --- a/abcontroller.py +++ b/abcontroller.py @@ -17,7 +17,6 @@ class ABController: def setCurrentSong(self, path): self._ensureSongExists(path) self._songLimits = self._limits[path] - #self._currentLimits = None def storeLimits(self, aLimit, bLimit, song=None): if song is not None: @@ -39,10 +38,12 @@ class ABController: if index >= 0 and index < len(self._songLimits): self._currentLimits = self._songLimits[index] + def setLimits(self, aLimit, bLimit): + self._currentLimits = _AB(aLimit, bLimit) + def positionChanged(self, position): if not self._currentLimits: return - print("No early return") if position > self._currentLimits.b and self._setPositionCallback and self._enabled: self._setPositionCallback(self._currentLimits.a) diff --git a/abcontroller_unittest.py b/abcontroller_unittest.py index 736ac6b..6e6e779 100644 --- a/abcontroller_unittest.py +++ b/abcontroller_unittest.py @@ -182,8 +182,36 @@ def test_clearAbController(): assert uut.getLimits(s[0]) == None def test_setTemporaryLimits(): - pass + abLimits = [ + AB(0.2, 0.4), + AB(0.3, 0.5), + AB(0.0, 1.2) + ] + uut = ABController() + + for l in abLimits: + uut.setLimits(l.a, l.b) + checkLimits(uut, l.a, l.b) + +def test_setTemporaryLimitsWithCurrentSong(): + songLimits = AB(0.2, 0.4) + abLimits = [ + AB(0.2, 0.4), + AB(0.3, 0.5), + AB(0.0, 1.2) + ] + song = "/path/to/song" + uut = ABController() + uut.setCurrentSong(song) + uut.storeLimits(songLimits.a, songLimits.b) + uut.loadLimits(0) + + for l in abLimits: + uut.setLimits(l.a, l.b) + checkLimits(uut, l.a, l.b) + def test_defaultBehaviour(): uut = ABController() + checkDefaultLimits(uut) diff --git a/solo_tool.py b/solo_tool.py index 8530125..db28c45 100644 --- a/solo_tool.py +++ b/solo_tool.py @@ -36,9 +36,12 @@ class SoloTool: def storeAbLimits(self, aLimit, bLimit): self._abController.storeLimits(aLimit, bLimit) - def setAbLimit(self, index): + def loadAbLimits(self, index): self._abController.loadLimits(index) + def setAbLimits(self, aLimit, bLimit): + self._abController.setLimits(aLimit, bLimit) + def getAbLimits(self): currentSong = self._playlist.getCurrentSong() if currentSong is not None: diff --git a/solo_tool_integrationtest.py b/solo_tool_integrationtest.py index 9321e89..cd635d4 100644 --- a/solo_tool_integrationtest.py +++ b/solo_tool_integrationtest.py @@ -107,7 +107,7 @@ def test_addAndSetAbLimits(): uut.tick() assert mockPlayer.position == 0.5 - uut.setAbLimit(0) + uut.loadAbLimits(0) uut.tick() assert mockPlayer.position == 0.5 @@ -120,7 +120,7 @@ def test_addAndSetAbLimits(): uut.tick() assert mockPlayer.position == 0.2 - uut.setAbLimit(1) + uut.loadAbLimits(1) uut.tick() assert mockPlayer.position == 0.2 @@ -151,7 +151,7 @@ def test_multipleSongsAndAbLimits(): for i, l in enumerate(abLimits): uut.setSong(i) - uut.setAbLimit(0) + uut.loadAbLimits(0) mockPlayer.position = l[0] uut.tick() @@ -176,7 +176,7 @@ def test_storeAbLimitsWithoutSong(): assert mockPlayer.position == default mockPlayer.position = overflow - uut.setAbLimit(0) + uut.loadAbLimits(0) uut.tick() assert mockPlayer.position == default mockPlayer.position = overflow @@ -186,7 +186,7 @@ def test_storeAbLimitsWithoutSong(): assert mockPlayer.position == default mockPlayer.position = overflow - uut.setAbLimit(0) + uut.loadAbLimits(0) uut.tick() assert mockPlayer.position == default mockPlayer.position = overflow @@ -196,7 +196,7 @@ def test_storeAbLimitsWithoutSong(): assert mockPlayer.position == default mockPlayer.position = overflow - uut.setAbLimit(0) + uut.loadAbLimits(0) uut.tick() assert mockPlayer.position == default mockPlayer.position = overflow @@ -206,7 +206,7 @@ def test_storeAbLimitsWithoutSong(): assert mockPlayer.position == default mockPlayer.position = overflow - uut.setAbLimit(0) + uut.loadAbLimits(0) uut.tick() assert mockPlayer.position == abLimit[0] @@ -270,4 +270,24 @@ def test_getters(): mockPlayer.position = 0.8 assert uut.getPlaybackPosition() == 0.8 - +def test_setTemporaryLimits(): + song = "test.flac" + abLimits = [ + [0.2, 0.4], + [0.1, 0.4] + ] + overflow = 0.5 + mockPlayer = MockPlayer() + uut = SoloTool(mockPlayer) + + uut.setAbLimitEnable(True) + mockPlayer.position = overflow + uut.addSong(song) + uut.setSong(0) + uut.storeAbLimits(abLimits[0][0], abLimits[0][1]) + uut.loadAbLimits(0) + + uut.setAbLimits(abLimits[1][0], abLimits[1][1]) + uut.tick() + assert mockPlayer.position == abLimits[1][0] + |