| @@ -48,6 +48,12 @@ | |||||
| #include "atom-util.h" | #include "atom-util.h" | ||||
| #include "urid.h" | #include "urid.h" | ||||
| #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) | |||||
| # define LV2_ATOM_FORGE_DEPRECATED __attribute__((__deprecated__)) | |||||
| #else | |||||
| # define LV2_ATOM_FORGE_DEPRECATED | |||||
| #endif | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| #else | #else | ||||
| @@ -89,7 +95,7 @@ typedef struct { | |||||
| LV2_Atom_Forge_Frame* stack; | LV2_Atom_Forge_Frame* stack; | ||||
| LV2_URID Blank; | |||||
| LV2_URID Blank LV2_ATOM_FORGE_DEPRECATED; | |||||
| LV2_URID Bool; | LV2_URID Bool; | ||||
| LV2_URID Chunk; | LV2_URID Chunk; | ||||
| LV2_URID Double; | LV2_URID Double; | ||||
| @@ -97,9 +103,10 @@ typedef struct { | |||||
| LV2_URID Int; | LV2_URID Int; | ||||
| LV2_URID Long; | LV2_URID Long; | ||||
| LV2_URID Literal; | LV2_URID Literal; | ||||
| LV2_URID Object; | |||||
| LV2_URID Path; | LV2_URID Path; | ||||
| LV2_URID Property; | LV2_URID Property; | ||||
| LV2_URID Resource; | |||||
| LV2_URID Resource LV2_ATOM_FORGE_DEPRECATED; | |||||
| LV2_URID Sequence; | LV2_URID Sequence; | ||||
| LV2_URID String; | LV2_URID String; | ||||
| LV2_URID Tuple; | LV2_URID Tuple; | ||||
| @@ -120,6 +127,10 @@ lv2_atom_forge_set_buffer(LV2_Atom_Forge* forge, uint8_t* buf, size_t size); | |||||
| static inline void | static inline void | ||||
| lv2_atom_forge_init(LV2_Atom_Forge* forge, LV2_URID_Map* map) | lv2_atom_forge_init(LV2_Atom_Forge* forge, LV2_URID_Map* map) | ||||
| { | { | ||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic push | |||||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |||||
| #endif | |||||
| lv2_atom_forge_set_buffer(forge, NULL, 0); | lv2_atom_forge_set_buffer(forge, NULL, 0); | ||||
| forge->Blank = map->map(map->handle, LV2_ATOM__Blank); | forge->Blank = map->map(map->handle, LV2_ATOM__Blank); | ||||
| forge->Bool = map->map(map->handle, LV2_ATOM__Bool); | forge->Bool = map->map(map->handle, LV2_ATOM__Bool); | ||||
| @@ -129,6 +140,7 @@ lv2_atom_forge_init(LV2_Atom_Forge* forge, LV2_URID_Map* map) | |||||
| forge->Int = map->map(map->handle, LV2_ATOM__Int); | forge->Int = map->map(map->handle, LV2_ATOM__Int); | ||||
| forge->Long = map->map(map->handle, LV2_ATOM__Long); | forge->Long = map->map(map->handle, LV2_ATOM__Long); | ||||
| forge->Literal = map->map(map->handle, LV2_ATOM__Literal); | forge->Literal = map->map(map->handle, LV2_ATOM__Literal); | ||||
| forge->Object = map->map(map->handle, LV2_ATOM__Object); | |||||
| forge->Path = map->map(map->handle, LV2_ATOM__Path); | forge->Path = map->map(map->handle, LV2_ATOM__Path); | ||||
| forge->Property = map->map(map->handle, LV2_ATOM__Property); | forge->Property = map->map(map->handle, LV2_ATOM__Property); | ||||
| forge->Resource = map->map(map->handle, LV2_ATOM__Resource); | forge->Resource = map->map(map->handle, LV2_ATOM__Resource); | ||||
| @@ -138,6 +150,9 @@ lv2_atom_forge_init(LV2_Atom_Forge* forge, LV2_URID_Map* map) | |||||
| forge->URI = map->map(map->handle, LV2_ATOM__URI); | forge->URI = map->map(map->handle, LV2_ATOM__URI); | ||||
| forge->URID = map->map(map->handle, LV2_ATOM__URID); | forge->URID = map->map(map->handle, LV2_ATOM__URID); | ||||
| forge->Vector = map->map(map->handle, LV2_ATOM__Vector); | forge->Vector = map->map(map->handle, LV2_ATOM__Vector); | ||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic pop | |||||
| #endif | |||||
| } | } | ||||
| static inline LV2_Atom* | static inline LV2_Atom* | ||||
| @@ -188,6 +203,40 @@ lv2_atom_forge_top_is(LV2_Atom_Forge* forge, uint32_t type) | |||||
| (lv2_atom_forge_deref(forge, forge->stack->ref)->type == type); | (lv2_atom_forge_deref(forge, forge->stack->ref)->type == type); | ||||
| } | } | ||||
| /** Return true iff @p type is an atom:Object. */ | |||||
| static inline bool | |||||
| lv2_atom_forge_is_object_type(const LV2_Atom_Forge* forge, uint32_t type) | |||||
| { | |||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic push | |||||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |||||
| #endif | |||||
| return (type == forge->Object || | |||||
| type == forge->Blank || | |||||
| type == forge->Resource); | |||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic pop | |||||
| #endif | |||||
| } | |||||
| /** Return true iff @p type is an atom:Object with a blank ID. */ | |||||
| static inline bool | |||||
| lv2_atom_forge_is_blank(const LV2_Atom_Forge* forge, | |||||
| uint32_t type, | |||||
| const LV2_Atom_Object_Body* body) | |||||
| { | |||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic push | |||||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |||||
| #endif | |||||
| return (type == forge->Blank || | |||||
| (type == forge->Object && | |||||
| ((LV2_Atom_Object_Body*)body)->id == 0)); | |||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic pop | |||||
| #endif | |||||
| } | |||||
| /** | /** | ||||
| @} | @} | ||||
| @name Output Configuration | @name Output Configuration | ||||
| @@ -321,7 +370,8 @@ lv2_atom_forge_primitive(LV2_Atom_Forge* forge, const LV2_Atom* a) | |||||
| if (lv2_atom_forge_top_is(forge, forge->Vector)) { | if (lv2_atom_forge_top_is(forge, forge->Vector)) { | ||||
| return lv2_atom_forge_raw(forge, LV2_ATOM_BODY_CONST(a), a->size); | return lv2_atom_forge_raw(forge, LV2_ATOM_BODY_CONST(a), a->size); | ||||
| } else { | } else { | ||||
| return lv2_atom_forge_write(forge, a, (uint32_t)sizeof(LV2_Atom) + a->size); | |||||
| return lv2_atom_forge_write( | |||||
| forge, a, (uint32_t)sizeof(LV2_Atom) + a->size); | |||||
| } | } | ||||
| } | } | ||||
| @@ -503,7 +553,7 @@ lv2_atom_forge_tuple(LV2_Atom_Forge* forge, LV2_Atom_Forge_Frame* frame) | |||||
| } | } | ||||
| /** | /** | ||||
| Write the header of an atom:Resource. | |||||
| Write the header of an atom:Object. | |||||
| The passed frame will be initialised to represent this object. To complete | The passed frame will be initialised to represent this object. To complete | ||||
| the object, write a sequence of properties, then pop the frame with | the object, write a sequence of properties, then pop the frame with | ||||
| @@ -514,12 +564,12 @@ lv2_atom_forge_tuple(LV2_Atom_Forge* forge, LV2_Atom_Forge_Frame* frame) | |||||
| LV2_URID eg_Cat = map("http://example.org/Cat"); | LV2_URID eg_Cat = map("http://example.org/Cat"); | ||||
| LV2_URID eg_name = map("http://example.org/name"); | LV2_URID eg_name = map("http://example.org/name"); | ||||
| // Write object header | |||||
| // Start object with type eg_Cat and blank ID | |||||
| LV2_Atom_Forge_Frame frame; | LV2_Atom_Forge_Frame frame; | ||||
| lv2_atom_forge_resource(forge, &frame, 1, eg_Cat); | |||||
| lv2_atom_forge_object(forge, &frame, 0, eg_Cat); | |||||
| // Write property: eg:name = "Hobbes" | |||||
| lv2_atom_forge_property_head(forge, eg_name, 0); | |||||
| // Append property eg:name = "Hobbes" | |||||
| lv2_atom_forge_key(forge, eg_name); | |||||
| lv2_atom_forge_string(forge, "Hobbes", strlen("Hobbes")); | lv2_atom_forge_string(forge, "Hobbes", strlen("Hobbes")); | ||||
| // Finish object | // Finish object | ||||
| @@ -527,39 +577,93 @@ lv2_atom_forge_tuple(LV2_Atom_Forge* forge, LV2_Atom_Forge_Frame* frame) | |||||
| @endcode | @endcode | ||||
| */ | */ | ||||
| static inline LV2_Atom_Forge_Ref | static inline LV2_Atom_Forge_Ref | ||||
| lv2_atom_forge_object(LV2_Atom_Forge* forge, | |||||
| LV2_Atom_Forge_Frame* frame, | |||||
| LV2_URID id, | |||||
| LV2_URID otype) | |||||
| { | |||||
| const LV2_Atom_Object a = { | |||||
| { sizeof(LV2_Atom_Object) - sizeof(LV2_Atom), forge->Object }, | |||||
| { id, otype } | |||||
| }; | |||||
| return lv2_atom_forge_push( | |||||
| forge, frame, lv2_atom_forge_write(forge, &a, sizeof(a))); | |||||
| } | |||||
| /** | |||||
| The same as lv2_atom_forge_resource(), but for object:Resource. | |||||
| This function is deprecated and should not be used in new code. | |||||
| Use lv2_atom_forge_resource() directly instead. | |||||
| */ | |||||
| LV2_ATOM_FORGE_DEPRECATED | |||||
| static inline LV2_Atom_Forge_Ref | |||||
| lv2_atom_forge_resource(LV2_Atom_Forge* forge, | lv2_atom_forge_resource(LV2_Atom_Forge* forge, | ||||
| LV2_Atom_Forge_Frame* frame, | LV2_Atom_Forge_Frame* frame, | ||||
| LV2_URID id, | LV2_URID id, | ||||
| LV2_URID otype) | LV2_URID otype) | ||||
| { | { | ||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic push | |||||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |||||
| #endif | |||||
| const LV2_Atom_Object a = { | const LV2_Atom_Object a = { | ||||
| { (uint32_t)(sizeof(LV2_Atom_Object) - sizeof(LV2_Atom)), forge->Resource }, | |||||
| { sizeof(LV2_Atom_Object) - sizeof(LV2_Atom), forge->Resource }, | |||||
| { id, otype } | { id, otype } | ||||
| }; | }; | ||||
| return lv2_atom_forge_push( | return lv2_atom_forge_push( | ||||
| forge, frame, lv2_atom_forge_write(forge, &a, sizeof(a))); | forge, frame, lv2_atom_forge_write(forge, &a, sizeof(a))); | ||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic pop | |||||
| #endif | |||||
| } | } | ||||
| /** | /** | ||||
| The same as lv2_atom_forge_resource(), but for object:Blank. | The same as lv2_atom_forge_resource(), but for object:Blank. | ||||
| This function is deprecated and should not be used in new code. | |||||
| Use lv2_atom_forge_resource() directly instead. | |||||
| */ | */ | ||||
| LV2_ATOM_FORGE_DEPRECATED | |||||
| static inline LV2_Atom_Forge_Ref | static inline LV2_Atom_Forge_Ref | ||||
| lv2_atom_forge_blank(LV2_Atom_Forge* forge, | lv2_atom_forge_blank(LV2_Atom_Forge* forge, | ||||
| LV2_Atom_Forge_Frame* frame, | LV2_Atom_Forge_Frame* frame, | ||||
| uint32_t id, | uint32_t id, | ||||
| LV2_URID otype) | LV2_URID otype) | ||||
| { | { | ||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic push | |||||
| # pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |||||
| #endif | |||||
| const LV2_Atom_Object a = { | const LV2_Atom_Object a = { | ||||
| { (uint32_t)(sizeof(LV2_Atom_Object) - sizeof(LV2_Atom)), forge->Blank }, | |||||
| { sizeof(LV2_Atom_Object) - sizeof(LV2_Atom), forge->Blank }, | |||||
| { id, otype } | { id, otype } | ||||
| }; | }; | ||||
| return lv2_atom_forge_push( | return lv2_atom_forge_push( | ||||
| forge, frame, lv2_atom_forge_write(forge, &a, sizeof(a))); | forge, frame, lv2_atom_forge_write(forge, &a, sizeof(a))); | ||||
| #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) | |||||
| # pragma GCC diagnostic pop | |||||
| #endif | |||||
| } | |||||
| /** | |||||
| Write a property key in an Object, to be followed by the value. | |||||
| See lv2_atom_forge_object() documentation for an example. | |||||
| */ | |||||
| static inline LV2_Atom_Forge_Ref | |||||
| lv2_atom_forge_key(LV2_Atom_Forge* forge, | |||||
| LV2_URID key) | |||||
| { | |||||
| const LV2_Atom_Property_Body a = { key, 0, { 0, 0 } }; | |||||
| return lv2_atom_forge_write(forge, &a, 2 * sizeof(uint32_t)); | |||||
| } | } | ||||
| /** | /** | ||||
| Write the header for a property body (likely in an Object). | |||||
| See lv2_atom_forge_resource() documentation for an example. | |||||
| Write the header for a property body in an object, with context. | |||||
| If you do not need the context, which is almost certainly the case, | |||||
| use the simpler lv2_atom_forge_key() instead. | |||||
| */ | */ | ||||
| static inline LV2_Atom_Forge_Ref | static inline LV2_Atom_Forge_Ref | ||||
| lv2_atom_forge_property_head(LV2_Atom_Forge* forge, | lv2_atom_forge_property_head(LV2_Atom_Forge* forge, | ||||
| @@ -567,7 +671,7 @@ lv2_atom_forge_property_head(LV2_Atom_Forge* forge, | |||||
| LV2_URID context) | LV2_URID context) | ||||
| { | { | ||||
| const LV2_Atom_Property_Body a = { key, context, { 0, 0 } }; | const LV2_Atom_Property_Body a = { key, context, { 0, 0 } }; | ||||
| return lv2_atom_forge_write(forge, &a, (uint32_t)sizeof(uint32_t) * 2); | |||||
| return lv2_atom_forge_write(forge, &a, 2 * sizeof(uint32_t)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -579,7 +683,7 @@ lv2_atom_forge_sequence_head(LV2_Atom_Forge* forge, | |||||
| uint32_t unit) | uint32_t unit) | ||||
| { | { | ||||
| const LV2_Atom_Sequence a = { | const LV2_Atom_Sequence a = { | ||||
| { (uint32_t)(sizeof(LV2_Atom_Sequence) - sizeof(LV2_Atom)), forge->Sequence }, | |||||
| { sizeof(LV2_Atom_Sequence) - sizeof(LV2_Atom), forge->Sequence }, | |||||
| { unit, 0 } | { unit, 0 } | ||||
| }; | }; | ||||
| return lv2_atom_forge_push( | return lv2_atom_forge_push( | ||||