From 321eb1077a54aa84dca2f6363fe776af4f489689 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 12 Feb 2009 16:47:48 +0100 Subject: wildmidi: provide and current total song time The _WM_Info struct provides all we need, it is obtained by WildMidi_GetInfo(). --- src/decoder/wildmidi_plugin.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/decoder/wildmidi_plugin.c b/src/decoder/wildmidi_plugin.c index e8cd42dee..39b82d0b1 100644 --- a/src/decoder/wildmidi_plugin.c +++ b/src/decoder/wildmidi_plugin.c @@ -54,23 +54,38 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs) .channels = 2, }; midi *wm; + const struct _WM_Info *info; enum decoder_command cmd; wm = WildMidi_Open(path_fs); if (wm == NULL) 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 { char buffer[4096]; int len; + info = WildMidi_GetInfo(wm); + if (info == NULL) + break; + len = WildMidi_GetOutput(wm, buffer, sizeof(buffer)); if (len <= 0) 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); WildMidi_Close(wm); @@ -79,10 +94,24 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs) static struct tag * 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 */ - (void)path_fs; + wm = WildMidi_Open(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; } -- cgit v1.2.3