volume-control.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <obs.hpp>
  3. #include <QWidget>
  4. class QPushButton;
  5. class VolumeMeter : public QWidget
  6. {
  7. Q_OBJECT
  8. Q_PROPERTY(QColor bkColor READ getBkColor WRITE setBkColor DESIGNABLE true)
  9. Q_PROPERTY(QColor magColor READ getMagColor WRITE setMagColor DESIGNABLE true)
  10. Q_PROPERTY(QColor peakColor READ getPeakColor WRITE setPeakColor DESIGNABLE true)
  11. Q_PROPERTY(QColor peakHoldColor READ getPeakHoldColor WRITE setPeakHoldColor DESIGNABLE true)
  12. private:
  13. float mag, peak, peakHold;
  14. QColor bkColor, magColor, peakColor, peakHoldColor;
  15. QTimer *resetTimer;
  16. public:
  17. explicit VolumeMeter(QWidget *parent = 0);
  18. void setLevels(float nmag, float npeak, float npeakHold);
  19. QColor getBkColor() const;
  20. void setBkColor(QColor c);
  21. QColor getMagColor() const;
  22. void setMagColor(QColor c);
  23. QColor getPeakColor() const;
  24. void setPeakColor(QColor c);
  25. QColor getPeakHoldColor() const;
  26. void setPeakHoldColor(QColor c);
  27. protected:
  28. void paintEvent(QPaintEvent *event);
  29. private slots:
  30. void resetState();
  31. };
  32. class QLabel;
  33. class QSlider;
  34. class MuteCheckBox;
  35. class VolControl : public QWidget {
  36. Q_OBJECT
  37. private:
  38. OBSSource source;
  39. QLabel *nameLabel;
  40. QLabel *volLabel;
  41. VolumeMeter *volMeter;
  42. QSlider *slider;
  43. MuteCheckBox *mute;
  44. QPushButton *config = nullptr;
  45. float levelTotal;
  46. float levelCount;
  47. obs_fader_t *obs_fader;
  48. obs_volmeter_t *obs_volmeter;
  49. static void OBSVolumeChanged(void *param, float db);
  50. static void OBSVolumeLevel(void *data, float level, float mag,
  51. float peak, float muted);
  52. static void OBSVolumeMuted(void *data, calldata_t *calldata);
  53. void EmitConfigClicked();
  54. private slots:
  55. void VolumeChanged();
  56. void VolumeMuted(bool muted);
  57. void VolumeLevel(float mag, float peak, float peakHold, bool muted);
  58. void SetMuted(bool checked);
  59. void SliderChanged(int vol);
  60. void updateText();
  61. signals:
  62. void ConfigClicked();
  63. public:
  64. VolControl(OBSSource source, bool showConfig = false);
  65. ~VolControl();
  66. inline obs_source_t *GetSource() const {return source;}
  67. QString GetName() const;
  68. void SetName(const QString &newName);
  69. };