RE: Shuffling and unshuffling (was Re: ID3 tag quest ion)

"Moser, Robert L. II" <[email protected]> Tue, 18 Feb 2003 14:14:13 -0600
Newsgroups gmane.music.equipment.slimp3.dev
Message-ID <8F76CAB2F77CE542B4B6CCEDD9B03CCB01B2D51C@vhapalexce.v21.med.va.gov>
It might be worthwhile to inject some info about how shuffle is currently
implemented:

In the client struct there is an array containing the full paths of all the
songs, in the playlist order (or order that they were added if not a saved
playlist).

There is a second array which contains the indexes of the first list in the
shuffled order.

The current song is an index into the second array.

Unshuffling is basically free, as all you have to do is make the second
array be 0..(songcount - 1).  Shuffling is accomplished by taking that array
of 0..(songcount-1) and using the algorithm from perlfaq4.

Prior to shuffling, the current song index into the first array is noted.
After the shuffle, if the client is currently playing, that song index is
found in the shuffled array and that position is swapped with the first
position in the array (which is why the currently playing song is always the
first one after the shuffle).  If the client isn't playing, then the current
song pointer is set to the first song in the list, no matter what it was
previously.

Robert

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/FpY02D/vN2EAA/xGHJAA/rIp0lB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/