O2 2.0
A communication protocol for interactive music and media applications.
Functions
OSC Interoperation

Functions

O2err o2_osc_port_new (const char *service_name, int port_num, int tcp_flag)
 Create a port to receive OSC messages. More...
 
O2err o2_osc_port_free (int port_num)
 Remove a port receiving OSC messages. More...
 
O2err o2_osc_delegate (const char *service_name, const char *ip, int port_num, int tcp_flag)
 Create a service that forwards O2 messages to an OSC server. More...
 
uint64_t o2_osc_time_offset (uint64_t offset)
 Set the OSC time offset. More...
 

Detailed Description

Function Documentation

◆ o2_osc_delegate()

O2err o2_osc_delegate ( const char *  service_name,
const char *  ip,
int  port_num,
int  tcp_flag 
)

Create a service that forwards O2 messages to an OSC server.

Parameters
service_nameThe o2 service name without a '/' prefix.
ipThe ip address of the osc server.
port_numThe port number of the osc server.
tcp_flagSend OSC message via TCP protocol, in which case port_num is the TCP server port, not a connection.
Returns
O2_SUCCESS if success, O2_FAIL if not.

If tcp_flag is set, a TCP connection will be established with the OSC server. When the created service receives any O2 messages, it will send the message to the OSC server. If the incoming message has a timestamp for some future time, the message will be held until that time, then sent to the OSC server. (Ideally, O2 could convert the message to an OSC timestamped bundle and send it immediately to achieve precise forward-synchronous timing, but this requires clock synchronization with the OSC server, which is normally unimplemented.)

If this is a tcp connection, close it by calling o2_service_free.

◆ o2_osc_port_free()

O2err o2_osc_port_free ( int  port_num)

Remove a port receiving OSC messages.

This removes a port created by o2_osc_port_new. If you want to remove the corresponding service, you must also call o2_service_free with the service name. The port should be the same port passed to o2_osc_port_new. In the case of TCP, this will close all connections that were accepted from this server port as well as the server port.

Parameters
port_numThe port number that receives OSC messages or that receives connect requests for TCP connections.
Returns
O2_SUCCESS if success, O2_FAIL if not.

◆ o2_osc_port_new()

O2err o2_osc_port_new ( const char *  service_name,
int  port_num,
int  tcp_flag 
)

Create a port to receive OSC messages.

OSC messages are converted to O2 messages and directed to the service. E.g. if the service is "maxmsp" and the message address is /foo/x, then the message is directed to and handled by /maxmsp/foo/x. If the #service_name does not exist at any time after calling o2_osc_port_new, incoming OSC messages will be dropped until the service is available again. Note that this function does not automatically create a service named service_name.

Parameters
service_nameThe name of the service to which messages are delivered
port_numPort number.
tcp_flagBe a TCP server for remote clients. Otherwise, use UDP
Returns
O2_SUCCESS if success, O2_FAIL if not.

◆ o2_osc_time_offset()

uint64_t o2_osc_time_offset ( uint64_t  offset)

Set the OSC time offset.

Parameters
offsetthe offset between (global) O2 time and OSC time
Returns
the previous offset

O2 global time should start from 0.0 when the clock is started, whereas OSC time starts at 1 Jan 1900. The offset is the OSC time corresponding to O2 time 0.0. Equivalently, OSC_time = O2_time + offset.