00001
00032
00033 #if !defined(STRICT)
00034 #define STRICT
00035 #endif // !defined(STRICT)
00036
00037 #include <windows.h>
00038 #include <windowsx.h>
00039 #include <shlobj.h>
00040 #include <assert.h>
00041
00042 #ifdef _MSC_VER
00043
00044 #pragma warning(disable: 4068)
00045 #endif
00046
00047 #include "resource.h"
00048 #include "AOut.h"
00049
00050 #include "AEncodeProperties.h"
00051
00052 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 };
00053 const unsigned int AEncodeProperties::the_MPEG1_Bitrates[14] = {320, 256, 224, 192, 160, 128, 112, 96, 80, 64, 56, 48, 40, 32 };
00054 const unsigned int AEncodeProperties::the_MPEG2_Bitrates[14] = {160, 144, 128, 112, 96, 80, 64, 56, 48, 40, 32, 24, 16, 8};
00055 const unsigned int AEncodeProperties::the_ChannelModes[] = {BE_MP3_MODE_MONO, BE_MP3_MODE_STEREO, BE_MP3_MODE_JSTEREO, BE_MP3_MODE_DUALCHANNEL };
00056
00057 const LAME_QUALTIY_PRESET AEncodeProperties::the_Presets[] = {LQP_NOPRESET, LQP_NORMAL_QUALITY, LQP_LOW_QUALITY, LQP_HIGH_QUALITY, LQP_VOICE_QUALITY, LQP_PHONE, LQP_SW, LQP_AM, LQP_FM, LQP_VOICE, LQP_RADIO, LQP_TAPE, LQP_HIFI, LQP_CD, LQP_STUDIO};
00058 const unsigned int AEncodeProperties::the_SamplingFreqs[9] = { 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000 };
00059
00060
00061
00062
00063 #pragma argsused
00064 static UINT CALLBACK DLLFindCallback(
00065 HWND hdlg,
00066 UINT uiMsg,
00067 WPARAM wParam,
00068 LPARAM lParam
00069 )
00070 {
00071 UINT result = 0;
00072
00073 switch (uiMsg)
00074 {
00075 case WM_NOTIFY:
00076 OFNOTIFY * info = (OFNOTIFY *)lParam;
00077 if (info->hdr.code == CDN_FILEOK)
00078 {
00079 result = 1;
00080
00081
00082 ALameDLL * tstFile = new ALameDLL;
00083 if (tstFile != NULL)
00084 {
00085 if (tstFile->Load(info->lpOFN->lpstrFile))
00086 {
00087 result = 0;
00088 }
00089
00090 delete tstFile;
00091 }
00092
00093 if (result == 1)
00094 {
00095 TCHAR output[250];
00096 ::LoadString(AOut::GetInstance(),IDS_STRING_DLL_UNRECOGNIZED,output,250);
00097 AOut::MyMessageBox( output, MB_OK|MB_ICONEXCLAMATION, hdlg);
00098 SetWindowLong(hdlg, DWL_MSGRESULT , -100);
00099 }
00100 }
00101 }
00102
00103 return result;
00104 }
00105
00106 #pragma argsused
00107 static int CALLBACK BrowseFolderCallbackroc(
00108 HWND hwnd,
00109 UINT uMsg,
00110 LPARAM lParam,
00111 LPARAM lpData
00112 )
00113 {
00114 AEncodeProperties * the_prop;
00115 the_prop = (AEncodeProperties *) lpData;
00116
00117
00118 if (uMsg == BFFM_INITIALIZED)
00119 {
00120
00121
00122
00123
00124
00125 ::SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)the_prop->GetOutputDirectory());
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 return 0;
00143 }
00144
00145 #pragma argsused
00146 static BOOL CALLBACK ConfigProc(
00147 HWND hwndDlg,
00148 UINT uMsg,
00149 WPARAM wParam,
00150 LPARAM lParam
00151 )
00152 {
00153 BOOL bResult;
00154 AEncodeProperties * the_prop;
00155 the_prop = (AEncodeProperties *) GetProp(hwndDlg, "AEncodeProperties-Config");
00156
00157 switch (uMsg) {
00158 case WM_COMMAND:
00159 if (the_prop != NULL)
00160 {
00161 bResult = the_prop->HandleDialogCommand( hwndDlg, wParam, lParam);
00162 }
00163 break;
00164 case WM_INITDIALOG:
00165 assert(the_prop == NULL);
00166
00167 the_prop = (AEncodeProperties *) lParam;
00168
00169 assert(the_prop != NULL);
00170
00171 SetProp(hwndDlg, "AEncodeProperties-Config", the_prop);
00172
00173 the_prop->InitConfigDlg(hwndDlg);
00174
00175 bResult = TRUE;
00176 break;
00177 case WM_HSCROLL:
00178
00179 if ((HWND)lParam == GetDlgItem(hwndDlg,IDC_SLIDER_QUALITY))
00180 {
00181 UINT VbrQuality = SendMessage(GetDlgItem( hwndDlg, IDC_SLIDER_QUALITY), TBM_GETPOS, NULL, NULL);
00182 char tmp[2];
00183 wsprintf(tmp,"%d",VbrQuality);
00184 ::SetWindowText(GetDlgItem( hwndDlg, IDC_CONFIG_QUALITY), tmp);
00185 }
00186 break;
00187 default:
00188 bResult = FALSE;
00189 }
00190 return bResult;
00191 }
00192
00194
00196
00199
00200
00201 const char * AEncodeProperties::GetChannelModeString(int a_channelID) const
00202 {
00203 assert(a_channelID < sizeof(the_ChannelModes));
00204
00205 switch (a_channelID) {
00206 case 0:
00207 return "Mono";
00208 case 1:
00209 return "Stereo";
00210 case 2:
00211 return "Joint-stereo";
00212 default:
00213 return "Dual Channel";
00214 }
00215 }
00216
00217 const int AEncodeProperties::GetBitrateString(char * string, int string_size, int a_bitrateID) const
00218 {
00219 assert(a_bitrateID < sizeof(the_Bitrates));
00220 assert(string != NULL);
00221
00222 if (string_size >= 4)
00223 return wsprintf(string,"%d",the_Bitrates[a_bitrateID]);
00224 else
00225 return -1;
00226 }
00227
00228 const unsigned int AEncodeProperties::GetChannelModeValue() const
00229 {
00230 assert(nChannelIndex < sizeof(the_ChannelModes));
00231
00232 return the_ChannelModes[nChannelIndex];
00233 }
00234
00235 const unsigned int AEncodeProperties::GetBitrateValue() const
00236 {
00237 assert(nMinBitrateIndex < sizeof(the_Bitrates));
00238
00239 return the_Bitrates[nMinBitrateIndex];
00240 }
00241
00242 inline const int AEncodeProperties::GetBitrateValueMPEG2(DWORD & bitrate) const
00243 {
00244 int i;
00245
00246 for (i=0;i<sizeof(the_MPEG2_Bitrates)/sizeof(unsigned int);i++)
00247 {
00248 if (the_MPEG2_Bitrates[i] == the_Bitrates[nMinBitrateIndex])
00249 {
00250 bitrate = the_MPEG2_Bitrates[i];
00251 return 0;
00252 }
00253 else if (the_MPEG2_Bitrates[i] < the_Bitrates[nMinBitrateIndex])
00254 {
00255 bitrate = the_MPEG2_Bitrates[i];
00256 return -1;
00257 }
00258 }
00259
00260 bitrate = 160;
00261 return -1;
00262 }
00263
00264 inline const int AEncodeProperties::GetBitrateValueMPEG1(DWORD & bitrate) const
00265 {
00266 int i;
00267
00268 for (i=sizeof(the_MPEG1_Bitrates)/sizeof(unsigned int)-1;i>=0;i--)
00269 {
00270 if (the_MPEG1_Bitrates[i] == the_Bitrates[nMinBitrateIndex])
00271 {
00272 bitrate = the_MPEG1_Bitrates[i];
00273 return 0;
00274 }
00275 else if (the_MPEG1_Bitrates[i] > the_Bitrates[nMinBitrateIndex])
00276 {
00277 bitrate = the_MPEG1_Bitrates[i];
00278 return 1;
00279 }
00280 }
00281
00282 bitrate = 32;
00283 return 1;
00284 }
00285
00286 const int AEncodeProperties::GetBitrateValue(DWORD & bitrate, const DWORD MPEG_Version) const
00287 {
00288 assert((MPEG_Version == MPEG1) || (MPEG_Version == MPEG2));
00289 assert(nMinBitrateIndex < sizeof(the_Bitrates));
00290
00291 if (MPEG_Version == MPEG2)
00292 return GetBitrateValueMPEG2(bitrate);
00293 else
00294 return GetBitrateValueMPEG1(bitrate);
00295 }
00296
00297 const char * AEncodeProperties::GetPresetModeString(const int a_presetID) const
00298 {
00299 assert(a_presetID < sizeof(the_Presets));
00300
00301 switch (a_presetID) {
00302 case 1:
00303 return "Normal";
00304 case 2:
00305 return "Low";
00306 case 3:
00307 return "High";
00308 case 4:
00309 return "Voice";
00310 case 5:
00311 return "Phone";
00312 case 6:
00313 return "SW";
00314 case 7:
00315 return "AM";
00316 case 8:
00317 return "FM";
00318 case 9:
00319 return "Voice";
00320 case 10:
00321 return "Radio";
00322 case 11:
00323 return "Tape";
00324 case 12:
00325 return "Hi-Fi";
00326 case 13:
00327 return "CD";
00328 case 14:
00329 return "Studio";
00330 default:
00331 return "None";
00332 }
00333 }
00334
00335 const LAME_QUALTIY_PRESET AEncodeProperties::GetPresetModeValue() const
00336 {
00337 assert(nPresetIndex < sizeof(the_Presets));
00338
00339 return the_Presets[nPresetIndex];
00340 }
00341
00342 bool AEncodeProperties::Config(const HINSTANCE Hinstance, const HWND HwndParent)
00343 {
00344
00345
00346
00347 hDllInstance = Hinstance;
00348
00349 return (::DialogBoxParam(Hinstance, MAKEINTRESOURCE(IDD_CONFIG), HwndParent, ::ConfigProc, (LPARAM) this) == 1);
00350 }
00351
00352 bool AEncodeProperties::InitConfigDlg(HWND HwndDlg)
00353 {
00354
00355
00356
00357
00358 int i;
00359
00360
00361 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_CHANNELS), CB_RESETCONTENT , NULL, NULL);
00362 for (i=0;i<GetChannelLentgh();i++)
00363 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_CHANNELS), CB_ADDSTRING, NULL, (LPARAM) GetChannelModeString(i));
00364
00365
00366 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_RESETCONTENT , NULL, NULL);
00367 char tmp[10];
00368 for (i=0;i<sizeof(the_SamplingFreqs)/sizeof(unsigned int);i++)
00369 {
00370 wsprintf(tmp, "%d", the_SamplingFreqs[i]);
00371 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_ADDSTRING, NULL, (LPARAM) tmp );
00372 }
00373
00374
00375
00376 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_RESETCONTENT , NULL, NULL);
00377 for (i=0;i<GetBitrateLentgh();i++)
00378 {
00379 GetBitrateString(tmp, 5, i);
00380 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_ADDSTRING, NULL, (LPARAM) tmp );
00381 }
00382
00383
00384 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_RESETCONTENT , NULL, NULL);
00385 for (i=0;i<GetBitrateLentgh();i++)
00386 {
00387 GetBitrateString(tmp, 5, i);
00388 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_ADDSTRING, NULL, (LPARAM) tmp );
00389 }
00390
00391
00392 SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_SETRANGE, TRUE, MAKELONG(0,9));
00393
00394
00395 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_RESETCONTENT , NULL, NULL);
00396 for (i=0;i<GetPresetLentgh();i++)
00397 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_ADDSTRING, NULL, (LPARAM) GetPresetModeString(i));
00398
00399 UpdateConfigs(HwndDlg);
00400
00401 UpdateDlgFromValue(HwndDlg);
00402
00403 return true;
00404 }
00405
00406 bool AEncodeProperties::UpdateDlgFromValue(HWND HwndDlg)
00407 {
00408
00409
00410
00411
00412 int i;
00413
00414
00415 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_CRC), BM_SETCHECK, GetCRCMode() ?BST_CHECKED:BST_UNCHECKED, NULL);
00416 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_ORIGINAL), BM_SETCHECK, GetOriginalMode() ?BST_CHECKED:BST_UNCHECKED, NULL);
00417 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_PRIVATE), BM_SETCHECK, GetPrivateMode() ?BST_CHECKED:BST_UNCHECKED, NULL);
00418 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_COPYRIGHT), BM_SETCHECK, GetCopyrightMode()?BST_CHECKED:BST_UNCHECKED, NULL);
00419 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_RESERVOIR), BM_SETCHECK, !GetNoBiResMode() ?BST_CHECKED:BST_UNCHECKED, NULL);
00420 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_VBR), BM_SETCHECK, GetVBRUseMode() ?BST_CHECKED:BST_UNCHECKED, NULL);
00421 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_XINGVBR), BM_SETCHECK, GetXingFrameMode()?BST_CHECKED:BST_UNCHECKED, NULL);
00422 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_RESAMPLE), BM_SETCHECK, GetResampleMode() ?BST_CHECKED:BST_UNCHECKED, NULL);
00423 SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_CHANNELFORCE), BM_SETCHECK, bForceChannel ?BST_CHECKED:BST_UNCHECKED, NULL);
00424
00425
00426 for (i=0;i<GetChannelLentgh();i++)
00427 {
00428 if (i == nChannelIndex)
00429 {
00430 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_CHANNELS), CB_SETCURSEL, i, NULL);
00431 break;
00432 }
00433 }
00434
00435
00436 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_SETCURSEL, nSamplingFreqIndex, NULL);
00437
00438
00439
00440 for (i=0;i<GetBitrateLentgh();i++)
00441 {
00442 if (i == nMinBitrateIndex)
00443 {
00444 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_SETCURSEL, i, NULL);
00445 break;
00446 }
00447 }
00448
00449
00450 for (i=0;i<GetBitrateLentgh();i++)
00451 {
00452 if (i == nMaxBitrateIndex)
00453 {
00454 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_SETCURSEL, i, NULL);
00455 break;
00456 }
00457 }
00458
00459
00460
00461
00462 char tmp[3];
00463 wsprintf(tmp,"%d",VbrQuality);
00464 SetWindowText(GetDlgItem( HwndDlg, IDC_CONFIG_QUALITY), tmp);
00465 SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_SETPOS, TRUE, VbrQuality);
00466
00467
00468
00469 if (GetVBRUseMode())
00470 {
00471 AEncodeProperties::DisplayVbrOptions(HwndDlg, true);
00472 }
00473 else
00474 {
00475 AEncodeProperties::DisplayVbrOptions(HwndDlg, false);
00476 }
00477
00478
00479 if (GetResampleMode())
00480 {
00481 ::EnableWindow(::GetDlgItem(HwndDlg,IDC_COMBO_SAMPLEFREQ), TRUE);
00482 }
00483 else
00484 {
00485 ::EnableWindow(::GetDlgItem(HwndDlg,IDC_COMBO_SAMPLEFREQ), FALSE);
00486 }
00487
00488
00489
00490 for (i=0;i<GetPresetLentgh();i++)
00491 {
00492 if (i == nPresetIndex)
00493 {
00494 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_SETCURSEL, i, NULL);
00495 break;
00496 }
00497 }
00498
00499
00500
00501 ::SetWindowText(::GetDlgItem( HwndDlg, IDC_EDIT_OUTPUTDIR), OutputDir.c_str());
00502
00506 #ifdef OLD
00507 AParameters prms;
00508
00509 prms.Attach("SOFTWARE\\MUKOLI\\out_lame\\Configs");
00510
00511 char currentName[MAX_PATH];
00512 unsigned long DSize = MAX_PATH;
00513 prms.QueryValue("current", currentName, DSize);
00514
00515 char string[MAX_PATH];
00516
00517
00518 while (prms.NextSubKey( string, MAX_PATH) == AParameters::KEY_FOUND)
00519 {
00520 AParameters * tmpkey = prms.GetSubKey(string);
00521
00522 char string2[MAX_PATH];
00523 unsigned long DSize = MAX_PATH;
00524
00525 tmpkey->QueryValue("Name", string2, DSize);
00526
00527 prms.ReleaseSubKey(tmpkey);
00528
00529 if (strcmp(string,currentName) == 0)
00530 {
00531 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_SETCURSEL, i, NULL);
00532 break;
00533 }
00534
00535 i++;
00536 }
00537
00538 prms.Detach();
00539 #endif // OLD
00540
00541 return true;
00542 }
00543
00544 bool AEncodeProperties::UpdateValueFromDlg(HWND HwndDlg)
00545 {
00546 nChannelIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_CHANNELS), CB_GETCURSEL, NULL, NULL);
00547 nMinBitrateIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_BITRATE), CB_GETCURSEL, NULL, NULL);
00548 nMaxBitrateIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_MAXBITRATE), CB_GETCURSEL, NULL, NULL);
00549 nPresetIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_PRESET), CB_GETCURSEL, NULL, NULL);
00550 VbrQuality = SendMessage(GetDlgItem( HwndDlg, IDC_SLIDER_QUALITY), TBM_GETPOS , NULL, NULL);
00551 nSamplingFreqIndex = SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SAMPLEFREQ), CB_GETCURSEL, NULL, NULL);
00552
00553 bCRC = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_CRC), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00554 bCopyright = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_COPYRIGHT), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00555 bOriginal = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_ORIGINAL), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00556 bPrivate = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_PRIVATE), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00557 bNoBitRes =!(SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_RESERVOIR), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00558 bVBRused = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_VBR), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00559 bXingFrame = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_XINGVBR), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00560 bResample = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_RESAMPLE), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00561 bForceChannel = (SendMessage(GetDlgItem( HwndDlg, IDC_CHECK_CHANNELFORCE), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
00562
00563 char tmpPath[MAX_PATH];
00564 ::GetWindowText( ::GetDlgItem( HwndDlg, IDC_EDIT_OUTPUTDIR), tmpPath, MAX_PATH);
00565 OutputDir = tmpPath;
00566
00567
00568
00569
00570 return true;
00571 }
00572
00573 bool AEncodeProperties::GetVBRValue(DWORD & MaxBitrate, int & Quality, BOOL & VBRHeader, const DWORD MPEG_Version) const
00574 {
00575 assert((MPEG_Version == MPEG1) || (MPEG_Version == MPEG2));
00576 assert(nMaxBitrateIndex < sizeof(the_Bitrates));
00577
00578 if (bVBRused)
00579 {
00580 MaxBitrate = the_Bitrates[nMaxBitrateIndex];
00581
00582 if (MPEG_Version == MPEG1)
00583 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];
00584 else
00585 MaxBitrate = MaxBitrate<the_MPEG2_Bitrates[0]?MaxBitrate:the_MPEG2_Bitrates[0];
00586
00587 VBRHeader = bXingFrame;
00588 Quality = VbrQuality;
00589 }
00590
00591 return bVBRused;
00592
00593 }
00594
00595 void AEncodeProperties::ParamsRestore()
00596 {
00597
00598 bCopyright = true;
00599 bCRC = true;
00600 bOriginal = true;
00601 bPrivate = true;
00602 bNoBitRes = false;
00603 bVBRused = false;
00604 bXingFrame = true;
00605 bResample = false;
00606 bForceChannel = false;
00607
00608 nChannelIndex = 2;
00609 nMinBitrateIndex = 6;
00610 nMaxBitrateIndex = 4;
00611 nPresetIndex = 0;
00612 VbrQuality = 1;
00613 nSamplingFreqIndex = 1;
00614
00615 OutputDir = "c:\\";
00616
00617 DllLocation = "plugins\\lame_enc.dll";
00618
00619
00620 if (my_stored_data.LoadFile(my_store_location))
00621 {
00622 TiXmlNode* node;
00623
00624 node = my_stored_data.FirstChild("out_lame");
00625
00626 TiXmlElement* CurrentNode = node->FirstChildElement("configs");
00627
00628 std::string CurrentConfig = "";
00629
00630 if (CurrentNode->Attribute("default") != NULL)
00631 {
00632 CurrentConfig = *CurrentNode->Attribute("default");
00633 }
00634
00635
00636 TiXmlElement* iterateElmt = node->FirstChildElement("DLL");
00637 if (iterateElmt != NULL)
00638 {
00639 const std::string * tmpname = iterateElmt->Attribute("location");
00640 if (tmpname != NULL)
00641 {
00642 DllLocation = *tmpname;
00643 }
00644 }
00645
00646 GetValuesFromKey(CurrentConfig, *CurrentNode);
00647 }
00648 else
00649 {
00653 }
00654 }
00655
00656 void AEncodeProperties::ParamsSave()
00657 {
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 }
00677
00678 void AEncodeProperties::DisplayVbrOptions(HWND hDialog, bool bValue)
00679 {
00680 if(bValue)
00681 {
00682 ::SetWindowText(::GetDlgItem(hDialog,IDC_STATIC_MINBITRATE), "Min Bitrate");
00683 }
00684 else
00685 {
00686 ::SetWindowText(::GetDlgItem(hDialog,IDC_STATIC_MINBITRATE), "Bitrate");
00687 }
00688
00689 ::EnableWindow(::GetDlgItem( hDialog, IDC_CHECK_XINGVBR), bValue);
00690
00691 ::EnableWindow(::GetDlgItem( hDialog, IDC_COMBO_MAXBITRATE), bValue);
00692
00693 ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_MAXBITRATE), bValue);
00694
00695 ::EnableWindow(::GetDlgItem( hDialog, IDC_SLIDER_QUALITY), bValue);
00696
00697 ::EnableWindow(::GetDlgItem( hDialog, IDC_CONFIG_QUALITY), bValue);
00698
00699 ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_VBRQUALITY), bValue);
00700
00701 ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_VBRQUALITY_LOW), bValue);
00702
00703 ::EnableWindow(::GetDlgItem( hDialog, IDC_STATIC_VBRQUALITY_HIGH), bValue);
00704
00705 }
00706
00707 AEncodeProperties::AEncodeProperties()
00708 {
00709 std::string path = "";
00710 HMODULE htmp = LoadLibrary("out_lame.dll");
00711 if (htmp != NULL)
00712 {
00713 char output[MAX_PATH];
00714 ::GetModuleFileName(htmp, output, MAX_PATH);
00715 ::FreeLibrary(htmp);
00716
00717 path = output;
00718 }
00719 my_store_location = path.substr(0,path.find_last_of('\\')+1);
00720 my_store_location += "out_lame.xml";
00721
00722
00723
00724 HANDLE hFile = ::CreateFile(my_store_location.c_str(), 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL );
00725 ::CloseHandle(hFile);
00726 }
00727
00728
00729 void AEncodeProperties::SaveValuesToStringKey(const std::string & config_name)
00730 {
00731
00732 if (my_stored_data.LoadFile(my_store_location))
00733 {
00734
00735 TiXmlNode* node = my_stored_data.FirstChild("out_lame");
00736
00737 if (node != NULL)
00738 {
00739 TiXmlElement* ConfigNode = node->FirstChildElement("configs");
00740
00741 if (ConfigNode != NULL)
00742 {
00743
00744 TiXmlElement* tmpNode = ConfigNode->FirstChildElement("config");
00745 while (tmpNode != NULL)
00746 {
00747 const std::string * tmpname = tmpNode->Attribute("name");
00748 if (tmpname->compare(config_name) == 0)
00749 {
00750 break;
00751 }
00752 tmpNode = tmpNode->NextSiblingElement("config");
00753 }
00754
00755 if (tmpNode == NULL)
00756 {
00757
00758 tmpNode = new TiXmlElement("config");
00759 tmpNode->SetAttribute("name",config_name);
00760
00761
00762 SaveValuesToElement(tmpNode);
00763
00764 ConfigNode->InsertEndChild(*tmpNode);
00765 }
00766 else
00767 {
00768
00769 SaveValuesToElement(tmpNode);
00770 }
00771
00772
00773
00774 my_stored_data.SaveFile(my_store_location);
00775 }
00776 }
00777 }
00778 }
00779
00780 void AEncodeProperties::GetValuesFromKey(const std::string & config_name, const TiXmlNode & parentNode)
00781 {
00782 TiXmlElement* tmpElt;
00783 TiXmlElement* iterateElmt;
00784
00785
00786 iterateElmt = parentNode.FirstChildElement("config");
00787 while (iterateElmt != NULL)
00788 {
00789 const std::string * tmpname = iterateElmt->Attribute("name");
00790 if ((tmpname != NULL) && (tmpname->compare(config_name) == 0))
00791 {
00792 break;
00793 }
00794 iterateElmt = iterateElmt->NextSiblingElement("config");
00795 }
00796
00797 if (iterateElmt != NULL)
00798 {
00799
00800 const std::string * tmpname;
00801
00802
00803 tmpElt = iterateElmt->FirstChildElement("Copyright");
00804 if (tmpElt != NULL)
00805 {
00806 tmpname = tmpElt->Attribute("use");
00807 if (tmpname != NULL)
00808 bCopyright = (tmpname->compare("true") == 0);
00809 }
00810
00811
00812 tmpElt = iterateElmt->FirstChildElement("CRC");
00813 if (tmpElt != NULL)
00814 {
00815 tmpname = tmpElt->Attribute("use");
00816 if (tmpname != NULL)
00817 bCRC = (tmpname->compare("true") == 0);
00818 }
00819
00820
00821 tmpElt = iterateElmt->FirstChildElement("Original");
00822 if (tmpElt != NULL)
00823 {
00824 tmpname = tmpElt->Attribute("use");
00825 if (tmpname != NULL)
00826 bOriginal = (tmpname->compare("true") == 0);
00827 }
00828
00829
00830 tmpElt = iterateElmt->FirstChildElement("Private");
00831 if (tmpElt != NULL)
00832 {
00833 tmpname = tmpElt->Attribute("use");
00834 if (tmpname != NULL)
00835 bPrivate = (tmpname->compare("true") == 0);
00836 }
00837
00838
00839 tmpElt = iterateElmt->FirstChildElement("Bit_reservoir");
00840 if (tmpElt != NULL)
00841 {
00842 tmpname = tmpElt->Attribute("use");
00843 if (tmpname != NULL)
00844 bNoBitRes = !(tmpname->compare("true") == 0);
00845 }
00846
00847
00848 tmpElt = iterateElmt->FirstChildElement("bitrate");
00849 tmpname = tmpElt->Attribute("min");
00850 if (tmpname != NULL)
00851 {
00852 unsigned int uitmp = atoi(tmpname->c_str());
00853 for (int i=0;i<sizeof(the_Bitrates)/sizeof(unsigned int);i++)
00854 {
00855 if (the_Bitrates[i] == uitmp)
00856 {
00857 nMinBitrateIndex = i;
00858 break;
00859 }
00860 }
00861 }
00862
00863 tmpname = tmpElt->Attribute("max");
00864 if (tmpname != NULL)
00865 {
00866 unsigned int uitmp = atoi(tmpname->c_str());
00867 for (int i=0;i<sizeof(the_Bitrates)/sizeof(unsigned int);i++)
00868 {
00869 if (the_Bitrates[i] == uitmp)
00870 {
00871 nMaxBitrateIndex = i;
00872 break;
00873 }
00874 }
00875 }
00876
00877
00878 tmpElt = iterateElmt->FirstChildElement("resampling");
00879 if (tmpElt != NULL)
00880 {
00881 tmpname = tmpElt->Attribute("use");
00882 if (tmpname != NULL)
00883 bResample = (tmpname->compare("true") == 0);
00884
00885 unsigned int uitmp = atoi(tmpElt->Attribute("freq")->c_str());
00886 for (int i=0;i<sizeof(the_SamplingFreqs)/sizeof(unsigned int);i++)
00887 {
00888 if (the_SamplingFreqs[i] == uitmp)
00889 {
00890 nSamplingFreqIndex = i;
00891 break;
00892 }
00893 }
00894 }
00895
00896
00897 tmpElt = iterateElmt->FirstChildElement("VBR");
00898 if (tmpElt != NULL)
00899 {
00900 tmpname = tmpElt->Attribute("use");
00901 if (tmpname != NULL)
00902 bVBRused = (tmpname->compare("true") == 0);
00903
00904 tmpname = tmpElt->Attribute("header");
00905 if (tmpname != NULL)
00906 bXingFrame = (tmpname->compare("true") == 0);
00907
00908 tmpname = tmpElt->Attribute("quality");
00909 if (tmpname != NULL)
00910 {
00911 VbrQuality = atoi(tmpname->c_str());
00912 }
00913 }
00914
00915
00916 tmpElt = iterateElmt->FirstChildElement("output");
00917 if (tmpElt != NULL)
00918 {
00919 OutputDir = *tmpElt->Attribute("path");
00920 }
00921
00922
00923 tmpElt = iterateElmt->FirstChildElement("Channel");
00924 if (tmpElt != NULL)
00925 {
00926 const std::string * tmpStr = tmpElt->Attribute("mode");
00927 for (int i=0;i<GetChannelLentgh();i++)
00928 {
00929 if (tmpStr->compare(GetChannelModeString(i)) == 0)
00930 {
00931 nChannelIndex = i;
00932 break;
00933 }
00934 }
00935
00936 tmpname = tmpElt->Attribute("force");
00937 if (tmpname != NULL)
00938 bForceChannel = (tmpname->compare("true") == 0);
00939 }
00940
00941
00942 tmpElt = iterateElmt->FirstChildElement("Preset");
00943 if (tmpElt != NULL)
00944 {
00945 const std::string * tmpStr = tmpElt->Attribute("type");
00946 for (int i=0;i<GetPresetLentgh();i++)
00947 {
00948 if (tmpStr->compare(GetPresetModeString(i)) == 0)
00949 {
00950 nPresetIndex = i;
00951 break;
00952 }
00953 }
00954
00955 }
00956
00957 }
00958 }
00959
00963 void AEncodeProperties::SaveParams(const HWND hParentWnd)
00964 {
00965 char string[MAX_PATH];
00966 int nIdx = SendMessage(::GetDlgItem( hParentWnd ,IDC_COMBO_SETTINGS ), CB_GETCURSEL, NULL, NULL);
00967 ::SendMessage(::GetDlgItem( hParentWnd ,IDC_COMBO_SETTINGS ), CB_GETLBTEXT , nIdx, (LPARAM) string);
00968
00969 #ifdef OLD
00970 AParameters prms;
00971
00972 prms.Attach("SOFTWARE\\MUKOLI\\out_lame\\Configs");
00973 prms.ResetSubKey();
00974
00975 bool bFound = false;
00976 char keystring[MAX_PATH];
00977 AParameters * subkey;
00978 char keyName[MAX_PATH];
00979 while (prms.NextSubKey(keystring, MAX_PATH) == AParameters::KEY_FOUND)
00980 {
00981 subkey = prms.GetSubKey(keystring);
00982 unsigned long DSize = MAX_PATH;
00983 subkey->QueryValue("Name", keyName, DSize);
00984
00985 if (strcmp(keyName,string) == 0)
00986 {
00987
00988
00989
00990
00991
00992
00993
00994
00995 bFound = true;
00996 break;
00997 }
00998
00999 prms.ReleaseSubKey(subkey);
01000 }
01001
01002 assert(bFound);
01003
01004
01005 prms.SetValueString("current",keystring);
01006
01007
01008
01009
01010
01011
01012
01013
01014 if (strcmp(keystring,"Current") != 0)
01015 {
01016 AEncodeProperties tmpProperties;
01017 tmpProperties.GetValuesFromKey(*subkey);
01018
01019 assert(should not use the subkey of another class...);
01020
01021 if (tmpProperties != this)
01022 {
01023 TCHAR tmpout[250],output[250];
01024 ::LoadString(AOut::GetInstance(),IDS_STRING_SAVE_PARAMS,tmpout,250);
01025 wsprintf(output,"%s\"%s\" ?",tmpout,keyName);
01026 if (AOut::MyMessageBox( output, MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL, hParentWnd) != IDYES)
01027 {
01028
01029 prms.SetValueString("current","Current");
01030
01031 subkey = prms.GetSubKey("Current");
01032 }
01033
01034 SaveValuesToKey(*subkey);
01035 }
01036 tmpProperties.output();
01037 this->output();
01038
01039 }
01040 else
01041 {
01042 SaveValuesToKey(*subkey);
01043 }
01044 prms.ReleaseSubKey(subkey);
01045
01046 prms.Detach();
01047 #endif // OLD
01048 }
01049
01050 bool AEncodeProperties::operator !=(const AEncodeProperties & the_instance) const
01051 {
01052 return ((bCopyright != the_instance.bCopyright)
01053 || (bCRC != the_instance.bCRC)
01054 || (bOriginal != the_instance.bOriginal)
01055 || (bPrivate != the_instance.bPrivate)
01056 || (bNoBitRes != the_instance.bNoBitRes)
01057 || (bVBRused != the_instance.bVBRused)
01058 || (bXingFrame != the_instance.bXingFrame)
01059 || (bForceChannel != the_instance.bForceChannel)
01060 || (bResample != the_instance.bResample)
01061 || (nChannelIndex != the_instance.nChannelIndex)
01062 || (nMinBitrateIndex != the_instance.nMinBitrateIndex)
01063 || (nMaxBitrateIndex != the_instance.nMaxBitrateIndex)
01064 || (nPresetIndex != the_instance.nPresetIndex)
01065 || (VbrQuality != the_instance.VbrQuality)
01066 || (nSamplingFreqIndex != the_instance.nSamplingFreqIndex)
01067 || (OutputDir.compare(the_instance.OutputDir) != 0)
01068 );
01069 }
01070
01071 void AEncodeProperties::SelectSavedParams(const std::string the_string)
01072 {
01073
01074 if (my_stored_data.LoadFile(my_store_location))
01075 {
01076 TiXmlNode* node;
01077
01078 node = my_stored_data.FirstChild("out_lame");
01079
01080 TiXmlElement* CurrentNode = node->FirstChildElement("configs");
01081
01082 if (CurrentNode != NULL)
01083 {
01084 CurrentNode->SetAttribute("default",the_string);
01085 GetValuesFromKey(the_string, *CurrentNode);
01086 my_stored_data.SaveFile(my_store_location);
01087 }
01088 }
01089 }
01090
01091 inline void AEncodeProperties::SetAttributeBool(TiXmlElement * the_elt,const std::string & the_string, const bool the_value) const
01092 {
01093 if (the_value == false)
01094 the_elt->SetAttribute(the_string, "false");
01095 else
01096 the_elt->SetAttribute(the_string, "true");
01097 }
01098
01099 void AEncodeProperties::SaveValuesToElement(TiXmlElement * the_element) const
01100 {
01101
01102 TiXmlElement * tmpElt;
01103
01104
01105 tmpElt = the_element->FirstChildElement("Bit_reservoir");
01106 if (tmpElt == NULL)
01107 {
01108 tmpElt = new TiXmlElement("Bit_reservoir");
01109 SetAttributeBool(tmpElt, "use", !bNoBitRes);
01110 the_element->InsertEndChild(*tmpElt);
01111 }
01112 else
01113 {
01114 SetAttributeBool(tmpElt, "use", !bNoBitRes);
01115 }
01116
01117
01118 tmpElt = the_element->FirstChildElement("Copyright");
01119 if (tmpElt == NULL)
01120 {
01121 tmpElt = new TiXmlElement("Copyright");
01122 SetAttributeBool( tmpElt, "use", bCopyright);
01123 the_element->InsertEndChild(*tmpElt);
01124 }
01125 else
01126 {
01127 SetAttributeBool( tmpElt, "use", bCopyright);
01128 }
01129
01130
01131 tmpElt = the_element->FirstChildElement("CRC");
01132 if (tmpElt == NULL)
01133 {
01134 tmpElt = new TiXmlElement("CRC");
01135 SetAttributeBool( tmpElt, "use", bCRC);
01136 the_element->InsertEndChild(*tmpElt);
01137 }
01138 else
01139 {
01140 SetAttributeBool( tmpElt, "use", bCRC);
01141 }
01142
01143
01144 tmpElt = the_element->FirstChildElement("Original");
01145 if (tmpElt == NULL)
01146 {
01147 tmpElt = new TiXmlElement("Original");
01148 SetAttributeBool( tmpElt, "use", bOriginal);
01149 the_element->InsertEndChild(*tmpElt);
01150 }
01151 else
01152 {
01153 SetAttributeBool( tmpElt, "use", bOriginal);
01154 }
01155
01156
01157 tmpElt = the_element->FirstChildElement("Private");
01158 if (tmpElt == NULL)
01159 {
01160 tmpElt = new TiXmlElement("Private");
01161 SetAttributeBool( tmpElt, "use", bPrivate);
01162 the_element->InsertEndChild(*tmpElt);
01163 }
01164 else
01165 {
01166 SetAttributeBool( tmpElt, "use", bPrivate);
01167 }
01168
01169
01170 tmpElt = the_element->FirstChildElement("Channel");
01171 if (tmpElt == NULL)
01172 {
01173 tmpElt = new TiXmlElement("Channel");
01174 tmpElt->SetAttribute("mode", GetChannelModeString(nChannelIndex));
01175 SetAttributeBool( tmpElt, "force", bForceChannel);
01176 the_element->InsertEndChild(*tmpElt);
01177 }
01178 else
01179 {
01180 tmpElt->SetAttribute("mode", GetChannelModeString(nChannelIndex));
01181 SetAttributeBool( tmpElt, "force", bForceChannel);
01182 }
01183
01184
01185 tmpElt = the_element->FirstChildElement("Preset");
01186 if (tmpElt == NULL)
01187 {
01188 tmpElt = new TiXmlElement("Preset");
01189 tmpElt->SetAttribute("type", GetPresetModeString(nPresetIndex));
01190 the_element->InsertEndChild(*tmpElt);
01191 }
01192 else
01193 {
01194 tmpElt->SetAttribute("type", GetPresetModeString(nPresetIndex));
01195 }
01196
01197
01198 tmpElt = the_element->FirstChildElement("bitrate");
01199 if (tmpElt == NULL)
01200 {
01201 tmpElt = new TiXmlElement("bitrate");
01202 tmpElt->SetAttribute("min", the_Bitrates[nMinBitrateIndex]);
01203 tmpElt->SetAttribute("max", the_Bitrates[nMaxBitrateIndex]);
01204 the_element->InsertEndChild(*tmpElt);
01205 }
01206 else
01207 {
01208 tmpElt->SetAttribute("min", the_Bitrates[nMinBitrateIndex]);
01209 tmpElt->SetAttribute("max", the_Bitrates[nMaxBitrateIndex]);
01210 }
01211
01212
01213 tmpElt = the_element->FirstChildElement("output");
01214 if (tmpElt == NULL)
01215 {
01216 tmpElt = new TiXmlElement("output");
01217 tmpElt->SetAttribute("path", OutputDir);
01218 the_element->InsertEndChild(*tmpElt);
01219 }
01220 else
01221 {
01222 tmpElt->SetAttribute("path", OutputDir);
01223 }
01224
01225
01226 tmpElt = the_element->FirstChildElement("resampling");
01227 if (tmpElt == NULL)
01228 {
01229 tmpElt = new TiXmlElement("resampling");
01230 SetAttributeBool( tmpElt, "use", bResample);
01231 tmpElt->SetAttribute("freq", the_SamplingFreqs[nSamplingFreqIndex]);
01232 the_element->InsertEndChild(*tmpElt);
01233 }
01234 else
01235 {
01236 SetAttributeBool( tmpElt, "use", bResample);
01237 tmpElt->SetAttribute("freq", the_SamplingFreqs[nSamplingFreqIndex]);
01238 }
01239
01240
01241 tmpElt = the_element->FirstChildElement("VBR");
01242 if (tmpElt == NULL)
01243 {
01244 tmpElt = new TiXmlElement("VBR");
01245 SetAttributeBool( tmpElt, "use", bVBRused);
01246 SetAttributeBool( tmpElt, "header", bXingFrame);
01247 tmpElt->SetAttribute("quality", VbrQuality);
01248 the_element->InsertEndChild(*tmpElt);
01249 }
01250 else
01251 {
01252 SetAttributeBool( tmpElt, "use", bVBRused);
01253 SetAttributeBool( tmpElt, "header", bXingFrame);
01254 tmpElt->SetAttribute("quality", VbrQuality);
01255 }
01256
01257 }
01258
01259 bool AEncodeProperties::HandleDialogCommand(const HWND parentWnd, const WPARAM wParam, const LPARAM lParam)
01260 {
01261 UINT command;
01262 command = GET_WM_COMMAND_ID(wParam, lParam);
01263
01264 switch (command)
01265 {
01266 case IDOK :
01267 {
01268 bool bShouldEnd = true;
01269
01270
01271 char string[MAX_PATH];
01272 ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
01273
01274 AEncodeProperties tmpDlgProps;
01275 tmpDlgProps.UpdateValueFromDlg(parentWnd);
01276
01277 AEncodeProperties tmpSavedProps;
01278 tmpSavedProps.SelectSavedParams(string);
01279 tmpSavedProps.ParamsRestore();
01280
01281
01282 if (tmpDlgProps != tmpSavedProps)
01283 {
01284 int save;
01285
01286 if (strcmp(string,"Current") == 0)
01287 {
01288
01289 TCHAR tmpStr[250];
01290 ::LoadString(AOut::GetInstance(),IDS_STRING_PROMPT_REPLACE_CURRENT,tmpStr,250);
01291
01292 save = AOut::MyMessageBox( tmpStr, MB_OKCANCEL|MB_ICONQUESTION, parentWnd);
01293 }
01294 else
01295 {
01296
01297 TCHAR tmpStr[250];
01298 ::LoadString(AOut::GetInstance(),IDS_STRING_PROMPT_REPLACE_SETING,tmpStr,250);
01299 TCHAR tmpDsp[500];
01300 wsprintf(tmpDsp,tmpStr,string);
01301
01302 save = AOut::MyMessageBox( tmpDsp, MB_YESNOCANCEL|MB_ICONQUESTION, parentWnd);
01303 }
01304
01305 if (save == IDCANCEL)
01306 bShouldEnd = false;
01307 else if (save == IDNO)
01308 {
01309
01310 UpdateValueFromDlg(parentWnd);
01311 SaveValuesToStringKey("Current");
01312 SelectSavedParams("Current");
01313 }
01314 else
01315 {
01316
01317 UpdateValueFromDlg(parentWnd);
01318 SaveValuesToStringKey(string);
01319 }
01320 }
01321 SaveParams(parentWnd);
01322
01323 if (bShouldEnd)
01324 {
01325 RemoveProp(parentWnd, "AEncodeProperties-Config");
01326
01327 EndDialog(parentWnd, true);
01328 }
01329 }
01330 break;
01331
01332 case IDCANCEL:
01333 RemoveProp(parentWnd, "AEncodeProperties-Config");
01334 EndDialog(parentWnd, false);
01335 break;
01336
01337 case IDC_FIND_DLL:
01338 {
01339 OPENFILENAME file;
01340 char DllLocation[512];
01341 wsprintf(DllLocation,"%s",GetDllLocation());
01342
01343 memset(&file, 0, sizeof(file));
01344 file.lStructSize = sizeof(file);
01345 file.hwndOwner = parentWnd;
01346 file.Flags = OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_ENABLEHOOK | OFN_EXPLORER ;
01348 file.lpstrFile = DllLocation;
01349 file.lpstrFilter = "Lame DLL (lame_enc.dll)\0LAME_ENC.DLL\0DLL (*.dll)\0*.DLL\0All (*.*)\0*.*\0";
01350 file.nFilterIndex = 1;
01351 file.nMaxFile = sizeof(DllLocation);
01352 file.lpfnHook = DLLFindCallback;
01353
01354 GetOpenFileName(&file);
01355
01356 SetDllLocation(DllLocation);
01357
01358 }
01359 break;
01360
01361 case IDC_BUTTON_OUTPUT:
01362 {
01363 #ifndef SIMPLE_FOLDER
01364 BROWSEINFO info;
01365 memset(&info,0,sizeof(info));
01366
01367 char FolderName[MAX_PATH];
01368
01369 info.hwndOwner = parentWnd;
01370 info.pszDisplayName = FolderName;
01371 info.lpfn = BrowseFolderCallbackroc;
01372 info.lParam = (LPARAM) this;
01373
01374
01375 TCHAR output[250];
01376 ::LoadString(AOut::GetInstance(),IDS_STRING_DIR_SELECT,output,250);
01377 info.lpszTitle = output;
01378
01379 #ifdef BIF_EDITBOX
01380 info.ulFlags |= BIF_EDITBOX;
01381 #else // BIF_EDITBOX
01382 info.ulFlags |= 0x0010;
01383 #endif // BIF_EDITBOX
01384
01385 #ifdef BIF_VALIDATE
01386 info.ulFlags |= BIF_VALIDATE;
01387 #else // BIF_VALIDATE
01388 info.ulFlags |= 0x0020;
01389 #endif // BIF_VALIDATE
01390
01391 #ifdef BIF_NEWDIALOGSTYLE
01392 info.ulFlags |= BIF_NEWDIALOGSTYLE;
01393 #else // BIF_NEWDIALOGSTYLE
01394 info.ulFlags |= 0x0040;
01395 #endif // BIF_NEWDIALOGSTYLE
01396
01397 ITEMIDLIST *item = SHBrowseForFolder(&info);
01398
01399 if (item != NULL)
01400 {
01401 char tmpOutputDir[MAX_PATH];
01402 wsprintf(tmpOutputDir,"%s",GetOutputDirectory());
01403
01404 SHGetPathFromIDList( item,tmpOutputDir );
01405 SetOutputDirectory( tmpOutputDir );
01406 ::SetWindowText(GetDlgItem( parentWnd, IDC_EDIT_OUTPUTDIR), tmpOutputDir);
01407
01408 }
01409 #else // SIMPLE_FOLDER
01410 OPENFILENAME file;
01411
01412 memset(&file, 0, sizeof(file));
01413 file.lStructSize = sizeof(file);
01414 file.hwndOwner = parentWnd;
01415 file.Flags = OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_ENABLEHOOK | OFN_EXPLORER ;
01416
01417
01418 file.lpstrInitialDir = GetOutputDirectory();
01419 file.lpstrFilter = "A Directory\0.*\0";
01420
01421 file.nMaxFile = MAX_PATH;
01422
01423
01424 file.Flags = OFN_NOREADONLYRETURN | OFN_HIDEREADONLY | OFN_EXPLORER;
01425
01426 TCHAR output[250];
01427 ::LoadString(AOut::GetInstance(),IDS_STRING_DIR_SELECT,output,250);
01428 file.lpstrTitle = output;
01429
01430 GetSaveFileName(&file);
01431 #endif // SIMPLE_FOLDER
01432 }
01433 break;
01434
01435 case IDC_CHECK_VBR:
01436 {
01437 bool tmp_bVBRused = (SendMessage(GetDlgItem( parentWnd, IDC_CHECK_VBR), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
01438 if (tmp_bVBRused)
01439 {
01440 AEncodeProperties::DisplayVbrOptions(parentWnd, true);
01441 }
01442 else
01443 {
01444 AEncodeProperties::DisplayVbrOptions(parentWnd, false);
01445 }
01446 }
01447 break;
01448
01449 case IDC_CHECK_RESAMPLE:
01450 {
01451 bool tmp_bResampleUsed = (SendMessage(GetDlgItem( parentWnd, IDC_CHECK_RESAMPLE), BM_GETCHECK, NULL, NULL) == BST_CHECKED);
01452 if (tmp_bResampleUsed)
01453 {
01454 ::EnableWindow(::GetDlgItem(parentWnd,IDC_COMBO_SAMPLEFREQ), TRUE);
01455 }
01456 else
01457 {
01458 ::EnableWindow(::GetDlgItem(parentWnd,IDC_COMBO_SAMPLEFREQ), FALSE);
01459 }
01460 }
01461 break;
01462
01463 case IDC_COMBO_SETTINGS:
01464
01465 if (CBN_SELENDOK == GET_WM_COMMAND_CMD(wParam, lParam))
01466 {
01467 char string[MAX_PATH];
01468 int nIdx = SendMessage(HWND(lParam), CB_GETCURSEL, NULL, NULL);
01469 SendMessage(HWND(lParam), CB_GETLBTEXT , nIdx, (LPARAM) string);
01470
01471
01472 SelectSavedParams(string);
01473 UpdateDlgFromValue(parentWnd);
01474 }
01475 break;
01476
01477 case IDC_BUTTON_CONFIG_SAVE:
01478 {
01479
01480 char string[MAX_PATH];
01481 ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
01482
01483 UpdateValueFromDlg(parentWnd);
01484 SaveValuesToStringKey(string);
01485 SelectSavedParams(string);
01486 UpdateConfigs(parentWnd);
01487 UpdateDlgFromValue(parentWnd);
01488 }
01489 break;
01490
01491 case IDC_BUTTON_CONFIG_RENAME:
01492 {
01493 char string[MAX_PATH];
01494 ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
01495
01496 if (RenameCurrentTo(string))
01497 {
01498
01499 UpdateConfigs(parentWnd);
01500 }
01501
01502 }
01503 break;
01504
01505 case IDC_BUTTON_CONFIG_DELETE:
01506 {
01507 char string[MAX_PATH];
01508 ::GetWindowText(::GetDlgItem( parentWnd, IDC_COMBO_SETTINGS), string, MAX_PATH);
01509
01510 if (DeleteConfig(string))
01511 {
01512
01513 UpdateConfigs(parentWnd);
01514 UpdateDlgFromValue(parentWnd);
01515 }
01516 }
01517 break;
01518 }
01519
01520 return FALSE;
01521 }
01522
01523 bool AEncodeProperties::RenameCurrentTo(const std::string & new_config_name)
01524 {
01525 bool bResult = false;
01526
01527
01528
01529 if (my_stored_data.LoadFile(my_store_location))
01530 {
01531 TiXmlNode* node;
01532
01533 node = my_stored_data.FirstChild("out_lame");
01534
01535 TiXmlElement* CurrentNode = node->FirstChildElement("configs");
01536
01537 if (CurrentNode->Attribute("default") != NULL)
01538 {
01539 std::string CurrentConfigName = *CurrentNode->Attribute("default");
01540
01541
01542 if (CurrentConfigName == "")
01543 {
01544 bResult = true;
01545 }
01546 else if (CurrentConfigName != "Current")
01547 {
01548
01549 TiXmlElement* iterateElmt = CurrentNode->FirstChildElement("config");
01550
01551 while (iterateElmt != NULL)
01552 {
01553 const std::string * tmpname = iterateElmt->Attribute("name");
01557 if (tmpname != NULL)
01558 {
01559 if (tmpname->compare(CurrentConfigName) == 0)
01560 {
01561 iterateElmt->SetAttribute("name",new_config_name);
01562 bResult = true;
01563 break;
01564 }
01565 }
01566
01567 iterateElmt = iterateElmt->NextSiblingElement("config");
01568 }
01569 }
01570
01571 if (bResult)
01572 {
01573 CurrentNode->SetAttribute("default",new_config_name);
01574
01575 my_stored_data.SaveFile(my_store_location);
01576 }
01577 }
01578 }
01579
01580 return bResult;
01581 }
01582
01583 bool AEncodeProperties::DeleteConfig(const std::string & config_name)
01584 {
01585 bool bResult = false;
01586
01587 if (config_name != "Current")
01588 {
01589
01590
01591 if (my_stored_data.LoadFile(my_store_location))
01592 {
01593 TiXmlNode* node;
01594
01595 node = my_stored_data.FirstChild("out_lame");
01596
01597 TiXmlElement* CurrentNode = node->FirstChildElement("configs");
01598
01599 TiXmlElement* iterateElmt = CurrentNode->FirstChildElement("config");
01600
01601 while (iterateElmt != NULL)
01602 {
01603 const std::string * tmpname = iterateElmt->Attribute("name");
01607 if (tmpname != NULL)
01608 {
01609 if (tmpname->compare(config_name) == 0)
01610 {
01611 CurrentNode->RemoveChild(iterateElmt);
01612 bResult = true;
01613 break;
01614 }
01615 }
01616
01617 iterateElmt = iterateElmt->NextSiblingElement("config");
01618 }
01619 }
01620
01621 if (bResult)
01622 {
01623 my_stored_data.SaveFile(my_store_location);
01624
01625
01626 SelectSavedParams("Current");
01627
01628 }
01629 }
01630
01631 return bResult;
01632 }
01633
01634 void AEncodeProperties::UpdateConfigs(const HWND HwndDlg)
01635 {
01636
01637 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_RESETCONTENT , NULL, NULL);
01638
01639
01640
01641 if (my_stored_data.LoadFile(my_store_location))
01642 {
01643 TiXmlNode* node;
01644
01645 node = my_stored_data.FirstChild("out_lame");
01646
01647 TiXmlElement* CurrentNode = node->FirstChildElement("configs");
01648
01649 std::string CurrentConfig = "";
01650
01651 if (CurrentNode->Attribute("default") != NULL)
01652 {
01653 CurrentConfig = *CurrentNode->Attribute("default");
01654 }
01655
01656 TiXmlElement* iterateElmt;
01657
01658
01659 iterateElmt = CurrentNode->FirstChildElement("config");
01660 int Idx = 0;
01661 while (iterateElmt != NULL)
01662 {
01663 const std::string * tmpname = iterateElmt->Attribute("name");
01667 if (tmpname != NULL)
01668 {
01669 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_ADDSTRING, NULL, (LPARAM) tmpname->c_str());
01670 if (tmpname->compare(CurrentConfig) == 0)
01671 {
01672 SendMessage(GetDlgItem( HwndDlg, IDC_COMBO_SETTINGS), CB_SETCURSEL, Idx, NULL);
01673 }
01674 }
01675 Idx++;
01676 iterateElmt = iterateElmt->NextSiblingElement("config");
01677 }
01678 }
01679 }