|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:BSD$ |
|
10 ** You may use this file under the terms of the BSD license as follows: |
|
11 ** |
|
12 ** Redistribution and use in source and binary forms, with or without |
|
13 ** modification, are permitted provided that the following conditions are met: |
|
14 ** - Redistributions of source code must retain the above copyright notice, |
|
15 ** this list of conditions and the following disclaimer. |
|
16 ** - Redistributions in binary form must reproduce the above copyright notice, |
|
17 ** this list of conditions and the following disclaimer in the documentation |
|
18 ** and/or other materials provided with the distribution. |
|
19 ** - Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the |
|
20 ** names of its contributors may be used to endorse or promote products |
|
21 ** derived from this software without specific prior written permission. |
|
22 ** |
|
23 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
24 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
25 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
26 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
27 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
28 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
29 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
30 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
31 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
32 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
33 ** POSSIBILITY OF SUCH DAMAGE. |
|
34 ** $QT_END_LICENSE$ |
|
35 ** |
|
36 *****************************************************************************/ |
|
37 |
|
38 #ifndef LEVELMETER_H |
|
39 #define LEVELMETER_H |
|
40 |
|
41 #include <QTime> |
|
42 #include <QWidget> |
|
43 |
|
44 /** |
|
45 * Widget which displays a vertical audio level meter, indicating the |
|
46 * RMS and peak levels of the window of audio samples most recently analysed |
|
47 * by the Engine. |
|
48 */ |
|
49 class LevelMeter : public QWidget { |
|
50 Q_OBJECT |
|
51 public: |
|
52 LevelMeter(QWidget *parent = 0); |
|
53 ~LevelMeter(); |
|
54 |
|
55 void paintEvent(QPaintEvent *event); |
|
56 |
|
57 public slots: |
|
58 void reset(); |
|
59 void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples); |
|
60 |
|
61 private slots: |
|
62 void redrawTimerExpired(); |
|
63 |
|
64 private: |
|
65 /** |
|
66 * Height of RMS level bar. |
|
67 * Range 0.0 - 1.0. |
|
68 */ |
|
69 qreal m_rmsLevel; |
|
70 |
|
71 /** |
|
72 * Most recent peak level. |
|
73 * Range 0.0 - 1.0. |
|
74 */ |
|
75 qreal m_peakLevel; |
|
76 |
|
77 /** |
|
78 * Height of peak level bar. |
|
79 * This is calculated by decaying m_peakLevel depending on the |
|
80 * elapsed time since m_peakLevelChanged, and the value of m_decayRate. |
|
81 */ |
|
82 qreal m_decayedPeakLevel; |
|
83 |
|
84 /** |
|
85 * Time at which m_peakLevel was last changed. |
|
86 */ |
|
87 QTime m_peakLevelChanged; |
|
88 |
|
89 /** |
|
90 * Rate at which peak level bar decays. |
|
91 * Expressed in level units / millisecond. |
|
92 */ |
|
93 qreal m_peakDecayRate; |
|
94 |
|
95 /** |
|
96 * High watermark of peak level. |
|
97 * Range 0.0 - 1.0. |
|
98 */ |
|
99 qreal m_peakHoldLevel; |
|
100 |
|
101 /** |
|
102 * Time at which m_peakHoldLevel was last changed. |
|
103 */ |
|
104 QTime m_peakHoldLevelChanged; |
|
105 |
|
106 QTimer *m_redrawTimer; |
|
107 |
|
108 QColor m_rmsColor; |
|
109 QColor m_peakColor; |
|
110 |
|
111 }; |
|
112 |
|
113 #endif // LEVELMETER_H |