From f2ed595cda0766818e397dd433a9743a4eeeab38 Mon Sep 17 00:00:00 2001 From: Shoh Sewell Date: Wed, 3 May 2023 16:41:07 -0700 Subject: [PATCH 1/3] Adds decimal digits to volume slider tooltip Modifies the volume slider tooltip so that: -If the volume slider falls below 10%, the volume tooltip will display one decimal digit of precision (e.g. 3.4%). -Else if the volume slider falls below 1%, display one decimal digit of precision (e.g. 0.34%). -Otherwise display the volume slider tooltip as normal. This helps show changes in volume between 0% and 10% where a change in volume isn't shown in the UI but is heard (especially when the "Limit volume control to 100%" option is unchecked in the "Output" Preferences submenu. --- Window/VolumeSlider.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Window/VolumeSlider.m b/Window/VolumeSlider.m index a2a489afd..37fec33a9 100644 --- a/Window/VolumeSlider.m +++ b/Window/VolumeSlider.m @@ -64,7 +64,15 @@ static void *kVolumeSliderContext = &kVolumeSliderContext; double volume; volume = linearToLogarithmic(value, MAX_VOLUME); - NSString *text = [NSString stringWithFormat:@"%0.lf%%", volume]; + // If volume becomes less than 1%, display two decimal digits of precision (e.g. 0.34%). + if(volume < 1) + NSString *text = [NSString stringWithFormat:@"%0.2lf%%", volume]; + // Else if volume becomes less than 10%, display one decimal digit of precision (e.g. 3.4%). + else if(volume < 10) + NSString *text = [NSString stringWithFormat:@"%0.1lf%%", volume]; + // Else display no decimal digits. + else + NSString *text = [NSString stringWithFormat:@"%0.lf%%", volume]; [textView setString:text]; } -- 2.45.2 From 8a06f2ad1c302bba04d9e5560363bd2a7096bbb1 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Wed, 3 May 2023 17:21:08 -0700 Subject: [PATCH 2/3] Update VolumeSlider.m Fix variable declaration --- Window/VolumeSlider.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Window/VolumeSlider.m b/Window/VolumeSlider.m index 37fec33a9..14223f32a 100644 --- a/Window/VolumeSlider.m +++ b/Window/VolumeSlider.m @@ -63,16 +63,17 @@ static void *kVolumeSliderContext = &kVolumeSliderContext; double value = [self doubleValue]; double volume; volume = linearToLogarithmic(value, MAX_VOLUME); + NSString *text; // If volume becomes less than 1%, display two decimal digits of precision (e.g. 0.34%). if(volume < 1) - NSString *text = [NSString stringWithFormat:@"%0.2lf%%", volume]; + text = [NSString stringWithFormat:@"%0.2lf%%", volume]; // Else if volume becomes less than 10%, display one decimal digit of precision (e.g. 3.4%). else if(volume < 10) - NSString *text = [NSString stringWithFormat:@"%0.1lf%%", volume]; + text = [NSString stringWithFormat:@"%0.1lf%%", volume]; // Else display no decimal digits. else - NSString *text = [NSString stringWithFormat:@"%0.lf%%", volume]; + text = [NSString stringWithFormat:@"%0.lf%%", volume]; [textView setString:text]; } -- 2.45.2 From 3e41edc7d636158025755100d45a2b6e8e92c4e5 Mon Sep 17 00:00:00 2001 From: Shoh Sewell Date: Thu, 4 May 2023 18:46:13 -0700 Subject: [PATCH 3/3] Makes volume logarithmic when limited to 100% Modifies Helper.m, Helper.h, and VolumeSlider.m so when volume is limited to 100%, the volume slider is logarithmic with an X^2 approximation. Also makes sure the value shown on the volume tooltip is not logarithmic when limited to 100%. Makes some variables in VolumeSlider.m and parameters in Helper.h/Helper.m const as well. --- Audio/Helper.h | 4 ++-- Audio/Helper.m | 10 +++++----- Window/VolumeSlider.m | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Audio/Helper.h b/Audio/Helper.h index c28b7170f..3b78cdff3 100644 --- a/Audio/Helper.h +++ b/Audio/Helper.h @@ -7,5 +7,5 @@ * */ -double logarithmicToLinear(double logarithmic, double MAX_VOLUME); -double linearToLogarithmic(double linear, double MAX_VOLUME); +double logarithmicToLinear(const double logarithmic, double MAX_VOLUME); +double linearToLogarithmic(const double linear, double MAX_VOLUME); diff --git a/Audio/Helper.m b/Audio/Helper.m index 3618730d9..6e1e54822 100644 --- a/Audio/Helper.m +++ b/Audio/Helper.m @@ -13,13 +13,13 @@ // These functions are helpers for the process of converting volume from a linear to logarithmic scale. // Numbers that goes in to audioPlayer should be logarithmic. Numbers that are displayed to the user should be linear. // Here's why: http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html -// We are using the approximation of X^4. +// We are using the approximation of X^2 when volume is limited to 100% and X^4 when volume is limited to 800%. // Input/Output values are in percents. -double logarithmicToLinear(double logarithmic, double MAX_VOLUME) { - return (MAX_VOLUME == 100.0) ? logarithmic : pow((logarithmic / MAX_VOLUME), 0.25) * 100.0; +double logarithmicToLinear(const double logarithmic, double MAX_VOLUME) { + return (MAX_VOLUME == 100.0) ? pow((logarithmic / MAX_VOLUME), 0.5) * 100.0 : pow((logarithmic / MAX_VOLUME), 0.25) * 100.0; } -double linearToLogarithmic(double linear, double MAX_VOLUME) { - return (MAX_VOLUME == 100.0) ? linear : (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * MAX_VOLUME; +double linearToLogarithmic(const double linear, double MAX_VOLUME) { + return (MAX_VOLUME == 100.0) ? (linear / 100.0) * (linear / 100.0) * MAX_VOLUME : (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * MAX_VOLUME; } // End helper volume function thingies. ONWARDS TO GLORY! diff --git a/Window/VolumeSlider.m b/Window/VolumeSlider.m index 14223f32a..ccaedf7f3 100644 --- a/Window/VolumeSlider.m +++ b/Window/VolumeSlider.m @@ -60,9 +60,9 @@ static void *kVolumeSliderContext = &kVolumeSliderContext; } - (void)updateToolTip { - double value = [self doubleValue]; - double volume; - volume = linearToLogarithmic(value, MAX_VOLUME); + const double value = [self doubleValue]; + // Sets volume to be the slider value if limit is set to 100% or the actual volume otherwise. + const double volume = (MAX_VOLUME == 100) ? value : linearToLogarithmic(value, MAX_VOLUME); NSString *text; // If volume becomes less than 1%, display two decimal digits of precision (e.g. 0.34%). -- 2.45.2