Q:

How should I code the back end of a timeline

I want to create a program with a timeline much like the ones you'd see in a video editor. The events that are placed on that timeline will have a starting time and an ending time (or a length?). It will be possible to move the timeline's playhead freely, forward and backwards, and even control it's speed. What is important is that the playhead should trigger the events when it "enters" or "exits" the objects as it moves over them. I don't want to use timers since there could be quite a lot of those events and it would probably be inefficient.
What would be the best way to view this problem? I've already coded the graphical part (using QGraphicsView where the events are represented using custom QGraphicsItems), now I'm looking for the best way to implement the back end.
Did my question make sense? Is it too ambiguous?

A:

It seems like you want a data structure that efficiently supports the following operations:

Insert and delete time intervals.
Shift a time interval over.
Query for all time intervals overlapping with a certain time.

For this, you might want to look at the interval tree data structure, which efficiently supports operations (1) and (3).  You can implement operation (2) by deleting an existing segment and then reinserting it into the interval tree.
To implement the reading pointer, you can just continuously query the segment tree for all segments overlapping the current time.
Hope this helps!

