~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to arts/tools/levelmeters.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    /*
 
2
 
 
3
    Copyright (C) 2000 Hans Meine
 
4
                           <hans_meine@gmx.net>
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
    */
 
21
 
 
22
#ifndef ARTS_TOOLS_LEVELMETERS_H
 
23
#define ARTS_TOOLS_LEVELMETERS_H
 
24
 
 
25
#include <qobject.h>
 
26
#include <qframe.h>
 
27
#include <qdatetime.h>
 
28
#include <qlist.h>
 
29
#include <math.h>
 
30
 
 
31
// helper functions
 
32
const float LEVEL_MIN= 1.f/(1<<20); // minimal positive sample for 20 bit resolution
 
33
inline float levelToDB(float level) {
 
34
        if (level<LEVEL_MIN) level=LEVEL_MIN; // prevent from div by 0
 
35
        return (6.f/log(2.f))*log(level);
 
36
}
 
37
 
 
38
inline float DBToLevel(float db) {
 
39
        return exp(db/(log(2.f)/6.f));
 
40
}
 
41
 
 
42
/**
 
43
 * Base class for a single volume / value bar.
 
44
 */
 
45
class LevelMeter : public QFrame {
 
46
        Q_OBJECT
 
47
public:
 
48
        LevelMeter(QWidget *parent): QFrame(parent) {}
 
49
public slots:
 
50
        virtual void setValue(float f) = 0;
 
51
};
 
52
 
 
53
/**
 
54
 * Base class for a pair of volume / value bars.
 
55
 */
 
56
class StereoLevelMeter : public QFrame {
 
57
        Q_OBJECT
 
58
public:
 
59
        StereoLevelMeter(QWidget *parent): QFrame(parent) {}
 
60
public slots:
 
61
        virtual void setValues(float left, float right) = 0;
 
62
};
 
63
 
 
64
/**
 
65
 * Special LevelMeter which remembers min and max of the last [peakMillis]
 
66
 * milliseconds and displays a full bar with optional max/min markers.
 
67
 */
 
68
class PeakBar : public LevelMeter {
 
69
        Q_OBJECT
 
70
                bool clipped;
 
71
 
 
72
protected:
 
73
        static const int peakMillis=1500; // how long do the peaks stay at their max?
 
74
        
 
75
        class Observation {
 
76
        public:
 
77
                QTime time;
 
78
                float value;
 
79
                Observation(float aValue): value(aValue) { time.start(); }
 
80
        };
 
81
        QList<Observation> lastValues;
 
82
        
 
83
        float currentValue, maxValue, minValue;
 
84
        void checkMinMax();
 
85
 
 
86
        bool displayMinPeak;
 
87
        bool horizontalMode;
 
88
 
 
89
        void frameChanged();
 
90
        
 
91
public:
 
92
        PeakBar(QWidget *parent);
 
93
        
 
94
        QSize sizeHint() const;
 
95
 
 
96
        void drawContents(QPainter *p);
 
97
        virtual void setValue(float f);
 
98
};
 
99
 
 
100
/**
 
101
 * Special class which draws the Db scale with ticks, numbers and so on.
 
102
 */
 
103
class ScaleView : public QFrame {
 
104
        Q_OBJECT
 
105
protected:
 
106
        QFont font;
 
107
        int dbRange;
 
108
        int upperMargin, lowerMargin;
 
109
public:
 
110
        ScaleView(QWidget *parent);
 
111
        void setDbRange(int db);
 
112
        void setScaleMargins(int margins) { upperMargin= margins; lowerMargin=margins; }
 
113
        QSize sizeHint() const;
 
114
        void drawContents(QPainter *p);
 
115
};
 
116
 
 
117
/**
 
118
 * Reusable class which displays two volume bars (left/right) with a Db scale
 
119
 * and clip indicators. Supports / will have a context menu with some display
 
120
 * options like Db range, whether minimal values are also shown and others.
 
121
 */
 
122
class PeakLevelMeters : public StereoLevelMeter {
 
123
        Q_OBJECT
 
124
protected:
 
125
        int dbRange;
 
126
        PeakBar left, right;
 
127
        ScaleView scaleView;
 
128
 
 
129
public:
 
130
        PeakLevelMeters(QWidget *parent);
 
131
 
 
132
public slots:
 
133
        void setValues(float leftVal, float rightVal);
 
134
        void setDbRange(int db);
 
135
};
 
136
 
 
137
class KLed;
 
138
 
 
139
/**
 
140
 * Simple LevelMeter implementation with 12 KLeds.
 
141
 * Shows them in green/yellow/red combi if not blueState set, in which
 
142
 * case it's all blue. (Original artscontrol widget by stw.)
 
143
 */
 
144
class LedMeter : public LevelMeter {
 
145
        Q_OBJECT
 
146
protected:
 
147
        KLed *leds[12];
 
148
 
 
149
public:
 
150
        LedMeter(QWidget *parent, bool blueState = false);
 
151
        void setValue(float f);
 
152
};
 
153
 
 
154
/**
 
155
 * A simple pair of LedMeters.
 
156
 */
 
157
class StereoLedMeters : public StereoLevelMeter {
 
158
        Q_OBJECT
 
159
protected:
 
160
        LedMeter left, right;
 
161
        
 
162
public:
 
163
        StereoLedMeters(QWidget *parent);
 
164
public slots:
 
165
        void setValues(float left, float right);
 
166
};
 
167
 
 
168
#endif /* ARTS_TOOLS_LEVELMETERS_H */