LV2: Forge

# LV2

An open and extensible audio plugin standard

Version | 1.18.10

Data Structures | Typedefs | Functions
Forge
LV2 » Atom

## Detailed Description

An API for constructing LV2 atoms.

## Data Structures
struct | LV2_Atom_Forge_Frame
struct | LV2_Atom_Forge

## Typedefs
typedef void * | LV2_Atom_Forge_Sink_Handle
typedef intptr_t | LV2_Atom_Forge_Ref
typedef LV2_Atom_Forge_Ref(* | LV2_Atom_Forge_Sink) (LV2_Atom_Forge_Sink_Handle handle, const void *buf, uint32_t size)
typedef LV2_Atom *(* | LV2_Atom_Forge_Deref_Func) (LV2_Atom_Forge_Sink_Handle handle, LV2_Atom_Forge_Ref ref)

## Functions
static void | lv2_atom_forge_init (LV2_Atom_Forge *forge, LV2_URID_Map *map)
static LV2_Atom * | lv2_atom_forge_deref (LV2_Atom_Forge *forge, LV2_Atom_Forge_Ref ref)

## Output Configuration
static void | lv2_atom_forge_set_buffer (LV2_Atom_Forge *forge, uint8_t *buf, size_t size)
static void | lv2_atom_forge_set_sink (LV2_Atom_Forge *forge, LV2_Atom_Forge_Sink sink, LV2_Atom_Forge_Deref_Func deref, LV2_Atom_Forge_Sink_Handle handle)

## Object Stack
static LV2_Atom_Forge_Ref | lv2_atom_forge_push (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, LV2_Atom_Forge_Ref ref)
static void | lv2_atom_forge_pop (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame)
static bool | lv2_atom_forge_top_is (LV2_Atom_Forge *forge, uint32_t type)
static bool | lv2_atom_forge_is_object_type (const LV2_Atom_Forge *forge, uint32_t type)
static bool | lv2_atom_forge_is_blank (const LV2_Atom_Forge *forge, uint32_t type, const LV2_Atom_Object_Body *body)

## Low Level Output
static LV2_Atom_Forge_Ref | lv2_atom_forge_raw (LV2_Atom_Forge *forge, const void *data, uint32_t size)
static void | lv2_atom_forge_pad (LV2_Atom_Forge *forge, uint32_t written)
static LV2_Atom_Forge_Ref | lv2_atom_forge_write (LV2_Atom_Forge *forge, const void *data, uint32_t size)
static LV2_Atom_Forge_Ref | lv2_atom_forge_string_body (LV2_Atom_Forge *forge, const char *str, uint32_t len)

## Atom Output
static LV2_Atom_Forge_Ref | lv2_atom_forge_atom (LV2_Atom_Forge *forge, uint32_t size, uint32_t type)
static LV2_Atom_Forge_Ref | lv2_atom_forge_primitive (LV2_Atom_Forge *forge, const LV2_Atom *a)
static LV2_Atom_Forge_Ref | lv2_atom_forge_int (LV2_Atom_Forge *forge, int32_t val)
static LV2_Atom_Forge_Ref | lv2_atom_forge_long (LV2_Atom_Forge *forge, int64_t val)
static LV2_Atom_Forge_Ref | lv2_atom_forge_float (LV2_Atom_Forge *forge, float val)
static LV2_Atom_Forge_Ref | lv2_atom_forge_double (LV2_Atom_Forge *forge, double val)
static LV2_Atom_Forge_Ref | lv2_atom_forge_bool (LV2_Atom_Forge *forge, bool val)
static LV2_Atom_Forge_Ref | lv2_atom_forge_urid (LV2_Atom_Forge *forge, LV2_URID id)
static LV2_Atom_Forge_Ref | lv2_atom_forge_typed_string (LV2_Atom_Forge *forge, uint32_t type, const char *str, uint32_t len)
static LV2_Atom_Forge_Ref | lv2_atom_forge_string (LV2_Atom_Forge *forge, const char *str, uint32_t len)
static LV2_Atom_Forge_Ref | lv2_atom_forge_uri (LV2_Atom_Forge *forge, const char *uri, uint32_t len)
static LV2_Atom_Forge_Ref | lv2_atom_forge_path (LV2_Atom_Forge *forge, const char *path, uint32_t len)
static LV2_Atom_Forge_Ref | lv2_atom_forge_literal (LV2_Atom_Forge *forge, const char *str, uint32_t len, uint32_t datatype, uint32_t lang)
static LV2_Atom_Forge_Ref | lv2_atom_forge_vector_head (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, uint32_t child_size, uint32_t child_type)
static LV2_Atom_Forge_Ref | lv2_atom_forge_vector (LV2_Atom_Forge *forge, uint32_t child_size, uint32_t child_type, uint32_t n_elems, const void *elems)
static LV2_Atom_Forge_Ref | lv2_atom_forge_tuple (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame)
static LV2_Atom_Forge_Ref | lv2_atom_forge_object (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, LV2_URID id, LV2_URID otype)
static LV2_DEPRECATED LV2_Atom_Forge_Ref | lv2_atom_forge_resource (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, LV2_URID id, LV2_URID otype)
static LV2_DEPRECATED LV2_Atom_Forge_Ref | lv2_atom_forge_blank (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, uint32_t id, LV2_URID otype)
static LV2_Atom_Forge_Ref | lv2_atom_forge_key (LV2_Atom_Forge *forge, LV2_URID key)
static LV2_Atom_Forge_Ref | lv2_atom_forge_property_head (LV2_Atom_Forge *forge, LV2_URID key, LV2_URID context)
static LV2_Atom_Forge_Ref | lv2_atom_forge_sequence_head (LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, uint32_t unit)
static LV2_Atom_Forge_Ref | lv2_atom_forge_frame_time (LV2_Atom_Forge *forge, int64_t frames)
static LV2_Atom_Forge_Ref | lv2_atom_forge_beat_time (LV2_Atom_Forge *forge, double beats)

