aboutsummaryrefslogtreecommitdiff
path: root/props.lv2/test
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-18 10:27:22 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-18 10:27:22 +0100
commit6ca13cb62f077b7e28407f9ced62cd7b699bb503 (patch)
treec6d09b657c3facf1b790d2fdefc1faaa5d1a36de /props.lv2/test
parent3c8086a604dc53d234532aa1480649cdb057c7ce (diff)
parent914a279624f7252b5981c988f583d17d119c0918 (diff)
downloadsherlock.lv2-6ca13cb62f077b7e28407f9ced62cd7b699bb503.tar.xz
Merge commit '914a279624f7252b5981c988f583d17d119c0918'
Diffstat (limited to 'props.lv2/test')
-rw-r--r--props.lv2/test/props.c375
-rw-r--r--props.lv2/test/props.ttl2
2 files changed, 108 insertions, 269 deletions
diff --git a/props.lv2/test/props.c b/props.lv2/test/props.c
index 516d48c..e4b27d8 100644
--- a/props.lv2/test/props.c
+++ b/props.lv2/test/props.c
@@ -24,24 +24,13 @@
#define PROPS_PREFIX "http://open-music-kontrollers.ch/lv2/props#"
#define PROPS_TEST_URI PROPS_PREFIX"test"
-#define MAX_NPROPS 33
+#define MAX_NPROPS 7
#define MAX_STRLEN 256
-typedef struct _plugstate0_t plugstate0_t;
-typedef struct _plugstate1_t plugstate1_t;
+typedef struct _plugstate_t plugstate_t;
typedef struct _plughandle_t plughandle_t;
-struct _plugstate0_t {
- int32_t val1;
- int64_t val2;
- float val3;
- double val4;
- int32_t val5;
- int32_t val6;
- char val7 [MAX_STRLEN];
-};
-
-struct _plugstate1_t {
+struct _plugstate_t {
int32_t val1;
int64_t val2;
float val3;
@@ -61,18 +50,12 @@ struct _plughandle_t {
LV2_URID log_note;
PROPS_T(props, MAX_NPROPS);
-
- plugstate0_t dyn;
- plugstate0_t _dyn;
-
- plugstate1_t stat;
- plugstate1_t _stat;
+ plugstate_t state;
+ plugstate_t stash;
struct {
- LV2_URID stat2;
- LV2_URID stat4;
- LV2_URID dyn2;
- LV2_URID dyn4;
+ LV2_URID val2;
+ LV2_URID val4;
} urid;
const LV2_Atom_Sequence *event_in;
@@ -109,65 +92,33 @@ _intercept(void *data, LV2_Atom_Forge *forge, int64_t frames,
{
case PROP_EVENT_GET:
{
- _log_printf(handle, handle->log_trace, "GET : %s", impl->def->label);
+ _log_printf(handle, handle->log_trace, "GET : %s", impl->def->property);
break;
}
case PROP_EVENT_SET:
{
- _log_printf(handle, handle->log_trace, "SET : %s", impl->def->label);
+ _log_printf(handle, handle->log_trace, "SET : %s", impl->def->property);
break;
}
case PROP_EVENT_REGISTER:
{
- _log_printf(handle, handle->log_trace, "REGISTER: %s", impl->def->label);
+ _log_printf(handle, handle->log_trace, "REGISTER: %s", impl->def->property);
break;
}
case PROP_EVENT_SAVE:
{
- _log_printf(handle, handle->log_note, "SAVE : %s", impl->def->label);
+ _log_printf(handle, handle->log_note, "SAVE : %s", impl->def->property);
break;
}
case PROP_EVENT_RESTORE:
{
- _log_printf(handle, handle->log_note, "RESTORE : %s", impl->def->label);
+ _log_printf(handle, handle->log_note, "RESTORE : %s", impl->def->property);
break;
}
}
}
static void
-_intercept_dyn1(void *data, LV2_Atom_Forge *forge, int64_t frames,
- props_event_t event, props_impl_t *impl)
-{
- plughandle_t *handle = data;
-
- _intercept(data, forge, frames, event, impl);
-
- if(event & PROP_EVENT_WRITE)
- {
- handle->dyn.val2 = handle->dyn.val1 * 2;
-
- props_set(&handle->props, forge, frames, handle->urid.dyn2, &handle->ref);
- }
-}
-
-static void
-_intercept_dyn3(void *data, LV2_Atom_Forge *forge, int64_t frames,
- props_event_t event, props_impl_t *impl)
-{
- plughandle_t *handle = data;
-
- _intercept(data, forge, frames, event, impl);
-
- if(event & PROP_EVENT_WRITE)
- {
- handle->dyn.val4 = handle->dyn.val3 * 2;
-
- props_set(&handle->props, forge, frames, handle->urid.dyn4, &handle->ref);
- }
-}
-
-static void
_intercept_stat1(void *data, LV2_Atom_Forge *forge, int64_t frames,
props_event_t event, props_impl_t *impl)
{
@@ -177,9 +128,10 @@ _intercept_stat1(void *data, LV2_Atom_Forge *forge, int64_t frames,
if(event & PROP_EVENT_WRITE)
{
- handle->stat.val2 = handle->stat.val1 * 2;
+ handle->state.val2 = handle->state.val1 * 2;
- props_set(&handle->props, forge, frames, handle->urid.stat2, &handle->ref);
+ if(forge)
+ props_set(&handle->props, forge, frames, handle->urid.val2, &handle->ref);
}
}
@@ -193,9 +145,10 @@ _intercept_stat3(void *data, LV2_Atom_Forge *forge, int64_t frames,
if(event & PROP_EVENT_WRITE)
{
- handle->stat.val4 = handle->stat.val3 * 2;
+ handle->state.val4 = handle->state.val3 * 2;
- props_set(&handle->props, forge, frames, handle->urid.stat4, &handle->ref);
+ if(forge)
+ props_set(&handle->props, forge, frames, handle->urid.val4, &handle->ref);
}
}
@@ -209,189 +162,70 @@ _intercept_stat6(void *data, LV2_Atom_Forge *forge, int64_t frames,
if(event & PROP_EVENT_WRITE)
{
- const char *path = strstr(handle->stat.val6, "file://")
- ? handle->stat.val6 + 7 // skip "file://"
- : handle->stat.val6;
+ const char *path = strstr(handle->state.val6, "file://")
+ ? handle->state.val6 + 7 // skip "file://"
+ : handle->state.val6;
FILE *f = fopen(path, "wb"); // create empty file
if(f)
fclose(f);
}
}
-static const props_def_t dyn1 = {
- .label = "Int",
- .comment = "This is a 32-bit integer",
- .property = PROPS_PREFIX"Int",
- .access = LV2_PATCH__writable,
- .unit = LV2_UNITS__hz,
- .type = LV2_ATOM__Int,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept_dyn1,
- .minimum.i = 0,
- .maximum.i = 10
-};
-
-static const props_def_t dyn2 = {
- .label = "Long",
- .comment = "This is a 64-bit integer",
- .property = PROPS_PREFIX"Long",
- .access = LV2_PATCH__readable,
- .unit = LV2_UNITS__khz,
- .type = LV2_ATOM__Long,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
- .minimum.h = 0,
- .maximum.h = 20
-};
-
-static const props_def_t dyn3 = {
- .label = "Float",
- .comment = "This is a 32-bit floating point",
- .property = PROPS_PREFIX"Float",
- .access = LV2_PATCH__writable,
- .unit = LV2_UNITS__mhz,
- .type = LV2_ATOM__Float,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept_dyn3,
- .minimum.f = -0.5f,
- .maximum.f = 0.5f
-};
-
-static const props_def_t dyn4 = {
- .label = "Double",
- .comment = "This is a 64-bit floating point",
- .property = PROPS_PREFIX"Double",
- .access = LV2_PATCH__readable,
- .unit = LV2_UNITS__db,
- .type = LV2_ATOM__Double,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
- .minimum.d = -1.0,
- .maximum.d = 1.0
-};
-
-static const props_scale_point_t scale_points5 [] = {
- {.label = "One", .value.i = 0},
- {.label = "Two", .value.i = 1},
- {.label = "Three", .value.i = 2},
- {.label = "Four", .value.i = 3},
- {.label = NULL } // sentinel
-};
-
-static const props_def_t dyn5 = {
- .label = "scaleInt",
- .comment = "This is a 32-bit integer enumeration",
- .property = PROPS_PREFIX"scaleInt",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__Int,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
- .minimum.i = 0,
- .maximum.i = 3,
- .scale_points = scale_points5
-};
-
-static const props_def_t dyn6 = {
- .label = "Bool",
- .comment = "This is a boolean",
- .property = PROPS_PREFIX"Bool",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__Bool,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
- .minimum.d = 0,
- .maximum.d = 1
-};
-
-static const props_def_t dyn7 = {
- .label = "String",
- .comment = "This is a string",
- .property = PROPS_PREFIX"String",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__String,
- .mode = PROP_MODE_DYNAMIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
- .max_size = MAX_STRLEN // strlen
-};
-
-static const props_def_t stat1 = {
- .label = "statInt",
- .property = PROPS_PREFIX"statInt",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__Int,
- .mode = PROP_MODE_STATIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept_stat1,
-};
-
-static const props_def_t stat2 = {
- .label = "statLong",
- .property = PROPS_PREFIX"statLong",
- .access = LV2_PATCH__readable,
- .type = LV2_ATOM__Long,
- .mode = PROP_MODE_STATIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
-};
-
-static const props_def_t stat3 = {
- .label = "statFloat",
- .property = PROPS_PREFIX"statFloat",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__Float,
- .mode = PROP_MODE_STATIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept_stat3,
-};
-
-static const props_def_t stat4 = {
- .label = "statDouble",
- .property = PROPS_PREFIX"statDouble",
- .access = LV2_PATCH__readable,
- .type = LV2_ATOM__Double,
- .mode = PROP_MODE_STATIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
-};
-
-static const props_def_t stat5 = {
- .label = "statString",
- .property = PROPS_PREFIX"statString",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__String,
- .mode = PROP_MODE_STATIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept,
- .max_size = MAX_STRLEN // strlen
-};
-
-static const props_def_t stat6 = {
- .label = "statPath",
- .property = PROPS_PREFIX"statPath",
- .access = LV2_PATCH__writable,
- .type = LV2_ATOM__Path,
- .mode = PROP_MODE_STATIC,
- .event_mask = PROP_EVENT_ALL,
- .event_cb = _intercept_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 const props_def_t defs [MAX_NPROPS] = {
+ {
+ .property = PROPS_PREFIX"statInt",
+ .offset = offsetof(plugstate_t, val1),
+ .type = LV2_ATOM__Int,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept_stat1,
+ },
+ {
+ .property = PROPS_PREFIX"statLong",
+ .access = LV2_PATCH__readable,
+ .offset = offsetof(plugstate_t, val2),
+ .type = LV2_ATOM__Long,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept,
+ },
+ {
+ .property = PROPS_PREFIX"statFloat",
+ .offset = offsetof(plugstate_t, val3),
+ .type = LV2_ATOM__Float,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept_stat3,
+ },
+ {
+ .property = PROPS_PREFIX"statDouble",
+ .access = LV2_PATCH__readable,
+ .offset = offsetof(plugstate_t, val4),
+ .type = LV2_ATOM__Double,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept,
+ },
+ {
+ .property = PROPS_PREFIX"statString",
+ .offset = offsetof(plugstate_t, val5),
+ .type = LV2_ATOM__String,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept,
+ .max_size = MAX_STRLEN // strlen
+ },
+ {
+ .property = PROPS_PREFIX"statPath",
+ .offset = offsetof(plugstate_t, val6),
+ .type = LV2_ATOM__Path,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept_stat6,
+ .max_size = MAX_STRLEN // strlen
+ },
+ {
+ .property = PROPS_PREFIX"statChunk",
+ .offset = offsetof(plugstate_t, val7),
+ .type = LV2_ATOM__Chunk,
+ .event_mask = PROP_EVENT_ALL,
+ .event_cb = _intercept,
+ .max_size = MAX_STRLEN // strlen
+ }
};
static LV2_Handle
@@ -436,36 +270,16 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
return NULL;
}
- plugstate0_t *dyn = &handle->dyn;
- plugstate0_t *_dyn = &handle->_dyn;
- plugstate1_t *stat = &handle->stat;
- plugstate1_t *_stat = &handle->_stat;
-
- if( !props_register(&handle->props, &dyn1, &dyn->val1, &_dyn->val1)
- || !(handle->urid.dyn2 =
- props_register(&handle->props, &dyn2, &dyn->val2, &_dyn->val2))
- || !props_register(&handle->props, &dyn3, &dyn->val3, &_dyn->val3)
- || !(handle->urid.dyn4 =
- props_register(&handle->props, &dyn4, &dyn->val4, &_dyn->val4))
- || !props_register(&handle->props, &dyn5, &dyn->val5, &_dyn->val5)
- || !props_register(&handle->props, &dyn6, &dyn->val6, &_dyn->val6)
- || !props_register(&handle->props, &dyn7, &dyn->val7, &_dyn->val7)
-
- || !props_register(&handle->props, &stat1, &stat->val1, &_stat->val1)
- || !(handle->urid.stat2 =
- props_register(&handle->props, &stat2, &stat->val2, &_stat->val2))
- || !props_register(&handle->props, &stat3, &stat->val3, &_stat->val3)
- || !(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, &stat7, &stat->val7, &_stat->val7) )
+ if(!props_register(&handle->props, defs, MAX_NPROPS, &handle->state, &handle->stash))
{
_log_printf(handle, handle->log_trace, "ERR : registering");
free(handle);
return NULL;
}
+ handle->urid.val2 = props_map(&handle->props, PROPS_PREFIX"statLong");
+ handle->urid.val4 = props_map(&handle->props, PROPS_PREFIX"statDouble");
+
return handle;
}
@@ -525,7 +339,7 @@ _state_save(LV2_Handle instance, LV2_State_Store_Function store,
{
plughandle_t *handle = (plughandle_t *)instance;
- return props_save(&handle->props, &handle->forge, store, state, flags, features);
+ return props_save(&handle->props, store, state, flags, features);
}
static LV2_State_Status
@@ -535,7 +349,7 @@ _state_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve,
{
plughandle_t *handle = (plughandle_t *)instance;
- return props_restore(&handle->props, &handle->forge, retrieve, state, flags, features);
+ return props_restore(&handle->props, retrieve, state, flags, features);
}
LV2_State_Interface state_iface = {
@@ -543,11 +357,36 @@ LV2_State_Interface state_iface = {
.restore = _state_restore
};
+static inline LV2_Worker_Status
+_work(LV2_Handle instance, LV2_Worker_Respond_Function respond,
+LV2_Worker_Respond_Handle worker, uint32_t size, const void *body)
+{
+ plughandle_t *handle = instance;
+
+ return props_work(&handle->props, respond, worker, size, body);
+}
+
+static inline LV2_Worker_Status
+_work_response(LV2_Handle instance, uint32_t size, const void *body)
+{
+ plughandle_t *handle = instance;
+
+ return props_work_response(&handle->props, size, body);
+}
+
+LV2_Worker_Interface work_iface = {
+ .work = _work,
+ .work_response = _work_response,
+ .end_run = NULL
+};
+
static const void *
extension_data(const char *uri)
{
if(!strcmp(uri, LV2_STATE__interface))
return &state_iface;
+ else if(!strcmp(uri, LV2_WORKER__interface))
+ return &work_iface;
return NULL;
}
diff --git a/props.lv2/test/props.ttl b/props.lv2/test/props.ttl
index 282710b..3f6b188 100644
--- a/props.lv2/test/props.ttl
+++ b/props.lv2/test/props.ttl
@@ -108,7 +108,7 @@ props:test
lv2:project proj:props ;
lv2:extensionData state:interface ;
lv2:requiredFeature urid:map, log:log, state:loadDefaultState ;
- lv2:optionalFeature lv2:isLive, lv2:hardRTCapable ;
+ lv2:optionalFeature lv2:isLive, lv2:hardRTCapable, state:threadSafeRestore ;
lv2:port [
# sink event port