diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jalv.c | 23 | ||||
-rw-r--r-- | src/jalv_internal.h | 6 | ||||
-rw-r--r-- | src/state.c | 40 |
3 files changed, 47 insertions, 22 deletions
@@ -84,11 +84,9 @@ uri_to_id(LV2_URI_Map_Callback_Data callback_data, #define NS_EXT "http://lv2plug.in/ns/ext/" static LV2_URI_Map_Feature uri_map = { NULL, &uri_to_id }; -static const LV2_Feature uri_map_feature = { NS_EXT "uri-map", &uri_map }; -static LV2_URID_Map map = { NULL, &map_uri }; -static const LV2_Feature map_feature = { NS_EXT "urid#map", &map }; -static LV2_URID_Unmap unmap = { NULL, &unmap_uri }; -static const LV2_Feature unmap_feature = { NS_EXT "urid#unmap", &unmap }; +static LV2_Feature uri_map_feature = { NS_EXT "uri-map", &uri_map }; +static LV2_Feature map_feature = { NS_EXT "urid#map", NULL }; +static LV2_Feature unmap_feature = { NS_EXT "urid#unmap", NULL }; static LV2_Feature instance_feature = { NS_EXT "instance-access", NULL }; #ifdef HAVE_LV2_UI_RESIZE @@ -449,7 +447,7 @@ jalv_ui_write(SuilController controller, if (protocol != 0 && protocol != host->atom_prot_id) { fprintf(stderr, "UI write with unsupported protocol %d (%s)\n", - protocol, unmap.unmap(host, protocol)); + protocol, symap_unmap(host->symap, protocol)); return; } @@ -519,12 +517,19 @@ main(int argc, char** argv) host.symap = symap_new(); uri_map.callback_data = &host; - map.handle = &host; - unmap.handle = &host; + + host.map.handle = &host; + host.map.map = map_uri; + map_feature.data = &host.map; + + host.unmap.handle = &host; + host.unmap.unmap = unmap_uri; + unmap_feature.data = &host.unmap; + host.midi_event_id = uri_to_id(&host, "http://lv2plug.in/ns/ext/event", NS_MIDI "MidiEvent"); - host.atom_prot_id = map.map(map.handle, NS_ATOM "atomTransfer"); + host.atom_prot_id = symap_map(host.symap, NS_ATOM "atomTransfer"); #ifdef HAVE_LV2_UI_RESIZE ui_resize.data = &host; diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 1030acd..8c62d9a 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -28,6 +28,8 @@ #include "serd/serd.h" #include "suil/suil.h" +#include "lv2/lv2plug.in/ns/ext/urid/urid.h" + #include "lv2_evbuf.h" #include "symap.h" @@ -92,7 +94,9 @@ typedef struct { SerdWriter* writer; /**< RDF writer (for state) */ struct Property* props; /**< Restored state properties */ SerdNode state_node; /**< Instance state node (for state) */ - SerdNode last_sym; /**< Last port symbol encountered in state */ + SerdNode last_sym; /**< Last port symbol found in state */ + LV2_URID_Map map; + LV2_URID_Unmap unmap; Symap* symap; /**< Symbol (URI) map */ jack_client_t* jack_client; /**< Jack client */ jack_ringbuffer_t* ui_events; /**< Port events from UI */ diff --git a/src/state.c b/src/state.c index 7e4c786..8aa7859 100644 --- a/src/state.c +++ b/src/state.c @@ -46,17 +46,23 @@ property_cmp(const void* a, const void* b) } #ifdef HAVE_LV2_STATE +typedef struct { + LV2_URID_Unmap* unmap; + const SerdNode* subject; + SerdWriter* writer; +} StoreData; + static int -store_callback(void* host_data, +store_callback(void* handle, uint32_t key, const void* value, size_t size, uint32_t type, uint32_t flags) { - Jalv* jalv = (Jalv*)host_data; - const char* key_uri = symap_unmap(jalv->symap, key); - const char* type_uri = symap_unmap(jalv->symap, type); + StoreData* data = (StoreData*)handle; + const char* key_uri = data->unmap->unmap(data->unmap->handle, key); + const char* type_uri = data->unmap->unmap(data->unmap->handle, type); if (strcmp(type_uri, (const char*)(NS_ATOM "String"))) { fprintf(stderr, "error: Unsupported (not atom:String) value stored\n"); return 1; @@ -67,8 +73,8 @@ store_callback(void* host_data, const SerdNode o = serd_node_from_string(SERD_LITERAL, USTR(value)); const SerdNode t = serd_node_from_string(SERD_URI, USTR(type_uri)); - serd_writer_write_statement(jalv->writer, SERD_ANON_CONT, NULL, - &jalv->state_node, &p, &o, &t, NULL); + serd_writer_write_statement(data->writer, SERD_ANON_CONT, NULL, + data->subject, &p, &o, &t, NULL); return 0; } @@ -77,22 +83,29 @@ store_callback(void* host_data, return 1; } +typedef struct { + LV2_URID_Map* map; + const struct Property* props; + const uint32_t num_props; +} RetrieveData; + static const void* -retrieve_callback(void* host_data, +retrieve_callback(void* handle, uint32_t key, size_t* size, uint32_t* type, uint32_t* flags) { - Jalv* jalv = (Jalv*)host_data; + RetrieveData* data = (RetrieveData*)handle; struct Property search_key = { key, SERD_NODE_NULL, SERD_NODE_NULL }; struct Property* prop = (struct Property*)bsearch( - &search_key, jalv->props, jalv->num_props, + &search_key, data->props, data->num_props, sizeof(struct Property), property_cmp); if (prop) { *size = prop->value.n_bytes; - *type = symap_map(jalv->symap, (const char*)(NS_ATOM "String")); + *type = data->map->map(data->map->handle, + (const char*)(NS_ATOM "String")); *flags = 0; return prop->value.buf; } @@ -175,10 +188,12 @@ jalv_save(Jalv* jalv, const char* dir) &state_instanceState, &jalv->state_node, NULL, NULL); + StoreData data = { &jalv->unmap, &jalv->state_node, jalv->writer }; + // Write properties to state blank node state->save(lilv_instance_get_handle(jalv->instance), store_callback, - jalv, + &data, LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE, NULL); @@ -290,9 +305,10 @@ jalv_restore_instance(Jalv* jalv, const char* dir) lilv_instance_get_extension_data(jalv->instance, LV2_STATE_INTERFACE_URI); if (state_iface) { + RetrieveData data = { &jalv->map, jalv->props, jalv->num_props }; state_iface->restore(lilv_instance_get_handle(jalv->instance), retrieve_callback, - jalv, 0, NULL); + &data, 0, NULL); } #endif // HAVE_LV2_STATE } |