window-basic-main.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 <obs.hpp>
  18. #include <unordered_map>
  19. #include <vector>
  20. #include <memory>
  21. #include "window-main.hpp"
  22. #include "window-basic-interaction.hpp"
  23. #include "window-basic-properties.hpp"
  24. #include "window-basic-transform.hpp"
  25. #include "window-basic-adv-audio.hpp"
  26. #include "window-basic-filters.hpp"
  27. #include <util/platform.h>
  28. #include <util/util.hpp>
  29. #include <QPointer>
  30. class QListWidgetItem;
  31. class VolControl;
  32. class QNetworkReply;
  33. #include "ui_OBSBasic.h"
  34. #define DESKTOP_AUDIO_1 Str("DesktopAudioDevice1")
  35. #define DESKTOP_AUDIO_2 Str("DesktopAudioDevice2")
  36. #define AUX_AUDIO_1 Str("AuxAudioDevice1")
  37. #define AUX_AUDIO_2 Str("AuxAudioDevice2")
  38. #define AUX_AUDIO_3 Str("AuxAudioDevice3")
  39. struct BasicOutputHandler;
  40. enum class QtDataRole {
  41. OBSRef = Qt::UserRole,
  42. OBSSignals,
  43. };
  44. class OBSBasic : public OBSMainWindow {
  45. Q_OBJECT
  46. friend class OBSBasicPreview;
  47. enum class MoveDir {
  48. Up,
  49. Down,
  50. Left,
  51. Right
  52. };
  53. private:
  54. std::unordered_map<obs_source_t*, int> sourceSceneRefs;
  55. std::vector<VolControl*> volumes;
  56. std::vector<OBSSignal> signalHandlers;
  57. bool loaded = false;
  58. long disableSaving = 1;
  59. bool projectChanged = false;
  60. QPointer<QThread> updateCheckThread;
  61. QPointer<QThread> logUploadThread;
  62. QPointer<OBSBasicInteraction> interaction;
  63. QPointer<OBSBasicProperties> properties;
  64. QPointer<OBSBasicTransform> transformWindow;
  65. QPointer<OBSBasicAdvAudio> advAudioWindow;
  66. QPointer<OBSBasicFilters> filters;
  67. QPointer<QTimer> cpuUsageTimer;
  68. os_cpu_usage_info_t *cpuUsageInfo = nullptr;
  69. OBSService service;
  70. std::unique_ptr<BasicOutputHandler> outputHandler;
  71. gs_vertbuffer_t *box = nullptr;
  72. gs_vertbuffer_t *circle = nullptr;
  73. bool sceneChanging = false;
  74. bool ignoreSelectionUpdate = false;
  75. int previewX = 0, previewY = 0;
  76. int previewCX = 0, previewCY = 0;
  77. float previewScale = 0.0f;
  78. ConfigFile basicConfig;
  79. QPointer<QWidget> projectors[10];
  80. void DrawBackdrop(float cx, float cy);
  81. void SetupEncoders();
  82. void CreateDefaultScene();
  83. void ClearVolumeControls();
  84. void UploadLog(const char *file);
  85. void Save(const char *file);
  86. void Load(const char *file);
  87. void InitHotkeys();
  88. void CreateHotkeys();
  89. void ClearHotkeys();
  90. bool InitService();
  91. bool InitBasicConfigDefaults();
  92. bool InitBasicConfig();
  93. void InitOBSCallbacks();
  94. void InitPrimitives();
  95. OBSSceneItem GetSceneItem(QListWidgetItem *item);
  96. OBSSceneItem GetCurrentSceneItem();
  97. bool QueryRemoveSource(obs_source_t *source);
  98. void TimedCheckForUpdates();
  99. void CheckForUpdates();
  100. void GetFPSCommon(uint32_t &num, uint32_t &den) const;
  101. void GetFPSInteger(uint32_t &num, uint32_t &den) const;
  102. void GetFPSFraction(uint32_t &num, uint32_t &den) const;
  103. void GetFPSNanoseconds(uint32_t &num, uint32_t &den) const;
  104. void GetConfigFPS(uint32_t &num, uint32_t &den) const;
  105. void UpdateSources(OBSScene scene);
  106. void InsertSceneItem(obs_sceneitem_t *item);
  107. void LoadSceneListOrder(obs_data_array_t *array);
  108. obs_data_array_t *SaveSceneListOrder();
  109. void ChangeSceneIndex(bool relative, int idx, int invalidIdx);
  110. void TempFileOutput(const char *path, int vBitrate, int aBitrate);
  111. void TempStreamOutput(const char *url, const char *key,
  112. int vBitrate, int aBitrate);
  113. void CreateInteractionWindow(obs_source_t *source);
  114. void CreatePropertiesWindow(obs_source_t *source);
  115. void CreateFiltersWindow(obs_source_t *source);
  116. void CloseDialogs();
  117. void ClearSceneData();
  118. void CleanupUnusedSources();
  119. void Nudge(int dist, MoveDir dir);
  120. void OpenProjector(obs_source_t *source, int monitor);
  121. void GetAudioSourceFilters();
  122. void GetAudioSourceProperties();
  123. void VolControlContextMenu();
  124. void AddSceneCollection(bool create_new);
  125. void RefreshSceneCollections();
  126. void ChangeSceneCollection();
  127. void LoadProfile();
  128. void ResetProfileData();
  129. bool AddProfile(bool create_new, const char *title, const char *text,
  130. const char *init_text = nullptr);
  131. void DeleteProfile(const char *profile_name, const char *profile_dir);
  132. void RefreshProfiles();
  133. void ChangeProfile();
  134. void SaveProjectNow();
  135. obs_hotkey_pair_id streamingHotkeys, recordingHotkeys;
  136. public slots:
  137. void StartStreaming();
  138. void StopStreaming();
  139. void StreamingStart();
  140. void StreamingStop(int errorcode);
  141. void StartRecording();
  142. void StopRecording();
  143. void RecordingStart();
  144. void RecordingStop(int code);
  145. void SaveProjectDeferred();
  146. void SaveProject();
  147. private slots:
  148. void AddSceneItem(OBSSceneItem item);
  149. void RemoveSceneItem(OBSSceneItem item);
  150. void AddScene(OBSSource source);
  151. void RemoveScene(OBSSource source);
  152. void UpdateSceneSelection(OBSSource source);
  153. void RenameSources(QString newName, QString prevName);
  154. void SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select);
  155. void ActivateAudioSource(OBSSource source);
  156. void DeactivateAudioSource(OBSSource source);
  157. void RemoveSelectedScene();
  158. void RemoveSelectedSceneItem();
  159. void ReorderSources(OBSScene scene);
  160. void ProcessHotkey(obs_hotkey_id id, bool pressed);
  161. private:
  162. /* OBS Callbacks */
  163. static void SceneReordered(void *data, calldata_t *params);
  164. static void SceneItemAdded(void *data, calldata_t *params);
  165. static void SceneItemRemoved(void *data, calldata_t *params);
  166. static void SceneItemSelected(void *data, calldata_t *params);
  167. static void SceneItemDeselected(void *data, calldata_t *params);
  168. static void SourceAdded(void *data, calldata_t *params);
  169. static void SourceRemoved(void *data, calldata_t *params);
  170. static void SourceActivated(void *data, calldata_t *params);
  171. static void SourceDeactivated(void *data, calldata_t *params);
  172. static void SourceRenamed(void *data, calldata_t *params);
  173. static void ChannelChanged(void *data, calldata_t *params);
  174. static void RenderMain(void *data, uint32_t cx, uint32_t cy);
  175. void ResizePreview(uint32_t cx, uint32_t cy);
  176. void AddSource(const char *id);
  177. QMenu *CreateAddSourcePopupMenu();
  178. void AddSourcePopupMenu(const QPoint &pos);
  179. void copyActionsDynamicProperties();
  180. static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
  181. public:
  182. OBSScene GetCurrentScene();
  183. obs_service_t *GetService();
  184. void SetService(obs_service_t *service);
  185. bool StreamingActive();
  186. int ResetVideo();
  187. bool ResetAudio();
  188. void ResetOutputs();
  189. void ResetAudioDevice(const char *sourceId, const char *deviceId,
  190. const char *deviceDesc, int channel);
  191. void NewProject();
  192. void LoadProject();
  193. inline void GetDisplayRect(int &x, int &y, int &cx, int &cy)
  194. {
  195. x = previewX;
  196. y = previewY;
  197. cx = previewCX;
  198. cy = previewCY;
  199. }
  200. inline double GetCPUUsage() const
  201. {
  202. return os_cpu_usage_info_query(cpuUsageInfo);
  203. }
  204. void SaveService();
  205. bool LoadService();
  206. void ReorderSceneItem(obs_sceneitem_t *item, size_t idx);
  207. void CreateSourcePopupMenu(QListWidgetItem *item, bool preview);
  208. void UpdateTitleBar();
  209. protected:
  210. virtual void closeEvent(QCloseEvent *event) override;
  211. virtual void changeEvent(QEvent *event) override;
  212. virtual void resizeEvent(QResizeEvent *event) override;
  213. private slots:
  214. void on_actionShow_Recordings_triggered();
  215. void on_actionRemux_triggered();
  216. void on_action_Settings_triggered();
  217. void on_actionAdvAudioProperties_triggered();
  218. void on_advAudioProps_clicked();
  219. void on_advAudioProps_destroyed();
  220. void on_actionShowLogs_triggered();
  221. void on_actionUploadCurrentLog_triggered();
  222. void on_actionUploadLastLog_triggered();
  223. void on_actionViewCurrentLog_triggered();
  224. void on_actionCheckForUpdates_triggered();
  225. void on_actionEditTransform_triggered();
  226. void on_actionResetTransform_triggered();
  227. void on_actionRotate90CW_triggered();
  228. void on_actionRotate90CCW_triggered();
  229. void on_actionRotate180_triggered();
  230. void on_actionFlipHorizontal_triggered();
  231. void on_actionFlipVertical_triggered();
  232. void on_actionFitToScreen_triggered();
  233. void on_actionStretchToScreen_triggered();
  234. void on_actionCenterToScreen_triggered();
  235. void on_scenes_currentItemChanged(QListWidgetItem *current,
  236. QListWidgetItem *prev);
  237. void on_scenes_customContextMenuRequested(const QPoint &pos);
  238. void on_actionAddScene_triggered();
  239. void on_actionRemoveScene_triggered();
  240. void on_actionSceneUp_triggered();
  241. void on_actionSceneDown_triggered();
  242. void on_sources_currentItemChanged(QListWidgetItem *current,
  243. QListWidgetItem *prev);
  244. void on_sources_customContextMenuRequested(const QPoint &pos);
  245. void on_sources_itemDoubleClicked(QListWidgetItem *item);
  246. void on_actionAddSource_triggered();
  247. void on_actionRemoveSource_triggered();
  248. void on_actionInteract_triggered();
  249. void on_actionSourceProperties_triggered();
  250. void on_actionSourceUp_triggered();
  251. void on_actionSourceDown_triggered();
  252. void on_actionMoveUp_triggered();
  253. void on_actionMoveDown_triggered();
  254. void on_actionMoveToTop_triggered();
  255. void on_actionMoveToBottom_triggered();
  256. void on_streamButton_clicked();
  257. void on_recordButton_clicked();
  258. void on_settingsButton_clicked();
  259. void on_actionWebsite_triggered();
  260. void on_preview_customContextMenuRequested(const QPoint &pos);
  261. void on_previewDisabledLabel_customContextMenuRequested(
  262. const QPoint &pos);
  263. void on_actionNewSceneCollection_triggered();
  264. void on_actionDupSceneCollection_triggered();
  265. void on_actionRenameSceneCollection_triggered();
  266. void on_actionRemoveSceneCollection_triggered();
  267. void on_actionNewProfile_triggered();
  268. void on_actionDupProfile_triggered();
  269. void on_actionRenameProfile_triggered();
  270. void on_actionRemoveProfile_triggered();
  271. void on_actionShowSettingsFolder_triggered();
  272. void on_actionShowProfileFolder_triggered();
  273. void logUploadFinished(const QString &text, const QString &error);
  274. void updateFileFinished(const QString &text, const QString &error);
  275. void AddSourceFromAction();
  276. void MoveSceneToTop();
  277. void MoveSceneToBottom();
  278. void EditSceneName();
  279. void EditSceneItemName();
  280. void SceneNameEdited(QWidget *editor,
  281. QAbstractItemDelegate::EndEditHint endHint);
  282. void SceneItemNameEdited(QWidget *editor,
  283. QAbstractItemDelegate::EndEditHint endHint);
  284. void OpenSceneFilters();
  285. void OpenFilters();
  286. void TogglePreview();
  287. void NudgeUp();
  288. void NudgeDown();
  289. void NudgeLeft();
  290. void NudgeRight();
  291. void OpenPreviewProjector();
  292. void OpenSourceProjector();
  293. void OpenSceneProjector();
  294. public:
  295. explicit OBSBasic(QWidget *parent = 0);
  296. virtual ~OBSBasic();
  297. virtual void OBSInit() override;
  298. virtual config_t *Config() const override;
  299. virtual int GetProfilePath(char *path, size_t size, const char *file)
  300. const;
  301. private:
  302. std::unique_ptr<Ui::OBSBasic> ui;
  303. };