From 915e212ae5c20d694744231d2a018b7939e8802e Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 4 Mar 2025 00:12:44 -0800 Subject: [PATCH] Bug Fix: Snap pitch and tempo settings to 1 Pitch and tempo weren't snapping to exactly 1.0 before, as a result of various things. This fixes that. Signed-off-by: Christopher Snowhill --- Application/PlaybackController.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index dbe0d0609..4d3797fc5 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -153,6 +153,17 @@ static double reverseSpeedScale(double input, double min, double max) { return (input * (max - min) / 100.0) + min; } +- (void)snapSpeeds { + double pitch = [[NSUserDefaults standardUserDefaults] doubleForKey:@"pitch"]; + double tempo = [[NSUserDefaults standardUserDefaults] doubleForKey:@"tempo"]; + if(fabs(pitch - 1.0) < 1e-6) { + [[NSUserDefaults standardUserDefaults] setDouble:1.0 forKey:@"pitch"]; + } + if(fabs(tempo - 1.0) < 1e-6) { + [[NSUserDefaults standardUserDefaults] setDouble:1.0 forKey:@"tempo"]; + } +} + - (void)awakeFromNib { BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"]; const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0; @@ -167,6 +178,8 @@ static double reverseSpeedScale(double input, double min, double max) { double tempo = [[NSUserDefaults standardUserDefaults] doubleForKey:@"tempo"]; [tempoSlider setDoubleValue:reverseSpeedScale(tempo, [tempoSlider minValue], [tempoSlider maxValue])]; + [self snapSpeeds]; + BOOL speedLock = [[NSUserDefaults standardUserDefaults] boolForKey:@"speedLock"]; [lockButton setTitle:speedLock ? @"🔒" : @"🔓"]; @@ -548,6 +561,8 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) { if([[NSUserDefaults standardUserDefaults] boolForKey:@"speedLock"]) { [[NSUserDefaults standardUserDefaults] setDouble:pitch forKey:@"tempo"]; } + + [self snapSpeeds]; } - (IBAction)changeTempo:(id)sender { @@ -559,6 +574,8 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) { if([[NSUserDefaults standardUserDefaults] boolForKey:@"speedLock"]) { [[NSUserDefaults standardUserDefaults] setDouble:tempo forKey:@"pitch"]; } + + [self snapSpeeds]; } - (IBAction)skipToNextAlbum:(id)sender {