window-basic-main.hpp 11 KB

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