window-basic-main.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. obs_hotkey_pair_id streamingHotkeys, recordingHotkeys;
  126. public slots:
  127. void StartStreaming();
  128. void StopStreaming();
  129. void StreamingStart();
  130. void StreamingStop(int errorcode);
  131. void StartRecording();
  132. void StopRecording();
  133. void RecordingStart();
  134. void RecordingStop(int code);
  135. void SaveProject();
  136. private slots:
  137. void AddSceneItem(OBSSceneItem item);
  138. void RemoveSceneItem(OBSSceneItem item);
  139. void AddScene(OBSSource source);
  140. void RemoveScene(OBSSource source);
  141. void UpdateSceneSelection(OBSSource source);
  142. void RenameSources(QString newName, QString prevName);
  143. void SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select);
  144. void ActivateAudioSource(OBSSource source);
  145. void DeactivateAudioSource(OBSSource source);
  146. void RemoveSelectedScene();
  147. void RemoveSelectedSceneItem();
  148. void ReorderSources(OBSScene scene);
  149. void ProcessHotkey(obs_hotkey_id id, bool pressed);
  150. private:
  151. /* OBS Callbacks */
  152. static void SceneReordered(void *data, calldata_t *params);
  153. static void SceneItemAdded(void *data, calldata_t *params);
  154. static void SceneItemRemoved(void *data, calldata_t *params);
  155. static void SceneItemSelected(void *data, calldata_t *params);
  156. static void SceneItemDeselected(void *data, calldata_t *params);
  157. static void SourceAdded(void *data, calldata_t *params);
  158. static void SourceRemoved(void *data, calldata_t *params);
  159. static void SourceActivated(void *data, calldata_t *params);
  160. static void SourceDeactivated(void *data, calldata_t *params);
  161. static void SourceRenamed(void *data, calldata_t *params);
  162. static void ChannelChanged(void *data, calldata_t *params);
  163. static void RenderMain(void *data, uint32_t cx, uint32_t cy);
  164. void ResizePreview(uint32_t cx, uint32_t cy);
  165. void AddSource(const char *id);
  166. QMenu *CreateAddSourcePopupMenu();
  167. void AddSourcePopupMenu(const QPoint &pos);
  168. void copyActionsDynamicProperties();
  169. static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
  170. public:
  171. OBSScene GetCurrentScene();
  172. obs_service_t *GetService();
  173. void SetService(obs_service_t *service);
  174. bool StreamingActive();
  175. int ResetVideo();
  176. bool ResetAudio();
  177. void ResetOutputs();
  178. void ResetAudioDevice(const char *sourceId, const char *deviceId,
  179. const char *deviceDesc, int channel);
  180. void NewProject();
  181. void LoadProject();
  182. inline void GetDisplayRect(int &x, int &y, int &cx, int &cy)
  183. {
  184. x = previewX;
  185. y = previewY;
  186. cx = previewCX;
  187. cy = previewCY;
  188. }
  189. inline double GetCPUUsage() const
  190. {
  191. return os_cpu_usage_info_query(cpuUsageInfo);
  192. }
  193. void SaveService();
  194. bool LoadService();
  195. void ReorderSceneItem(obs_sceneitem_t *item, size_t idx);
  196. void CreateSourcePopupMenu(QListWidgetItem *item, bool preview);
  197. void UpdateTitleBar();
  198. protected:
  199. virtual void closeEvent(QCloseEvent *event) override;
  200. virtual void changeEvent(QEvent *event) override;
  201. virtual void resizeEvent(QResizeEvent *event) override;
  202. private slots:
  203. void on_actionShow_Recordings_triggered();
  204. void on_actionRemux_triggered();
  205. void on_action_Settings_triggered();
  206. void on_actionAdvAudioProperties_triggered();
  207. void on_advAudioProps_clicked();
  208. void on_advAudioProps_destroyed();
  209. void on_actionShowLogs_triggered();
  210. void on_actionUploadCurrentLog_triggered();
  211. void on_actionUploadLastLog_triggered();
  212. void on_actionViewCurrentLog_triggered();
  213. void on_actionCheckForUpdates_triggered();
  214. void on_actionEditTransform_triggered();
  215. void on_actionResetTransform_triggered();
  216. void on_actionRotate90CW_triggered();
  217. void on_actionRotate90CCW_triggered();
  218. void on_actionRotate180_triggered();
  219. void on_actionFlipHorizontal_triggered();
  220. void on_actionFlipVertical_triggered();
  221. void on_actionFitToScreen_triggered();
  222. void on_actionStretchToScreen_triggered();
  223. void on_actionCenterToScreen_triggered();
  224. void on_scenes_currentItemChanged(QListWidgetItem *current,
  225. QListWidgetItem *prev);
  226. void on_scenes_customContextMenuRequested(const QPoint &pos);
  227. void on_actionAddScene_triggered();
  228. void on_actionRemoveScene_triggered();
  229. void on_actionSceneUp_triggered();
  230. void on_actionSceneDown_triggered();
  231. void on_sources_currentItemChanged(QListWidgetItem *current,
  232. QListWidgetItem *prev);
  233. void on_sources_customContextMenuRequested(const QPoint &pos);
  234. void on_sources_itemDoubleClicked(QListWidgetItem *item);
  235. void on_actionAddSource_triggered();
  236. void on_actionRemoveSource_triggered();
  237. void on_actionInteract_triggered();
  238. void on_actionSourceProperties_triggered();
  239. void on_actionSourceUp_triggered();
  240. void on_actionSourceDown_triggered();
  241. void on_actionMoveUp_triggered();
  242. void on_actionMoveDown_triggered();
  243. void on_actionMoveToTop_triggered();
  244. void on_actionMoveToBottom_triggered();
  245. void on_streamButton_clicked();
  246. void on_recordButton_clicked();
  247. void on_settingsButton_clicked();
  248. void on_actionWebsite_triggered();
  249. void on_preview_customContextMenuRequested(const QPoint &pos);
  250. void on_previewDisabledLabel_customContextMenuRequested(
  251. const QPoint &pos);
  252. void on_actionNewSceneCollection_triggered();
  253. void on_actionDupSceneCollection_triggered();
  254. void on_actionRenameSceneCollection_triggered();
  255. void on_actionRemoveSceneCollection_triggered();
  256. void logUploadFinished(const QString &text, const QString &error);
  257. void updateFileFinished(const QString &text, const QString &error);
  258. void AddSourceFromAction();
  259. void MoveSceneToTop();
  260. void MoveSceneToBottom();
  261. void EditSceneName();
  262. void EditSceneItemName();
  263. void SceneNameEdited(QWidget *editor,
  264. QAbstractItemDelegate::EndEditHint endHint);
  265. void SceneItemNameEdited(QWidget *editor,
  266. QAbstractItemDelegate::EndEditHint endHint);
  267. void OpenSceneFilters();
  268. void OpenFilters();
  269. void TogglePreview();
  270. void NudgeUp();
  271. void NudgeDown();
  272. void NudgeLeft();
  273. void NudgeRight();
  274. void OpenPreviewProjector();
  275. void OpenSourceProjector();
  276. void OpenSceneProjector();
  277. public:
  278. explicit OBSBasic(QWidget *parent = 0);
  279. virtual ~OBSBasic();
  280. virtual void OBSInit() override;
  281. virtual config_t *Config() const override;
  282. private:
  283. std::unique_ptr<Ui::OBSBasic> ui;
  284. };