From 6fc9dea2ef99d545963e76de2c9d98a18ed025f9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 17 Nov 2012 18:40:20 +0000 Subject: Fix position event iteration to reduce iterations and correctly handle updates in the middle of a cycle. --- plugins/eg-metro.lv2/metro.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/plugins/eg-metro.lv2/metro.c b/plugins/eg-metro.lv2/metro.c index 60b61f3..54b2a70 100644 --- a/plugins/eg-metro.lv2/metro.c +++ b/plugins/eg-metro.lv2/metro.c @@ -276,26 +276,25 @@ run(LV2_Handle instance, uint32_t sample_count) /* Work forwards in time frame by frame, handling events as we go */ const LV2_Atom_Sequence* in = self->ports.control; - LV2_Atom_Event* ev = lv2_atom_sequence_begin(&in->body); uint32_t last_t = 0; - for (uint32_t t = 0; t < sample_count; ++t) { - while (!lv2_atom_sequence_is_end(&in->body, in->atom.size, ev) && - ev->time.frames == t) { - /* Play the click for the time slice from last_t until now */ - play(self, last_t, t); - - if (ev->body.type == uris->atom_Blank) { - const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; - if (obj->body.otype == uris->time_Position) { - /* Received position information, update */ - update_position(self, obj); - } + for (LV2_Atom_Event* ev = lv2_atom_sequence_begin(&in->body); + !lv2_atom_sequence_is_end(&in->body, in->atom.size, ev); + ev = lv2_atom_sequence_next(ev)) { + + /* Play the click for the time slice from last_t until now */ + play(self, last_t, ev->time.frames); + + if (ev->body.type == uris->atom_Blank) { + const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; + if (obj->body.otype == uris->time_Position) { + /* Received position information, update */ + update_position(self, obj); } - - /* Update time for next iteration and move to next event*/ - last_t = t; - ev = lv2_atom_sequence_next(ev); } + + /* Update time for next iteration and move to next event*/ + last_t = ev->time.frames; + ev = lv2_atom_sequence_next(ev); } /* Play for remainder of cycle */ -- cgit v1.2.1