23 #include <QApplication>    32 #include <KLocalizedString>    56     m_tracks(0), m_sample_rate(0), m_yf(), m_yp(),
    57     m_fast_queue(), m_peak_queue(),
    58     m_current_fast(), m_current_peak(), m_timer(),
    59     m_color_low(Qt::green),
    60     m_color_normal(Qt::yellow),
    63     setAttribute(Qt::WA_NoBackground);
    99     if (qFuzzyCompare(static_cast<float>(rate), 
m_sample_rate)) 
return;
   111     const unsigned int samples = buffer.
size();
   114     unsigned int next_fraction = samples_per_update;
   115     const unsigned int queue_depth = ((samples / samples_per_update) + 2);
   119     float n = 1.0f / tanf(
float(M_PI) * Fg);
   120     const float a0_fr = 1.0f / (1.0f + n);
   121     const float b1_fr = (1.0f - n) / (1.0f + n);
   125     n = 1.0f / tanf(
float(M_PI) * Fg);
   126     const float a0_fd = 1.0f / (1.0f + n);
   127     const float b1_fd = (1.0f - n) / (1.0f + n);
   131     n = 1.0f / tanf(
float(M_PI) * Fg);
   132     const float a0_pr = 1.0f / (1.0f + n);
   133     const float b1_pr = (1.0f - n) / (1.0f + n);
   137     n = 1.0f / tanf(
float(M_PI) * Fg);
   138     const float a0_pd = 1.0f / (1.0f + n);
   139     const float b1_pd = (1.0f - n) / (1.0f + n);
   141     float yf = 
m_yf[track];
   142     float yp = 
m_yp[track];
   144     for (
unsigned int t = 0; t < samples; ++t) {
   148         if (x > yf) yf = (a0_fr * x) + (a0_fr * last_x) - (b1_fr * yf); 
   149         yf = (a0_fd * x) + (a0_fd * last_x) - (b1_fd * yf); 
   152         if (x > yp) yp = (a0_pr * x) + (a0_pr * last_x) - (b1_pr * yp); 
   153         yp = (a0_pd * x) + (a0_pd * last_x) - (b1_pd * yp); 
   159         if ((t > next_fraction) || (t == samples-1)) {
   160             next_fraction += samples_per_update;
   163             if ((next_fraction + samples_per_update) > samples)
   164                next_fraction = samples-1;
   166             enqueue(track, yf, yp, queue_depth);
   193                                 unsigned int queue_depth)
   254     bool need_update = 
false;
   256     for (
int track=0; track < 
m_tracks; track++) {
   257         if (
dequeue(track, fast, peak)) {
   268     if (need_update) repaint();
   275     QFontMetrics fm = p.fontMetrics();
   276     QRect 
rect = fm.boundingRect(i18n(
"%1 dB", -999));
   278     const int border = 4;
   279     const int w  = width() - 2 * border;
   280     const int h  = height();
   281     const int tw = rect.width();
   282     const int th = rect.height();
   283     const int y  = ((height() - th) / 2);
   287     const QColor textcolor = palette().buttonText().color();
   288     const QBrush brush(palette().
background().color());
   294     while (right > tw + border) {
   300             txt = i18n(
"%1 dB", db);
   302                 pow(10.0, static_cast<double>(db) / 20.0));
   304         } 
while ((x > right) && (x >= tw));
   308         int text_width = fm.boundingRect(txt).width();
   315         p.drawRoundRect(x - r, y - r, text_width + 2 * r, th + 2 * r,
   316                         (200 * r) / th, (200 * r) / th);
   321         p.drawText(x, 1, text_width, h, Qt::AlignCenter, txt);
   349     Q_ASSERT(width() > 0);
   350     Q_ASSERT(height() > 0);
   357     const unsigned int border = 4;
   358     const unsigned int cell = 3;
   359     const unsigned int w = width() - (border * 2) - (cell * 2);
   365     for (track = 0; track < 
m_tracks; ++track) {
   368         for (
unsigned int i = 0; i < w; i += cell * 2) {
   379                 border + (track * h),
   381                 (i > fast) ? color.dark() : color
   390         else if (peak >= w_low)
   396             border + cell + peak,
   397             border + (track * h),
 
virtual void enqueue(unsigned int track, float fast, float peak, unsigned int queue_depth)
static const float F_FAST_RISE
virtual void drawContents()
static const float UPDATES_PER_SECOND
QVector< float > m_current_fast
virtual ~LevelMeter() Q_DECL_OVERRIDE
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
static const float F_FAST_DECAY
virtual bool dequeue(unsigned int track, float &fast, float &peak)
virtual void setSampleRate(double rate)
static const float F_PEAK_DECAY
QVector< QQueue< float > > m_peak_queue
QVector< QQueue< float > > m_fast_queue
static const char * background[]
virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE
virtual void setTracks(unsigned int tracks)
LevelMeter(QWidget *parent)
static float sample2float(const sample_t s)
virtual void timedUpdate()
virtual void updateTrack(unsigned int track, const Kwave::SampleArray &buffer)
unsigned int size() const
virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
static const float F_PEAK_RISE
QVector< float > m_current_peak
static double rect(double param)
void drawScale(QPainter &p)