From 1647bd1b883d6a4ee720ca70a22c7f0112829357 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Mon, 24 Mar 2025 17:12:48 +0100 Subject: [PATCH] commit 96 --- .../theaterdsl/device/DynamicValue.kt | 18 ++++++++++++++++++ .../de/moritzruth/theaterdsl/show/Runner.kt | 15 +++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/de/moritzruth/theaterdsl/device/DynamicValue.kt b/src/main/kotlin/de/moritzruth/theaterdsl/device/DynamicValue.kt index 25a316e..6984a35 100644 --- a/src/main/kotlin/de/moritzruth/theaterdsl/device/DynamicValue.kt +++ b/src/main/kotlin/de/moritzruth/theaterdsl/device/DynamicValue.kt @@ -16,6 +16,7 @@ import kotlin.time.TimeSource interface DynamicValue { fun reset() + fun skipTransition() fun getCurrentValue(): T } @@ -71,6 +72,14 @@ abstract class DoubleDV(private val initialStaticValue: Double) : DynamicValu state = State.Static(initialStaticValue) } + override fun skipTransition() { + state = when (val s = state) { + is State.Fade -> State.Static(s.end) + is State.PulseOnce -> State.Static(s.end) + else -> s + } + } + override fun getCurrentValue(): T { val elapsedTime = stateChangeMark.elapsedNow() @@ -215,6 +224,8 @@ class ConcreteDV(private val initialStaticValue: T) : DynamicValue { state = State.Static(initialStaticValue) } + override fun skipTransition() {} + override fun getCurrentValue(): T = when (val s = state) { is State.Static -> s.value } @@ -252,6 +263,13 @@ class ColorDV(private val initialStaticValue: Color = Color.WHITE) : DynamicValu state = State.Static(initialStaticValue) } + override fun skipTransition() { + state = when(val s = state) { + is State.Fade -> State.Static(s.end) + else -> s + } + } + override fun getCurrentValue(): Color { val elapsedTime = stateChangeMark.elapsedNow() diff --git a/src/main/kotlin/de/moritzruth/theaterdsl/show/Runner.kt b/src/main/kotlin/de/moritzruth/theaterdsl/show/Runner.kt index 536a1d4..ff38b4a 100644 --- a/src/main/kotlin/de/moritzruth/theaterdsl/show/Runner.kt +++ b/src/main/kotlin/de/moritzruth/theaterdsl/show/Runner.kt @@ -81,10 +81,6 @@ class ShowContext( else -> it.copy(position = position, isLightBehindCurtainOn = isLightBehindCurtainOn) } } - - if (step.cue is StepCue.MusicStart) { - logger.info { "Music started: ${step.cue.title} (${step.cue.duration.inWholeSeconds}s)" } - } } } @@ -157,6 +153,8 @@ fun CoroutineScope.startStepRunning(context: ShowContext) = launch { context.stateFlow.map { it.position }.distinctUntilChanged().collect { position -> context.outputDataFreeze.incrementAndGet() + val isJump = context.show.getNextValidPosition(lastPosition) != position + if (position < lastPosition) { context.devices.forEach { it.dvs.forEach(DynamicValue<*>::reset) } lastPosition = ShowPosition.START @@ -164,12 +162,13 @@ fun CoroutineScope.startStepRunning(context: ShowContext) = launch { while (lastPosition != position) { lastPosition = context.show.getNextValidPosition(lastPosition) ?: break - val step = context.show.acts[lastPosition] + lastStepJob?.cancelAndJoin() + if (isJump) context.devices.forEach { it.dvs.forEach(DynamicValue<*>::skipTransition) } + lastStepJob = launch(SupervisorJob(currentCoroutineContext().job), CoroutineStart.UNDISPATCHED) { val runContext = object : StepRunContext, CoroutineScope by this {} - step.runner?.let { runContext.it() } } } @@ -200,8 +199,8 @@ private fun CoroutineScope.startWebsocketServer(context: ShowContext) = launch { embeddedServer(CIO, port = 80) { install(WebSockets) { - pingPeriod = 10.seconds - timeout = 15.seconds + pingPeriod = 2.seconds + timeout = 5.seconds maxFrameSize = Long.MAX_VALUE }