1
0

preferences.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "preferences.h"
  2. #include "resource.h"
  3. #include "../nu/ComboBox.h"
  4. #include "../nu/Slider.h"
  5. #include "../Agave/Language/api_language.h"
  6. #include <strsafe.h>
  7. /* note to maintainers:
  8. the combobox code assumes that the options are in numerical order starting from 0
  9. if this assumption ever changes, you'll need to map AAC_MODE_* and AAC_PROFILE_* to/from indices
  10. there are some asserts to test this (which will only test in debug mode of course)
  11. */
  12. const int bitrate_slider_precision = 4;
  13. static void SetSliderBitrate(HWND hwnd, unsigned int bitrate)
  14. {
  15. Slider preset_slider(hwnd, IDC_SLIDER_PRESET);
  16. int low = (unsigned int)SendMessage(GetDlgItem(hwnd,IDC_SLIDER_PRESET), TBM_GETRANGEMIN, 0, 0);
  17. int position = (bitrate - low)/bitrate_slider_precision + low;
  18. preset_slider.SetPosition(position, Slider::REDRAW);
  19. }
  20. unsigned int GetSliderBitrate(HWND hwnd)
  21. {
  22. int low = (unsigned int)SendMessage(GetDlgItem(hwnd,IDC_SLIDER_PRESET), TBM_GETRANGEMIN, 0, 0);
  23. int position = SendMessage(GetDlgItem(hwnd,IDC_SLIDER_PRESET),TBM_GETPOS,0,0);
  24. unsigned int bitrate = (position - low)*bitrate_slider_precision + low;
  25. return bitrate;
  26. }
  27. void UpdateInfo(HWND hwnd, const AACConfiguration *config)
  28. {
  29. wchar_t temp[128] = {0};
  30. switch(AACConfig_GetAOT(config))
  31. {
  32. case AUD_OBJ_TYP_LC:
  33. SetDlgItemText(hwnd, IDC_INFO_MODE, L"MPEG-4 AAC LC");
  34. break;
  35. case AUD_OBJ_TYP_HEAAC:
  36. SetDlgItemText(hwnd, IDC_INFO_MODE, L"MPEG-4 HE-AAC");
  37. break;
  38. case AUD_OBJ_TYP_PS:
  39. SetDlgItemText(hwnd, IDC_INFO_MODE, L"MPEG-4 HE-AACv2");
  40. break;
  41. }
  42. if (config->mode == AAC_MODE_VBR)
  43. {
  44. StringCbPrintfW(temp, sizeof(temp), WASABI_API_LNGSTRINGW(IDS_VBR_PRESET), config->preset, AACConfig_GetBitrate(config, 2 /* TODO! */)/1000);
  45. SetDlgItemText(hwnd, IDC_INFO_BITRATE, temp);
  46. }
  47. else
  48. {
  49. StringCbPrintfW(temp, sizeof(temp), WASABI_API_LNGSTRINGW(IDS_CBR_PRESET), AACConfig_GetBitrate(config, 2 /* TODO! */)/1000);
  50. SetDlgItemText(hwnd, IDC_INFO_BITRATE, temp);
  51. }
  52. }
  53. /* call this to update the UI according to the configuration values */
  54. void UpdateUI(HWND hwnd, AACConfigurationFile *config)
  55. {
  56. wchar_t temp[128] = {0};
  57. ComboBox mode_list(hwnd, IDC_MODE);
  58. ComboBox profile_list(hwnd, IDC_PROFILE);
  59. config->changing = true;
  60. Slider preset_slider(hwnd, IDC_SLIDER_PRESET);
  61. if (config->config.mode == AAC_MODE_VBR)
  62. {
  63. preset_slider.SetRange(1, 6, Slider::REDRAW);
  64. preset_slider.SetTickFrequency(1);
  65. preset_slider.SetPosition(config->config.preset, Slider::REDRAW);
  66. SetDlgItemText(hwnd, IDC_STATIC_PRESET, WASABI_API_LNGSTRINGW(IDS_PRESET));
  67. StringCbPrintf(temp, sizeof(temp), L"%u", config->config.preset);
  68. SetDlgItemText(hwnd, IDC_EDIT_PRESET, temp);
  69. profile_list.SelectItem(AAC_PROFILE_AUTOMATIC);
  70. EnableWindow(profile_list, FALSE);
  71. ShowWindow(GetDlgItem(hwnd, IDC_KBPS), SW_HIDE);
  72. }
  73. else /* implied: if (config->config.mode == AAC_MODE_CBR) */
  74. {
  75. int low, high;
  76. AACConfig_GetBitrateRange(&config->config, &low, &high);
  77. low = ((low/1000+3)&~3); /* convert to kbps round up to nearest multiple of 4 */
  78. high = ((high/1000)&~3); /* convert to kbps round down to nearest multiple of 4 */
  79. int slider_high = low + (high - low)/bitrate_slider_precision;
  80. preset_slider.SetRange(low, slider_high, Slider::REDRAW);
  81. if (config->config.profile >= AAC_PROFILE_HE)
  82. preset_slider.SetTickFrequency(1);
  83. else
  84. preset_slider.SetTickFrequency(4);
  85. SetSliderBitrate(hwnd, config->config.bitrate);
  86. config->config.bitrate = GetSliderBitrate(hwnd);
  87. SetDlgItemText(hwnd, IDC_STATIC_PRESET, WASABI_API_LNGSTRINGW(IDS_BITRATE));
  88. StringCbPrintf(temp, sizeof(temp), L"%u", config->config.bitrate);
  89. SetDlgItemText(hwnd, IDC_EDIT_PRESET, temp);
  90. profile_list.SelectItem(config->config.profile);
  91. EnableWindow(profile_list, TRUE);
  92. ShowWindow(GetDlgItem(hwnd, IDC_KBPS), SW_SHOWNA);
  93. }
  94. config->changing = false;
  95. }
  96. int Preferences_GetEncoderVersion(char *version_string, size_t cch)
  97. {
  98. char version[128] = {0};
  99. MPEG4ENC_GetVersionInfo(version, sizeof(version)/sizeof(*version));
  100. char *p = version;
  101. while (p && *p)
  102. {
  103. if (*p != '.' && (*p < '0' || *p > '9'))
  104. {
  105. *p = 0;
  106. break;
  107. }
  108. p++;
  109. }
  110. StringCchPrintfA(version_string, cch, WASABI_API_LNGSTRING(IDS_VERSION), version);
  111. return 0;
  112. }