[vlc-commits] macosx: save default audio profile as custom when quiting

Victorien Le Couviour--Tuffet git at videolan.org
Thu Jul 13 11:26:14 CEST 2017


vlc | branch: master | Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com> | Tue Jul  4 09:08:56 2017 +0200| [116e785cac491c23fe8ee6d6631cfc2029fb149f] | committer: Jean-Baptiste Kempf

macosx: save default audio profile as custom when quiting

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=116e785cac491c23fe8ee6d6631cfc2029fb149f
---

 .../gui/macosx/VLCAudioEffectsWindowController.h   |  2 +-
 .../gui/macosx/VLCAudioEffectsWindowController.m   | 76 ++++++++++++++++++++++
 modules/gui/macosx/VLCMain.m                       |  2 +-
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/modules/gui/macosx/VLCAudioEffectsWindowController.h b/modules/gui/macosx/VLCAudioEffectsWindowController.h
index 283b652b3f..ead4d711c4 100644
--- a/modules/gui/macosx/VLCAudioEffectsWindowController.h
+++ b/modules/gui/macosx/VLCAudioEffectsWindowController.h
@@ -116,7 +116,7 @@
 
 - (void)toggleWindow:(id)sender;
 - (void)updateCocoaWindowLevel:(NSInteger)i_level;
-- (void)saveCurrentProfile;
+- (void)saveCurrentProfileAtTerminate;
 
 /* Equalizer */
 - (IBAction)equalizerBandSliderUpdated:(id)sender;
diff --git a/modules/gui/macosx/VLCAudioEffectsWindowController.m b/modules/gui/macosx/VLCAudioEffectsWindowController.m
index a036adbcd4..b445961ac6 100644
--- a/modules/gui/macosx/VLCAudioEffectsWindowController.m
+++ b/modules/gui/macosx/VLCAudioEffectsWindowController.m
@@ -378,6 +378,82 @@
     [defaults synchronize];
 }
 
+- (void)saveCurrentProfileAtTerminate
+{
+    if (i_old_profile_index)
+        return [self saveCurrentProfile];
+
+    playlist_t *p_playlist = pl_Get(getIntf());
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    NSString *newPresetString = [NSString stringWithCString:var_InheritString(p_playlist, "equalizer-bands") encoding:NSASCIIStringEncoding];
+    float newPresetPreamp = var_InheritFloat(p_playlist, "equalizer-preamp");
+
+    NSInteger defaultPresetIndex = [self getPresetIndexForProfile:0];
+    NSString *defaultPresetString = [[defaults objectForKey:@"EQValues"] objectAtIndex:defaultPresetIndex];
+    float defaultPresetPreamp = [[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:defaultPresetIndex] floatValue];
+    if ([[self generateProfileString] compare:[[defaults objectForKey:@"AudioEffectProfiles"] firstObject]] == NSOrderedSame &&
+        [newPresetString compare:defaultPresetString] == NSOrderedSame &&
+        newPresetPreamp == defaultPresetPreamp)
+        return;
+
+    NSMutableArray *workArray;
+    int num_custom;
+
+    if ([newPresetString compare:defaultPresetString] != NSOrderedSame ||
+        newPresetPreamp != defaultPresetPreamp)
+    {
+        /* preset title */
+        NSArray<NSString *> *presetTitles = [defaults objectForKey:@"EQTitles"];
+        NSString *newPresetTitle;
+
+        num_custom = 0;
+        do
+            newPresetTitle = [@"Custom" stringByAppendingString:[NSString stringWithFormat:@"%03i",num_custom++]];
+        while ([presetTitles containsObject:newPresetTitle]);
+
+        workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
+        [workArray addObject:newPresetTitle];
+        [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
+
+        /* preset name */
+        NSString *decomposedStringWithCanonicalMapping = [newPresetTitle decomposedStringWithCanonicalMapping];
+        workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
+        [workArray addObject:decomposedStringWithCanonicalMapping];
+        [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
+        var_SetString(p_playlist, "equalizer-preset", [decomposedStringWithCanonicalMapping UTF8String]);
+
+        /* preset bands */
+        workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
+        [workArray addObject:newPresetString];
+        [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
+
+        /* preset preamp */
+        workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
+        [workArray addObject:[NSString stringWithFormat:@"%.1f", [_equalizerPreampSlider floatValue]]];
+        [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
+    }
+
+    /* profile string */
+    workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
+    [workArray addObject:[self generateProfileString]];
+    [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
+
+    /* profile name */
+    NSArray<NSString *> *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
+    NSString *newProfileName;
+
+    num_custom = 0;
+    do
+        newProfileName = [@"Custom" stringByAppendingString:[NSString stringWithFormat:@"%03i",num_custom++]];
+    while ([profileNames containsObject:newProfileName]);
+
+    workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
+    [workArray addObject:newProfileName];
+    [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
+
+    [defaults synchronize];
+}
+
 - (IBAction)profileSelectorAction:(id)sender
 {
     [self saveCurrentProfile];
diff --git a/modules/gui/macosx/VLCMain.m b/modules/gui/macosx/VLCMain.m
index e815f2c29e..33fcea320a 100644
--- a/modules/gui/macosx/VLCMain.m
+++ b/modules/gui/macosx/VLCMain.m
@@ -336,7 +336,7 @@ static VLCMain *sharedInstance = nil;
 
     /* save current video and audio profiles */
     [[self videoEffectsPanel] saveCurrentProfileAtTerminate];
-    [[self audioEffectsPanel] saveCurrentProfile];
+    [[self audioEffectsPanel] saveCurrentProfileAtTerminate];
 
     /* Save some interface state in configuration, at module quit */
     config_PutInt(p_intf, "random", var_GetBool(p_playlist, "random"));



More information about the vlc-commits mailing list