@@ -143,7 +143,6 @@ public: | |||
displayMeter(2, 0.0); | |||
int refresh = float(jack_get_buffer_size(jClient)) / jack_get_sample_rate(jClient) * 1000; | |||
setRefreshRate(refresh > 25 ? refresh : 25); | |||
m_peakTimerId = startTimer(refresh > 50 ? refresh : 50); | |||
} | |||
@@ -33,15 +33,10 @@ DigitalPeakMeter::DigitalPeakMeter(QWidget* parent) | |||
fColorBase(93, 231, 61), | |||
fColorBaseAlt(15, 110, 15, 100), | |||
fChannelsData(nullptr), | |||
fLastValueData(nullptr), | |||
fPaintTimer(this) | |||
fLastValueData(nullptr) | |||
{ | |||
setChannels(0); | |||
setColor(GREEN); | |||
fPaintTimer.setInterval(60); | |||
connect(&fPaintTimer, SIGNAL(timeout()), this, SLOT(update())); | |||
fPaintTimer.start(); | |||
} | |||
DigitalPeakMeter::~DigitalPeakMeter() | |||
@@ -60,12 +55,23 @@ void DigitalPeakMeter::displayMeter(int meter, float level) | |||
if (meter <= 0 || meter > fChannels || fChannelsData == nullptr) | |||
return qCritical("DigitalPeakMeter::displayMeter(%i, %f) - invalid meter number", meter, level); | |||
if (level < 0.0f) | |||
level = -level; | |||
else if (level > 1.0f) | |||
int i = meter - 1; | |||
if (fSmoothMultiplier > 0) | |||
level = (fLastValueData[i] * fSmoothMultiplier + level) / float(fSmoothMultiplier + 1); | |||
if (level < 0.001f) | |||
level = 0.0f; | |||
else if (level > 0.999f) | |||
level = 1.0f; | |||
fChannelsData[meter-1] = level; | |||
if (fChannelsData[i] != level) | |||
{ | |||
fChannelsData[i] = level; | |||
update(); | |||
} | |||
fLastValueData[i] = level; | |||
} | |||
void DigitalPeakMeter::setChannels(int channels) | |||
@@ -87,7 +93,7 @@ void DigitalPeakMeter::setChannels(int channels) | |||
fChannelsData = new float[channels]; | |||
fLastValueData = new float[channels]; | |||
for (int i=0; i < channels; i++) | |||
for (int i=0; i < channels; ++i) | |||
{ | |||
fChannelsData[i] = 0.0f; | |||
fLastValueData[i] = 0.0f; | |||
@@ -146,15 +152,6 @@ void DigitalPeakMeter::setOrientation(Orientation orientation) | |||
updateSizes(); | |||
} | |||
void DigitalPeakMeter::setRefreshRate(int rate) | |||
{ | |||
Q_ASSERT(rate > 0); | |||
fPaintTimer.stop(); | |||
fPaintTimer.setInterval(rate); | |||
fPaintTimer.start(); | |||
} | |||
void DigitalPeakMeter::setSmoothRelease(int value) | |||
{ | |||
Q_ASSERT(value >= 0 && value <= 5); | |||
@@ -169,7 +166,7 @@ void DigitalPeakMeter::setSmoothRelease(int value) | |||
QSize DigitalPeakMeter::minimumSizeHint() const | |||
{ | |||
return QSize(30, 30); | |||
return QSize(10, 10); | |||
} | |||
QSize DigitalPeakMeter::sizeHint() const | |||
@@ -212,13 +209,10 @@ void DigitalPeakMeter::paintEvent(QPaintEvent* event) | |||
painter.setPen(fColorBackground); | |||
painter.setBrush(fGradientMeter); | |||
for (int i=0; i < fChannels; i++) | |||
for (int i=0; i < fChannels; ++i) | |||
{ | |||
float value, level = fChannelsData[i]; | |||
if (level == fLastValueData[i]) | |||
continue; | |||
if (fOrientation == HORIZONTAL) | |||
value = level * float(fWidth); | |||
else if (fOrientation == VERTICAL) | |||
@@ -226,18 +220,12 @@ void DigitalPeakMeter::paintEvent(QPaintEvent* event) | |||
else | |||
value = 0.0f; | |||
if (value < 0.0f) | |||
value = 0.0f; | |||
else if (fSmoothMultiplier > 0) | |||
value = (fLastValueData[i] * float(fSmoothMultiplier) + value) / float(fSmoothMultiplier + 1); | |||
if (fOrientation == HORIZONTAL) | |||
painter.drawRect(0, meterX, int(value), fSizeMeter); | |||
else if (fOrientation == VERTICAL) | |||
painter.drawRect(meterX, int(value), fSizeMeter, fHeight); | |||
meterX += fSizeMeter; | |||
fLastValueData[i] = value; | |||
} | |||
painter.setBrush(Qt::black); | |||
@@ -12,7 +12,7 @@ | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the GPL.txt file | |||
* For a full copy of the GNU General Public License see the COPYING file | |||
*/ | |||
#ifndef __DIGITALPEAKMETER_HPP__ | |||
@@ -41,7 +41,6 @@ public: | |||
void setChannels(int channels); | |||
void setColor(Color color); | |||
void setOrientation(Orientation orientation); | |||
void setRefreshRate(int rate); | |||
void setSmoothRelease(int value); | |||
QSize minimumSizeHint() const; | |||
@@ -67,8 +66,6 @@ private: | |||
float* fChannelsData; | |||
float* fLastValueData; | |||
QTimer fPaintTimer; | |||
}; | |||
#endif // __DIGITALPEAKMETER_HPP__ |
@@ -2,14 +2,14 @@ | |||
* Pixmap Dial, a custom Qt4 widget | |||
* Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* any later version. | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
* published by the Free Software Foundation; either version 2 of | |||
* the License, or any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the COPYING file | |||
@@ -2,14 +2,14 @@ | |||
* Pixmap Dial, a custom Qt4 widget | |||
* Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* any later version. | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
* published by the Free Software Foundation; either version 2 of | |||
* the License, or any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* For a full copy of the GNU General Public License see the COPYING file | |||