window-basic-settings.hpp 8.8 KB
Newer Older
1 2
/******************************************************************************
    Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
S
Socapex 已提交
3
                          Philippe Groarke <philippe.groarke@gmail.com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

J
jp9000 已提交
19 20
#pragma once

21
#include <util/util.hpp>
22
#include <QDialog>
23
#include <QPointer>
24
#include <memory>
S
Socapex 已提交
25
#include <string>
J
jp9000 已提交
26

27 28
#include <libff/ff-util.h>

29
#include <obs.hpp>
J
jp9000 已提交
30

31 32
#include "auth-base.hpp"

33
class OBSBasic;
34
class QAbstractButton;
J
jp9000 已提交
35
class QComboBox;
36
class QCheckBox;
37
class QLabel;
38
class OBSPropertiesView;
P
Palana 已提交
39
class OBSHotkeyWidget;
40 41

#include "ui_OBSBasicSettings.h"
J
jp9000 已提交
42

S
Shaolin 已提交
43 44 45 46
#define VOLUME_METER_DECAY_FAST        23.53
#define VOLUME_METER_DECAY_MEDIUM      11.76
#define VOLUME_METER_DECAY_SLOW        8.57

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
class SilentUpdateCheckBox : public QCheckBox {
	Q_OBJECT

public slots:
	void setCheckedSilently(bool checked)
	{
		bool blocked = blockSignals(true);
		setChecked(checked);
		blockSignals(blocked);
	}
};

class SilentUpdateSpinBox : public QSpinBox {
	Q_OBJECT

public slots:
	void setValueSilently(int val)
	{
		bool blocked = blockSignals(true);
		setValue(val);
		blockSignals(blocked);
	}
};

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
class OBSFFDeleter
{
public:
	void operator()(const ff_format_desc *format)
	{
		ff_format_desc_free(format);
	}
	void operator()(const ff_codec_desc *codec)
	{
		ff_codec_desc_free(codec);
	}
};
using OBSFFCodecDesc = std::unique_ptr<const ff_codec_desc,
		OBSFFDeleter>;
using OBSFFFormatDesc = std::unique_ptr<const ff_format_desc,
		OBSFFDeleter>;

88 89
class OBSBasicSettings : public QDialog {
	Q_OBJECT
90

91
private:
92 93
	OBSBasic *main;

94
	std::unique_ptr<Ui::OBSBasicSettings> ui;
P
Palana 已提交
95

96 97
	std::shared_ptr<Auth> auth;

98
	bool generalChanged = false;
99
	bool stream1Changed = false;
100 101 102
	bool outputsChanged = false;
	bool audioChanged = false;
	bool videoChanged = false;
P
Palana 已提交
103
	bool hotkeysChanged = false;
J
jp9000 已提交
104
	bool advancedChanged = false;
105 106
	int  pageIndex = 0;
	bool loading = true;
S
Socapex 已提交
107
	std::string savedTheme;
108

109
	int lastSimpleRecQualityIdx = 0;
P
pkviet 已提交
110
	int lastChannelSetupIdx = 0;
111

112 113
	OBSFFFormatDesc formats;

114
	OBSPropertiesView *streamProperties = nullptr;
J
jp9000 已提交
115 116
	OBSPropertiesView *streamEncoderProps = nullptr;
	OBSPropertiesView *recordEncoderProps = nullptr;
117

118
	QPointer<QLabel> advOutRecWarning;
119
	QPointer<QLabel> simpleOutRecWarning;
120

121 122
	QString curPreset;
	QString curQSVPreset;
J
jp9000 已提交
123
	QString curNVENCPreset;
124
	QString curAMDPreset;
125

126 127 128
	QString curAdvStreamEncoder;
	QString curAdvRecordEncoder;

129 130 131 132 133 134 135 136 137
	using AudioSource_t =
		std::tuple<OBSWeakSource,
			QPointer<QCheckBox>, QPointer<QSpinBox>,
			QPointer<QCheckBox>, QPointer<QSpinBox>>;
	std::vector<AudioSource_t> audioSources;
	std::vector<OBSSignal> audioSourceSignals;
	OBSSignal sourceCreated;
	OBSSignal channelChanged;

P
Palana 已提交
138 139 140 141
	std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
	OBSSignal hotkeyRegistered;
	OBSSignal hotkeyUnregistered;

142 143 144
	uint32_t outputCX = 0;
	uint32_t outputCY = 0;

145 146 147 148
	void SaveCombo(QComboBox *widget, const char *section,
			const char *value);
	void SaveComboData(QComboBox *widget, const char *section,
			const char *value);
J
jp9000 已提交
149 150
	void SaveCheckBox(QAbstractButton *widget, const char *section,
			const char *value, bool invert = false);
151 152 153 154
	void SaveEdit(QLineEdit *widget, const char *section,
			const char *value);
	void SaveSpinBox(QSpinBox *widget, const char *section,
			const char *value);
155 156 157
	void SaveFormat(QComboBox *combo);
	void SaveEncoder(QComboBox *combo, const char *section,
			const char *value);
158

159 160
	inline bool Changed() const
	{
161
		return generalChanged || outputsChanged || stream1Changed ||
P
Palana 已提交
162 163
			audioChanged || videoChanged || advancedChanged ||
			hotkeysChanged;
164 165
	}

S
Socapex 已提交
166 167 168 169 170
	inline void EnableApplyButton(bool en)
	{
		ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
	}

171 172 173
	inline void ClearChanged()
	{
		generalChanged = false;
174
		stream1Changed = false;
175 176 177
		outputsChanged = false;
		audioChanged   = false;
		videoChanged   = false;
P
Palana 已提交
178
		hotkeysChanged = false;
J
jp9000 已提交
179
		advancedChanged= false;
S
Socapex 已提交
180
		EnableApplyButton(false);
181 182
	}

183 184 185 186 187 188
#ifdef _WIN32
	bool aeroWasDisabled = false;
	QCheckBox *toggleAero = nullptr;
	void ToggleDisableAero(bool checked);
#endif

J
jp9000 已提交
189 190
	void HookWidget(QWidget *widget, const char *signal, const char *slot);

191 192
	bool QueryChanges();

J
jp9000 已提交
193
	void LoadEncoderTypes();
J
jp9000 已提交
194
	void LoadColorRanges();
195 196
	void LoadFormats();
	void ReloadCodecs(const ff_format_desc *formatDesc);
197

198
	void LoadGeneralSettings();
199
	void LoadStream1Settings();
200
	void LoadOutputSettings();
201
	void LoadAudioSettings();
202
	void LoadVideoSettings();
P
Palana 已提交
203
	void LoadHotkeySettings(obs_hotkey_id ignoreKey=OBS_INVALID_HOTKEY_ID);
J
jp9000 已提交
204
	void LoadAdvancedSettings();
205
	void LoadSettings(bool changedOnly);
206

J
jp9000 已提交
207 208 209
	OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
			const char *path, bool changed = false);

210 211
	/* general */
	void LoadLanguageList();
