2022-03-20 10:45:12 +01:00

49 lines
1.0 KiB
Python

from osc4py3.as_eventloop import *
from osc4py3 import oscbuildparse
def start_osc():
osc_startup()
def terminate_osc():
osc_terminate()
def temperature(temp, name):
print(f'{temp} - {name}')
def update():
osc_process()
class OscBroadcaster:
def __init__(self, name: str, host: str, port: str, command_channel: str):
self.name = name
self.host = host
self.port = port
self.cmd = command_channel
osc_udp_client(self.host, self.port, self.name)
def utterance(self, utterance: str, channel: str):
msg = oscbuildparse.OSCMessage(channel, None, [utterance])
osc_send(msg, self.name)
osc_process()
def command(self, command: str):
msg = oscbuildparse.OSCMessage(self.cmd, None, [command])
osc_send(msg, self.name)
osc_process()
class OscReceiver:
def __init__(self, name: str, host: str, port: str, callback_fn=None):
self.name = name
self.host = host
self.port = port
osc_udp_server(self.host, self.port, self.name)
if callback_fn:
osc_method('/', callback_fn)
else:
osc_method('/', temperature)