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.
*** base/src/playlist.cpp.orig Wed Jun 27 13:05:59 2001
--- base/src/playlist.cpp Wed Jun 27 13:11:29 2001
***************
*** 429,472 ****
toBeShuffled = &m_shuffleList;
int max = toBeShuffled->size();
! vector<PlaylistItem *> tempShuffled;
srand((unsigned int)time(NULL));
!
! int i;
! vector<bool> 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++)
{
! 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;
}
!
! toBeShuffled->erase(toBeShuffled->begin(), toBeShuffled->end());
! vector<PlaylistItem *>::iterator iter = tempShuffled.begin();
! for (; iter != tempShuffled.end(); iter++)
! toBeShuffled->push_back(*iter);
}
Error PlaylistManager::SetCurrentItem(PlaylistItem* item)
{
return SetCurrentIndex(IndexOf(item));
--- 429,452 ----
toBeShuffled = &m_shuffleList;
int max = toBeShuffled->size();
! vector<PlaylistItem *> tempShuffled (max, (PlaylistItem*)0);
srand((unsigned int)time(NULL));
!
int index = 0;
! for (int i = 0; i < max; i++)
{
! index = (int)((double)rand() / (RAND_MAX + 1.0) * max);
! do {
! index ++;
! if (index == max) index=0;
! } while (tempShuffled[index]);
! tempShuffled[index] = (*toBeShuffled)[i];
}
! (*toBeShuffled).swap (tempShuffled);
}
+
Error PlaylistManager::SetCurrentItem(PlaylistItem* item)
{
return SetCurrentIndex(IndexOf(item));
***************
*** 493,500 ****
{
m_mutex.Acquire();
index = CheckIndex(index);
! if(m_shuffle)
! index = InternalIndexOf(&m_shuffleList, ItemAt(index));
InternalSetCurrentIndex(index);
m_mutex.Release();
return kError_NoErr;
--- 473,481 ----
{
m_mutex.Acquire();
index = CheckIndex(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,555 ****
{
index++;
! if( (index >= count) &&
! (m_repeatMode == kPlaylistMode_RepeatAll || userAction))
{
! index = 0;
!
! if(m_shuffle)
! {
! ShuffleIt();
! }
! }
! else if(index >= count)
! {
! index = m_current;
}
}
--- 518,532 ----
{
index++;
! if( (index >= count) )
{
! if(m_repeatMode == kPlaylistMode_RepeatAll || userAction)
! {
! index = 0;
! if (m_shuffle) ShuffleIt();
! }
! else
! index = m_current;
}
}
***************
*** 576,594 ****
{
if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
{
! if( (index == 0) &&
! (m_repeatMode == kPlaylistMode_RepeatAll || userAction))
{
! index = count - 1;
!
! if(m_shuffle)
{
! ShuffleIt();
}
! }
! else if(index != 0)
! {
! index--;
}
}
--- 553,568 ----
{
if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
{
! index--;
! if (index < 0)
{
! if (m_repeatMode == kPlaylistMode_RepeatAll || userAction)
{
! index = count - 1;
! if(m_shuffle) ShuffleIt();
}
! 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