#ifndef _TEMPOTRACKER_H
#define _TEMPOTRACKER_H

#include "midifile.h"

typedef struct _ttempo_t ttempo_t;

typedef struct {
  int len,size;
  int ppq;
  ttempo_t *tmap;
} tempotracker_t;

void init_tempotracker(tempotracker_t *tt);
void free_tempotracker_data(tempotracker_t *tt);

void tempotracker_load(tempotracker_t *tt,MIDIFILE *mf); // clears old

int tempotracker_get_tempo(tempotracker_t *tt,int abstickpos); // in usec_per_quarter  or -1

float tempotracker_get_time(tempotracker_t *tt,int abstickpos); // in secs  or -1

int tempotracker_get_tick(tempotracker_t *tt,float abstime); // in seconds, returns abstickpos  or -1

int tempotracker_next_tempochange(tempotracker_t *tt,int abstickpos); // in absticks  or _ticklength()

// length of loaded midifile, in ticks or seconds
int tempotracker_get_ticklength(tempotracker_t *tt); // or -1
float tempotracker_get_timelength(tempotracker_t *tt); // or -1

#endif
