godot_osc_demo/UI.gd

36 lines
1.1 KiB
GDScript

extends Control
func _ready():
var scene = preload("res://osc_receiver.tscn")
var osc_server = scene.instantiate()
add_child(osc_server)
# configure all sensors
for i in range(4):
var nodename = "VSlider%d" % (i + 1)
var osc_addr = "/slider/%d/set" % i
var slider_node = find_child(nodename)
osc_server.register_callback(osc_addr, "f", slider_node.recv_osc)
for i in range(4):
var nodename = "Button%d" % (i + 1)
var osc_addr = "/button/%d/set" % i
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)