AudioMixer.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /******************************************************************************
  2. Copyright (C) 2025 by Taylor Giampaolo <[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 "OBSBasic.hpp"
  16. #include <components/MenuCheckBox.hpp>
  17. #include <components/VolumeControl.hpp>
  18. #include <QObject>
  19. #include <QPointer>
  20. #include <QTimer>
  21. #include <unordered_set>
  22. class QHBoxLayout;
  23. class QMenu;
  24. class QPushButton;
  25. class QScrollArea;
  26. class QStackedWidget;
  27. class QToolBar;
  28. class QVBoxLayout;
  29. class AudioMixer : public QFrame {
  30. Q_OBJECT
  31. struct RankedVolume {
  32. VolumeControl *control;
  33. int sortingWeight;
  34. };
  35. public:
  36. explicit AudioMixer(QWidget *parent = 0);
  37. ~AudioMixer();
  38. void refreshVolumeColors();
  39. void setMixerLayoutVertical(bool vertical);
  40. void createMixerContextMenu();
  41. void showMixerContextMenu();
  42. private:
  43. std::vector<OBSSignal> signalHandlers;
  44. static void onFrontendEvent(enum obs_frontend_event event, void *data);
  45. void handleFrontendEvent(enum obs_frontend_event event);
  46. std::unordered_map<QString, QPointer<VolumeControl>> volumeList;
  47. void addControlForUuid(QString uuid);
  48. void removeControlForUuid(QString uuid);
  49. std::unordered_set<QString> globalSources;
  50. std::unordered_set<QString> previewSources;
  51. bool mixerVertical{false};
  52. int hiddenCount{0};
  53. bool showHidden{false};
  54. bool showInactive{false};
  55. bool keepInactiveLast{false};
  56. bool keepHiddenLast{false};
  57. bool showToolbar{true};
  58. QFrame *mixerFrame{nullptr};
  59. QVBoxLayout *mainLayout{nullptr};
  60. QVBoxLayout *mixerLayout{nullptr};
  61. QStackedWidget *stackedMixerArea{nullptr};
  62. QToolBar *mixerToolbar{nullptr};
  63. QAction *layoutButton{nullptr};
  64. QAction *advAudio{nullptr};
  65. QPushButton *optionsButton{nullptr};
  66. QPushButton *toggleHiddenButton{nullptr};
  67. QPointer<QMenu> mixerMenu;
  68. QPointer<MenuCheckBox> showHiddenCheckBox;
  69. QPointer<QWidgetAction> showHiddenAction;
  70. QScrollArea *hMixerScrollArea{nullptr};
  71. QWidget *hVolumeWidgets{nullptr};
  72. QVBoxLayout *hVolumeControlLayout{nullptr};
  73. QScrollArea *vMixerScrollArea{nullptr};
  74. QWidget *vVolumeWidgets{nullptr};
  75. QHBoxLayout *vVolumeControlLayout{nullptr};
  76. QBoxLayout *activeLayout() const;
  77. void reloadVolumeControls();
  78. bool getMixerVisibilityForControl(VolumeControl *widget);
  79. void clearPreviewSources();
  80. bool isSourcePreviewed(obs_source_t *source);
  81. bool isSourceGlobal(obs_source_t *source);
  82. void clearVolumeControls();
  83. void updateShowInactive();
  84. void updateKeepInactiveLast();
  85. void updateShowHidden();
  86. void updateKeepHiddenLast();
  87. void updateShowToolbar();
  88. QTimer updateTimer;
  89. void updateVolumeLayouts();
  90. // OBS Callbacks
  91. static void obsSourceActivated(void *data, calldata_t *params);
  92. static void obsSourceDeactivated(void *data, calldata_t *params);
  93. static void obsSourceAudioActivated(void *data, calldata_t *params);
  94. static void obsSourceAudioDeactivated(void *data, calldata_t *params);
  95. static void obsSourceCreate(void *data, calldata_t *params);
  96. static void obsSourceRemove(void *data, calldata_t *params);
  97. static void obsSourceRename(void *data, calldata_t *params);
  98. private slots:
  99. void sourceCreated(QString uuid);
  100. void sourceRemoved(QString uuid);
  101. void updatePreviewSources();
  102. void updateGlobalSources();
  103. void unhideAllAudioControls();
  104. void queueLayoutUpdate();
  105. VolumeControl *createVolumeControl(obs_source_t *source);
  106. void updateControlVisibility(QString uuid);
  107. void updateLayout();
  108. void toggleShowInactive(bool checked);
  109. void toggleKeepInactiveLast(bool checked);
  110. void toggleShowHidden(bool checked);
  111. void toggleKeepHiddenLast(bool checked);
  112. void mixerContextMenuRequested();
  113. signals:
  114. void advAudioPropertiesClicked();
  115. };