## Data Structure Documentation

## ◆ LV2_Atom_Forge_Frame

struct LV2_Atom_Forge_Frame

A stack frame used for keeping track of nested Atom containers.

Data Fields
struct LV2_Atom_Forge_Frame * | parent |
LV2_Atom_Forge_Ref | ref |

## ◆ LV2_Atom_Forge

struct LV2_Atom_Forge

A "forge" for creating atoms by appending to a buffer.

Data Fields
uint8_t * | buf |
uint32_t | offset |
uint32_t | size |
LV2_Atom_Forge_Sink | sink |
LV2_Atom_Forge_Deref_Func | deref |
LV2_Atom_Forge_Sink_Handle | handle |
LV2_Atom_Forge_Frame * | stack |
LV2_URID Blank | LV2_DEPRECATED |
LV2_URID | Bool |
LV2_URID | Chunk |
LV2_URID | Double |
LV2_URID | Float |
LV2_URID | Int |
LV2_URID | Long |
LV2_URID | Literal |
LV2_URID | Object |
LV2_URID | Path |
LV2_URID | Property |
LV2_URID Resource | LV2_DEPRECATED |
LV2_URID | Sequence |
LV2_URID | String |
LV2_URID | Tuple |
LV2_URID | URI |
LV2_URID | URID |
LV2_URID | Vector |

## Typedef Documentation

## ◆ LV2_Atom_Forge_Sink_Handle

typedef void* LV2_Atom_Forge_Sink_Handle

Handle for LV2_Atom_Forge_Sink.

## ◆ LV2_Atom_Forge_Ref

typedef intptr_t LV2_Atom_Forge_Ref

A reference to a chunk of written output.

## ◆ LV2_Atom_Forge_Sink

typedef LV2_Atom_Forge_Ref(* LV2_Atom_Forge_Sink) (LV2_Atom_Forge_Sink_Handle handle, const void *buf, uint32_t size)

Sink function for writing output.

See lv2_atom_forge_set_sink().

## ◆ LV2_Atom_Forge_Deref_Func

typedef LV2_Atom *(* LV2_Atom_Forge_Deref_Func) (LV2_Atom_Forge_Sink_Handle handle, LV2_Atom_Forge_Ref ref)

Function for resolving a reference.

See lv2_atom_forge_set_sink().

## Function Documentation

## ◆ lv2_atom_forge_set_buffer()

void lv2_atom_forge_set_buffer | ( | LV2_Atom_Forge * | forge,
|  | uint8_t * | buf,
|  | size_t | size )
| inlinestatic

Set the output buffer where Forge will write atoms.

## ◆ lv2_atom_forge_init()

void lv2_atom_forge_init | ( | LV2_Atom_Forge * | forge,
|  | LV2_URID_Map * | map )
| inlinestatic

Initialise Forge.

URIs will be mapped using map and stored, a reference to map itself is not held.

## ◆ lv2_atom_forge_deref()

LV2_Atom * lv2_atom_forge_deref | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Ref | ref )
| inlinestatic

Access the Atom pointed to by a reference.

