aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--solo-tool-project/src/solo_tool/notifier.py1
-rw-r--r--solo-tool-project/src/solo_tool/solo_tool.py8
-rw-r--r--solo-tool-project/test/notifier_unittest.py1
-rw-r--r--solo-tool-project/test/solo_tool_integrationtest.py34
-rw-r--r--web-project/src/solo_tool_web.py3
5 files changed, 44 insertions, 3 deletions
diff --git a/solo-tool-project/src/solo_tool/notifier.py b/solo-tool-project/src/solo_tool/notifier.py
index 73b84b7..dadf85c 100644
--- a/solo-tool-project/src/solo_tool/notifier.py
+++ b/solo-tool-project/src/solo_tool/notifier.py
@@ -4,6 +4,7 @@ class Notifier:
PLAYBACK_RATE_EVENT = 2
CURRENT_SONG_EVENT = 3
CURRENT_KEY_POINT_EVENT = 3
+ KEY_POINTS_EVENT = 4
def __init__(self, player):
self._callbacks = dict()
diff --git a/solo-tool-project/src/solo_tool/solo_tool.py b/solo-tool-project/src/solo_tool/solo_tool.py
index 0f47aef..199e2ad 100644
--- a/solo-tool-project/src/solo_tool/solo_tool.py
+++ b/solo-tool-project/src/solo_tool/solo_tool.py
@@ -16,8 +16,9 @@ class SoloTool:
self._song = index
path = self._songs[index]
self._player.setCurrentSong(path)
- self._notifier.notify(Notifier.CURRENT_SONG_EVENT, index)
self._keyPoint = 0.0
+ self._notifier.notify(Notifier.CURRENT_SONG_EVENT, index)
+ self._notifier.notify(Notifier.CURRENT_KEY_POINT_EVENT, index)
@staticmethod
def _keyPointValid(kp: float) -> bool:
@@ -49,13 +50,14 @@ class SoloTool:
def keyPoints(self) -> list[float]:
if self._song is None:
return None
- return self._keyPoints[self._song]
+ return self._keyPoints[self._song].copy()
@keyPoints.setter
def keyPoints(self, new: list[float]) -> None:
if new is not None and self._song is not None:
sanitized = sorted(list(set([p for p in new if SoloTool._keyPointValid(p)])))
self._keyPoints[self._song] = sanitized
+ self._notifier.notify(Notifier.KEY_POINTS_EVENT, sanitized.copy())
@property
def keyPoint(self) -> float:
@@ -127,3 +129,5 @@ class SoloTool:
def registerCurrentKeyPointCallback(self, callback):
self._notifier.registerCallback(Notifier.CURRENT_KEY_POINT_EVENT, callback)
+ def registerKeyPointsCallback(self, callback):
+ self._notifier.registerCallback(Notifier.KEY_POINTS_EVENT, callback)
diff --git a/solo-tool-project/test/notifier_unittest.py b/solo-tool-project/test/notifier_unittest.py
index 115d21a..51d3e48 100644
--- a/solo-tool-project/test/notifier_unittest.py
+++ b/solo-tool-project/test/notifier_unittest.py
@@ -38,6 +38,7 @@ def test_allEvents(uut):
checkEvent(uut, Notifier.PLAYBACK_RATE_EVENT)
checkEvent(uut, Notifier.CURRENT_SONG_EVENT)
checkEvent(uut, Notifier.CURRENT_KEY_POINT_EVENT)
+ checkEvent(uut, Notifier.KEY_POINTS_EVENT)
def test_eventWithoutRegisteredCallbacks(uut):
uut.notify(Notifier.PLAYING_STATE_EVENT, 0)
diff --git a/solo-tool-project/test/solo_tool_integrationtest.py b/solo-tool-project/test/solo_tool_integrationtest.py
index 2a55df9..3d7d20f 100644
--- a/solo-tool-project/test/solo_tool_integrationtest.py
+++ b/solo-tool-project/test/solo_tool_integrationtest.py
@@ -405,3 +405,37 @@ def test_currentKeyPointNotification(uut):
uut.keyPoint = 0.5
assert not called
+def test_keyPointsNotification(uut):
+ called = False
+ receivedValue = None
+ def callback(value):
+ nonlocal called, receivedValue
+ called = True
+ receivedValue = value
+
+ uut.registerKeyPointsCallback(callback)
+ assert not called
+
+ song = "test.flac"
+ uut.addSong(song)
+ uut.song = 0
+ assert not called
+
+ # Adding list of key points triggers a notification
+ uut.keyPoints = [0.2, 0.4]
+ assert called
+ assert receivedValue == [0.2, 0.4]
+ called = False
+
+ # Same list does trigger a notification again
+ uut.keyPoints = [0.2, 0.4]
+ assert called
+ assert receivedValue == [0.2, 0.4]
+ called = False
+
+ # Incrementing list of key points triggers a notification after sanitization
+ uut.keyPoints += [0.2, None, 0.1]
+ assert called
+ assert receivedValue == [0.1, 0.2, 0.4]
+ called = False
+
diff --git a/web-project/src/solo_tool_web.py b/web-project/src/solo_tool_web.py
index 6616d82..e3dd9aa 100644
--- a/web-project/src/solo_tool_web.py
+++ b/web-project/src/solo_tool_web.py
@@ -20,9 +20,10 @@ def keyPointTables() -> None:
for kp in st._keyPoints[i]:
ui.item(f"{kp:0.2}", on_click=handlers.setKeyPoint(st, kp)).props('clickable v-ripple')
+st.registerKeyPointsCallback(lambda new: keyPointTables.refresh())
+
def addKeyPoint() -> None:
st.keyPoints += [st.keyPoint]
- keyPointTables.refresh()
def main():
fullscreen = ui.fullscreen()