3
Copyright (C) 2000 Hans Meine
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.
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.
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.
22
#ifndef ARTS_TOOLS_LEVELMETERS_H
23
#define ARTS_TOOLS_LEVELMETERS_H
27
#include <qdatetime.h>
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);
38
inline float DBToLevel(float db) {
39
return exp(db/(log(2.f)/6.f));
43
* Base class for a single volume / value bar.
45
class LevelMeter : public QFrame {
48
LevelMeter(QWidget *parent): QFrame(parent) {}
50
virtual void setValue(float f) = 0;
54
* Base class for a pair of volume / value bars.
56
class StereoLevelMeter : public QFrame {
59
StereoLevelMeter(QWidget *parent): QFrame(parent) {}
61
virtual void setValues(float left, float right) = 0;
65
* Special LevelMeter which remembers min and max of the last [peakMillis]
66
* milliseconds and displays a full bar with optional max/min markers.
68
class PeakBar : public LevelMeter {
73
static const int peakMillis=1500; // how long do the peaks stay at their max?
79
Observation(float aValue): value(aValue) { time.start(); }
81
QList<Observation> lastValues;
83
float currentValue, maxValue, minValue;
92
PeakBar(QWidget *parent);
94
QSize sizeHint() const;
96
void drawContents(QPainter *p);
97
virtual void setValue(float f);
101
* Special class which draws the Db scale with ticks, numbers and so on.
103
class ScaleView : public QFrame {
108
int upperMargin, lowerMargin;
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);
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.
122
class PeakLevelMeters : public StereoLevelMeter {
130
PeakLevelMeters(QWidget *parent);
133
void setValues(float leftVal, float rightVal);
134
void setDbRange(int db);
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.)
144
class LedMeter : public LevelMeter {
150
LedMeter(QWidget *parent, bool blueState = false);
151
void setValue(float f);
155
* A simple pair of LedMeters.
157
class StereoLedMeters : public StereoLevelMeter {
160
LedMeter left, right;
163
StereoLedMeters(QWidget *parent);
165
void setValues(float left, float right);
168
#endif /* ARTS_TOOLS_LEVELMETERS_H */