Newer
Older
monitord / lame-3.97 / ACM / .svn / text-base / AEncodeProperties.cpp.svn-base
@root root on 23 Jan 2012 57 KB Migration from SVN revision 455
  1. /**
  2. *
  3. * Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows
  4. *
  5. * Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 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. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. /*!
  23. \author Steve Lhomme
  24. \version \$Id: AEncodeProperties.cpp,v 1.8 2002/04/08 18:43:30 robux4 Exp $
  25. */
  26.  
  27. #if !defined(STRICT)
  28. #define STRICT
  29. #endif // !defined(STRICT)
  30.  
  31. #include <windows.h>
  32. #include <windowsx.h>
  33. #include <shlobj.h>
  34. #include <assert.h>
  35.  
  36. #ifdef _MSC_VER
  37. // no problem with unknown pragmas
  38. #pragma warning(disable: 4068)
  39. #endif
  40.  
  41. #include "resource.h"
  42. #include <config.h>
  43. #include "util.h"
  44. #include "adebug.h"
  45. #include "AEncodeProperties.h"
  46. #include "ACM.h"
  47. //#include "AParameters/AParameters.h"
  48.  
  49. #ifndef TTS_BALLOON
  50. #define TTS_BALLOON 0x40
  51. #endif // TTS_BALLOON
  52.  
  53. const unsigned int AEncodeProperties::the_Bitrates[18] = {320, 256, 224, 192, 160, 144, 128, 112, 96, 80, 64, 56, 48, 40, 32, 24, 16, 8 };
  54. const unsigned int AEncodeProperties::the_MPEG1_Bitrates[14] = {320, 256, 224, 192, 160, 128, 112, 96, 80, 64, 56, 48, 40, 32 };
  55. const unsigned int AEncodeProperties::the_MPEG2_Bitrates[14] = {160, 144, 128, 112, 96, 80, 64, 56, 48, 40, 32, 24, 16, 8};
  56. const unsigned int AEncodeProperties::the_ChannelModes[3] = { STEREO, JOINT_STEREO, DUAL_CHANNEL };
  57. //const char AEncodeProperties::the_Presets[][13] = {"None", "CD", "Studio", "Hi-Fi", "Phone", "Voice", "Radio", "Tape", "FM", "AM", "SW"};
  58. //const LAME_QUALTIY_PRESET AEncodeProperties::the_Presets[] = {LQP_NOPRESET, LQP_R3MIX_QUALITY, LQP_NORMAL_QUALITY, LQP_LOW_QUALITY, LQP_HIGH_QUALITY, LQP_VERYHIGH_QUALITY, LQP_VOICE_QUALITY, LQP_PHONE, LQP_SW, LQP_AM, LQP_FM, LQP_VOICE, LQP_RADIO, LQP_TAPE, LQP_HIFI, LQP_CD, LQP_STUDIO};
  59. //const unsigned int AEncodeProperties::the_SamplingFreqs[9] = { 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000 };
  60.  
  61. ToolTipItem AEncodeProperties::Tooltips[13]={
  62. { IDC_CHECK_ENC_ABR, "Allow encoding with an average bitrate\r\ninstead of a constant one.\r\n\r\nIt can improve the quality for the same bitrate." },
  63. { IDC_CHECK_COPYRIGHT, "Mark the encoded data as copyrighted." },
  64. { IDC_CHECK_CHECKSUM, "Put a checksum in the encoded data.\r\n\r\nThis can make the file less sensitive to data loss." },
  65. { IDC_CHECK_ORIGINAL, "Mark the encoded data as an original file." },
  66. { IDC_CHECK_PRIVATE, "Mark the encoded data as private." },
  67. { IDC_COMBO_ENC_STEREO, "Select the type of stereo mode used for encoding:\r\n\r\n- Stereo : the usual one\r\n- Joint-Stereo : mix both channel to achieve better compression\r\n- Dual Channel : treat both channel as separate" },
  68. { IDC_STATIC_DECODING, "Decoding not supported for the moment by the codec." },
  69. { IDC_CHECK_ENC_SMART, "Disable bitrate when there is too much compression.\r\n(default 1:15 ratio)" },
  70. { IDC_STATIC_CONFIG_VERSION, "Version of this codec.\r\n\r\nvX.X.X is the version of the codec interface.\r\nX.XX is the version of the encoding engine." },
  71. { IDC_SLIDER_AVERAGE_MIN, "Select the minimum Average Bitrate allowed." },
  72. { IDC_SLIDER_AVERAGE_MAX, "Select the maximum Average Bitrate allowed." },
  73. { IDC_SLIDER_AVERAGE_STEP, "Select the step of Average Bitrate between the min and max.\r\n\r\nA step of 5 between 152 and 165 means you have :\r\n165, 160 and 155" },
  74. { IDC_SLIDER_AVERAGE_SAMPLE, "Check the resulting values of the (min,max,step) combination.\r\n\r\nUse the keyboard to navigate (right -> left)." },
  75. };
  76. //int AEncodeProperties::tst = 0;
  77.  
  78. /*
  79. #pragma argsused
  80. static UINT CALLBACK DLLFindCallback(
  81. HWND hdlg, // handle to child dialog box
  82. UINT uiMsg, // message identifier
  83. WPARAM wParam, // message parameter
  84. LPARAM lParam // message parameter
  85. )
  86. {
  87. UINT result = 0;
  88.  
  89. switch (uiMsg)
  90. {
  91. case WM_NOTIFY:
  92. OFNOTIFY * info = (OFNOTIFY *)lParam;
  93. if (info->hdr.code == CDN_FILEOK)
  94. {
  95. result = 1; // by default we don't accept the file
  96.  
  97. // Check if the selected file is a valid DLL with all the required functions
  98. ALameDLL * tstFile = new ALameDLL;
  99. if (tstFile != NULL)
  100. {
  101. if (tstFile->Load(info->lpOFN->lpstrFile))
  102. {
  103. result = 0;
  104. }
  105.  
  106. delete tstFile;
  107. }
  108.  
  109. if (result == 1)
  110. {
  111. TCHAR output[250];
  112. ::LoadString(AOut::GetInstance(),IDS_STRING_DLL_UNRECOGNIZED,output,250);
  113. AOut::MyMessageBox( output, MB_OK|MB_ICONEXCLAMATION, hdlg);
  114. SetWindowLong(hdlg, DWL_MSGRESULT , -100);
  115. }
  116. }
  117. }
  118.  
  119. return result;
  120. }
  121.  
  122. #pragma argsused
  123. static int CALLBACK BrowseFolderCallbackroc(
  124. HWND hwnd,
  125. UINT uMsg,
  126. LPARAM lParam,
  127. LPARAM lpData
  128. )
  129. {
  130. AEncodeProperties * the_prop;
  131. the_prop = (AEncodeProperties *) lpData;
  132.  
  133.  
  134. if (uMsg == BFFM_INITIALIZED)
  135. {
  136. // char FolderName[MAX_PATH];
  137. // SHGetPathFromIDList((LPITEMIDLIST) lParam,FolderName);
  138. //ADbg tst;
  139. //tst.OutPut("init folder to %s ",the_prop->GetOutputDirectory());
  140. // CreateFile();
  141. ::SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)the_prop->GetOutputDirectory());
  142. }/* else if (uMsg == BFFM_SELCHANGED)
  143. {
  144. // verify that the folder is writable
  145. // ::SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM)0); // disable
  146. char FolderName[MAX_PATH];
  147. SHGetPathFromIDList((LPITEMIDLIST) lParam, FolderName);
  148. // if (CreateFile(FolderName,STANDARD_RIGHTS_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL) == INVALID_HANDLE_VALUE)
  149. if ((GetFileAttributes(FolderName) & FILE_ATTRIBUTE_DIRECTORY) != 0)
  150. ::SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM)1); // enable
  151. else
  152. ::SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM)0); // disable
  153. //ADbg tst;
  154. //tst.OutPut("change folder to %s ",FolderName);
  155. }* /
  156.  
  157. return 0;
  158. }
  159. */
  160. #pragma argsused
  161. static BOOL CALLBACK ConfigProc(
  162. HWND hwndDlg, // handle to dialog box
  163. UINT uMsg, // message
  164. WPARAM wParam, // first message parameter
  165. LPARAM lParam // second message parameter
  166. )
  167. {
  168. BOOL bResult;
  169. AEncodeProperties * the_prop;
  170. the_prop = (AEncodeProperties *) GetProp(hwndDlg, "AEncodeProperties-Config");
  171.  
  172. switch (uMsg) {
  173. case WM_COMMAND:
  174. if (the_prop != NULL)
  175. {
  176. bResult = the_prop->HandleDialogCommand( hwndDlg, wParam, lParam);
  177. }
  178. break;
  179. case WM_INITDIALOG:
  180. assert(the_prop == NULL);
  181.  
  182. the_prop = (AEncodeProperties *) lParam;
  183. the_prop->my_debug.OutPut("there hwnd = 0x%08X",hwndDlg);
  184.  
  185. assert(the_prop != NULL);
  186.  
  187. SetProp(hwndDlg, "AEncodeProperties-Config", the_prop);
  188.  
  189. the_prop->InitConfigDlg(hwndDlg);
  190.  
  191. bResult = TRUE;
  192. break;
  193.  
  194. case WM_HSCROLL:
  195. // check if it's the ABR sliders
  196. if ((HWND)lParam == GetDlgItem(hwndDlg,IDC_SLIDER_AVERAGE_MIN))
  197. {
  198. the_prop->UpdateDlgFromSlides(hwndDlg);
  199. }
  200. else if ((HWND)lParam == GetDlgItem(hwndDlg,IDC_SLIDER_AVERAGE_MAX))
  201. {
  202. the_prop->UpdateDlgFromSlides(hwndDlg);
  203. }
  204. else if ((HWND)lParam == GetDlgItem(hwndDlg,IDC_SLIDER_AVERAGE_STEP))
  205. {
  206. the_prop->UpdateDlgFromSlides(hwndDlg);
  207. }
  208. else if ((HWND)lParam == GetDlgItem(hwndDlg,IDC_SLIDER_AVERAGE_SAMPLE))
  209. {
  210. the_prop->UpdateDlgFromSlides(hwndDlg);
  211. }
  212. break;
  213.  
  214. case WM_NOTIFY:
  215. if (TTN_GETDISPINFO == ((LPNMHDR)lParam)->code) {
  216. NMTTDISPINFO *lphdr = (NMTTDISPINFO *)lParam;
  217. UINT id = (lphdr->uFlags & TTF_IDISHWND) ? GetWindowLong((HWND)lphdr->hdr.idFrom, GWL_ID) : lphdr->hdr.idFrom;
  218.  
  219. *lphdr->lpszText = 0;
  220.  
  221. SendMessage(lphdr->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, 0, 5000);
  222.  
  223. for(int i=0; i<sizeof AEncodeProperties::Tooltips/sizeof AEncodeProperties::Tooltips[0]; ++i) {
  224. if (id == AEncodeProperties::Tooltips[i].id)
  225. lphdr->lpszText = const_cast<char *>(AEncodeProperties::Tooltips[i].tip);
  226. }
  227.  
  228. return TRUE;
  229. }
  230. break;
  231.  
  232. default:
  233. bResult = FALSE; // will be treated by DefWindowProc
  234. }
  235. return bResult;
  236. }
  237.  
  238. //////////////////////////////////////////////////////////////////////
  239. // Construction/Destruction
  240. //////////////////////////////////////////////////////////////////////
  241. /**
  242. \class AEncodeProperties
  243. */
  244.  
  245.  
  246. const char * AEncodeProperties::GetChannelModeString(int a_channelID) const
  247. {
  248. assert(a_channelID < sizeof(the_ChannelModes));
  249.  
  250. switch (a_channelID) {
  251. case 0:
  252. return "Stereo";
  253. case 1:
  254. return "Joint-stereo";
  255. case 2:
  256. return "Dual Channel";
  257. default:
  258. assert(a_channelID);
  259. return NULL;
  260. }
  261. }
  262.  
  263. const int AEncodeProperties::GetBitrateString(char * string, int string_size, int a_bitrateID) const
  264. {
  265. assert(a_bitrateID < sizeof(the_Bitrates));
  266. assert(string != NULL);
  267.  
  268. if (string_size >= 4)
  269. return wsprintf(string,"%d",the_Bitrates[a_bitrateID]);
  270. else
  271. return -1;
  272. }
  273.  
  274. const unsigned int AEncodeProperties::GetChannelModeValue() const
  275. {
  276. assert(nChannelIndex < sizeof(the_ChannelModes));
  277.  
  278. return the_ChannelModes[nChannelIndex];
  279. }
  280.  
  281. const unsigned int AEncodeProperties::GetBitrateValue() const
  282. {
  283. assert(nMinBitrateIndex < sizeof(the_Bitrates));
  284.  
  285. return the_Bitrates[nMinBitrateIndex];
  286. }
  287.  
  288. inline const int AEncodeProperties::GetBitrateValueMPEG2(DWORD & bitrate) const
  289. {
  290. int i;
  291.  
  292. for (i=0;i<sizeof(the_MPEG2_Bitrates)/sizeof(unsigned int);i++)
  293. {
  294. if (the_MPEG2_Bitrates[i] == the_Bitrates[nMinBitrateIndex])
  295. {
  296. bitrate = the_MPEG2_Bitrates[i];
  297. return 0;
  298. }
  299. else if (the_MPEG2_Bitrates[i] < the_Bitrates[nMinBitrateIndex])
  300. {
  301. bitrate = the_MPEG2_Bitrates[i];
  302. return -1;
  303. }
  304. }
  305. bitrate = 160;
  306. return -1;
  307. }
  308.  
  309. inline const int AEncodeProperties::GetBitrateValueMPEG1(DWORD & bitrate) const
  310. {
  311. int i;
  312.  
  313. for (i=sizeof(the_MPEG1_Bitrates)/sizeof(unsigned int)-1;i>=0;i--)
  314. {
  315. if (the_MPEG1_Bitrates[i] == the_Bitrates[nMinBitrateIndex])
  316. {
  317. bitrate = the_MPEG1_Bitrates[i];
  318. return 0;
  319. }
  320. else if (the_MPEG1_Bitrates[i] > the_Bitrates[nMinBitrateIndex])
  321. {
  322. bitrate = the_MPEG1_Bitrates[i];
  323. return 1;
  324. }
  325. }
  326. bitrate = 32;
  327. return 1;
  328. }
  329. /*
  330. const int AEncodeProperties::GetBitrateValue(DWORD & bitrate, const DWORD MPEG_Version) const
  331. {
  332. assert((MPEG_Version == MPEG1) || (MPEG_Version == MPEG2));
  333. assert(nMinBitrateIndex < sizeof(the_Bitrates));
  334.  
  335. if (MPEG_Version == MPEG2)
  336. return GetBitrateValueMPEG2(bitrate);
  337. else
  338. return GetBitrateValueMPEG1(bitrate);
  339. }
  340. /*
  341. const char * AEncodeProperties::GetPresetModeString(const int a_presetID) const
  342. {
  343. assert(a_presetID < sizeof(the_Presets));
  344.  
  345. switch (a_presetID) {
  346. case 1:
  347. return "r3mix";
  348. case 2:
  349. return "Normal";
  350. case 3:
  351. return "Low";
  352. case 4:
  353. return "High";
  354. case 5:
  355. return "Very High";
  356. case 6:
  357. return "Voice";
  358. case 7:
  359. return "Phone";
  360. case 8:
  361. return "SW";
  362. case 9:
  363. return "AM";
  364. case 10:
  365. return "FM";
  366. case 11:
  367. return "Voice";
  368. case 12:
  369. return "Radio";
  370. case 13:
  371. return "Tape";
  372. case 14:
  373. return "Hi-Fi";
  374. case 15:
  375. return "CD";
  376. case 16:
  377. return "Studio";
  378. default:
  379. return "None";
  380. }
  381. }
  382.  
  383. const LAME_QUALTIY_PRESET AEncodeProperties::GetPresetModeValue() const
  384. {
  385. assert(nPresetIndex < sizeof(the_Presets));
  386.  
  387. return the_Presets[nPresetIndex];
  388. }
  389. */
  390. bool AEncodeProperties::Config(const HINSTANCE Hinstance, const HWND HwndParent)
  391. {
  392. //WM_INITDIALOG ?
  393.  
  394. // remember the instance to retreive strings
  395. // hDllInstance = Hinstance;
  396.  
  397. my_debug.OutPut("here");
  398. int ret = ::DialogBoxParam(Hinstance, MAKEINTRESOURCE(IDD_CONFIG), HwndParent, ::ConfigProc, (LPARAM) this);
  399. /* if (ret == -1)
  400. {
  401. LPVOID lpMsgBuf;
  402. FormatMessage(
  403. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  404. FORMAT_MESSAGE_FROM_SYSTEM |
  405. FORMAT_MESSAGE_IGNORE_INSERTS,
  406. NULL,
  407. GetLastError(),
  408. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  409. (LPTSTR) &lpMsgBuf,
  410. 0,
  411. NULL
  412. );
  413. // Process any inserts in lpMsgBuf.
  414. // ...
  415. // Display the string.
  416. AOut::MyMessageBox( (LPCTSTR)lpMsgBuf, MB_OK | MB_ICONINFORMATION );
  417. // Free the buffer.
  418. LocalFree( lpMsgBuf );
  419. return false;
  420. }
  421. */
  422. return true;
  423. }
  424.  
  425. bool AEncodeProperties::InitConfigDlg(HWND HwndDlg)
  426. {
  427. // get all the required strings
  428. // TCHAR Version[5];
  429. // LoadString(hDllInstance, IDS_STRING_VERSION, Version, 5);
  430.  
  431. int i;
  432.  
  433. // Add required channel modes
  434. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_ENC_STEREO), CB_RESETCONTENT , NULL, NULL);
  435. for (i=0;i<GetChannelLentgh();i++)
  436. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_ENC_STEREO), CB_ADDSTRING, NULL, (LPARAM) GetChannelModeString(i));
  437.  
  438. char tmp[20];
  439. wsprintf(tmp, "v%s",ACM::GetVersionString());
  440. SetWindowText( GetDlgItem( HwndDlg, IDC_STATIC_CONFIG_VERSION), tmp);
  441.  
  442. // Add all possible re-sampling freq
  443. /* SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_RESETCONTENT , NULL, NULL);
  444. char tmp[10];
  445. for (i=0;i<sizeof(the_SamplingFreqs)/sizeof(unsigned int);i++)
  446. {
  447. wsprintf(tmp, "%d", the_SamplingFreqs[i]);
  448. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_ADDSTRING, NULL, (LPARAM) tmp );
  449. }
  450. */
  451.  
  452. // Add required bitrates
  453. /* SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_RESETCONTENT , NULL, NULL);
  454. for (i=0;i<GetBitrateLentgh();i++)
  455. {
  456. GetBitrateString(tmp, 5, i);
  457. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_ADDSTRING, NULL, (LPARAM) tmp );
  458. }
  459.  
  460. // Add bitrates to the VBR combo box too
  461. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_RESETCONTENT , NULL, NULL);
  462. for (i=0;i<GetBitrateLentgh();i++)
  463. {
  464. GetBitrateString(tmp, 5, i);
  465. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_ADDSTRING, NULL, (LPARAM) tmp );
  466. }
  467.  
  468. // Add VBR Quality Slider
  469. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_SETRANGE, TRUE, MAKELONG(0,9));
  470.  
  471. // Add presets
  472. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_RESETCONTENT , NULL, NULL);
  473. for (i=0;i<GetPresetLentgh();i++)
  474. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_ADDSTRING, NULL, (LPARAM) GetPresetModeString(i));
  475. */
  476.  
  477. // Add ABR Sliders
  478. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_MIN), TBM_SETRANGE, TRUE, MAKELONG(8,320));
  479. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_MAX), TBM_SETRANGE, TRUE, MAKELONG(8,320));
  480. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_STEP), TBM_SETRANGE, TRUE, MAKELONG(1,16));
  481.  
  482. // Tool-Tip initialiasiation
  483. TOOLINFO ti;
  484. HWND ToolTipWnd;
  485. char DisplayStr[30] = "test tooltip";
  486.  
  487. ToolTipWnd = CreateWindowEx(WS_EX_TOPMOST,
  488. TOOLTIPS_CLASS,
  489. NULL,
  490. WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP|TTS_BALLOON ,
  491. CW_USEDEFAULT,
  492. CW_USEDEFAULT,
  493. CW_USEDEFAULT,
  494. CW_USEDEFAULT,
  495. HwndDlg,
  496. NULL,
  497. NULL,
  498. NULL
  499. );
  500.  
  501. SetWindowPos(ToolTipWnd,
  502. HWND_TOPMOST,
  503. 0,
  504. 0,
  505. 0,
  506. 0,
  507. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  508.  
  509. /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
  510. ti.cbSize = sizeof(TOOLINFO);
  511. ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
  512. ti.hwnd = HwndDlg;
  513. ti.lpszText = LPSTR_TEXTCALLBACK;
  514. /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
  515. for(i=0; i<sizeof Tooltips/sizeof Tooltips[0]; ++i) {
  516. ti.uId = (WPARAM)GetDlgItem(HwndDlg, Tooltips[i].id);
  517.  
  518. if (ti.uId)
  519. SendMessage(ToolTipWnd, TTM_ADDTOOL, 0, (LPARAM)&ti);
  520. }
  521.  
  522. my_debug.OutPut("call UpdateConfigs");
  523.  
  524. UpdateConfigs(HwndDlg);
  525.  
  526. my_debug.OutPut("call UpdateDlgFromValue");
  527.  
  528. UpdateDlgFromValue(HwndDlg);
  529.  
  530.  
  531. my_debug.OutPut("finished InitConfigDlg");
  532.  
  533.  
  534. return true;
  535. }
  536.  
  537. bool AEncodeProperties::UpdateDlgFromValue(HWND HwndDlg)
  538. {
  539. // get all the required strings
  540. // TCHAR Version[5];
  541. // LoadString(hDllInstance, IDS_STRING_VERSION, Version, 5);
  542.  
  543. int i;
  544.  
  545. // Check boxes if required
  546. ::CheckDlgButton( HwndDlg, IDC_CHECK_CHECKSUM, GetCRCMode() ?BST_CHECKED:BST_UNCHECKED );
  547. ::CheckDlgButton( HwndDlg, IDC_CHECK_ORIGINAL, GetOriginalMode() ?BST_CHECKED:BST_UNCHECKED );
  548. ::CheckDlgButton( HwndDlg, IDC_CHECK_PRIVATE, GetPrivateMode() ?BST_CHECKED:BST_UNCHECKED );
  549. ::CheckDlgButton( HwndDlg, IDC_CHECK_COPYRIGHT, GetCopyrightMode() ?BST_CHECKED:BST_UNCHECKED );
  550. ::CheckDlgButton( HwndDlg, IDC_CHECK_ENC_SMART, GetSmartOutputMode()?BST_CHECKED:BST_UNCHECKED );
  551. ::CheckDlgButton( HwndDlg, IDC_CHECK_ENC_ABR, GetAbrOutputMode() ?BST_CHECKED:BST_UNCHECKED );
  552. // ::CheckDlgButton( HwndDlg, IDC_CHECK_RESERVOIR, !GetNoBiResMode() ?BST_CHECKED:BST_UNCHECKED );
  553. // ::CheckDlgButton( HwndDlg, IDC_CHECK_XINGVBR, GetXingFrameMode()?BST_CHECKED:BST_UNCHECKED );
  554. // ::CheckDlgButton( HwndDlg, IDC_CHECK_RESAMPLE, GetResampleMode() ?BST_CHECKED:BST_UNCHECKED );
  555. // ::CheckDlgButton( HwndDlg, IDC_CHECK_CHANNELFORCE, bForceChannel ?BST_CHECKED:BST_UNCHECKED );
  556. // Add required channel modes
  557. for (i=0;i<GetChannelLentgh();i++)
  558. {
  559. if (i == nChannelIndex)
  560. {
  561. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_ENC_STEREO), CB_SETCURSEL, i, NULL);
  562. break;
  563. }
  564. }
  565.  
  566. // Add VBR Quality
  567. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_MIN), TBM_SETPOS, TRUE, AverageBitrate_Min);
  568. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_MAX), TBM_SETPOS, TRUE, AverageBitrate_Max);
  569. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_STEP), TBM_SETPOS, TRUE, AverageBitrate_Step);
  570. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_SETPOS, TRUE, AverageBitrate_Max);
  571.  
  572. UpdateDlgFromSlides(HwndDlg);
  573.  
  574. EnableAbrOptions(HwndDlg, GetAbrOutputMode());
  575. // UpdateAbrSteps(AverageBitrate_Min, AverageBitrate_Max, AverageBitrate_Step);
  576. // Add all possible re-sampling freq
  577. /* SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_SETCURSEL, nSamplingFreqIndex, NULL);
  578.  
  579. // Add required bitrates
  580. for (i=0;i<GetBitrateLentgh();i++)
  581. {
  582. if (i == nMinBitrateIndex)
  583. {
  584. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_SETCURSEL, i, NULL);
  585. break;
  586. }
  587. }
  588.  
  589. // Add bitrates to the VBR combo box too
  590. for (i=0;i<GetBitrateLentgh();i++)
  591. {
  592. if (i == nMaxBitrateIndex)
  593. {
  594. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_SETCURSEL, i, NULL);
  595. break;
  596. }
  597. }
  598.  
  599. // SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_SETRANGE, TRUE, MAKELONG(0,9));
  600.  
  601. char tmp[3];
  602. wsprintf(tmp,"%d",VbrQuality);
  603. SetWindowText(GetDlgItem( HwndDlg, IDC_CONFIG_QUALITY), tmp);
  604. SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_SETPOS, TRUE, VbrQuality);
  605. wsprintf(tmp,"%d",AverageBitrate);
  606. SetWindowText(GetDlgItem( HwndDlg, IDC_EDIT_AVERAGE), tmp);
  607. // Display VBR settings if needed
  608. AEncodeProperties::DisplayVbrOptions(HwndDlg, mBRmode);
  609.  
  610. // Display Resample settings if needed
  611. if (GetResampleMode())
  612. {
  613. ::EnableWindow(::GetDlgItem(HwndDlg,IDC_COMBO_SAMPLEFREQ), TRUE);
  614. }
  615. else
  616. {
  617. ::EnableWindow(::GetDlgItem(HwndDlg,IDC_COMBO_SAMPLEFREQ), FALSE);
  618. }
  619.  
  620.  
  621. // Add presets
  622. for (i=0;i<GetPresetLentgh();i++)
  623. {
  624. if (i == nPresetIndex)
  625. {
  626. SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_SETCURSEL, i, NULL);
  627. break;
  628. }
  629. }
  630.  
  631. // Add User configs
  632. // SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_RESETCONTENT , NULL, NULL);
  633. ::SetWindowText(::GetDlgItem( HwndDlg, IDC_EDIT_OUTPUTDIR), OutputDir.c_str());
  634. */
  635. /**
  636. \todo Select the right saved config
  637. */
  638.  
  639. return true;
  640. }
  641.  
  642. bool AEncodeProperties::UpdateValueFromDlg(HWND HwndDlg)
  643. {
  644. nChannelIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_ENC_STEREO), CB_GETCURSEL, NULL, NULL);
  645. // nMinBitrateIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_GETCURSEL, NULL, NULL);
  646. // nMaxBitrateIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_GETCURSEL, NULL, NULL);
  647. // nPresetIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_GETCURSEL, NULL, NULL);
  648. // VbrQuality = SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_GETPOS , NULL, NULL);
  649. // nSamplingFreqIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_GETCURSEL, NULL, NULL);
  650.  
  651. bCRC = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_CHECKSUM) == BST_CHECKED);
  652. bCopyright = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_COPYRIGHT) == BST_CHECKED);
  653. bOriginal = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_ORIGINAL) == BST_CHECKED);
  654. bPrivate = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_PRIVATE) == BST_CHECKED);
  655. bSmartOutput = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_ENC_SMART) == BST_CHECKED);
  656. bAbrOutput = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_ENC_ABR) == BST_CHECKED);
  657. // bNoBitRes =!(::IsDlgButtonChecked( HwndDlg, IDC_CHECK_RESERVOIR) == BST_CHECKED);
  658. // bXingFrame = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_XINGVBR) == BST_CHECKED);
  659. // bResample = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_RESAMPLE) == BST_CHECKED);
  660. // bForceChannel = (::IsDlgButtonChecked( HwndDlg, IDC_CHECK_CHANNELFORCE) == BST_CHECKED);
  661.  
  662. AverageBitrate_Min = SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_MIN), TBM_GETPOS , NULL, NULL);
  663. AverageBitrate_Max = SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_MAX), TBM_GETPOS , NULL, NULL);
  664. AverageBitrate_Step = SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_AVERAGE_STEP), TBM_GETPOS , NULL, NULL);
  665.  
  666. EnableAbrOptions(HwndDlg, bAbrOutput);
  667.  
  668. my_debug.OutPut("nChannelIndex %d, bCRC %d, bCopyright %d, bOriginal %d, bPrivate %d",nChannelIndex, bCRC, bCopyright, bOriginal, bPrivate);
  669.  
  670. /* char tmpPath[MAX_PATH];
  671. ::GetWindowText( ::GetDlgItem( HwndDlg, IDC_EDIT_OUTPUTDIR), tmpPath, MAX_PATH);
  672. OutputDir = tmpPath;
  673.  
  674. if (::IsDlgButtonChecked(HwndDlg, IDC_RADIO_BITRATE_CBR) == BST_CHECKED)
  675. mBRmode = BR_CBR;
  676. else if (::IsDlgButtonChecked(HwndDlg, IDC_RADIO_BITRATE_VBR) == BST_CHECKED)
  677. mBRmode = BR_VBR;
  678. else
  679. mBRmode = BR_ABR;
  680. ::GetWindowText( ::GetDlgItem( HwndDlg, IDC_EDIT_AVERAGE), tmpPath, MAX_PATH);
  681. AverageBitrate = atoi(tmpPath);
  682. if (AverageBitrate < 8)
  683. AverageBitrate = 8;
  684. if (AverageBitrate > 320)
  685. AverageBitrate = 320;
  686. */
  687. return true;
  688. }
  689. /*
  690. VBRMETHOD AEncodeProperties::GetVBRValue(DWORD & MaxBitrate, int & Quality, DWORD & AbrBitrate, BOOL & VBRHeader, const DWORD MPEG_Version) const
  691. {
  692. assert((MPEG_Version == MPEG1) || (MPEG_Version == MPEG2));
  693. assert(nMaxBitrateIndex < sizeof(the_Bitrates));
  694.  
  695. if (mBRmode == BR_VBR)
  696. {
  697. MaxBitrate = the_Bitrates[nMaxBitrateIndex];
  698.  
  699. if (MPEG_Version == MPEG1)
  700. MaxBitrate = MaxBitrate>the_MPEG1_Bitrates[sizeof(the_MPEG1_Bitrates)/sizeof(unsigned int)-1]?MaxBitrate:the_MPEG1_Bitrates[sizeof(the_MPEG1_Bitrates)/sizeof(unsigned int)-1];
  701. else
  702. MaxBitrate = MaxBitrate<the_MPEG2_Bitrates[0]?MaxBitrate:the_MPEG2_Bitrates[0];
  703.  
  704. VBRHeader = bXingFrame;
  705. Quality = VbrQuality;
  706. AbrBitrate = 0;
  707.  
  708. return VBR_METHOD_DEFAULT; // for the moment
  709. }
  710. else if (mBRmode == BR_ABR)
  711. {
  712. MaxBitrate = the_Bitrates[nMaxBitrateIndex];
  713.  
  714. if (MPEG_Version == MPEG1)
  715. MaxBitrate = MaxBitrate>the_MPEG1_Bitrates[sizeof(the_MPEG1_Bitrates)/sizeof(unsigned int)-1]?MaxBitrate:the_MPEG1_Bitrates[sizeof(the_MPEG1_Bitrates)/sizeof(unsigned int)-1];
  716. else
  717. MaxBitrate = MaxBitrate<the_MPEG2_Bitrates[0]?MaxBitrate:the_MPEG2_Bitrates[0];
  718.  
  719. VBRHeader = bXingFrame;
  720. Quality = 0;
  721. AbrBitrate = AverageBitrate*1000;
  722. return VBR_METHOD_ABR;
  723. }
  724. else
  725. {
  726. return VBR_METHOD_NONE;
  727. }
  728. }
  729. */
  730. void AEncodeProperties::ParamsRestore()
  731. {
  732. // use these default parameters in case one is not found
  733. bCopyright = true;
  734. bCRC = true;
  735. bOriginal = true;
  736. bPrivate = true;
  737. bNoBitRes = false; // enable bit reservoir
  738. bXingFrame = true;
  739. bResample = false;
  740. bForceChannel = false;
  741. bSmartOutput = true;
  742. bAbrOutput = true;
  743. AverageBitrate_Min = 80; // a bit lame
  744. AverageBitrate_Max = 160; // a bit lame
  745. AverageBitrate_Step = 8; // a bit lame
  746. SmartRatioMax = 15.0;
  747.  
  748. nChannelIndex = 2; // joint-stereo
  749. mBRmode = BR_CBR;
  750. nMinBitrateIndex = 6; // 128 kbps (works for both MPEGI and II)
  751. nMaxBitrateIndex = 4; // 160 kbps (works for both MPEGI and II)
  752. nPresetIndex = 0; // None
  753. VbrQuality = 1; // Quite High
  754. // AverageBitrate = 128; // a bit lame
  755. nSamplingFreqIndex = 1; // 44100
  756.  
  757. // OutputDir = "c:\\";
  758.  
  759. // DllLocation = "plugins\\lame_enc.dll";
  760.  
  761. // get the values from the saved file if possible
  762. if (my_stored_data.LoadFile(my_store_location))
  763. {
  764. TiXmlNode* node;
  765.  
  766. node = my_stored_data.FirstChild("lame_acm");
  767.  
  768. TiXmlElement* CurrentNode = node->FirstChildElement("encodings");
  769.  
  770. std::string CurrentConfig = "";
  771.  
  772. if (CurrentNode->Attribute("default") != NULL)
  773. {
  774. CurrentConfig = *CurrentNode->Attribute("default");
  775. }
  776.  
  777. /* // output parameters
  778. TiXmlElement* iterateElmt = node->FirstChildElement("DLL");
  779. if (iterateElmt != NULL)
  780. {
  781. const std::string * tmpname = iterateElmt->Attribute("location");
  782. if (tmpname != NULL)
  783. {
  784. DllLocation = *tmpname;
  785. }
  786. }
  787. */
  788. GetValuesFromKey(CurrentConfig, *CurrentNode);
  789. }
  790. else
  791. {
  792. /**
  793. \todo save the data in the file !
  794. */
  795. }
  796. }
  797.  
  798. void AEncodeProperties::ParamsSave()
  799. {
  800. /*
  801.  
  802.  
  803. save the current parameters in the corresponding subkey
  804.  
  805.  
  806.  
  807. HKEY OssKey;
  808.  
  809. if (RegCreateKeyEx ( HKEY_LOCAL_MACHINE, "SOFTWARE\\MUKOLI\\out_lame", 0, "", REG_OPTION_NON_VOLATILE, KEY_WRITE , NULL, &OssKey, NULL ) == ERROR_SUCCESS) {
  810.  
  811. if (RegSetValueEx(OssKey, "DLL Location", 0, REG_EXPAND_SZ, (CONST BYTE *)DllLocation, strlen(DllLocation)+1 ) != ERROR_SUCCESS)
  812. return;
  813. RegCloseKey(OssKey);
  814. }
  815. */
  816. }
  817. /*
  818. void AEncodeProperties::DisplayVbrOptions(const HWND hDialog, const BRMode the_mode)
  819. {
  820. bool bVBR = false;
  821. bool bABR = false;
  822.  
  823. switch ( the_mode )
  824. {
  825. case BR_CBR:
  826. ::CheckRadioButton(hDialog, IDC_RADIO_BITRATE_CBR, IDC_RADIO_BITRATE_ABR, IDC_RADIO_BITRATE_CBR);
  827. break;
  828. case BR_VBR:
  829. ::CheckRadioButton(hDialog, IDC_RADIO_BITRATE_CBR, IDC_RADIO_BITRATE_ABR, IDC_RADIO_BITRATE_VBR);
  830. bVBR = true;
  831. break;
  832. case BR_ABR:
  833. ::CheckRadioButton(hDialog, IDC_RADIO_BITRATE_CBR, IDC_RADIO_BITRATE_ABR, IDC_RADIO_BITRATE_ABR);
  834. bABR = true;
  835. break;
  836.  
  837. }
  838.  
  839. if(bVBR|bABR)
  840. {
  841. ::SetWindowText(::GetDlgItem(hDialog,IDC_STATIC_MINBITRATE), "Min Bitrate");
  842. }
  843. else
  844. {
  845. ::SetWindowText(::GetDlgItem(hDialog,IDC_STATIC_MINBITRATE), "Bitrate");
  846. }
  847.  
  848. ::EnableWindow(::GetDlgItem( hDialog, IDC_CHECK_XINGVBR), bVBR|bABR);
  849.  
  850. ::EnableWindow(::GetDlgItem( hDialog, IDC_COMBO_MAXBITRATE), bVBR|bABR);
  851.  
  852. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_MAXBITRATE), bVBR|bABR);
  853.  
  854. ::EnableWindow(::GetDlgItem( hDialog, IDC_SLIDER_QUALITY), bVBR);
  855.  
  856. ::EnableWindow(::GetDlgItem( hDialog, IDC_CONFIG_QUALITY), bVBR);
  857.  
  858. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_VBRQUALITY), bVBR);
  859.  
  860. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_VBRQUALITY_LOW), bVBR);
  861.  
  862. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_VBRQUALITY_HIGH), bVBR);
  863.  
  864. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_ABR), bABR);
  865.  
  866. ::EnableWindow(::GetDlgItem( hDialog, IDC_EDIT_AVERAGE), bABR);
  867. }
  868. */
  869. AEncodeProperties::AEncodeProperties(HMODULE hModule)
  870. :my_debug(ADbg(DEBUG_LEVEL_CREATION)),
  871. my_hModule(hModule)
  872. {
  873. std::string path = "";
  874. // HMODULE htmp = LoadLibrary("out_lame.dll");
  875. if (hModule != NULL)
  876. {
  877. char output[MAX_PATH];
  878. ::GetModuleFileName(hModule, output, MAX_PATH);
  879. // ::FreeLibrary(htmp);
  880.  
  881. path = output;
  882. }
  883. my_store_location = path.substr(0,path.find_last_of('\\')+1);
  884. my_store_location += "lame_acm.xml";
  885.  
  886. my_debug.OutPut("store path = %s",my_store_location.c_str());
  887. //#ifdef OLD
  888. // ::OutputDebugString(my_store_location.c_str());
  889.  
  890. // make sure the XML file is present
  891. HANDLE hFile = ::CreateFile(my_store_location.c_str(), 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL );
  892. ::CloseHandle(hFile);
  893. //#endif // OLD
  894. my_debug.OutPut("AEncodeProperties creation completed (0x%08X)",this);
  895. }
  896.  
  897. // Save the values to the right XML saved config
  898. void AEncodeProperties::SaveValuesToStringKey(const std::string & config_name)
  899. {
  900. // get the current data in the file to keep them
  901. if (my_stored_data.LoadFile(my_store_location))
  902. {
  903. // check if the Node corresponding to the config_name already exist.
  904. TiXmlNode* node = my_stored_data.FirstChild("lame_acm");
  905.  
  906. if (node != NULL)
  907. {
  908. TiXmlElement* ConfigNode = node->FirstChildElement("encodings");
  909.  
  910. if (ConfigNode != NULL)
  911. {
  912. // look all the <config> tags
  913. TiXmlElement* tmpNode = ConfigNode->FirstChildElement("config");
  914. while (tmpNode != NULL)
  915. {
  916. const std::string * tmpname = tmpNode->Attribute("name");
  917. if (tmpname->compare(config_name) == 0)
  918. {
  919. break;
  920. }
  921. tmpNode = tmpNode->NextSiblingElement("config");
  922. }
  923.  
  924. if (tmpNode == NULL)
  925. {
  926. // Create the node
  927. tmpNode = new TiXmlElement("config");
  928. tmpNode->SetAttribute("name",config_name);
  929.  
  930. // save data in the node
  931. SaveValuesToElement(tmpNode);
  932.  
  933. ConfigNode->InsertEndChild(*tmpNode);
  934. }
  935. else
  936. {
  937. // save data in the node
  938. SaveValuesToElement(tmpNode);
  939. }
  940.  
  941.  
  942. // and save the file
  943. my_stored_data.SaveFile(my_store_location);
  944. }
  945. }
  946. }
  947. }
  948.  
  949. void AEncodeProperties::GetValuesFromKey(const std::string & config_name, const TiXmlNode & parentNode)
  950. {
  951. TiXmlElement* tmpElt;
  952. TiXmlElement* iterateElmt;
  953.  
  954. // find the config that correspond to CurrentConfig
  955. iterateElmt = parentNode.FirstChildElement("config");
  956. while (iterateElmt != NULL)
  957. {
  958. const std::string * tmpname = iterateElmt->Attribute("name");
  959. if ((tmpname != NULL) && (tmpname->compare(config_name) == 0))
  960. {
  961. break;
  962. }
  963. iterateElmt = iterateElmt->NextSiblingElement("config");
  964. }
  965.  
  966. if (iterateElmt != NULL)
  967. {
  968. // get all the parameters saved in this Element
  969. const std::string * tmpname;
  970.  
  971. // Smart output parameter
  972. tmpElt = iterateElmt->FirstChildElement("Smart");
  973. if (tmpElt != NULL)
  974. {
  975. tmpname = tmpElt->Attribute("use");
  976. if (tmpname != NULL)
  977. bSmartOutput = (tmpname->compare("true") == 0);
  978. tmpname = tmpElt->Attribute("ratio");
  979. if (tmpname != NULL)
  980. SmartRatioMax = atof(tmpname->c_str());
  981. }
  982.  
  983. // Smart output parameter
  984. tmpElt = iterateElmt->FirstChildElement("ABR");
  985. if (tmpElt != NULL)
  986. {
  987. tmpname = tmpElt->Attribute("use");
  988. if (tmpname != NULL)
  989. bAbrOutput = (tmpname->compare("true") == 0);
  990. tmpname = tmpElt->Attribute("min");
  991. if (tmpname != NULL)
  992. AverageBitrate_Min = atoi(tmpname->c_str());
  993.  
  994. tmpname = tmpElt->Attribute("max");
  995. if (tmpname != NULL)
  996. AverageBitrate_Max = atoi(tmpname->c_str());
  997.  
  998. tmpname = tmpElt->Attribute("step");
  999. if (tmpname != NULL)
  1000. AverageBitrate_Step = atoi(tmpname->c_str());
  1001. }
  1002.  
  1003. // Copyright parameter
  1004. tmpElt = iterateElmt->FirstChildElement("Copyright");
  1005. if (tmpElt != NULL)
  1006. {
  1007. tmpname = tmpElt->Attribute("use");
  1008. if (tmpname != NULL)
  1009. bCopyright = (tmpname->compare("true") == 0);
  1010. }
  1011.  
  1012. // Copyright parameter
  1013. tmpElt = iterateElmt->FirstChildElement("CRC");
  1014. if (tmpElt != NULL)
  1015. {
  1016. tmpname = tmpElt->Attribute("use");
  1017. if (tmpname != NULL)
  1018. bCRC = (tmpname->compare("true") == 0);
  1019. }
  1020.  
  1021. // Copyright parameter
  1022. tmpElt = iterateElmt->FirstChildElement("Original");
  1023. if (tmpElt != NULL)
  1024. {
  1025. tmpname = tmpElt->Attribute("use");
  1026. if (tmpname != NULL)
  1027. bOriginal = (tmpname->compare("true") == 0);
  1028. }
  1029.  
  1030. // Copyright parameter
  1031. tmpElt = iterateElmt->FirstChildElement("Private");
  1032. if (tmpElt != NULL)
  1033. {
  1034. tmpname = tmpElt->Attribute("use");
  1035. if (tmpname != NULL)
  1036. bPrivate = (tmpname->compare("true") == 0);
  1037. }
  1038. /*
  1039. // Copyright parameter
  1040. tmpElt = iterateElmt->FirstChildElement("Bit_reservoir");
  1041. if (tmpElt != NULL)
  1042. {
  1043. tmpname = tmpElt->Attribute("use");
  1044. if (tmpname != NULL)
  1045. bNoBitRes = !(tmpname->compare("true") == 0);
  1046. }
  1047.  
  1048. // bitrates
  1049. tmpElt = iterateElmt->FirstChildElement("bitrate");
  1050. tmpname = tmpElt->Attribute("min");
  1051. if (tmpname != NULL)
  1052. {
  1053. unsigned int uitmp = atoi(tmpname->c_str());
  1054. for (int i=0;i<sizeof(the_Bitrates)/sizeof(unsigned int);i++)
  1055. {
  1056. if (the_Bitrates[i] == uitmp)
  1057. {
  1058. nMinBitrateIndex = i;
  1059. break;
  1060. }
  1061. }
  1062. }
  1063.  
  1064. tmpname = tmpElt->Attribute("max");
  1065. if (tmpname != NULL)
  1066. {
  1067. unsigned int uitmp = atoi(tmpname->c_str());
  1068. for (int i=0;i<sizeof(the_Bitrates)/sizeof(unsigned int);i++)
  1069. {
  1070. if (the_Bitrates[i] == uitmp)
  1071. {
  1072. nMaxBitrateIndex = i;
  1073. break;
  1074. }
  1075. }
  1076. }
  1077. */
  1078. /*
  1079. // resampling parameters
  1080. tmpElt = iterateElmt->FirstChildElement("resampling");
  1081. if (tmpElt != NULL)
  1082. {
  1083. tmpname = tmpElt->Attribute("use");
  1084. if (tmpname != NULL)
  1085. bResample = (tmpname->compare("true") == 0);
  1086.  
  1087. unsigned int uitmp = atoi(tmpElt->Attribute("freq")->c_str());
  1088. for (int i=0;i<sizeof(the_SamplingFreqs)/sizeof(unsigned int);i++)
  1089. {
  1090. if (the_SamplingFreqs[i] == uitmp)
  1091. {
  1092. nSamplingFreqIndex = i;
  1093. break;
  1094. }
  1095. }
  1096. }
  1097.  
  1098. // VBR parameters
  1099. tmpElt = iterateElmt->FirstChildElement("VBR");
  1100. if (tmpElt != NULL)
  1101. {
  1102. tmpname = tmpElt->Attribute("use");
  1103. if (tmpname != NULL)
  1104. {
  1105. if (tmpname->compare("ABR") == 0)
  1106. mBRmode = BR_ABR;
  1107. else if (tmpname->compare("true") == 0)
  1108. mBRmode = BR_VBR;
  1109. else
  1110. mBRmode = BR_CBR;
  1111. }
  1112.  
  1113. tmpname = tmpElt->Attribute("header");
  1114. if (tmpname != NULL)
  1115. bXingFrame = (tmpname->compare("true") == 0);
  1116.  
  1117. tmpname = tmpElt->Attribute("quality");
  1118. if (tmpname != NULL)
  1119. {
  1120. VbrQuality = atoi(tmpname->c_str());
  1121. }
  1122.  
  1123. tmpname = tmpElt->Attribute("average");
  1124. if (tmpname != NULL)
  1125. {
  1126. AverageBitrate = atoi(tmpname->c_str());
  1127. }
  1128. else
  1129. {
  1130. }
  1131. }
  1132.  
  1133. // output parameters
  1134. tmpElt = iterateElmt->FirstChildElement("output");
  1135. if (tmpElt != NULL)
  1136. {
  1137. OutputDir = *tmpElt->Attribute("path");
  1138. }
  1139. */
  1140. //#ifdef OLD
  1141. // Channel mode parameter
  1142. tmpElt = iterateElmt->FirstChildElement("Channel");
  1143. if (tmpElt != NULL)
  1144. {
  1145. const std::string * tmpStr = tmpElt->Attribute("mode");
  1146. if (tmpStr != NULL)
  1147. {
  1148. for (int i=0;i<GetChannelLentgh();i++)
  1149. {
  1150. if (tmpStr->compare(GetChannelModeString(i)) == 0)
  1151. {
  1152. nChannelIndex = i;
  1153. break;
  1154. }
  1155. }
  1156. }
  1157. /*
  1158. tmpname = tmpElt->Attribute("force");
  1159. if (tmpname != NULL)
  1160. bForceChannel = (tmpname->compare("true") == 0);
  1161. */
  1162. }
  1163. //#endif // OLD
  1164.  
  1165. // Preset parameter
  1166. /*
  1167. tmpElt = iterateElmt->FirstChildElement("Preset");
  1168. if (tmpElt != NULL)
  1169. {
  1170. const std::string * tmpStr = tmpElt->Attribute("type");
  1171. for (int i=0;i<GetPresetLentgh();i++)
  1172. {
  1173. if (tmpStr->compare(GetPresetModeString(i)) == 0)
  1174. {
  1175. nPresetIndex = i;
  1176. break;
  1177. }
  1178. }
  1179.  
  1180. }
  1181. */
  1182. }
  1183. }
  1184.  
  1185. /**
  1186. \todo save the parameters
  1187. * /
  1188. void AEncodeProperties::SaveParams(const HWND hParentWnd)
  1189. {
  1190. char string[MAX_PATH];
  1191. /* int nIdx = SendMessage(::GetDlgItem( hParentWnd ,IDC_COMBO_SETTINGS ), CB_GETCURSEL, NULL, NULL);
  1192. ::SendMessage(::GetDlgItem( hParentWnd ,IDC_COMBO_SETTINGS ), CB_GETLBTEXT , nIdx, (LPARAM) string);
  1193. * /
  1194. }*/
  1195.  
  1196. bool AEncodeProperties::operator !=(const AEncodeProperties & the_instance) const
  1197. {
  1198. /*
  1199. ::OutputDebugString(bCopyright != the_instance.bCopyright?"1":"-");
  1200. ::OutputDebugString(bCRC != the_instance.bCRC ?"2":"-");
  1201. ::OutputDebugString(bOriginal != the_instance.bOriginal ?"3":"-");
  1202. ::OutputDebugString(bPrivate != the_instance.bPrivate ?"4":"-");
  1203. ::OutputDebugString(bNoBitRes != the_instance.bNoBitRes ?"5":"-");
  1204. ::OutputDebugString(mBRmode != the_instance.mBRmode ?"6":"-");
  1205. ::OutputDebugString(bXingFrame != the_instance.bXingFrame?"7":"-");
  1206. ::OutputDebugString(bForceChannel != the_instance.bForceChannel?"8":"-");
  1207. ::OutputDebugString(bResample != the_instance.bResample ?"9":"-");
  1208. ::OutputDebugString(nChannelIndex != the_instance.nChannelIndex?"10":"-");
  1209. ::OutputDebugString(nMinBitrateIndex != the_instance.nMinBitrateIndex?"11":"-");
  1210. ::OutputDebugString(nMaxBitrateIndex != the_instance.nMaxBitrateIndex?"12":"-");
  1211. ::OutputDebugString(nPresetIndex != the_instance.nPresetIndex?"13":"-");
  1212. ::OutputDebugString(VbrQuality != the_instance.VbrQuality?"14":"-");
  1213. ::OutputDebugString(AverageBitrate != the_instance.AverageBitrate?"15":"-");
  1214. ::OutputDebugString(nSamplingFreqIndex != the_instance.nSamplingFreqIndex?"16":"-");
  1215. ::OutputDebugString(OutputDir.compare(the_instance.OutputDir) != 0?"17":"-");
  1216.  
  1217. std::string tmp = "";
  1218. char tmpI[10];
  1219. _itoa(AverageBitrate,tmpI,10);
  1220. tmp += tmpI;
  1221. tmp += " != ";
  1222. _itoa(the_instance.AverageBitrate,tmpI,10);
  1223. tmp += tmpI;
  1224. ::OutputDebugString(tmp.c_str());
  1225. */
  1226. return ((bCopyright != the_instance.bCopyright)
  1227. || (bCRC != the_instance.bCRC)
  1228. || (bOriginal != the_instance.bOriginal)
  1229. || (bPrivate != the_instance.bPrivate)
  1230. || (bSmartOutput != the_instance.bSmartOutput)
  1231. || (SmartRatioMax != the_instance.SmartRatioMax)
  1232. || (bAbrOutput != the_instance.bAbrOutput)
  1233. || (AverageBitrate_Min != the_instance.AverageBitrate_Min)
  1234. || (AverageBitrate_Max != the_instance.AverageBitrate_Max)
  1235. || (AverageBitrate_Step != the_instance.AverageBitrate_Step)
  1236. || (bNoBitRes != the_instance.bNoBitRes)
  1237. || (mBRmode != the_instance.mBRmode)
  1238. || (bXingFrame != the_instance.bXingFrame)
  1239. || (bForceChannel != the_instance.bForceChannel)
  1240. || (bResample != the_instance.bResample)
  1241. || (nChannelIndex != the_instance.nChannelIndex)
  1242. || (nMinBitrateIndex != the_instance.nMinBitrateIndex)
  1243. || (nMaxBitrateIndex != the_instance.nMaxBitrateIndex)
  1244. || (nPresetIndex != the_instance.nPresetIndex)
  1245. || (VbrQuality != the_instance.VbrQuality)
  1246. // || (AverageBitrate != the_instance.AverageBitrate)
  1247. || (nSamplingFreqIndex != the_instance.nSamplingFreqIndex)
  1248. // || (OutputDir.compare(the_instance.OutputDir) != 0)
  1249. );
  1250. }
  1251.  
  1252. void AEncodeProperties::SelectSavedParams(const std::string the_string)
  1253. {
  1254. // get the values from the saved file if possible
  1255. if (my_stored_data.LoadFile(my_store_location))
  1256. {
  1257. TiXmlNode* node;
  1258.  
  1259. node = my_stored_data.FirstChild("lame_acm");
  1260.  
  1261. TiXmlElement* CurrentNode = node->FirstChildElement("encodings");
  1262.  
  1263. if (CurrentNode != NULL)
  1264. {
  1265. CurrentNode->SetAttribute("default",the_string);
  1266. GetValuesFromKey(the_string, *CurrentNode);
  1267. my_stored_data.SaveFile(my_store_location);
  1268. }
  1269. }
  1270. }
  1271.  
  1272. inline void AEncodeProperties::SetAttributeBool(TiXmlElement * the_elt,const std::string & the_string, const bool the_value) const
  1273. {
  1274. if (the_value == false)
  1275. the_elt->SetAttribute(the_string, "false");
  1276. else
  1277. the_elt->SetAttribute(the_string, "true");
  1278. }
  1279.  
  1280. void AEncodeProperties::SaveValuesToElement(TiXmlElement * the_element) const
  1281. {
  1282. // get all the parameters saved in this Element
  1283. TiXmlElement * tmpElt;
  1284.  
  1285. // Bit Reservoir parameter
  1286. /*
  1287. tmpElt = the_element->FirstChildElement("Bit_reservoir");
  1288. if (tmpElt == NULL)
  1289. {
  1290. tmpElt = new TiXmlElement("Bit_reservoir");
  1291. SetAttributeBool(tmpElt, "use", !bNoBitRes);
  1292. the_element->InsertEndChild(*tmpElt);
  1293. }
  1294. else
  1295. {
  1296. SetAttributeBool(tmpElt, "use", !bNoBitRes);
  1297. }
  1298. */
  1299. // Copyright parameter
  1300. tmpElt = the_element->FirstChildElement("Copyright");
  1301. if (tmpElt == NULL)
  1302. {
  1303. tmpElt = new TiXmlElement("Copyright");
  1304. SetAttributeBool( tmpElt, "use", bCopyright);
  1305. the_element->InsertEndChild(*tmpElt);
  1306. }
  1307. else
  1308. {
  1309. SetAttributeBool( tmpElt, "use", bCopyright);
  1310. }
  1311.  
  1312. // Smart Output parameter
  1313. tmpElt = the_element->FirstChildElement("Smart");
  1314. if (tmpElt == NULL)
  1315. {
  1316. tmpElt = new TiXmlElement("Smart");
  1317. SetAttributeBool( tmpElt, "use", bSmartOutput);
  1318. tmpElt->SetAttribute("ratio", SmartRatioMax);
  1319. the_element->InsertEndChild(*tmpElt);
  1320. }
  1321. else
  1322. {
  1323. SetAttributeBool( tmpElt, "use", bSmartOutput);
  1324. tmpElt->SetAttribute("ratio", SmartRatioMax);
  1325. }
  1326.  
  1327. // Smart Output parameter
  1328. tmpElt = the_element->FirstChildElement("ABR");
  1329. if (tmpElt == NULL)
  1330. {
  1331. tmpElt = new TiXmlElement("ABR");
  1332. SetAttributeBool( tmpElt, "use", bAbrOutput);
  1333. tmpElt->SetAttribute("min", AverageBitrate_Min);
  1334. tmpElt->SetAttribute("max", AverageBitrate_Max);
  1335. tmpElt->SetAttribute("step", AverageBitrate_Step);
  1336. the_element->InsertEndChild(*tmpElt);
  1337. }
  1338. else
  1339. {
  1340. SetAttributeBool( tmpElt, "use", bAbrOutput);
  1341. tmpElt->SetAttribute("min", AverageBitrate_Min);
  1342. tmpElt->SetAttribute("max", AverageBitrate_Max);
  1343. tmpElt->SetAttribute("step", AverageBitrate_Step);
  1344. }
  1345.  
  1346. // CRC parameter
  1347. tmpElt = the_element->FirstChildElement("CRC");
  1348. if (tmpElt == NULL)
  1349. {
  1350. tmpElt = new TiXmlElement("CRC");
  1351. SetAttributeBool( tmpElt, "use", bCRC);
  1352. the_element->InsertEndChild(*tmpElt);
  1353. }
  1354. else
  1355. {
  1356. SetAttributeBool( tmpElt, "use", bCRC);
  1357. }
  1358.  
  1359. // Original parameter
  1360. tmpElt = the_element->FirstChildElement("Original");
  1361. if (tmpElt == NULL)
  1362. {
  1363. tmpElt = new TiXmlElement("Original");
  1364. SetAttributeBool( tmpElt, "use", bOriginal);
  1365. the_element->InsertEndChild(*tmpElt);
  1366. }
  1367. else
  1368. {
  1369. SetAttributeBool( tmpElt, "use", bOriginal);
  1370. }
  1371.  
  1372. // Private parameter
  1373. tmpElt = the_element->FirstChildElement("Private");
  1374. if (tmpElt == NULL)
  1375. {
  1376. tmpElt = new TiXmlElement("Private");
  1377. SetAttributeBool( tmpElt, "use", bPrivate);
  1378. the_element->InsertEndChild(*tmpElt);
  1379. }
  1380. else
  1381. {
  1382. SetAttributeBool( tmpElt, "use", bPrivate);
  1383. }
  1384.  
  1385. // Channel Mode parameter
  1386. tmpElt = the_element->FirstChildElement("Channel");
  1387. if (tmpElt == NULL)
  1388. {
  1389. tmpElt = new TiXmlElement("Channel");
  1390. tmpElt->SetAttribute("mode", GetChannelModeString(nChannelIndex));
  1391. // SetAttributeBool( tmpElt, "force", bForceChannel);
  1392. the_element->InsertEndChild(*tmpElt);
  1393. }
  1394. else
  1395. {
  1396. tmpElt->SetAttribute("mode", GetChannelModeString(nChannelIndex));
  1397. // SetAttributeBool( tmpElt, "force", bForceChannel);
  1398. }
  1399. /*
  1400. // Preset parameter
  1401. tmpElt = the_element->FirstChildElement("Preset");
  1402. if (tmpElt == NULL)
  1403. {
  1404. tmpElt = new TiXmlElement("Preset");
  1405. tmpElt->SetAttribute("type", GetPresetModeString(nPresetIndex));
  1406. the_element->InsertEndChild(*tmpElt);
  1407. }
  1408. else
  1409. {
  1410. tmpElt->SetAttribute("type", GetPresetModeString(nPresetIndex));
  1411. }
  1412.  
  1413. // Bitrate parameter
  1414. tmpElt = the_element->FirstChildElement("bitrate");
  1415. if (tmpElt == NULL)
  1416. {
  1417. tmpElt = new TiXmlElement("bitrate");
  1418. tmpElt->SetAttribute("min", the_Bitrates[nMinBitrateIndex]);
  1419. tmpElt->SetAttribute("max", the_Bitrates[nMaxBitrateIndex]);
  1420. the_element->InsertEndChild(*tmpElt);
  1421. }
  1422. else
  1423. {
  1424. tmpElt->SetAttribute("min", the_Bitrates[nMinBitrateIndex]);
  1425. tmpElt->SetAttribute("max", the_Bitrates[nMaxBitrateIndex]);
  1426. }
  1427.  
  1428. // Output Directory parameter
  1429. tmpElt = the_element->FirstChildElement("output");
  1430. if (tmpElt == NULL)
  1431. {
  1432. tmpElt = new TiXmlElement("output");
  1433. tmpElt->SetAttribute("path", OutputDir);
  1434. the_element->InsertEndChild(*tmpElt);
  1435. }
  1436. else
  1437. {
  1438. tmpElt->SetAttribute("path", OutputDir);
  1439. }
  1440. */
  1441. /*
  1442. // Resampling parameter
  1443. tmpElt = the_element->FirstChildElement("resampling");
  1444. if (tmpElt == NULL)
  1445. {
  1446. tmpElt = new TiXmlElement("resampling");
  1447. SetAttributeBool( tmpElt, "use", bResample);
  1448. tmpElt->SetAttribute("freq", the_SamplingFreqs[nSamplingFreqIndex]);
  1449. the_element->InsertEndChild(*tmpElt);
  1450. }
  1451. else
  1452. {
  1453. SetAttributeBool( tmpElt, "use", bResample);
  1454. tmpElt->SetAttribute("freq", the_SamplingFreqs[nSamplingFreqIndex]);
  1455. }
  1456.  
  1457. // VBR parameter
  1458. tmpElt = the_element->FirstChildElement("VBR");
  1459. if (tmpElt == NULL)
  1460. {
  1461. tmpElt = new TiXmlElement("VBR");
  1462. if (mBRmode == BR_ABR)
  1463. tmpElt->SetAttribute("use", "ABR");
  1464. else
  1465. SetAttributeBool( tmpElt, "use", (mBRmode != BR_CBR));
  1466.  
  1467. SetAttributeBool( tmpElt, "header", bXingFrame);
  1468. tmpElt->SetAttribute("quality", VbrQuality);
  1469. tmpElt->SetAttribute("average", AverageBitrate);
  1470. the_element->InsertEndChild(*tmpElt);
  1471. }
  1472. else
  1473. {
  1474. if (mBRmode == BR_ABR)
  1475. tmpElt->SetAttribute("use", "ABR");
  1476. else
  1477. SetAttributeBool( tmpElt, "use", (mBRmode != BR_CBR));
  1478.  
  1479. SetAttributeBool( tmpElt, "header", bXingFrame);
  1480. tmpElt->SetAttribute("quality", VbrQuality);
  1481. tmpElt->SetAttribute("average", AverageBitrate);
  1482. }
  1483. */
  1484. }
  1485.  
  1486. bool AEncodeProperties::HandleDialogCommand(const HWND parentWnd, const WPARAM wParam, const LPARAM lParam)
  1487. {
  1488. UINT command;
  1489. command = GET_WM_COMMAND_ID(wParam, lParam);
  1490.  
  1491. switch (command)
  1492. {
  1493. case IDOK :
  1494. {
  1495. bool bShouldEnd = true;
  1496.  
  1497. // save parameters
  1498. char string[MAX_PATH];
  1499. // ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
  1500.  
  1501. wsprintf(string,"Current"); // only the Current config is supported at the moment
  1502. my_debug.OutPut("my_hModule = 0x%08X",my_hModule);
  1503. /*
  1504. AEncodeProperties tmpDlgProps(my_hModule);
  1505. AEncodeProperties tmpSavedProps(my_hModule);
  1506. //#ifdef OLD
  1507. tmpDlgProps.UpdateValueFromDlg(parentWnd);
  1508. tmpSavedProps.SelectSavedParams(string);
  1509. tmpSavedProps.ParamsRestore();
  1510. // check if the values from the DLG are the same as the one saved in the config file
  1511. // if yes, just do nothing
  1512. /*
  1513. if (tmpDlgProps != tmpSavedProps)
  1514. {
  1515. int save;
  1516.  
  1517. if (strcmp(string,"Current") == 0)
  1518. {
  1519. // otherwise, prompt the user if he wants to overwrite the settings
  1520. TCHAR tmpStr[250];
  1521. ::LoadString(AOut::GetInstance(),IDS_STRING_PROMPT_REPLACE_CURRENT,tmpStr,250);
  1522.  
  1523. save = AOut::MyMessageBox( tmpStr, MB_OKCANCEL|MB_ICONQUESTION, parentWnd);
  1524. }
  1525. else
  1526. {
  1527. // otherwise, prompt the user if he wants to overwrite the settings
  1528. TCHAR tmpStr[250];
  1529. ::LoadString(AOut::GetInstance(),IDS_STRING_PROMPT_REPLACE_SETING,tmpStr,250);
  1530. TCHAR tmpDsp[500];
  1531. wsprintf(tmpDsp,tmpStr,string);
  1532.  
  1533. save = AOut::MyMessageBox( tmpDsp, MB_YESNOCANCEL|MB_ICONQUESTION, parentWnd);
  1534. }
  1535.  
  1536. if (save == IDCANCEL)
  1537. bShouldEnd = false;
  1538. else if (save == IDNO)
  1539. {
  1540. // save the values in 'current'
  1541. UpdateValueFromDlg(parentWnd);
  1542. SaveValuesToStringKey("Current");
  1543. SelectSavedParams("Current");
  1544. }
  1545. else
  1546. {
  1547. // do so and save in XML
  1548. UpdateValueFromDlg(parentWnd);
  1549. SaveValuesToStringKey(string);
  1550. }
  1551. }
  1552. */
  1553. //#endif // OLD
  1554. my_debug.OutPut("before : nChannelIndex %d, bCRC %d, bCopyright %d, bOriginal %d, bPrivate %d",nChannelIndex, bCRC, bCopyright, bOriginal, bPrivate);
  1555.  
  1556. my_debug.OutPut("call UpdateValueFromDlg");
  1557.  
  1558. UpdateValueFromDlg(parentWnd);
  1559.  
  1560. my_debug.OutPut("call SaveValuesToStringKey");
  1561.  
  1562. SaveValuesToStringKey("Current"); // only Current config is supported now
  1563.  
  1564. // SaveParams(parentWnd);
  1565.  
  1566. //my_debug.OutPut("call SelectSavedParams");
  1567.  
  1568. // SelectSavedParams(string);
  1569. // UpdateDlgFromValue(parentWnd);
  1570.  
  1571. my_debug.OutPut("finished saving");
  1572.  
  1573. if (bShouldEnd)
  1574. {
  1575. RemoveProp(parentWnd, "AEncodeProperties-Config");
  1576. EndDialog(parentWnd, true);
  1577. }
  1578. }
  1579. break;
  1580.  
  1581. case IDCANCEL:
  1582. RemoveProp(parentWnd, "AEncodeProperties-Config");
  1583. EndDialog(parentWnd, false);
  1584. break;
  1585.  
  1586. /* case IDC_FIND_DLL:
  1587. {
  1588. OPENFILENAME file;
  1589. char DllLocation[512];
  1590. wsprintf(DllLocation,"%s",GetDllLocation());
  1591.  
  1592. memset(&file, 0, sizeof(file));
  1593. file.lStructSize = sizeof(file);
  1594. file.hwndOwner = parentWnd;
  1595. file.Flags = OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_ENABLEHOOK | OFN_EXPLORER ;
  1596. /// file.lpstrFile = AOut::the_AOut->DllLocation;
  1597. file.lpstrFile = DllLocation;
  1598. file.lpstrFilter = "Lame DLL (lame_enc.dll)\0LAME_ENC.DLL\0DLL (*.dll)\0*.DLL\0All (*.*)\0*.*\0";
  1599. file.nFilterIndex = 1;
  1600. file.nMaxFile = sizeof(DllLocation);
  1601. file.lpfnHook = DLLFindCallback; // use to validate the DLL chosen
  1602.  
  1603. GetOpenFileName(&file);
  1604.  
  1605. SetDllLocation(DllLocation);
  1606. // use this filename if necessary
  1607. }
  1608. break;
  1609. */
  1610. /* case IDC_BUTTON_OUTPUT:
  1611. {
  1612. #ifndef SIMPLE_FOLDER
  1613. BROWSEINFO info;
  1614. memset(&info,0,sizeof(info));
  1615.  
  1616. char FolderName[MAX_PATH];
  1617.  
  1618. info.hwndOwner = parentWnd;
  1619. info.pszDisplayName = FolderName;
  1620. info.lpfn = BrowseFolderCallbackroc;
  1621. info.lParam = (LPARAM) this;
  1622.  
  1623. // get the localised window title
  1624. TCHAR output[250];
  1625. ::LoadString(AOut::GetInstance(),IDS_STRING_DIR_SELECT,output,250);
  1626. info.lpszTitle = output;
  1627.  
  1628. #ifdef BIF_EDITBOX
  1629. info.ulFlags |= BIF_EDITBOX;
  1630. #else // BIF_EDITBOX
  1631. info.ulFlags |= 0x0010;
  1632. #endif // BIF_EDITBOX
  1633.  
  1634. #ifdef BIF_VALIDATE
  1635. info.ulFlags |= BIF_VALIDATE;
  1636. #else // BIF_VALIDATE
  1637. info.ulFlags |= 0x0020;
  1638. #endif // BIF_VALIDATE
  1639.  
  1640. #ifdef BIF_NEWDIALOGSTYLE
  1641. info.ulFlags |= BIF_NEWDIALOGSTYLE;
  1642. #else // BIF_NEWDIALOGSTYLE
  1643. info.ulFlags |= 0x0040;
  1644. #endif // BIF_NEWDIALOGSTYLE
  1645.  
  1646. ITEMIDLIST *item = SHBrowseForFolder(&info);
  1647.  
  1648. if (item != NULL)
  1649. {
  1650. char tmpOutputDir[MAX_PATH];
  1651. wsprintf(tmpOutputDir,"%s",GetOutputDirectory());
  1652.  
  1653. SHGetPathFromIDList( item,tmpOutputDir );
  1654. SetOutputDirectory( tmpOutputDir );
  1655. ::SetWindowText(GetDlgItem( parentWnd, IDC_EDIT_OUTPUTDIR), tmpOutputDir);
  1656. // wsprintf(OutputDir,FolderName);
  1657. }
  1658. #else // SIMPLE_FOLDER
  1659. OPENFILENAME file;
  1660.  
  1661. memset(&file, 0, sizeof(file));
  1662. file.lStructSize = sizeof(file);
  1663. file.hwndOwner = parentWnd;
  1664. file.Flags = OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_ENABLEHOOK | OFN_EXPLORER ;
  1665. // file.lpstrFile = GetDllLocation();
  1666. // file.lpstrFile = GetOutputDirectory();
  1667. file.lpstrInitialDir = GetOutputDirectory();
  1668. file.lpstrFilter = "A Directory\0.*\0";
  1669. // file.nFilterIndex = 1;
  1670. file.nMaxFile = MAX_PATH;
  1671. // file.lpfnHook = DLLFindCallback; // use to validate the DLL chosen
  1672. // file.Flags = OFN_ENABLESIZING | OFN_NOREADONLYRETURN | OFN_HIDEREADONLY;
  1673. file.Flags = OFN_NOREADONLYRETURN | OFN_HIDEREADONLY | OFN_EXPLORER;
  1674.  
  1675. TCHAR output[250];
  1676. ::LoadString(AOut::GetInstance(),IDS_STRING_DIR_SELECT,output,250);
  1677. file.lpstrTitle = output;
  1678.  
  1679. GetSaveFileName(&file);
  1680. #endif // SIMPLE_FOLDER
  1681. }
  1682. break;
  1683. */
  1684. case IDC_CHECK_ENC_ABR:
  1685. EnableAbrOptions(parentWnd, ::IsDlgButtonChecked( parentWnd, IDC_CHECK_ENC_ABR) == BST_CHECKED);
  1686. break;
  1687. /* case IDC_RADIO_BITRATE_CBR:
  1688. AEncodeProperties::DisplayVbrOptions(parentWnd, AEncodeProperties::BR_CBR);
  1689. break;
  1690.  
  1691. case IDC_RADIO_BITRATE_VBR:
  1692. AEncodeProperties::DisplayVbrOptions(parentWnd, AEncodeProperties::BR_VBR);
  1693. break;
  1694.  
  1695. case IDC_RADIO_BITRATE_ABR:
  1696. AEncodeProperties::DisplayVbrOptions(parentWnd, AEncodeProperties::BR_ABR);
  1697. break;
  1698.  
  1699. case IDC_CHECK_RESAMPLE:
  1700. {
  1701. bool tmp_bResampleUsed = (::IsDlgButtonChecked( parentWnd, IDC_CHECK_RESAMPLE) == BST_CHECKED);
  1702. if (tmp_bResampleUsed)
  1703. {
  1704. ::EnableWindow(::GetDlgItem(parentWnd,IDC_COMBO_SAMPLEFREQ), TRUE);
  1705. }
  1706. else
  1707. {
  1708. ::EnableWindow(::GetDlgItem(parentWnd,IDC_COMBO_SAMPLEFREQ), FALSE);
  1709. }
  1710. }
  1711. break;
  1712. */
  1713. /* case IDC_COMBO_SETTINGS:
  1714. // if (CBN_SELCHANGE == GET_WM_COMMAND_CMD(wParam, lParam))
  1715. if (CBN_SELENDOK == GET_WM_COMMAND_CMD(wParam, lParam))
  1716. {
  1717. char string[MAX_PATH];
  1718. int nIdx = SendMessage(HWND(lParam), CB_GETCURSEL, NULL, NULL);
  1719. SendMessage(HWND(lParam), CB_GETLBTEXT , nIdx, (LPARAM) string);
  1720.  
  1721. // get the info corresponding to the new selected item
  1722. SelectSavedParams(string);
  1723. UpdateDlgFromValue(parentWnd);
  1724. }
  1725. break;
  1726. */
  1727. /* case IDC_BUTTON_CONFIG_SAVE:
  1728. {
  1729. // save the data in the current config
  1730. char string[MAX_PATH];
  1731. ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
  1732.  
  1733. UpdateValueFromDlg(parentWnd);
  1734. SaveValuesToStringKey(string);
  1735. SelectSavedParams(string);
  1736. UpdateConfigs(parentWnd);
  1737. UpdateDlgFromValue(parentWnd);
  1738. }
  1739. break;
  1740.  
  1741. case IDC_BUTTON_CONFIG_RENAME:
  1742. {
  1743. char string[MAX_PATH];
  1744. ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
  1745.  
  1746. if (RenameCurrentTo(string))
  1747. {
  1748. // Update the names displayed
  1749. UpdateConfigs(parentWnd);
  1750. }
  1751.  
  1752. }
  1753. break;
  1754.  
  1755. case IDC_BUTTON_CONFIG_DELETE:
  1756. {
  1757. char string[MAX_PATH];
  1758. ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
  1759. if (DeleteConfig(string))
  1760. {
  1761. // Update the names displayed
  1762. UpdateConfigs(parentWnd);
  1763. UpdateDlgFromValue(parentWnd);
  1764. }
  1765. }
  1766. break;
  1767. */
  1768. }
  1769. return FALSE;
  1770. }
  1771.  
  1772. bool AEncodeProperties::RenameCurrentTo(const std::string & new_config_name)
  1773. {
  1774. bool bResult = false;
  1775.  
  1776. // display all the names of the saved configs
  1777. // get the values from the saved file if possible
  1778. if (my_stored_data.LoadFile(my_store_location))
  1779. {
  1780. TiXmlNode* node;
  1781.  
  1782. node = my_stored_data.FirstChild("lame_acm");
  1783.  
  1784. TiXmlElement* CurrentNode = node->FirstChildElement("encodings");
  1785.  
  1786. if (CurrentNode->Attribute("default") != NULL)
  1787. {
  1788. std::string CurrentConfigName = *CurrentNode->Attribute("default");
  1789.  
  1790. // no rename possible for Current
  1791. if (CurrentConfigName == "")
  1792. {
  1793. bResult = true;
  1794. }
  1795. else if (CurrentConfigName != "Current")
  1796. {
  1797. // find the config that correspond to CurrentConfig
  1798. TiXmlElement* iterateElmt = CurrentNode->FirstChildElement("config");
  1799. // int Idx = 0;
  1800. while (iterateElmt != NULL)
  1801. {
  1802. const std::string * tmpname = iterateElmt->Attribute("name");
  1803. /**
  1804. \todo support language names
  1805. */
  1806. if (tmpname != NULL)
  1807. {
  1808. if (tmpname->compare(CurrentConfigName) == 0)
  1809. {
  1810. iterateElmt->SetAttribute("name",new_config_name);
  1811. bResult = true;
  1812. break;
  1813. }
  1814. }
  1815. // Idx++;
  1816. iterateElmt = iterateElmt->NextSiblingElement("config");
  1817. }
  1818. }
  1819.  
  1820. if (bResult)
  1821. {
  1822. CurrentNode->SetAttribute("default",new_config_name);
  1823.  
  1824. my_stored_data.SaveFile(my_store_location);
  1825. }
  1826. }
  1827. }
  1828.  
  1829. return bResult;
  1830. }
  1831.  
  1832. bool AEncodeProperties::DeleteConfig(const std::string & config_name)
  1833. {
  1834. bool bResult = false;
  1835.  
  1836. if (config_name != "Current")
  1837. {
  1838. // display all the names of the saved configs
  1839. // get the values from the saved file if possible
  1840. if (my_stored_data.LoadFile(my_store_location))
  1841. {
  1842. TiXmlNode* node;
  1843.  
  1844. node = my_stored_data.FirstChild("lame_acm");
  1845.  
  1846. TiXmlElement* CurrentNode = node->FirstChildElement("encodings");
  1847.  
  1848. TiXmlElement* iterateElmt = CurrentNode->FirstChildElement("config");
  1849. // int Idx = 0;
  1850. while (iterateElmt != NULL)
  1851. {
  1852. const std::string * tmpname = iterateElmt->Attribute("name");
  1853. /**
  1854. \todo support language names
  1855. */
  1856. if (tmpname != NULL)
  1857. {
  1858. if (tmpname->compare(config_name) == 0)
  1859. {
  1860. CurrentNode->RemoveChild(iterateElmt);
  1861. bResult = true;
  1862. break;
  1863. }
  1864. }
  1865. // Idx++;
  1866. iterateElmt = iterateElmt->NextSiblingElement("config");
  1867. }
  1868. }
  1869.  
  1870. if (bResult)
  1871. {
  1872. my_stored_data.SaveFile(my_store_location);
  1873.  
  1874. // select a new default config : "Current"
  1875. SelectSavedParams("Current");
  1876.  
  1877. }
  1878. }
  1879.  
  1880. return bResult;
  1881. }
  1882.  
  1883. void AEncodeProperties::UpdateConfigs(const HWND HwndDlg)
  1884. {
  1885. // Add User configs
  1886. // SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_RESETCONTENT , NULL, NULL);
  1887.  
  1888. // display all the names of the saved configs
  1889. // get the values from the saved file if possible
  1890. if (my_stored_data.LoadFile(my_store_location))
  1891. {
  1892. TiXmlNode* node;
  1893.  
  1894. node = my_stored_data.FirstChild("lame_acm");
  1895.  
  1896. TiXmlElement* CurrentNode = node->FirstChildElement("encodings");
  1897.  
  1898. std::string CurrentConfig = "";
  1899.  
  1900. if (CurrentNode->Attribute("default") != NULL)
  1901. {
  1902. CurrentConfig = *CurrentNode->Attribute("default");
  1903. }
  1904.  
  1905. TiXmlElement* iterateElmt;
  1906.  
  1907. my_debug.OutPut("are we here ?");
  1908.  
  1909. // find the config that correspond to CurrentConfig
  1910. iterateElmt = CurrentNode->FirstChildElement("config");
  1911. int Idx = 0;
  1912. while (iterateElmt != NULL)
  1913. {
  1914. const std::string * tmpname = iterateElmt->Attribute("name");
  1915. /**
  1916. \todo support language names
  1917. */
  1918. if (tmpname != NULL)
  1919. {
  1920. // SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_ADDSTRING, NULL, (LPARAM) tmpname->c_str());
  1921. if (tmpname->compare(CurrentConfig) == 0)
  1922. {
  1923. // SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_SETCURSEL, Idx, NULL);
  1924. SelectSavedParams(*tmpname);
  1925. UpdateDlgFromValue(HwndDlg);
  1926. }
  1927. }
  1928. my_debug.OutPut("Idx = %d",Idx);
  1929.  
  1930. Idx++;
  1931. // only Current config supported now
  1932. // iterateElmt = iterateElmt->NextSiblingElement("config");
  1933. iterateElmt = NULL;
  1934. my_debug.OutPut("iterateElmt = 0x%08X",iterateElmt);
  1935.  
  1936. }
  1937. }
  1938. }
  1939. /*
  1940. void AEncodeProperties::UpdateAbrSteps(unsigned int min, unsigned int max, unsigned int step) const
  1941. {
  1942. }
  1943. */
  1944. void AEncodeProperties::UpdateDlgFromSlides(HWND hwndDlg) const
  1945. {
  1946. UINT value_min, value_max, value_step, value;
  1947. char tmp[4];
  1948.  
  1949. value_min = SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_MIN), TBM_GETPOS, NULL, NULL);
  1950. value_max = SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_MAX), TBM_GETPOS, NULL, NULL);
  1951.  
  1952. if (value_min>value_max)
  1953. {
  1954. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_MIN), TBM_SETPOS, TRUE, value_max);
  1955. UpdateDlgFromSlides(hwndDlg);
  1956. return;
  1957. }
  1958.  
  1959. if (value_max<value_min)
  1960. {
  1961. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_MAX), TBM_SETPOS, TRUE, value_min);
  1962. UpdateDlgFromSlides(hwndDlg);
  1963. return;
  1964. }
  1965.  
  1966. wsprintf(tmp,"%3d",value_min);
  1967. ::SetWindowText(GetDlgItem( hwndDlg, IDC_STATIC_AVERAGE_MIN_VALUE), tmp);
  1968. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_SETRANGEMIN, TRUE, value_min);
  1969.  
  1970. wsprintf(tmp,"%3d",value_max);
  1971. ::SetWindowText(GetDlgItem( hwndDlg, IDC_STATIC_AVERAGE_MAX_VALUE), tmp);
  1972. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_SETRANGEMAX, TRUE, value_max);
  1973. value_step = SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_STEP), TBM_GETPOS, NULL, NULL);
  1974. wsprintf(tmp,"%3d",value_step);
  1975. ::SetWindowText(GetDlgItem( hwndDlg, IDC_STATIC_AVERAGE_STEP_VALUE), tmp);
  1976.  
  1977. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_CLEARTICS, TRUE, 0);
  1978. for(UINT i=value_max; i>=value_min;i-=value_step)
  1979. {
  1980. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_SETTIC, 0, i);
  1981. }
  1982. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_SETLINESIZE, 0, value_step);
  1983. SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_SETPAGESIZE, 0, value_step);
  1984. value = SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_AVERAGE_SAMPLE), TBM_GETPOS, NULL, NULL);
  1985. wsprintf(tmp,"%3d",value);
  1986. ::SetWindowText(GetDlgItem( hwndDlg, IDC_STATIC_AVERAGE_SAMPLE_VALUE), tmp);
  1987. }
  1988.  
  1989. void AEncodeProperties::EnableAbrOptions(HWND hDialog, bool enable)
  1990. {
  1991. ::EnableWindow(::GetDlgItem( hDialog, IDC_SLIDER_AVERAGE_MIN), enable);
  1992. ::EnableWindow(::GetDlgItem( hDialog, IDC_SLIDER_AVERAGE_MAX), enable);
  1993. ::EnableWindow(::GetDlgItem( hDialog, IDC_SLIDER_AVERAGE_STEP), enable);
  1994. ::EnableWindow(::GetDlgItem( hDialog, IDC_SLIDER_AVERAGE_SAMPLE), enable);
  1995. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_MIN), enable);
  1996. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_MAX), enable);
  1997. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_STEP), enable);
  1998. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_SAMPLE), enable);
  1999. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_MIN_VALUE), enable);
  2000. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_MAX_VALUE), enable);
  2001. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_STEP_VALUE), enable);
  2002. ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_AVERAGE_SAMPLE_VALUE), enable);
  2003. }
  2004.