// AudioDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "By5000Asiplay Demo.h"
#include "AudioDlg.h"
#include ".\audiodlg.h"
#include "By5000asiplay.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAudioDlg 对话框

IMPLEMENT_DYNAMIC(CAudioDlg, CDialog)
CAudioDlg::CAudioDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAudioDlg::IDD, pParent)
	, m_uiCardNumber(0)
{
}

CAudioDlg::~CAudioDlg()
{
}

void CAudioDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MEDIA_AUDIO_VOLUMN, m_MediaAudioVolumn);
	DDX_Control(pDX, IDC_MEDIA_NEXT_FILE_AUDIO_VOLUMN, m_MediaNextFileAudioVolumn);
	DDX_Control(pDX, IDC_COMBO_AUDIO_CHANNEL, m_ComboAudioChannel);
	DDX_Control(pDX, IDC_COMBO_NEXT_FILE_AUDIO_CHANNEL, m_ComboNextFileAudioChannel);
}


BEGIN_MESSAGE_MAP(CAudioDlg, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_SET_MEDIA_AUDIO_VOLUMN, OnBnClickedButtonSetMediaAudioVolumn)
	ON_BN_CLICKED(IDC_BUTTON_SET_MEDIA_NEXT_FILE_AUDIO_VOLUMN, OnBnClickedButtonSetMediaNextFileAudioVolumn)
	ON_BN_CLICKED(IDC_BUTTON_MEDIA_AUDIO_AUTO_ADJUST,OnBnClickedButtonMediaAudioAutoAdjust)
	ON_BN_CLICKED(IDC_BUTTON_CAPTURE_AUDIO_AUTO_ADJUST, OnBnClickedButtonCaptureAudioAutoAdjust)
	ON_CBN_SELCHANGE(IDC_COMBO_AUDIO_CHANNEL, OnCbnSelchangeComboAudioChannel)
	ON_CBN_SELCHANGE(IDC_COMBO_NEXT_FILE_AUDIO_CHANNEL, OnCbnSelchangeComboNextFileAudioChannel)
	ON_CBN_SELCHANGE(IDC_COMBO_AUDIO_OUTPUT_MODE, OnCbnSelchangeComboAudioOutputMode)
	ON_CBN_SELCHANGE(IDC_COMBO_AUDIO_OUTPUT_SOURCE, OnCbnSelchangeComboAudioOutputSource)
END_MESSAGE_MAP()


// CAudioDlg 消息处理程序

void CAudioDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
//	OnOK();
}

BOOL CAudioDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here
	CString strItem;

	strItem = _T("立体声");
	m_ComboAudioChannel.AddString(strItem);
	m_ComboNextFileAudioChannel.AddString(strItem);
	strItem = _T("左声道");
	m_ComboAudioChannel.AddString(strItem);
	m_ComboNextFileAudioChannel.AddString(strItem);
	strItem = _T("右声道");
	m_ComboAudioChannel.AddString(strItem);
	m_ComboNextFileAudioChannel.AddString(strItem);
	strItem = _T("混合声道");
	m_ComboAudioChannel.AddString(strItem);
	m_ComboNextFileAudioChannel.AddString(strItem);
	m_ComboAudioChannel.SetCurSel(0);
	m_ComboNextFileAudioChannel.SetCurSel(0);

	m_MediaAudioVolumn.SetWindowText(_T("255"));
	m_MediaNextFileAudioVolumn.SetWindowText(_T("255"));

	m_bMediaAudioAutoAdjustEnabled = FALSE;
	m_bCapturedAudioAutoAdjustEnabled = FALSE;
	((CComboBox *)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_MODE))->AddString(_T("手动"));
	((CComboBox *)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_MODE))->AddString(_T("自动"));
	((CComboBox *)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_MODE))->SetCurSel(0);
	((CComboBox *)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_SOURCE))->AddString(_T("播放"));
	((CComboBox *)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_SOURCE))->AddString(_T("输入"));
	((CComboBox *)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_SOURCE))->SetCurSel(0);


	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CAudioDlg::OnBnClickedButtonSetMediaAudioVolumn()
{
	// TODO: Add your control notification handler code here
	CString str;
	m_MediaAudioVolumn.GetWindowText(str);
#ifdef _UNICODE
	swscanf_s(str,_T("%d"),&m_MediaAudioVolumn);

#else
	sscanf_s(str,_T("%d"),&m_uiMediaAudioVolumn);
#endif
	Seekfit_By5000asiplay_MediaSetAudioVolumn(m_uiMediaAudioVolumn, m_uiCardNumber);
}

void CAudioDlg::OnBnClickedButtonSetMediaNextFileAudioVolumn()
{
	// TODO: Add your control notification handler code here
	CString str;
	m_MediaNextFileAudioVolumn.GetWindowText(str);
#ifdef _UNICODE
	swscanf_s(str, _T("%d"), &m_MediaNextFileAudioVolumn);

#else
	sscanf_s(str, _T("%d"), &m_uiNextFileMediaAudioVolumn);
#endif
	Seekfit_By5000asiplay_MediaNextSetAudioVolumn(m_uiNextFileMediaAudioVolumn, m_uiCardNumber);
}

