Time stamp

The timestamp of the event can either specified in real time or in song ticks. Which format is used is determined by the event flags.

The resolution of real-time value is in nano second. Since 64 bit length is required for the actual time calculation, it is represented by a structure of pair of second and nano second:

typedef struct {
	long int tv_sec;	/* seconds */
        long int tv_nsec;	/* nanoseconds */
} snd_seq_real_time_t;

The song tick is defined simply as a 32 bit integer.

typedef unsigned int snd_seq_tick_time_t;       /* midi ticks */

The time stored in an event record is a union of these two different time values.

typedef union {
	snd_seq_tick_time_t tick;
	snd_seq_real_time_t time;
} snd_seq_timestamp_t;

Note that the time format used for real time events is very similar to timeval struct used for unix system time. The 'absurd' resolution of the timestamps allows us to perform very accurate conversions between songposition and real time. Round-off errors can be neglected.

If a timestamp with a relative timestamp is delivered to to ALSA the specified timestamp will be used as an offset to the current time of the queue the event is send into. A absolute timestamp is on the contrary the time counted from the moment when the queue started. A relative timestamp is convered into an aboslute time when the event is enqueued.

An client that relies on these relative timestamps is the MIDI input port. As each sequencer queue has it's own clock the only way to deliver events at the right time is by using the relative timestamp format. When the event arrives at the queue it is normalised to absolute format.