From d2d8ef58b6ac2a4fd2816fa85cf32b531040a93d Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 3 Feb 2022 07:59:44 +0100 Subject: [PATCH] [orx-osc] Upgrade to JavaOSC 0.8, add address to listener message --- .../src/main/kotlin/ChataigneOSC.kt | 14 ++++++------- orx-jvm/orx-osc/build.gradle | 2 +- orx-jvm/orx-osc/src/main/kotlin/OSC.kt | 20 +++++++++---------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/orx-jvm/orx-chataigne/src/main/kotlin/ChataigneOSC.kt b/orx-jvm/orx-chataigne/src/main/kotlin/ChataigneOSC.kt index c711cbc3..564efb5e 100644 --- a/orx-jvm/orx-chataigne/src/main/kotlin/ChataigneOSC.kt +++ b/orx-jvm/orx-chataigne/src/main/kotlin/ChataigneOSC.kt @@ -13,8 +13,8 @@ open class ChataigneOSC( private var currentDouble = 0.0 init { - osc.listen(key) { - currentDouble = (it[0] as Float).toDouble() + osc.listen(key) { _, message -> + currentDouble = (message[0] as Float).toDouble() } } @@ -28,11 +28,11 @@ open class ChataigneOSC( private var currentColor = ColorRGBa.BLACK init { - osc.listen(key) { - val red = it[0] as Float - val green = it[1] as Float - val blue = it[2] as Float - val alpha = it[3] as Float + osc.listen(key) { _, message -> + val red = message[0] as Float + val green = message[1] as Float + val blue = message[2] as Float + val alpha = message[3] as Float currentColor = ColorRGBa(red.toDouble(), green.toDouble(), blue.toDouble(), alpha.toDouble()) } diff --git a/orx-jvm/orx-osc/build.gradle b/orx-jvm/orx-osc/build.gradle index 8dd740d4..72980f4c 100644 --- a/orx-jvm/orx-osc/build.gradle +++ b/orx-jvm/orx-osc/build.gradle @@ -1,5 +1,5 @@ dependencies { def withoutSlf4j = { exclude group: 'org.slf4j' } - implementation "com.illposed.osc:javaosc-core:0.6", withoutSlf4j + implementation "com.illposed.osc:javaosc-core:0.8", withoutSlf4j } \ No newline at end of file diff --git a/orx-jvm/orx-osc/src/main/kotlin/OSC.kt b/orx-jvm/orx-osc/src/main/kotlin/OSC.kt index cd0a4fc3..40126302 100644 --- a/orx-jvm/orx-osc/src/main/kotlin/OSC.kt +++ b/orx-jvm/orx-osc/src/main/kotlin/OSC.kt @@ -3,9 +3,9 @@ package org.openrndr.extra.osc import com.illposed.osc.OSCMessage import com.illposed.osc.OSCMessageListener import com.illposed.osc.messageselector.OSCPatternAddressMessageSelector -import com.illposed.osc.transport.udp.OSCPort -import com.illposed.osc.transport.udp.OSCPortIn -import com.illposed.osc.transport.udp.OSCPortOut +import com.illposed.osc.transport.OSCPort +import com.illposed.osc.transport.OSCPortIn +import com.illposed.osc.transport.OSCPortOut import mu.KotlinLogging import java.net.InetAddress import java.net.PortUnreachableException @@ -17,9 +17,9 @@ private val logger = KotlinLogging.logger {} @Suppress("unused") class OSC ( - val address: InetAddress = InetAddress.getLocalHost(), - val portIn: Int = OSCPort.DEFAULT_SC_OSC_PORT, - val portOut: Int = portIn + val address: InetAddress = InetAddress.getLocalHost(), + val portIn: Int = OSCPort.DEFAULT_SC_OSC_PORT, + val portOut: Int = portIn ) { private val receiver: OSCPortIn = OSCPortIn(portIn) private val sender: OSCPortOut = OSCPortOut(address, portOut) @@ -39,11 +39,11 @@ class OSC ( } } - fun listen(channel: String, callback: (List) -> Unit) { + fun listen(channel: String, callback: (String, List) -> Unit) { val selector = OSCPatternAddressMessageSelector(channel); val cb = OSCMessageListener { - callback(it.message.arguments) + callback(it.message.address, it.message.arguments) } receiver.dispatcher.addListener(selector, cb) @@ -56,7 +56,7 @@ class OSC ( infix fun String.bind(prop: KMutableProperty0) { val channel = this - listen(channel) { + listen(channel) { address, it -> when (val message = it.first()) { is Double -> prop.set(message) is Float -> prop.set(message.toDouble()) @@ -64,8 +64,6 @@ class OSC ( } } - fun listen(function: OSC.() -> Unit) = function() - // Cannot be called inside a listener's callback fun removeListener(channel: String?) { val listener = listeners[channel]