void CAudioDlg::OnBnClickedButtonMediaAudioAutoAdjust()
{
	// TODO: Add your control notification handler code here
	m_bMediaAudioAutoAdjustEnabled = !m_bMediaAudioAutoAdjustEnabled;

	if (m_bMediaAudioAutoAdjustEnabled)
		Seekfit_By5000asiplay_MediaEnableAudioVolumnAutoAdjust(m_uiCardNumber);
	else
		Seekfit_By5000asiplay_MediaDisableAudioVolumnAutoAdjust(m_uiCardNumber);

	if (m_bMediaAudioAutoAdjustEnabled)
		SetDlgItemText(IDC_BUTTON_MEDIA_AUDIO_AUTO_ADJUST, _T("禁止"));
	else
		SetDlgItemText(IDC_BUTTON_MEDIA_AUDIO_AUTO_ADJUST, _T("使能"));
}

void CAudioDlg::OnBnClickedButtonCaptureAudioAutoAdjust()
{
	// TODO: Add your control notification handler code here
	m_bCapturedAudioAutoAdjustEnabled = !m_bCapturedAudioAutoAdjustEnabled;

	if (m_bCapturedAudioAutoAdjustEnabled)
		Seekfit_By5000asiplay_CapturedStreamEnableAudioVolumnAutoAdjust(m_uiCardNumber);
	else
		Seekfit_By5000asiplay_CapturedStreamDisableAudioVolumnAutoAdjust(m_uiCardNumber);

	if (m_bCapturedAudioAutoAdjustEnabled)
		SetDlgItemText(IDC_BUTTON_CAPTURE_AUDIO_AUTO_ADJUST, _T("禁止"));
	else
		SetDlgItemText(IDC_BUTTON_CAPTURE_AUDIO_AUTO_ADJUST, _T("使能"));
}

void CAudioDlg::OnCbnSelchangeComboAudioChannel()
{
	// TODO: Add your control notification handler code here
	int iChannel;
	iChannel = m_ComboAudioChannel.GetCurSel();

	if (iChannel == 0)
		m_uiMediaAudioChannel = AUDIO_CHANNEL_STEREO;
	else if (iChannel == 1)
		m_uiMediaAudioChannel = AUDIO_CHANNEL_LEFT;
	else if (iChannel == 2)
		m_uiMediaAudioChannel = AUDIO_CHANNEL_RIGHT;
	else if (iChannel == 3)
		m_uiMediaAudioChannel = AUDIO_CHANNEL_BLEND;
	else
		m_uiMediaAudioChannel = AUDIO_CHANNEL_STEREO;

	Seekfit_By5000asiplay_MediaSetAudioChannel(m_uiMediaAudioChannel, m_uiCardNumber);
}

void CAudioDlg::OnCbnSelchangeComboNextFileAudioChannel()
{
	// TODO: Add your control notification handler code here
	int iChannel;
	iChannel = m_ComboNextFileAudioChannel.GetCurSel();

	if (iChannel == 0)
		m_uiNextFileMediaAudioChannel = AUDIO_CHANNEL_STEREO;
	else if (iChannel == 1)
		m_uiNextFileMediaAudioChannel = AUDIO_CHANNEL_LEFT;
	else if (iChannel == 2)
		m_uiNextFileMediaAudioChannel = AUDIO_CHANNEL_RIGHT;
	else if (iChannel == 3)
		m_uiNextFileMediaAudioChannel = AUDIO_CHANNEL_BLEND;
	else
		m_uiNextFileMediaAudioChannel = AUDIO_CHANNEL_STEREO;

	Seekfit_By5000asiplay_MediaNextSetAudioChannel(m_uiNextFileMediaAudioChannel, m_uiCardNumber);
}

void CAudioDlg::OnCbnSelchangeComboAudioOutputMode()
{
	// TODO: 在此添加控件通知处理程序代码
	INT nIndex1 = ((CComboBox*)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_MODE))->GetCurSel();
	INT nIndex2 = ((CComboBox*)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_SOURCE))->GetCurSel(); 
	UINT uiMode;
	UINT uiSource;
	if(nIndex1 == 1)//当为自动模式时,source可以不设;
	{
		uiMode = AUDIO_PLAYBACK_AUTO_MODE;

	}
	else if(nIndex1 == 0)
	{
		uiMode = AUDIO_PLAYBACK_MANUAL_MODE;
	}	
	if(nIndex2 == 1)
	{
		uiSource = AUDIO_PLAYBACK_CAPTURE_SOURCE;
	}
	else if(nIndex2 == 0)
	{
		uiSource = AUDIO_PLAYBACK_MEDIA_SOURCE;
	}
	Seekfit_By5000asiplay_SetAudioPlayBackMode(uiMode,uiSource);
}

void CAudioDlg::OnCbnSelchangeComboAudioOutputSource()
{
	// TODO: 在此添加控件通知处理程序代码
	INT nIndex1 = ((CComboBox*)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_MODE))->GetCurSel();
	INT nIndex2 = ((CComboBox*)GetDlgItem(IDC_COMBO_AUDIO_OUTPUT_SOURCE))->GetCurSel(); 
	UINT uiMode;
	UINT uiSource;
	if(nIndex1 == 1)//当为自动模式时,source可以不设;
	{
		uiMode = AUDIO_PLAYBACK_AUTO_MODE;
	}
	else if(nIndex1 == 0)
	{
		uiMode = AUDIO_PLAYBACK_MANUAL_MODE;
	}	
	if(nIndex2 == 1)
	{
		uiSource = AUDIO_PLAYBACK_CAPTURE_SOURCE;
	}
	else if(nIndex2 == 0)
	{
		uiSource = AUDIO_PLAYBACK_MEDIA_SOURCE;
	}
	Seekfit_By5000asiplay_SetAudioPlayBackMode(uiMode,uiSource);
}
