window-basic-settings.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Philippe Groarke <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #pragma once
  16. #include <util/util.hpp>
  17. #include <QDialog>
  18. #include <memory>
  19. #include <string>
  20. #include <libff/ff-util.h>
  21. #include <obs.h>
  22. class OBSBasic;
  23. class QAbstractButton;
  24. class QComboBox;
  25. class QCheckBox;
  26. class QLabel;
  27. class OBSPropertiesView;
  28. class OBSHotkeyWidget;
  29. #include "ui_OBSBasicSettings.h"
  30. #define VOLUME_METER_DECAY_FAST 23.53
  31. #define VOLUME_METER_DECAY_MEDIUM 11.76
  32. #define VOLUME_METER_DECAY_SLOW 8.57
  33. class SilentUpdateCheckBox : public QCheckBox {
  34. Q_OBJECT
  35. public slots:
  36. void setCheckedSilently(bool checked)
  37. {
  38. bool blocked = blockSignals(true);
  39. setChecked(checked);
  40. blockSignals(blocked);
  41. }
  42. };
  43. class SilentUpdateSpinBox : public QSpinBox {
  44. Q_OBJECT
  45. public slots:
  46. void setValueSilently(int val)
  47. {
  48. bool blocked = blockSignals(true);
  49. setValue(val);
  50. blockSignals(blocked);
  51. }
  52. };
  53. class OBSFFDeleter
  54. {
  55. public:
  56. void operator()(const ff_format_desc *format)
  57. {
  58. ff_format_desc_free(format);
  59. }
  60. void operator()(const ff_codec_desc *codec)
  61. {
  62. ff_codec_desc_free(codec);
  63. }
  64. };
  65. using OBSFFCodecDesc = std::unique_ptr<const ff_codec_desc,
  66. OBSFFDeleter>;
  67. using OBSFFFormatDesc = std::unique_ptr<const ff_format_desc,
  68. OBSFFDeleter>;
  69. class OBSBasicSettings : public QDialog {
  70. Q_OBJECT
  71. private:
  72. OBSBasic *main;
  73. std::unique_ptr<Ui::OBSBasicSettings> ui;
  74. bool generalChanged = false;
  75. bool stream1Changed = false;
  76. bool outputsChanged = false;
  77. bool audioChanged = false;
  78. bool videoChanged = false;
  79. bool hotkeysChanged = false;
  80. bool advancedChanged = false;
  81. int pageIndex = 0;
  82. bool loading = true;
  83. std::string savedTheme;
  84. int lastSimpleRecQualityIdx = 0;
  85. int lastChannelSetupIdx = 0;
  86. OBSFFFormatDesc formats;
  87. OBSPropertiesView *streamProperties = nullptr;
  88. OBSPropertiesView *streamEncoderProps = nullptr;
  89. OBSPropertiesView *recordEncoderProps = nullptr;
  90. QPointer<QLabel> advOutRecWarning;
  91. QPointer<QLabel> simpleOutRecWarning;
  92. QString curPreset;
  93. QString curQSVPreset;
  94. QString curNVENCPreset;
  95. QString curAMDPreset;
  96. QString curAdvStreamEncoder;
  97. QString curAdvRecordEncoder;
  98. using AudioSource_t =
  99. std::tuple<OBSWeakSource,
  100. QPointer<QCheckBox>, QPointer<QSpinBox>,
  101. QPointer<QCheckBox>, QPointer<QSpinBox>>;
  102. std::vector<AudioSource_t> audioSources;
  103. std::vector<OBSSignal> audioSourceSignals;
  104. OBSSignal sourceCreated;
  105. OBSSignal channelChanged;
  106. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  107. OBSSignal hotkeyRegistered;
  108. OBSSignal hotkeyUnregistered;
  109. uint32_t outputCX = 0;
  110. uint32_t outputCY = 0;
  111. void SaveCombo(QComboBox *widget, const char *section,
  112. const char *value);
  113. void SaveComboData(QComboBox *widget, const char *section,
  114. const char *value);
  115. void SaveCheckBox(QAbstractButton *widget, const char *section,
  116. const char *value, bool invert = false);
  117. void SaveEdit(QLineEdit *widget, const char *section,
  118. const char *value);
  119. void SaveSpinBox(QSpinBox *widget, const char *section,
  120. const char *value);
  121. void SaveFormat(QComboBox *combo);
  122. void SaveEncoder(QComboBox *combo, const char *section,
  123. const char *value);
  124. inline bool Changed() const
  125. {
  126. return generalChanged || outputsChanged || stream1Changed ||
  127. audioChanged || videoChanged || advancedChanged ||
  128. hotkeysChanged;
  129. }
  130. inline void EnableApplyButton(bool en)
  131. {
  132. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  133. }
  134. inline void ClearChanged()
  135. {
  136. generalChanged = false;
  137. stream1Changed = false;
  138. outputsChanged = false;
  139. audioChanged = false;
  140. videoChanged = false;
  141. hotkeysChanged = false;
  142. advancedChanged= false;
  143. EnableApplyButton(false);
  144. }
  145. #ifdef _WIN32
  146. bool aeroWasDisabled = false;
  147. QCheckBox *toggleAero = nullptr;
  148. void ToggleDisableAero(bool checked);
  149. #endif
  150. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  151. bool QueryChanges();
  152. void LoadServiceTypes();
  153. void LoadEncoderTypes();
  154. void LoadColorRanges();
  155. void LoadFormats();
  156. void ReloadCodecs(const ff_format_desc *formatDesc);
  157. void LoadGeneralSettings();
  158. void LoadStream1Settings();
  159. void LoadOutputSettings();
  160. void LoadAudioSettings();
  161. void LoadVideoSettings();
  162. void LoadHotkeySettings(obs_hotkey_id ignoreKey=OBS_INVALID_HOTKEY_ID);
  163. void LoadAdvancedSettings();
  164. void LoadSettings(bool changedOnly);
  165. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  166. const char *path, bool changed = false);
  167. /* general */
  168. void LoadLanguageList();
  169. void LoadThemeList();
  170. /* output */
  171. void LoadSimpleOutputSettings();
  172. void LoadAdvOutputStreamingSettings();
  173. void LoadAdvOutputStreamingEncoderProperties();
  174. void LoadAdvOutputRecordingSettings();
  175. void LoadAdvOutputRecordingEncoderProperties();
  176. void LoadAdvOutputFFmpegSettings();
  177. void LoadAdvOutputAudioSettings();
  178. void SetAdvOutputFFmpegEnablement(
  179. ff_codec_type encoderType, bool enabled,
  180. bool enableEncode = false);
  181. /* audio */
  182. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  183. void LoadAudioDevices();
  184. void LoadAudioSources();
  185. /* video */
  186. void LoadRendererList();
  187. void ResetDownscales(uint32_t cx, uint32_t cy);
  188. void LoadDownscaleFilters();
  189. void LoadResolutionLists();
  190. void LoadFPSData();
  191. void SaveGeneralSettings();
  192. void SaveStream1Settings();
  193. void SaveOutputSettings();
  194. void SaveAudioSettings();
  195. void SaveVideoSettings();
  196. void SaveHotkeySettings();
  197. void SaveAdvancedSettings();
  198. void SaveSettings();
  199. void UpdateSimpleOutStreamDelayEstimate();
  200. void UpdateAdvOutStreamDelayEstimate();
  201. void FillSimpleRecordingValues();
  202. void FillSimpleStreamingValues();
  203. void FillAudioMonitoringDevices();
  204. void RecalcOutputResPixels(const char *resText);
  205. private slots:
  206. void on_theme_activated(int idx);
  207. void on_listWidget_itemSelectionChanged();
  208. void on_buttonBox_clicked(QAbstractButton *button);
  209. void on_streamType_currentIndexChanged(int idx);
  210. void on_simpleOutputBrowse_clicked();
  211. void on_advOutRecPathBrowse_clicked();
  212. void on_advOutFFPathBrowse_clicked();
  213. void on_advOutEncoder_currentIndexChanged(int idx);
  214. void on_advOutRecEncoder_currentIndexChanged(int idx);
  215. void on_advOutFFIgnoreCompat_stateChanged(int state);
  216. void on_advOutFFFormat_currentIndexChanged(int idx);
  217. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  218. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  219. void on_advOutFFType_currentIndexChanged(int idx);
  220. void on_colorFormat_currentIndexChanged(const QString &text);
  221. void on_filenameFormatting_textEdited(const QString &text);
  222. void on_outputResolution_editTextChanged(const QString &text);
  223. void on_baseResolution_editTextChanged(const QString &text);
  224. void on_disableOSXVSync_clicked();
  225. void GeneralChanged();
  226. void AudioChanged();
  227. void AudioChangedRestart();
  228. void ReloadAudioSources();
  229. void SurroundWarning(int idx);
  230. void SpeakerLayoutChanged(int idx);
  231. void OutputsChanged();
  232. void Stream1Changed();
  233. void VideoChanged();
  234. void VideoChangedResolution();
  235. void VideoChangedRestart();
  236. void HotkeysChanged();
  237. void ReloadHotkeys(obs_hotkey_id ignoreKey=OBS_INVALID_HOTKEY_ID);
  238. void AdvancedChanged();
  239. void AdvancedChangedRestart();
  240. void UpdateStreamDelayEstimate();
  241. void UpdateAutomaticReplayBufferCheckboxes();
  242. void AdvOutRecCheckWarnings();
  243. void SimpleRecordingQualityChanged();
  244. void SimpleRecordingEncoderChanged();
  245. void SimpleRecordingQualityLosslessWarning(int idx);
  246. void SimpleReplayBufferChanged();
  247. void AdvReplayBufferChanged();
  248. void SimpleStreamingEncoderChanged();
  249. protected:
  250. virtual void closeEvent(QCloseEvent *event);
  251. public:
  252. OBSBasicSettings(QWidget *parent);
  253. ~OBSBasicSettings();
  254. };