window-basic-main.hpp 32 KB

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