From e67d8439326d886315ccddd2d7a842df0c45359f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 10 Aug 2022 12:36:16 -0400 Subject: Clean up atom dumping code --- src/jack.c | 16 +------------- src/jalv.c | 60 +++++++++++++++++++++++++---------------------------- src/jalv_internal.h | 7 +++++++ 3 files changed, 36 insertions(+), 47 deletions(-) diff --git a/src/jack.c b/src/jack.c index eff07d5..da99703 100644 --- a/src/jack.c +++ b/src/jack.c @@ -18,7 +18,6 @@ #include "lilv/lilv.h" #include "lv2/atom/atom.h" #include "lv2/atom/forge.h" -#include "sratom/sratom.h" #include "zix/ring.h" #include "zix/sem.h" @@ -125,20 +124,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) lv2_atom_forge_float(forge, pos.beats_per_minute); } - if (jalv->opts.dump) { - char* str = sratom_to_turtle(jalv->sratom, - &jalv->unmap, - "time:", - NULL, - NULL, - lv2_pos->type, - lv2_pos->size, - LV2_ATOM_BODY(lv2_pos)); - jalv_ansi_start(stdout, 36); - printf("\n## Position ##\n%s\n", str); - jalv_ansi_reset(stdout); - free(str); - } + jalv_dump_atom(jalv, stdout, "Position", lv2_pos, 32); } // Update transport state to expected values for next cycle diff --git a/src/jalv.c b/src/jalv.c index 8a3920f..98b4b86 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -504,21 +504,8 @@ jalv_ui_write(void* const jalv_handle, return; } - if (jalv->opts.dump && protocol == jalv->urids.atom_eventTransfer) { - const LV2_Atom* atom = (const LV2_Atom*)buffer; - - char* str = sratom_to_turtle(jalv->sratom, - &jalv->unmap, - "jalv:", - NULL, - NULL, - atom->type, - atom->size, - LV2_ATOM_BODY_CONST(atom)); - jalv_ansi_start(stdout, 36); - printf("\n## UI => Plugin (%u bytes) ##\n%s\n", atom->size, str); - jalv_ansi_reset(stdout); - free(str); + if (protocol == jalv->urids.atom_eventTransfer) { + jalv_dump_atom(jalv, stdout, "UI => Plugin", (const LV2_Atom*)buffer, 36); } char buf[MSG_BUFFER_SIZE]; @@ -634,6 +621,30 @@ jalv_send_to_ui(Jalv* jalv, return false; } +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->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); + } +} + bool jalv_run(Jalv* jalv, uint32_t nframes) { @@ -688,23 +699,8 @@ jalv_update(Jalv* jalv) // Read event body zix_ring_read(jalv->plugin_to_ui, buf, ev.size); - if (jalv->opts.dump && ev.protocol == jalv->urids.atom_eventTransfer) { - // Dump event in Turtle to the console - LV2_Atom* atom = (LV2_Atom*)buf; - - char* str = sratom_to_turtle(jalv->ui_sratom, - &jalv->unmap, - "jalv:", - NULL, - NULL, - atom->type, - atom->size, - LV2_ATOM_BODY(atom)); - - jalv_ansi_start(stdout, 35); - printf("\n## Plugin => UI (%u bytes) ##\n%s\n", atom->size, str); - jalv_ansi_reset(stdout); - free(str); + if (ev.protocol == jalv->urids.atom_eventTransfer) { + jalv_dump_atom(jalv, stdout, "Plugin => UI", (const LV2_Atom*)buf, 35); } jalv_ui_port_event(jalv, ev.index, ev.size, ev.protocol, buf); diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 13fe704..03b46f3 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -185,6 +185,13 @@ jalv_send_to_ui(Jalv* jalv, uint32_t size, const void* body); +void +jalv_dump_atom(Jalv* jalv, + FILE* stream, + const char* label, + const LV2_Atom* atom, + int color); + bool jalv_run(Jalv* jalv, uint32_t nframes); -- cgit v1.2.1