summaryrefslogtreecommitdiff
path: root/dgedit
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
parent64d8efa4f3abe4257120b85fb4d4a063d96edbfc (diff)
Volume fader improvement.
Diffstat (limited to 'dgedit')
-rw-r--r--dgedit/mainwindow.cc1
-rw-r--r--dgedit/volumefader.cc30
-rw-r--r--dgedit/volumefader.h4
3 files changed, 26 insertions, 9 deletions
diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc
index d815d5c..5bf623e 100644
--- a/dgedit/mainwindow.cc
+++ b/dgedit/mainwindow.cc
@@ -189,6 +189,7 @@ MainWindow::MainWindow()
&player, SLOT(setGainDB(double)));
connect(&player, SIGNAL(peakUpdate(double)),
vol, SLOT(updatePeakPower(double)));
+ vol->setVolumeDb(0);
dockWidget->widget()->layout()->addWidget(vol);
addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
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");
}
diff --git a/dgedit/volumefader.h b/dgedit/volumefader.h
index 33dfc2b..7209956 100644
--- a/dgedit/volumefader.h
+++ b/dgedit/volumefader.h
@@ -29,6 +29,7 @@
#include <QWidget>
#include <QSlider>
+#include <QLabel>
#include <stdio.h>
@@ -56,6 +57,9 @@ signals:
private:
QSlider *volslider;
+ QLabel *volumepeak;
+ QLabel *volume;
+ double peak;
};
#endif/*__DRUMGIZMO_VOLUMEFADER_H__*/