[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 private var currentDouble = 0.0
init { init {
osc.listen(key) { osc.listen(key) { _, message ->
currentDouble = (it[0] as Float).toDouble() currentDouble = (message[0] as Float).toDouble()
} }
} }
@@ -28,11 +28,11 @@ open class ChataigneOSC(
private var currentColor = ColorRGBa.BLACK private var currentColor = ColorRGBa.BLACK
init { init {
osc.listen(key) { osc.listen(key) { _, message ->
val red = it[0] as Float val red = message[0] as Float
val green = it[1] as Float val green = message[1] as Float
val blue = it[2] as Float val blue = message[2] as Float
val alpha = it[3] as Float val alpha = message[3] as Float
currentColor = ColorRGBa(red.toDouble(), green.toDouble(), blue.toDouble(), alpha.toDouble()) currentColor = ColorRGBa(red.toDouble(), green.toDouble(), blue.toDouble(), alpha.toDouble())
} }

View File

@@ -1,5 +1,5 @@
dependencies { dependencies {
def withoutSlf4j = { exclude group: 'org.slf4j' } 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.OSCMessage
import com.illposed.osc.OSCMessageListener import com.illposed.osc.OSCMessageListener
import com.illposed.osc.messageselector.OSCPatternAddressMessageSelector import com.illposed.osc.messageselector.OSCPatternAddressMessageSelector
import com.illposed.osc.transport.udp.OSCPort import com.illposed.osc.transport.OSCPort
import com.illposed.osc.transport.udp.OSCPortIn import com.illposed.osc.transport.OSCPortIn
import com.illposed.osc.transport.udp.OSCPortOut import com.illposed.osc.transport.OSCPortOut
import mu.KotlinLogging import mu.KotlinLogging
import java.net.InetAddress import java.net.InetAddress
import java.net.PortUnreachableException import java.net.PortUnreachableException
@@ -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 selector = OSCPatternAddressMessageSelector(channel);
val cb = OSCMessageListener { val cb = OSCMessageListener {
callback(it.message.arguments) callback(it.message.address, it.message.arguments)
} }
receiver.dispatcher.addListener(selector, cb) receiver.dispatcher.addListener(selector, cb)
@@ -56,7 +56,7 @@ class OSC (
infix fun String.bind(prop: KMutableProperty0<Double>) { infix fun String.bind(prop: KMutableProperty0<Double>) {
val channel = this val channel = this
listen(channel) { listen(channel) { address, it ->
when (val message = it.first()) { when (val message = it.first()) {
is Double -> prop.set(message) is Double -> prop.set(message)
is Float -> prop.set(message.toDouble()) 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 // Cannot be called inside a listener's callback
fun removeListener(channel: String?) { fun removeListener(channel: String?) {
val listener = listeners[channel] val listener = listeners[channel]