Add initial support for DMX lighting

This commit is contained in:
2025-08-08 03:36:23 +01:00
parent 99ddcfbc6b
commit cfb6c517c1
4 changed files with 326 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
import events
from item import Item
import dmx
class MakeItems:
def __new__(cls, config):
@@ -45,3 +46,73 @@ class MakeSet:
raise KeyError('{} not in items'.format(item))
return config
class MakeFixtureTypes:
def __new__(cls, config):
def parse_range(src):
(a, b) = src.split('-')
return (int(a), int(b))
types = {}
for ftype in config:
channels = {}
for channel in config[ftype].keys():
dmxchannel = int(config[ftype][channel]['channel'])
finechannel = config[ftype][channel].get('fine-channel')
if finechannel is not None:
finechannel = int(finechannel)
fade = config[ftype][channel].get('fade', True)
rangesrc = config[ftype][channel]['range']
if isinstance(rangesrc, dict):
range = {}
for entry in rangesrc:
range[entry] = parse_range(rangesrc[entry])
else:
range = parse_range(rangesrc)
channels[channel] = {'channel' : dmxchannel, 'fine-channel' : finechannel, 'range' : range, 'fade' : fade}
types[ftype] = dmx.FixtureType(channels)
return types
class MakeFixtures:
def __new__(cls, config, fixture_types):
fixtures = {}
for fixture in config:
dmxch = config[fixture]['dmx']
type = config[fixture]['type']
if type not in fixture_types:
raise KeyError('{} not in fixture_types'.format(type))
fixtures[fixture] = dmx.Fixture(dmxch, fixture_types[type])
return fixtures
class MakeGroups:
def __new__(cls, config, fixtures):
groups = {}
for group in config:
fobjects = []
for fixture in config[group]:
if fixture not in fixtures:
raise KeyError('{} not in fixtures'.format(fixture))
fobjects.append(fixtures[fixture])
# XXX process modifiers
groups[group] = dmx.Group(fobjects)
return groups
class MakeScenes:
def __new__(cls, config, fixtures, groups):
scenes = {}
for scene in config:
objects = {}
for name in config[scene].keys():
if name in groups:
obj = groups[name]
elif name in fixtures:
obj = fixtures[name]
else:
raise KeyError('{} is not a group or a fixture'.format(name))
for channel in config[scene][name].keys():
if not obj.is_channel(channel):
raise KeyError('{} is not a channel within {}'.format(channel, name))
objects[name] = (obj, config[scene][name])
scenes[scene] = dmx.Scene(objects)
return scenes