AEncodeProperties.cpp 57 KB

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