From dec11ce2e6771d77a659b00d69126ab12bc205c7 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Sun, 27 Apr 2014 14:56:04 +0200 Subject: Volume fader improvement. --- dgedit/mainwindow.cc | 1 + dgedit/volumefader.cc | 30 +++++++++++++++++++++--------- dgedit/volumefader.h | 4 ++++ 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 #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 #include +#include #include @@ -56,6 +57,9 @@ signals: private: QSlider *volslider; + QLabel *volumepeak; + QLabel *volume; + double peak; }; #endif/*__DRUMGIZMO_VOLUMEFADER_H__*/ -- cgit v1.2.3