/*
 *  call-seq:
 *    rewind  ->  self
 *
 *  Rewind the Music to the beginning. If the Music was paused, it
 *  will still be paused after the rewind. Does nothing if the Music
 *  is stopped.
 */
static VALUE rg_music_rewind( VALUE self )
{
  RG_Music *music;
  Data_Get_Struct(self, RG_Music, music);

  /* Check that the music is current. */
  if( _rg_music_current_check(self) )
  {
    /* Only do anything if it's not stopped */
    if( !rg_music_stoppedp(self) )
    {
      /* Remember whether it was paused. */
      int was_paused = Mix_PausedMusic();

      /*
       * Rather than using SDL_mixer's crippled Mix_RewindMusic,
       * which only works for a few file types, we'll just stop and
       * start the music again from the beginning.
       */
      Mix_HaltMusic();
      int result = Mix_PlayMusic(music->wrap->music, music->repeats);

      if( result == -1 )
      {
        rb_raise(eSDLError, "Could not rewind Music: %s", Mix_GetError());
      }

      /* Pause it again if it was paused before. */
      if( was_paused )
      {
        Mix_PauseMusic();
      }
    }
  }

  return self;
}