103 lines
1.8 KiB
C++
Executable File
103 lines
1.8 KiB
C++
Executable File
// Playlist.cpp: implementation of the CPlaylist class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "musicplayer.h"
|
|
#include "Playlist.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CPlaylist::CPlaylist()
|
|
{
|
|
m_CurrentFile = 0;
|
|
m_TotalFiles = 0;
|
|
m_FileList.RemoveAll();
|
|
m_FilePath = L"";
|
|
}
|
|
|
|
CPlaylist::~CPlaylist()
|
|
{
|
|
|
|
}
|
|
|
|
CString CPlaylist::GetNextWorkFileName(bool bForword, bool bRandom)
|
|
{
|
|
if (bRandom) // 随机获取
|
|
{
|
|
// 计算随机数
|
|
MakeRandom(m_CurrentFile);
|
|
if (m_CurrentFile < m_TotalFiles - 1)
|
|
{
|
|
m_CurrentFile++;
|
|
}
|
|
else
|
|
{
|
|
m_CurrentFile = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (bForword) // 前一个文件
|
|
{
|
|
if (m_CurrentFile > 0)
|
|
{
|
|
m_CurrentFile--;
|
|
}
|
|
else
|
|
{
|
|
m_CurrentFile = m_TotalFiles - 1;
|
|
}
|
|
}
|
|
else // 后一个文件
|
|
{
|
|
if (m_CurrentFile < m_TotalFiles - 1)
|
|
{
|
|
m_CurrentFile++;
|
|
}
|
|
else
|
|
{
|
|
m_CurrentFile = 0;
|
|
}
|
|
}
|
|
}
|
|
return m_FilePath + m_FileList.GetAt(m_CurrentFile);
|
|
}
|
|
|
|
unsigned int CPlaylist::MakeRandom(int MaxNumber)
|
|
{
|
|
return m_Seed[MaxNumber];
|
|
}
|
|
|
|
void CPlaylist::InitSeed(int iNumber)
|
|
{
|
|
ZeroMemory(m_Seed,1024);
|
|
unsigned* iValue = (unsigned*)calloc(iNumber,sizeof(unsigned));
|
|
int k = 0;
|
|
int tmp = 0;
|
|
for (int j = 0; j < iNumber; j++)
|
|
{
|
|
iValue[j] = j;
|
|
}
|
|
|
|
for (int i = 0; i < iNumber; i++)
|
|
{
|
|
srand(Random());
|
|
k = rand() % iNumber;
|
|
tmp = iValue[k];
|
|
iValue[k] = iValue[iNumber - k -1];
|
|
iValue[iNumber - k -1] = tmp;
|
|
}
|
|
|
|
CopyMemory(m_Seed,iValue,iNumber * 4);
|
|
ZeroMemory(iValue,iNumber);
|
|
}
|