]> git.sesse.net Git - nageru/blob - nageru/lrameter.h
Add support for V4L2 output.
[nageru] / nageru / lrameter.h
1 #ifndef LRAMETER_H
2 #define LRAMETER_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 LRAMeter : public QWidget
17 {
18         Q_OBJECT
19
20 public:
21         LRAMeter(QWidget *parent);
22
23         void set_levels(float level_lufs, float range_low_lufs, float range_high_lufs) {
24                 std::lock_guard<std::mutex> lock(level_mutex);
25                 this->level_lufs = level_lufs;
26                 this->range_low_lufs = range_low_lufs;
27                 this->range_high_lufs = range_high_lufs;
28                 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
29         }
30
31         double lufs_to_pos(float level_lu, int height)
32         {
33                 return ::lufs_to_pos(level_lu, height, min_level, max_level);
34         }
35
36         void set_min_level(float min_level)
37         {
38                 this->min_level = min_level;
39                 recalculate_pixmaps();
40         }
41
42         void set_max_level(float max_level)
43         {
44                 this->max_level = max_level;
45                 recalculate_pixmaps();
46         }
47
48         void set_ref_level(float ref_level_lufs)
49         {
50                 this->ref_level_lufs = ref_level_lufs;
51         }
52
53 private:
54         void resizeEvent(QResizeEvent *event) override;
55         void paintEvent(QPaintEvent *event) override;
56         void recalculate_pixmaps();
57
58         std::mutex level_mutex;
59         float level_lufs = -HUGE_VAL;
60         float range_low_lufs = -HUGE_VAL;
61         float range_high_lufs = -HUGE_VAL;
62         float min_level = -18.0f, max_level = 9.0f, ref_level_lufs = -23.0f;
63
64         QPixmap on_pixmap, off_pixmap;
65 };
66
67 #endif