[orx-osc] Upgrade to JavaOSC 0.8, add address to listener message

This commit is contained in:
Edwin Jakobs
2022-02-03 07:59:44 +01:00
parent ddbbb2c2a6
commit d2d8ef58b6
3 changed files with 17 additions and 19 deletions

View File

@@ -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())
}

View File

@@ -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
}

View File

@@ -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<Any>) -> Unit) {
fun listen(channel: String, callback: (String, List<Any>) -> 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<Double>) {
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]