diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-08-04 15:13:55 +0200 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-08-04 15:13:55 +0200 |
commit | 6b6a7d06ba18d8d2777797f2274b35bc576ef2a0 (patch) | |
tree | 085a354ed62c330970d337b3a8f85a8579d5b8a1 /osc_inspector.c | |
parent | 88fdedc539bacb232652871d9beffa272fb94592 (diff) | |
download | sherlock.lv2-6b6a7d06ba18d8d2777797f2274b35bc576ef2a0.tar.xz |
various fixes.
* patch messages sent on wrong port, etc.
Diffstat (limited to 'osc_inspector.c')
-rw-r--r-- | osc_inspector.c | 137 |
1 files changed, 65 insertions, 72 deletions
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 }; |