window-basic-main.hpp 32 KB

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