00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PPageAudioSwitcher.h"
00028
00029
00030
00031 IMPLEMENT_DYNAMIC(CPPageAudioSwitcher, CPPageBase)
00032 CPPageAudioSwitcher::CPPageAudioSwitcher(IFilterGraph* pFG)
00033 : CPPageBase(CPPageAudioSwitcher::IDD, CPPageAudioSwitcher::IDD)
00034 , m_fDownSampleTo441(FALSE)
00035 , m_fCustomChannelMapping(FALSE)
00036 , m_nChannels(0)
00037 , m_fEnableAudioSwitcher(FALSE)
00038 , m_dwChannelMask(0)
00039 , m_tAudioTimeShift(0)
00040 , m_fAudioTimeShift(FALSE)
00041 {
00042 m_pAudioSwitcher = FindFilter(__uuidof(CAudioSwitcherFilter), pFG);
00043 }
00044
00045 CPPageAudioSwitcher::~CPPageAudioSwitcher()
00046 {
00047 }
00048
00049 void CPPageAudioSwitcher::DoDataExchange(CDataExchange* pDX)
00050 {
00051 __super::DoDataExchange(pDX);
00052 DDX_Check(pDX, IDC_CHECK3, m_fDownSampleTo441);
00053 DDX_Check(pDX, IDC_CHECK1, m_fCustomChannelMapping);
00054 DDX_Control(pDX, IDC_EDIT1, m_nChannelsCtrl);
00055 DDX_Text(pDX, IDC_EDIT1, m_nChannels);
00056 DDX_Control(pDX, IDC_SPIN1, m_nChannelsSpinCtrl);
00057 DDX_Control(pDX, IDC_LIST1, m_list);
00058 DDX_Check(pDX, IDC_CHECK2, m_fEnableAudioSwitcher);
00059 DDX_Control(pDX, IDC_CHECK3, m_fDownSampleTo441Ctrl);
00060 DDX_Control(pDX, IDC_CHECK1, m_fCustomChannelMappingCtrl);
00061 DDX_Control(pDX, IDC_EDIT2, m_tAudioTimeShiftCtrl);
00062 DDX_Control(pDX, IDC_SPIN2, m_tAudioTimeShiftSpin);
00063 DDX_Text(pDX, IDC_EDIT2, m_tAudioTimeShift);
00064 DDX_Check(pDX, IDC_CHECK4, m_fAudioTimeShift);
00065 DDX_Control(pDX, IDC_CHECK4, m_fAudioTimeShiftCtrl);
00066 }
00067
00068 BEGIN_MESSAGE_MAP(CPPageAudioSwitcher, CPPageBase)
00069 ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
00070 ON_WM_DRAWITEM()
00071 ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
00072 ON_UPDATE_COMMAND_UI(IDC_CHECK3, OnUpdateAudioSwitcher)
00073 ON_UPDATE_COMMAND_UI(IDC_CHECK4, OnUpdateAudioSwitcher)
00074 ON_UPDATE_COMMAND_UI(IDC_EDIT2, OnUpdateAudioSwitcher)
00075 ON_UPDATE_COMMAND_UI(IDC_SPIN2, OnUpdateAudioSwitcher)
00076 ON_UPDATE_COMMAND_UI(IDC_CHECK1, OnUpdateAudioSwitcher)
00077 ON_UPDATE_COMMAND_UI(IDC_EDIT1, OnUpdateChannelMapping)
00078 ON_UPDATE_COMMAND_UI(IDC_SPIN1, OnUpdateChannelMapping)
00079 ON_UPDATE_COMMAND_UI(IDC_LIST1, OnUpdateChannelMapping)
00080 ON_UPDATE_COMMAND_UI(IDC_STATIC1, OnUpdateChannelMapping)
00081 ON_UPDATE_COMMAND_UI(IDC_STATIC2, OnUpdateChannelMapping)
00082 ON_UPDATE_COMMAND_UI(IDC_STATIC3, OnUpdateChannelMapping)
00083 END_MESSAGE_MAP()
00084
00085
00086
00087
00088 BOOL CPPageAudioSwitcher::OnInitDialog()
00089 {
00090 __super::OnInitDialog();
00091
00092 AppSettings& s = AfxGetAppSettings();
00093
00094 m_fEnableAudioSwitcher = s.fEnableAudioSwitcher;
00095 m_fDownSampleTo441 = s.fDownSampleTo441;
00096 m_fAudioTimeShift = s.fAudioTimeShift;
00097 m_tAudioTimeShift = s.tAudioTimeShift;
00098 m_tAudioTimeShiftSpin.SetRange32(-1000*60*60*24, 1000*60*60*24);
00099 m_fCustomChannelMapping = s.fCustomChannelMapping;
00100 memcpy(m_pSpeakerToChannelMap, s.pSpeakerToChannelMap, sizeof(s.pSpeakerToChannelMap));
00101
00102 if(m_pAudioSwitcher)
00103 m_pAudioSwitcher->GetInputSpeakerConfig(&m_dwChannelMask);
00104
00105 m_nChannels = 1;
00106 m_nChannelsSpinCtrl.SetRange(1, 18);
00107
00108 if(m_pAudioSwitcher)
00109 m_nChannels = m_pAudioSwitcher->GetNumberOfInputChannels();
00110
00111 m_list.InsertColumn(0, _T(""), LVCFMT_LEFT, 100);
00112 m_list.InsertItem(0, _T(""));
00113 m_list.InsertItem(1, _T("Front Left"));
00114 m_list.InsertItem(2, _T("Front Right"));
00115 m_list.InsertItem(3, _T("Front Center"));
00116 m_list.InsertItem(4, _T("Low Frequency"));
00117 m_list.InsertItem(5, _T("Back Left"));
00118 m_list.InsertItem(6, _T("Back Right"));
00119 m_list.InsertItem(7, _T("Front Left of Center"));
00120 m_list.InsertItem(8, _T("Front Right of Center"));
00121 m_list.InsertItem(9, _T("Back Center"));
00122 m_list.InsertItem(10, _T("Side Left"));
00123 m_list.InsertItem(11, _T("Side Right"));
00124 m_list.InsertItem(12, _T("Top Center"));
00125 m_list.InsertItem(13, _T("Top Front Left"));
00126 m_list.InsertItem(14, _T("Top Front Center"));
00127 m_list.InsertItem(15, _T("Top Front Right"));
00128 m_list.InsertItem(16, _T("Top Back Left"));
00129 m_list.InsertItem(17, _T("Top Back Center"));
00130 m_list.InsertItem(18, _T("Top Back Right"));
00131 m_list.SetColumnWidth(0, LVSCW_AUTOSIZE);
00132
00133 for(int i = 1; i <= 18; i++)
00134 {
00135 m_list.InsertColumn(i, _T(""), LVCFMT_CENTER, 16);
00136 CString n;
00137 n.Format(_T("%d"), i);
00138 m_list.SetItemText(0, i, n);
00139
00140
00141 }
00142
00143 UpdateData(FALSE);
00144
00145 return TRUE;
00146
00147 }
00148
00149 BOOL CPPageAudioSwitcher::OnApply()
00150 {
00151 UpdateData();
00152
00153 AppSettings& s = AfxGetAppSettings();
00154
00155 s.fEnableAudioSwitcher = !!m_fEnableAudioSwitcher;
00156 s.fDownSampleTo441 = !!m_fDownSampleTo441;
00157 s.fAudioTimeShift = !!m_fAudioTimeShift;
00158 s.tAudioTimeShift = m_tAudioTimeShift;
00159 s.fCustomChannelMapping = !!m_fCustomChannelMapping;
00160 memcpy(s.pSpeakerToChannelMap, m_pSpeakerToChannelMap, sizeof(m_pSpeakerToChannelMap));
00161
00162 if(m_pAudioSwitcher)
00163 {
00164 m_pAudioSwitcher->SetSpeakerConfig(s.fCustomChannelMapping, m_pSpeakerToChannelMap);
00165 m_pAudioSwitcher->EnableDownSamplingTo441(s.fDownSampleTo441);
00166 m_pAudioSwitcher->SetAudioTimeShift(m_fAudioTimeShift ? 10000i64*m_tAudioTimeShift : 0);
00167 }
00168
00169 return __super::OnApply();
00170 }
00171
00172 void CPPageAudioSwitcher::OnNMClickList1(NMHDR* pNMHDR, LRESULT* pResult)
00173 {
00174 LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
00175
00176 if(lpnmlv->iItem > 0 && lpnmlv->iSubItem > 0 && lpnmlv->iSubItem <= m_nChannels)
00177 {
00178 UpdateData();
00179 m_pSpeakerToChannelMap[m_nChannels-1][lpnmlv->iItem-1] ^= 1<<(lpnmlv->iSubItem-1);
00180 m_list.RedrawItems(lpnmlv->iItem, lpnmlv->iItem);
00181 SetModified();
00182
00183 if(GetKeyState(VK_SHIFT) & 0x8000)
00184 {
00185 OnApply();
00186 }
00187 }
00188
00189 *pResult = 0;
00190 }
00191
00192 void CPPageAudioSwitcher::OnEnChangeEdit1()
00193 {
00194 if(IsWindow(m_list.m_hWnd))
00195 {
00196 UpdateData();
00197 m_list.Invalidate();
00198 }
00199 }
00200
00201 #include <math.h>
00202
00203 void CPPageAudioSwitcher::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00204 {
00205 if(nIDCtl != IDC_LIST1) return;
00206
00207
00208
00209
00210 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
00211
00212 pDC->SetBkMode(TRANSPARENT);
00213
00214 CPen p(PS_INSIDEFRAME, 1, 0xe0e0e0);
00215 CPen* old = pDC->SelectObject(&p);
00216
00217 pDC->MoveTo(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom-1);
00218 pDC->LineTo(lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom-1);
00219
00220 CHeaderCtrl* pHeader = m_list.GetHeaderCtrl();
00221 int nColumnCount = pHeader->GetItemCount();
00222
00223 for(int i = 0; i < nColumnCount; i++)
00224 {
00225 CRect r, rb;
00226 m_list.GetSubItemRect(lpDrawItemStruct->itemID, i, LVIR_BOUNDS, rb);
00227 m_list.GetSubItemRect(lpDrawItemStruct->itemID, i, LVIR_LABEL, r);
00228
00229 pDC->MoveTo(r.right-1, r.top);
00230 pDC->LineTo(r.right-1, r.bottom-1);
00231
00232 CSize s = pDC->GetTextExtent(m_list.GetItemText(lpDrawItemStruct->itemID, i));
00233
00234 if(i == 0)
00235 {
00236 r.left = rb.left;
00237
00238 if(lpDrawItemStruct->itemID == 0)
00239 {
00240 pDC->MoveTo(0, 0);
00241 pDC->LineTo(r.right, r.bottom-1);
00242 }
00243 else
00244 {
00245 pDC->SetTextColor(m_list.IsWindowEnabled() ? 0 : 0xb0b0b0);
00246 pDC->TextOut(r.left+1, (r.top+r.bottom-s.cy)/2, m_list.GetItemText(lpDrawItemStruct->itemID, i));
00247 }
00248 }
00249 else
00250 {
00251 pDC->SetTextColor(i > m_nChannels ? 0xe0e0e0 : (!m_list.IsWindowEnabled() ? 0xb0b0b0 : 0));
00252
00253 if(lpDrawItemStruct->itemID == 0)
00254 {
00255 pDC->TextOut((r.left+r.right-s.cx)/2, (r.top+r.bottom-s.cy)/2, m_list.GetItemText(lpDrawItemStruct->itemID, i));
00256 }
00257 else
00258 {
00259 if(m_dwChannelMask & (1<<(lpDrawItemStruct->itemID-1)))
00260 {
00261 int nBitsSet = 0;
00262
00263 for(int j = 1; j <= (1<<(lpDrawItemStruct->itemID-1)); j <<= 1)
00264 {
00265 if(m_dwChannelMask & j)
00266 nBitsSet++;
00267 }
00268
00269 if(nBitsSet == i)
00270 {
00271 COLORREF tmp = pDC->GetTextColor();
00272
00273 pDC->SetTextColor(0xe0e0e0);
00274 CFont f;
00275 f.CreatePointFont(MulDiv(100, 96, pDC->GetDeviceCaps(LOGPIXELSX)), _T("Marlett"));
00276 CFont* old = pDC->SelectObject(&f);
00277 s = pDC->GetTextExtent(_T("g"));
00278 pDC->TextOut((r.left+r.right-s.cx)/2, (r.top+r.bottom-s.cy)/2, _T("g"));
00279
00280 pDC->SetTextColor(tmp);
00281 }
00282 }
00283
00284 if(m_pSpeakerToChannelMap[m_nChannels-1][lpDrawItemStruct->itemID-1] & (1<<(i-1)))
00285 {
00286 CFont f;
00287 f.CreatePointFont(MulDiv(100, 96, pDC->GetDeviceCaps(LOGPIXELSX)), _T("Marlett"));
00288 CFont* old = pDC->SelectObject(&f);
00289 s = pDC->GetTextExtent(_T("a"));
00290 pDC->TextOut((r.left+r.right-s.cx)/2, (r.top+r.bottom-s.cy)/2, _T("a"));
00291 pDC->SelectObject(old);
00292 }
00293 }
00294 }
00295 }
00296
00297 pDC->SelectObject(old);
00298 }
00299
00300 void CPPageAudioSwitcher::OnUpdateAudioSwitcher(CCmdUI* pCmdUI)
00301 {
00302
00303 pCmdUI->Enable(IsDlgButtonChecked(IDC_CHECK2));
00304 }
00305
00306 void CPPageAudioSwitcher::OnUpdateChannelMapping(CCmdUI* pCmdUI)
00307 {
00308
00309 pCmdUI->Enable(IsDlgButtonChecked(IDC_CHECK2)
00310 && IsDlgButtonChecked(IDC_CHECK1));
00311 }