diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2021-12-21 08:16:55 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2021-12-21 08:16:55 +0100 |
commit | 182a14f4b9aec4722f7f94ab44bf57356c6d71aa (patch) | |
tree | c2c3a683184a53ddc141fe33e02fc934b793d196 /abcontroller.py | |
parent | 1ca1fbcc001e27f46fc033f44ad5459bd0351bc9 (diff) |
Added AB controller with some tests, minor refactor to playlist
Diffstat (limited to 'abcontroller.py')
-rw-r--r-- | abcontroller.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/abcontroller.py b/abcontroller.py new file mode 100644 index 0000000..8c14c0c --- /dev/null +++ b/abcontroller.py @@ -0,0 +1,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) |