From 2d9c28d8f7e6f2e13a2b2644922257ffde3367ba Mon Sep 17 00:00:00 2001 From: Aleksoid Date: Fri, 8 Aug 2008 06:48:17 +0000 Subject: FIX : Problems with SHUFFLE function (bug #2030723) git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@721 10f7b99b-c216-0410-bff0-8a66a9350fd8 --- src/apps/mplayerc/Playlist.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/apps/mplayerc/Playlist.cpp') diff --git a/src/apps/mplayerc/Playlist.cpp b/src/apps/mplayerc/Playlist.cpp index dea354112..e8cd66220 100644 --- a/src/apps/mplayerc/Playlist.cpp +++ b/src/apps/mplayerc/Playlist.cpp @@ -250,17 +250,34 @@ void CPlaylist::SetPos(POSITION pos) m_pos = pos; } -CPlaylistItem& CPlaylist::GetNextWrap(POSITION& pos) +#define Rand(a, b) rand()%(b-a+1)+a + +POSITION CPlaylist::Shuffle() { - GetNext(pos); + CAtlArray a; + a.SetCount(GetCount()); + srand((unsigned)time(NULL)); + POSITION pos = GetHeadPosition(); + for(int i = 0; pos; i++, GetNext(pos)) + a[i].pos = pos; + + pos = GetPos(); + int rnd = Rand(0, a.GetCount()-1); + while(pos == a[rnd].pos) rnd = Rand(0, a.GetCount()-1); - if(!pos) - { - // FIXME: add param: , bool fShuffle - if(GetCount() > 2 && AfxGetApp()->GetProfileInt(ResStr(IDS_R_SETTINGS), _T("ShufflePlaylistItems"), FALSE)) - Randomize(); + return a[rnd].pos; +} - pos = GetHeadPosition(); +CPlaylistItem& CPlaylist::GetNextWrap(POSITION& pos) +{ + if(AfxGetApp()->GetProfileInt(ResStr(IDS_R_SETTINGS), _T("ShufflePlaylistItems"), FALSE) && GetCount() > 2) + { + pos = Shuffle(); + } + else + { + GetNext(pos); + if(!pos) pos = GetHeadPosition(); } return(GetAt(pos)); -- cgit v1.2.3