From a55027e8e3c6a041f4ad7477de9c4d7771a0e197 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 19 Sep 2025 12:01:14 +0200 Subject: [PATCH] Base structure for engine --- src/engine.py | 42 +++++++++++++++++++++++++++++++++++++++--- src/models.py | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/engine.py b/src/engine.py index 929ac9f..a35bd58 100644 --- a/src/engine.py +++ b/src/engine.py @@ -1,4 +1,40 @@ -class Engine: - """Calculates a sequence.""" +from decimal import Decimal +import logging - +from models import EngineFixture, Flickr + + +class Engine: + """Render a lightshow.""" + + def __init__(self, flickr: Flickr, apis: dict[str, str]) -> None: + self.time: Decimal = Decimal.from_float(0) + self.fixtures: dict[str, EngineFixture] = { + f.id: EngineFixture(f) for s in flickr.spaces for f in s.fixtures + } + self.flickr = flickr + self.apis = apis + + # Validate fixture APIs + for id, f in self.fixtures.items(): + if f.fixture.api not in self.apis.keys(): + logging.warning( + f"Fixture API unknown [{f.fixture.api}]. Fixture will be removed. Fixture ID [{f.fixture.id}]. Known APIs [{', '.join([a for a in self.apis.keys()])}]." + ) + del self.fixtures[id] + + def next(self, step_size: Decimal): + """Calculate light values for next step in time. Step size in seconds.""" + prev_time = self.time + self.time += step_size + + for s in self.flickr.sequences: + for t in s.tracks: + # TODO: Calculate new state + pass + + def propagate(self): + """Forward new fixture states to APIs.""" + for f in self.fixtures.values(): + api = self.apis[f.fixture.api] + # TODO: Pass update to API diff --git a/src/models.py b/src/models.py index eebbbe6..e7e5ad4 100644 --- a/src/models.py +++ b/src/models.py @@ -37,6 +37,12 @@ class Fixture: name: str """Human readable name.""" + api: str + """API this fixture has to be used with.""" + + api_id: str + """Custom id for specific API.""" + capabilities: Capabilities """Which dynamic capabilities does the fixture have.""" @@ -53,6 +59,29 @@ class Fixture: """In range [0,1], how exposed is the light source of the fixture. 0: no exposure. 1: full exposure.""" +@dataclass +class EngineFixture: + """A fixture for engine use during rendering.""" + + fixture: Fixture + """Reference meta data for fixture.""" + + on: bool = False + """On state.""" + + bri: float = 0 + """Brightness state.""" + + hue: float = 0 + """Hue state.""" + + sat: float = 0 + """Saturation state.""" + + transition: float = 0 + """Transition time in seconds.""" + + @dataclass_json @dataclass class Space: @@ -67,9 +96,6 @@ class Space: fixtures: list[Fixture] """All fixtures present in the space.""" - center: SpaceVector - """A reference point in the space from which the audience perspective might be assumed.""" - version: str = "1" """Metatag to track version of datastructure.""" @@ -164,6 +190,8 @@ if __name__ == "__main__": Fixture( "98iwd", "Cool Light", + "hue", + "9jsif", Capabilities.BRIGHTNESS, SpaceVector(), SpaceVector(), @@ -171,7 +199,6 @@ if __name__ == "__main__": 0.5, ) ], - SpaceVector(), ) ], [