aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-21 22:56:14 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-21 22:56:14 +0100
commit6bdde28f33b3e27349731291ee94c043ec238e4d (patch)
tree1f165897eba916bf9293f2ecf23ec1767ffadb5c
parent663970d0165e226147d95fb92c617714dfbd7553 (diff)
AB controller integration test added
-rw-r--r--abcontroller.py5
-rw-r--r--solo_tool.py22
-rw-r--r--solo_tool_integrationtest.py48
3 files changed, 61 insertions, 14 deletions
diff --git a/abcontroller.py b/abcontroller.py
index 9d232c1..e9eace4 100644
--- a/abcontroller.py
+++ b/abcontroller.py
@@ -3,8 +3,8 @@ from collections import namedtuple
_AB = namedtuple("_AB", ["a", "b"])
class ABController:
- def __init__(self, enabled=True):
- self.setPositionCallback = None
+ def __init__(self, enabled=True, callback=None):
+ 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,7 +42,6 @@ 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)
diff --git a/solo_tool.py b/solo_tool.py
index b1edba6..ff0f768 100644
--- a/solo_tool.py
+++ b/solo_tool.py
@@ -7,11 +7,15 @@ class SoloTool:
def __init__(self, player=None):
self._player = Player() if player is None else player
self._playlist = Playlist(self._playlistCallback)
- self._abController = ABController()
+ self._abController = ABController(callback=self._abControllerCallback)
self._sessionManager = SessionManager(self._playlist, self._abController)
def _playlistCallback(self, path):
- self._player.setCurrentSong("")
+ self._player.setCurrentSong(path)
+ self._abController.setCurrentSong(path)
+
+ def _abControllerCallback(self, position):
+ self._player.setPlaybackPosition(position)
def addSong(self, path):
self._sessionManager.addSong(path)
@@ -19,6 +23,20 @@ class SoloTool:
def setSong(self, index):
self._playlist.setCurrentSong(index)
+ def addAbLimit(self, aLimit, bLimit):
+ self._abController.addLimits(aLimit, bLimit)
+
+ def setAbLimit(self, index):
+ self._abController.setCurrentLimits(0)
+
+ def tick(self):
+ position = self._player.getPlaybackPosition()
+ self._abController.positionChanged(position)
+
+ def loadSession(self, path):
+ with open(path, "r") as f:
+ self._sessionManager.loadSession(f)
+
# Playback control
def play(self):
self._player.play()
diff --git a/solo_tool_integrationtest.py b/solo_tool_integrationtest.py
index 561778b..b3a0978 100644
--- a/solo_tool_integrationtest.py
+++ b/solo_tool_integrationtest.py
@@ -43,15 +43,6 @@ class MockPlayer():
def setCurrentSong(self, path):
self.currentSong = path
-def test_addAndSetSong():
- song = "/path/to/song"
- mockPlayer = MockPlayer()
-
- uut = SoloTool(mockPlayer)
-
- uut.addSong(song)
- uut.setSong(0)
-
def test_playerControls():
mockPlayer = MockPlayer()
uut = SoloTool(mockPlayer)
@@ -75,3 +66,42 @@ def test_playerControls():
assert mockPlayer.volume == 1.0
uut.setPlaybackVolume(0.5)
assert mockPlayer.volume == 0.5
+
+def test_addAndSetSong():
+ song = "test.flac"
+ mockPlayer = MockPlayer()
+ uut = SoloTool(mockPlayer)
+
+ uut.addSong(song)
+ assert mockPlayer.currentSong == ""
+
+ uut.setSong(0)
+ assert mockPlayer.currentSong == song
+
+def test_addAndSetAbLimit():
+ song = "test.flac"
+ abLimit = [0.2, 0.4]
+ mockPlayer = MockPlayer()
+ uut = SoloTool(mockPlayer)
+
+ uut.addSong(song)
+ uut.setSong(0)
+
+ uut.addAbLimit(abLimit[0], abLimit[1])
+
+ mockPlayer.position = 0.0
+ uut.tick()
+ assert mockPlayer.position == 0.0
+
+ mockPlayer.position = 0.5
+ uut.tick()
+ assert mockPlayer.position == 0.5
+
+ uut.setAbLimit(0)
+
+ uut.tick()
+ assert mockPlayer.position == 0.2
+
+ uut.tick()
+ assert mockPlayer.position == 0.2
+