#pragma once
// WAC.com Class Liblary for Visual C++
// Copyright (C) WAC.com Inc. All rights reserved.
//
// This file is a part of the WAC.com Class Liblary.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.
// 07.05.14 : コードの整備 (sha)
// 07.05.15 : x64対応 (sha)
#include "MCIDevice.h"
/////////////////////////////////////////////////////////////////////////////
// CMciCDAudioT
template <class TBase>
class CMciCDAudioT : public TBase
{
protected:
typedef CMciCDAudioT thisClass;
public:
CMciCDAudioT()
{
}
virtual ~CMciCDAudioT()
{
}
public:
// デバイスのオープン
MCIERROR Open(LPCTSTR szDrive = NULL)
{
ATLASSERT(m_nDeviceID == 0);
DWORD_PTR dwFlags = MCI_WAIT | MCI_OPEN_TYPE;
MCI_OPEN_PARMS params = { 0 };
params.lpstrDeviceType = (LPCTSTR)thisClass::GetDeviceType(szDrive);
MCIERROR dwResult = this->SendCommand(MCI_OPEN, dwFlags, (DWORD_PTR)¶ms);
if (dwResult != 0)
{
return dwResult;
}
this->SetTimeFormat(MCI_FORMAT_TMSF);
m_nDeviceID = params.wDeviceID;
return dwResult;
}
public:
// トラック数の取得
MCIERROR GetTrackCount(DWORD_PTR& dwTrackCount)
{
// 初期化
dwTrackCount = 0;
DWORD_PTR dwFlags = MCI_STATUS_ITEM | MCI_WAIT;
MCI_STATUS_PARMS params = { 0 };
params.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
MCIERROR dwResult = this->SendCommand(MCI_STATUS, dwFlags, (DWORD_PTR)¶ms);
if (dwResult != 0)
{
return dwResult;
}
dwTrackCount = params.dwReturn;
return dwResult;
}
// トラックの種類の取得
DWORD GetTrackType(DWORD dwTrack, DWORD_PTR& dwTrackType)
{
// 初期化
dwTrackType = 0;
DWORD_PTR dwFlags = MCI_WAIT | MCI_STATUS_ITEM | MCI_TRACK;
MCI_STATUS_PARMS params = { 0 };
params.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
params.dwTrack = dwTrack;
MCIERROR dwResult = this->SendCommand(MCI_STATUS, dwFlags, (DWORD_PTR)¶ms);
if (dwResult != 0)
{
return dwResult;
}
dwTrackType = params.dwReturn;
return dwResult;
}
// トラックの開始位置の取得
DWORD GetTrackPosition(DWORD dwTrack, DWORD_PTR& dwTrackPosition)
{
// 初期化
dwTrackPosition = 0;
DWORD_PTR dwFlags = MCI_WAIT | MCI_STATUS_ITEM | MCI_TRACK;
MCI_STATUS_PARMS params = { 0 };
params.dwItem = MCI_STATUS_POSITION;
params.dwTrack = dwTrack;
MCIERROR dwResult = this->SendCommand(MCI_STATUS, dwFlags, (DWORD_PTR)¶ms);
if (dwResult != 0)
{
return dwResult;
}
dwTrackPosition = params.dwReturn;
return dwResult;
}
// トラック長の取得
DWORD GetTrackLength(DWORD dwTrack, DWORD_PTR& dwTrackLength)
{
// 初期化
dwTrackLength = 0;
DWORD_PTR dwFlags = MCI_WAIT | MCI_STATUS_ITEM | MCI_TRACK;
MCI_STATUS_PARMS params = { 0 };
params.dwItem = MCI_STATUS_LENGTH;
params.dwTrack = dwTrack;
MCIERROR dwResult = this->SendCommand(MCI_STATUS, dwFlags, (DWORD_PTR)¶ms);
if (dwResult != 0)
{
return dwResult;
}
dwTrackLength = params.dwReturn;
return dwResult;
}
protected:
static CString GetDeviceType(LPCTSTR szDrive)
{
CString strDeviceType;
if (szDrive == NULL)
{
strDeviceType = _T("cdaudio");
}
else
{
CString strDrive = thisClass::PathRemoveBackslash(szDrive); // SHLWAPI 4.71
strDeviceType.Format(_T("cdaudio!%s"), strDrive);
}
return strDeviceType;
}
protected:
// ShlwapiHelper.hよりコピー
static CString PathRemoveBackslash(CString strPath)
{
TCHAR szPath[_MAX_PATH] = { 0 };
#ifdef _SECURE_ATL
_tcscpy_s(szPath, strPath);
#else
_tcscpy(szPath, strPath);
#endif
::PathRemoveBackslash(szPath); // SHLWAPI 4.71
return szPath;
}
};
typedef CMciCDAudioT<CMciDevice> CMciCDAudio;