Re: random playlist patch

2001-06-27 Thread kristian kvilekval

Here's the unified version:


--- base/src/playlist.cpp.orig  Wed Jun 27 13:05:59 2001
+++ base/src/playlist.cpp   Wed Jun 27 13:11:29 2001
@@ -429,44 +429,24 @@
 toBeShuffled = &m_shuffleList;
 
 int max = toBeShuffled->size();
-vector tempShuffled;
+vector tempShuffled (max, (PlaylistItem*)0);
 
 srand((unsigned int)time(NULL));
-
-int i;
-vector usedList;
-for (i = 0; i < max; i++)
-{
-usedList.push_back(false);
-}
-
-bool used = true;
+   
 int  index = 0;
-int  lastindex = 0;
-
-for (i = 0; i < max; i++) 
+for (int i = 0; i < max; i++)
 {
-while (used)
-{
-index = (int)((double)rand() / (RAND_MAX + 1.0) * max);
-if (usedList[index] == false)
-used = false;
-if (max - i > 50 && abs(index - lastindex) < 10)
-used = true;
-} 
-usedList[index] = true;
-PlaylistItem *dupe = (*toBeShuffled)[index];
-tempShuffled.push_back(dupe);
-used = true;
-lastindex = index;
+   index = (int)((double)rand() / (RAND_MAX + 1.0) * max);
+   do {
+index ++;
+if (index == max) index=0;
+   } while (tempShuffled[index]);
+   tempShuffled[index] = (*toBeShuffled)[i];
 }
-
-toBeShuffled->erase(toBeShuffled->begin(), toBeShuffled->end());
-vector::iterator iter = tempShuffled.begin();
-for (; iter != tempShuffled.end(); iter++) 
-toBeShuffled->push_back(*iter);
+(*toBeShuffled).swap (tempShuffled);
 }
 
+
 Error PlaylistManager::SetCurrentItem(PlaylistItem* item)
 {
 return SetCurrentIndex(IndexOf(item));
@@ -493,8 +473,9 @@
 {
m_mutex.Acquire();
index = CheckIndex(index);
-   if(m_shuffle)
-  index = InternalIndexOf(&m_shuffleList, ItemAt(index));
+//index is always the internal index (never an index to the shuffle list).
+//   if(m_shuffle)
+//  index = InternalIndexOf(&m_shuffleList, ItemAt(index));
InternalSetCurrentIndex(index);
m_mutex.Release();
return kError_NoErr;
@@ -537,19 +518,15 @@
 {
 index++;
 
-if( (index >= count) && 
-(m_repeatMode == kPlaylistMode_RepeatAll || userAction))
+if( (index >= count) )
 {
-index = 0;
-
-if(m_shuffle)
-{
-ShuffleIt();
-}
-}
-else if(index >= count)
-{
-index = m_current;
+   if(m_repeatMode == kPlaylistMode_RepeatAll || userAction)
+   {
+  index = 0;
+  if (m_shuffle) ShuffleIt();
+   }
+   else
+  index = m_current;
 }
 }
 
@@ -576,19 +553,16 @@
 {
 if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
 {
-if( (index == 0) && 
-(m_repeatMode == kPlaylistMode_RepeatAll || userAction))
+index--;
+if (index < 0)
 {
-index = count - 1;
-
-if(m_shuffle)
+if  (m_repeatMode == kPlaylistMode_RepeatAll || userAction)
 {
-ShuffleIt();
+index = count - 1;
+if(m_shuffle)  ShuffleIt();
 }
-}
-else if(index != 0)
-{
-index--;
+else
+   index = 0;
 }
 }
 

-- 
Kristian G. Kvilekval
email:[EMAIL PROTECTED] office:(805)893-4178 http://www.cs.ucsb.edu/~kris
___
[EMAIL PROTECTED]
http://www.freeamp.org/mailman/listinfo/freeamp-dev



Re: random playlist patch

2001-06-27 Thread Isaac Richards

Mind resending with a a 'diff -u' so it's readable? =)

Isaac

On Wednesday 27 June 2001 16:30, kristian kvilekval wrote:
> Freeamp shuffles it's random playlist too often, giving the
> appearance that it repeats songs.This patch gives
> better behaviour including:
>
> 1.   Start with random song
> 2.   Create shuffle lists faster
> 3.   Shuffle only after all songs have been played.
>
___
[EMAIL PROTECTED]
http://www.freeamp.org/mailman/listinfo/freeamp-dev