aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dumper.c81
-rw-r--r--src/dumper.h38
-rw-r--r--src/jalv.c64
-rw-r--r--src/jalv_internal.h14
-rw-r--r--src/mapper.c6
5 files changed, 135 insertions, 68 deletions
diff --git a/src/dumper.c b/src/dumper.c
new file mode 100644
index 0000000..64f66e9
--- /dev/null
+++ b/src/dumper.c
@@ -0,0 +1,81 @@
+// Copyright 2012-2024 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "dumper.h"
+
+#include "log.h"
+
+#include "lilv/lilv.h"
+#include "lv2/atom/atom.h"
+#include "lv2/patch/patch.h"
+#include "lv2/time/time.h"
+#include "lv2/urid/urid.h"
+#include "serd/serd.h"
+#include "sratom/sratom.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+
+struct JalvDumperImpl {
+ LV2_URID_Unmap* unmap;
+ SerdEnv* env;
+ Sratom* sratom;
+};
+
+JalvDumper*
+jalv_dumper_new(LV2_URID_Map* const map, LV2_URID_Unmap* const unmap)
+{
+ JalvDumper* const dumper = (JalvDumper*)calloc(1, sizeof(JalvDumper));
+ SerdEnv* const env = serd_env_new(NULL);
+ Sratom* const sratom = sratom_new(map);
+ if (!dumper || !env || !sratom) {
+ jalv_dumper_free(dumper);
+ return NULL;
+ }
+
+ serd_env_set_prefix_from_strings(
+ env, (const uint8_t*)"patch", (const uint8_t*)LV2_PATCH_PREFIX);
+ serd_env_set_prefix_from_strings(
+ env, (const uint8_t*)"time", (const uint8_t*)LV2_TIME_PREFIX);
+ serd_env_set_prefix_from_strings(
+ env, (const uint8_t*)"xsd", (const uint8_t*)LILV_NS_XSD);
+
+ dumper->env = env;
+ dumper->sratom = sratom;
+ dumper->unmap = unmap;
+ return dumper;
+}
+
+void
+jalv_dumper_free(JalvDumper* const dumper)
+{
+ if (dumper) {
+ sratom_free(dumper->sratom);
+ serd_env_free(dumper->env);
+ free(dumper);
+ }
+}
+
+void
+jalv_dump_atom(JalvDumper* const dumper,
+ FILE* const stream,
+ const char* const label,
+ const LV2_Atom* const atom,
+ const int color)
+{
+ if (dumper) {
+ char* const str = sratom_to_turtle(dumper->sratom,
+ dumper->unmap,
+ "jalv:",
+ NULL,
+ NULL,
+ atom->type,
+ atom->size,
+ LV2_ATOM_BODY_CONST(atom));
+
+ jalv_ansi_start(stream, color);
+ fprintf(stream, "\n# %s (%u bytes):\n%s\n", label, atom->size, str);
+ jalv_ansi_reset(stream);
+ free(str);
+ }
+}
diff --git a/src/dumper.h b/src/dumper.h
new file mode 100644
index 0000000..9b0cec9
--- /dev/null
+++ b/src/dumper.h
@@ -0,0 +1,38 @@
+// Copyright 2012-2024 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_DUMPER_H
+#define JALV_DUMPER_H
+
+#include "attributes.h"
+
+#include "lv2/atom/atom.h"
+#include "lv2/urid/urid.h"
+
+#include <stdio.h>
+
+// LV2 atom dumper
+JALV_BEGIN_DECLS
+
+/// Dumper for writing atoms as Turtle for debugging
+typedef struct JalvDumperImpl JalvDumper;
+
+/// Allocate, configure, and return a new atom dumper
+JalvDumper*
+jalv_dumper_new(LV2_URID_Map* map, LV2_URID_Unmap* unmap);
+
+/// Free memory allocated by jalv_init_dumper()
+void
+jalv_dumper_free(JalvDumper* dumper);
+
+/// Dump an atom to stdout
+void
+jalv_dump_atom(JalvDumper* dumper,
+ FILE* stream,
+ const char* label,
+ const LV2_Atom* atom,
+ int color);
+
+JALV_END_DECLS
+
+#endif // JALV_DUMPER_H
diff --git a/src/jalv.c b/src/jalv.c
index 4f9d4f6..794d688 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -4,6 +4,7 @@
#include "backend.h"
#include "comm.h"
#include "control.h"
+#include "dumper.h"
#include "frontend.h"
#include "jalv_config.h"
#include "jalv_internal.h"
@@ -31,12 +32,9 @@
#include "lv2/options/options.h"
#include "lv2/patch/patch.h"
#include "lv2/state/state.h"
-#include "lv2/time/time.h"
#include "lv2/ui/ui.h"
#include "lv2/urid/urid.h"
#include "lv2/worker/worker.h"
-#include "serd/serd.h"
-#include "sratom/sratom.h"
#include "zix/allocator.h"
#include "zix/attributes.h"
#include "zix/filesystem.h"
@@ -379,7 +377,7 @@ jalv_send_to_plugin(void* const jalv_handle,
(sizeof(LV2_Atom) + atom->size != buffer_size)) {
st = ZIX_STATUS_BAD_ARG;
} else {
- jalv_dump_atom(jalv, stdout, "UI => Plugin", atom, 36);
+ jalv_dump_atom(jalv->dumper, stdout, "UI => Plugin", atom, 36);
st = jalv_write_event(
jalv->ui_to_plugin, port_index, atom->size, atom->type, atom + 1U);
}
@@ -546,30 +544,6 @@ jalv_init_ui(Jalv* jalv)
}
}
-void
-jalv_dump_atom(Jalv* const jalv,
- FILE* const stream,
- const char* const label,
- const LV2_Atom* const atom,
- const int color)
-{
- if (jalv->opts.dump) {
- char* const str = sratom_to_turtle(jalv->sratom,
- jalv_mapper_urid_unmap(jalv->mapper),
- "jalv:",
- NULL,
- NULL,
- atom->type,
- atom->size,
- LV2_ATOM_BODY_CONST(atom));
-
- jalv_ansi_start(stream, color);
- fprintf(stream, "\n# %s (%u bytes):\n%s\n", label, atom->size, str);
- jalv_ansi_reset(stream);
- free(str);
- }
-}
-
static int
ring_error(const char* const message)
{
@@ -610,7 +584,7 @@ jalv_update(Jalv* jalv)
}
} else if (header.type == EVENT_TRANSFER) {
const JalvEventTransfer* const msg = (const JalvEventTransfer*)body;
- jalv_dump_atom(jalv, stdout, "Plugin => UI", &msg->atom, 35);
+ jalv_dump_atom(jalv->dumper, stdout, "Plugin => UI", &msg->atom, 35);
jalv_frontend_port_event(jalv,
msg->port_index,
sizeof(LV2_Atom) + msg->atom.size,
@@ -740,21 +714,6 @@ jalv_select_custom_ui(const Jalv* const jalv)
return NULL;
}
-static SerdEnv*
-jalv_new_env(void)
-{
- SerdEnv* const env = serd_env_new(NULL);
- if (env) {
- serd_env_set_prefix_from_strings(
- env, (const uint8_t*)"patch", (const uint8_t*)LV2_PATCH_PREFIX);
- serd_env_set_prefix_from_strings(
- env, (const uint8_t*)"time", (const uint8_t*)LV2_TIME_PREFIX);
- serd_env_set_prefix_from_strings(
- env, (const uint8_t*)"xsd", (const uint8_t*)LILV_NS_XSD);
- }
- return env;
-}
-
static void
jalv_init_features(Jalv* const jalv)
{
@@ -920,7 +879,6 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->world = world;
jalv->mapper = jalv_mapper_new();
- jalv->env = jalv_new_env();
jalv->block_length = 4096U;
jalv->midi_buf_size = 1024U;
jalv->msg_buf_size = 1024U;
@@ -930,6 +888,13 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->log.urids = &jalv->urids;
jalv->log.tracing = jalv->opts.trace;
+ // Set up atom dumping for debugging if enabled
+ LV2_URID_Map* const urid_map = jalv_mapper_urid_map(jalv->mapper);
+ LV2_URID_Unmap* const urid_unmap = jalv_mapper_urid_unmap(jalv->mapper);
+ if (jalv->opts.dump) {
+ jalv->dumper = jalv_dumper_new(urid_map, urid_unmap);
+ }
+
zix_sem_init(&jalv->work_lock, 1);
zix_sem_init(&jalv->done, 0);
zix_sem_init(&jalv->paused, 0);
@@ -937,14 +902,8 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv_init_urids(jalv->mapper, &jalv->urids);
jalv_init_nodes(world, &jalv->nodes);
jalv_init_features(jalv);
-
- LV2_URID_Map* const urid_map = jalv_mapper_urid_map(jalv->mapper);
lv2_atom_forge_init(&jalv->forge, urid_map);
- // Set up atom reading and writing environment
- jalv->sratom = sratom_new(urid_map);
- sratom_set_env(jalv->sratom, jalv->env);
-
// Create temporary directory for plugin state
jalv->temp_dir = zix_create_temporary_directory(NULL, "jalvXXXXXX");
if (!jalv->temp_dir) {
@@ -1222,8 +1181,7 @@ jalv_close(Jalv* const jalv)
}
free(jalv->controls.controls);
- sratom_free(jalv->sratom);
- serd_env_free(jalv->env);
+ jalv_dumper_free(jalv->dumper);
lilv_uis_free(jalv->uis);
jalv_mapper_free(jalv->mapper);
lilv_world_free(jalv->world);
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 96e2c56..cad085b 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -6,6 +6,7 @@
#include "attributes.h"
#include "control.h"
+#include "dumper.h"
#include "jalv_config.h"
#include "log.h"
#include "mapper.h"
@@ -19,8 +20,6 @@
#include "zix/sem.h"
#include "lilv/lilv.h"
-#include "serd/serd.h"
-#include "sratom/sratom.h"
#if USE_SUIL
# include "suil/suil.h"
#endif
@@ -71,8 +70,7 @@ struct JalvImpl {
JalvNodes nodes; ///< Nodes
JalvLog log; ///< Log for error/warning/debug messages
LV2_Atom_Forge forge; ///< Atom forge
- SerdEnv* env; ///< Environment for RDF printing
- Sratom* sratom; ///< Atom serialiser
+ JalvDumper* dumper; ///< Atom dumper (console debug output)
JalvBackend* backend; ///< Audio system backend
ZixRing* ui_to_plugin; ///< Port events from UI
ZixRing* plugin_to_ui; ///< Port events from plugin
@@ -156,14 +154,6 @@ jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent);
bool
jalv_ui_is_resizable(Jalv* jalv);
-/// Dump an atom to stdout in a "developer-readable" format (Turtle)
-void
-jalv_dump_atom(Jalv* jalv,
- FILE* stream,
- const char* label,
- const LV2_Atom* atom,
- int color);
-
/// Periodically update user interface
int
jalv_update(Jalv* jalv);
diff --git a/src/mapper.c b/src/mapper.c
index 27367e0..7afccab 100644
--- a/src/mapper.c
+++ b/src/mapper.c
@@ -70,13 +70,13 @@ jalv_mapper_free(JalvMapper* const mapper)
LV2_URID_Map*
jalv_mapper_urid_map(JalvMapper* const mapper)
{
- return &mapper->map;
+ return mapper ? &mapper->map : NULL;
}
LV2_URID_Unmap*
jalv_mapper_urid_unmap(JalvMapper* const mapper)
{
- return &mapper->unmap;
+ return mapper ? &mapper->unmap : NULL;
}
LV2_URID
@@ -88,5 +88,5 @@ jalv_mapper_map_uri(JalvMapper* const mapper, const char* const sym)
const char*
jalv_mapper_unmap_uri(const JalvMapper* mapper, uint32_t id)
{
- return symap_unmap(mapper->symap, id);
+ return mapper ? symap_unmap(mapper->symap, id) : NULL;
}