Skip to content

Commit

Permalink
Normalizing color models of twinky and klanglicht - part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sknull committed Dec 8, 2024
1 parent df5f139 commit 93e1096
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ShellyColor(
this.deviceGain = gain
}

override fun getRgbColor(): RGBColor = color.clone()
override fun toRgbColor(): RGBColor = color.clone()

override fun setRgbColor(rgbColor: RGBColor) {
color = rgbColor.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class XledFrameDmxFadeable(
this.deviceGain = gain
}

override fun getRgbColor(): RGBColor {
override fun toRgbColor(): RGBColor {
val color = xledFrame[0, 0].toRgbColor()
return RGBColor(color.red, color.green, color.blue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package de.visualdigits.klanglicht.model.dmx.parameter
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import de.visualdigits.klanglicht.model.dmx.model.Dmx
import de.visualdigits.kotlin.twinkly.model.color.BlendMode
import de.visualdigits.kotlin.twinkly.model.color.RGBColor
import de.visualdigits.kotlin.twinkly.model.parameter.Fadeable
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -70,4 +71,8 @@ class DmxScene(
)
} else throw IllegalArgumentException("Cannot not fade another type")
}

override fun toRgbColor(): RGBColor {
return RGBColor(0,0,0)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.visualdigits.klanglicht.model.dmx.parameter

import de.visualdigits.kotlin.twinkly.model.color.BlendMode
import de.visualdigits.kotlin.twinkly.model.color.RGBColor
import de.visualdigits.kotlin.twinkly.model.parameter.Parameter


Expand All @@ -21,4 +22,8 @@ class IntParameter(
override fun clone(): IntParameter {
return IntParameter(name, value)
}

override fun toRgbColor(): RGBColor {
return RGBColor(0,0,0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class ParameterSet(
updateParameterMap()
}

override fun getRgbColor(): RGBColor? = parameters.filterIsInstance<RGBColor>().firstOrNull()
override fun toRgbColor(): RGBColor = parameters.filterIsInstance<RGBColor>().firstOrNull()?: RGBColor(0,0,0)

override fun setRgbColor(rgbColor: RGBColor) {
getRgbColor()?.setRgbColor(rgbColor)
toRgbColor()?.setRgbColor(rgbColor)
updateParameterMap()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.visualdigits.klanglicht.model.dmx.parameter

import de.visualdigits.klanglicht.model.dmx.fixture.Fixture
import de.visualdigits.kotlin.twinkly.model.color.BlendMode
import de.visualdigits.kotlin.twinkly.model.color.RGBColor
import de.visualdigits.kotlin.twinkly.model.parameter.Parameter
import kotlin.math.asin
import kotlin.math.atan2
Expand All @@ -11,12 +12,9 @@ import kotlin.math.sin
import kotlin.math.sqrt

class RotationParameter(

/** The fixture for this rotation (needed to calculate raw values). */
val fixture: Fixture,

val panDegrees: Double,

val tiltDegrees: Double
) : Parameter<RotationParameter> {

Expand Down Expand Up @@ -60,4 +58,8 @@ class RotationParameter(
override fun clone(): RotationParameter {
return RotationParameter(fixture, panDegrees, tiltDegrees)
}

override fun toRgbColor(): RGBColor {
return RGBColor(0,0,0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class HybridScene(

override fun toString(): String {
return fadeables
.mapNotNull { it.value.getRgbColor()?.ansiColor() }
.mapNotNull { it.value.toRgbColor()?.ansiColor() }
.joinToString("")
.trim() + " " +
fadeables
.mapNotNull { it.value.getRgbColor()?.hex() }
.mapNotNull { it.value.toRgbColor()?.hex() }
}

override fun clone(): HybridScene {
Expand Down Expand Up @@ -82,7 +82,7 @@ class HybridScene(

private fun initializeFromFadeables() {
this.ids = this.fadeables().map { sc -> sc.getId() }
this.hexColors = this.fadeables().mapNotNull { sc -> sc.getRgbColor()?.hex() }
this.hexColors = this.fadeables().mapNotNull { sc -> sc.toRgbColor()?.hex() }
this.gains = this.fadeables().map { sc -> sc.getGain() }
this.turnOns = this.fadeables().mapNotNull { sc -> sc.getTurnOn() }.joinToString(",")
}
Expand Down Expand Up @@ -206,7 +206,7 @@ class HybridScene(
initializeFromFadeables()
}

fun getRgbColor(id: String): RGBColor? = fadeables[id]?.getRgbColor()
fun getRgbColor(id: String): RGBColor? = fadeables[id]?.toRgbColor()

override fun fade(
other: HybridScene,
Expand All @@ -222,7 +222,7 @@ class HybridScene(
other.fadeableMap().filter { it.value is ShellyColor }.forEach {
val otherFadeable = it.value as ShellyColor
val fadeable = fadeables[otherFadeable.getId()]
if (fadeable != null && otherFadeable.getRgbColor() != fadeable.getRgbColor()) {
if (fadeable != null && otherFadeable.toRgbColor() != fadeable.toRgbColor()) {
launch { otherFadeable.write(true, fadeDuration) }
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ class HybridScene(
// first collect all frame data for the dmx frame to avoid lots of costly write operations to a serial interface
otherParameterSets.forEach { (id, otherParameterSet) ->
val parameterSet = parameterSets[id]
if (parameterSet != null && otherParameterSet.getRgbColor() != parameterSet.getRgbColor()) {
if (parameterSet != null && otherParameterSet.toRgbColor() != parameterSet.toRgbColor()) {
val faded = parameterSet.fade(otherParameterSet, factor, BlendMode.AVERAGE)
preferences.dmx!!.setDmxData(
baseChannel = faded.baseChannel,
Expand Down Expand Up @@ -336,4 +336,8 @@ class HybridScene(
throw IllegalArgumentException("Cannot not fade another type")
}
}

override fun toRgbColor(): RGBColor {
return RGBColor(0,0,0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LMHtmlScenes(
sb.append("<span class=\"label\">").append("C U R R E N T S C E N E").append("</span>\n")
sb.append("<div class=\"center-group\">\n")
prefs.currentScene?.fadeables()?.forEach { fadeable ->
val color = fadeable.getRgbColor()?.web() ?: "#000000"
val color = fadeable.toRgbColor()?.web() ?: "#000000"
val html = renderPanel(color)
sb.append(html)
}
Expand Down

0 comments on commit 93e1096

Please sign in to comment.