window-basic-main.hpp 32 KB

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