diff options
author | Eddy Pedroni <epedroni@pm.me> | 2025-02-25 14:58:30 +0100 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2025-02-25 14:58:30 +0100 |
commit | bb94fb1ab32732a354f7df68bf0a056d233b2b69 (patch) | |
tree | 82607687a76cb1f049d225bc3151c33c54f9d61c /solo-tool-project/src/solo_tool/solo_tool.py | |
parent | 62490ac2be04aa3b819222f11389e0549f5909e9 (diff) |
Refactor key point implementation and tests
Diffstat (limited to 'solo-tool-project/src/solo_tool/solo_tool.py')
-rw-r--r-- | solo-tool-project/src/solo_tool/solo_tool.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/solo-tool-project/src/solo_tool/solo_tool.py b/solo-tool-project/src/solo_tool/solo_tool.py index bc20013..0489517 100644 --- a/solo-tool-project/src/solo_tool/solo_tool.py +++ b/solo-tool-project/src/solo_tool/solo_tool.py @@ -13,12 +13,18 @@ class SoloTool: self._keyPoint = None def _updateSong(self, index): + previousSong = self._song self._song = index - path = self._songs[index] - self._player.setCurrentSong(path) - self._keyPoint = 0.0 + self._player.setCurrentSong(self._songs[index]) self._notifier.notify(Notifier.CURRENT_SONG_EVENT, index) - self._notifier.notify(Notifier.CURRENT_KEY_POINT_EVENT, index) + + previousKp = self._keyPoint + self._keyPoint = self.keyPoints[0] if len(self.keyPoints) > 0 else 0.0 + if previousKp != self._keyPoint: + self._notifier.notify(Notifier.CURRENT_KEY_POINT_EVENT, self._keyPoint) + + if previousSong is None or self._keyPoints[previousSong] != self._keyPoints[index]: + self._notifier.notify(Notifier.KEY_POINT_LIST_EVENT, self.keyPoints) @staticmethod def _keyPointValid(kp: float) -> bool: @@ -61,8 +67,8 @@ class SoloTool: 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()) + self._keyPoints[self._song] = sanitized.copy() + self._notifier.notify(Notifier.KEY_POINT_LIST_EVENT, self.keyPoints) @property def keyPoint(self) -> float: @@ -125,6 +131,12 @@ class SoloTool: def registerSongListCallback(self, callback): self._notifier.registerCallback(Notifier.SONG_LIST_EVENT, callback) + def registerKeyPointSelectionCallback(self, callback): + self._notifier.registerCallback(Notifier.CURRENT_KEY_POINT_EVENT, callback) + + def registerKeyPointListCallback(self, callback): + self._notifier.registerCallback(Notifier.KEY_POINT_LIST_EVENT, callback) + def registerPlayingStateCallback(self, callback): self._notifier.registerCallback(Notifier.PLAYING_STATE_EVENT, callback) @@ -134,8 +146,3 @@ class SoloTool: def registerRateCallback(self, callback): self._notifier.registerCallback(Notifier.PLAYBACK_RATE_EVENT, callback) - 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) |