PropPage_adv.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * LAME MP3 encoder for DirectShow
  3. * Advanced property page
  4. *
  5. * Copyright (c) 2000-2005 Marie Orlova, Peter Gubanov, Vitaly Ivanov, Elecard Ltd.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #include <streams.h>
  23. #include <olectl.h>
  24. #include <commctrl.h>
  25. #include "iaudioprops.h"
  26. #include "mpegac.h"
  27. #include "resource.h"
  28. #include "PropPage_adv.h"
  29. #include "Reg.h"
  30. #define MPG_MD_STEREO 0
  31. #define MPG_MD_JOINT_STEREO 1
  32. #define MPG_MD_DUAL_CHANNEL 2
  33. #define MPG_MD_MONO 3
  34. // Strings which apear in comboboxes
  35. const char *chChMode[4] = {
  36. "Mono",
  37. "Standard stereo",
  38. "Joint stereo",
  39. "Dual channel"};
  40. ////////////////////////////////////////////////////////////////
  41. // CreateInstance
  42. ////////////////////////////////////////////////////////////////
  43. CUnknown *CMpegAudEncPropertyPageAdv::CreateInstance( LPUNKNOWN punk, HRESULT *phr )
  44. {
  45. CMpegAudEncPropertyPageAdv *pNewObject
  46. = new CMpegAudEncPropertyPageAdv( punk, phr );
  47. if( pNewObject == NULL )
  48. *phr = E_OUTOFMEMORY;
  49. return pNewObject;
  50. }
  51. ////////////////////////////////////////////////////////////////
  52. // Constructor
  53. ////////////////////////////////////////////////////////////////
  54. CMpegAudEncPropertyPageAdv::CMpegAudEncPropertyPageAdv(LPUNKNOWN punk, HRESULT *phr) :
  55. CBasePropertyPage(NAME("Encoder Advanced Property Page"), punk, IDD_ADVPROPS, IDS_AUDIO_ADVANCED_TITLE),
  56. m_pAEProps(NULL)
  57. {
  58. ASSERT(phr);
  59. InitCommonControls();
  60. }
  61. //
  62. // OnConnect
  63. //
  64. // Give us the filter to communicate with
  65. HRESULT CMpegAudEncPropertyPageAdv::OnConnect(IUnknown *pUnknown)
  66. {
  67. ASSERT(m_pAEProps == NULL);
  68. // Ask the filter for it's control interface
  69. HRESULT hr = pUnknown->QueryInterface(IID_IAudioEncoderProperties,(void **)&m_pAEProps);
  70. if (FAILED(hr) || !m_pAEProps)
  71. return E_NOINTERFACE;
  72. ASSERT(m_pAEProps);
  73. // Get current filter state
  74. // m_pAEProps->LoadAudioEncoderPropertiesFromRegistry();
  75. m_pAEProps->get_EnforceVBRmin(&m_dwEnforceVBRmin);
  76. m_pAEProps->get_VoiceMode(&m_dwVoiceMode);
  77. m_pAEProps->get_KeepAllFreq(&m_dwKeepAllFreq);
  78. m_pAEProps->get_StrictISO(&m_dwStrictISO);
  79. m_pAEProps->get_NoShortBlock(&m_dwNoShortBlock);
  80. m_pAEProps->get_XingTag(&m_dwXingTag);
  81. m_pAEProps->get_ChannelMode(&m_dwChannelMode);
  82. m_pAEProps->get_ForceMS(&m_dwForceMS);
  83. m_pAEProps->get_ModeFixed(&m_dwModeFixed);
  84. m_pAEProps->get_SampleOverlap(&m_dwOverlap);
  85. m_pAEProps->get_SetDuration(&m_dwSetStop);
  86. return NOERROR;
  87. }
  88. //
  89. // OnDisconnect
  90. //
  91. // Release the interface
  92. HRESULT CMpegAudEncPropertyPageAdv::OnDisconnect()
  93. {
  94. // Release the interface
  95. if (m_pAEProps == NULL)
  96. return E_UNEXPECTED;
  97. m_pAEProps->set_EnforceVBRmin(m_dwEnforceVBRmin);
  98. m_pAEProps->set_VoiceMode(m_dwVoiceMode);
  99. m_pAEProps->set_KeepAllFreq(m_dwKeepAllFreq);
  100. m_pAEProps->set_StrictISO(m_dwStrictISO);
  101. m_pAEProps->set_NoShortBlock(m_dwNoShortBlock);
  102. m_pAEProps->set_XingTag(m_dwXingTag);
  103. m_pAEProps->set_ChannelMode(m_dwChannelMode);
  104. m_pAEProps->set_ForceMS(m_dwForceMS);
  105. m_pAEProps->set_ModeFixed(m_dwModeFixed);
  106. m_pAEProps->set_SampleOverlap(m_dwOverlap);
  107. m_pAEProps->set_SetDuration(m_dwSetStop);
  108. m_pAEProps->SaveAudioEncoderPropertiesToRegistry();
  109. m_pAEProps->Release();
  110. m_pAEProps = NULL;
  111. return NOERROR;
  112. }
  113. //
  114. // OnActivate
  115. //
  116. // Called on dialog creation
  117. HRESULT CMpegAudEncPropertyPageAdv::OnActivate(void)
  118. {
  119. InitPropertiesDialog(m_hwnd);
  120. return NOERROR;
  121. }
  122. //
  123. // OnDeactivate
  124. //
  125. // Called on dialog destruction
  126. HRESULT CMpegAudEncPropertyPageAdv::OnDeactivate(void)
  127. {
  128. return NOERROR;
  129. }
  130. ////////////////////////////////////////////////////////////////
  131. // OnReceiveMessage - message handler function
  132. ////////////////////////////////////////////////////////////////
  133. BOOL CMpegAudEncPropertyPageAdv::OnReceiveMessage(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  134. {
  135. switch (uMsg)
  136. {
  137. case WM_COMMAND:
  138. switch (LOWORD(wParam))
  139. {
  140. case IDC_RADIO_STEREO:
  141. case IDC_RADIO_JSTEREO:
  142. case IDC_RADIO_DUAL:
  143. case IDC_RADIO_MONO:
  144. {
  145. DWORD dwChannelMode = LOWORD(wParam) - IDC_RADIO_STEREO;
  146. CheckRadioButton(hwnd, IDC_RADIO_STEREO, IDC_RADIO_MONO, LOWORD(wParam));
  147. if (dwChannelMode == MPG_MD_JOINT_STEREO)
  148. EnableWindow(GetDlgItem(hwnd,IDC_CHECK_FORCE_MS),TRUE);
  149. else
  150. EnableWindow(GetDlgItem(hwnd,IDC_CHECK_FORCE_MS),FALSE);
  151. m_pAEProps->set_ChannelMode(dwChannelMode);
  152. SetDirty();
  153. }
  154. break;
  155. case IDC_CHECK_ENFORCE_MIN:
  156. m_pAEProps->set_EnforceVBRmin(IsDlgButtonChecked(hwnd, IDC_CHECK_ENFORCE_MIN));
  157. SetDirty();
  158. break;
  159. case IDC_CHECK_VOICE:
  160. m_pAEProps->set_VoiceMode(IsDlgButtonChecked(hwnd, IDC_CHECK_VOICE));
  161. SetDirty();
  162. break;
  163. case IDC_CHECK_KEEP_ALL_FREQ:
  164. m_pAEProps->set_KeepAllFreq(IsDlgButtonChecked(hwnd, IDC_CHECK_KEEP_ALL_FREQ));
  165. SetDirty();
  166. break;
  167. case IDC_CHECK_STRICT_ISO:
  168. m_pAEProps->set_StrictISO(IsDlgButtonChecked(hwnd, IDC_CHECK_STRICT_ISO));
  169. SetDirty();
  170. break;
  171. case IDC_CHECK_DISABLE_SHORT_BLOCK:
  172. m_pAEProps->set_NoShortBlock(IsDlgButtonChecked(hwnd, IDC_CHECK_DISABLE_SHORT_BLOCK));
  173. SetDirty();
  174. break;
  175. case IDC_CHECK_XING_TAG:
  176. m_pAEProps->set_XingTag(IsDlgButtonChecked(hwnd, IDC_CHECK_XING_TAG));
  177. SetDirty();
  178. break;
  179. case IDC_CHECK_FORCE_MS:
  180. m_pAEProps->set_ForceMS(IsDlgButtonChecked(hwnd, IDC_CHECK_FORCE_MS));
  181. SetDirty();
  182. break;
  183. case IDC_CHECK_MODE_FIXED:
  184. m_pAEProps->set_ModeFixed(IsDlgButtonChecked(hwnd, IDC_CHECK_MODE_FIXED));
  185. SetDirty();
  186. break;
  187. case IDC_CHECK_OVERLAP:
  188. m_pAEProps->set_SampleOverlap(IsDlgButtonChecked(hwnd, IDC_CHECK_OVERLAP));
  189. SetDirty();
  190. break;
  191. case IDC_CHECK_STOP:
  192. m_pAEProps->set_SetDuration(IsDlgButtonChecked(hwnd, IDC_CHECK_STOP));
  193. SetDirty();
  194. break;
  195. }
  196. return TRUE;
  197. case WM_DESTROY:
  198. return TRUE;
  199. default:
  200. return FALSE;
  201. }
  202. return TRUE;
  203. }
  204. //
  205. // OnApplyChanges
  206. //
  207. HRESULT CMpegAudEncPropertyPageAdv::OnApplyChanges()
  208. {
  209. m_pAEProps->get_EnforceVBRmin(&m_dwEnforceVBRmin);
  210. m_pAEProps->get_VoiceMode(&m_dwVoiceMode);
  211. m_pAEProps->get_KeepAllFreq(&m_dwKeepAllFreq);
  212. m_pAEProps->get_StrictISO(&m_dwStrictISO);
  213. m_pAEProps->get_ChannelMode(&m_dwChannelMode);
  214. m_pAEProps->get_ForceMS(&m_dwForceMS);
  215. m_pAEProps->get_NoShortBlock(&m_dwNoShortBlock);
  216. m_pAEProps->get_XingTag(&m_dwXingTag);
  217. m_pAEProps->get_ModeFixed(&m_dwModeFixed);
  218. m_pAEProps->get_SampleOverlap(&m_dwOverlap);
  219. m_pAEProps->get_SetDuration(&m_dwSetStop);
  220. m_pAEProps->SaveAudioEncoderPropertiesToRegistry();
  221. m_pAEProps->ApplyChanges();
  222. return S_OK;
  223. }
  224. //
  225. // Initialize dialogbox controls with proper values
  226. //
  227. void CMpegAudEncPropertyPageAdv::InitPropertiesDialog(HWND hwndParent)
  228. {
  229. EnableControls(hwndParent, TRUE);
  230. //
  231. // initialize radio bottons
  232. //
  233. DWORD dwChannelMode;
  234. m_pAEProps->get_ChannelMode(&dwChannelMode);
  235. CheckRadioButton(hwndParent, IDC_RADIO_STEREO, IDC_RADIO_MONO, IDC_RADIO_STEREO + dwChannelMode);
  236. if (dwChannelMode == MPG_MD_JOINT_STEREO)
  237. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_FORCE_MS), TRUE);
  238. else
  239. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_FORCE_MS), FALSE);
  240. //
  241. // initialize checkboxes
  242. //
  243. DWORD dwEnforceVBRmin;
  244. m_pAEProps->get_EnforceVBRmin(&dwEnforceVBRmin);
  245. CheckDlgButton(hwndParent, IDC_CHECK_ENFORCE_MIN, dwEnforceVBRmin ? BST_CHECKED : BST_UNCHECKED);
  246. DWORD dwVoiceMode;
  247. m_pAEProps->get_VoiceMode(&dwVoiceMode);
  248. CheckDlgButton(hwndParent, IDC_CHECK_VOICE, dwVoiceMode ? BST_CHECKED : BST_UNCHECKED);
  249. DWORD dwKeepAllFreq;
  250. m_pAEProps->get_KeepAllFreq(&dwKeepAllFreq);
  251. CheckDlgButton(hwndParent, IDC_CHECK_KEEP_ALL_FREQ, dwKeepAllFreq ? BST_CHECKED : BST_UNCHECKED);
  252. DWORD dwStrictISO;
  253. m_pAEProps->get_StrictISO(&dwStrictISO);
  254. CheckDlgButton(hwndParent, IDC_CHECK_STRICT_ISO, dwStrictISO ? BST_CHECKED : BST_UNCHECKED);
  255. DWORD dwNoShortBlock;
  256. m_pAEProps->get_NoShortBlock(&dwNoShortBlock);
  257. CheckDlgButton(hwndParent, IDC_CHECK_DISABLE_SHORT_BLOCK, dwNoShortBlock ? BST_CHECKED : BST_UNCHECKED);
  258. DWORD dwXingEnabled;
  259. m_pAEProps->get_XingTag(&dwXingEnabled);
  260. CheckDlgButton(hwndParent, IDC_CHECK_XING_TAG, dwXingEnabled ? BST_CHECKED : BST_UNCHECKED);
  261. DWORD dwForceMS;
  262. m_pAEProps->get_ForceMS(&dwForceMS);
  263. CheckDlgButton(hwndParent, IDC_CHECK_FORCE_MS, dwForceMS ? BST_CHECKED : BST_UNCHECKED);
  264. DWORD dwModeFixed;
  265. m_pAEProps->get_ModeFixed(&dwModeFixed);
  266. CheckDlgButton(hwndParent, IDC_CHECK_MODE_FIXED, dwModeFixed ? BST_CHECKED : BST_UNCHECKED);
  267. DWORD dwOverlap;
  268. m_pAEProps->get_SampleOverlap(&dwOverlap);
  269. CheckDlgButton(hwndParent, IDC_CHECK_OVERLAP, dwOverlap ? BST_CHECKED : BST_UNCHECKED);
  270. DWORD dwStopTime;
  271. m_pAEProps->get_SetDuration(&dwStopTime);
  272. CheckDlgButton(hwndParent, IDC_CHECK_STOP, dwStopTime ? BST_CHECKED : BST_UNCHECKED);
  273. }
  274. ////////////////////////////////////////////////////////////////
  275. // EnableControls
  276. ////////////////////////////////////////////////////////////////
  277. void CMpegAudEncPropertyPageAdv::EnableControls(HWND hwndParent, bool bEnable)
  278. {
  279. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_ENFORCE_MIN), bEnable);
  280. EnableWindow(GetDlgItem(hwndParent, IDC_RADIO_STEREO), bEnable);
  281. EnableWindow(GetDlgItem(hwndParent, IDC_RADIO_JSTEREO), bEnable);
  282. EnableWindow(GetDlgItem(hwndParent, IDC_RADIO_DUAL), bEnable);
  283. EnableWindow(GetDlgItem(hwndParent, IDC_RADIO_MONO), bEnable);
  284. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_FORCE_MS), bEnable);
  285. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_VOICE), bEnable);
  286. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_KEEP_ALL_FREQ), bEnable);
  287. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_STRICT_ISO), bEnable);
  288. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_DISABLE_SHORT_BLOCK), bEnable);
  289. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_XING_TAG), bEnable);
  290. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_MODE_FIXED), bEnable);
  291. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_OVERLAP), bEnable);
  292. EnableWindow(GetDlgItem(hwndParent, IDC_CHECK_STOP), bEnable);
  293. }
  294. //
  295. // SetDirty
  296. //
  297. // notifies the property page site of changes
  298. void CMpegAudEncPropertyPageAdv::SetDirty()
  299. {
  300. m_bDirty = TRUE;
  301. if (m_pPageSite)
  302. m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  303. }