Skip to content

Commit d770627

Browse files
committed
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.
1 parent 28b0933 commit d770627

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/modplug.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ void ModPlug_Seek(ModPlugFile* file, int millisecond)
270270
file->mSoundFile.SetCurrentPos((int)(millisecond * postime));
271271
}
272272

273+
int ModPlug_Tell(ModPlugFile *file)
274+
{
275+
int currentPos = (int)file->mSoundFile.GetCurrentPos();
276+
int maxpos;
277+
int maxtime = (int)file->mSoundFile.GetSongTime() * 1000;
278+
float postime;
279+
maxpos = (int)file->mSoundFile.GetMaxPosition();
280+
postime = 0.0f;
281+
if (maxtime != 0.0f)
282+
postime = (float)maxpos / (float)maxtime;
283+
if (postime == 0.0f)
284+
return 0;
285+
return (int) ((float)currentPos / postime);
286+
}
287+
273288
void ModPlug_GetSettings(ModPlug_Settings* settings)
274289
{
275290
memcpy(settings, &ModPlug::gSettings, sizeof(ModPlug_Settings));

src/modplug.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ extern "C" {
1313

1414
#define LIBMODPLUG_MAJOR 0L
1515
#define LIBMODPLUG_MINOR 8L
16-
#define LIBMODPLUG_REVISION 9L
17-
#define LIBMODPLUG_PATCH 1L
16+
#define LIBMODPLUG_REVISION 10L
17+
#define LIBMODPLUG_PATCH 0L
1818
#define LIBMODPLUG_VERSION \
1919
((LIBMODPLUG_MAJOR <<24) | \
2020
(LIBMODPLUG_MINOR <<16) | \
@@ -79,6 +79,9 @@ MODPLUG_EXPORT int ModPlug_GetLength(ModPlugFile* file);
7979
* ModPlug_GetLength() does not report the full length. */
8080
MODPLUG_EXPORT void ModPlug_Seek(ModPlugFile* file, int millisecond);
8181

82+
/* Get the absolute playing position in song, in milliseconds. */
83+
MODPLUG_EXPORT int ModPlug_Tell(ModPlugFile* file);
84+
8285
enum _ModPlug_Flags
8386
{
8487
MODPLUG_ENABLE_OVERSAMPLING = 1 << 0, /* Enable oversampling (*highly* recommended) */

0 commit comments

Comments
 (0)