refs #387, preparation for level meter

* not yet connected with audio
This commit is contained in:
Klaus Basan
2015-02-15 17:18:06 +01:00
parent 7201d09c9a
commit 496d63cf11
3 changed files with 212 additions and 11 deletions

85
src/blackgui/levelmeter.h Normal file
View File

@@ -0,0 +1,85 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*
* Class based on qt example: Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
*/
//! \file
#ifndef BLACKGUI_LEVELMETER_H
#define BLACKGUI_LEVELMETER_H
#include <QTime>
#include <QWidget>
namespace BlackGui
{
/**
* Widget which displays a vertical audio level meter, indicating the
* RMS and peak levels of the window of audio samples most recently analyzed
* by the Engine.
*/
class CLevelMeter : public QWidget
{
Q_OBJECT
public:
//! Constructor
CLevelMeter(QWidget *parent = 0);
//! Destructor
~CLevelMeter();
//! \copydoc QWidget::paintEvent
void paintEvent(QPaintEvent *event) override;
public slots:
//! Clean up
void reset();
//! Values
void levelChanged(double rmsLevel, double peakLevel, int numSamples);
private slots:
void ps_redrawTimerExpired();
private:
const int RedrawInterval = 100; // ms
const double PeakDecayRate = 0.001;
const int PeakHoldLevelDuration = 2000; // ms
//! Height of RMS level bar, range 0.0 - 1.0.
double m_rmsLevel = 0.0;
//! Most recent peak level, range 0.0 - 1.0.
double m_peakLevel = 0.0;
//! Height of peak level bar.
//! This is calculated by decaying m_peakLevel depending on the elapsed time since m_peakLevelChanged, and the value of m_decayRate.
double m_decayedPeakLevel = 0.0;
//! Time at which m_peakLevel was last changed.
QTime m_peakLevelChanged;
//! Rate at which peak level bar decays. Expressed in level units / millisecond.
double m_peakDecayRate;
//! High watermark of peak level. Range 0.0 - 1.0.
double m_peakHoldLevel = 0.0;
//! Time at which m_peakHoldLevel was last changed.
QTime m_peakHoldLevelChanged;
QTimer *m_redrawTimer;
QColor m_rmsColor;
QColor m_peakColor;
};
}
#endif // guard