Files
virtual-controller/osc_sender.py
T

37 lines
833 B
Python

from pythonosc import udp_client
from osc_receiver import osc_receiver
_osc_client = None
_osc_send_port = 8000
_osc_send_ip = "127.0.0.1"
def get_osc_client():
global _osc_client
if _osc_client is None:
_osc_client = udp_client.SimpleUDPClient(_osc_send_ip, _osc_send_port)
return _osc_client
def set_osc_target(ip=None, port=None):
global _osc_client, _osc_send_ip, _osc_send_port
if ip is not None:
_osc_send_ip = ip
if port is not None:
_osc_send_port = port
_osc_client = None
def send_osc_message(address, value=1.0):
try:
get_osc_client().send_message(address, float(value))
osc_receiver.osc_out_signal.emit(address, str(value))
print(f"[OSC] → {address} {value}")
except Exception as e:
print(f"[OSC send] Error: {e}")