Support unrar64.dll
[xy_vsfilter.git] / src / apps / mplayerc / PPageAudioSwitcher.cpp
blob65839a2c133f62dd50a1e7d8c11f7081b8b12db4
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PPageAudioSwitcher.cpp : implementation file
25 #include "stdafx.h"
26 #include <math.h>
27 #include "mplayerc.h"
28 #include "PPageAudioSwitcher.h"
30 // CPPageAudioSwitcher dialog
32 IMPLEMENT_DYNAMIC(CPPageAudioSwitcher, CPPageBase)
33 CPPageAudioSwitcher::CPPageAudioSwitcher(IFilterGraph* pFG)
34 : CPPageBase(CPPageAudioSwitcher::IDD, CPPageAudioSwitcher::IDD)
35 , m_fAudioNormalize(FALSE)
36 , m_fAudioNormalizeRecover(FALSE)
37 , m_fDownSampleTo441(FALSE)
38 , m_fCustomChannelMapping(FALSE)
39 , m_nChannels(0)
40 , m_fEnableAudioSwitcher(FALSE)
41 , m_dwChannelMask(0)
42 , m_tAudioTimeShift(0)
43 , m_fAudioTimeShift(FALSE)
44 , m_AudioBoost(0)
46 m_pASF = FindFilter(__uuidof(CAudioSwitcherFilter), pFG);
49 CPPageAudioSwitcher::~CPPageAudioSwitcher()
53 void CPPageAudioSwitcher::DoDataExchange(CDataExchange* pDX)
55 __super::DoDataExchange(pDX);
56 DDX_Check(pDX, IDC_CHECK5, m_fAudioNormalize);
57 DDX_Check(pDX, IDC_CHECK6, m_fAudioNormalizeRecover);
58 DDX_Slider(pDX, IDC_SLIDER1, m_AudioBoost);
59 DDX_Control(pDX, IDC_SLIDER1, m_AudioBoostCtrl);
60 DDX_Check(pDX, IDC_CHECK3, m_fDownSampleTo441);
61 DDX_Check(pDX, IDC_CHECK1, m_fCustomChannelMapping);
62 DDX_Control(pDX, IDC_EDIT1, m_nChannelsCtrl);
63 DDX_Text(pDX, IDC_EDIT1, m_nChannels);
64 DDX_Control(pDX, IDC_SPIN1, m_nChannelsSpinCtrl);
65 DDX_Control(pDX, IDC_LIST1, m_list);
66 DDX_Check(pDX, IDC_CHECK2, m_fEnableAudioSwitcher);
67 DDX_Control(pDX, IDC_CHECK3, m_fDownSampleTo441Ctrl);
68 DDX_Control(pDX, IDC_CHECK1, m_fCustomChannelMappingCtrl);
69 DDX_Control(pDX, IDC_EDIT2, m_tAudioTimeShiftCtrl);
70 DDX_Control(pDX, IDC_SPIN2, m_tAudioTimeShiftSpin);
71 DDX_Text(pDX, IDC_EDIT2, m_tAudioTimeShift);
72 DDX_Check(pDX, IDC_CHECK4, m_fAudioTimeShift);
73 DDX_Control(pDX, IDC_CHECK4, m_fAudioTimeShiftCtrl);
76 BEGIN_MESSAGE_MAP(CPPageAudioSwitcher, CPPageBase)
77 ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
78 ON_WM_DRAWITEM()
79 ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
80 ON_UPDATE_COMMAND_UI(IDC_SLIDER1, OnUpdateAudioSwitcher)
81 ON_UPDATE_COMMAND_UI(IDC_CHECK5, OnUpdateAudioSwitcher)
82 ON_UPDATE_COMMAND_UI(IDC_CHECK6, OnUpdateAudioSwitcher)
83 ON_UPDATE_COMMAND_UI(IDC_CHECK3, OnUpdateAudioSwitcher)
84 ON_UPDATE_COMMAND_UI(IDC_CHECK4, OnUpdateAudioSwitcher)
85 ON_UPDATE_COMMAND_UI(IDC_EDIT2, OnUpdateAudioSwitcher)
86 ON_UPDATE_COMMAND_UI(IDC_SPIN2, OnUpdateAudioSwitcher)
87 ON_UPDATE_COMMAND_UI(IDC_CHECK1, OnUpdateAudioSwitcher)
88 ON_UPDATE_COMMAND_UI(IDC_EDIT1, OnUpdateChannelMapping)
89 ON_UPDATE_COMMAND_UI(IDC_SPIN1, OnUpdateChannelMapping)
90 ON_UPDATE_COMMAND_UI(IDC_LIST1, OnUpdateChannelMapping)
91 ON_UPDATE_COMMAND_UI(IDC_STATIC1, OnUpdateChannelMapping)
92 ON_UPDATE_COMMAND_UI(IDC_STATIC2, OnUpdateChannelMapping)
93 ON_UPDATE_COMMAND_UI(IDC_STATIC3, OnUpdateChannelMapping)
94 ON_WM_HSCROLL()
95 END_MESSAGE_MAP()
98 // CPPageAudioSwitcher message handlers
100 BOOL CPPageAudioSwitcher::OnInitDialog()
102 __super::OnInitDialog();
104 AppSettings& s = AfxGetAppSettings();
106 m_fEnableAudioSwitcher = s.fEnableAudioSwitcher;
107 m_fAudioNormalize = s.fAudioNormalize;
108 m_fAudioNormalizeRecover = s.fAudioNormalizeRecover;
109 m_AudioBoost = (int)(50.0f*log10(s.AudioBoost));
110 m_AudioBoostCtrl.SetRange(0, 100);
111 m_fDownSampleTo441 = s.fDownSampleTo441;
112 m_fAudioTimeShift = s.fAudioTimeShift;
113 m_tAudioTimeShift = s.tAudioTimeShift;
114 m_tAudioTimeShiftSpin.SetRange32(-1000*60*60*24, 1000*60*60*24);
115 m_fCustomChannelMapping = s.fCustomChannelMapping;
116 memcpy(m_pSpeakerToChannelMap, s.pSpeakerToChannelMap, sizeof(s.pSpeakerToChannelMap));
118 if(m_pASF)
119 m_pASF->GetInputSpeakerConfig(&m_dwChannelMask);
121 m_nChannels = 1;
122 m_nChannelsSpinCtrl.SetRange(1, 18);
124 if(m_pASF)
125 m_nChannels = m_pASF->GetNumberOfInputChannels();
127 m_list.InsertColumn(0, _T(""), LVCFMT_LEFT, 100);
128 m_list.InsertItem(0, _T(""));
129 m_list.InsertItem(1, _T("Front Left"));
130 m_list.InsertItem(2, _T("Front Right"));
131 m_list.InsertItem(3, _T("Front Center"));
132 m_list.InsertItem(4, _T("Low Frequency"));
133 m_list.InsertItem(5, _T("Back Left"));
134 m_list.InsertItem(6, _T("Back Right"));
135 m_list.InsertItem(7, _T("Front Left of Center"));
136 m_list.InsertItem(8, _T("Front Right of Center"));
137 m_list.InsertItem(9, _T("Back Center"));
138 m_list.InsertItem(10, _T("Side Left"));
139 m_list.InsertItem(11, _T("Side Right"));
140 m_list.InsertItem(12, _T("Top Center"));
141 m_list.InsertItem(13, _T("Top Front Left"));
142 m_list.InsertItem(14, _T("Top Front Center"));
143 m_list.InsertItem(15, _T("Top Front Right"));
144 m_list.InsertItem(16, _T("Top Back Left"));
145 m_list.InsertItem(17, _T("Top Back Center"));
146 m_list.InsertItem(18, _T("Top Back Right"));
147 m_list.SetColumnWidth(0, LVSCW_AUTOSIZE);
149 for(int i = 1; i <= 18; i++)
151 m_list.InsertColumn(i, _T(""), LVCFMT_CENTER, 16);
152 CString n;
153 n.Format(_T("%d"), i);
154 m_list.SetItemText(0, i, n);
155 // m_list.SetColumnWidth(i, LVSCW_AUTOSIZE);
156 // m_list.SetColumnWidth(i, m_list.GetColumnWidth(i)*8/10);
159 UpdateData(FALSE);
161 return TRUE; // return TRUE unless you set the focus to a control
162 // EXCEPTION: OCX Property Pages should return FALSE
165 BOOL CPPageAudioSwitcher::OnApply()
167 UpdateData();
169 AppSettings& s = AfxGetAppSettings();
171 s.fEnableAudioSwitcher = !!m_fEnableAudioSwitcher;
172 s.fAudioNormalize = !!m_fAudioNormalize;
173 s.fAudioNormalizeRecover = !!m_fAudioNormalizeRecover;
174 s.AudioBoost = (float)pow(10.0, (double)m_AudioBoost/50);
175 s.fDownSampleTo441 = !!m_fDownSampleTo441;
176 s.fAudioTimeShift = !!m_fAudioTimeShift;
177 s.tAudioTimeShift = m_tAudioTimeShift;
178 s.fCustomChannelMapping = !!m_fCustomChannelMapping;
179 memcpy(s.pSpeakerToChannelMap, m_pSpeakerToChannelMap, sizeof(m_pSpeakerToChannelMap));
181 if(m_pASF)
183 m_pASF->SetSpeakerConfig(s.fCustomChannelMapping, s.pSpeakerToChannelMap);
184 m_pASF->EnableDownSamplingTo441(s.fDownSampleTo441);
185 m_pASF->SetAudioTimeShift(s.fAudioTimeShift ? 10000i64*s.tAudioTimeShift : 0);
186 m_pASF->SetNormalizeBoost(s.fAudioNormalize, s.fAudioNormalizeRecover, s.AudioBoost);
189 return __super::OnApply();
192 void CPPageAudioSwitcher::OnNMClickList1(NMHDR* pNMHDR, LRESULT* pResult)
194 LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
196 if(lpnmlv->iItem > 0 && lpnmlv->iSubItem > 0 && lpnmlv->iSubItem <= m_nChannels)
198 UpdateData();
199 m_pSpeakerToChannelMap[m_nChannels-1][lpnmlv->iItem-1] ^= 1<<(lpnmlv->iSubItem-1);
200 m_list.RedrawItems(lpnmlv->iItem, lpnmlv->iItem);
201 SetModified();
203 if(GetKeyState(VK_SHIFT) & 0x8000)
205 OnApply();
209 *pResult = 0;
212 void CPPageAudioSwitcher::OnEnChangeEdit1()
214 if(IsWindow(m_list.m_hWnd))
216 UpdateData();
217 m_list.Invalidate();
221 #include <math.h>
223 void CPPageAudioSwitcher::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
225 if(nIDCtl != IDC_LIST1) return;
227 // if(lpDrawItemStruct->itemID == 0)
228 // UpdateData();
230 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
232 pDC->SetBkMode(TRANSPARENT);
234 CPen p(PS_INSIDEFRAME, 1, 0xe0e0e0);
235 CPen* old = pDC->SelectObject(&p);
237 pDC->MoveTo(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom-1);
238 pDC->LineTo(lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom-1);
240 CHeaderCtrl* pHeader = m_list.GetHeaderCtrl();
241 int nColumnCount = pHeader->GetItemCount();
243 for(int i = 0; i < nColumnCount; i++)
245 CRect r, rb;
246 m_list.GetSubItemRect(lpDrawItemStruct->itemID, i, LVIR_BOUNDS, rb);
247 m_list.GetSubItemRect(lpDrawItemStruct->itemID, i, LVIR_LABEL, r);
249 pDC->MoveTo(r.right-1, r.top);
250 pDC->LineTo(r.right-1, r.bottom-1);
252 CSize s = pDC->GetTextExtent(m_list.GetItemText(lpDrawItemStruct->itemID, i));
254 if(i == 0)
256 r.left = rb.left;
258 if(lpDrawItemStruct->itemID == 0)
260 pDC->MoveTo(0, 0);
261 pDC->LineTo(r.right, r.bottom-1);
263 else
265 pDC->SetTextColor(m_list.IsWindowEnabled() ? 0 : 0xb0b0b0);
266 pDC->TextOut(r.left+1, (r.top+r.bottom-s.cy)/2, m_list.GetItemText(lpDrawItemStruct->itemID, i));
269 else
271 pDC->SetTextColor(i > m_nChannels ? 0xe0e0e0 : (!m_list.IsWindowEnabled() ? 0xb0b0b0 : 0));
273 if(lpDrawItemStruct->itemID == 0)
275 pDC->TextOut((r.left+r.right-s.cx)/2, (r.top+r.bottom-s.cy)/2, m_list.GetItemText(lpDrawItemStruct->itemID, i));
277 else
279 if(m_dwChannelMask & (1<<(lpDrawItemStruct->itemID-1)))
281 int nBitsSet = 0;
283 for(int j = 1; j <= (1<<(lpDrawItemStruct->itemID-1)); j <<= 1)
285 if(m_dwChannelMask & j)
286 nBitsSet++;
289 if(nBitsSet == i)
291 COLORREF tmp = pDC->GetTextColor();
293 pDC->SetTextColor(0xe0e0e0);
294 CFont f;
295 f.CreatePointFont(MulDiv(100, 96, pDC->GetDeviceCaps(LOGPIXELSX)), _T("Marlett"));
296 CFont* old = pDC->SelectObject(&f);
297 s = pDC->GetTextExtent(_T("g"));
298 pDC->TextOut((r.left+r.right-s.cx)/2, (r.top+r.bottom-s.cy)/2, _T("g"));
300 pDC->SetTextColor(tmp);
304 if(m_pSpeakerToChannelMap[m_nChannels-1][lpDrawItemStruct->itemID-1] & (1<<(i-1)))
306 CFont f;
307 f.CreatePointFont(MulDiv(100, 96, pDC->GetDeviceCaps(LOGPIXELSX)), _T("Marlett"));
308 CFont* old = pDC->SelectObject(&f);
309 s = pDC->GetTextExtent(_T("a"));
310 pDC->TextOut((r.left+r.right-s.cx)/2, (r.top+r.bottom-s.cy)/2, _T("a"));
311 pDC->SelectObject(old);
317 pDC->SelectObject(old);
320 void CPPageAudioSwitcher::OnUpdateAudioSwitcher(CCmdUI* pCmdUI)
322 // UpdateData();
323 pCmdUI->Enable(IsDlgButtonChecked(IDC_CHECK2)/*m_fEnableAudioSwitcher*/);
326 void CPPageAudioSwitcher::OnUpdateChannelMapping(CCmdUI* pCmdUI)
328 // UpdateData();
329 pCmdUI->Enable(IsDlgButtonChecked(IDC_CHECK2)/*m_fEnableAudioSwitcher*/
330 && IsDlgButtonChecked(IDC_CHECK1)/*m_fCustomChannelMapping*/);
333 void CPPageAudioSwitcher::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
335 SetModified();
337 __super::OnHScroll(nSBCode, nPos, pScrollBar);