add loop points information calls
authorVitaly Novichkov
Mon, 23 Dec 2019 14:01:02 +0300
changeset 1118d711a86866aa
parent 1117 70412138c859
child 1119 24ca9a03d51c
add loop points information calls

- Mix_GetMusicLoopStartTime() to retrieve loop start time position
- Mix_GetMusicLoopEndTime() to retrieve loop end time position
- Mix_GetMusicLoopLengthTime() to retrieve a length of looping area
include/SDL_mixer.h
src/codecs/music_cmd.c
src/codecs/music_flac.c
src/codecs/music_fluidsynth.c
src/codecs/music_mad.c
src/codecs/music_mikmod.c
src/codecs/music_modplug.c
src/codecs/music_mpg123.c
src/codecs/music_nativemidi.c
src/codecs/music_ogg.c
src/codecs/music_opus.c
src/codecs/music_timidity.c
src/codecs/music_wav.c
src/music.c
src/music.h
     1.1 --- a/include/SDL_mixer.h	Mon Dec 23 14:01:02 2019 +0300
     1.2 +++ b/include/SDL_mixer.h	Mon Dec 23 14:01:02 2019 +0300
     1.3 @@ -617,6 +617,28 @@
     1.4   */
     1.5  extern DECLSPEC double SDLCALL Mix_GetMusicPosition(Mix_Music *music);
     1.6  
     1.7 +/* Return music duration in seconds.
     1.8 +   If NULL is passed, returns duration of current playing music.
     1.9 +   Returns -1 on error.
    1.10 + */
    1.11 +extern DECLSPEC double SDLCALL Mix_MusicDuration(Mix_Music *music);
    1.12 +
    1.13 +/*
    1.14 +    Get the loop start time position of music stream
    1.15 +    returns -1.0 if this feature is not used for this music or not supported for some codec
    1.16 + */
    1.17 +extern DECLSPEC double SDLCALL Mix_GetMusicLoopStartTime(Mix_Music *music);
    1.18 +/*
    1.19 +    Get the loop end time position of music stream
    1.20 +    returns -1.0 if this feature is not used for this music or not supported for some codec
    1.21 + */
    1.22 +extern DECLSPEC double SDLCALL Mix_GetMusicLoopEndTime(Mix_Music *music);
    1.23 +/*
    1.24 +    Get the loop time length of music stream
    1.25 +    returns -1.0 if this feature is not used for this music or not supported for some codec
    1.26 + */
    1.27 +extern DECLSPEC double SDLCALL Mix_GetMusicLoopLengthTime(Mix_Music *music);
    1.28 +
    1.29  /* Check the status of a specific channel.
    1.30     If the specified channel is -1, check all channels.
    1.31  */
    1.32 @@ -626,12 +648,6 @@
    1.33  /* Stop music and set external music playback command */
    1.34  extern DECLSPEC int SDLCALL Mix_SetMusicCMD(const char *command);
    1.35  
    1.36 -/* Return music duration in seconds.
    1.37 -   If NULL is passed, returns duration of current playing music.
    1.38 -   Returns -1 on error.
    1.39 - */
    1.40 -extern DECLSPEC double SDLCALL Mix_MusicDuration(Mix_Music *music);
    1.41 -
    1.42  /* Synchro value is set by MikMod from modules while playing */
    1.43  extern DECLSPEC int SDLCALL Mix_SetSynchroValue(int value);
    1.44  extern DECLSPEC int SDLCALL Mix_GetSynchroValue(void);
     2.1 --- a/src/codecs/music_cmd.c	Mon Dec 23 14:01:02 2019 +0300
     2.2 +++ b/src/codecs/music_cmd.c	Mon Dec 23 14:01:02 2019 +0300
     2.3 @@ -282,6 +282,9 @@
     2.4      NULL,   /* Seek */
     2.5      NULL,   /* Tell */
     2.6      NULL,   /* Duration */
     2.7 +    NULL,   /* LoopStart */
     2.8 +    NULL,   /* LoopEnd */
     2.9 +    NULL,   /* LoopLength */
    2.10      MusicCMD_Pause,
    2.11      MusicCMD_Resume,
    2.12      MusicCMD_Stop,
     3.1 --- a/src/codecs/music_flac.c	Mon Dec 23 14:01:02 2019 +0300
     3.2 +++ b/src/codecs/music_flac.c	Mon Dec 23 14:01:02 2019 +0300
     3.3 @@ -699,6 +699,33 @@
     3.4      return (double)music->full_length / music->sample_rate;
     3.5  }
     3.6  
     3.7 +static double FLAC_LoopStart(void *music_p)
     3.8 +{
     3.9 +    FLAC_Music *music = (FLAC_Music *)music_p;
    3.10 +    if (music->loop > 0) {
    3.11 +        return (double)music->loop_start / music->sample_rate;
    3.12 +    }
    3.13 +    return -1.0;
    3.14 +}
    3.15 +
    3.16 +static double FLAC_LoopEnd(void *music_p)
    3.17 +{
    3.18 +    FLAC_Music *music = (FLAC_Music *)music_p;
    3.19 +    if (music->loop > 0) {
    3.20 +        return (double)music->loop_end / music->sample_rate;
    3.21 +    }
    3.22 +    return -1.0;
    3.23 +}
    3.24 +
    3.25 +static double FLAC_LoopLength(void *music_p)
    3.26 +{
    3.27 +    FLAC_Music *music = (FLAC_Music *)music_p;
    3.28 +    if (music->loop > 0) {
    3.29 +        return (double)music->loop_len / music->sample_rate;
    3.30 +    }
    3.31 +    return -1.0;
    3.32 +}
    3.33 +
    3.34  /* Close the given FLAC_Music object */
    3.35  static void FLAC_Delete(void *context)
    3.36  {
    3.37 @@ -738,6 +765,9 @@
    3.38      FLAC_Seek,
    3.39      FLAC_Tell,
    3.40      FLAC_Duration,
    3.41 +    FLAC_LoopStart,
    3.42 +    FLAC_LoopEnd,
    3.43 +    FLAC_LoopLength,
    3.44      NULL,   /* Pause */
    3.45      NULL,   /* Resume */
    3.46      NULL,   /* Stop */
     4.1 --- a/src/codecs/music_fluidsynth.c	Mon Dec 23 14:01:02 2019 +0300
     4.2 +++ b/src/codecs/music_fluidsynth.c	Mon Dec 23 14:01:02 2019 +0300
     4.3 @@ -312,6 +312,9 @@
     4.4      NULL,   /* Seek */
     4.5      NULL,   /* Tell */
     4.6      NULL,   /* Duration */
     4.7 +    NULL,   /* LoopStart */
     4.8 +    NULL,   /* LoopEnd */
     4.9 +    NULL,   /* LoopLength */
    4.10      NULL,   /* Pause */
    4.11      NULL,   /* Resume */
    4.12      FLUIDSYNTH_Stop,
     5.1 --- a/src/codecs/music_mad.c	Mon Dec 23 14:01:02 2019 +0300
     5.2 +++ b/src/codecs/music_mad.c	Mon Dec 23 14:01:02 2019 +0300
     5.3 @@ -474,6 +474,9 @@
     5.4      MAD_Seek,
     5.5      NULL,   /* Tell */
     5.6      NULL,   /* Duration */
     5.7 +    NULL,   /* LoopStart */
     5.8 +    NULL,   /* LoopEnd */
     5.9 +    NULL,   /* LoopLength */
    5.10      NULL,   /* Pause */
    5.11      NULL,   /* Resume */
    5.12      NULL,   /* Stop */
     6.1 --- a/src/codecs/music_mikmod.c	Mon Dec 23 14:01:02 2019 +0300
     6.2 +++ b/src/codecs/music_mikmod.c	Mon Dec 23 14:01:02 2019 +0300
     6.3 @@ -492,6 +492,9 @@
     6.4      MIKMOD_Seek,
     6.5      NULL,   /* Tell */
     6.6      NULL,   /* Duration */
     6.7 +    NULL,   /* LoopStart */
     6.8 +    NULL,   /* LoopEnd */
     6.9 +    NULL,   /* LoopLength */
    6.10      NULL,   /* Pause */
    6.11      NULL,   /* Resume */
    6.12      MIKMOD_Stop,
     7.1 --- a/src/codecs/music_modplug.c	Mon Dec 23 14:01:02 2019 +0300
     7.2 +++ b/src/codecs/music_modplug.c	Mon Dec 23 14:01:02 2019 +0300
     7.3 @@ -320,6 +320,9 @@
     7.4      MODPLUG_Seek,
     7.5      NULL,   /* Tell */
     7.6      MODPLUG_Duration,
     7.7 +    NULL,   /* LoopStart */
     7.8 +    NULL,   /* LoopEnd */
     7.9 +    NULL,   /* LoopLength */
    7.10      NULL,   /* Pause */
    7.11      NULL,   /* Resume */
    7.12      NULL,   /* Stop */
     8.1 --- a/src/codecs/music_mpg123.c	Mon Dec 23 14:01:02 2019 +0300
     8.2 +++ b/src/codecs/music_mpg123.c	Mon Dec 23 14:01:02 2019 +0300
     8.3 @@ -499,6 +499,9 @@
     8.4      MPG123_Seek,
     8.5      MPG123_Tell,
     8.6      MPG123_Duration,
     8.7 +    NULL,   /* LoopStart */
     8.8 +    NULL,   /* LoopEnd */
     8.9 +    NULL,   /* LoopLength */
    8.10      NULL,   /* Pause */
    8.11      NULL,   /* Resume */
    8.12      NULL,   /* Stop */
     9.1 --- a/src/codecs/music_nativemidi.c	Mon Dec 23 14:01:02 2019 +0300
     9.2 +++ b/src/codecs/music_nativemidi.c	Mon Dec 23 14:01:02 2019 +0300
     9.3 @@ -103,6 +103,9 @@
     9.4      NULL,   /* Seek */
     9.5      NULL,   /* Tell */
     9.6      NULL,   /* Duration */
     9.7 +    NULL,   /* LoopStart */
     9.8 +    NULL,   /* LoopEnd */
     9.9 +    NULL,   /* LoopLength */
    9.10      NATIVEMIDI_Pause,
    9.11      NATIVEMIDI_Resume,
    9.12      NATIVEMIDI_Stop,
    10.1 --- a/src/codecs/music_ogg.c	Mon Dec 23 14:01:02 2019 +0300
    10.2 +++ b/src/codecs/music_ogg.c	Mon Dec 23 14:01:02 2019 +0300
    10.3 @@ -493,6 +493,34 @@
    10.4  #endif
    10.5  }
    10.6  
    10.7 +static double   OGG_LoopStart(void *music_p)
    10.8 +{
    10.9 +    OGG_music *music = (OGG_music *)music_p;
   10.10 +    if (music->loop > 0) {
   10.11 +        return (double)music->loop_start / music->vi.rate;
   10.12 +    }
   10.13 +    return -1.0;
   10.14 +}
   10.15 +
   10.16 +static double   OGG_LoopEnd(void *music_p)
   10.17 +{
   10.18 +    OGG_music *music = (OGG_music *)music_p;
   10.19 +    if (music->loop > 0) {
   10.20 +        return (double)music->loop_end / music->vi.rate;
   10.21 +    }
   10.22 +    return -1.0;
   10.23 +}
   10.24 +
   10.25 +static double   OGG_LoopLength(void *music_p)
   10.26 +{
   10.27 +    OGG_music *music = (OGG_music *)music_p;
   10.28 +    if (music->loop > 0) {
   10.29 +        return (double)music->loop_len / music->vi.rate;
   10.30 +    }
   10.31 +    return -1.0;
   10.32 +}
   10.33 +
   10.34 +
   10.35  /* Close the given OGG stream */
   10.36  static void OGG_Delete(void *context)
   10.37  {
   10.38 @@ -530,6 +558,9 @@
   10.39      OGG_Seek,
   10.40      OGG_Tell,
   10.41      OGG_Duration,
   10.42 +    OGG_LoopStart,
   10.43 +    OGG_LoopEnd,
   10.44 +    OGG_LoopLength,
   10.45      NULL,   /* Pause */
   10.46      NULL,   /* Resume */
   10.47      NULL,   /* Stop */
    11.1 --- a/src/codecs/music_opus.c	Mon Dec 23 14:01:02 2019 +0300
    11.2 +++ b/src/codecs/music_opus.c	Mon Dec 23 14:01:02 2019 +0300
    11.3 @@ -473,6 +473,33 @@
    11.4      return music->full_length / 48000.0;
    11.5  }
    11.6  
    11.7 +static double OPUS_LoopStart(void *music_p)
    11.8 +{
    11.9 +    OPUS_music *music = (OPUS_music *)music_p;
   11.10 +    if (music->loop > 0) {
   11.11 +        return (double)music->loop_start / 48000.0;
   11.12 +    }
   11.13 +    return -1.0;
   11.14 +}
   11.15 +
   11.16 +static double OPUS_LoopEnd(void *music_p)
   11.17 +{
   11.18 +    OPUS_music *music = (OPUS_music *)music_p;
   11.19 +    if (music->loop > 0) {
   11.20 +        return (double)music->loop_end / 48000.0;
   11.21 +    }
   11.22 +    return -1.0;
   11.23 +}
   11.24 +
   11.25 +static double OPUS_LoopLength(void *music_p)
   11.26 +{
   11.27 +    OPUS_music *music = (OPUS_music *)music_p;
   11.28 +    if (music->loop > 0) {
   11.29 +        return (double)music->loop_len / 48000.0;
   11.30 +    }
   11.31 +    return -1.0;
   11.32 +}
   11.33 +
   11.34  /* Close the given Opus stream */
   11.35  static void OPUS_Delete(void *context)
   11.36  {
   11.37 @@ -510,6 +537,9 @@
   11.38      OPUS_Seek,
   11.39      OPUS_Tell,
   11.40      OPUS_Duration,
   11.41 +    OPUS_LoopStart,
   11.42 +    OPUS_LoopEnd,
   11.43 +    OPUS_LoopLength,
   11.44      NULL,   /* Pause */
   11.45      NULL,   /* Resume */
   11.46      NULL,   /* Stop */
    12.1 --- a/src/codecs/music_timidity.c	Mon Dec 23 14:01:02 2019 +0300
    12.2 +++ b/src/codecs/music_timidity.c	Mon Dec 23 14:01:02 2019 +0300
    12.3 @@ -258,6 +258,9 @@
    12.4      TIMIDITY_Seek,
    12.5      NULL,   /* Tell */
    12.6      TIMIDITY_Duration,
    12.7 +    NULL,   /* LoopStart */
    12.8 +    NULL,   /* LoopEnd */
    12.9 +    NULL,   /* LoopLength */
   12.10      NULL,   /* Pause */
   12.11      NULL,   /* Resume */
   12.12      NULL,   /* Stop */
    13.1 --- a/src/codecs/music_wav.c	Mon Dec 23 14:01:02 2019 +0300
    13.2 +++ b/src/codecs/music_wav.c	Mon Dec 23 14:01:02 2019 +0300
    13.3 @@ -1112,6 +1112,9 @@
    13.4      WAV_Seek,   /* Seek */
    13.5      WAV_Tell,   /* Tell */
    13.6      WAV_Duration,
    13.7 +    NULL,   /* LoopStart */
    13.8 +    NULL,   /* LoopEnd */
    13.9 +    NULL,   /* LoopLength */
   13.10      NULL,   /* Pause */
   13.11      NULL,   /* Resume */
   13.12      NULL,   /* Stop */
    14.1 --- a/src/music.c	Mon Dec 23 14:01:02 2019 +0300
    14.2 +++ b/src/music.c	Mon Dec 23 14:01:02 2019 +0300
    14.3 @@ -848,6 +848,86 @@
    14.4      return(retval);
    14.5  }
    14.6  
    14.7 +/* Get Loop start position */
    14.8 +static double music_internal_loop_start(Mix_Music *music)
    14.9 +{
   14.10 +    if (music->interface->LoopStart) {
   14.11 +        return music->interface->LoopStart(music->context);
   14.12 +    }
   14.13 +    return -1;
   14.14 +}
   14.15 +double Mix_GetMusicLoopStartTime(Mix_Music *music)
   14.16 +{
   14.17 +    double retval;
   14.18 +
   14.19 +    Mix_LockAudio();
   14.20 +    if (music) {
   14.21 +        retval = music_internal_loop_start(music);
   14.22 +    } else if (music_playing) {
   14.23 +        retval = music_internal_loop_start(music_playing);
   14.24 +    } else {
   14.25 +        Mix_SetError("Music isn't playing");
   14.26 +        retval = -1.0;
   14.27 +    }
   14.28 +    Mix_UnlockAudio();
   14.29 +
   14.30 +    return(retval);
   14.31 +}
   14.32 +
   14.33 +/* Get Loop end position */
   14.34 +static double music_internal_loop_end(Mix_Music *music)
   14.35 +{
   14.36 +    if (music->interface->LoopEnd) {
   14.37 +        return music->interface->LoopEnd(music->context);
   14.38 +    }
   14.39 +    return -1;
   14.40 +}
   14.41 +double Mix_GetMusicLoopEndTime(Mix_Music *music)
   14.42 +{
   14.43 +    double retval;
   14.44 +
   14.45 +    Mix_LockAudio();
   14.46 +    if (music) {
   14.47 +        retval = music_internal_loop_end(music);
   14.48 +    } else if (music_playing) {
   14.49 +        retval = music_internal_loop_end(music_playing);
   14.50 +    } else {
   14.51 +        Mix_SetError("Music isn't playing");
   14.52 +        retval = -1.0;
   14.53 +    }
   14.54 +    Mix_UnlockAudio();
   14.55 +
   14.56 +    return(retval);
   14.57 +}
   14.58 +
   14.59 +/* Get Loop end position */
   14.60 +static double music_internal_loop_length(Mix_Music *music)
   14.61 +{
   14.62 +    if (music->interface->LoopLength) {
   14.63 +        return music->interface->LoopLength(music->context);
   14.64 +    }
   14.65 +    return -1;
   14.66 +}
   14.67 +double Mix_GetMusicLoopLengthTime(Mix_Music *music)
   14.68 +{
   14.69 +    double retval;
   14.70 +
   14.71 +    Mix_LockAudio();
   14.72 +    if (music) {
   14.73 +        retval = music_internal_loop_length(music);
   14.74 +    } else if (music_playing) {
   14.75 +        retval = music_internal_loop_length(music_playing);
   14.76 +    } else {
   14.77 +        Mix_SetError("Music isn't playing");
   14.78 +        retval = -1.0;
   14.79 +    }
   14.80 +    Mix_UnlockAudio();
   14.81 +
   14.82 +    return(retval);
   14.83 +}
   14.84 +
   14.85 +
   14.86 +
   14.87  /* Set the music's initial volume */
   14.88  static void music_internal_initialize_volume(void)
   14.89  {
    15.1 --- a/src/music.h	Mon Dec 23 14:01:02 2019 +0300
    15.2 +++ b/src/music.h	Mon Dec 23 14:01:02 2019 +0300
    15.3 @@ -91,6 +91,15 @@
    15.4      /* Get Music duration (in seconds) */
    15.5      double (*Duration)(void *music);
    15.6  
    15.7 +    /* Tell a loop start position (in seconds) */
    15.8 +    double (*LoopStart)(void *music);
    15.9 +
   15.10 +    /* Tell a loop end position (in seconds) */
   15.11 +    double (*LoopEnd)(void *music);
   15.12 +
   15.13 +    /* Tell a loop length position (in seconds) */
   15.14 +    double (*LoopLength)(void *music);
   15.15 +
   15.16      /* Pause playing music */
   15.17      void (*Pause)(void *music);
   15.18