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