diff options
Diffstat (limited to 'solo-tool-project/src/solo_tool/handlers.py')
-rw-r--r-- | solo-tool-project/src/solo_tool/handlers.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/solo-tool-project/src/solo_tool/handlers.py b/solo-tool-project/src/solo_tool/handlers.py index 13e982b..1e0e22c 100644 --- a/solo-tool-project/src/solo_tool/handlers.py +++ b/solo-tool-project/src/solo_tool/handlers.py @@ -2,6 +2,14 @@ from collections.abc import Callable from solo_tool.solo_tool import SoloTool +def playPause(st: SoloTool) -> Callable[[], None]: + def f(): + if st.playing: + st.pause() + else: + st.play() + return f + def changeSong(st: SoloTool, delta: int) -> Callable[[], None]: def f(): if st.song is None: @@ -19,3 +27,37 @@ def positionToKeyPoint(st: SoloTool) -> Callable[[], None]: def f(): st.keyPoint = st.position return f + +def setKeyPoint(st: SoloTool, kp: float) -> Callable[[], None]: + def f(): + st.keyPoint = kp + return f + +def changeKeyPoint(st: SoloTool, delta: int) -> Callable[[], None]: + from bisect import bisect_right, bisect_left + def f(): + if delta > 0: + pivot = bisect_right(st.keyPoints, st.keyPoint) - 1 + elif delta < 0: + pivot = bisect_left(st.keyPoints, st.keyPoint) - 1 + else: + return + new = max(min(pivot + delta, len(st.keyPoints) - 1), 0) + st.keyPoint = st.keyPoints[new] + return f + +def rateAbsolute(st: SoloTool, value: float) -> Callable[[], None]: + def f(): + st.rate = value + return f + +def rateRelative(st: SoloTool, delta: float) -> Callable[[], None]: + def f(): + st.rate += delta + return f + +def volumeAbsolute(st: SoloTool, value: float) -> Callable[[], None]: + def f(): + st.volume = value + return f + |