window-basic-main.hpp 34 KB

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