## ◆ lv2_atom_forge_push()

LV2_Atom_Forge_Ref lv2_atom_forge_push | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame,
|  | LV2_Atom_Forge_Ref | ref )
| inlinestatic

Push a stack frame.

This is done automatically by container functions (which take a stack frame pointer), but may be called by the user to push the top level container when writing to an existing Atom.

## ◆ lv2_atom_forge_pop()

void lv2_atom_forge_pop | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame )
| inlinestatic

Pop a stack frame.

This must be called when a container is finished.

## ◆ lv2_atom_forge_top_is()

bool lv2_atom_forge_top_is | ( | LV2_Atom_Forge * | forge,
|  | uint32_t | type )
| inlinestatic

Return true iff the top of the stack has the given type.

## ◆ lv2_atom_forge_is_object_type()

bool lv2_atom_forge_is_object_type | ( | const LV2_Atom_Forge * | forge,
|  | uint32_t | type )
| inlinestatic

Return true iff type is an atom:Object.

## ◆ lv2_atom_forge_is_blank()

bool lv2_atom_forge_is_blank | ( | const LV2_Atom_Forge * | forge,
|  | uint32_t | type,
|  | const LV2_Atom_Object_Body * | body )
| inlinestatic

Return true iff type is an atom:Object with a blank ID.

## ◆ lv2_atom_forge_set_sink()

void lv2_atom_forge_set_sink | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Sink | sink,
|  | LV2_Atom_Forge_Deref_Func | deref,
|  | LV2_Atom_Forge_Sink_Handle | handle )
| inlinestatic

Set the sink function where Forge will write output.

The return value of forge functions is an LV2_Atom_Forge_Ref which is an integer type safe to use as a pointer but is otherwise opaque. The sink function must return a ref that can be dereferenced to access as least sizeof(LV2_Atom) bytes of the written data, so sizes can be updated. For ringbuffers, this should be possible as long as the size of the buffer is a multiple of sizeof(LV2_Atom), since atoms are always aligned.

Note that 0 is an invalid reference, so if you are using a buffer offset be sure to offset it such that 0 is never a valid reference. You will get confusing errors otherwise.

## ◆ lv2_atom_forge_raw()

LV2_Atom_Forge_Ref lv2_atom_forge_raw | ( | LV2_Atom_Forge * | forge,
|  | const void * | data,
|  | uint32_t | size )
| inlinestatic

Write raw output.

This is used internally, but is also useful for writing atom types not explicitly supported by the forge API. Note the caller is responsible for ensuring the output is appropriately padded.

## ◆ lv2_atom_forge_pad()

void lv2_atom_forge_pad | ( | LV2_Atom_Forge * | forge,
|  | uint32_t | written )
| inlinestatic

Pad output accordingly so next write is 64-bit aligned.

## ◆ lv2_atom_forge_write()

LV2_Atom_Forge_Ref lv2_atom_forge_write | ( | LV2_Atom_Forge * | forge,
|  | const void * | data,
|  | uint32_t | size )
| inlinestatic

Write raw output, padding to 64-bits as necessary.

## ◆ lv2_atom_forge_string_body()

LV2_Atom_Forge_Ref lv2_atom_forge_string_body | ( | LV2_Atom_Forge * | forge,
|  | const char * | str,
|  | uint32_t | len )
| inlinestatic

Write a null-terminated string body.

## ◆ lv2_atom_forge_atom()

LV2_Atom_Forge_Ref lv2_atom_forge_atom | ( | LV2_Atom_Forge * | forge,
|  | uint32_t | size,
|  | uint32_t | type )
| inlinestatic

Write an atom:Atom header.

## ◆ lv2_atom_forge_primitive()

LV2_Atom_Forge_Ref lv2_atom_forge_primitive | ( | LV2_Atom_Forge * | forge,
|  | const LV2_Atom * | a )
| inlinestatic

Write a primitive (fixed-size) atom.

## ◆ lv2_atom_forge_int()

LV2_Atom_Forge_Ref lv2_atom_forge_int | ( | LV2_Atom_Forge * | forge,
|  | int32_t | val )
| inlinestatic

Write an atom:Int.

## ◆ lv2_atom_forge_long()

LV2_Atom_Forge_Ref lv2_atom_forge_long | ( | LV2_Atom_Forge * | forge,
|  | int64_t | val )
| inlinestatic

Write an atom:Long.

## ◆ lv2_atom_forge_float()

