Skip to content

Commit

Permalink
add new C api function ModPlug_Tell to get the playing position in msecs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sezero committed Jan 29, 2022
1 parent d5d0cdc commit 76ce2aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/modplug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 5 additions & 2 deletions src/modplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) | \
Expand Down Expand Up @@ -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) */
Expand Down

0 comments on commit 76ce2aa

Please sign in to comment.