S
Socapex 已提交
212
	void LoadThemeList();
213

214 215 216 217
	/* stream */
	void InitStreamPage();
	inline bool IsCustomService() const;
	void LoadServices(bool showAll);
218 219
	void OnOAuthStreamKeyConnected();
	void OnAuthConnected();
220 221 222 223 224
	QString lastService;
private slots:
	void UpdateServerList();
	void UpdateKeyLink();
	void on_show_clicked();
225 226 227
	void on_connectAccount_clicked();
	void on_disconnectAccount_clicked();
	void on_useStreamKey_clicked();
228 229
private:

230 231
	/* output */
	void LoadSimpleOutputSettings();
J
jp9000 已提交
232 233 234 235 236 237
	void LoadAdvOutputStreamingSettings();
	void LoadAdvOutputStreamingEncoderProperties();
	void LoadAdvOutputRecordingSettings();
	void LoadAdvOutputRecordingEncoderProperties();
	void LoadAdvOutputFFmpegSettings();
	void LoadAdvOutputAudioSettings();
238 239 240
	void SetAdvOutputFFmpegEnablement(
		ff_codec_type encoderType, bool enabled,
		bool enableEncode = false);
241

242
	/* audio */
243
	void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
244
	void LoadAudioDevices();
245
	void LoadAudioSources();