LV2_Atom_Forge_Ref lv2_atom_forge_float | ( | LV2_Atom_Forge * | forge,
|  | float | val )
| inlinestatic

Write an atom:Float.

## ◆ lv2_atom_forge_double()

LV2_Atom_Forge_Ref lv2_atom_forge_double | ( | LV2_Atom_Forge * | forge,
|  | double | val )
| inlinestatic

Write an atom:Double.

## ◆ lv2_atom_forge_bool()

LV2_Atom_Forge_Ref lv2_atom_forge_bool | ( | LV2_Atom_Forge * | forge,
|  | bool | val )
| inlinestatic

Write an atom:Bool.

## ◆ lv2_atom_forge_urid()

LV2_Atom_Forge_Ref lv2_atom_forge_urid | ( | LV2_Atom_Forge * | forge,
|  | LV2_URID | id )
| inlinestatic

Write an atom:URID.

## ◆ lv2_atom_forge_typed_string()

LV2_Atom_Forge_Ref lv2_atom_forge_typed_string | ( | LV2_Atom_Forge * | forge,
|  | uint32_t | type,
|  | const char * | str,
|  | uint32_t | len )
| inlinestatic

Write an atom compatible with atom:String.

Used internally.

## ◆ lv2_atom_forge_string()

LV2_Atom_Forge_Ref lv2_atom_forge_string | ( | LV2_Atom_Forge * | forge,
|  | const char * | str,
|  | uint32_t | len )
| inlinestatic

Write an atom:String.

Note that str need not be NULL terminated.

## ◆ lv2_atom_forge_uri()

LV2_Atom_Forge_Ref lv2_atom_forge_uri | ( | LV2_Atom_Forge * | forge,
|  | const char * | uri,
|  | uint32_t | len )
| inlinestatic

Write an atom:URI.

Note that uri need not be NULL terminated. This does not map the URI, but writes the complete URI string. To write a mapped URI, use lv2_atom_forge_urid().

## ◆ lv2_atom_forge_path()

LV2_Atom_Forge_Ref lv2_atom_forge_path | ( | LV2_Atom_Forge * | forge,
|  | const char * | path,
|  | uint32_t | len )
| inlinestatic

Write an atom:Path.

Note that path need not be NULL terminated.

## ◆ lv2_atom_forge_literal()

LV2_Atom_Forge_Ref lv2_atom_forge_literal | ( | LV2_Atom_Forge * | forge,
|  | const char * | str,
|  | uint32_t | len,
|  | uint32_t | datatype,
|  | uint32_t | lang )
| inlinestatic

Write an atom:Literal.

## ◆ lv2_atom_forge_vector_head()

LV2_Atom_Forge_Ref lv2_atom_forge_vector_head | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame,
|  | uint32_t | child_size,
|  | uint32_t | child_type )
| inlinestatic

Start an atom:Vector.

## ◆ lv2_atom_forge_vector()

LV2_Atom_Forge_Ref lv2_atom_forge_vector | ( | LV2_Atom_Forge * | forge,
|  | uint32_t | child_size,
|  | uint32_t | child_type,
|  | uint32_t | n_elems,
|  | const void * | elems )
| inlinestatic

Write a complete atom:Vector.

## ◆ lv2_atom_forge_tuple()

LV2_Atom_Forge_Ref lv2_atom_forge_tuple | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame )
| inlinestatic

Write the header of an atom:Tuple.

The passed frame will be initialised to represent this tuple. To complete the tuple, write a sequence of atoms, then pop the frame with lv2_atom_forge_pop().

For example:

// Write tuple (1, 2.0)
LV2_Atom_Forge_Frame frame;
LV2_Atom* tup = (LV2_Atom*)lv2_atom_forge_tuple(forge, &frame);
lv2_atom_forge_int(forge, 1);
lv2_atom_forge_float(forge, 2.0);
lv2_atom_forge_pop(forge, &frame);
LV2_Atom
The header of an atom:Atom.
Definition atom.h:97
lv2_atom_forge_tuple
static LV2_Atom_Forge_Ref lv2_atom_forge_tuple(LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame)
Write the header of an atom:Tuple.
Definition forge.h:515
lv2_atom_forge_int
static LV2_Atom_Forge_Ref lv2_atom_forge_int(LV2_Atom_Forge *forge, int32_t val)
Write an atom:Int.
Definition forge.h:352
lv2_atom_forge_pop
static void lv2_atom_forge_pop(LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame)
Pop a stack frame.
Definition forge.h:181
lv2_atom_forge_float
static LV2_Atom_Forge_Ref lv2_atom_forge_float(LV2_Atom_Forge *forge, float val)
Write an atom:Float.
Definition forge.h:368
LV2_Atom_Forge_Frame
A stack frame used for keeping track of nested Atom containers.
Definition forge.h:76

