from collections.abc import Callable from solo_tool.solo_tool import SoloTool def changeSong(st: SoloTool, delta: int) -> Callable[[], None]: def f(): if st.song is None: st.song = 0 else: st.song += delta return f def seekRelative(st: SoloTool, delta: float) -> Callable[[], None]: def f(): st.position += delta return f def positionToKeyPoint(st: SoloTool) -> Callable[[], None]: def f(): st.keyPoint = st.position 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