#ifndef _MIDIPLAYER_H
#define _MIDIPLAYER_H

#include <stdbool.h>

typedef struct _MIDIPLAYER midiplayer_t;
struct MIDIFILE;
struct midi_event_t;

typedef void (*MIDIPLAYER_OUTFN)(void *user,struct midi_event_t *ev);

midiplayer_t *midiplayer_load(const char *midifile); // still needs rewind!
midiplayer_t *midiplayer_from_midi(struct MIDIFILE *mf); // takes over mf
void free_midiplayer(midiplayer_t *player);

void midiplayer_rewind(midiplayer_t *player); // or: seek(-1) to reinit midi

// all events UP TO (but NOT including) abstickpos are executed
void midiplayer_runto(midiplayer_t *player,int abstickpos,MIDIPLAYER_OUTFN outfn,void *user);

// will reinit midi and rewind() if abstime<0
int midiplayer_seek(midiplayer_t *player,float abstime,MIDIPLAYER_OUTFN outfn,void *user); // in seconds, returns new abstickpos

// midi file properties:
int midiplayer_getppq(midiplayer_t *player);  // TODO: not really needed anymore ...
struct MIDIFILE *midiplayer_getmf(midiplayer_t *player);
float midiplayer_getlength(midiplayer_t *player); // in seconds

// current play state properties:
bool midiplayer_isdone(midiplayer_t *player);
float midiplayer_gettime(midiplayer_t *player); // in seconds
int midiplayer_gettempo(midiplayer_t *player); // in usec_per_quarter
// TODO?
//int midiplayer_gettick(midiplayer_t *player); // absolute tick pos
int midiplayer_next_tempochange(midiplayer_t *player); // in absticks  or _getlength()

#endif
