summaryrefslogtreecommitdiff
path: root/dgedit/volumefader.cc
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2014-04-27 14:56:04 +0200
committerJonas Suhr Christensen <jsc@umbraculum.org>2014-04-27 14:56:04 +0200
commitdec11ce2e6771d77a659b00d69126ab12bc205c7 (patch)
tree04a9fd7393ae1d8f7227271b676e3940e056d94a /dgedit/volumefader.cc
parent64d8efa4f3abe4257120b85fb4d4a063d96edbfc (diff)
Volume fader improvement.
Diffstat (limited to 'dgedit/volumefader.cc')
-rw-r--r--dgedit/volumefader.cc30
1 files changed, 21 insertions, 9 deletions
diff --git a/dgedit/volumefader.cc b/dgedit/volumefader.cc
index 83a0bbf..33b1f57 100644
--- a/dgedit/volumefader.cc
+++ b/dgedit/volumefader.cc
@@ -32,21 +32,28 @@
#include <math.h>
#define SCALAR 10
+#define P 0.5
VolumeFader::VolumeFader()
{
+ peak = 0;
volslider = new QSlider();
volslider->setRange(-60 * SCALAR , 10 * SCALAR);
-
+ volslider->setOrientation(Qt::Horizontal);
+
+ volumepeak = new QLabel();
+
+ volume = new QLabel();
+
connect(volslider, SIGNAL(valueChanged(int)), this, SLOT(handleValueChanged()));
QVBoxLayout* lo = new QVBoxLayout();
lo->addWidget(volslider);
- setLayout(lo);
+ lo->addWidget(volumepeak);
+ lo->addWidget(volume);
- setVolumeDb(10);
- setVolumePower(10);
+ setLayout(lo);
}
VolumeFader::~VolumeFader()
@@ -58,27 +65,32 @@ void VolumeFader::updatePeakDb(double)
{
}
-void VolumeFader::updatePeakPower(double)
+void VolumeFader::updatePeakPower(double newpeak)
{
-
+ peak = (newpeak * (1-P) + peak * P);
+ volumepeak->setText("Peak " + QString::number(peak, 'f', 5));
+ handleValueChanged();
}
void VolumeFader::setVolumeDb(double db)
{
volslider->setValue(db*SCALAR);
+ handleValueChanged();
}
void VolumeFader::setVolumePower(double power)
{
- double db = 10 * log10(power);
+ double db = 20 * log10(power);
setVolumeDb(db);
+ handleValueChanged();
}
void VolumeFader::handleValueChanged()
{
double db = ((double)volslider->value())/((double)SCALAR);
- double power = pow(10, db/10);
-// printf("Volume %f db, %f power\n", db, pow(10, db/10));
+ double power = pow(10, db/20);
emit volumeChangedDb(db);
emit volumeChangedPower(power);
+
+ volume->setText("Gain " + QString::number(volslider->value()/SCALAR) + " dB");
}