VolumeControl.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #pragma once
  2. #include <obs.hpp>
  3. #include <components/VolumeName.hpp>
  4. #include <components/VolumeSlider.hpp>
  5. #include <Idian/Utils.hpp>
  6. #include <QFrame>
  7. #include <QPushButton>
  8. #include <QWidget>
  9. class MuteCheckBox;
  10. class QBoxLayout;
  11. class QLabel;
  12. class VolumeMeter;
  13. class VolumeControl : public QFrame {
  14. Q_OBJECT
  15. public:
  16. struct MixerStatus {
  17. enum Value : uint32_t {
  18. None = 0,
  19. Active = 1 << 0,
  20. Locked = 1 << 1,
  21. Global = 1 << 2,
  22. Pinned = 1 << 3,
  23. Hidden = 1 << 4,
  24. Unassigned = 1 << 5,
  25. Preview = 1 << 6,
  26. };
  27. MixerStatus() = default;
  28. MixerStatus(Value v) : bits(v) {}
  29. bool has(Value v) const { return (bits & v) != 0; }
  30. void set(Value v, bool enable)
  31. {
  32. if (enable) {
  33. bits |= v;
  34. } else {
  35. bits &= ~v;
  36. }
  37. }
  38. MixerStatus operator|(Value v) const { return MixerStatus(bits | v); }
  39. MixerStatus &operator|=(Value v)
  40. {
  41. bits |= v;
  42. return *this;
  43. }
  44. MixerStatus operator&(Value v) const { return MixerStatus(bits & v); }
  45. MixerStatus &operator&=(Value v)
  46. {
  47. bits &= v;
  48. return *this;
  49. }
  50. MixerStatus operator~() const { return MixerStatus(~bits); }
  51. private:
  52. uint32_t bits = None;
  53. explicit MixerStatus(uint32_t v) : bits(v) {}
  54. };
  55. private:
  56. std::unique_ptr<idian::Utils> utils;
  57. OBSWeakSource weakSource_;
  58. const char *uuid;
  59. std::vector<OBSSignal> obsSignals;
  60. QBoxLayout *mainLayout;
  61. QLabel *categoryLabel;
  62. VolumeName *nameButton;
  63. QLabel *volumeLabel;
  64. VolumeMeter *volumeMeter;
  65. VolumeSlider *slider;
  66. QPushButton *muteButton;
  67. QPushButton *monitorButton;
  68. OBSFader obs_fader;
  69. QString sourceName;
  70. bool vertical;
  71. MixerStatus mixerStatus_;
  72. QMenu *contextMenu;
  73. static void obsVolumeChanged(void *param, float db);
  74. static void obsVolumeMuted(void *data, calldata_t *calldata);
  75. static void obsMixersOrMonitoringChanged(void *data, calldata_t *);
  76. static void obsSourceActivated(void *data, calldata_t *params);
  77. static void obsSourceDeactivated(void *data, calldata_t *params);
  78. static void obsSourceDestroy(void *data, calldata_t *params);
  79. void setLayoutVertical(bool vertical);
  80. void showVolumeControlMenu(QPoint pos = QPoint(0, 0));
  81. void updateCategoryLabel();
  82. void updateDecayRate();
  83. void updatePeakMeterType();
  84. void setMuted(bool mute);
  85. void setMonitoring(obs_monitoring_type type);
  86. public slots:
  87. void sourceActiveChanged(bool active);
  88. void setUseDisabledColors(bool greyscale);
  89. void setLocked(bool locked);
  90. void updateMixerState();
  91. private slots:
  92. void renameSource();
  93. void changeVolume();
  94. void handleMuteButton(bool checked);
  95. void handleMonitorButton(bool checked);
  96. void sliderChanged(int vol);
  97. void updateText();
  98. void setName(QString name);
  99. void handleSourceDestroyed() { deleteLater(); }
  100. signals:
  101. void unhideAll();
  102. public:
  103. explicit VolumeControl(obs_source_t *source, QWidget *parent, bool vertical);
  104. explicit VolumeControl(obs_source_t *source, QWidget *parent) : VolumeControl(source, parent, false) {}
  105. ~VolumeControl();
  106. inline OBSWeakSource weakSource() const { return weakSource_; }
  107. QString const &getCachedName() const { return sourceName; }
  108. void setMeterDecayRate(qreal q);
  109. void setPeakMeterType(enum obs_peak_meter_type peakMeterType);
  110. void enableSlider(bool enable);
  111. MixerStatus &mixerStatus() { return mixerStatus_; }
  112. void setGlobalInMixer(bool global);
  113. void setPinnedInMixer(bool pinned);
  114. void setHiddenInMixer(bool hidden);
  115. void setContextMenu(QMenu *cm) { contextMenu = cm; }
  116. bool isVertical() const { return vertical; }
  117. void setVertical(bool vertical);
  118. void updateTabOrder();
  119. QWidget *firstWidget() const { return qobject_cast<QWidget *>(nameButton); }
  120. QWidget *lastWidget() const
  121. {
  122. return vertical ? qobject_cast<QWidget *>(monitorButton) : qobject_cast<QWidget *>(slider);
  123. }
  124. void updateName();
  125. void refreshColors();
  126. void setLevels(const float magnitude[MAX_AUDIO_CHANNELS], const float peak[MAX_AUDIO_CHANNELS],
  127. const float inputPeak[MAX_AUDIO_CHANNELS]);
  128. };