181#define O2_SERVICE_CONFLICT (-2)
185#define O2_NO_SERVICE (-3)
188#define O2_NO_MEMORY (-4)
191#define O2_ALREADY_RUNNING (-5)
194#define O2_BAD_NAME (-6)
197#define O2_BAD_TYPE (-7)
201#define O2_BAD_ARGS (-8)
204#define O2_TCP_HUP (-9)
208#define O2_HOSTNAME_TO_NETADDR_FAIL (-10)
211#define O2_TCP_CONNECT_FAIL (-11)
215#define O2_NO_CLOCK (-12)
218#define O2_NO_HANDLER (-13)
221#define O2_INVALID_MSG (-14)
224#define O2_SEND_FAIL (-15)
227#define O2_BAD_SERVICE_NAME (-16)
230#define O2_SERVICE_EXISTS (-17)
233#define O2_NOT_INITIALIZED (-18)
243#define O2_LOCAL_NOTIME 0
251#define O2_REMOTE_NOTIME 1
265#define O2_BRIDGE_NOTIME 2
282#define O2_TO_OSC_NOTIME 3
332#define O2_MARKER_A (void *) 0xdeadbeefdeadbeefL
333#define O2_MARKER_B (void *) 0xf00baa23f00baa23L
336extern void *((*o2_malloc)(
size_t size));
337extern void ((*o2_free)(
void *));
338void *o2_calloc(
size_t n,
size_t s);
345void *o2_dbg_malloc(
size_t size,
const char *file,
int line);
346void o2_dbg_free(
void *obj,
const char *file,
int line);
347#define O2_MALLOC(x) o2_dbg_malloc(x, __FILE__, __LINE__)
348#define O2_FREE(x) o2_dbg_free(x, __FILE__, __LINE__)
363#define O2_MALLOC(x) (*o2_malloc)(x)
365#define O2_MALLOC(x) o2_dbg_malloc(x, __FILE__, __LINE__)
372#define O2_FREE(x) (*o2_free)(x)
374#define O2_FREE(x) (*o2_dbg_free)(x, __FILE__, __LINE__)
381void *o2_calloc(
size_t n,
size_t s);
382#define O2_CALLOC(n, s) o2_calloc((n), (s))
385#define O2_CALLOC(n, s) o2_dbg_calloc((n), (s), __FILE__, __LINE__)
429#define MSG_DATA_LENGTH(m) (((int32_t *) &((m)->timestamp))[-1])
436#define WORD_ALIGN_PTR(p) ((char *) (((size_t) (p)) & ~3))
437#define O2_MSG_TYPES(msg) \
438 WORD_ALIGN_PTR((msg)->address + strlen((msg)->address) + 4) + 1;
596extern const char *o2_application_name;
670int o2_memory(
void *((*malloc)(
size_t size)),
void ((*free)(
void *)));
735int o2_hub(
const char *ipaddress,
int port);
809int o2_tap(
const char *tappee,
const char *tapper);
1048#define o2_send(path, time, ...) \
1049 o2_send_marker(path, time, FALSE, \
1050 __VA_ARGS__, O2_MARKER_A, O2_MARKER_B)
\
1053int o2_send_marker(
const char *path,
double time,
int tcp_flag,
1054 const char *typestring, ...);
1079#define o2_send_cmd(path, time, ...) \
1080 o2_send_marker(path, time, TRUE, \
1081 __VA_ARGS__, O2_MARKER_A, O2_MARKER_B)
1421#define o2_add_symbol(s) o2_add_string_or_symbol(O2_SYMBOL, s)
1424#define o2_add_string(s) o2_add_string_or_symbol(O2_STRING, s)
1442#define o2_add_double(d) o2_add_double_or_time(O2_DOUBLE, d)
1445#define o2_add_time(t) o2_add_double_or_time(O2_TIME, t)
1452#define o2_add_int32(i) o2_add_int32_or_char(O2_INT32, i)
1455#define o2_add_char(c) o2_add_int32_or_char(O2_CHAR, c)
1466#define o2_add_true() o2_add_only_typecode(O2_TRUE);
1469#define o2_add_false() o2_add_only_typecode(O2_FALSE);
1472#define o2_add_bool(x) o2_add_int32_or_char(O2_BOOL, x != 0)
1475#define o2_add_nil() o2_add_only_typecode(O2_NIL);
1478#define o2_add_infinitum() o2_add_only_typecode(O2_INFINITUM);
1481#define o2_add_start_array() o2_add_only_typecode(O2_ARRAY_START);
1484#define o2_add_end_array() o2_add_only_typecode(O2_ARRAY_END);
1495 int length,
void *data);
1549 const char *service,
const char *address,
int tcp_flag);
\
1707#define O2_SCHED_TABLE_LEN 128
1710typedef struct o2_sched {
1714} o2_sched, *o2_sched_ptr;
int o2_stop_flag
set this flag to stop o2_run()
int o2_poll()
Process current O2 messages.
o2_time o2_time_get()
Get the estimated synchronized global O2 time.
o2_sched o2_gtsched
Scheduler that schedules according to global (master) clock time.
const char * o2_error_to_string(int i)
Return text representation of an O2 error.
void(* o2_method_handler)(const o2_msg_data_ptr msg, const char *types, o2_arg_ptr *argv, int argc, void *user_data)
callback function to receive an O2 message
Definition o2.h:630
int o2_schedule(o2_sched_ptr scheduler, o2_message_ptr msg)
o2_time o2_set_discovery_period(o2_time period)
Set discovery period.
uint64_t o2_osc_time_offset(uint64_t offset)
Set the OSC time offset.
int o2_status(const char *service)
Check the status of the service.
o2_time(* o2_time_callback)(void *rock)
signature for callback that defines the master clock
Definition o2.h:990
int o2_initialize(const char *application_name)
Start O2.
void * o2_dbg_calloc(size_t n, size_t s, const char *file, int line)
allocate memory
int o2_get_address(const char **ipaddress, int *port)
Get IP address and TCP connection port number.
int o2_method_new(const char *path, const char *typespec, o2_method_handler h, void *user_data, int coerce, int parse)
Add a handler for an address.
int o2_osc_port_new(const char *service_name, int port_num, int tcp_flag)
Create a port to receive OSC messages.
o2_sched o2_ltsched
Scheduler that schedules according to local clock time.
int o2_message_send(o2_message_ptr msg)
Send an O2 message. (See also macros o2_send and o2_send_cmd).
int o2_service_free(const char *service_name)
Remove a local service.
o2_sched_ptr o2_active_sched
Current scheduler.
int o2_memory(void *((*malloc)(size_t size)), void((*free)(void *)))
Tell O2 how to allocate/free memory.
int o2_run(int rate)
Run O2.
double o2_time
O2 timestamps are doubles representing seconds since the approximate start time of the application.
Definition o2.h:392
int o2_hub(const char *ipaddress, int port)
Connect to a hub.
int o2_clock_is_synchronized
A variable indicating that the clock is the master or is synchronized to the master.
int 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.
int o2_tap(const char *tappee, const char *tapper)
copy messages from one service to another
int o2_service_new(const char *service_name)
Add a service to the current application.
int o2_osc_port_free(int port_num)
Remove a port receiving OSC messages.
o2_time o2_local_time()
Get the real time using the local O2 clock.
int o2_clock_set(o2_time_callback gettime, void *rock)
Provide a time reference to O2.
o2_type
An enumeration of the O2 message types.
Definition o2.h:486
int o2_finish()
release the memory and shut down O2.
int o2_roundtrip(double *mean, double *min)
Get network round-trip information.
@ O2_ARRAY_END
End array or tuple.
Definition o2.h:493
@ O2_BLOB
Binary Large OBject (BLOB) type.
Definition o2.h:491
@ O2_FALSE
Symbol representing the value False.
Definition o2.h:503
@ O2_TRUE
Symbol representing the value True.
Definition o2.h:502
@ O2_INFINITUM
Symbol representing the value Infinitum.
Definition o2.h:505
@ O2_VECTOR
Prefix to indicate a vector.
Definition o2.h:509
@ O2_FLOAT
32 bit IEEE-754 float.
Definition o2.h:489
@ O2_MIDI
4 byte MIDI packet.
Definition o2.h:501
@ O2_DOUBLE
64 bit IEEE-754 double.
Definition o2.h:498
@ O2_TIME
OSC time type.
Definition o2.h:497
@ O2_CHAR
8bit char variable (Standard C).
Definition o2.h:500
@ O2_INT32
32 bit signed integer.
Definition o2.h:488
@ O2_ARRAY_START
Start array or tuple.
Definition o2.h:492
@ O2_NIL
Symbol representing the value Nil.
Definition o2.h:504
@ O2_INT64
64 bit signed integer.
Definition o2.h:496
@ O2_BOOL
Boolean value returned as either 0 or 1.
Definition o2.h:508
@ O2_SYMBOL
Used in systems distinguish strings and symbols.
Definition o2.h:499
@ O2_STRING
NULL terminated string (Standard C).
Definition o2.h:490
void o2_debug_flags(const char *flags)
Enable debugging output.
int o2_extract_start(o2_msg_data_ptr msg)
initialize internal state to parse, extract, and coerce message arguments.
o2_arg_ptr o2_get_next(o2_type type_code)
get the next message parameter
int o2_add_blob(o2_blob_ptr b)
add an o2_blob to the message (see o2_send_start()), where the blob is given as a pointer to an o2_bl...
o2_message_ptr o2_service_message_finish(o2_time time, const char *service, const char *address, int tcp_flag)
finish and return a message, prepending service name
int o2_add_vector(o2_type element_type, int length, void *data)
add a vector
int o2_add_message(o2_message_ptr msg)
add a message to a bundle
int o2_send_finish(o2_time time, const char *address, int tcp_flag)
send a message allocated by o2_send_start().
o2_message_ptr o2_message_finish(o2_time time, const char *address, int tcp_flag)
finish and return the message.
int o2_add_blob_data(uint32_t size, void *data)
add an o2_blob to the message (see o2_send_start()), where the blob is specified by a size and a data...
o2_blob_ptr o2_blob_new(uint32_t size)
Allocate a blob.
void o2_message_free(o2_message_ptr msg)
free a message allocated by o2_send_start().
int o2_add_int32_or_char(o2_type tcode, int32_t i)
This function supports o2_add_int32() and o2_add_char() Normally, you should not call this directly.
int o2_add_float(float f)
add a float to the message (see o2_send_start())
int o2_add_midi(uint32_t m)
add a short midi message to the message (see o2_send_start())
int o2_add_int64(int64_t i)
add an int64 to the message (see o2_send_start())
int o2_send_start()
Prepare to build a message.
int o2_add_only_typecode(o2_type typecode)
This function supports o2_add_true(), o2_add_false(), o2_add_bool(), o2_add_nil(),...
int o2_add_double_or_time(o2_type tchar, double d)
This function supports o2_add_double() and o2_add_time() Normally, you should not call this directly.
int o2_add_string_or_symbol(o2_type tcode, const char *s)
This function suppports o2_add_symbol() and o2_add_string() Normally, you should not call this direct...
The structure for binary large object.
Definition o2.h:477
char data[4]
the data, actually of variable length
Definition o2.h:479
uint32_t size
size of data
Definition o2.h:478
an O2 message container
Definition o2.h:456
int tcp_flag
send message by tcp?
Definition o2.h:462
int64_t pad_if_needed
make sure allocated is 8-byte aligned
Definition o2.h:459
int32_t allocated
how many bytes allocated in data part
Definition o2.h:465
int32_t length
the length of the message in data part
Definition o2.h:466
struct o2_message * next
links used for free list and scheduler
Definition o2.h:458
int64_t pad_if_needed2
make sure allocated is 8-byte aligned
Definition o2.h:463
data part of an O2 message
Definition o2.h:413
o2_time timestamp
the message delivery time (0 for immediate)
Definition o2.h:414
char address[4]
the message address string
Definition o2.h:423
union of all O2 parameter types
Definition o2.h:533
o2_time t
TimeTag value.
Definition o2.h:549
double * vd
vector of IEEE-754 doubles
Definition o2.h:559
int64_t * vh
vector of 64-bit signed integers
Definition o2.h:558
int64_t i64
64 bit signed integer.
Definition o2.h:536
int32_t B
a boolean value, either 0 or 1
Definition o2.h:551
double f64
an alias for d
Definition o2.h:541
int c
Standard C, 8 bit, char, stored as int.
Definition o2.h:546
float * vf
vector of IEEE-754 floats
Definition o2.h:560
int32_t len
IMPORTANT: divide by 4 or 8 to get length in elements.
Definition o2.h:553
o2_blob b
a blob (unstructured bytes)
Definition o2.h:550
int64_t h
an alias for i64
Definition o2.h:537
float f32
an alias for f
Definition o2.h:539
uint32_t m
Definition o2.h:547
double d
64 bit IEEE-754 double.
Definition o2.h:540
int32_t i32
32 bit signed integer.
Definition o2.h:534
int32_t typ
type of vector elements
Definition o2.h:555
int32_t i
an alias for i32
Definition o2.h:535
int32_t * vi
vector of 32-bit signed integers
Definition o2.h:557
float f
32 bit IEEE-754 float.
Definition o2.h:538