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 <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-03-04 00:12:44 -08:00
parent 001f3e53ea
commit 915e212ae5

View file

@ -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 {