[vlc-commits] macosx: audio effects: Do same profile handling for audio effects

David Fuhrmann git at videolan.org
Wed Dec 13 22:52:29 CET 2017


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Wed Dec 13 21:32:52 2017 +0100| [b77321140b053d3883c165e538d8bd41d47cffa2] | committer: David Fuhrmann

macosx: audio effects: Do same profile handling for audio effects

This ports over video effects profile handling to audio effects.
Behaviour is the same for the main audio profile.
This also fixes an occasion where equalizer was not updated correctly.

refs #19260

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

 .../gui/macosx/VLCAudioEffectsWindowController.m   | 147 +++++++++++++--------
 1 file changed, 94 insertions(+), 53 deletions(-)

diff --git a/modules/gui/macosx/VLCAudioEffectsWindowController.m b/modules/gui/macosx/VLCAudioEffectsWindowController.m
index 445e886007..8a5ed1c7e8 100644
--- a/modules/gui/macosx/VLCAudioEffectsWindowController.m
+++ b/modules/gui/macosx/VLCAudioEffectsWindowController.m
@@ -37,15 +37,6 @@
 
 #import <math.h>
 
- at interface VLCAudioEffectsWindowController ()
-{
-    NSInteger i_old_profile_index;
-}
-- (void)resetProfileSelector;
-- (void)updatePresetSelector;
-- (void)setBandSliderValuesForPreset:(NSInteger)presetID;
- at end
-
 #pragma mark -
 #pragma mark Initialization
 
@@ -79,19 +70,27 @@
         [workNames addObject:toNSStr(preset_list[i])];
     }
 
-    NSString *defaultProfile = [NSString stringWithFormat:@"ZmxhdA==;;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%i",
-                                .0,25.,100.,-11.,8.,2.5,7.,.85,1.,.4,.5,.5,2.,0];
-
-    NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithArray:workValues], @"EQValues", [NSArray arrayWithArray:workPreamp], @"EQPreampValues", [NSArray arrayWithArray:workTitles], @"EQTitles", [NSArray arrayWithArray:workNames], @"EQNames", [NSArray arrayWithObject:defaultProfile], @"AudioEffectProfiles", [NSArray arrayWithObject:_NS("Default")], @"AudioEffectProfileNames", nil];
+    NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
+                                 [NSArray arrayWithArray:workValues], @"EQValues",
+                                 [NSArray arrayWithArray:workPreamp], @"EQPreampValues",
+                                 [NSArray arrayWithArray:workTitles], @"EQTitles",
+                                 [NSArray arrayWithArray:workNames], @"EQNames",
+                                 [NSArray arrayWithObject:[VLCAudioEffectsWindowController defaultProfileString]], @"AudioEffectProfiles",
+                                 [NSArray arrayWithObject:_NS("Default")], @"AudioEffectProfileNames",
+                                  nil];
     [defaults registerDefaults:appDefaults];
 }
 
++ (NSString *)defaultProfileString
+{
+    return [NSString stringWithFormat:@"ZmxhdA==;;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%i",
+            .0,25.,100.,-11.,8.,2.5,7.,.85,1.,.4,.5,.5,2.,0];
+}
+
 - (id)init
 {
     self = [super initWithWindowNibName:@"AudioEffects"];
     if (self) {
-        i_old_profile_index = -1;
-
         self.popupPanel = [[VLCPopupPanelController alloc] init];
         self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
 
@@ -105,9 +104,9 @@
             [self resetAudioFilters];
 
             [self loadProfile];
+        } else {
+            [self saveCurrentProfileIndex:0];
         }
-        else
-            [defaults setInteger:0 forKey:@"AudioEffectSelectedProfile"];
     }
 
     return self;
@@ -121,11 +120,12 @@
     return [[defaults objectForKey:@"EQNames"] indexOfObject:presetName];
 }
 
+/// Loads values from profile into variables
 - (void)loadProfile
 {
     intf_thread_t *p_intf = getIntf();
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    NSInteger selectedProfile = [defaults integerForKey:@"AudioEffectSelectedProfile"];
+    NSInteger profileIndex = [self currentProfileIndex];
     playlist_t *p_playlist = pl_Get(p_intf);
 
     /* disable existing filters */
@@ -138,7 +138,13 @@
     playlist_EnableAudioFilter(p_playlist, "karaoke", false);
 
     /* fetch preset */
-    NSArray *items = [[[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:(NSUInteger) selectedProfile] componentsSeparatedByString:@";"];
+    NSString *profileString;
+    if (profileIndex == 0)
+        profileString = [VLCAudioEffectsWindowController defaultProfileString];
+    else
+        profileString = [[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:profileIndex];
+
+    NSArray *items = [profileString componentsSeparatedByString:@";"];
 
     /* eq preset */
     char const *psz_eq_preset = [B64DecNSStr([items firstObject]) UTF8String];
@@ -151,6 +157,7 @@
     NSString *tempString = B64DecNSStr([items objectAtIndex:1]);
     NSArray *tempArray;
     NSUInteger count;
+
     /* enable the new filters */
     if ([tempString length] > 0) {
         tempArray = [tempString componentsSeparatedByString:@":"];
@@ -159,7 +166,7 @@
             playlist_EnableAudioFilter(p_playlist, [[tempArray objectAtIndex:x] UTF8String], true);
     }
 
-    NSInteger presetIndex = [self getPresetIndexForProfile:selectedProfile];
+    NSInteger presetIndex = [self getPresetIndexForProfile:profileIndex];
 
     /* values */
     var_SetFloat(p_playlist, "compressor-rms-peak",[[items objectAtIndex:2] floatValue]);
@@ -208,8 +215,6 @@
 
     [_equalizerTwoPassCheckbox setState:[[items objectAtIndex:15] intValue]];
 
-    /* store current profile selection */
-    [defaults setInteger:selectedProfile forKey:@"AudioEffectSelectedProfile"];
     [defaults synchronize];
 
     if (p_aout)
@@ -296,6 +301,27 @@
 #pragma mark -
 #pragma mark internal functions
 
+
+- (void)saveCurrentProfileIndex:(NSInteger)index
+{
+    [[NSUserDefaults standardUserDefaults] setInteger:index forKey:@"AudioEffectSelectedProfile"];
+}
+
+- (NSInteger)currentProfileIndex
+{
+    return [[NSUserDefaults standardUserDefaults] integerForKey:@"AudioEffectSelectedProfile"];
+}
+
+/// Returns the list of profile names (omitting the Default entry)
+- (NSArray *)nonDefaultProfileNames
+{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+    NSMutableArray *names = [[defaults stringArrayForKey:@"AudioEffectProfileNames"] mutableCopy];
+    [names removeObjectAtIndex:0];
+    return [names copy];
+}
+
 - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on
 {
     playlist_EnableAudioFilter(pl_Get(getIntf()), psz_name, b_on);
@@ -306,22 +332,25 @@
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     [_profilePopup removeAllItems];
 
-    NSArray *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
-    [_profilePopup addItemsWithTitles:profileNames];
+    // Ignore "Default" index 0 from settings
+    [_profilePopup addItemWithTitle:_NS("Default")];
+
+    [_profilePopup addItemsWithTitles:[self nonDefaultProfileNames]];
 
     [[_profilePopup menu] addItem:[NSMenuItem separatorItem]];
     [_profilePopup addItemWithTitle:_NS("Duplicate current profile...")];
     [[_profilePopup lastItem] setTarget: self];
     [[_profilePopup lastItem] setAction: @selector(addAudioEffectsProfile:)];
 
-    if ([profileNames count] > 1) {
+    if ([[self nonDefaultProfileNames] count] > 0) {
         [_profilePopup addItemWithTitle:_NS("Organize Profiles...")];
         [[_profilePopup lastItem] setTarget: self];
         [[_profilePopup lastItem] setAction: @selector(removeAudioEffectsProfile:)];
     }
 
-    [_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
-    if (i_old_profile_index || [[NSUserDefaults standardUserDefaults] integerForKey:@"AudioEffectSelectedProfile"])
+    [_profilePopup selectItemAtIndex:[self currentProfileIndex]];
+    // Loading only non-default profiles ensures that vlcrc or command line settings are not overwritten
+    if ([self currentProfileIndex] > 0)
         [self profileSelectorAction:self];
 }
 
@@ -346,6 +375,7 @@
 - (NSString *)generateProfileString
 {
     playlist_t *p_playlist = pl_Get(getIntf());
+
     return [NSString stringWithFormat:@"%@;%@;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%i",
                      B64EncAndFree(var_GetNonEmptyString(p_playlist, "equalizer-preset")),
                      B64EncAndFree(var_InheritString(p_playlist, "audio-filter")),
@@ -367,7 +397,8 @@
 
 - (void)saveCurrentProfile
 {
-    if (!i_old_profile_index || i_old_profile_index == -1)
+    NSInteger currentProfileIndex = [self currentProfileIndex];
+    if (currentProfileIndex == 0)
         return;
 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
@@ -375,18 +406,20 @@
     NSString *newProfile = [self generateProfileString];
 
     NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
-    if (i_old_profile_index >= [workArray count])
+    if (currentProfileIndex >= [workArray count])
         return;
 
-    [workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile];
+    [workArray replaceObjectAtIndex:currentProfileIndex withObject:newProfile];
     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
     [defaults synchronize];
 }
 
 - (void)saveCurrentProfileAtTerminate
 {
-    if (i_old_profile_index)
-        return [self saveCurrentProfile];
+    if ([self currentProfileIndex] > 0) {
+        [self saveCurrentProfile];
+        return;
+    }
 
     if (_applyProfileCheckbox.state == NSOffState)
         return;
@@ -399,7 +432,7 @@
     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 &&
+    if ([[self generateProfileString] compare:[VLCAudioEffectsWindowController defaultProfileString]] == NSOrderedSame &&
         [newPresetString compare:defaultPresetString] == NSOrderedSame &&
         newPresetPreamp == defaultPresetPreamp)
         return;
@@ -459,7 +492,7 @@
     [workArray addObject:newProfileName];
     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
 
-    [defaults setInteger:([workArray count] - 1) forKey:@"AudioEffectSelectedProfile"];
+    [self saveCurrentProfileIndex:([workArray count] - 1)];
 
     [defaults synchronize];
 }
@@ -467,11 +500,12 @@
 - (IBAction)profileSelectorAction:(id)sender
 {
     [self saveCurrentProfile];
-    i_old_profile_index = [_profilePopup indexOfSelectedItem];
-    [[NSUserDefaults standardUserDefaults] setInteger:i_old_profile_index forKey:@"AudioEffectSelectedProfile"];
+
+    [self saveCurrentProfileIndex:[_profilePopup indexOfSelectedItem]];
     [self loadProfile];
 
     /* update UI */
+    [self equalizerUpdated];
     [self resetCompressor];
     [self resetSpatializer];
     [self resetAudioFilters];
@@ -489,17 +523,18 @@
     __unsafe_unretained typeof(self) _self = self;
     [_textfieldPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSString *resultingText) {
 
-        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+        NSInteger currentProfileIndex = [_self currentProfileIndex];
         if (returnCode != NSOKButton) {
-            [_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
+            [_profilePopup selectItemAtIndex:currentProfileIndex];
             return;
         }
 
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSArray *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
 
         // duplicate names are not allowed in the popup control
         if ([resultingText length] == 0 || [profileNames containsObject:resultingText]) {
-            [_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
+            [_profilePopup selectItemAtIndex:currentProfileIndex];
 
             NSAlert *alert = [[NSAlert alloc] init];
             [alert setAlertStyle:NSCriticalAlertStyle];
@@ -519,11 +554,14 @@
         NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
         [workArray addObject:newProfile];
         [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
-        [defaults setInteger:[workArray count] - 1 forKey:@"AudioEffectSelectedProfile"];
+
         workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
         [workArray addObject:resultingText];
         [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
 
+        [_self saveCurrentProfileIndex:([workArray count] - 1)];
+
+
         /* save defaults */
         [defaults synchronize];
         [_self resetProfileSelector];
@@ -538,22 +576,21 @@
     [_popupPanel setSubTitleString:_NS("Select the preset you would like to remove:")];
     [_popupPanel setOkButtonString:_NS("Remove")];
     [_popupPanel setCancelButtonString:_NS("Cancel")];
-    [_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]];
+    [_popupPanel setPopupButtonContent:[self nonDefaultProfileNames]];
 
     __unsafe_unretained typeof(self) _self = self;
     [_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
 
-        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+        NSInteger currentProfileIndex = [_self currentProfileIndex];
         if (returnCode != NSOKButton) {
-            [_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
+            [_profilePopup selectItemAtIndex:currentProfileIndex];
             return;
         }
 
-        if (!selectedIndex) { // TODO: add popup to notify user
-            [_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
-            return;
-        }
+        // Popup panel does not contain the "Default" entry
+        selectedIndex++;
 
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         /* remove selected profile from settings */
         NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
         [workArray removeObjectAtIndex:selectedIndex];
@@ -562,8 +599,8 @@
         [workArray removeObjectAtIndex:selectedIndex];
         [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
 
-        if (i_old_profile_index >= selectedIndex)
-            [defaults setInteger:i_old_profile_index - 1 forKey:@"AudioEffectSelectedProfile"];
+        if (currentProfileIndex >= selectedIndex)
+            [_self saveCurrentProfileIndex:(currentProfileIndex - 1)];
 
         /* save defaults */
         [defaults synchronize];
@@ -935,8 +972,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
 - (IBAction)compressorSliderUpdated:(id)sender
 {
-    audio_output_t *p_aout = getAout();
-    char *psz_property;
+    char *psz_property = nil;
     float f_value = [sender floatValue];
 
     if (sender == _compressorBand1Slider)
@@ -954,6 +990,9 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
     else if (sender == _compressorBand7Slider)
         psz_property = "compressor-makeup-gain";
 
+    assert(psz_property);
+
+    audio_output_t *p_aout = getAout();
     if (p_aout) {
         var_SetFloat(p_aout, psz_property, f_value);
         vlc_object_release(p_aout);
@@ -1035,8 +1074,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
 - (IBAction)spatializerSliderUpdated:(id)sender
 {
-    audio_output_t *p_aout = getAout();
-    char *psz_property = NULL;
+    char *psz_property = nil;
     float f_value = [sender floatValue];
 
     if (sender == _spatializerBand1Slider)
@@ -1050,6 +1088,9 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
     else if (sender == _spatializerBand5Slider)
         psz_property = "spatializer-damp";
 
+    assert(psz_property);
+
+    audio_output_t *p_aout = getAout();
     if (p_aout) {
         var_SetFloat(p_aout, psz_property, f_value / 10.f);
         vlc_object_release(p_aout);



More information about the vlc-commits mailing list