From 76ce2aa81df075438483b3ba6e4188d2c56e910d Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 29 Jan 2022 18:55:50 +0300 Subject: [PATCH] add new C api function ModPlug_Tell to get the playing position in msecs the function was originally authored and is provided by Vitaly Novichkov. increase the version number to 0.8.10 so the new functions can be checked easily at compile time. --- src/modplug.cpp | 15 +++++++++++++++ src/modplug.h | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/modplug.cpp b/src/modplug.cpp index 35ac5e1b..73490fa6 100644 --- a/src/modplug.cpp +++ b/src/modplug.cpp @@ -270,6 +270,21 @@ void ModPlug_Seek(ModPlugFile* file, int millisecond) file->mSoundFile.SetCurrentPos((int)(millisecond * postime)); } +int ModPlug_Tell(ModPlugFile *file) +{ + int currentPos = (int)file->mSoundFile.GetCurrentPos(); + int maxpos; + int maxtime = (int)file->mSoundFile.GetSongTime() * 1000; + float postime; + maxpos = (int)file->mSoundFile.GetMaxPosition(); + postime = 0.0f; + if (maxtime != 0.0f) + postime = (float)maxpos / (float)maxtime; + if (postime == 0.0f) + return 0; + return (int) ((float)currentPos / postime); +} + void ModPlug_GetSettings(ModPlug_Settings* settings) { memcpy(settings, &ModPlug::gSettings, sizeof(ModPlug_Settings)); diff --git a/src/modplug.h b/src/modplug.h index 5662106e..a525c091 100644 --- a/src/modplug.h +++ b/src/modplug.h @@ -13,8 +13,8 @@ extern "C" { #define LIBMODPLUG_MAJOR 0L #define LIBMODPLUG_MINOR 8L -#define LIBMODPLUG_REVISION 9L -#define LIBMODPLUG_PATCH 1L +#define LIBMODPLUG_REVISION 10L +#define LIBMODPLUG_PATCH 0L #define LIBMODPLUG_VERSION \ ((LIBMODPLUG_MAJOR <<24) | \ (LIBMODPLUG_MINOR <<16) | \ @@ -79,6 +79,9 @@ MODPLUG_EXPORT int ModPlug_GetLength(ModPlugFile* file); * ModPlug_GetLength() does not report the full length. */ MODPLUG_EXPORT void ModPlug_Seek(ModPlugFile* file, int millisecond); +/* Get the absolute playing position in song, in milliseconds. */ +MODPLUG_EXPORT int ModPlug_Tell(ModPlugFile* file); + enum _ModPlug_Flags { MODPLUG_ENABLE_OVERSAMPLING = 1 << 0, /* Enable oversampling (*highly* recommended) */