Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksoid <aleksoid@users.sourceforge.net>2008-08-08 10:48:17 +0400
committerAleksoid <aleksoid@users.sourceforge.net>2008-08-08 10:48:17 +0400
commit2d9c28d8f7e6f2e13a2b2644922257ffde3367ba (patch)
treeccc1545b88be9547eca85ac29ccb1e7db631b9f8 /src/apps/mplayerc/Playlist.cpp
parent84ec48dc986329966267e581f29a2f4f3d7b51f5 (diff)
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
Diffstat (limited to 'src/apps/mplayerc/Playlist.cpp')
-rw-r--r--src/apps/mplayerc/Playlist.cpp33
1 files changed, 25 insertions, 8 deletions
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<plsort2_t> 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));