window-basic-main.hpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QBuffer>
  16. #include <QAction>
  17. #include <QThread>
  18. #include <QWidgetAction>
  19. #include <QSystemTrayIcon>
  20. #include <QStyledItemDelegate>
  21. #include <obs.hpp>
  22. #include <vector>
  23. #include <memory>
  24. #include "window-main.hpp"
  25. #include "window-basic-interaction.hpp"
  26. #include "window-basic-properties.hpp"
  27. #include "window-basic-transform.hpp"
  28. #include "window-basic-adv-audio.hpp"
  29. #include "window-basic-filters.hpp"
  30. #include "window-missing-files.hpp"
  31. #include "window-projector.hpp"
  32. #include "window-basic-about.hpp"
  33. #include "auth-base.hpp"
  34. #include "log-viewer.hpp"
  35. #include "undo-stack-obs.hpp"
  36. #include <obs-frontend-internal.hpp>
  37. #include <util/platform.h>
  38. #include <util/threading.h>
  39. #include <util/util.hpp>
  40. #include <QPointer>
  41. class QMessageBox;
  42. class QListWidgetItem;
  43. class VolControl;
  44. class OBSBasicStats;
  45. #include "ui_OBSBasic.h"
  46. #include "ui_ColorSelect.h"
  47. #define DESKTOP_AUDIO_1 Str("DesktopAudioDevice1")
  48. #define DESKTOP_AUDIO_2 Str("DesktopAudioDevice2")
  49. #define AUX_AUDIO_1 Str("AuxAudioDevice1")
  50. #define AUX_AUDIO_2 Str("AuxAudioDevice2")
  51. #define AUX_AUDIO_3 Str("AuxAudioDevice3")
  52. #define AUX_AUDIO_4 Str("AuxAudioDevice4")
  53. #define SIMPLE_ENCODER_X264 "x264"
  54. #define SIMPLE_ENCODER_X264_LOWCPU "x264_lowcpu"
  55. #define SIMPLE_ENCODER_QSV "qsv"
  56. #define SIMPLE_ENCODER_NVENC "nvenc"
  57. #define SIMPLE_ENCODER_NVENC_HEVC "nvenc_hevc"
  58. #define SIMPLE_ENCODER_AMD "amd"
  59. #define SIMPLE_ENCODER_AMD_HEVC "amd_hevc"
  60. #define SIMPLE_ENCODER_APPLE_H264 "apple_h264"
  61. #define PREVIEW_EDGE_SIZE 10
  62. struct BasicOutputHandler;
  63. enum class QtDataRole {
  64. OBSRef = Qt::UserRole,
  65. OBSSignals,
  66. };
  67. struct SavedProjectorInfo {
  68. ProjectorType type;
  69. int monitor;
  70. std::string geometry;
  71. std::string name;
  72. bool alwaysOnTop;
  73. bool alwaysOnTopOverridden;
  74. };
  75. struct SourceCopyInfo {
  76. OBSWeakSource weak_source;
  77. bool visible;
  78. obs_sceneitem_crop crop;
  79. obs_transform_info transform;
  80. obs_blending_method blend_method;
  81. obs_blending_type blend_mode;
  82. };
  83. struct QuickTransition {
  84. QPushButton *button = nullptr;
  85. OBSSource source;
  86. obs_hotkey_id hotkey = OBS_INVALID_HOTKEY_ID;
  87. int duration = 0;
  88. int id = 0;
  89. bool fadeToBlack = false;
  90. inline QuickTransition() {}
  91. inline QuickTransition(OBSSource source_, int duration_, int id_,
  92. bool fadeToBlack_ = false)
  93. : source(source_),
  94. duration(duration_),
  95. id(id_),
  96. fadeToBlack(fadeToBlack_),
  97. renamedSignal(std::make_shared<OBSSignal>(
  98. obs_source_get_signal_handler(source), "rename",
  99. SourceRenamed, this))
  100. {
  101. }
  102. private:
  103. static void SourceRenamed(void *param, calldata_t *data);
  104. std::shared_ptr<OBSSignal> renamedSignal;
  105. };
  106. class ColorSelect : public QWidget {
  107. public:
  108. explicit ColorSelect(QWidget *parent = 0);
  109. private:
  110. std::unique_ptr<Ui::ColorSelect> ui;
  111. };
  112. class OBSBasic : public OBSMainWindow {
  113. Q_OBJECT
  114. Q_PROPERTY(QIcon imageIcon READ GetImageIcon WRITE SetImageIcon
  115. DESIGNABLE true)
  116. Q_PROPERTY(QIcon colorIcon READ GetColorIcon WRITE SetColorIcon
  117. DESIGNABLE true)
  118. Q_PROPERTY(QIcon slideshowIcon READ GetSlideshowIcon WRITE
  119. SetSlideshowIcon DESIGNABLE true)
  120. Q_PROPERTY(QIcon audioInputIcon READ GetAudioInputIcon WRITE
  121. SetAudioInputIcon DESIGNABLE true)
  122. Q_PROPERTY(QIcon audioOutputIcon READ GetAudioOutputIcon WRITE
  123. SetAudioOutputIcon DESIGNABLE true)
  124. Q_PROPERTY(QIcon desktopCapIcon READ GetDesktopCapIcon WRITE
  125. SetDesktopCapIcon DESIGNABLE true)
  126. Q_PROPERTY(QIcon windowCapIcon READ GetWindowCapIcon WRITE
  127. SetWindowCapIcon DESIGNABLE true)
  128. Q_PROPERTY(QIcon gameCapIcon READ GetGameCapIcon WRITE SetGameCapIcon
  129. DESIGNABLE true)
  130. Q_PROPERTY(QIcon cameraIcon READ GetCameraIcon WRITE SetCameraIcon
  131. DESIGNABLE true)
  132. Q_PROPERTY(QIcon textIcon READ GetTextIcon WRITE SetTextIcon
  133. DESIGNABLE true)
  134. Q_PROPERTY(QIcon mediaIcon READ GetMediaIcon WRITE SetMediaIcon
  135. DESIGNABLE true)
  136. Q_PROPERTY(QIcon browserIcon READ GetBrowserIcon WRITE SetBrowserIcon
  137. DESIGNABLE true)
  138. Q_PROPERTY(QIcon groupIcon READ GetGroupIcon WRITE SetGroupIcon
  139. DESIGNABLE true)
  140. Q_PROPERTY(QIcon sceneIcon READ GetSceneIcon WRITE SetSceneIcon
  141. DESIGNABLE true)
  142. Q_PROPERTY(QIcon defaultIcon READ GetDefaultIcon WRITE SetDefaultIcon
  143. DESIGNABLE true)
  144. Q_PROPERTY(QIcon audioProcessOutputIcon READ GetAudioProcessOutputIcon
  145. WRITE SetAudioProcessOutputIcon DESIGNABLE true)
  146. friend class OBSAbout;
  147. friend class OBSBasicPreview;
  148. friend class OBSBasicStatusBar;
  149. friend class OBSBasicSourceSelect;
  150. friend class OBSBasicTransform;
  151. friend class OBSBasicSettings;
  152. friend class Auth;
  153. friend class AutoConfig;
  154. friend class AutoConfigStreamPage;
  155. friend class RecordButton;
  156. friend class ReplayBufferButton;
  157. friend class ExtraBrowsersModel;
  158. friend class ExtraBrowsersDelegate;
  159. friend class DeviceCaptureToolbar;
  160. friend class DeviceToolbarPropertiesThread;
  161. friend class OBSBasicSourceSelect;
  162. friend class OBSYoutubeActions;
  163. friend struct BasicOutputHandler;
  164. friend struct OBSStudioAPI;
  165. enum class MoveDir { Up, Down, Left, Right };
  166. enum DropType {
  167. DropType_RawText,
  168. DropType_Text,
  169. DropType_Image,
  170. DropType_Media,
  171. DropType_Html,
  172. DropType_Url,
  173. };
  174. enum ContextBarSize {
  175. ContextBarSize_Minimized,
  176. ContextBarSize_Reduced,
  177. ContextBarSize_Normal
  178. };
  179. enum class CenterType {
  180. Scene,
  181. Vertical,
  182. Horizontal,
  183. };
  184. private:
  185. obs_frontend_callbacks *api = nullptr;
  186. std::shared_ptr<Auth> auth;
  187. std::vector<VolControl *> volumes;
  188. std::vector<OBSSignal> signalHandlers;
  189. QList<QPointer<QDockWidget>> extraDocks;
  190. bool loaded = false;
  191. long disableSaving = 1;
  192. bool projectChanged = false;
  193. bool previewEnabled = true;
  194. ContextBarSize contextBarSize = ContextBarSize_Normal;
  195. std::deque<SourceCopyInfo> clipboard;
  196. OBSWeakSourceAutoRelease copyFiltersSource;
  197. bool copyVisible = true;
  198. obs_transform_info copiedTransformInfo;
  199. obs_sceneitem_crop copiedCropInfo;
  200. bool hasCopiedTransform = false;
  201. OBSWeakSourceAutoRelease copySourceTransition;
  202. bool closing = false;
  203. QScopedPointer<QThread> devicePropertiesThread;
  204. QScopedPointer<QThread> whatsNewInitThread;
  205. QScopedPointer<QThread> updateCheckThread;
  206. QScopedPointer<QThread> introCheckThread;
  207. QScopedPointer<QThread> logUploadThread;
  208. QPointer<OBSBasicInteraction> interaction;
  209. QPointer<OBSBasicProperties> properties;
  210. QPointer<OBSBasicTransform> transformWindow;
  211. QPointer<OBSBasicAdvAudio> advAudioWindow;
  212. QPointer<OBSBasicFilters> filters;
  213. QPointer<QDockWidget> statsDock;
  214. QPointer<OBSAbout> about;
  215. QPointer<OBSMissingFiles> missDialog;
  216. QPointer<OBSLogViewer> logView;
  217. QPointer<QTimer> cpuUsageTimer;
  218. QPointer<QTimer> diskFullTimer;
  219. QPointer<QTimer> nudge_timer;
  220. bool recent_nudge = false;
  221. os_cpu_usage_info_t *cpuUsageInfo = nullptr;
  222. OBSService service;
  223. std::unique_ptr<BasicOutputHandler> outputHandler;
  224. bool streamingStopping = false;
  225. bool recordingStopping = false;
  226. bool replayBufferStopping = false;
  227. gs_vertbuffer_t *box = nullptr;
  228. gs_vertbuffer_t *boxLeft = nullptr;
  229. gs_vertbuffer_t *boxTop = nullptr;
  230. gs_vertbuffer_t *boxRight = nullptr;
  231. gs_vertbuffer_t *boxBottom = nullptr;
  232. gs_vertbuffer_t *circle = nullptr;
  233. gs_vertbuffer_t *actionSafeMargin = nullptr;
  234. gs_vertbuffer_t *graphicsSafeMargin = nullptr;
  235. gs_vertbuffer_t *fourByThreeSafeMargin = nullptr;
  236. gs_vertbuffer_t *leftLine = nullptr;
  237. gs_vertbuffer_t *topLine = nullptr;
  238. gs_vertbuffer_t *rightLine = nullptr;
  239. int previewX = 0, previewY = 0;
  240. int previewCX = 0, previewCY = 0;
  241. float previewScale = 0.0f;
  242. ConfigFile basicConfig;
  243. std::vector<SavedProjectorInfo *> savedProjectorsArray;
  244. std::vector<OBSProjector *> projectors;
  245. QPointer<QWidget> stats;
  246. QPointer<QWidget> remux;
  247. QPointer<QWidget> extraBrowsers;
  248. QPointer<QWidget> importer;
  249. QPointer<QMenu> startStreamMenu;
  250. QPointer<QPushButton> transitionButton;
  251. QPointer<QPushButton> replayBufferButton;
  252. QPointer<QHBoxLayout> replayLayout;
  253. QScopedPointer<QPushButton> pause;
  254. QScopedPointer<QPushButton> replay;
  255. QPointer<QPushButton> vcamButton;
  256. bool vcamEnabled = false;
  257. QScopedPointer<QSystemTrayIcon> trayIcon;
  258. QPointer<QAction> sysTrayStream;
  259. QPointer<QAction> sysTrayRecord;
  260. QPointer<QAction> sysTrayReplayBuffer;
  261. QPointer<QAction> sysTrayVirtualCam;
  262. QPointer<QAction> showHide;
  263. QPointer<QAction> exit;
  264. QPointer<QMenu> trayMenu;
  265. QPointer<QMenu> previewProjector;
  266. QPointer<QMenu> studioProgramProjector;
  267. QPointer<QMenu> multiviewProjectorMenu;
  268. QPointer<QMenu> previewProjectorSource;
  269. QPointer<QMenu> previewProjectorMain;
  270. QPointer<QMenu> sceneProjectorMenu;
  271. QPointer<QMenu> sourceProjector;
  272. QPointer<QMenu> scaleFilteringMenu;
  273. QPointer<QMenu> blendingMethodMenu;
  274. QPointer<QMenu> blendingModeMenu;
  275. QPointer<QMenu> colorMenu;
  276. QPointer<QWidgetAction> colorWidgetAction;
  277. QPointer<ColorSelect> colorSelect;
  278. QPointer<QMenu> deinterlaceMenu;
  279. QPointer<QMenu> perSceneTransitionMenu;
  280. QPointer<QObject> shortcutFilter;
  281. QPointer<QAction> renameScene;
  282. QPointer<QAction> renameSource;
  283. QPointer<QWidget> programWidget;
  284. QPointer<QVBoxLayout> programLayout;
  285. QPointer<QLabel> programLabel;
  286. QScopedPointer<QThread> patronJsonThread;
  287. std::string patronJson;
  288. std::atomic<obs_scene_t *> currentScene = nullptr;
  289. void UpdateMultiviewProjectorMenu();
  290. void DrawBackdrop(float cx, float cy);
  291. void SetupEncoders();
  292. void CreateFirstRunSources();
  293. void CreateDefaultScene(bool firstStart);
  294. void UpdateVolumeControlsDecayRate();
  295. void UpdateVolumeControlsPeakMeterType();
  296. void ClearVolumeControls();
  297. void UploadLog(const char *subdir, const char *file, const bool crash);
  298. void Save(const char *file);
  299. void LoadData(obs_data_t *data, const char *file);
  300. void Load(const char *file);
  301. void InitHotkeys();
  302. void CreateHotkeys();
  303. void ClearHotkeys();
  304. bool InitService();
  305. bool InitBasicConfigDefaults();
  306. void InitBasicConfigDefaults2();
  307. bool InitBasicConfig();
  308. void InitOBSCallbacks();
  309. void InitPrimitives();
  310. void OnFirstLoad();
  311. OBSSceneItem GetSceneItem(QListWidgetItem *item);
  312. OBSSceneItem GetCurrentSceneItem();
  313. bool QueryRemoveSource(obs_source_t *source);
  314. void TimedCheckForUpdates();
  315. void CheckForUpdates(bool manualUpdate);
  316. void GetFPSCommon(uint32_t &num, uint32_t &den) const;
  317. void GetFPSInteger(uint32_t &num, uint32_t &den) const;
  318. void GetFPSFraction(uint32_t &num, uint32_t &den) const;
  319. void GetFPSNanoseconds(uint32_t &num, uint32_t &den) const;
  320. void GetConfigFPS(uint32_t &num, uint32_t &den) const;
  321. void UpdatePreviewScalingMenu();
  322. void LoadSceneListOrder(obs_data_array_t *array);
  323. obs_data_array_t *SaveSceneListOrder();
  324. void ChangeSceneIndex(bool relative, int idx, int invalidIdx);
  325. void TempFileOutput(const char *path, int vBitrate, int aBitrate);
  326. void TempStreamOutput(const char *url, const char *key, int vBitrate,
  327. int aBitrate);
  328. void CloseDialogs();
  329. void ClearSceneData();
  330. void ClearProjectors();
  331. void Nudge(int dist, MoveDir dir);
  332. OBSProjector *OpenProjector(obs_source_t *source, int monitor,
  333. ProjectorType type);
  334. void GetAudioSourceFilters();
  335. void GetAudioSourceProperties();
  336. void VolControlContextMenu();
  337. void ToggleVolControlLayout();
  338. void ToggleMixerLayout(bool vertical);
  339. void RefreshSceneCollections();
  340. void ChangeSceneCollection();
  341. void LogScenes();
  342. void ResetProfileData();
  343. bool AddProfile(bool create_new, const char *title, const char *text,
  344. const char *init_text = nullptr, bool rename = false);
  345. bool CreateProfile(const std::string &newName, bool create_new,
  346. bool showWizardChecked, bool rename = false);
  347. void DeleteProfile(const char *profile_name, const char *profile_dir);
  348. void RefreshProfiles();
  349. void ChangeProfile();
  350. void CheckForSimpleModeX264Fallback();
  351. void SaveProjectNow();
  352. int GetTopSelectedSourceItem();
  353. QModelIndexList GetAllSelectedSourceItems();
  354. obs_hotkey_pair_id streamingHotkeys, recordingHotkeys, pauseHotkeys,
  355. replayBufHotkeys, vcamHotkeys, togglePreviewHotkeys,
  356. contextBarHotkeys;
  357. obs_hotkey_id forceStreamingStopHotkey;
  358. void InitDefaultTransitions();
  359. void InitTransition(obs_source_t *transition);
  360. obs_source_t *FindTransition(const char *name);
  361. OBSSource GetCurrentTransition();
  362. obs_data_array_t *SaveTransitions();
  363. void LoadTransitions(obs_data_array_t *transitions,
  364. obs_load_source_cb cb, void *private_data);
  365. obs_source_t *fadeTransition;
  366. obs_source_t *cutTransition;
  367. void CreateProgramDisplay();
  368. void CreateProgramOptions();
  369. void AddQuickTransitionId(int id);
  370. void AddQuickTransition();
  371. void AddQuickTransitionHotkey(QuickTransition *qt);
  372. void RemoveQuickTransitionHotkey(QuickTransition *qt);
  373. void LoadQuickTransitions(obs_data_array_t *array);
  374. obs_data_array_t *SaveQuickTransitions();
  375. void ClearQuickTransitionWidgets();
  376. void RefreshQuickTransitions();
  377. void DisableQuickTransitionWidgets();
  378. void EnableTransitionWidgets(bool enable);
  379. void CreateDefaultQuickTransitions();
  380. void PasteShowHideTransition(obs_sceneitem_t *item, bool show,
  381. obs_source_t *tr);
  382. QMenu *CreatePerSceneTransitionMenu();
  383. QMenu *CreateVisibilityTransitionMenu(bool visible);
  384. QuickTransition *GetQuickTransition(int id);
  385. int GetQuickTransitionIdx(int id);
  386. QMenu *CreateTransitionMenu(QWidget *parent, QuickTransition *qt);
  387. void ClearQuickTransitions();
  388. void QuickTransitionClicked();
  389. void QuickTransitionChange();
  390. void QuickTransitionChangeDuration(int value);
  391. void QuickTransitionRemoveClicked();
  392. void SetPreviewProgramMode(bool enabled);
  393. void ResizeProgram(uint32_t cx, uint32_t cy);
  394. void SetCurrentScene(obs_scene_t *scene, bool force = false);
  395. static void RenderProgram(void *data, uint32_t cx, uint32_t cy);
  396. std::vector<QuickTransition> quickTransitions;
  397. QPointer<QWidget> programOptions;
  398. QPointer<OBSQTDisplay> program;
  399. OBSWeakSource lastScene;
  400. OBSWeakSource swapScene;
  401. OBSWeakSource programScene;
  402. bool editPropertiesMode = false;
  403. bool sceneDuplicationMode = true;
  404. bool swapScenesMode = true;
  405. volatile bool previewProgramMode = false;
  406. obs_hotkey_id togglePreviewProgramHotkey = 0;
  407. obs_hotkey_id transitionHotkey = 0;
  408. obs_hotkey_id statsHotkey = 0;
  409. obs_hotkey_id screenshotHotkey = 0;
  410. obs_hotkey_id sourceScreenshotHotkey = 0;
  411. int quickTransitionIdCounter = 1;
  412. bool overridingTransition = false;
  413. int programX = 0, programY = 0;
  414. int programCX = 0, programCY = 0;
  415. float programScale = 0.0f;
  416. int disableOutputsRef = 0;
  417. inline void OnActivate(bool force = false);
  418. inline void OnDeactivate();
  419. void AddDropSource(const char *file, DropType image);
  420. void AddDropURL(const char *url, QString &name, obs_data_t *settings,
  421. const obs_video_info &ovi);
  422. void ConfirmDropUrl(const QString &url);
  423. void dragEnterEvent(QDragEnterEvent *event) override;
  424. void dragLeaveEvent(QDragLeaveEvent *event) override;
  425. void dragMoveEvent(QDragMoveEvent *event) override;
  426. void dropEvent(QDropEvent *event) override;
  427. void ReplayBufferClicked();
  428. bool sysTrayMinimizeToTray();
  429. void EnumDialogs();
  430. QList<QDialog *> visDialogs;
  431. QList<QDialog *> modalDialogs;
  432. QList<QMessageBox *> visMsgBoxes;
  433. QList<QPoint> visDlgPositions;
  434. QByteArray startingDockLayout;
  435. obs_data_array_t *SaveProjectors();
  436. void LoadSavedProjectors(obs_data_array_t *savedProjectors);
  437. void ReceivedIntroJson(const QString &text);
  438. void ShowWhatsNew(const QString &url);
  439. void UpdatePreviewProgramIndicators();
  440. #ifdef BROWSER_AVAILABLE
  441. QList<QSharedPointer<QDockWidget>> extraBrowserDocks;
  442. QList<QSharedPointer<QAction>> extraBrowserDockActions;
  443. QStringList extraBrowserDockTargets;
  444. void ClearExtraBrowserDocks();
  445. void LoadExtraBrowserDocks();
  446. void SaveExtraBrowserDocks();
  447. void ManageExtraBrowserDocks();
  448. void AddExtraBrowserDock(const QString &title, const QString &url,
  449. const QString &uuid, bool firstCreate);
  450. #endif
  451. QIcon imageIcon;
  452. QIcon colorIcon;
  453. QIcon slideshowIcon;
  454. QIcon audioInputIcon;
  455. QIcon audioOutputIcon;
  456. QIcon desktopCapIcon;
  457. QIcon windowCapIcon;
  458. QIcon gameCapIcon;
  459. QIcon cameraIcon;
  460. QIcon textIcon;
  461. QIcon mediaIcon;
  462. QIcon browserIcon;
  463. QIcon groupIcon;
  464. QIcon sceneIcon;
  465. QIcon defaultIcon;
  466. QIcon audioProcessOutputIcon;
  467. QIcon GetImageIcon() const;
  468. QIcon GetColorIcon() const;
  469. QIcon GetSlideshowIcon() const;
  470. QIcon GetAudioInputIcon() const;
  471. QIcon GetAudioOutputIcon() const;
  472. QIcon GetDesktopCapIcon() const;
  473. QIcon GetWindowCapIcon() const;
  474. QIcon GetGameCapIcon() const;
  475. QIcon GetCameraIcon() const;
  476. QIcon GetTextIcon() const;
  477. QIcon GetMediaIcon() const;
  478. QIcon GetBrowserIcon() const;
  479. QIcon GetDefaultIcon() const;
  480. QIcon GetAudioProcessOutputIcon() const;
  481. QSlider *tBar;
  482. bool tBarActive = false;
  483. OBSSource GetOverrideTransition(OBSSource source);
  484. int GetOverrideTransitionDuration(OBSSource source);
  485. void UpdateProjectorHideCursor();
  486. void UpdateProjectorAlwaysOnTop(bool top);
  487. void ResetProjectors();
  488. QPointer<QObject> screenshotData;
  489. void MoveSceneItem(enum obs_order_movement movement,
  490. const QString &action_name);
  491. bool autoStartBroadcast = true;
  492. bool autoStopBroadcast = true;
  493. bool broadcastActive = false;
  494. bool broadcastReady = false;
  495. QPointer<QThread> youtubeStreamCheckThread;
  496. #if YOUTUBE_ENABLED
  497. void YoutubeStreamCheck(const std::string &key);
  498. void ShowYouTubeAutoStartWarning();
  499. void YouTubeActionDialogOk(const QString &id, const QString &key,
  500. bool autostart, bool autostop,
  501. bool start_now);
  502. #endif
  503. void BroadcastButtonClicked();
  504. void SetBroadcastFlowEnabled(bool enabled);
  505. void UpdatePreviewSafeAreas();
  506. bool drawSafeAreas = false;
  507. void CenterSelectedSceneItems(const CenterType &centerType);
  508. void ShowMissingFilesDialog(obs_missing_files_t *files);
  509. QColor selectionColor;
  510. QColor cropColor;
  511. QColor hoverColor;
  512. QColor GetSelectionColor() const;
  513. QColor GetCropColor() const;
  514. QColor GetHoverColor() const;
  515. public slots:
  516. void DeferSaveBegin();
  517. void DeferSaveEnd();
  518. void DisplayStreamStartError();
  519. void SetupBroadcast();
  520. void StartStreaming();
  521. void StopStreaming();
  522. void ForceStopStreaming();
  523. void StreamDelayStarting(int sec);
  524. void StreamDelayStopping(int sec);
  525. void StreamingStart();
  526. void StreamStopping();
  527. void StreamingStop(int errorcode, QString last_error);
  528. void StartRecording();
  529. void StopRecording();
  530. void RecordingStart();
  531. void RecordStopping();
  532. void RecordingStop(int code, QString last_error);
  533. void RecordingFileChanged(QString lastRecordingPath);
  534. void ShowReplayBufferPauseWarning();
  535. void StartReplayBuffer();
  536. void StopReplayBuffer();
  537. void ReplayBufferStart();
  538. void ReplayBufferSave();
  539. void ReplayBufferSaved();
  540. void ReplayBufferStopping();
  541. void ReplayBufferStop(int code);
  542. void StartVirtualCam();
  543. void StopVirtualCam();
  544. void OnVirtualCamStart();
  545. void OnVirtualCamStop(int code);
  546. void SaveProjectDeferred();
  547. void SaveProject();
  548. void SetTransition(OBSSource transition);
  549. void OverrideTransition(OBSSource transition);
  550. void TransitionToScene(OBSScene scene, bool force = false);
  551. void TransitionToScene(OBSSource scene, bool force = false,
  552. bool quickTransition = false,
  553. int quickDuration = 0, bool black = false,
  554. bool manual = false);
  555. void SetCurrentScene(OBSSource scene, bool force = false);
  556. bool AddSceneCollection(bool create_new,
  557. const QString &name = QString());
  558. bool NewProfile(const QString &name);
  559. bool DuplicateProfile(const QString &name);
  560. void DeleteProfile(const QString &profileName);
  561. void UpdatePatronJson(const QString &text, const QString &error);
  562. void ShowContextBar();
  563. void HideContextBar();
  564. void PauseRecording();
  565. void UnpauseRecording();
  566. private slots:
  567. void on_actionMainUndo_triggered();
  568. void on_actionMainRedo_triggered();
  569. void AddSceneItem(OBSSceneItem item);
  570. void AddScene(OBSSource source);
  571. void RemoveScene(OBSSource source);
  572. void RenameSources(OBSSource source, QString newName, QString prevName);
  573. void ActivateAudioSource(OBSSource source);
  574. void DeactivateAudioSource(OBSSource source);
  575. void DuplicateSelectedScene();
  576. void RemoveSelectedScene();
  577. void ToggleAlwaysOnTop();
  578. void ReorderSources(OBSScene scene);
  579. void RefreshSources(OBSScene scene);
  580. void ProcessHotkey(obs_hotkey_id id, bool pressed);
  581. void AddTransition();
  582. void RenameTransition();
  583. void TransitionClicked();
  584. void TransitionStopped();
  585. void TransitionFullyStopped();
  586. void TriggerQuickTransition(int id);
  587. void SetDeinterlacingMode();
  588. void SetDeinterlacingOrder();
  589. void SetScaleFilter();
  590. void SetBlendingMethod();
  591. void SetBlendingMode();
  592. void IconActivated(QSystemTrayIcon::ActivationReason reason);
  593. void SetShowing(bool showing);
  594. void ToggleShowHide();
  595. void HideAudioControl();
  596. void UnhideAllAudioControls();
  597. void ToggleHideMixer();
  598. void MixerRenameSource();
  599. void on_vMixerScrollArea_customContextMenuRequested();
  600. void on_hMixerScrollArea_customContextMenuRequested();
  601. void on_actionCopySource_triggered();
  602. void on_actionPasteRef_triggered();
  603. void on_actionPasteDup_triggered();
  604. void on_actionCopyFilters_triggered();
  605. void on_actionPasteFilters_triggered();
  606. void ColorChange();
  607. SourceTreeItem *GetItemWidgetFromSceneItem(obs_sceneitem_t *sceneItem);
  608. void on_actionShowAbout_triggered();
  609. void AudioMixerCopyFilters();
  610. void AudioMixerPasteFilters();
  611. void EnablePreview();
  612. void DisablePreview();
  613. void SceneCopyFilters();
  614. void ScenePasteFilters();
  615. void CheckDiskSpaceRemaining();
  616. void OpenSavedProjector(SavedProjectorInfo *info);
  617. void ScenesReordered();
  618. void ResetStatsHotkey();
  619. void SetImageIcon(const QIcon &icon);
  620. void SetColorIcon(const QIcon &icon);
  621. void SetSlideshowIcon(const QIcon &icon);
  622. void SetAudioInputIcon(const QIcon &icon);
  623. void SetAudioOutputIcon(const QIcon &icon);
  624. void SetDesktopCapIcon(const QIcon &icon);
  625. void SetWindowCapIcon(const QIcon &icon);
  626. void SetGameCapIcon(const QIcon &icon);
  627. void SetCameraIcon(const QIcon &icon);
  628. void SetTextIcon(const QIcon &icon);
  629. void SetMediaIcon(const QIcon &icon);
  630. void SetBrowserIcon(const QIcon &icon);
  631. void SetGroupIcon(const QIcon &icon);
  632. void SetSceneIcon(const QIcon &icon);
  633. void SetDefaultIcon(const QIcon &icon);
  634. void SetAudioProcessOutputIcon(const QIcon &icon);
  635. void TBarChanged(int value);
  636. void TBarReleased();
  637. void LockVolumeControl(bool lock);
  638. private:
  639. /* OBS Callbacks */
  640. static void SceneReordered(void *data, calldata_t *params);
  641. static void SceneRefreshed(void *data, calldata_t *params);
  642. static void SceneItemAdded(void *data, calldata_t *params);
  643. static void SourceCreated(void *data, calldata_t *params);
  644. static void SourceRemoved(void *data, calldata_t *params);
  645. static void SourceActivated(void *data, calldata_t *params);
  646. static void SourceDeactivated(void *data, calldata_t *params);
  647. static void SourceAudioActivated(void *data, calldata_t *params);
  648. static void SourceAudioDeactivated(void *data, calldata_t *params);
  649. static void SourceRenamed(void *data, calldata_t *params);
  650. static void RenderMain(void *data, uint32_t cx, uint32_t cy);
  651. void ResizePreview(uint32_t cx, uint32_t cy);
  652. void AddSource(const char *id);
  653. QMenu *CreateAddSourcePopupMenu();
  654. void AddSourcePopupMenu(const QPoint &pos);
  655. void copyActionsDynamicProperties();
  656. static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
  657. void AutoRemux(QString input, bool no_show = false);
  658. void UpdatePause(bool activate = true);
  659. void UpdateReplayBuffer(bool activate = true);
  660. bool OutputPathValid();
  661. void OutputPathInvalidMessage();
  662. bool LowDiskSpace();
  663. void DiskSpaceMessage();
  664. OBSSource prevFTBSource = nullptr;
  665. public:
  666. OBSSource GetProgramSource();
  667. OBSScene GetCurrentScene();
  668. void SysTrayNotify(const QString &text, QSystemTrayIcon::MessageIcon n);
  669. inline OBSSource GetCurrentSceneSource()
  670. {
  671. OBSScene curScene = GetCurrentScene();
  672. return OBSSource(obs_scene_get_source(curScene));
  673. }
  674. obs_service_t *GetService();
  675. void SetService(obs_service_t *service);
  676. int GetTransitionDuration();
  677. int GetTbarPosition();
  678. inline bool IsPreviewProgramMode() const
  679. {
  680. return os_atomic_load_bool(&previewProgramMode);
  681. }
  682. inline bool VCamEnabled() const { return vcamEnabled; }
  683. bool Active() const;
  684. void ResetUI();
  685. int ResetVideo();
  686. bool ResetAudio();
  687. void AddVCamButton();
  688. void ResetOutputs();
  689. void RefreshVolumeColors();
  690. void ResetAudioDevice(const char *sourceId, const char *deviceId,
  691. const char *deviceDesc, int channel);
  692. void NewProject();
  693. void LoadProject();
  694. inline void GetDisplayRect(int &x, int &y, int &cx, int &cy)
  695. {
  696. x = previewX;
  697. y = previewY;
  698. cx = previewCX;
  699. cy = previewCY;
  700. }
  701. inline bool SavingDisabled() const { return disableSaving; }
  702. inline double GetCPUUsage() const
  703. {
  704. return os_cpu_usage_info_query(cpuUsageInfo);
  705. }
  706. void SaveService();
  707. bool LoadService();
  708. inline Auth *GetAuth() { return auth.get(); }
  709. inline void EnableOutputs(bool enable)
  710. {
  711. if (enable) {
  712. if (--disableOutputsRef < 0)
  713. disableOutputsRef = 0;
  714. } else {
  715. disableOutputsRef++;
  716. }
  717. }
  718. QMenu *AddDeinterlacingMenu(QMenu *menu, obs_source_t *source);
  719. QMenu *AddScaleFilteringMenu(QMenu *menu, obs_sceneitem_t *item);
  720. QMenu *AddBlendingMethodMenu(QMenu *menu, obs_sceneitem_t *item);
  721. QMenu *AddBlendingModeMenu(QMenu *menu, obs_sceneitem_t *item);
  722. QMenu *AddBackgroundColorMenu(QMenu *menu, QWidgetAction *widgetAction,
  723. ColorSelect *select,
  724. obs_sceneitem_t *item);
  725. void CreateSourcePopupMenu(int idx, bool preview);
  726. void UpdateTitleBar();
  727. void SystemTrayInit();
  728. void SystemTray(bool firstStarted);
  729. void OpenSavedProjectors();
  730. void CreateInteractionWindow(obs_source_t *source);
  731. void CreatePropertiesWindow(obs_source_t *source);
  732. void CreateFiltersWindow(obs_source_t *source);
  733. QAction *AddDockWidget(QDockWidget *dock);
  734. static OBSBasic *Get();
  735. const char *GetCurrentOutputPath();
  736. void DeleteProjector(OBSProjector *projector);
  737. void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  738. const char *slot);
  739. QIcon GetSourceIcon(const char *id) const;
  740. QIcon GetGroupIcon() const;
  741. QIcon GetSceneIcon() const;
  742. OBSWeakSource copyFilter;
  743. void ShowStatusBarMessage(const QString &message);
  744. static OBSData
  745. BackupScene(obs_scene_t *scene,
  746. std::vector<obs_source_t *> *sources = nullptr);
  747. void CreateSceneUndoRedoAction(const QString &action_name,
  748. OBSData undo_data, OBSData redo_data);
  749. static inline OBSData
  750. BackupScene(obs_source_t *scene_source,
  751. std::vector<obs_source_t *> *sources = nullptr)
  752. {
  753. obs_scene_t *scene = obs_scene_from_source(scene_source);
  754. return BackupScene(scene, sources);
  755. }
  756. void CreateFilterPasteUndoRedoAction(const QString &text,
  757. obs_source_t *source,
  758. obs_data_array_t *undo_array,
  759. obs_data_array_t *redo_array);
  760. void UpdateEditMenu();
  761. void SetDisplayAffinity(QWindow *window);
  762. protected:
  763. virtual void closeEvent(QCloseEvent *event) override;
  764. #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
  765. virtual bool nativeEvent(const QByteArray &eventType, void *message,
  766. qintptr *result) override;
  767. #else
  768. virtual bool nativeEvent(const QByteArray &eventType, void *message,
  769. long *result) override;
  770. #endif
  771. virtual void changeEvent(QEvent *event) override;
  772. private slots:
  773. void on_actionFullscreenInterface_triggered();
  774. void on_actionShow_Recordings_triggered();
  775. void on_actionRemux_triggered();
  776. void on_action_Settings_triggered();
  777. void on_actionShowMissingFiles_triggered();
  778. void on_actionAdvAudioProperties_triggered();
  779. void on_actionShowLogs_triggered();
  780. void on_actionUploadCurrentLog_triggered();
  781. void on_actionUploadLastLog_triggered();
  782. void on_actionViewCurrentLog_triggered();
  783. void on_actionCheckForUpdates_triggered();
  784. void on_actionRepair_triggered();
  785. void on_actionShowCrashLogs_triggered();
  786. void on_actionUploadLastCrashLog_triggered();
  787. void on_actionEditTransform_triggered();
  788. void on_actionCopyTransform_triggered();
  789. void on_actionPasteTransform_triggered();
  790. void on_actionRotate90CW_triggered();
  791. void on_actionRotate90CCW_triggered();
  792. void on_actionRotate180_triggered();
  793. void on_actionFlipHorizontal_triggered();
  794. void on_actionFlipVertical_triggered();
  795. void on_actionFitToScreen_triggered();
  796. void on_actionStretchToScreen_triggered();
  797. void on_actionCenterToScreen_triggered();
  798. void on_actionVerticalCenter_triggered();
  799. void on_actionHorizontalCenter_triggered();
  800. void on_customContextMenuRequested(const QPoint &pos);
  801. void on_scenes_currentItemChanged(QListWidgetItem *current,
  802. QListWidgetItem *prev);
  803. void on_scenes_customContextMenuRequested(const QPoint &pos);
  804. void GridActionClicked();
  805. void on_actionAddScene_triggered();
  806. void on_actionRemoveScene_triggered();
  807. void on_actionSceneUp_triggered();
  808. void on_actionSceneDown_triggered();
  809. void on_sources_customContextMenuRequested(const QPoint &pos);
  810. void on_scenes_itemDoubleClicked(QListWidgetItem *item);
  811. void on_actionAddSource_triggered();
  812. void on_actionRemoveSource_triggered();
  813. void on_actionInteract_triggered();
  814. void on_actionSourceProperties_triggered();
  815. void on_actionSourceUp_triggered();
  816. void on_actionSourceDown_triggered();
  817. void on_actionMoveUp_triggered();
  818. void on_actionMoveDown_triggered();
  819. void on_actionMoveToTop_triggered();
  820. void on_actionMoveToBottom_triggered();
  821. void on_actionLockPreview_triggered();
  822. void on_scalingMenu_aboutToShow();
  823. void on_actionScaleWindow_triggered();
  824. void on_actionScaleCanvas_triggered();
  825. void on_actionScaleOutput_triggered();
  826. void on_streamButton_clicked();
  827. void on_recordButton_clicked();
  828. void VCamButtonClicked();
  829. void on_settingsButton_clicked();
  830. void Screenshot(OBSSource source_ = nullptr);
  831. void ScreenshotSelectedSource();
  832. void ScreenshotProgram();
  833. void ScreenshotScene();
  834. void on_actionHelpPortal_triggered();
  835. void on_actionWebsite_triggered();
  836. void on_actionDiscord_triggered();
  837. void on_preview_customContextMenuRequested(const QPoint &pos);
  838. void ProgramViewContextMenuRequested(const QPoint &pos);
  839. void PreviewDisabledMenu(const QPoint &pos);
  840. void on_actionNewSceneCollection_triggered();
  841. void on_actionDupSceneCollection_triggered();
  842. void on_actionRenameSceneCollection_triggered();
  843. void on_actionRemoveSceneCollection_triggered();
  844. void on_actionImportSceneCollection_triggered();
  845. void on_actionExportSceneCollection_triggered();
  846. void on_actionNewProfile_triggered();
  847. void on_actionDupProfile_triggered();
  848. void on_actionRenameProfile_triggered();
  849. void on_actionRemoveProfile_triggered(bool skipConfirmation = false);
  850. void on_actionImportProfile_triggered();
  851. void on_actionExportProfile_triggered();
  852. void on_actionShowSettingsFolder_triggered();
  853. void on_actionShowProfileFolder_triggered();
  854. void on_actionAlwaysOnTop_triggered();
  855. void on_toggleListboxToolbars_toggled(bool visible);
  856. void on_toggleContextBar_toggled(bool visible);
  857. void on_toggleStatusBar_toggled(bool visible);
  858. void on_toggleSourceIcons_toggled(bool visible);
  859. void on_transitions_currentIndexChanged(int index);
  860. void on_transitionAdd_clicked();
  861. void on_transitionRemove_clicked();
  862. void on_transitionProps_clicked();
  863. void on_transitionDuration_valueChanged(int value);
  864. void on_tbar_position_valueChanged(int value);
  865. void on_actionShowTransitionProperties_triggered();
  866. void on_actionHideTransitionProperties_triggered();
  867. void on_modeSwitch_clicked();
  868. // Source Context Buttons
  869. void on_sourcePropertiesButton_clicked();
  870. void on_sourceFiltersButton_clicked();
  871. void on_sourceInteractButton_clicked();
  872. void on_autoConfigure_triggered();
  873. void on_stats_triggered();
  874. void on_resetUI_triggered();
  875. void on_resetDocks_triggered(bool force = false);
  876. void on_lockDocks_toggled(bool lock);
  877. void PauseToggled();
  878. void logUploadFinished(const QString &text, const QString &error);
  879. void crashUploadFinished(const QString &text, const QString &error);
  880. void openLogDialog(const QString &text, const bool crash);
  881. void updateCheckFinished();
  882. void AddSourceFromAction();
  883. void MoveSceneToTop();
  884. void MoveSceneToBottom();
  885. void EditSceneName();
  886. void EditSceneItemName();
  887. void SceneNameEdited(QWidget *editor,
  888. QAbstractItemDelegate::EndEditHint endHint);
  889. void OpenSceneFilters();
  890. void OpenFilters(OBSSource source = nullptr);
  891. void OpenProperties(OBSSource source = nullptr);
  892. void OpenInteraction(OBSSource source = nullptr);
  893. void EnablePreviewDisplay(bool enable);
  894. void TogglePreview();
  895. void NudgeUp();
  896. void NudgeDown();
  897. void NudgeLeft();
  898. void NudgeRight();
  899. void NudgeUpFar();
  900. void NudgeDownFar();
  901. void NudgeLeftFar();
  902. void NudgeRightFar();
  903. void OpenStudioProgramProjector();
  904. void OpenPreviewProjector();
  905. void OpenSourceProjector();
  906. void OpenMultiviewProjector();
  907. void OpenSceneProjector();
  908. void OpenStudioProgramWindow();
  909. void OpenPreviewWindow();
  910. void OpenSourceWindow();
  911. void OpenMultiviewWindow();
  912. void OpenSceneWindow();
  913. void StackedMixerAreaContextMenuRequested();
  914. public slots:
  915. void on_actionResetTransform_triggered();
  916. bool StreamingActive();
  917. bool RecordingActive();
  918. bool ReplayBufferActive();
  919. bool VirtualCamActive();
  920. void ClearContextBar();
  921. void UpdateContextBar(bool force = false);
  922. void UpdateContextBarDeferred(bool force = false);
  923. void UpdateContextBarVisibility();
  924. private:
  925. std::unique_ptr<Ui::OBSBasic> ui;
  926. public:
  927. /* `undo_s` needs to be declared after `ui` to prevent an uninitialized
  928. * warning for `ui` while initializing `undo_s`. */
  929. undo_stack undo_s;
  930. explicit OBSBasic(QWidget *parent = 0);
  931. virtual ~OBSBasic();
  932. virtual void OBSInit() override;
  933. virtual config_t *Config() const override;
  934. virtual int GetProfilePath(char *path, size_t size,
  935. const char *file) const override;
  936. static void InitBrowserPanelSafeBlock();
  937. };
  938. class SceneRenameDelegate : public QStyledItemDelegate {
  939. Q_OBJECT
  940. public:
  941. SceneRenameDelegate(QObject *parent);
  942. virtual void setEditorData(QWidget *editor,
  943. const QModelIndex &index) const override;
  944. protected:
  945. virtual bool eventFilter(QObject *editor, QEvent *event) override;
  946. };