New rack rack-ears
[calf.git] / src / calf / lv2_atom.h
blob9707a948b79895cab57ab333d2ad88a02a1bd955
1 /*
2 Copyright 2008-2012 David Robillard <http://drobilla.net>
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /**
18 @file atom.h C header for the LV2 Atom extension
19 <http://lv2plug.in/ns/ext/atom>.
22 #ifndef LV2_ATOM_H
23 #define LV2_ATOM_H
25 #include <stdint.h>
26 #include <stddef.h>
28 #define LV2_ATOM_URI "http://lv2plug.in/ns/ext/atom"
29 #define LV2_ATOM_PREFIX LV2_ATOM_URI "#"
31 #define LV2_ATOM__Atom LV2_ATOM_PREFIX "Atom"
32 #define LV2_ATOM__AtomPort LV2_ATOM_PREFIX "AtomPort"
33 #define LV2_ATOM__Blank LV2_ATOM_PREFIX "Blank"
34 #define LV2_ATOM__Bool LV2_ATOM_PREFIX "Bool"
35 #define LV2_ATOM__Chunk LV2_ATOM_PREFIX "Chunk"
36 #define LV2_ATOM__Double LV2_ATOM_PREFIX "Double"
37 #define LV2_ATOM__Event LV2_ATOM_PREFIX "Event"
38 #define LV2_ATOM__Float LV2_ATOM_PREFIX "Float"
39 #define LV2_ATOM__Int LV2_ATOM_PREFIX "Int"
40 #define LV2_ATOM__Literal LV2_ATOM_PREFIX "Literal"
41 #define LV2_ATOM__Long LV2_ATOM_PREFIX "Long"
42 #define LV2_ATOM__Number LV2_ATOM_PREFIX "Number"
43 #define LV2_ATOM__Object LV2_ATOM_PREFIX "Object"
44 #define LV2_ATOM__Path LV2_ATOM_PREFIX "Path"
45 #define LV2_ATOM__Property LV2_ATOM_PREFIX "Property"
46 #define LV2_ATOM__Resource LV2_ATOM_PREFIX "Resource"
47 #define LV2_ATOM__Sequence LV2_ATOM_PREFIX "Sequence"
48 #define LV2_ATOM__Sound LV2_ATOM_PREFIX "Sound"
49 #define LV2_ATOM__String LV2_ATOM_PREFIX "String"
50 #define LV2_ATOM__Tuple LV2_ATOM_PREFIX "Tuple"
51 #define LV2_ATOM__URI LV2_ATOM_PREFIX "URI"
52 #define LV2_ATOM__URID LV2_ATOM_PREFIX "URID"
53 #define LV2_ATOM__Vector LV2_ATOM_PREFIX "Vector"
54 #define LV2_ATOM__atomTransfer LV2_ATOM_PREFIX "atomTransfer"
55 #define LV2_ATOM__beatTime LV2_ATOM_PREFIX "beatTime"
56 #define LV2_ATOM__bufferType LV2_ATOM_PREFIX "bufferType"
57 #define LV2_ATOM__childType LV2_ATOM_PREFIX "childType"
58 #define LV2_ATOM__eventTransfer LV2_ATOM_PREFIX "eventTransfer"
59 #define LV2_ATOM__frameTime LV2_ATOM_PREFIX "frameTime"
60 #define LV2_ATOM__supports LV2_ATOM_PREFIX "supports"
61 #define LV2_ATOM__timeUnit LV2_ATOM_PREFIX "timeUnit"
63 #define LV2_ATOM_REFERENCE_TYPE 0
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
69 /** This expression will fail to compile if double does not fit in 64 bits. */
70 typedef char lv2_atom_assert_double_fits_in_64_bits[
71 ((sizeof(double) <= sizeof(uint64_t)) * 2) - 1];
73 /**
74 Return a pointer to the contents of an Atom. The "contents" of an atom
75 is the data past the complete type-specific header.
76 @param type The type of the atom, e.g. LV2_Atom_String.
77 @param atom A variable-sized atom.
79 #define LV2_ATOM_CONTENTS(type, atom) \
80 ((void*)((uint8_t*)(atom) + sizeof(type)))
82 /**
83 Const version of LV2_ATOM_CONTENTS.
85 #define LV2_ATOM_CONTENTS_CONST(type, atom) \
86 ((const void*)((const uint8_t*)(atom) + sizeof(type)))
88 /**
89 Return a pointer to the body of an Atom. The "body" of an atom is the
90 data just past the LV2_Atom head (i.e. the same offset for all types).
92 #define LV2_ATOM_BODY(atom) LV2_ATOM_CONTENTS(LV2_Atom, atom)
94 /**
95 Const version of LV2_ATOM_BODY.
97 #define LV2_ATOM_BODY_CONST(atom) LV2_ATOM_CONTENTS_CONST(LV2_Atom, atom)
99 /** The header of an atom:Atom. */
100 typedef struct {
101 uint32_t size; /**< Size in bytes, not including type and size. */
102 uint32_t type; /**< Type of this atom (mapped URI). */
103 } LV2_Atom;
105 /** An atom:Int or atom:Bool. May be cast to LV2_Atom. */
106 typedef struct {
107 LV2_Atom atom; /**< Atom header. */
108 int32_t body; /**< Integer value. */
109 } LV2_Atom_Int;
111 /** An atom:Long. May be cast to LV2_Atom. */
112 typedef struct {
113 LV2_Atom atom; /**< Atom header. */
114 int64_t body; /**< Integer value. */
115 } LV2_Atom_Long;
117 /** An atom:Float. May be cast to LV2_Atom. */
118 typedef struct {
119 LV2_Atom atom; /**< Atom header. */
120 float body; /**< Floating point value. */
121 } LV2_Atom_Float;
123 /** An atom:Double. May be cast to LV2_Atom. */
124 typedef struct {
125 LV2_Atom atom; /**< Atom header. */
126 double body; /**< Floating point value. */
127 } LV2_Atom_Double;
129 /** An atom:Bool. May be cast to LV2_Atom. */
130 typedef LV2_Atom_Int LV2_Atom_Bool;
132 /** An atom:URID. May be cast to LV2_Atom. */
133 typedef struct {
134 LV2_Atom atom; /**< Atom header. */
135 uint32_t body; /**< URID. */
136 } LV2_Atom_URID;
138 /** An atom:String. May be cast to LV2_Atom. */
139 typedef struct {
140 LV2_Atom atom; /**< Atom header. */
141 /* Contents (a null-terminated UTF-8 string) follow here. */
142 } LV2_Atom_String;
144 /** The body of an atom:Literal. */
145 typedef struct {
146 uint32_t datatype; /**< Datatype URID. */
147 uint32_t lang; /**< Language URID. */
148 /* Contents (a null-terminated UTF-8 string) follow here. */
149 } LV2_Atom_Literal_Body;
151 /** An atom:Literal. May be cast to LV2_Atom. */
152 typedef struct {
153 LV2_Atom atom; /**< Atom header. */
154 LV2_Atom_Literal_Body body; /**< Body. */
155 } LV2_Atom_Literal;
157 /** An atom:Tuple. May be cast to LV2_Atom. */
158 typedef struct {
159 LV2_Atom atom; /**< Atom header. */
160 /* Contents (a series of complete atoms) follow here. */
161 } LV2_Atom_Tuple;
163 /** The body of an atom:Vector. */
164 typedef struct {
165 uint32_t child_size; /**< The size of each element in the vector. */
166 uint32_t child_type; /**< The type of each element in the vector. */
167 /* Contents (a series of packed atom bodies) follow here. */
168 } LV2_Atom_Vector_Body;
170 /** An atom:Vector. May be cast to LV2_Atom. */
171 typedef struct {
172 LV2_Atom atom; /**< Atom header. */
173 LV2_Atom_Vector_Body body; /**< Body. */
174 } LV2_Atom_Vector;
176 /** The body of an atom:Property (e.g. in an atom:Object). */
177 typedef struct {
178 uint32_t key; /**< Key (predicate) (mapped URI). */
179 uint32_t context; /**< Context URID (may be, and generally is, 0). */
180 LV2_Atom value; /**< Value atom header. */
181 /* Value atom body follows here. */
182 } LV2_Atom_Property_Body;
184 /** An atom:Property. May be cast to LV2_Atom. */
185 typedef struct {
186 LV2_Atom atom; /**< Atom header. */
187 LV2_Atom_Property_Body body; /**< Body. */
188 } LV2_Atom_Property;
190 /** The body of an atom:Object. May be cast to LV2_Atom. */
191 typedef struct {
192 uint32_t id; /**< URID, or 0 for blank. */
193 uint32_t otype; /**< Type URID (same as rdf:type, for fast dispatch). */
194 /* Contents (a series of property bodies) follow here. */
195 } LV2_Atom_Object_Body;
197 /** An atom:Object. May be cast to LV2_Atom. */
198 typedef struct {
199 LV2_Atom atom; /**< Atom header. */
200 LV2_Atom_Object_Body body; /**< Body. */
201 } LV2_Atom_Object;
203 /** The header of an atom:Event. Note this type is NOT an LV2_Atom. */
204 typedef struct {
205 /** Time stamp. Which type is valid is determined by context. */
206 union {
207 int64_t frames; /**< Time in audio frames. */
208 double beats; /**< Time in beats. */
209 } time;
210 LV2_Atom body; /**< Event body atom header. */
211 /* Body atom contents follow here. */
212 } LV2_Atom_Event;
215 The body of an atom:Sequence (a sequence of events).
217 The unit field is either a URID that described an appropriate time stamp
218 type, or may be 0 where a default stamp type is known. For
219 LV2_Descriptor::run(), the default stamp type is audio frames.
221 The contents of a sequence is a series of LV2_Atom_Event, each aligned
222 to 64-bits, e.g.:
223 <pre>
224 | Event 1 (size 6) | Event 2
225 | | | | | | | | |
226 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
227 |FRAMES |SUBFRMS|TYPE |SIZE |DATADATADATAPAD|FRAMES |SUBFRMS|...
228 </pre>
230 typedef struct {
231 uint32_t unit; /**< URID of unit of event time stamps. */
232 uint32_t pad; /**< Currently unused. */
233 /* Contents (a series of events) follow here. */
234 } LV2_Atom_Sequence_Body;
236 /** An atom:Sequence. */
237 typedef struct {
238 LV2_Atom atom; /**< Atom header. */
239 LV2_Atom_Sequence_Body body; /**< Body. */
240 } LV2_Atom_Sequence;
242 #ifdef __cplusplus
243 } /* extern "C" */
244 #endif
246 #endif /* LV2_ATOM_H */