aboutsummaryrefslogtreecommitdiffstats
path: root/abcontroller.py
blob: 8c14c0c32279ec1b53d58b97e432e0adb5315852 (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
from collections import namedtuple

_AB = namedtuple("_AB", ["a", "b"])

class ABController:
    def __init__(self):
        self.setPositionCallback = None
        self._limits = dict() # dictionary of all songs
        self._songLimits = None # list of limits for selected song
        self._currentLimits = None # a/b positions of selected limit

    def setCurrentSong(self, path):
        if path not in self._limits:
            self._limits[path] = list()

        self._songLimits = self._limits[path]
        self._currentLimits = None

    def addLimits(self, aLimit, bLimit):
        if self._songLimits is None:
            return

        ab = _AB(aLimit, bLimit)
        self._songLimits.append(ab)

    def setCurrentLimits(self, index):
        if not self._songLimits:
            return

        if index >= 0 and index < len(self._songLimits):
            self._currentLimits = self._songLimits[index]

    def positionChanged(self, position):
        if not self._currentLimits:
            return

        if position > self._currentLimits.b and self.setPositionCallback:
            self.setPositionCallback(self._currentLimits.a)