atom.h (10416B)
1 /* 2 Copyright 2008-2016 David Robillard <http://drobilla.net> 3 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. 7 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. 15 */ 16 17 /** 18 @defgroup atom Atom 19 20 A generic value container and several data types, see 21 <http://lv2plug.in/ns/ext/atom> for details. 22 23 @{ 24 */ 25 26 #ifndef LV2_ATOM_H 27 #define LV2_ATOM_H 28 29 #include <stdint.h> 30 #include <stddef.h> 31 32 #define LV2_ATOM_URI "http://lv2plug.in/ns/ext/atom" ///< http://lv2plug.in/ns/ext/atom 33 #define LV2_ATOM_PREFIX LV2_ATOM_URI "#" ///< http://lv2plug.in/ns/ext/atom# 34 35 #define LV2_ATOM__Atom LV2_ATOM_PREFIX "Atom" ///< http://lv2plug.in/ns/ext/atom#Atom 36 #define LV2_ATOM__AtomPort LV2_ATOM_PREFIX "AtomPort" ///< http://lv2plug.in/ns/ext/atom#AtomPort 37 #define LV2_ATOM__Blank LV2_ATOM_PREFIX "Blank" ///< http://lv2plug.in/ns/ext/atom#Blank 38 #define LV2_ATOM__Bool LV2_ATOM_PREFIX "Bool" ///< http://lv2plug.in/ns/ext/atom#Bool 39 #define LV2_ATOM__Chunk LV2_ATOM_PREFIX "Chunk" ///< http://lv2plug.in/ns/ext/atom#Chunk 40 #define LV2_ATOM__Double LV2_ATOM_PREFIX "Double" ///< http://lv2plug.in/ns/ext/atom#Double 41 #define LV2_ATOM__Event LV2_ATOM_PREFIX "Event" ///< http://lv2plug.in/ns/ext/atom#Event 42 #define LV2_ATOM__Float LV2_ATOM_PREFIX "Float" ///< http://lv2plug.in/ns/ext/atom#Float 43 #define LV2_ATOM__Int LV2_ATOM_PREFIX "Int" ///< http://lv2plug.in/ns/ext/atom#Int 44 #define LV2_ATOM__Literal LV2_ATOM_PREFIX "Literal" ///< http://lv2plug.in/ns/ext/atom#Literal 45 #define LV2_ATOM__Long LV2_ATOM_PREFIX "Long" ///< http://lv2plug.in/ns/ext/atom#Long 46 #define LV2_ATOM__Number LV2_ATOM_PREFIX "Number" ///< http://lv2plug.in/ns/ext/atom#Number 47 #define LV2_ATOM__Object LV2_ATOM_PREFIX "Object" ///< http://lv2plug.in/ns/ext/atom#Object 48 #define LV2_ATOM__Path LV2_ATOM_PREFIX "Path" ///< http://lv2plug.in/ns/ext/atom#Path 49 #define LV2_ATOM__Property LV2_ATOM_PREFIX "Property" ///< http://lv2plug.in/ns/ext/atom#Property 50 #define LV2_ATOM__Resource LV2_ATOM_PREFIX "Resource" ///< http://lv2plug.in/ns/ext/atom#Resource 51 #define LV2_ATOM__Sequence LV2_ATOM_PREFIX "Sequence" ///< http://lv2plug.in/ns/ext/atom#Sequence 52 #define LV2_ATOM__Sound LV2_ATOM_PREFIX "Sound" ///< http://lv2plug.in/ns/ext/atom#Sound 53 #define LV2_ATOM__String LV2_ATOM_PREFIX "String" ///< http://lv2plug.in/ns/ext/atom#String 54 #define LV2_ATOM__Tuple LV2_ATOM_PREFIX "Tuple" ///< http://lv2plug.in/ns/ext/atom#Tuple 55 #define LV2_ATOM__URI LV2_ATOM_PREFIX "URI" ///< http://lv2plug.in/ns/ext/atom#URI 56 #define LV2_ATOM__URID LV2_ATOM_PREFIX "URID" ///< http://lv2plug.in/ns/ext/atom#URID 57 #define LV2_ATOM__Vector LV2_ATOM_PREFIX "Vector" ///< http://lv2plug.in/ns/ext/atom#Vector 58 #define LV2_ATOM__atomTransfer LV2_ATOM_PREFIX "atomTransfer" ///< http://lv2plug.in/ns/ext/atom#atomTransfer 59 #define LV2_ATOM__beatTime LV2_ATOM_PREFIX "beatTime" ///< http://lv2plug.in/ns/ext/atom#beatTime 60 #define LV2_ATOM__bufferType LV2_ATOM_PREFIX "bufferType" ///< http://lv2plug.in/ns/ext/atom#bufferType 61 #define LV2_ATOM__childType LV2_ATOM_PREFIX "childType" ///< http://lv2plug.in/ns/ext/atom#childType 62 #define LV2_ATOM__eventTransfer LV2_ATOM_PREFIX "eventTransfer" ///< http://lv2plug.in/ns/ext/atom#eventTransfer 63 #define LV2_ATOM__frameTime LV2_ATOM_PREFIX "frameTime" ///< http://lv2plug.in/ns/ext/atom#frameTime 64 #define LV2_ATOM__supports LV2_ATOM_PREFIX "supports" ///< http://lv2plug.in/ns/ext/atom#supports 65 #define LV2_ATOM__timeUnit LV2_ATOM_PREFIX "timeUnit" ///< http://lv2plug.in/ns/ext/atom#timeUnit 66 67 #define LV2_ATOM_REFERENCE_TYPE 0 ///< The special type for a reference atom 68 69 #ifdef __cplusplus 70 extern "C" { 71 #endif 72 73 /** @cond */ 74 /** This expression will fail to compile if double does not fit in 64 bits. */ 75 typedef char lv2_atom_assert_double_fits_in_64_bits[ 76 ((sizeof(double) <= sizeof(uint64_t)) * 2) - 1]; 77 /** @endcond */ 78 79 /** 80 Return a pointer to the contents of an Atom. The "contents" of an atom 81 is the data past the complete type-specific header. 82 @param type The type of the atom, e.g. LV2_Atom_String. 83 @param atom A variable-sized atom. 84 */ 85 #define LV2_ATOM_CONTENTS(type, atom) \ 86 ((uint8_t*)(atom) + sizeof(type)) 87 88 /** 89 Const version of LV2_ATOM_CONTENTS. 90 */ 91 #define LV2_ATOM_CONTENTS_CONST(type, atom) \ 92 ((const uint8_t*)(atom) + sizeof(type)) 93 94 /** 95 Return a pointer to the body of an Atom. The "body" of an atom is the 96 data just past the LV2_Atom head (i.e. the same offset for all types). 97 */ 98 #define LV2_ATOM_BODY(atom) LV2_ATOM_CONTENTS(LV2_Atom, atom) 99 100 /** 101 Const version of LV2_ATOM_BODY. 102 */ 103 #define LV2_ATOM_BODY_CONST(atom) LV2_ATOM_CONTENTS_CONST(LV2_Atom, atom) 104 105 /** The header of an atom:Atom. */ 106 typedef struct { 107 uint32_t size; /**< Size in bytes, not including type and size. */ 108 uint32_t type; /**< Type of this atom (mapped URI). */ 109 } LV2_Atom; 110 111 /** An atom:Int or atom:Bool. May be cast to LV2_Atom. */ 112 typedef struct { 113 LV2_Atom atom; /**< Atom header. */ 114 int32_t body; /**< Integer value. */ 115 } LV2_Atom_Int; 116 117 /** An atom:Long. May be cast to LV2_Atom. */ 118 typedef struct { 119 LV2_Atom atom; /**< Atom header. */ 120 int64_t body; /**< Integer value. */ 121 } LV2_Atom_Long; 122 123 /** An atom:Float. May be cast to LV2_Atom. */ 124 typedef struct { 125 LV2_Atom atom; /**< Atom header. */ 126 float body; /**< Floating point value. */ 127 } LV2_Atom_Float; 128 129 /** An atom:Double. May be cast to LV2_Atom. */ 130 typedef struct { 131 LV2_Atom atom; /**< Atom header. */ 132 double body; /**< Floating point value. */ 133 } LV2_Atom_Double; 134 135 /** An atom:Bool. May be cast to LV2_Atom. */ 136 typedef LV2_Atom_Int LV2_Atom_Bool; 137 138 /** An atom:URID. May be cast to LV2_Atom. */ 139 typedef struct { 140 LV2_Atom atom; /**< Atom header. */ 141 uint32_t body; /**< URID. */ 142 } LV2_Atom_URID; 143 144 /** An atom:String. May be cast to LV2_Atom. */ 145 typedef struct { 146 LV2_Atom atom; /**< Atom header. */ 147 /* Contents (a null-terminated UTF-8 string) follow here. */ 148 } LV2_Atom_String; 149 150 /** The body of an atom:Literal. */ 151 typedef struct { 152 uint32_t datatype; /**< Datatype URID. */ 153 uint32_t lang; /**< Language URID. */ 154 /* Contents (a null-terminated UTF-8 string) follow here. */ 155 } LV2_Atom_Literal_Body; 156 157 /** An atom:Literal. May be cast to LV2_Atom. */ 158 typedef struct { 159 LV2_Atom atom; /**< Atom header. */ 160 LV2_Atom_Literal_Body body; /**< Body. */ 161 } LV2_Atom_Literal; 162 163 /** An atom:Tuple. May be cast to LV2_Atom. */ 164 typedef struct { 165 LV2_Atom atom; /**< Atom header. */ 166 /* Contents (a series of complete atoms) follow here. */ 167 } LV2_Atom_Tuple; 168 169 /** The body of an atom:Vector. */ 170 typedef struct { 171 uint32_t child_size; /**< The size of each element in the vector. */ 172 uint32_t child_type; /**< The type of each element in the vector. */ 173 /* Contents (a series of packed atom bodies) follow here. */ 174 } LV2_Atom_Vector_Body; 175 176 /** An atom:Vector. May be cast to LV2_Atom. */ 177 typedef struct { 178 LV2_Atom atom; /**< Atom header. */ 179 LV2_Atom_Vector_Body body; /**< Body. */ 180 } LV2_Atom_Vector; 181 182 /** The body of an atom:Property (e.g. in an atom:Object). */ 183 typedef struct { 184 uint32_t key; /**< Key (predicate) (mapped URI). */ 185 uint32_t context; /**< Context URID (may be, and generally is, 0). */ 186 LV2_Atom value; /**< Value atom header. */ 187 /* Value atom body follows here. */ 188 } LV2_Atom_Property_Body; 189 190 /** An atom:Property. May be cast to LV2_Atom. */ 191 typedef struct { 192 LV2_Atom atom; /**< Atom header. */ 193 LV2_Atom_Property_Body body; /**< Body. */ 194 } LV2_Atom_Property; 195 196 /** The body of an atom:Object. May be cast to LV2_Atom. */ 197 typedef struct { 198 uint32_t id; /**< URID, or 0 for blank. */ 199 uint32_t otype; /**< Type URID (same as rdf:type, for fast dispatch). */ 200 /* Contents (a series of property bodies) follow here. */ 201 } LV2_Atom_Object_Body; 202 203 /** An atom:Object. May be cast to LV2_Atom. */ 204 typedef struct { 205 LV2_Atom atom; /**< Atom header. */ 206 LV2_Atom_Object_Body body; /**< Body. */ 207 } LV2_Atom_Object; 208 209 /** The header of an atom:Event. Note this type is NOT an LV2_Atom. */ 210 typedef struct { 211 /** Time stamp. Which type is valid is determined by context. */ 212 union { 213 int64_t frames; /**< Time in audio frames. */ 214 double beats; /**< Time in beats. */ 215 } time; 216 LV2_Atom body; /**< Event body atom header. */ 217 /* Body atom contents follow here. */ 218 } LV2_Atom_Event; 219 220 /** 221 The body of an atom:Sequence (a sequence of events). 222 223 The unit field is either a URID that described an appropriate time stamp 224 type, or may be 0 where a default stamp type is known. For 225 LV2_Descriptor::run(), the default stamp type is audio frames. 226 227 The contents of a sequence is a series of LV2_Atom_Event, each aligned 228 to 64-bits, e.g.: 229 <pre> 230 | Event 1 (size 6) | Event 2 231 | | | | | | | | | 232 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 233 |FRAMES |SUBFRMS|TYPE |SIZE |DATADATADATAPAD|FRAMES |SUBFRMS|... 234 </pre> 235 */ 236 typedef struct { 237 uint32_t unit; /**< URID of unit of event time stamps. */ 238 uint32_t pad; /**< Currently unused. */ 239 /* Contents (a series of events) follow here. */ 240 } LV2_Atom_Sequence_Body; 241 242 /** An atom:Sequence. */ 243 typedef struct { 244 LV2_Atom atom; /**< Atom header. */ 245 LV2_Atom_Sequence_Body body; /**< Body. */ 246 } LV2_Atom_Sequence; 247 248 /** 249 @} 250 */ 251 252 #ifdef __cplusplus 253 } /* extern "C" */ 254 #endif 255 256 #endif /* LV2_ATOM_H */