Main Page   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

AEncodeProperties.cpp

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

Generated at Tue Sep 4 20:59:07 2001 for out_lame by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001