1 /*
2  *  Copyright (C) 2014 Steve Harris et al. (see AUTHORS)
3  *
4  *  This program is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public License
6  *  as published by the Free Software Foundation; either version 2.1
7  *  of the License, or (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  $Id$
15  */
16 
17 #ifndef LO_OSC_TYPES_H
18 #define LO_OSC_TYPES_H
19 
20 /**
21  * \file lo_osc_types.h A liblo header defining OSC-related types and
22  * constants.
23  */
24 
25 #include <stdint.h>
26 
27 /**
28  * \addtogroup liblo
29  * @{
30  */
31 
32 /**
33  * \brief A structure to store OSC TimeTag values.
34  */
35 typedef struct {
36 	/** The number of seconds since Jan 1st 1900 in the UTC timezone. */
37 	uint32_t sec;
38 	/** The fractions of a second offset from above, expressed as 1/2^32nds
39          * of a second */
40 	uint32_t frac;
41 } lo_timetag;
42 
43 /**
44  * \brief An enumeration of bundle element types liblo can handle.
45  *
46  * The element of a bundle can either be a message or an other bundle.
47  */
48 typedef enum {
49 	/** bundle element is a message */
50 	LO_ELEMENT_MESSAGE = 1,
51 	/** bundle element is a bundle */
52 	LO_ELEMENT_BUNDLE = 2
53 } lo_element_type;
54 
55 /**
56  * \brief An enumeration of the OSC types liblo can send and receive.
57  *
58  * The value of the enumeration is the typechar used to tag messages and to
59  * specify arguments with lo_send().
60  */
61 typedef enum {
62 /* basic OSC types */
63 	/** 32 bit signed integer. */
64 	LO_INT32 =     'i',
65 	/** 32 bit IEEE-754 float. */
66 	LO_FLOAT =     'f',
67 	/** Standard C, NULL terminated string. */
68 	LO_STRING =    's',
69 	/** OSC binary blob type. Accessed using the lo_blob_*() functions. */
70 	LO_BLOB =      'b',
71 
72 /* extended OSC types */
73 	/** 64 bit signed integer. */
74 	LO_INT64 =     'h',
75 	/** OSC TimeTag type, represented by the lo_timetag structure. */
76 	LO_TIMETAG =   't',
77 	/** 64 bit IEEE-754 double. */
78 	LO_DOUBLE =    'd',
79 	/** Standard C, NULL terminated, string. Used in systems which
80 	  * distinguish strings and symbols. */
81 	LO_SYMBOL =    'S',
82 	/** Standard C, 8 bit, char variable. */
83 	LO_CHAR =      'c',
84 	/** A 4 byte MIDI packet. */
85 	LO_MIDI =      'm',
86 	/** Sybol representing the value True. */
87 	LO_TRUE =      'T',
88 	/** Sybol representing the value False. */
89 	LO_FALSE =     'F',
90 	/** Sybol representing the value Nil. */
91 	LO_NIL =       'N',
92 	/** Sybol representing the value Infinitum. */
93 	LO_INFINITUM = 'I'
94 } lo_type;
95 
96 
97 /**
98  * \brief Union used to read values from incoming messages.
99  *
100  * Types can generally be read using argv[n]->t where n is the argument number
101  * and t is the type character, with the exception of strings and symbols which
102  * must be read with &argv[n]->t.
103  */
104 typedef union {
105 	/** 32 bit signed integer. */
106     int32_t    i;
107 	/** 32 bit signed integer. */
108     int32_t    i32;
109 	/** 64 bit signed integer. */
110     int64_t    h;
111 	/** 64 bit signed integer. */
112     int64_t    i64;
113 	/** 32 bit IEEE-754 float. */
114     float      f;
115 	/** 32 bit IEEE-754 float. */
116     float      f32;
117 	/** 64 bit IEEE-754 double. */
118     double     d;
119 	/** 64 bit IEEE-754 double. */
120     double     f64;
121 	/** Standard C, NULL terminated string. */
122     char       s;
123 	/** Standard C, NULL terminated, string. Used in systems which
124 	  * distinguish strings and symbols. */
125     char       S;
126 	/** Standard C, 8 bit, char. */
127     unsigned char c;
128 	/** A 4 byte MIDI packet. */
129     uint8_t    m[4];
130 	/** OSC TimeTag value. */
131     lo_timetag t;
132     /** Blob **/
133     struct {
134         int32_t size;
135         char data;
136     } blob;
137 } lo_arg;
138 
139 /* Note: No struct literals in MSVC */
140 #ifdef _MSC_VER
141 #ifndef USE_ANSI_C
142 #define USE_ANSI_C
143 #endif
144 #endif
145 
146 /** \brief A timetag constant representing "now". */
147 #if defined(USE_ANSI_C) || defined(DLL_EXPORT)
148 lo_timetag lo_get_tt_immediate();
149 #define LO_TT_IMMEDIATE lo_get_tt_immediate()
150 #else // !USE_ANSI_C
151 #define LO_TT_IMMEDIATE ((lo_timetag){0U,1U})
152 #endif // USE_ANSI_C
153 
154 /** @} */
155 
156 #endif
157