aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-11-17 18:40:20 +0000
committerDavid Robillard <d@drobilla.net>2012-11-17 18:40:20 +0000
commit6fc9dea2ef99d545963e76de2c9d98a18ed025f9 (patch)
treeedce64297d4a3d52da7519bc01f9996eca197dfa
parent1c944d0d1644946329626c0e4dea38121ab7a0b3 (diff)
downloadlv2-6fc9dea2ef99d545963e76de2c9d98a18ed025f9.tar.xz
Fix position event iteration to reduce iterations and correctly handle updates in the middle of a cycle.
-rw-r--r--plugins/eg-metro.lv2/metro.c33
1 files 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 */