window-basic-main.hpp 35 KB

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