commit 96

This commit is contained in:
Moritz Ruth 2025-03-24 17:12:48 +01:00
parent 456e46cabf
commit 1647bd1b88
Signed by: moritzruth
GPG key ID: C9BBAB79405EE56D
2 changed files with 25 additions and 8 deletions

View file

@ -16,6 +16,7 @@ import kotlin.time.TimeSource
interface DynamicValue<T> { interface DynamicValue<T> {
fun reset() fun reset()
fun skipTransition()
fun getCurrentValue(): T fun getCurrentValue(): T
} }
@ -71,6 +72,14 @@ abstract class DoubleDV<T>(private val initialStaticValue: Double) : DynamicValu
state = State.Static(initialStaticValue) 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 { override fun getCurrentValue(): T {
val elapsedTime = stateChangeMark.elapsedNow() val elapsedTime = stateChangeMark.elapsedNow()
@ -215,6 +224,8 @@ class ConcreteDV<T>(private val initialStaticValue: T) : DynamicValue<T> {
state = State.Static(initialStaticValue) state = State.Static(initialStaticValue)
} }
override fun skipTransition() {}
override fun getCurrentValue(): T = when (val s = state) { override fun getCurrentValue(): T = when (val s = state) {
is State.Static -> s.value is State.Static -> s.value
} }
@ -252,6 +263,13 @@ class ColorDV(private val initialStaticValue: Color = Color.WHITE) : DynamicValu
state = State.Static(initialStaticValue) 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 { override fun getCurrentValue(): Color {
val elapsedTime = stateChangeMark.elapsedNow() val elapsedTime = stateChangeMark.elapsedNow()

View file

@ -81,10 +81,6 @@ class ShowContext(
else -> it.copy(position = position, isLightBehindCurtainOn = isLightBehindCurtainOn) 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.stateFlow.map { it.position }.distinctUntilChanged().collect { position ->
context.outputDataFreeze.incrementAndGet() context.outputDataFreeze.incrementAndGet()
val isJump = context.show.getNextValidPosition(lastPosition) != position
if (position < lastPosition) { if (position < lastPosition) {
context.devices.forEach { it.dvs.forEach(DynamicValue<*>::reset) } context.devices.forEach { it.dvs.forEach(DynamicValue<*>::reset) }
lastPosition = ShowPosition.START lastPosition = ShowPosition.START
@ -164,12 +162,13 @@ fun CoroutineScope.startStepRunning(context: ShowContext) = launch {
while (lastPosition != position) { while (lastPosition != position) {
lastPosition = context.show.getNextValidPosition(lastPosition) ?: break lastPosition = context.show.getNextValidPosition(lastPosition) ?: break
val step = context.show.acts[lastPosition] val step = context.show.acts[lastPosition]
lastStepJob?.cancelAndJoin() lastStepJob?.cancelAndJoin()
if (isJump) context.devices.forEach { it.dvs.forEach(DynamicValue<*>::skipTransition) }
lastStepJob = launch(SupervisorJob(currentCoroutineContext().job), CoroutineStart.UNDISPATCHED) { lastStepJob = launch(SupervisorJob(currentCoroutineContext().job), CoroutineStart.UNDISPATCHED) {
val runContext = object : StepRunContext, CoroutineScope by this {} val runContext = object : StepRunContext, CoroutineScope by this {}
step.runner?.let { runContext.it() } step.runner?.let { runContext.it() }
} }
} }
@ -200,8 +199,8 @@ private fun CoroutineScope.startWebsocketServer(context: ShowContext) = launch {
embeddedServer(CIO, port = 80) { embeddedServer(CIO, port = 80) {
install(WebSockets) { install(WebSockets) {
pingPeriod = 10.seconds pingPeriod = 2.seconds
timeout = 15.seconds timeout = 5.seconds
maxFrameSize = Long.MAX_VALUE maxFrameSize = Long.MAX_VALUE
} }