diff options
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | atom_inspector.c | 125 | ||||
-rw-r--r-- | atom_inspector_nk.c | 29 | ||||
-rw-r--r-- | midi_inspector.c | 134 | ||||
-rw-r--r-- | midi_inspector_nk.c | 20 | ||||
-rw-r--r-- | osc_inspector.c | 137 | ||||
-rw-r--r-- | osc_inspector_nk.c | 22 | ||||
-rw-r--r-- | sherlock.h | 20 | ||||
-rw-r--r-- | sherlock.ttl | 18 | ||||
-rw-r--r-- | sherlock_nk.c | 51 | ||||
-rw-r--r-- | sherlock_nk.h | 2 |
11 files changed, 310 insertions, 250 deletions
@@ -1 +1 @@ -0.15.27 +0.15.29 diff --git a/atom_inspector.c b/atom_inspector.c index 3c18ad5..12cfb4d 100644 --- a/atom_inspector.c +++ b/atom_inspector.c @@ -24,10 +24,9 @@ typedef struct _handle_t handle_t; struct _handle_t { LV2_URID_Map *map; - const LV2_Atom_Sequence *control_in; - LV2_Atom_Sequence *control_out; - LV2_Atom_Sequence *notify; - LV2_Atom_Forge forge; + const LV2_Atom_Sequence *control; + craft_t through; + craft_t notify; LV2_URID time_position; LV2_URID time_frame; @@ -62,10 +61,11 @@ instantiate(const LV2_Descriptor* descriptor, double rate, handle->time_position = handle->map->map(handle->map->handle, LV2_TIME__Position); handle->time_frame = handle->map->map(handle->map->handle, LV2_TIME__frame); - lv2_atom_forge_init(&handle->forge, handle->map); + lv2_atom_forge_init(&handle->through.forge, handle->map); + lv2_atom_forge_init(&handle->notify.forge, handle->map); if(!props_init(&handle->props, descriptor->URI, - defs, MAX_NPROPS, &handle->state, &handle->stash, + defs, MAX_NPROPS, &handle->state, &handle->stash, handle->map, handle)) { fprintf(stderr, "failed to allocate property structure\n"); @@ -84,13 +84,13 @@ connect_port(LV2_Handle instance, uint32_t port, void *data) switch(port) { case 0: - handle->control_in = (const LV2_Atom_Sequence *)data; + handle->control = (const LV2_Atom_Sequence *)data; break; case 1: - handle->control_out = (LV2_Atom_Sequence *)data; + handle->through.seq = (LV2_Atom_Sequence *)data; break; case 2: - handle->notify = (LV2_Atom_Sequence *)data; + handle->notify.seq = (LV2_Atom_Sequence *)data; break; default: break; @@ -101,35 +101,34 @@ static void run(LV2_Handle instance, uint32_t nsamples) { handle_t *handle = (handle_t *)instance; - uint32_t capacity; - LV2_Atom_Forge *forge = &handle->forge; - LV2_Atom_Forge_Frame frame; - LV2_Atom_Forge_Ref ref; + craft_t *through = &handle->through; + craft_t *notify = &handle->notify; - // size of input sequence - const size_t size = lv2_atom_total_size(&handle->control_in->atom); - - capacity = handle->control_out->atom.size; - lv2_atom_forge_set_buffer(forge, (uint8_t *)handle->control_out, capacity); - ref = lv2_atom_forge_sequence_head(forge, &frame, 0); + uint32_t capacity = through->seq->atom.size; + lv2_atom_forge_set_buffer(&through->forge, through->buf, capacity); + through->ref = lv2_atom_forge_sequence_head(&through->forge, &through->frame[0], 0); - props_idle(&handle->props, forge, 0, &ref); + capacity = notify->seq->atom.size; + lv2_atom_forge_set_buffer(¬ify->forge, notify->buf, capacity); + notify->ref = lv2_atom_forge_sequence_head(¬ify->forge, ¬ify->frame[0], 0); - LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev) + props_idle(&handle->props, ¬ify->forge, 0, ¬ify->ref); + + LV2_ATOM_SEQUENCE_FOREACH(handle->control, ev) { const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body; const int64_t frames = ev->time.frames; // copy all events to through port - if(ref) - ref = lv2_atom_forge_frame_time(forge, frames); - if(ref) - ref = lv2_atom_forge_raw(forge, &obj->atom, lv2_atom_total_size(&obj->atom)); - if(ref) - lv2_atom_forge_pad(forge, obj->atom.size); - - if( !props_advance(&handle->props, forge, frames, obj, &ref) - && lv2_atom_forge_is_object_type(forge, obj->atom.type) + if(through->ref) + through->ref = lv2_atom_forge_frame_time(&through->forge, frames); + if(through->ref) + through->ref = lv2_atom_forge_raw(&through->forge, &obj->atom, lv2_atom_total_size(&obj->atom)); + if(through->ref) + lv2_atom_forge_pad(&through->forge, obj->atom.size); + + if( !props_advance(&handle->props, ¬ify->forge, frames, obj, ¬ify->ref) + && lv2_atom_forge_is_object_type(¬ify->forge, obj->atom.type) && (obj->body.otype == handle->time_position) ) { const LV2_Atom_Long *time_frame = NULL; @@ -139,40 +138,48 @@ run(LV2_Handle instance, uint32_t nsamples) } } - if(ref) - lv2_atom_forge_pop(forge, &frame); + if(through->ref) + lv2_atom_forge_pop(&through->forge, &through->frame[0]); else - lv2_atom_sequence_clear(handle->control_out); - - // forge whole sequence as single event - capacity = handle->notify->atom.size; - lv2_atom_forge_set_buffer(forge, (uint8_t *)handle->notify, capacity); - ref = lv2_atom_forge_sequence_head(forge, &frame, 0); - - // only serialize sequence to UI if there were actually any events - if(handle->control_in->atom.size > sizeof(LV2_Atom_Sequence_Body)) + lv2_atom_sequence_clear(through->seq); + + bool has_event = notify->seq->atom.size > sizeof(LV2_Atom_Sequence_Body); + + if(notify->ref) + notify->ref = lv2_atom_forge_frame_time(¬ify->forge, nsamples-1); + if(notify->ref) + notify->ref = lv2_atom_forge_tuple(¬ify->forge, ¬ify->frame[1]); + if(notify->ref) + notify->ref = lv2_atom_forge_long(¬ify->forge, handle->frame); + if(notify->ref) + notify->ref = lv2_atom_forge_int(¬ify->forge, nsamples); + if(notify->ref) + notify->ref = lv2_atom_forge_sequence_head(¬ify->forge, ¬ify->frame[2], 0); + + // only serialize filtered events to UI + LV2_ATOM_SEQUENCE_FOREACH(handle->control, ev) { - LV2_Atom_Forge_Frame tup_frame; - - if(ref) - ref = lv2_atom_forge_frame_time(forge, 0); - if(ref) - ref = lv2_atom_forge_tuple(forge, &tup_frame); - if(ref) - ref = lv2_atom_forge_long(forge, handle->frame); - if(ref) - ref = lv2_atom_forge_int(forge, nsamples); - if(ref) - ref = lv2_atom_forge_write(forge, handle->control_in, size); - if(ref) - lv2_atom_forge_pop(forge, &tup_frame); - + if(true) //FIXME do filtering here + { + has_event = true; + if(notify->ref) + notify->ref = lv2_atom_forge_frame_time(¬ify->forge, ev->time.frames); + if(notify->ref) + notify->ref = lv2_atom_forge_write(¬ify->forge, &ev->body, sizeof(LV2_Atom) + ev->body.size); + } } - if(ref) - lv2_atom_forge_pop(forge, &frame); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[2]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[1]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[0]); else - lv2_atom_sequence_clear(handle->notify); + lv2_atom_sequence_clear(notify->seq); + + if(!has_event) // don't send anything + lv2_atom_sequence_clear(notify->seq); handle->frame += nsamples; } diff --git a/atom_inspector_nk.c b/atom_inspector_nk.c index ed639d3..00d937c 100644 --- a/atom_inspector_nk.c +++ b/atom_inspector_nk.c @@ -299,16 +299,35 @@ _atom_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat nk_layout_row_dynamic(ctx, widget_h, 4); { - if(nk_checkbox_label(ctx, "overwrite", &handle->state.overwrite)) + const int32_t state_overwrite = nk_check_label(ctx, "overwrite", handle->state.overwrite); + if(state_overwrite != handle->state.overwrite) + { + handle->state.overwrite = state_overwrite; _toggle(handle, handle->urid.overwrite, handle->state.overwrite, true); - if(nk_checkbox_label(ctx, "block", &handle->state.block)) + } + + const int32_t state_block = nk_check_label(ctx, "block", handle->state.block); + if(state_block != handle->state.block) + { + handle->state.block = state_block; _toggle(handle, handle->urid.block, handle->state.block, true); - if(nk_checkbox_label(ctx, "follow", &handle->state.follow)) + } + + const int32_t state_follow = nk_check_label(ctx, "follow", handle->state.follow); + if(state_follow != handle->state.follow) + { + handle->state.follow = state_follow; _toggle(handle, handle->urid.follow, handle->state.follow, true); - if(nk_checkbox_label(ctx, "pretty", &handle->pretty_numbers)) + } + + const int32_t state_pretty = nk_check_label(ctx, "pretty", handle->state.pretty); + if(state_pretty != handle->state.pretty) { + handle->state.pretty = state_pretty; + _toggle(handle, handle->urid.pretty, handle->state.pretty, true); + handle->ttl_dirty = true; - sratom_set_pretty_numbers(handle->sratom, handle->pretty_numbers); + sratom_set_pretty_numbers(handle->sratom, handle->state.pretty); } } diff --git a/midi_inspector.c b/midi_inspector.c index 95cd500..bab7c0c 100644 --- a/midi_inspector.c +++ b/midi_inspector.c @@ -26,10 +26,9 @@ typedef struct _handle_t handle_t; struct _handle_t { LV2_URID_Map *map; - const LV2_Atom_Sequence *control_in; - LV2_Atom_Sequence *control_out; - LV2_Atom_Sequence *notify; - LV2_Atom_Forge forge; + const LV2_Atom_Sequence *control; + craft_t through; + craft_t notify; LV2_URID time_position; LV2_URID time_frame; @@ -64,13 +63,13 @@ instantiate(const LV2_Descriptor* descriptor, double rate, handle->time_position = handle->map->map(handle->map->handle, LV2_TIME__Position); handle->time_frame = handle->map->map(handle->map->handle, LV2_TIME__frame); - handle->midi_event = handle->map->map(handle->map->handle, LV2_MIDI__MidiEvent); - lv2_atom_forge_init(&handle->forge, handle->map); + lv2_atom_forge_init(&handle->through.forge, handle->map); + lv2_atom_forge_init(&handle->notify.forge, handle->map); if(!props_init(&handle->props, descriptor->URI, - defs, MAX_NPROPS, &handle->state, &handle->stash, + defs, MAX_NPROPS, &handle->state, &handle->stash, handle->map, handle)) { fprintf(stderr, "failed to allocate property structure\n"); @@ -89,13 +88,13 @@ connect_port(LV2_Handle instance, uint32_t port, void *data) switch(port) { case 0: - handle->control_in = (const LV2_Atom_Sequence *)data; + handle->control = (const LV2_Atom_Sequence *)data; break; case 1: - handle->control_out = (LV2_Atom_Sequence *)data; + handle->through.seq = (LV2_Atom_Sequence *)data; break; case 2: - handle->notify = (LV2_Atom_Sequence *)data; + handle->notify.seq = (LV2_Atom_Sequence *)data; break; default: break; @@ -106,36 +105,34 @@ static void run(LV2_Handle instance, uint32_t nsamples) { handle_t *handle = (handle_t *)instance; - uint32_t capacity; - LV2_Atom_Forge *forge = &handle->forge; - LV2_Atom_Forge_Frame frame [3]; - LV2_Atom_Forge_Ref ref; - - // size of input sequence - const size_t size = lv2_atom_total_size(&handle->control_in->atom); - - // copy whole input sequence to through port - capacity = handle->control_out->atom.size; - lv2_atom_forge_set_buffer(forge, (uint8_t *)handle->control_out, capacity); - ref = lv2_atom_forge_sequence_head(forge, frame, 0); - - props_idle(&handle->props, forge, 0, &ref); - - LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev) + craft_t *through = &handle->through; + craft_t *notify = &handle->notify; + + uint32_t capacity = through->seq->atom.size; + lv2_atom_forge_set_buffer(&through->forge, through->buf, capacity); + through->ref = lv2_atom_forge_sequence_head(&through->forge, &through->frame[0], 0); + + capacity = notify->seq->atom.size; + lv2_atom_forge_set_buffer(¬ify->forge, notify->buf, capacity); + notify->ref = lv2_atom_forge_sequence_head(¬ify->forge, ¬ify->frame[0], 0); + + props_idle(&handle->props, ¬ify->forge, 0, ¬ify->ref); + + LV2_ATOM_SEQUENCE_FOREACH(handle->control, ev) { const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body; const int64_t frames = ev->time.frames; // copy all events to through port - if(ref) - ref = lv2_atom_forge_frame_time(forge, frames); - if(ref) - ref = lv2_atom_forge_raw(forge, &obj->atom, lv2_atom_total_size(&obj->atom)); - if(ref) - lv2_atom_forge_pad(forge, obj->atom.size); - - if( !props_advance(&handle->props, forge, frames, obj, &ref) - && lv2_atom_forge_is_object_type(forge, obj->atom.type) + if(through->ref) + through->ref = lv2_atom_forge_frame_time(&through->forge, frames); + if(through->ref) + through->ref = lv2_atom_forge_raw(&through->forge, &obj->atom, lv2_atom_total_size(&obj->atom)); + if(through->ref) + lv2_atom_forge_pad(&through->forge, obj->atom.size); + + if( !props_advance(&handle->props, ¬ify->forge, frames, obj, ¬ify->ref) + && lv2_atom_forge_is_object_type(¬ify->forge, obj->atom.type) && (obj->body.otype == handle->time_position) ) { const LV2_Atom_Long *time_frame = NULL; @@ -145,53 +142,48 @@ run(LV2_Handle instance, uint32_t nsamples) } } - if(ref) - lv2_atom_forge_pop(forge, frame); + if(through->ref) + lv2_atom_forge_pop(&through->forge, &through->frame[0]); else - lv2_atom_sequence_clear(handle->control_out); - - // forge whole sequence as single event - capacity = handle->notify->atom.size; - lv2_atom_forge_set_buffer(forge, (uint8_t *)handle->notify, capacity); - - bool has_midi = false; - - ref = lv2_atom_forge_sequence_head(forge, &frame[0], 0); - if(ref) - ref = lv2_atom_forge_frame_time(forge, 0); - if(ref) - ref = lv2_atom_forge_tuple(forge, &frame[1]); - if(ref) - ref = lv2_atom_forge_long(forge, handle->frame); - if(ref) - ref = lv2_atom_forge_int(forge, nsamples); - if(ref) - ref = lv2_atom_forge_sequence_head(forge, &frame[2], 0); + lv2_atom_sequence_clear(through->seq); + + bool has_event = notify->seq->atom.size > sizeof(LV2_Atom_Sequence_Body); + + if(notify->ref) + notify->ref = lv2_atom_forge_frame_time(¬ify->forge, nsamples-1); + if(notify->ref) + notify->ref = lv2_atom_forge_tuple(¬ify->forge, ¬ify->frame[1]); + if(notify->ref) + notify->ref = lv2_atom_forge_long(¬ify->forge, handle->frame); + if(notify->ref) + notify->ref = lv2_atom_forge_int(¬ify->forge, nsamples); + if(notify->ref) + notify->ref = lv2_atom_forge_sequence_head(¬ify->forge, ¬ify->frame[2], 0); // only serialize MIDI events to UI - LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev) + LV2_ATOM_SEQUENCE_FOREACH(handle->control, ev) { if(ev->body.type == handle->midi_event) { - has_midi = true; - if(ref) - ref = lv2_atom_forge_frame_time(forge, ev->time.frames); - if(ref) - ref = lv2_atom_forge_write(forge, &ev->body, sizeof(LV2_Atom) + ev->body.size); + has_event = true; + if(notify->ref) + notify->ref = lv2_atom_forge_frame_time(¬ify->forge, ev->time.frames); + if(notify->ref) + notify->ref = lv2_atom_forge_write(¬ify->forge, &ev->body, sizeof(LV2_Atom) + ev->body.size); } } - if(ref) - lv2_atom_forge_pop(forge, &frame[2]); - if(ref) - lv2_atom_forge_pop(forge, &frame[1]); - if(ref) - lv2_atom_forge_pop(forge, &frame[0]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[2]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[1]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[0]); else - lv2_atom_sequence_clear(handle->notify); + lv2_atom_sequence_clear(notify->seq); - if(!has_midi) // don't send anything - lv2_atom_sequence_clear(handle->notify); + if(!has_event) // don't send anything + lv2_atom_sequence_clear(notify->seq); handle->frame += nsamples; } diff --git a/midi_inspector_nk.c b/midi_inspector_nk.c index b1f811b..11258ef 100644 --- a/midi_inspector_nk.c +++ b/midi_inspector_nk.c @@ -485,12 +485,26 @@ _midi_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat nk_layout_row_dynamic(ctx, widget_h, 3); { - if(nk_checkbox_label(ctx, "overwrite", &handle->state.overwrite)) + const int32_t state_overwrite = nk_check_label(ctx, "overwrite", handle->state.overwrite); + if(state_overwrite != handle->state.overwrite) + { + handle->state.overwrite = state_overwrite; _toggle(handle, handle->urid.overwrite, handle->state.overwrite, true); - if(nk_checkbox_label(ctx, "block", &handle->state.block)) + } + + const int32_t state_block = nk_check_label(ctx, "block", handle->state.block); + if(state_block != handle->state.block) + { + handle->state.block = state_block; _toggle(handle, handle->urid.block, handle->state.block, true); - if(nk_checkbox_label(ctx, "follow", &handle->state.follow)) + } + + const int32_t state_follow = nk_check_label(ctx, "follow", handle->state.follow); + if(state_follow != handle->state.follow) + { + handle->state.follow = state_follow; _toggle(handle, handle->urid.follow, handle->state.follow, true); + } } const bool max_reached = handle->n_item >= MAX_LINES; diff --git a/osc_inspector.c b/osc_inspector.c index 69e09fd..3225de8 100644 --- a/osc_inspector.c +++ b/osc_inspector.c @@ -26,10 +26,9 @@ typedef struct _handle_t handle_t; struct _handle_t { LV2_URID_Map *map; - const LV2_Atom_Sequence *control_in; - LV2_Atom_Sequence *control_out; - LV2_Atom_Sequence *notify; - LV2_Atom_Forge forge; + const LV2_Atom_Sequence *control; + craft_t through; + craft_t notify; LV2_URID time_position; LV2_URID time_frame; @@ -65,12 +64,13 @@ instantiate(const LV2_Descriptor* descriptor, double rate, handle->time_position = handle->map->map(handle->map->handle, LV2_TIME__Position); handle->time_frame = handle->map->map(handle->map->handle, LV2_TIME__frame); - lv2_osc_urid_init(&handle->osc_urid, handle->map); - lv2_atom_forge_init(&handle->forge, handle->map); + + lv2_atom_forge_init(&handle->through.forge, handle->map); + lv2_atom_forge_init(&handle->notify.forge, handle->map); if(!props_init(&handle->props, descriptor->URI, - defs, MAX_NPROPS, &handle->state, &handle->stash, + defs, MAX_NPROPS, &handle->state, &handle->stash, handle->map, handle)) { fprintf(stderr, "failed to allocate property structure\n"); @@ -89,13 +89,13 @@ connect_port(LV2_Handle instance, uint32_t port, void *data) switch(port) { case 0: - handle->control_in = (const LV2_Atom_Sequence *)data; + handle->control = (const LV2_Atom_Sequence *)data; break; case 1: - handle->control_out = (LV2_Atom_Sequence *)data; + handle->through.seq = (LV2_Atom_Sequence *)data; break; case 2: - handle->notify = (LV2_Atom_Sequence *)data; + handle->notify.seq = (LV2_Atom_Sequence *)data; break; default: break; @@ -106,36 +106,34 @@ static void run(LV2_Handle instance, uint32_t nsamples) { handle_t *handle = (handle_t *)instance; - uint32_t capacity; - LV2_Atom_Forge *forge = &handle->forge; - LV2_Atom_Forge_Frame frame [3]; - LV2_Atom_Forge_Ref ref; - - // size of input sequence - const size_t size = lv2_atom_total_size(&handle->control_in->atom); - - // copy whole input sequence to through port - capacity = handle->control_out->atom.size; - lv2_atom_forge_set_buffer(forge, (uint8_t *)handle->control_out, capacity); - ref = lv2_atom_forge_sequence_head(forge, frame, 0); - - props_idle(&handle->props, forge, 0, &ref); - - LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev) + craft_t *through = &handle->through; + craft_t *notify = &handle->notify; + + uint32_t capacity = through->seq->atom.size; + lv2_atom_forge_set_buffer(&through->forge, through->buf, capacity); + through->ref = lv2_atom_forge_sequence_head(&through->forge, &through->frame[0], 0); + + capacity = notify->seq->atom.size; + lv2_atom_forge_set_buffer(¬ify->forge, notify->buf, capacity); + notify->ref = lv2_atom_forge_sequence_head(¬ify->forge, ¬ify->frame[0], 0); + + props_idle(&handle->props, ¬ify->forge, 0, ¬ify->ref); + + LV2_ATOM_SEQUENCE_FOREACH(handle->control, ev) { const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body; const int64_t frames = ev->time.frames; // copy all events to through port - if(ref) - ref = lv2_atom_forge_frame_time(forge, frames); - if(ref) - ref = lv2_atom_forge_raw(forge, &obj->atom, lv2_atom_total_size(&obj->atom)); - if(ref) - lv2_atom_forge_pad(forge, obj->atom.size); - - if( !props_advance(&handle->props, forge, frames, obj, &ref) - && lv2_atom_forge_is_object_type(forge, obj->atom.type) + if(through->ref) + through->ref = lv2_atom_forge_frame_time(&through->forge, frames); + if(through->ref) + through->ref = lv2_atom_forge_raw(&through->forge, &obj->atom, lv2_atom_total_size(&obj->atom)); + if(through->ref) + lv2_atom_forge_pad(&through->forge, obj->atom.size); + + if( !props_advance(&handle->props, ¬ify->forge, frames, obj, ¬ify->ref) + && lv2_atom_forge_is_object_type(¬ify->forge, obj->atom.type) && (obj->body.otype == handle->time_position) ) { const LV2_Atom_Long *time_frame = NULL; @@ -145,55 +143,50 @@ run(LV2_Handle instance, uint32_t nsamples) } } - if(ref) - lv2_atom_forge_pop(forge, frame); + if(through->ref) + lv2_atom_forge_pop(&through->forge, &through->frame[0]); else - lv2_atom_sequence_clear(handle->control_out); - - // forge whole sequence as single event - capacity = handle->notify->atom.size; - lv2_atom_forge_set_buffer(forge, (uint8_t *)handle->notify, capacity); - - bool has_osc = false; - - ref = lv2_atom_forge_sequence_head(forge, &frame[0], 0); - if(ref) - ref = lv2_atom_forge_frame_time(forge, 0); - if(ref) - ref = lv2_atom_forge_tuple(forge, &frame[1]); - if(ref) - ref = lv2_atom_forge_long(forge, handle->frame); - if(ref) - ref = lv2_atom_forge_int(forge, nsamples); - if(ref) - ref = lv2_atom_forge_sequence_head(forge, &frame[2], 0); + lv2_atom_sequence_clear(through->seq); + + bool has_event = notify->seq->atom.size > sizeof(LV2_Atom_Sequence_Body); + + if(notify->ref) + notify->ref = lv2_atom_forge_frame_time(¬ify->forge, nsamples-1); + if(notify->ref) + notify->ref = lv2_atom_forge_tuple(¬ify->forge, ¬ify->frame[1]); + if(notify->ref) + notify->ref = lv2_atom_forge_long(¬ify->forge, handle->frame); + if(notify->ref) + notify->ref = lv2_atom_forge_int(¬ify->forge, nsamples); + if(notify->ref) + notify->ref = lv2_atom_forge_sequence_head(¬ify->forge, ¬ify->frame[2], 0); // only serialize OSC events to UI - LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev) + LV2_ATOM_SEQUENCE_FOREACH(handle->control, ev) { const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body; if(lv2_osc_is_message_or_bundle_type(&handle->osc_urid, obj->body.otype)) { - has_osc = true; - if(ref) - ref = lv2_atom_forge_frame_time(forge, ev->time.frames); - if(ref) - ref = lv2_atom_forge_write(forge, &ev->body, sizeof(LV2_Atom) + ev->body.size); + has_event = true; + if(notify->ref) + notify->ref = lv2_atom_forge_frame_time(¬ify->forge, ev->time.frames); + if(notify->ref) + notify->ref = lv2_atom_forge_write(¬ify->forge, &ev->body, sizeof(LV2_Atom) + ev->body.size); } } - if(ref) - lv2_atom_forge_pop(forge, &frame[2]); - if(ref) - lv2_atom_forge_pop(forge, &frame[1]); - if(ref) - lv2_atom_forge_pop(forge, &frame[0]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[2]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[1]); + if(notify->ref) + lv2_atom_forge_pop(¬ify->forge, ¬ify->frame[0]); else - lv2_atom_sequence_clear(handle->notify); + lv2_atom_sequence_clear(notify->seq); - if(!has_osc) - lv2_atom_sequence_clear(handle->notify); + if(!has_event) // don't send anything + lv2_atom_sequence_clear(notify->seq); handle->frame += nsamples; } @@ -248,5 +241,5 @@ const LV2_Descriptor osc_inspector = { .run = run, .deactivate = NULL, .cleanup = cleanup, - .extension_data = extension_data + .extension_data = extension_data }; diff --git a/osc_inspector_nk.c b/osc_inspector_nk.c index 5373e44..d6f1640 100644 --- a/osc_inspector_nk.c +++ b/osc_inspector_nk.c @@ -91,7 +91,7 @@ _osc_timetag(mem_t *mem, LV2_OSC_Timetag *tt) const uint32_t us = floor(tt->fraction * 0x1p-32 * 1e6); const time_t ttime = tt->integral - 0x83aa7e80; const struct tm *ltime = localtime(&ttime); - + char tmp [32]; if(strftime(tmp, 32, "%d-%b-%Y %T", ltime)) _mem_printf(mem, "t:%s.%06"PRIu32, tmp, us); @@ -377,12 +377,26 @@ _osc_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *data nk_layout_row_dynamic(ctx, widget_h, 3); { - if(nk_checkbox_label(ctx, "overwrite", &handle->state.overwrite)) + const int32_t state_overwrite = nk_check_label(ctx, "overwrite", handle->state.overwrite); + if(state_overwrite != handle->state.overwrite) + { + handle->state.overwrite = state_overwrite; _toggle(handle, handle->urid.overwrite, handle->state.overwrite, true); - if(nk_checkbox_label(ctx, "block", &handle->state.block)) + } + + const int32_t state_block = nk_check_label(ctx, "block", handle->state.block); + if(state_block != handle->state.block) + { + handle->state.block = state_block; _toggle(handle, handle->urid.block, handle->state.block, true); - if(nk_checkbox_label(ctx, "follow", &handle->state.follow)) + } + + const int32_t state_follow = nk_check_label(ctx, "follow", handle->state.follow); + if(state_follow != handle->state.follow) + { + handle->state.follow = state_follow; _toggle(handle, handle->urid.follow, handle->state.follow, true); + } } const bool max_reached = handle->n_item >= MAX_LINES; @@ -51,6 +51,7 @@ extern const LV2_Descriptor osc_inspector; typedef struct _position_t position_t; typedef struct _state_t state_t; +typedef struct _craft_t craft_t; struct _position_t { uint64_t offset; @@ -61,9 +62,20 @@ struct _state_t { int32_t overwrite; int32_t block; int32_t follow; + int32_t pretty; }; -#define MAX_NPROPS 3 +struct _craft_t { + LV2_Atom_Forge forge; + LV2_Atom_Forge_Frame frame [3]; + LV2_Atom_Forge_Ref ref; + union { + LV2_Atom_Sequence *seq; + uint8_t *buf; + }; +}; + +#define MAX_NPROPS 4 static const props_def_t defs [MAX_NPROPS] = { { @@ -80,8 +92,14 @@ static const props_def_t defs [MAX_NPROPS] = { .property = SHERLOCK_URI"#follow", .offset = offsetof(state_t, follow), .type = LV2_ATOM__Bool, + }, + { + .property = SHERLOCK_URI"#pretty", + .offset = offsetof(state_t, pretty), + .type = LV2_ATOM__Bool, } }; + // there is a bug in LV2 <= 0.10 #if defined(LV2_ATOM_TUPLE_FOREACH) # undef LV2_ATOM_TUPLE_FOREACH diff --git a/sherlock.ttl b/sherlock.ttl index b14169a..24ea9f0 100644 --- a/sherlock.ttl +++ b/sherlock.ttl @@ -73,6 +73,12 @@ sherlock:follow rdfs:comment "Automatically scroll to and show last added event" ; rdfs:range atom:Bool . +sherlock:pretty + a lv2:Parameter ; + rdfs:label "Pretty" ; + rdfs:comment "Enable pretty printing" ; + rdfs:range atom:Bool . + # Atom Inspector Plugin sherlock:atom_inspector a lv2:Plugin, @@ -127,12 +133,14 @@ sherlock:atom_inspector patch:writable sherlock:overwrite, sherlock:block , - sherlock:follow ; + sherlock:follow , + sherlock:pretty ; state:state [ sherlock:overwrite false ; sherlock:block false ; sherlock:follow false ; + sherlock:pretty false ; ] . # MIDI Inspector Plugin @@ -183,12 +191,14 @@ sherlock:midi_inspector patch:writable sherlock:overwrite , sherlock:block , - sherlock:follow ; + sherlock:follow , + sherlock:pretty ; state:state [ sherlock:overwrite false ; sherlock:block false ; sherlock:follow false ; + sherlock:pretty false ; ] . # OSC Inspector Plugin @@ -239,10 +249,12 @@ sherlock:osc_inspector patch:writable sherlock:overwrite , sherlock:block , - sherlock:follow ; + sherlock:follow , + sherlock:pretty ; state:state [ sherlock:overwrite false ; sherlock:block false ; sherlock:follow false ; + sherlock:pretty false ; ] . diff --git a/sherlock_nk.c b/sherlock_nk.c index b0d5cde..bbd6993 100644 --- a/sherlock_nk.c +++ b/sherlock_nk.c @@ -29,13 +29,6 @@ #define NK_PUGL_IMPLEMENTATION #include <sherlock_nk.h> -const char *max_items [5] = { - "1k", "2k", "4k", "8k", "16k" -}; -const int32_t max_values [5] = { - 0x400, 0x800, 0x1000, 0x2000, 0x4000 -}; - static LV2_Atom_Forge_Ref _sink(LV2_Atom_Forge_Sink_Handle handle, const void *buf, uint32_t size) { @@ -169,7 +162,7 @@ _ruler(struct nk_context *ctx, float line_thickness, struct nk_color color) void _empty(struct nk_context *ctx) { - nk_text(ctx, NULL, 0, NK_TEXT_RIGHT); + nk_spacing(ctx, 1); } static void @@ -271,8 +264,8 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri, handle->write_function = write_function; handle->controller = controller; - if(!props_init(&handle->props, descriptor->URI, - defs, MAX_NPROPS, &handle->state, &handle->stash, + if(!props_init(&handle->props, plugin_uri, + defs, MAX_NPROPS, &handle->state, &handle->stash, handle->map, handle)) { fprintf(stderr, "failed to allocate property structure\n"); @@ -283,6 +276,7 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri, handle->urid.overwrite = props_map(&handle->props, defs[0].property);; handle->urid.block = props_map(&handle->props, defs[1].property);; handle->urid.follow = props_map(&handle->props, defs[2].property);; + handle->urid.pretty = props_map(&handle->props, defs[3].property);; nk_pugl_config_t *cfg = &handle->win.cfg; cfg->height = 700; @@ -327,7 +321,7 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri, handle->editor.lexer.data = NULL; handle->sratom = sratom_new(handle->map); - sratom_set_pretty_numbers(handle->sratom, handle->pretty_numbers); + sratom_set_pretty_numbers(handle->sratom, handle->state.pretty); handle->base_uri = "file:///tmp/base"; return handle; @@ -396,31 +390,28 @@ port_event(LV2UI_Handle instance, uint32_t i, uint32_t size, uint32_t urid, switch(i) { case 0: - case 1: + case 2: { - atom_ser_t ser; + const LV2_Atom_Tuple *tup = buf; - if(_ser_malloc(&ser, 512)) + if(tup->atom.type != handle->forge.Tuple) { - LV2_Atom_Forge_Frame frame; - lv2_atom_forge_set_sink(&handle->forge, _sink, _deref, &ser); - LV2_Atom_Forge_Ref ref = lv2_atom_forge_sequence_head(&handle->forge, &frame, 0); + atom_ser_t ser; - if(props_advance(&handle->props, &handle->forge, 0, buf, &ref)) - nk_pugl_post_redisplay(&handle->win); + if(_ser_malloc(&ser, 512)) + { + LV2_Atom_Forge_Frame frame; + lv2_atom_forge_set_sink(&handle->forge, _sink, _deref, &ser); + LV2_Atom_Forge_Ref ref = lv2_atom_forge_sequence_head(&handle->forge, &frame, 0); - lv2_atom_forge_pop(&handle->forge, &frame); + if(props_advance(&handle->props, &handle->forge, 0, buf, &ref)) + nk_pugl_post_redisplay(&handle->win); - _ser_free(&ser); - } + lv2_atom_forge_pop(&handle->forge, &frame); + + _ser_free(&ser); + } - break; - } - case 2: - { - const LV2_Atom_Tuple *tup = buf; - if(tup->atom.type != handle->forge.Tuple) - { break; } @@ -455,7 +446,7 @@ port_event(LV2UI_Handle instance, uint32_t i, uint32_t size, uint32_t urid, const bool overflow = handle->n_item > MAX_LINES; - if(!offset || !nsamples || !seq) + if(!offset || !nsamples || !seq || (seq->atom.size <= sizeof(LV2_Atom_Sequence_Body)) ) { break; } diff --git a/sherlock_nk.h b/sherlock_nk.h index 10c9d7f..4ac43cc 100644 --- a/sherlock_nk.h +++ b/sherlock_nk.h @@ -85,6 +85,7 @@ struct _plughandle_t { LV2_URID overwrite; LV2_URID block; LV2_URID follow; + LV2_URID pretty; } urid; state_t state; state_t stash; @@ -97,7 +98,6 @@ struct _plughandle_t { Sratom *sratom; const char *base_uri; - int pretty_numbers; float dy; |