aboutsummaryrefslogtreecommitdiffstats
path: root/abcontroller.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-12-21 15:23:27 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-12-21 15:23:27 +0100
commitc1bfcc6064b3a22c76b986d9339daf6cbd403c80 (patch)
tree1209bcf04f84c100cc6e8affc0cdd6c099f21bd4 /abcontroller.py
parent78e14031b50628566ef71666d37d538268678ba8 (diff)
Added more AB controller tests and features
Diffstat (limited to 'abcontroller.py')
-rw-r--r--abcontroller.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/abcontroller.py b/abcontroller.py
index 8c14c0c..302bc9e 100644
--- a/abcontroller.py
+++ b/abcontroller.py
@@ -3,25 +3,34 @@ from collections import namedtuple
_AB = namedtuple("_AB", ["a", "b"])
class ABController:
- def __init__(self):
+ def __init__(self, enabled=True):
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
+ self._enabled = enabled
- def setCurrentSong(self, path):
+ def _ensureSongExists(self, path):
if path not in self._limits:
self._limits[path] = list()
+ def setCurrentSong(self, path):
+ self._ensureSongExists(path)
self._songLimits = self._limits[path]
self._currentLimits = None
- def addLimits(self, aLimit, bLimit):
- if self._songLimits is None:
+ def addLimits(self, aLimit, bLimit, song=None):
+ if song is not None:
+ self._ensureSongExists(song)
+ songLimits = self._limits[song]
+ else:
+ songLimits = self._songLimits
+
+ if songLimits is None:
return
ab = _AB(aLimit, bLimit)
- self._songLimits.append(ab)
+ songLimits.append(ab)
def setCurrentLimits(self, index):
if not self._songLimits:
@@ -34,5 +43,8 @@ class ABController:
if not self._currentLimits:
return
- if position > self._currentLimits.b and self.setPositionCallback:
+ if position > self._currentLimits.b and self.setPositionCallback and self._enabled:
self.setPositionCallback(self._currentLimits.a)
+
+ def setEnable(self, enable):
+ self._enabled = enable