## ◆ lv2_atom_forge_object()

LV2_Atom_Forge_Ref lv2_atom_forge_object | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame,
|  | LV2_URID | id,
|  | LV2_URID | otype )
| inlinestatic

Write the header of an atom:Object.

The passed frame will be initialised to represent this object. To complete the object, write a sequence of properties, then pop the frame with lv2_atom_forge_pop().

For example:

LV2_URID eg_Cat = map("http://example.org/Cat");
LV2_URID eg_name = map("http://example.org/name");
// Start object with type eg_Cat and blank ID
LV2_Atom_Forge_Frame frame;
lv2_atom_forge_object(forge, &frame, 0, eg_Cat);
// Append property eg:name = "Hobbes"
lv2_atom_forge_key(forge, eg_name);
lv2_atom_forge_string(forge, "Hobbes", strlen("Hobbes"));
// Finish object
lv2_atom_forge_pop(forge, &frame);
lv2_atom_forge_string
static LV2_Atom_Forge_Ref lv2_atom_forge_string(LV2_Atom_Forge *forge, const char *str, uint32_t len)
Write an atom:String.
Definition forge.h:419
lv2_atom_forge_key
static LV2_Atom_Forge_Ref lv2_atom_forge_key(LV2_Atom_Forge *forge, LV2_URID key)
Write a property key in an Object, to be followed by the value.
Definition forge.h:602
lv2_atom_forge_object
static LV2_Atom_Forge_Ref lv2_atom_forge_object(LV2_Atom_Forge *forge, LV2_Atom_Forge_Frame *frame, LV2_URID id, LV2_URID otype)
Write the header of an atom:Object.
Definition forge.h:547
LV2_URID
uint32_t LV2_URID
URI mapped to an integer.
Definition urid.h:51

## ◆ lv2_atom_forge_resource()

LV2_DEPRECATED LV2_Atom_Forge_Ref lv2_atom_forge_resource | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame,
|  | LV2_URID | id,
|  | LV2_URID | otype )
| inlinestatic

The same as lv2_atom_forge_object(), but for object:Resource.

This function is deprecated and should not be used in new code. Use lv2_atom_forge_object() directly instead.

## ◆ lv2_atom_forge_blank()

LV2_DEPRECATED LV2_Atom_Forge_Ref lv2_atom_forge_blank | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame,
|  | uint32_t | id,
|  | LV2_URID | otype )
| inlinestatic

The same as lv2_atom_forge_object(), but for object:Blank.

This function is deprecated and should not be used in new code. Use lv2_atom_forge_object() directly instead.

## ◆ lv2_atom_forge_key()

LV2_Atom_Forge_Ref lv2_atom_forge_key | ( | LV2_Atom_Forge * | forge,
|  | LV2_URID | key )
| inlinestatic

Write a property key in an Object, to be followed by the value.

See lv2_atom_forge_object() documentation for an example.

## ◆ lv2_atom_forge_property_head()

LV2_Atom_Forge_Ref lv2_atom_forge_property_head | ( | LV2_Atom_Forge * | forge,
|  | LV2_URID | key,
|  | LV2_URID | context )
| inlinestatic

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.

## ◆ lv2_atom_forge_sequence_head()

LV2_Atom_Forge_Ref lv2_atom_forge_sequence_head | ( | LV2_Atom_Forge * | forge,
|  | LV2_Atom_Forge_Frame * | frame,
|  | uint32_t | unit )
| inlinestatic

Write the header for a Sequence.

## ◆ lv2_atom_forge_frame_time()

LV2_Atom_Forge_Ref lv2_atom_forge_frame_time | ( | LV2_Atom_Forge * | forge,
|  | int64_t | frames )
| inlinestatic

Write the time stamp header of an Event (in a Sequence) in audio frames.

After this, call the appropriate forge method(s) to write the body. Note the returned reference is to an LV2_Event which is NOT an Atom.

## ◆ lv2_atom_forge_beat_time()

LV2_Atom_Forge_Ref lv2_atom_forge_beat_time | ( | LV2_Atom_Forge * | forge,
|  | double | beats )
| inlinestatic

Write the time stamp header of an Event (in a Sequence) in beats.

After this, call the appropriate forge method(s) to write the body. Note the returned reference is to an LV2_Event which is NOT an Atom.