From e5894869070ac3af9c24641238db1bd752b4d5bf Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 27 Jun 2023 04:56:07 +0300 Subject: [PATCH] Song: add pretty-printers for EBU R 128 Integrated Loudness and Loudness Range fields They end up being used in a quite a number of places later on, it makes sense to have them in a common place. Integrated Loudness (LUFS) is *usually* negative, so we really want to always print a sign. But Loudness Range is non-negative. I think it makes sense to print one or at most two decimal places for these. --- src/core/song.cpp | 20 ++++++++++++++++++++ src/core/song.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/src/core/song.cpp b/src/core/song.cpp index caa58bade..3856c3974 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -685,6 +685,26 @@ QString Song::SampleRateBitDepthToText() const { } +QString Song::Ebur128LoudnessLUFSToText(const std::optional &v) { + + if (!v) return QObject::tr("Unknown"); + + return QString::asprintf("%+.2f ", *v) + QObject::tr("LUFS"); +} +QString Song::Ebur128LoudnessLUFSToText() const { + return Ebur128LoudnessLUFSToText(d->ebur128_integrated_loudness_lufs_); +} + +QString Song::Ebur128LoudnessRangeLUToText(const std::optional &v) { + + if (!v) return QObject::tr("Unknown"); + + return QString::asprintf("%.2f ", *v) + QObject::tr("LU"); +} +QString Song::Ebur128LoudnessRangeLUToText() const { + return Ebur128LoudnessRangeLUToText(d->ebur128_loudness_range_lu_); +} + QString Song::PrettyRating() const { float rating = d->rating_; diff --git a/src/core/song.h b/src/core/song.h index 4c585a715..3a7d34b75 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -225,6 +225,12 @@ class Song { const QUrl &stream_url() const; + static QString Ebur128LoudnessLUFSToText(const std::optional &v); + QString Ebur128LoudnessLUFSToText() const; + + static QString Ebur128LoudnessRangeLUToText(const std::optional &v); + QString Ebur128LoudnessRangeLUToText() const; + // Setters void set_id(const int id); void set_valid(const bool v);