wildmidi: provide and current total song time

The _WM_Info struct provides all we need, it is obtained by
WildMidi_GetInfo().
This commit is contained in:
Max Kellermann 2009-02-12 16:47:48 +01:00
parent 1492339463
commit 321eb1077a

View File

@ -54,23 +54,38 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs)
.channels = 2, .channels = 2,
}; };
midi *wm; midi *wm;
const struct _WM_Info *info;
enum decoder_command cmd; enum decoder_command cmd;
wm = WildMidi_Open(path_fs); wm = WildMidi_Open(path_fs);
if (wm == NULL) if (wm == NULL)
return; return;
decoder_initialized(decoder, &audio_format, false, -1); info = WildMidi_GetInfo(wm);
if (info == NULL) {
WildMidi_Close(wm);
return;
}
decoder_initialized(decoder, &audio_format, false,
info->approx_total_samples / WILDMIDI_SAMPLE_RATE);
do { do {
char buffer[4096]; char buffer[4096];
int len; int len;
info = WildMidi_GetInfo(wm);
if (info == NULL)
break;
len = WildMidi_GetOutput(wm, buffer, sizeof(buffer)); len = WildMidi_GetOutput(wm, buffer, sizeof(buffer));
if (len <= 0) if (len <= 0)
break; break;
cmd = decoder_data(decoder, NULL, buffer, len, 0, 0, NULL); cmd = decoder_data(decoder, NULL, buffer, len,
(float)info->current_sample /
(float)WILDMIDI_SAMPLE_RATE,
0, NULL);
} while (cmd == DECODE_COMMAND_NONE); } while (cmd == DECODE_COMMAND_NONE);
WildMidi_Close(wm); WildMidi_Close(wm);
@ -79,10 +94,24 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs)
static struct tag * static struct tag *
wildmidi_tag_dup(const char *path_fs) wildmidi_tag_dup(const char *path_fs)
{ {
struct tag *tag = tag_new(); midi *wm;
const struct _WM_Info *info;
struct tag *tag;
/* to be implemented */ wm = WildMidi_Open(path_fs);
(void)path_fs; if (wm == NULL)
return NULL;
info = WildMidi_GetInfo(wm);
if (info == NULL) {
WildMidi_Close(wm);
return NULL;
}
tag = tag_new();
tag->time = info->approx_total_samples / WILDMIDI_SAMPLE_RATE;
WildMidi_Close(wm);
return tag; return tag;
} }