volume-control.hpp 1.9 KB

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