246

247 248
	/* video */
	void LoadRendererList();
249
	void ResetDownscales(uint32_t cx, uint32_t cy);
250
	void LoadDownscaleFilters();
251 252 253 254
	void LoadResolutionLists();
	void LoadFPSData();

	void SaveGeneralSettings();
255
	void SaveStream1Settings();
256
	void SaveOutputSettings();
257
	void SaveAudioSettings();
258
	void SaveVideoSettings();
P
Palana 已提交
259
	void SaveHotkeySettings();
J
jp9000 已提交
260
	void SaveAdvancedSettings();
261
	void SaveSettings();
262

263 264 265
	void UpdateSimpleOutStreamDelayEstimate();
	void UpdateAdvOutStreamDelayEstimate();

266
	void FillSimpleRecordingValues();
267
	void FillSimpleStreamingValues();
268
	void FillAudioMonitoringDevices();
269

270 271
	void RecalcOutputResPixels(const char *resText);

272
private slots:
S
Socapex 已提交
273 274
	void on_theme_activated(int idx);

275
	void on_listWidget_itemSelectionChanged();
276 277
	void on_buttonBox_clicked(QAbstractButton *button);

278
	void on_service_currentIndexChanged(int idx);
279
	void on_simpleOutputBrowse_clicked();
J
jp9000 已提交
280 281 282 283
	void on_advOutRecPathBrowse_clicked();
	void on_advOutFFPathBrowse_clicked();
	void on_advOutEncoder_currentIndexChanged(int idx);
	void on_advOutRecEncoder_currentIndexChanged(int idx);
284
	void on_advOutFFIgnoreCompat_stateChanged(int state);
285 286 287
	void on_advOutFFFormat_currentIndexChanged(int idx);
	void on_advOutFFAEncoder_currentIndexChanged(int idx);
	void on_advOutFFVEncoder_currentIndexChanged(int idx);
288
	void on_advOutFFType_currentIndexChanged(int idx);
289

290 291
	void on_colorFormat_currentIndexChanged(const QString &text);

292
	void on_filenameFormatting_textEdited(const QString &text);
293
	void on_outputResolution_editTextChanged(const QString &text);
294
	void on_baseResolution_editTextChanged(const QString &text);
J
jp9000 已提交
295

296 297
	void on_disableOSXVSync_clicked();

J
jp9000 已提交
298 299 300
	void GeneralChanged();
	void AudioChanged();
	void AudioChangedRestart();
301
	void ReloadAudioSources();
P
pkviet 已提交
302 303
	void SurroundWarning(int idx);
	void SpeakerLayoutChanged(int idx);
304
	void OutputsChanged();
305
	void Stream1Changed();
J
jp9000 已提交
306 307 308
	void VideoChanged();
	void VideoChangedResolution();
	void VideoChangedRestart();
P
Palana 已提交
309 310
	void HotkeysChanged();
	void ReloadHotkeys(obs_hotkey_id ignoreKey=OBS_INVALID_HOTKEY_ID);
J
jp9000 已提交
311 312
	void AdvancedChanged();
	void AdvancedChangedRestart();
313

314 315
	void UpdateStreamDelayEstimate();

316 317
	void UpdateAutomaticReplayBufferCheckboxes();

318 319
	void AdvOutRecCheckWarnings();

320 321 322 323
	void SimpleRecordingQualityChanged();
	void SimpleRecordingEncoderChanged();
	void SimpleRecordingQualityLosslessWarning(int idx);

324
	void SimpleReplayBufferChanged();
325
	void AdvReplayBufferChanged();
326

327 328
	void SimpleStreamingEncoderChanged();

329 330
	OBSService SpawnTempService();

331 332
protected:
	virtual void closeEvent(QCloseEvent *event);
333

J
jp9000 已提交
334
public:
335
	OBSBasicSettings(QWidget *parent);
336
	~OBSBasicSettings();
J
jp9000 已提交
337
};