aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/src/solo_tool/solo_tool.py
diff options
context:
space:
mode:
Diffstat (limited to 'solo-tool-project/src/solo_tool/solo_tool.py')
-rw-r--r--solo-tool-project/src/solo_tool/solo_tool.py29
1 files changed, 10 insertions, 19 deletions
diff --git a/solo-tool-project/src/solo_tool/solo_tool.py b/solo-tool-project/src/solo_tool/solo_tool.py
index 884721b..97c3495 100644
--- a/solo-tool-project/src/solo_tool/solo_tool.py
+++ b/solo-tool-project/src/solo_tool/solo_tool.py
@@ -40,9 +40,10 @@ class SoloTool:
@song.setter
def song(self, new: int) -> None:
- if new is None or new < 0 or new >= len(self._songs):
- raise ValueError()
- if new != self._song:
+ if new is not None \
+ and new >= 0 \
+ and new < len(self._songs) \
+ and new != self._song:
self._updateSong(new)
@property
@@ -53,9 +54,7 @@ class SoloTool:
@keyPoints.setter
def keyPoints(self, new: list[float]) -> None:
- if new is None:
- raise ValueError()
- if self._song is not 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
@@ -65,9 +64,7 @@ class SoloTool:
@keyPoint.setter
def keyPoint(self, new: float) -> None:
- if not SoloTool._keyPointValid(new):
- raise ValueError()
- if self._song is not None and new != self._keyPoint:
+ if self._song is not None and SoloTool._keyPointValid(new) and new != self._keyPoint:
self._keyPoint = new
self._notifier.notify(Notifier.CURRENT_KEY_POINT_EVENT, new)
@@ -92,9 +89,7 @@ class SoloTool:
@rate.setter
def rate(self, new: float) -> None:
- if new is None or new <= 0.0:
- raise ValueError()
- if new != self._player.getPlaybackRate():
+ if new is not None and new >= 0.0 and new != self._player.getPlaybackRate():
self._player.setPlaybackRate(new)
self._notifier.notify(Notifier.PLAYBACK_RATE_EVENT, new)
@@ -104,9 +99,7 @@ class SoloTool:
@volume.setter
def volume(self, new: float) -> None:
- if new is None or new < 0.0:
- raise ValueError()
- if new != self._player.getPlaybackVolume():
+ if new is not None and new >= 0.0 and new != self._player.getPlaybackVolume():
self._player.setPlaybackVolume(new)
self._notifier.notify(Notifier.PLAYBACK_VOLUME_EVENT, new)
@@ -116,11 +109,9 @@ class SoloTool:
@position.setter
def position(self, new: float) -> None:
- if new is None or new < 0.0 or new >= 1.0:
- raise ValueError()
# TODO stop playback before changing position?
- if new != self._player.getPlaybackPosition():
- self._player.setPlaybackPosition(new)
+ if new is not None and new != self._player.getPlaybackPosition():
+ self._player.setPlaybackPosition(min(max(0.0, new), 1.0))
def registerPlayingStateCallback(self, callback):
self._notifier.registerCallback(Notifier.PLAYING_STATE_EVENT, callback)