diff options
author | David Robillard <d@drobilla.net> | 2022-08-10 12:36:16 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-08-17 13:50:56 -0400 |
commit | e67d8439326d886315ccddd2d7a842df0c45359f (patch) | |
tree | d845a95dd4449c52f45754d5f44e9c65d8287515 /src | |
parent | 3651d42e50e4c2519718d5e33b22222c01848b87 (diff) | |
download | jalv-e67d8439326d886315ccddd2d7a842df0c45359f.tar.gz jalv-e67d8439326d886315ccddd2d7a842df0c45359f.tar.bz2 jalv-e67d8439326d886315ccddd2d7a842df0c45359f.zip |
Clean up atom dumping code
Diffstat (limited to 'src')
-rw-r--r-- | src/jack.c | 16 | ||||
-rw-r--r-- | src/jalv.c | 60 | ||||
-rw-r--r-- | src/jalv_internal.h | 7 |
3 files changed, 36 insertions, 47 deletions
@@ -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 @@ -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); |