window-basic-main.hpp 29 KB

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