Commits

Anonymous committed d83539e

music.get_pos()

  • Participants
  • Parent commits e881b3e

Comments (0)

Files changed (7)

 
 March 23, 2002
 	big config.py update
+	music.get_pos()  (thx Michael Urman)
 
 March 20, 2002
 	sprite.spritecollideany() now works as described
 <a href=ref/pygame_mixer_music.html#fadeout>pygame.mixer.music.fadeout</a> - fadeout current music<br>
 <a href=ref/pygame_mixer_music.html#get_busy>pygame.mixer.music.get_busy</a> - query state of the music<br>
 <a href=ref/pygame_mixer_music.html#get_endevent>pygame.mixer.music.get_endevent</a> - query the current music finished event<br>
+<a href=ref/pygame_mixer_music.html#get_pos>pygame.mixer.music.get_pos</a> - query music position<br>
 <a href=ref/pygame_mixer_music.html#get_volume>pygame.mixer.music.get_volume</a> - query music volume<br>
 <a href=ref/pygame_mixer_music.html#load>pygame.mixer.music.load</a> - load current music<br>
 <a href=ref/pygame_mixer_music.html#pause>pygame.mixer.music.pause</a> - pause the playing music<br>

docs/ref/pygame_mixer_music.html

 query the current music finished event</td></tr>
 
 
+<tr><td><a href=#get_pos>get_pos</a></td><td> -
+query music position</td></tr>
+
+
 <tr><td><a href=#get_volume>get_volume</a></td><td> -
 query music volume</td></tr>
 
 will return the id of the current music finishe event.
 </ul><br>&nbsp;<br>
 
+<a name=get_pos><font size=+2><b>get_pos
+</b></font><br><font size=+1><tt>
+pygame.mixer.music.get_pos() -> val
+</tt></font><ul>
+Get the current (interpolated) time position of the music.
+Value is in ms, just like <a href=pygame_time.html#get_ticks>get_ticks()</a>.
+</ul><br>&nbsp;<br>
+
 <a name=get_volume><font size=+2><b>get_volume
 </b></font><br><font size=+1><tt>
 pygame.mixer.music.get_volume() -> val
-
                             Pygame Installation
 
    Python can be built from source, but the easiest way is to get a
 <li>TheCorruptor for his incredible logos and graphics</li>
 <li>Thanks to those sending in patches and fixes:
     Niki Spahiev, Gordon Tyler, Nathaniel Pryce, 
-    Dave Wallace, John Popplewell</li>
+    Dave Wallace, John Popplewell, Michael Urman</li>
 <li>And our bug hunters above and beyond:
     Angus, Guillaume Proux, Frank Raiser,
     Austin Henry, Kaweh Kazemi, Arturo Aldama,
-
                         Pygame Readme
    Version 1.4
    January 27, 2002 Python Game Development
      TheCorruptor for his incredible logos and graphics
 
      Thanks to those sending in patches and fixes: Niki Spahiev, Gordon
-   Tyler, Nathaniel Pryce, Dave Wallace, John Popplewell
+   Tyler, Nathaniel Pryce, Dave Wallace, John Popplewell, Michael Urman
 
      And our bug hunters above and beyond: Angus, Guillaume Proux, Frank
    Raiser, Austin Henry, Kaweh Kazemi, Arturo Aldama, Mike Mulcheck
      own rotozoom function. The surfarray module requires the python
      Numeric package for its multidimensional numeric arrays.
 
-   Todo
+   Todo / Ideas (feel free to submit)
      * smarten the config.py and setup.py stuff
-     * unify the types/classes for python 2.2 and above
+     * unify the types/classes for python 2.2
      * transform.skew() function
+     * transform.scroll() function
+     * image filtering (colors,blurs,etc)
+     * quake-like console with python interpreter
+     * soundarray module
+     * game lobby. client, simple server, and protocol
+     * surfarrays should be able to do RGBA along with RGB
 
    License
 
 
 static Mix_Music* current_music = NULL;
 static int endmusic_event = SDL_NOEVENT;
+static long long int music_pos = 0;
+static long int music_pos_time = -1;
+static int music_frequency = 0;
+static Uint16 music_format = 0;
+static int music_channels = 0;
 
 
 static void endmusic_callback(void)
 		e.type = endmusic_event;
 		SDL_PushEvent(&e);
 	}
+	Mix_SetPostMix(NULL, NULL);
+	music_pos_time = -1;
+}
+
+static void mixmusic_callback(void *udata, Uint8 *stream, int len)
+{
+	music_pos += len;
+	music_pos_time = SDL_GetTicks();
 }
 
 
 		return RAISE(PyExc_SDLError, "music not loaded");
 
 	Mix_HookMusicFinished(endmusic_callback);
+	Mix_SetPostMix(mixmusic_callback, NULL);
+	Mix_QuerySpec(&music_frequency, &music_format, &music_channels);
+	music_pos = 0;
+	music_pos_time = SDL_GetTicks();
 
 	val = Mix_PlayMusic(current_music, loops);
 	if(val == -1)
 
 
 
+    /*DOC*/ static char doc_get_pos[] =
+    /*DOC*/    "pygame.mixer.music.get_pos() -> val\n"
+    /*DOC*/    "query music position\n"
+    /*DOC*/    "\n"
+    /*DOC*/    "Get the current (interpolated) time position of the music.\n"
+    /*DOC*/    "Value is in ms, just like get_ticks().\n"
+    /*DOC*/ ;
+
+static PyObject* get_pos(PyObject* self, PyObject* args)
+{
+	long int ticks;
+
+	if(!PyArg_ParseTuple(args, ""))
+		return NULL;
+
+	MIXER_INIT_CHECK();
+
+	if (music_pos_time < 0)
+		return PyLong_FromLong(-1);
+
+	ticks = 1000 * music_pos /
+		(music_channels * music_frequency * ((music_format & 0xff) >> 3));
+	ticks += SDL_GetTicks() - music_pos_time;
+
+	return PyInt_FromLong((long)ticks);
+}
+
+
+
     /*DOC*/ static char doc_set_endevent[] =
     /*DOC*/    "pygame.mixer.music.set_endevent([eventid]) -> None\n"
     /*DOC*/    "sets music finished event\n"
 	{ "rewind", mus_rewind, 1, doc_rewind },
 	{ "set_volume", set_volume, 1, doc_set_volume },
 	{ "get_volume", get_volume, 1, doc_get_volume },
+	{ "get_pos", get_pos, 1, doc_get_pos },
 
 	{ "load", load, 1, doc_load },