]> git.sesse.net Git - nageru/blob - nageru/vumeter.h
Fix some leftovers in warning messages.
[nageru] / nageru / vumeter.h
1 #ifndef VUMETER_H
2 #define VUMETER_H
3
4 #include <math.h>
5 #include <QPixmap>
6 #include <QString>
7 #include <QWidget>
8 #include <mutex>
9
10 #include "vu_common.h"
11
12 class QObject;
13 class QPaintEvent;
14 class QResizeEvent;
15
16 class VUMeter : public QWidget
17 {
18         Q_OBJECT
19
20 public:
21         VUMeter(QWidget *parent);
22
23         void set_level(float level_lufs) {
24                 set_level(level_lufs, level_lufs);
25         }
26
27         void set_level(float level_lufs_left, float level_lufs_right) {
28                 std::lock_guard<std::mutex> lock(level_mutex);
29                 this->level_lufs[0] = level_lufs_left;
30                 this->level_lufs[1] = level_lufs_right;
31                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
32         }
33
34         void set_peak(float peak_lufs) {
35                 set_peak(peak_lufs, peak_lufs);
36         }
37
38         void set_peak(float peak_lufs_left, float peak_lufs_right) {
39                 std::lock_guard<std::mutex> lock(level_mutex);
40                 this->peak_lufs[0] = peak_lufs_left;
41                 this->peak_lufs[1] = peak_lufs_right;
42                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
43         }
44
45         double lufs_to_pos(float level_lu, int height)
46         {
47                 return ::lufs_to_pos(level_lu, height, min_level, max_level);
48         }
49
50         void set_min_level(float min_level)
51         {
52                 this->min_level = min_level;
53                 recalculate_pixmaps();
54         }
55
56         void set_max_level(float max_level)
57         {
58                 this->max_level = max_level;
59                 recalculate_pixmaps();
60         }
61
62         void set_ref_level(float ref_level_lufs)
63         {
64                 this->ref_level_lufs = ref_level_lufs;
65         }
66
67 private:
68         void resizeEvent(QResizeEvent *event) override;
69         void paintEvent(QPaintEvent *event) override;
70         void recalculate_pixmaps();
71
72         std::mutex level_mutex;
73         float level_lufs[2] { -HUGE_VALF, -HUGE_VALF };
74         float peak_lufs[2] { -HUGE_VALF, -HUGE_VALF };
75         float min_level = -18.0f, max_level = 9.0f, ref_level_lufs = -23.0f;
76
77         QPixmap full_on_pixmap, on_pixmap, off_pixmap;
78 };
79
80 #endif