AEncodeProperties.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /**
  2. *
  3. * Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows
  4. *
  5. * Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. /*!
  23. \author Steve Lhomme
  24. \version \$Id$
  25. */
  26. #if !defined(_AENCODEPROPERTIES_H__INCLUDED_)
  27. #define _AENCODEPROPERTIES_H__INCLUDED_
  28. #if _MSC_VER > 1000
  29. #pragma once
  30. #endif // _MSC_VER > 1000
  31. #include <windows.h>
  32. #include <string>
  33. #include "ADbg/ADbg.h"
  34. //#include "BladeMP3EncDLL.h"
  35. #include "tinyxml/tinyxml.h"
  36. //#include "AParameters/AParameters.h"
  37. typedef const struct {
  38. UINT id;
  39. const char *tip;
  40. } ToolTipItem;
  41. /**
  42. \class AEncodeProperties
  43. \brief the AEncodeProperties class is responsible for handling all the encoding properties
  44. */
  45. class AEncodeProperties
  46. {
  47. public:
  48. /**
  49. \brief default constructor
  50. \param the windows module with which you can retrieve many informations
  51. */
  52. AEncodeProperties(HMODULE hModule);
  53. /**
  54. \brief default destructor
  55. */
  56. virtual ~AEncodeProperties() {}
  57. /**
  58. \enum BRMode
  59. \brief A bitrate mode (CBR, VBR, ABR)
  60. */
  61. enum BRMode { BR_CBR, BR_VBR, BR_ABR };
  62. /**
  63. \brief Handle all the commands that occur in the Config dialog box
  64. */
  65. bool HandleDialogCommand(const HWND parentWnd, const WPARAM wParam, const LPARAM lParam);
  66. /**
  67. \brief check wether 2 instances are equal, ie have the same encoding parameters
  68. */
  69. bool operator != (const AEncodeProperties & the_instance) const;
  70. /**
  71. \brief Check wether the Encode process should use the Copyright bit
  72. */
  73. inline const bool GetCopyrightMode() const { return bCopyright; }
  74. /**
  75. \brief Check wether the Encode process should use the CRC bit
  76. */
  77. inline const bool GetCRCMode() const { return bCRC; }
  78. /**
  79. \brief Check wether the Encode process should use the Original bit
  80. */
  81. inline const bool GetOriginalMode() const { return bOriginal; }
  82. /**
  83. \brief Check wether the Encode process should use the Private bit
  84. */
  85. inline const bool GetPrivateMode() const { return bPrivate; }
  86. /**
  87. \brief Check wether the Encode process should use the Smart Bitrate output
  88. */
  89. inline const bool GetSmartOutputMode() const { return bSmartOutput; }
  90. /**
  91. \brief Check wether the Encode process should allow Average Bitrate output
  92. */
  93. inline const bool GetAbrOutputMode() const { return bAbrOutput; }
  94. /**
  95. \brief Check wether the Encode process shouldn't use the Bit Reservoir
  96. */
  97. inline const bool GetNoBiResMode() const { return bNoBitRes; }
  98. /**
  99. \brief Check wether the Encode process should force the channel mode (stereo or mono resampling)
  100. */
  101. inline const bool GetForceChannelMode() const { return bForceChannel; }
  102. /**
  103. \brief Check wether the Encode process should use the VBR mode
  104. */
  105. inline const BRMode GetVBRUseMode() const { return mBRmode; }
  106. /**
  107. \brief Check wether the Encode process should use the Xing frame in the VBR mode
  108. \note the Xing frame is a silent frame at the beginning that contain VBR statistics about the file.
  109. */
  110. inline const bool GetXingFrameMode() const { return bXingFrame; }
  111. /**
  112. \brief Check wether the Encode process should resample before encoding
  113. */
  114. inline const bool GetResampleMode() const { return bResample; }
  115. /**
  116. \brief Set wether the Encode process should use the Copyright bit
  117. */
  118. inline void SetCopyrightMode(const bool bMode) { bCopyright = bMode; }
  119. /**
  120. \brief Set wether the Encode process should use the CRC bit
  121. */
  122. inline void SetCRCMode(const bool bMode) { bCRC = bMode; }
  123. /**
  124. \brief Set wether the Encode process should use the Original bit
  125. */
  126. inline void SetOriginalMode(const bool bMode) { bOriginal = bMode; }
  127. /**
  128. \brief Set wether the Encode process should use the Private bit
  129. */
  130. inline void SetPrivateMode(const bool bMode) { bPrivate = bMode; }
  131. /**
  132. \brief Set wether the Encode process should use the Smart Bitrate output
  133. */
  134. inline void SetSmartOutputMode(const bool bMode) { bSmartOutput = bMode; }
  135. /**
  136. \brief Set wether the Encode process should use the Average Bitrate output
  137. */
  138. inline void SetAbrOutputMode(const bool bMode) { bAbrOutput = bMode; }
  139. /**
  140. \brief Set wether the Encode process shouldn't use the Bit Reservoir
  141. */
  142. inline void SetNoBiResMode(const bool bMode) { bNoBitRes = bMode; }
  143. /**
  144. \brief Set wether the Encode process should force the channel mode (stereo or mono resampling)
  145. */
  146. inline void SetForceChannelMode(const bool bMode) { bForceChannel = bMode; }
  147. /**
  148. \brief Set wether the Encode process should use the VBR mode
  149. */
  150. inline void SetVBRUseMode(const BRMode mode) { mBRmode = mode; }
  151. /**
  152. \brief Set wether the Encode process should use the Xing frame in the VBR mode
  153. \note the Xing frame is a silent frame at the beginning that contain VBR statistics about the file.
  154. */
  155. inline void SetXingFrameMode(const bool bMode) { bXingFrame = bMode; }
  156. /**
  157. \brief CBR : Get the bitrate to use /
  158. VBR : Get the minimum bitrate value
  159. */
  160. const unsigned int GetBitrateValue() const;
  161. /**
  162. \brief Get the current (VBR:min) bitrate for the specified MPEG version
  163. \param bitrate the data that will be filled with the bitrate
  164. \param MPEG_Version The MPEG version (MPEG1 or MPEG2)
  165. \return 0 if the bitrate is not found, 1 if the bitrate is found
  166. */
  167. const int GetBitrateValue(DWORD & bitrate, const DWORD MPEG_Version) const;
  168. /**
  169. \brief Get the current (VBR:min) bitrate for MPEG I
  170. \param bitrate the data that will be filled with the bitrate
  171. \return 0 if the bitrate is not found, 1 if the bitrate is found
  172. */
  173. const int GetBitrateValueMPEG1(DWORD & bitrate) const;
  174. /**
  175. \brief Get the current (VBR:min) bitrate for MPEG II
  176. \param bitrate the data that will be filled with the bitrate
  177. \return 0 if the bitrate is not found, 1 if the bitrate is found
  178. */
  179. const int GetBitrateValueMPEG2(DWORD & bitrate) const;
  180. /**
  181. \brief Get the current (VBR:min) bitrate in the form of a string
  182. \param string the string that will be filled
  183. \param string_size the size of the string
  184. \return -1 if the bitrate is not found, and the number of char copied otherwise
  185. */
  186. inline const int GetBitrateString(char * string, int string_size) const {return GetBitrateString(string,string_size,nMinBitrateIndex); }
  187. /**
  188. \brief Get the (VBR:min) bitrate corresponding to the specified index in the form of a string
  189. \param string the string that will be filled
  190. \param string_size the size of the string
  191. \param a_bitrateID the index in the Bitrate table
  192. \return -1 if the bitrate is not found, and the number of char copied otherwise
  193. */
  194. const int GetBitrateString(char * string, int string_size, int a_bitrateID) const;
  195. /**
  196. \brief Get the number of possible bitrates
  197. */
  198. inline const int GetBitrateLentgh() const { return sizeof(the_Bitrates) / sizeof(unsigned int); }
  199. /**
  200. \brief Get the number of possible sampling frequencies
  201. */
  202. inline const unsigned int GetResampleFreq() const { return the_SamplingFreqs[nSamplingFreqIndex]; }
  203. /**
  204. \brief Get the max compression ratio allowed (1:15 default)
  205. */
  206. inline double GetSmartRatio() const { return SmartRatioMax;}
  207. /**
  208. \brief Get the min ABR bitrate possible
  209. */
  210. inline unsigned int GetAbrBitrateMin() const { return AverageBitrate_Min;}
  211. /**
  212. \brief Get the max ABR bitrate possible
  213. */
  214. inline unsigned int GetAbrBitrateMax() const { return AverageBitrate_Max;}
  215. /**
  216. \brief Get the step between ABR bitrates
  217. */
  218. inline unsigned int GetAbrBitrateStep() const { return AverageBitrate_Step;}
  219. /**
  220. \brief Get the VBR attributes for a specified MPEG version
  221. \param MaxBitrate receive the maximum bitrate possible in the VBR mode
  222. \param Quality receive the quality value (0 to 9 see Lame doc for more info)
  223. \param VBRHeader receive the value that indicates wether the VBR/Xing header should be filled
  224. \param MPEG_Version The MPEG version (MPEG1 or MPEG2)
  225. \return the VBR mode (Old, New, ABR, MTRH, Default or None)
  226. */
  227. // VBRMETHOD GetVBRValue(DWORD & MaxBitrate, int & Quality, DWORD & AbrBitrate, BOOL & VBRHeader, const DWORD MPEG_Version) const;
  228. /**
  229. \brief Get the Lame DLL Location
  230. */
  231. // const char * GetDllLocation() const { return DllLocation.c_str(); }
  232. /**
  233. \brief Set the Lame DLL Location
  234. */
  235. // void SetDllLocation( const char * the_string ) { DllLocation = the_string; }
  236. /**
  237. \brief Get the output directory for encoding
  238. */
  239. // const char * GetOutputDirectory() const { return OutputDir.c_str(); }
  240. /**
  241. \brief Set the output directory for encoding
  242. */
  243. // void SetOutputDirectory( const char * the_string ) { OutputDir = the_string; }
  244. /**
  245. \brief Get the current channel mode to use
  246. */
  247. const unsigned int GetChannelModeValue() const;
  248. /**
  249. \brief Get the current channel mode in the form of a string
  250. */
  251. inline const char * GetChannelModeString() const {return GetChannelModeString(nChannelIndex); }
  252. /**
  253. \brief Get the channel mode in the form of a string for the specified Channel mode index
  254. \param a_channelID the Channel mode index (see GetChannelLentgh())
  255. */
  256. const char * GetChannelModeString(const int a_channelID) const;
  257. /**
  258. \brief Get the number of possible channel mode
  259. */
  260. inline const int GetChannelLentgh() const { return 3; }
  261. /**
  262. \brief Get the current preset to use, see lame documentation/code for more info on the possible presets
  263. */
  264. // const LAME_QUALTIY_PRESET GetPresetModeValue() const;
  265. /**
  266. \brief Get the preset in the form of a string for the specified Channel mode index
  267. \param a_presetID the preset index (see GetPresetLentgh())
  268. */
  269. const char * GetPresetModeString(const int a_presetID) const;
  270. /**
  271. \brief Get the number of possible presets
  272. */
  273. // inline const int GetPresetLentgh() const { return sizeof(the_Presets) / sizeof(LAME_QUALTIY_PRESET); }
  274. /**
  275. \brief Start the user configuration process (called by AOut::config())
  276. */
  277. bool Config(const HINSTANCE hInstance, const HWND HwndParent);
  278. /**
  279. \brief Init the config dialog box with the right texts and choices
  280. */
  281. bool InitConfigDlg(HWND hDialog);
  282. /**
  283. \brief Update the instance parameters from the config dialog box
  284. */
  285. bool UpdateValueFromDlg(HWND hDialog);
  286. /**
  287. \brief Update the config dialog box from the instance parameters
  288. */
  289. bool UpdateDlgFromValue(HWND hDialog);
  290. /**
  291. \brief Update the config dialog box with the BitRate mode
  292. */
  293. static void DisplayVbrOptions(const HWND hDialog, const BRMode the_mode);
  294. /**
  295. \brief Handle the saving of parameters when something has changed in the config dialog box
  296. */
  297. void SaveParams(const HWND hDialog);
  298. /**
  299. \brief Save the current parameters (current config in use)
  300. */
  301. void ParamsSave(void);
  302. /**
  303. \brief Load the parameters (current config in use)
  304. */
  305. void ParamsRestore(void);
  306. /**
  307. \brief Select the specified config name as the new default one
  308. */
  309. void SelectSavedParams(const std::string config_name);
  310. /**
  311. \brief Save the current parameters to the specified config name
  312. */
  313. void SaveValuesToStringKey(const std::string & config_name);
  314. /**
  315. \brief Rename the current config name to something else
  316. */
  317. bool RenameCurrentTo(const std::string & new_config_name);
  318. /**
  319. \brief Delete the config name from the saved configs
  320. */
  321. bool DeleteConfig(const std::string & config_name);
  322. ADbg my_debug;
  323. /**
  324. \brief Update the slides value (on scroll)
  325. */
  326. void UpdateDlgFromSlides(HWND parent_window) const;
  327. static ToolTipItem Tooltips[13];
  328. private:
  329. bool bCopyright;
  330. bool bCRC;
  331. bool bOriginal;
  332. bool bPrivate;
  333. bool bNoBitRes;
  334. BRMode mBRmode;
  335. bool bXingFrame;
  336. bool bForceChannel;
  337. bool bResample;
  338. bool bSmartOutput;
  339. bool bAbrOutput;
  340. int VbrQuality;
  341. unsigned int AverageBitrate_Min;
  342. unsigned int AverageBitrate_Max;
  343. unsigned int AverageBitrate_Step;
  344. double SmartRatioMax;
  345. static const unsigned int the_ChannelModes[3];
  346. int nChannelIndex;
  347. static const unsigned int the_Bitrates[18];
  348. static const unsigned int the_MPEG1_Bitrates[14];
  349. static const unsigned int the_MPEG2_Bitrates[14];
  350. int nMinBitrateIndex; // CBR and VBR
  351. int nMaxBitrateIndex; // only used in VBR mode
  352. static const unsigned int the_SamplingFreqs[9];
  353. int nSamplingFreqIndex;
  354. // static const LAME_QUALTIY_PRESET the_Presets[17];
  355. int nPresetIndex;
  356. // char DllLocation[512];
  357. // std::string DllLocation;
  358. // char OutputDir[MAX_PATH];
  359. // std::string OutputDir;
  360. // AParameters my_base_parameters;
  361. TiXmlDocument my_stored_data;
  362. std::string my_store_location;
  363. std::string my_current_config;
  364. // HINSTANCE hDllInstance;
  365. void SaveValuesToElement(TiXmlElement * the_element) const;
  366. inline void SetAttributeBool(TiXmlElement * the_elt,const std::string & the_string, const bool the_value) const;
  367. void UpdateConfigs(const HWND HwndDlg);
  368. void EnableAbrOptions(HWND hDialog, bool enable);
  369. HMODULE my_hModule;
  370. /**
  371. \brief
  372. \param config_name
  373. \param parentNode
  374. */
  375. void GetValuesFromKey(const std::string & config_name, const TiXmlNode & parentNode);
  376. };
  377. #endif // !defined(_AENCODEPROPERTIES_H__INCLUDED_)