From 4071b2156c319876bfeeeea7376afb5f5d520467 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 15 Jan 2024 12:55:05 +0100 Subject: [PATCH] flash --- cdoseaplay/lights.py | 83 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/cdoseaplay/lights.py b/cdoseaplay/lights.py index 4c7b09f..04bcb4b 100755 --- a/cdoseaplay/lights.py +++ b/cdoseaplay/lights.py @@ -45,6 +45,19 @@ LIGHTS = { 9: (channels(0, 0.9), 0.1), } +FLASHES = { + 0: (0.0, 9), + 1: (0.1, 8), + 2: (0.2, 7), + 3: (0.3, 6), + 4: (0.4, 5), + 5: (0.5, 4), + 6: (0.6, 3), + 7: (0.7, 2), + 8: (0.8, 1), + 9: (0.9, 0.1), +} + CURRENT_STATE = [0] * 16 @@ -102,15 +115,75 @@ def fade_to(target, duration): sender.stop() -def switch(state): +def flash(brightness, duration, flashes, flash_duration=1, base=0): + sender = sacn.sACNsender() + sender.start() + universe = 1 + sender.activate_output(universe) + sender[1].multicast = True + sender[1].dmx_data = [0] * 16 + + def fade_to(start, end, duration): + distance = end - start + steps = int(duration * 10) + if not steps: + steps = 1 + step = duration/steps + delta = distance/steps + current = start + value = current + switch = 0 + while steps: + switch += 1 + value += delta + n = int(round(value)) + if n != current: + current = n + old = sender[1].dmx_data[:16] + target = [n] * 16 + if switch % 2: + a = target + b = old + else: + a = old + b = target + sender[1].dmx_data = [a[x] if x % 2 else b[x] for x in range(16)] + time.sleep(step) + steps -= 1 + + step = duration / flashes + if step < 0: + step = 0 + while flashes: + fade_to(base, brightness, flash_duration) + sender[1].dmx_data = [0] * 16 + time.sleep(step) + flashes -= 1 + sender[1].dmx_data = [0] * 16 + time.sleep(0.1) + sender.stop() + + +def switch(state, seq): if config.lanbox: import lanbox lb = lanbox.Lanbox() lb.layerGo(state) else: - lights, duration = LIGHTS[state] - brightness = lights['7'] - fade_to(brightness, duration) + brightness, duration = FLASHES[state] + brightness = int(brightness * 255) + #fade_to(brightness, duration) + flashes = seq() + if flashes: + base = seq() + if base: + base = brightness/base + flash_duration = 0.01+seq()/24 + while flashes * flash_duration > duration: + flash_duration = flash_duration/2 + print("flash brightness: %s duration: %s flashes: %s flash duration %s base: %s" % (brightness, duration, flashes, flash_duration, base)) + flash(brightness, duration, flashes, flash_duration, base=base) + if __name__ == '__main__': path = sys.argv[1] @@ -135,5 +208,5 @@ if __name__ == '__main__': if not no_sleep: time.sleep(sleep) print("letter", letter, "offset", letter_offset, "light", light, "cue", letter_offset + light) - switch(light + letter_offset) + switch(light + letter_offset, seq) pos += sleep