Skip to content

Commit

Permalink
Cleanup Parameter class hierarchy introduce rotation parameter using …
Browse files Browse the repository at this point in the history
…great circle logic for fading (wip)
  • Loading branch information
sknull committed Oct 1, 2023
1 parent a624853 commit 1bba254
Show file tree
Hide file tree
Showing 77 changed files with 4,397 additions and 404 deletions.
6 changes: 1 addition & 5 deletions Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ A printout of the thread with those golden informations which kick started me on

== Current State

As I just started to convert the project to kotlin (the original Java code will remain private as ther is a lot of chaos...)
the REST interface itself is not yet implemented (also because I do not know which framework I want to use.
Spring boot seems not to be appropriate anymore along with kotlin and Micronaut seems to be abandonded and my
current experience with the latter during my professional work life is not so good.

For now things here are pretty basic as I start with implementing all models needed and basic interface access.
Binary file not shown.
Binary file added docs/hardware/yamaha/YXC_API_Spec_Advanced-1.pdf
Binary file not shown.
Binary file added docs/hardware/yamaha/YXC_API_Spec_Basic.pdf
Binary file not shown.
2,968 changes: 2,968 additions & 0 deletions docs/hardware/yamaha/rx-v673_dec.xml

Large diffs are not rendered by default.

50 changes: 0 additions & 50 deletions klanglicht-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,6 @@
<version>${revision}</version>

<dependencies>

<!-- common stuff -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>

<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${version.jackson}</version>
</dependency>

<!-- serial port -->
<dependency>
<groupId>io.github.java-native</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.visualdigits.kotlin.klanglicht.dmx

import de.visualdigits.kotlin.klanglicht.model.dmx.DMXInterfaceType
import de.visualdigits.kotlin.klanglicht.model.dmx.DmxFrame
import jssc.SerialPort
import jssc.SerialPortException
import org.apache.commons.lang3.StringUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.visualdigits.kotlin.klanglicht.model.color

interface Color {
import de.visualdigits.kotlin.klanglicht.model.parameter.Parameter

interface Color<T : Color<T>> : Parameter<T> {

fun value(): Long

Expand All @@ -17,6 +19,4 @@ interface Color {
fun toRGBW(): RGBWColor

fun toRGBA(): RGBAColor

fun toColorParameter(): ColorParameter
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package de.visualdigits.kotlin.klanglicht.model.color

import de.visualdigits.kotlin.klanglicht.model.parameter.IntParameter
import de.visualdigits.kotlin.klanglicht.model.parameter.Parameter
import org.apache.commons.lang3.StringUtils
import java.lang.IllegalArgumentException
import kotlin.math.floor
import kotlin.math.roundToInt

Expand All @@ -11,7 +14,7 @@ class HSVColor(
var s: Int = 0,
/** 0 -100 */
var v: Int = 0
) : Color {
) : Color<HSVColor> {

override fun toString(): String {
return "[" + StringUtils.join(listOf(h, s, v), ", ") + "]"
Expand All @@ -21,6 +24,21 @@ class HSVColor(
return "RGBColor(hex='${web()}', h=$h, s=$s , v=$v)"
}

override fun parameterMap(): Map<String, Int> {
val rgbColor = toRGB()
return mapOf(
"Red" to rgbColor.red,
"Green" to rgbColor.green,
"Blue" to rgbColor.blue,
)
}

override fun fade(other: Parameter<*>, factor: Double): HSVColor {
return if (other is HSVColor) {
other.toRGB().fade(other.toRGB(), factor).toHSV()
} else throw IllegalArgumentException("Cannot fade different parameter type")
}

override fun toRGB(): RGBColor {
val h = (this.h / 360.0)
val s = (this.s / 100.0)
Expand Down Expand Up @@ -51,10 +69,6 @@ class HSVColor(
)
}

inline fun <reified T : Color> mix(other: Color, factor: Double): T {
return toRGB().mix(other, factor)
}

override fun value(): Long {
return toRGB().value()
}
Expand Down Expand Up @@ -82,8 +96,4 @@ class HSVColor(
override fun toRGBA(): RGBAColor {
return toRGB().toRGBA()
}

override fun toColorParameter(): ColorParameter {
return toRGB().toColorParameter()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.visualdigits.kotlin.klanglicht.model.color

import de.visualdigits.kotlin.klanglicht.model.parameter.Parameter
import org.apache.commons.lang3.StringUtils
import java.lang.IllegalArgumentException
import kotlin.math.min
import kotlin.math.roundToInt
import java.lang.Long.decode
Expand All @@ -10,7 +12,7 @@ class RGBAColor(
green: Int = 0,
blue: Int = 0,
var amber: Int = 0
) : RGBColor(red, green, blue) {
) : RGBBaseColor<RGBAColor>(red, green, blue) {

companion object {
const val AMBER_RED = 255.0
Expand All @@ -35,12 +37,22 @@ class RGBAColor(
return "RGBColor(hex='${web()}', r=$red, g=$green , b=$blue, a=$amber)"
}

override fun toRGB(): RGBColor {
return RGBColor(
red = min(255, red + (amber / AMBER_FACTOR).roundToInt()),
green = min(255, green + (amber * AMBER_FACTOR).roundToInt()),
blue = blue
)
override fun parameterMap(): Map<String, Int> = mapOf(
"Red" to red,
"Green" to green,
"Blue" to blue,
"Amber" to amber
)

override fun fade(other: Parameter<*>, factor: Double): RGBAColor {
return if (other is RGBAColor) {
RGBAColor(
red = min(255, (red + factor * (other.red - red)).roundToInt()),
green = min(255, (green + factor * (other.green - green)).roundToInt()),
blue = min(255, (blue + factor * (other.blue - blue)).roundToInt()),
amber = min(255, (amber + factor * (other.amber - amber)).roundToInt())
)
} else throw IllegalArgumentException("Cannot fade different parameter type")
}

override fun value(): Long = (red.toLong() shl 24) or (green.toLong() shl 16) or (blue.toLong() shl 8) or amber.toLong()
Expand All @@ -53,6 +65,14 @@ class RGBAColor(
return toRGB().ansiColor()
}

override fun toRGB(): RGBColor {
return RGBColor(
red = min(255, red + (amber / AMBER_FACTOR).roundToInt()),
green = min(255, green + (amber * AMBER_FACTOR).roundToInt()),
blue = blue
)
}

override fun toHSV(): HSVColor {
return toRGB().toHSV()
}
Expand Down
Loading

0 comments on commit 1bba254

Please sign in to comment.