aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--props.lv2/CMakeLists.txt1
-rw-r--r--props.lv2/props.h84
-rw-r--r--props.lv2/test/chunk.binbin0 -> 16 bytes
-rw-r--r--props.lv2/test/props.c17
-rw-r--r--props.lv2/test/props.ttl24
5 files changed, 101 insertions, 25 deletions
diff --git a/props.lv2/CMakeLists.txt b/props.lv2/CMakeLists.txt
index f9c84b9..2fff6f0 100644
--- a/props.lv2/CMakeLists.txt
+++ b/props.lv2/CMakeLists.txt
@@ -34,6 +34,7 @@ target_link_libraries(props ${LIBS})
set_target_properties(props PROPERTIES PREFIX "")
install(TARGETS props DESTINATION ${DEST})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/props.ttl DESTINATION ${DEST})
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/chunk.bin DESTINATION ${DEST})
# manifest
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/manifest.ttl.in ${PROJECT_BINARY_DIR}/manifest.ttl)
diff --git a/props.lv2/props.h b/props.lv2/props.h
index f944719..d147e04 100644
--- a/props.lv2/props.h
+++ b/props.lv2/props.h
@@ -24,6 +24,7 @@ extern "C" {
#include <stdlib.h>
#include <stdatomic.h>
+#include <stdio.h>
#include <lv2/lv2plug.in/ns/lv2core/lv2.h>
#include <lv2/lv2plug.in/ns/ext/urid/urid.h>
@@ -38,7 +39,7 @@ extern "C" {
*****************************************************************************/
// definitions
-#define PROPS_TYPE_N 9
+#define PROPS_TYPE_N 10
// unions
typedef union _props_raw_t props_raw_t;
@@ -73,6 +74,7 @@ typedef void (*props_type_set_cb_t)(
props_impl_t *impl,
void *value,
LV2_URID new_type,
+ uint32_t sz,
const void *new_value);
union _props_raw_t {
@@ -184,6 +186,7 @@ struct _props_t {
LV2_URID atom_string;
LV2_URID atom_path;
LV2_URID atom_uri;
+ LV2_URID atom_chunk;
LV2_URID units_unit;
} urid;
@@ -283,7 +286,7 @@ _props_bool_get_cb(LV2_Atom_Forge *forge, const void *value)
}
static void
_props_int_set_cb(props_impl_t *impl, void *value,
- LV2_URID new_type, const void *new_value)
+ LV2_URID new_type, uint32_t sz, const void *new_value)
{
const props_t *props = impl->props;
int32_t *ref = value;
@@ -310,7 +313,7 @@ _props_long_get_cb(LV2_Atom_Forge *forge, const void *value)
}
static void
_props_long_set_cb(props_impl_t *impl, void *value,
- LV2_URID new_type, const void *new_value)
+ LV2_URID new_type, uint32_t sz, const void *new_value)
{
const props_t *props = impl->props;
int64_t *ref = value;
@@ -337,7 +340,7 @@ _props_float_get_cb(LV2_Atom_Forge *forge, const void *value)
}
static void
_props_float_set_cb(props_impl_t *impl, void *value,
- LV2_URID new_type, const void *new_value)
+ LV2_URID new_type, uint32_t sz, const void *new_value)
{
const props_t *props = impl->props;
float *ref = value;
@@ -364,7 +367,7 @@ _props_double_get_cb(LV2_Atom_Forge *forge, const void *value)
}
static void
_props_double_set_cb(props_impl_t *impl, void *value,
- LV2_URID new_type, const void *new_value)
+ LV2_URID new_type, uint32_t sz, const void *new_value)
{
const props_t *props = impl->props;
double *ref = value;
@@ -391,7 +394,7 @@ _props_urid_get_cb(LV2_Atom_Forge *forge, const void *value)
}
static void
_props_urid_set_cb(props_impl_t *impl, void *value,
- LV2_URID new_type, const void *new_value)
+ LV2_URID new_type, uint32_t sz, const void *new_value)
{
const props_t *props = impl->props;
uint32_t *ref = value;
@@ -433,7 +436,7 @@ _props_uri_get_cb(LV2_Atom_Forge *forge, const void *value)
}
static void
_props_string_set_cb(props_impl_t *impl, void *value,
- LV2_URID new_type, const void *new_value)
+ LV2_URID new_type, uint32_t sz, const void *new_value)
{
const props_t *props = impl->props;
@@ -443,6 +446,39 @@ _props_string_set_cb(props_impl_t *impl, void *value,
strncpy((char *)value, (const char *)new_value, impl->def->max_size);
}
+static uint32_t
+_props_chunk_size_cb(const void *value)
+{
+ const uint32_t sz = *(uint32_t *)value;
+ return sz;
+}
+static LV2_Atom_Forge_Ref
+_props_chunk_get_cb(LV2_Atom_Forge *forge, const void *value)
+{
+ const uint32_t sz = *(uint32_t *)value;
+ const uint8_t *src = value + sizeof(uint32_t);
+ LV2_Atom_Forge_Ref ref;
+
+ return (ref = lv2_atom_forge_atom(forge, sz, forge->Chunk))
+ && (ref = lv2_atom_forge_write(forge, src, sz));
+}
+static void
+_props_chunk_set_cb(props_impl_t *impl, void *value,
+ LV2_URID new_type, uint32_t sz, const void *new_value)
+{
+ const props_t *props = impl->props;
+
+ if(new_type == props->urid.atom_chunk)
+ {
+ *(uint32_t *)value = sz; // set chunk size
+ uint8_t *dst = value + sizeof(uint32_t);
+ const uint32_t msz = sz < impl->def->max_size - sizeof(uint32_t)
+ ? sz
+ : impl->def->max_size - sizeof(uint32_t);
+ memcpy(dst, new_value, msz);
+ }
+}
+
static inline void
_type_qsort(props_type_t *a, unsigned n)
{
@@ -603,9 +639,9 @@ _props_stash(props_t *props, props_impl_t *impl)
}
static inline void
-_props_set(props_t *props, props_impl_t *impl, LV2_URID type, const void *value)
+_props_set(props_t *props, props_impl_t *impl, LV2_URID type, uint32_t sz, const void *value)
{
- impl->type->set_cb(impl, impl->value, type, value);
+ impl->type->set_cb(impl, impl->value, type, sz, value);
_props_stash(props, impl);
}
@@ -757,13 +793,17 @@ _props_reg(props_t *props, LV2_Atom_Forge *forge, uint32_t frames, props_impl_t
if(def->scale_points)
{
+ LV2_Atom_Forge_Frame tuple_frame;
+ if(ref)
+ ref = lv2_atom_forge_key(forge, props->urid.lv2_scale_point);
+ if(ref)
+ ref = lv2_atom_forge_tuple(forge, &tuple_frame);
+
for(const props_scale_point_t *sp = def->scale_points; sp->label; sp++)
{
LV2_Atom_Forge_Frame scale_point_frame;
if(ref)
- ref = lv2_atom_forge_key(forge, props->urid.lv2_scale_point);
- if(ref)
ref = lv2_atom_forge_object(forge, &scale_point_frame, 0, 0);
{
if(ref)
@@ -779,6 +819,9 @@ _props_reg(props_t *props, LV2_Atom_Forge *forge, uint32_t frames, props_impl_t
if(ref)
lv2_atom_forge_pop(forge, &scale_point_frame);
}
+
+ if(ref)
+ lv2_atom_forge_pop(forge, &tuple_frame);
}
}
if(ref)
@@ -841,6 +884,7 @@ props_init(props_t *props, const size_t max_nimpls, const char *subject,
props->urid.atom_string = map->map(map->handle, LV2_ATOM__String);
props->urid.atom_path = map->map(map->handle, LV2_ATOM__Path);
props->urid.atom_uri = map->map(map->handle, LV2_ATOM__URI);
+ props->urid.atom_chunk = map->map(map->handle, LV2_ATOM__Chunk);
props->urid.units_unit = map->map(map->handle, LV2_UNITS__unit);
@@ -917,6 +961,14 @@ props_init(props_t *props, const size_t max_nimpls, const char *subject,
props->types[ptr].set_cb = _props_string_set_cb;
ptr++;
+ // URI
+ props->types[ptr].urid = props->urid.atom_chunk;
+ props->types[ptr].size = 0;
+ props->types[ptr].size_cb = _props_chunk_size_cb;
+ props->types[ptr].get_cb = _props_chunk_get_cb;
+ props->types[ptr].set_cb = _props_chunk_set_cb;
+ ptr++;
+
assert(ptr == PROPS_TYPE_N);
_type_qsort(props->types, PROPS_TYPE_N);
@@ -1076,7 +1128,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
props_impl_t *impl = _props_impl_search(props, property->body);
if(impl && (impl->access == props->urid.patch_writable) )
{
- _props_set(props, impl, value->type, LV2_ATOM_BODY_CONST(value));
+ _props_set(props, impl, value->type, value->size, LV2_ATOM_BODY_CONST(value));
const props_def_t *def = impl->def;
if(def->event_cb && (def->event_mask & PROP_EVENT_SET) )
@@ -1118,7 +1170,7 @@ props_advance(props_t *props, LV2_Atom_Forge *forge, uint32_t frames,
props_impl_t *impl = _props_impl_search(props, property);
if(impl && (impl->access == props->urid.patch_writable) )
{
- _props_set(props, impl, value->type, LV2_ATOM_BODY_CONST(value));
+ _props_set(props, impl, value->type, value->size, LV2_ATOM_BODY_CONST(value));
const props_def_t *def = impl->def;
if(def->event_cb && (def->event_mask & PROP_EVENT_SET) )
@@ -1196,7 +1248,7 @@ props_save(props_t *props, LV2_Atom_Forge *forge, LV2_State_Store_Function store
? value + 7 // skip "file://"
: value;
char *abstract = map_path->abstract_path(map_path->handle, path);
- if(abstract)
+ if(abstract && strcmp(abstract, path))
{
store(state, impl->property, abstract, strlen(abstract) + 1, impl->type->urid, flags);
free(abstract);
@@ -1249,13 +1301,13 @@ props_restore(props_t *props, LV2_Atom_Forge *forge, LV2_State_Retrieve_Function
char *absolute = map_path->absolute_path(map_path->handle, value);
if(absolute)
{
- _props_set(props, impl, type, absolute);
+ _props_set(props, impl, type, strlen(absolute) + 1, absolute);
free(absolute);
}
}
else // !Path
{
- _props_set(props, impl, type, value);
+ _props_set(props, impl, type, size, value);
}
const props_def_t *def = impl->def;
diff --git a/props.lv2/test/chunk.bin b/props.lv2/test/chunk.bin
new file mode 100644
index 0000000..b66efb8
--- /dev/null
+++ b/props.lv2/test/chunk.bin
Binary files differ
diff --git a/props.lv2/test/props.c b/props.lv2/test/props.c
index 2744ecb..516d48c 100644
--- a/props.lv2/test/props.c
+++ b/props.lv2/test/props.c
@@ -24,7 +24,7 @@
#define PROPS_PREFIX "http://open-music-kontrollers.ch/lv2/props#"
#define PROPS_TEST_URI PROPS_PREFIX"test"
-#define MAX_NPROPS 32
+#define MAX_NPROPS 33
#define MAX_STRLEN 256
typedef struct _plugstate0_t plugstate0_t;
@@ -48,6 +48,7 @@ struct _plugstate1_t {
double val4;
char val5 [MAX_STRLEN];
char val6 [MAX_STRLEN];
+ uint8_t val7 [MAX_STRLEN];
};
struct _plughandle_t {
@@ -382,6 +383,17 @@ static const props_def_t stat6 = {
.max_size = MAX_STRLEN // strlen
};
+static const props_def_t stat7 = {
+ .label = "statChunk",
+ .property = PROPS_PREFIX"statChunk",
+ .access = LV2_PATCH__writable,
+ .type = LV2_ATOM__Chunk,
+ .mode = PROP_MODE_STATIC,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept,
+ .max_size = MAX_STRLEN // strlen
+};
+
static LV2_Handle
instantiate(const LV2_Descriptor* descriptor, double rate,
const char *bundle_path, const LV2_Feature *const *features)
@@ -446,7 +458,8 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
|| !(handle->urid.stat4 =
props_register(&handle->props, &stat4, &stat->val4, &_stat->val4))
|| !props_register(&handle->props, &stat5, &stat->val5, &_stat->val5)
- || !props_register(&handle->props, &stat6, &stat->val6, &_stat->val6) )
+ || !props_register(&handle->props, &stat6, &stat->val6, &_stat->val6)
+ || !props_register(&handle->props, &stat7, &stat->val7, &_stat->val7) )
{
_log_printf(handle, handle->log_trace, "ERR : registering");
free(handle);
diff --git a/props.lv2/test/props.ttl b/props.lv2/test/props.ttl
index 7c5e111..17a8041 100644
--- a/props.lv2/test/props.ttl
+++ b/props.lv2/test/props.ttl
@@ -93,6 +93,12 @@ props:statPath
rdfs:label "statPath" ;
rdfs:comment "This is a path" .
+props:statChunk
+ a lv2:Parameter ;
+ rdfs:range atom:Chunk;
+ rdfs:label "statChunk" ;
+ rdfs:comment "This is a chunk" .
+
# Looper Test
props:test
a lv2:Plugin ,
@@ -126,17 +132,21 @@ props:test
lv2:designation lv2:control ;
] ;
- patch:writable props:statInt ;
- patch:writable props:statFloat ;
- patch:writable props:statString ;
- patch:writable props:statPath ;
+ patch:writable
+ props:statInt ,
+ props:statFloat ,
+ props:statString ,
+ props:statPath ,
+ props:statChunk ;
- patch:readable props:statLong ;
- patch:readable props:statDouble ;
+ patch:readable
+ props:statLong ,
+ props:statDouble ;
state:state [
props:statInt 4 ;
props:statFloat "0.4"^^xsd:float ;
props:statString "Hello world" ;
- props:statPath <hello.world> ;
+ props:statPath <manifest.ttl> ;
+ props:statChunk "Q"^^xsd:base64Binary ;
] .