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