window-basic-main.hpp 34 KB

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