From a67460db8ba2c3c50e75866fa85091fbebdc7386 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 28 Aug 2016 21:18:41 +0200 Subject: [PATCH] More tweaks to the dB formatting. --- mainwindow.cpp | 68 ++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7d2a2d5..9ed7d3e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -49,32 +49,40 @@ void quit_signal(int ignored) global_mainwindow->close(); } -string format_db_with_sign(double db) -{ - if (isfinite(db)) { - char buf[256]; - snprintf(buf, sizeof(buf), "%+.1f dB", db); - return buf; - } else if (db < 0.0) { - return "-∞ dB"; - } else { - // Should never happen, really. - return "+∞ dB"; - } -} +constexpr unsigned DB_NO_FLAGS = 0x0; +constexpr unsigned DB_WITH_SIGN = 0x1; +constexpr unsigned DB_BARE = 0x2; -string format_db(double db) +string format_db(double db, unsigned flags) { - if (isfinite(db)) { - char buf[256]; - snprintf(buf, sizeof(buf), "%.1f dB", db); - return buf; - } else if (db < 0.0) { - return "-∞ dB"; + string text; + if (flags & DB_WITH_SIGN) { + if (isfinite(db)) { + char buf[256]; + snprintf(buf, sizeof(buf), "%+.1f", db); + text = buf; + } else if (db < 0.0) { + text = "-∞"; + } else { + // Should never happen, really. + text = "+∞"; + } } else { - // Should never happen, really. - return "+∞ dB"; + if (isfinite(db)) { + char buf[256]; + snprintf(buf, sizeof(buf), "%.1f", db); + text = buf; + } else if (db < 0.0) { + text = "-∞"; + } else { + // Should never happen, really. + text = "∞"; + } + } + if (!(flags & DB_BARE)) { + text += " dB"; } + return text; } } // namespace @@ -166,9 +174,9 @@ void MainWindow::mixer_created(Mixer *mixer) ui->makeup_gain_auto_checkbox->setChecked(global_mixer->get_final_makeup_gain_auto()); ui->limiter_threshold_db_display->setText( - QString::fromStdString(format_db(mixer->get_limiter_threshold_dbfs()))); + QString::fromStdString(format_db(mixer->get_limiter_threshold_dbfs(), DB_WITH_SIGN))); ui->compressor_threshold_db_display->setText( - QString::fromStdString(format_db(mixer->get_compressor_threshold_dbfs()))); + QString::fromStdString(format_db(mixer->get_compressor_threshold_dbfs(), DB_WITH_SIGN))); connect(ui->locut_cutoff_knob, &QDial::valueChanged, this, &MainWindow::cutoff_knob_changed); cutoff_knob_changed(ui->locut_cutoff_knob->value()); @@ -280,7 +288,7 @@ void MainWindow::limiter_threshold_knob_changed(int value) float threshold_dbfs = value * 0.1f; global_mixer->set_limiter_threshold_dbfs(threshold_dbfs); ui->limiter_threshold_db_display->setText( - QString::fromStdString(format_db(threshold_dbfs))); + QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN))); } void MainWindow::compressor_threshold_knob_changed(int value) @@ -288,13 +296,13 @@ void MainWindow::compressor_threshold_knob_changed(int value) float threshold_dbfs = value * 0.1f; global_mixer->set_compressor_threshold_dbfs(threshold_dbfs); ui->compressor_threshold_db_display->setText( - QString::fromStdString(format_db(threshold_dbfs))); + QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN))); } void MainWindow::reset_meters_button_clicked() { global_mixer->reset_meters(); - ui->peak_display->setText("-inf"); + ui->peak_display->setText(QString::fromStdString(format_db(-HUGE_VAL, DB_WITH_SIGN | DB_BARE))); ui->peak_display->setStyleSheet(""); } @@ -320,7 +328,7 @@ void MainWindow::audio_level_callback(float level_lufs, float peak_db, float glo ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs); ui->correlation_meter->set_correlation(correlation); - ui->peak_display->setText(QString::fromStdString(format_db(peak_db))); + ui->peak_display->setText(QString::fromStdString(format_db(peak_db, DB_BARE))); if (peak_db > -0.1f) { // -0.1 dBFS is EBU peak limit. ui->peak_display->setStyleSheet("QLabel { background-color: red; color: white; }"); } else { @@ -331,13 +339,13 @@ void MainWindow::audio_level_callback(float level_lufs, float peak_db, float glo ui->gainstaging_knob->setValue(lrintf(gain_staging_db * 10.0f)); ui->gainstaging_knob->blockSignals(false); ui->gainstaging_db_display->setText( - QString::fromStdString(format_db_with_sign(gain_staging_db))); + QString::fromStdString(format_db(gain_staging_db, DB_WITH_SIGN))); ui->makeup_gain_knob->blockSignals(true); ui->makeup_gain_knob->setValue(lrintf(final_makeup_gain_db * 10.0f)); ui->makeup_gain_knob->blockSignals(false); ui->makeup_gain_db_display->setText( - QString::fromStdString(format_db_with_sign(final_makeup_gain_db))); + QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN))); }); } -- 2.39.2