diff --git a/OSCReceiver.gd b/OSCReceiver.gd index 37e64f5..ffea95c 100644 --- a/OSCReceiver.gd +++ b/OSCReceiver.gd @@ -74,22 +74,22 @@ func _poll(): _debug("OSC arg types: %s" % types) if _observers.has([address, types]): - var values = _parse_osc_values(packet, types, offset) + var values = _parse_osc_values(packet.slice(offset), types) if values == null: _debug("Invalid/Unsupported OSC message.") elif values.size() != types.length(): _debug("Mismatch between expected / received number of OSC arguments.") else: - values.append({ + var msg_info = { "ip": sender_ip, "port": sender_port, "address": address, "types": types - }) + } for callback in _observers[[address, types]]: - callback.callv(values) + callback.call(msg_info, values) func _parse_osc_addr_and_types(packet): var asep = packet.find(0) @@ -103,10 +103,11 @@ func _parse_osc_addr_and_types(packet): return [address, types, tsep + (4 - tsep % 4)] -func _parse_osc_values(packet, types, offset): +func _parse_osc_values(packet, types): + var result var values = [] var stream = StreamPeerBuffer.new() - stream.set_data_array(packet.slice(offset)) + stream.set_data_array(packet) stream.set_big_endian(true) for type_id in types: @@ -126,7 +127,7 @@ func _parse_osc_values(packet, types, offset): var null_found = false while not null_found: - for _i in range(4): + for _dummy in range(4): var ch = stream.get_u8() if not null_found and ch != 0: value.append(char(ch)) @@ -136,12 +137,24 @@ func _parse_osc_values(packet, types, offset): values.append("".join(value)) "b": var count = stream.get_u32() - values.append(stream.get_data(count)) + result = stream.get_data(count) - if count % 4: - stream.seek(stream.get_position() + (count % 4)) + if result[0] == OK: + values.append(result[1]) + + if count % 4: + stream.seek(stream.get_position() + (4 - count % 4)) + else: + _debug("Could not read OSC blob argument.") + return "t": - values.append(stream.get_data(8)) + result = stream.get_data(8) + + if result[0] == OK: + values.append(result[1]) + else: + _debug("Could not read OSC timetag argument.") + return "m", "r": values.append([ stream.get_u8(), @@ -156,7 +169,7 @@ func _parse_osc_values(packet, types, offset): "I", "N": values.append(null) _: - _debug("Argument type '%s' not yet supported." % type_id) + _debug("Argument type '%s' not supported." % type_id) return return values diff --git a/Slider.gd b/Slider.gd index c931e69..0153765 100644 --- a/Slider.gd +++ b/Slider.gd @@ -1,9 +1,9 @@ extends VSlider -func recv_osc(val, msg_info): +func recv_osc(msg_info, values): print("Sender IP: %s" % msg_info["ip"]) print("Sender Port: %d" % msg_info["port"]) - print("Adress: %s" % msg_info["address"]) + print("Address: %s" % msg_info["address"]) print("Types: %s" % msg_info["types"]) - set_value(clampf(val, 0.0, 1.0)) + set_value(clampf(values[0], 0.0, 1.0)) diff --git a/ToggleButton.gd b/ToggleButton.gd index cb72837..6b39dab 100644 --- a/ToggleButton.gd +++ b/ToggleButton.gd @@ -1,9 +1,9 @@ extends Button -func recv_osc(val, msg_info): +func recv_osc(msg_info, values): print("Sender IP: %s" % msg_info["ip"]) print("Sender Port: %d" % msg_info["port"]) - print("Adress: %s" % msg_info["address"]) + print("Address: %s" % msg_info["address"]) print("Types: %s" % msg_info["types"]) - set_pressed_no_signal(bool(val)) + set_pressed_no_signal(bool(values[0])) diff --git a/UI.gd b/UI.gd index 59e4e7f..2b0d484 100644 --- a/UI.gd +++ b/UI.gd @@ -19,5 +19,17 @@ func _ready(): var button_node = find_child(nodename) osc_server.register_callback(osc_addr, "i", button_node.recv_osc) + osc_server.register_callback("/string", "s", recv_osc) + osc_server.register_callback("/stringint", "si", recv_osc) + osc_server.register_callback("/blob", "b", recv_osc) + osc_server.register_callback("/blobint", "bi", recv_osc) + # start listening for osc messages osc_server.start_server() + +func recv_osc(msg_info, values): + print("Sender IP: %s" % msg_info["ip"]) + print("Sender Port: %d" % msg_info["port"]) + print("Address: %s" % msg_info["address"]) + print("Types: %s" % msg_info["types"]) + print("Values:", values)