📄 pmp300.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Portions Copyright (C) 1999 EMusic.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: pmp300.cpp,v 1.3 1999/12/02 22:06:52 elrod Exp $
____________________________________________________________________________*/
#include <assert.h>
#include <iostream>
#include <algorithm>
#ifdef unix
#include <strstream>
typedef ostrstream ostringstream;
#else
#include <sstream>
#endif
#include <string>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
using namespace std;
#include "config.h"
#include "errors.h"
#include "errno.h"
#include "pmp300.h"
#include "rio.h"
#include "utility.h"
typedef struct DeviceInfoStruct {
char* manufacturer;
char* device;
ConnectionType type;
} DeviceInfoStruct;
DeviceInfoStruct devices[] = {
{"Diamond", "Rio PMP-300", kConnection_Parallel}
};
const uint32 ports[] = { 0x378, 0x278, 0x03BC };
#define kNumDevices (sizeof(devices)/sizeof(DeviceInfoStruct))
Error privateReadPlaylist(CRio& rio,
bool useExternal,
uint32* totalMem,
uint32* usedMem,
vector<PlaylistItem*>* list,
PLMCallBackFunction function,
void* cookie);
bool FindRio(CRio& rio,
DeviceInfo* device,
PLMCallBackFunction function,
void* cookie);
extern "C"
{
PortableDevice *Initialize(FAContext* context)
{
return new PMP300(context);
}
}
#ifdef WIN32
bool LoadDriver(const char* driverName, const char* driverPath);
bool UnloadDriver(const char* driverName);
#endif
class PlaylistItemCompare {
public:
PlaylistItemCompare(PlaylistItem* item):m_item(item){}
// Function object used for comparing PlaylistItems
bool operator() (PlaylistItem* item) const
{
bool result = false;
assert(item);
if(item)
{
result = item->URL() == m_item->URL();
}
return result;
}
private:
PlaylistItem* m_item;
};
PMP300::PMP300(FAContext* context):PortableDevice(context)
{
m_context = context;
#ifdef WIN32
OSVERSIONINFO osid;
osid.dwOSVersionInfoSize = sizeof (osid);
GetVersionEx (&osid);
switch (osid.dwPlatformId)
{
// Window 3.x
case VER_PLATFORM_WIN32s:
break;
// Windows 95
case VER_PLATFORM_WIN32_WINDOWS:
break;
// Windows NT
case VER_PLATFORM_WIN32_NT:
{
#if !defined( _M_ALPHA )
if(osid.dwMajorVersion >= 4)
{
// this will allow us port access thru
// inp and outp so the rio stuff will
// work.
const char* driver = "portio";
char path[MAX_PATH];
uint32 size = sizeof(path);
context->prefs->GetInstallDirectory(path, &size);
strcat(path, "\\");
strcat(path, driver);
strcat(path, ".sys");
LoadDriver(driver, path);
}
#endif // !defined( _M_ALPHA )
break;
}
}
#endif //WIN32
}
PMP300::~PMP300()
{
#ifdef WIN32
// platform specific uninitialization
OSVERSIONINFO osid;
osid.dwOSVersionInfoSize = sizeof (osid);
GetVersionEx (&osid);
switch (osid.dwPlatformId)
{
// Window 3.x
case VER_PLATFORM_WIN32s:
break;
// Windows 95
case VER_PLATFORM_WIN32_WINDOWS:
break;
// Windows NT
case VER_PLATFORM_WIN32_NT:
{
#if !defined( _M_ALPHA )
if(osid.dwMajorVersion >= 4)
{
UnloadDriver("portio");
}
#endif // !defined( _M_ALPHA )
break;
}
}
#endif // WIN32
}
Error PMP300::GetSupportedDevices(DeviceInfo* device, uint32 index)
{
Error result = kError_InvalidParam;
assert(device);
if(device)
{
result = kError_NoMoreDevices;
if(index < kNumDevices)
{
device->SetManufacturer(devices[index].manufacturer);
device->SetDevice(devices[index].device);
device->SetConnectionType(devices[index].type);
result = kError_NoErr;
}
}
return result;
}
bool PMP300::IsDeviceAvailable(DeviceInfo* device)
{
bool result = false;
assert(device);
if(device)
{
if(!strcasecmp(device->GetDevice(), devices[0].device))
{
CRio rio;
result = FindRio(rio, device, NULL, NULL);
}
}
return result;
}
Error PMP300::GetDeviceInfo(DeviceInfo* device)
{
Error result = kError_InvalidParam;
assert(device);
if(device)
{
result = kError_DeviceNotFound;
if(!strcasecmp(device->GetDevice(), devices[0].device))
{
CRio rio;
bool rioPresent = false;
rioPresent = FindRio(rio, device, NULL, NULL);
if(rioPresent)
{
if( rio.RxDirectory() )
{
CDirBlock& cDirBlock = rio.GetDirectoryBlock();
CDirHeader& cDirHeader = cDirBlock.m_cDirHeader;
uint32 numEntries, totalMem, usedMem;
numEntries = cDirHeader.m_usCountEntry;
totalMem = ((long)cDirHeader.m_usCount32KBlockAvailable * CRIO_SIZE_32KBLOCK);
usedMem = ((long)cDirHeader.m_usCount32KBlockUsed * CRIO_SIZE_32KBLOCK);
rio.UseExternalFlash( true );
if( rio.RxDirectory() )
{
CDirBlock& cDirBlock = rio.GetDirectoryBlock();
CDirHeader& cDirHeader = cDirBlock.m_cDirHeader;
numEntries += cDirHeader.m_usCountEntry;
totalMem += ((long)cDirHeader.m_usCount32KBlockAvailable * CRIO_SIZE_32KBLOCK);
usedMem += ((long)cDirHeader.m_usCount32KBlockUsed * CRIO_SIZE_32KBLOCK);
}
device->SetNumEntries(numEntries);
device->SetCapacity(totalMem, usedMem);
}
result = kError_NoErr;
}
}
}
return result;
}
typedef struct RioProgressStruct {
PLMCallBackFunction function;
void* cookie;
PlaylistItem* item;
} RioProgressStruct;
static BOOL rioProgress(int pos, int total, void* cookie)
{
BOOL result = false;
if(cookie)
{
RioProgressStruct* ps = (RioProgressStruct*)cookie;
if(ps->function)
{
PLMEvent event;
event.type = kPLMEvent_Progress;
event.data.progressData.position = pos;
event.data.progressData.total = total;
event.data.progressData.item = ps->item;
result = ps->function(&event, ps->cookie);
}
}
return result;
}
Error PMP300::InitializeDevice(DeviceInfo* device,
PLMCallBackFunction function,
void* cookie)
{
Error result = kError_InvalidParam;
assert(device);
if(device)
{
result = kError_DeviceNotFound;
if(!strcasecmp(device->GetDevice(), devices[0].device))
{
CRio rio;
bool rioPresent = false;
rioPresent = FindRio(rio, device, function, cookie);
if(rioPresent)
{
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Status;
event.eventString += "A ";
event.eventString = device->GetDevice();
event.eventString += " has been found. Initializing internal memory...";
function(&event, cookie);
}
RioProgressStruct ps;
memset(&ps, 0x00, sizeof(ps));
ps.function = function;
ps.cookie = cookie;
ps.item = NULL;
result = kError_NoErr;
if(!rio.Initialize(true, rioProgress, &ps))
{
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Error;
event.data.errorData.errorCode = rio.GetErrorID();
event.eventString = "Initialize failed, ";
event.eventString += rio.GetErrorStr();
function(&event, cookie);
}
result = kError_UnknownErr;
}
if(function)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -