[vlc-devel] [PATCH 17/18] macosx: save default audio profile as custom when quiting

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Tue Jul 4 10:01:16 CEST 2017


---
 .../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"));
-- 
2.13.1



More information about the vlc-devel mailing list