diff options
-rw-r--r-- | blc2/constants.py | 1 | ||||
-rw-r--r-- | blc2/functions/chaser.py | 29 | ||||
-rw-r--r-- | blc2/functions/multichasertrack.py | 10 | ||||
-rw-r--r-- | blc2/workspace.py | 7 |
4 files changed, 44 insertions, 3 deletions
diff --git a/blc2/constants.py b/blc2/constants.py index bb207f9..eae7c18 100644 --- a/blc2/constants.py +++ b/blc2/constants.py @@ -66,6 +66,7 @@ SCENE = "Scene" AUDIO = "Audio" CHASER = "Chaser" CHASERSTEP = "ChaserStep" +MULTICHASERTRACK = "MultiChaserTrack" FUNCTION = "Function" INTERNAL = "Internal" diff --git a/blc2/functions/chaser.py b/blc2/functions/chaser.py index c63f8c4..796ea34 100644 --- a/blc2/functions/chaser.py +++ b/blc2/functions/chaser.py @@ -264,7 +264,7 @@ class Chaser(Function): if e.tag != BXW+"function": raise LoadError("Invalid function tag") - elif e.get("type") != CHASER: + elif e.get("type") != cls.type: raise LoadError("Load delegated to wrong class (this is a bug)") id_ = cls.int_or_none(e.get("id")) @@ -273,6 +273,8 @@ class Chaser(Function): name = e.get("name") advance_mode = e.get("advance-mode") + if advance_mode is None: + advance_mode = ONESHOT if advance_mode not in (LOOP, RANDOM, ONESHOT): raise ValueError("Invalid advance mode") @@ -281,4 +283,29 @@ class Chaser(Function): for step in e: ChaserStep.deserialize(w, step, chaser) + @classmethod + def deserialize(cls, w, e): + from .chaserstep import ChaserStep + + if e.tag != BXW+"function": + raise LoadError("Invalid function tag") + elif e.get("type") != cls.type: + raise LoadError("Load delegated to wrong class (this is a bug)") + + id_ = cls.int_or_none(e.get("id")) + if id_ is None: + raise LoadError("Function tag has invalid/missing ID") + + name = e.get("name") + advance_mode = e.get("advance-mode") + if advance + if advance_mode not in (LOOP, RANDOM, ONESHOT): + raise ValueError("Invalid advance mode") + + chaser = cls(w=w, id_=id_, name=name, advance_mode=advance_mode) + + for step in e: + ChaserStep.deserialize(w, step, chaser) + + return chaser return chaser diff --git a/blc2/functions/multichasertrack.py b/blc2/functions/multichasertrack.py new file mode 100644 index 0000000..159e885 --- /dev/null +++ b/blc2/functions/multichasertrack.py @@ -0,0 +1,10 @@ +from .chaser import Chaser +from ..constants import MULTICHASERTRACK + +class MultiChaserTrack(Chaser): + type = MULTICHASERTRACK + + def __init__(self, w, id_ = None, name = None, advance_mode = ONESHOT): + if advance_mode != ONESHOT: + raise ValueError("MultiChaserTrack can only have advance_mode ONESHOT") + super().__init__(w=w, id_=id_, name=name, advance_mode=advance_mode) diff --git a/blc2/workspace.py b/blc2/workspace.py index 2f2cf79..bbaeda2 100644 --- a/blc2/workspace.py +++ b/blc2/workspace.py @@ -8,7 +8,7 @@ import json import subprocess as subp import xml.etree.ElementTree as et -from .constants import AUDIO, SCENE, BXW, CHASER, CHASERSTEP +from .constants import AUDIO, SCENE, BXW, CHASER, CHASERSTEP, MULTICHASERTRACK, MULTICHASERSTEP from .functions.function import Function from .exceptions import LoadError from .interfaces import XMLSerializable @@ -217,6 +217,7 @@ class Workspace(XMLSerializable): from .functions.scene import Scene from .functions.audio import Audio from .functions.chaser import Chaser + from .functions.multichaser import MultiChaser if e.tag != BXW+"workspace": raise LoadError("Root tag must be workspace") @@ -248,6 +249,8 @@ class Workspace(XMLSerializable): Scene.deserialize(w, function) elif type_ == CHASER: Chaser.deserialize(w, function) + elif type_ == MULTICHASER: + MultiChaser.deserialize(w, function) else: raise LoadError("Unknown function type \"%s\"" % type_) @@ -272,7 +275,7 @@ class Workspace(XMLSerializable): all_f = list(self.functions.values()) while all_f: f = all_f.pop(0) - if f.type == CHASERSTEP: + if f.type in (CHASERSTEP, MULTICHASERTRACK): continue elif f.type in (AUDIO, SCENE): f_order.append(f) |