aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/src/solo_tool/handlers.py
blob: 1e0e22c0dfebd3ad0e2353d79f44eee8a73c4a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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:
            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 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