From 22e3dd24a00b43b7676b6a17bf9e1f2705e28ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= Date: Fri, 14 Sep 2012 16:41:13 +0200 Subject: [PATCH] macosx: added a profile management system to the audio effects (close #7342) This way, you can keep multiple sets of filters with their respective values. This implementation goes beyond custom EQ presets, which can be configured separately. --- NEWS | 8 +- .../Resources/English.lproj/AudioEffects.xib | 181 ++++++++- modules/gui/macosx/AudioEffects.h | 5 + modules/gui/macosx/AudioEffects.m | 367 +++++++++++++++--- 4 files changed, 482 insertions(+), 79 deletions(-) diff --git a/NEWS b/NEWS index 65c104b194..59795fbeb7 100644 --- a/NEWS +++ b/NEWS @@ -86,16 +86,18 @@ Mac OS X Interface: VLC's internal volume level * add the ability to create custom equalizer presets based upon the current selection and to manage the list of presets + * add custom profiles for video and audio effects, which let the user keep + multiple configuration sets of all the individual filters * add an option to disable skipping to next/previous file with the Apple Remote * add an option to show next / previous buttons * add an option to hide the shuffle and repeat buttons * add optional playlist columns for track number, genre, album, description, - date and language. + date and language * add options to the Advanced Open File dialog for start and stop time * add an option to play videos as a desktop background * add a new panel for media conversation and streaming - * allow the OS to turn off the screen(s) when playing audio-only media while the user - is idle. + * allow the OS to turn off the screen(s) when playing audio-only media while + the user is idle * The Streaming/Transcoding wizard and the open dialog's output panel are deprecated now diff --git a/extras/package/macosx/Resources/English.lproj/AudioEffects.xib b/extras/package/macosx/Resources/English.lproj/AudioEffects.xib index a635513ea2..07df62a687 100644 --- a/extras/package/macosx/Resources/English.lproj/AudioEffects.xib +++ b/extras/package/macosx/Resources/English.lproj/AudioEffects.xib @@ -2,10 +2,10 @@ 1050 - 11C74 + 11G45 851 - 1138.23 - 567.00 + 1138.51 + 569.00 YES @@ -21,7 +21,7 @@ YES - + YES @@ -46,7 +46,7 @@ 8211 2 - {{196, 289}, {409, 220}} + {{196, 254}, {409, 255}} -260571136 Audio Effects NSPanel @@ -61,7 +61,7 @@ 18 - {{-7, -10}, {424, 223}} + {{-7, 25}, {424, 223}} YES @@ -1816,8 +1816,74 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA + + + 268 + {{110, 6}, {190, 22}} + + YES + + -2076049856 + 133120 + + + 109199360 + 1 + + + 400 + 75 + + + Item 1 + + 1048576 + 2147483647 + 1 + + + _popUpItemAction: + + + YES + + OtherViews + + YES + + + + Item 2 + + 1048576 + 2147483647 + + + _popUpItemAction: + + + + + Item 3 + + 1048576 + 2147483647 + + + _popUpItemAction: + + + + + 1 + YES + YES + 2 + gradientTheme + + - {409, 220} + {409, 255} {{0, 0}, {1680, 1028}} @@ -2587,6 +2653,22 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA 663 + + + o_profile_pop + + + + 707 + + + + profileSelectorAction: + + + + 708 + @@ -2633,6 +2715,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA YES + @@ -3926,6 +4009,50 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA + + 701 + + + YES + + + + + + 702 + + + YES + + + + + + 703 + + + YES + + + + + + + + 704 + + + + + 705 + + + + + 706 + + + @@ -4250,6 +4377,13 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA 621.IBPluginDependency 621.IBViewBoundsToFrameTransform 622.IBPluginDependency + 701.IBPluginDependency + 701.IBViewBoundsToFrameTransform + 702.IBPluginDependency + 703.IBPluginDependency + 704.IBPluginDependency + 705.IBPluginDependency + 706.IBPluginDependency 80.IBAttributePlaceholdersKey 80.IBPluginDependency 80.IBViewBoundsToFrameTransform @@ -4288,9 +4422,9 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA YES com.apple.InterfaceBuilder.CocoaPlugin - {{531, 398}, {409, 220}} + {{531, 363}, {409, 255}} com.apple.InterfaceBuilder.CocoaPlugin - {{531, 398}, {409, 220}} + {{531, 363}, {409, 255}} {196, 240} {{357, 418}, {480, 270}} @@ -4737,6 +4871,15 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA P4AAAL+AAABDsAAAwxcAAA com.binarymethod.BGHUDAppKitPlugin + com.binarymethod.BGHUDAppKitPlugin + + P4AAAL+AAABCHAAAwbgAAA + + com.binarymethod.BGHUDAppKitPlugin + com.binarymethod.BGHUDAppKitPlugin + com.binarymethod.BGHUDAppKitPlugin + com.binarymethod.BGHUDAppKitPlugin + com.binarymethod.BGHUDAppKitPlugin InitialTabViewItem @@ -4810,7 +4953,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA - 700 + 708 @@ -4832,6 +4975,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA filter_enableHeadPhoneVirt: filter_enableVolumeNorm: filter_volNormSliderUpdated: + profileSelectorAction: resetCompressorValues: resetSpatializerValues: spat_enable: @@ -4855,6 +4999,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA id id id + id @@ -4871,6 +5016,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA filter_enableHeadPhoneVirt: filter_enableVolumeNorm: filter_volNormSliderUpdated: + profileSelectorAction: resetCompressorValues: resetSpatializerValues: spat_enable: @@ -4919,6 +5065,10 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA filter_volNormSliderUpdated: id + + profileSelectorAction: + id + resetCompressorValues: id @@ -4987,6 +5137,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA o_filter_normLevel_ckb o_filter_normLevel_lbl o_filter_normLevel_sld + o_profile_pop o_spat_band1_fld o_spat_band1_lbl o_spat_band1_sld @@ -5070,6 +5221,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA id id id + id @@ -5118,6 +5270,7 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA o_filter_normLevel_ckb o_filter_normLevel_lbl o_filter_normLevel_sld + o_profile_pop o_spat_band1_fld o_spat_band1_lbl o_spat_band1_sld @@ -5308,6 +5461,10 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA o_filter_normLevel_sld id + + o_profile_pop + id + o_spat_band1_fld id @@ -5416,8 +5573,8 @@ AADzUQABAAAAARbMY3VydgAAAAAAAAABAc0AAA YES - {9, 8} - {7, 2} + {11, 11} + {10, 3} {15, 15} diff --git a/modules/gui/macosx/AudioEffects.h b/modules/gui/macosx/AudioEffects.h index a2c007e4a0..6dcc718731 100644 --- a/modules/gui/macosx/AudioEffects.h +++ b/modules/gui/macosx/AudioEffects.h @@ -29,6 +29,8 @@ IBOutlet id o_tableView; IBOutlet id o_window; intf_thread_t *p_intf; + IBOutlet id o_profile_pop; + BOOL b_genericAudioProfileInInteraction; /* Equalizer */ IBOutlet id o_eq_enable_ckb; @@ -102,6 +104,9 @@ + (VLCAudioEffects *)sharedInstance; - (IBAction)toggleWindow:(id)sender; - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on; +- (IBAction)profileSelectorAction:(id)sender; +- (IBAction)addAudioEffectsProfile:(id)sender; +- (IBAction)removeAudioEffectsProfile:(id)sender; /* Equalizer */ - (void)setupEqualizer; diff --git a/modules/gui/macosx/AudioEffects.m b/modules/gui/macosx/AudioEffects.m index 3c6c4564ba..1e47b85137 100644 --- a/modules/gui/macosx/AudioEffects.m +++ b/modules/gui/macosx/AudioEffects.m @@ -34,11 +34,12 @@ #import #import +#import #import #pragma mark - -#pragma mark Initialization & Generic code +#pragma mark Initialization @implementation VLCAudioEffects static VLCAudioEffects *_o_sharedInstance = nil; @@ -75,7 +76,10 @@ static VLCAudioEffects *_o_sharedInstance = nil; [workNames addObject:[NSString stringWithUTF8String:preset_list[i]]]; } - NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithArray:workValues], @"EQValues", [NSArray arrayWithArray:workPreamp], @"EQPreampValues", [NSArray arrayWithArray:workTitles], @"EQTitles", [NSArray arrayWithArray:workNames], @"EQNames", nil]; + NSString *defaultProfile = [NSString stringWithFormat:@"%i;;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%i", + 0,.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]; [defaults registerDefaults:appDefaults]; [workValues release]; @@ -143,15 +147,11 @@ static VLCAudioEffects *_o_sharedInstance = nil; [self resetCompressor]; [self resetSpatializer]; [self resetAudioFilters]; + [self resetProfileSelector]; } -- (IBAction)toggleWindow:(id)sender -{ - if ([o_window isVisible]) - [o_window orderOut:sender]; - else - [o_window makeKeyAndOrderFront:sender]; -} +#pragma mark - +#pragma mark internal functions - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on { @@ -184,6 +184,168 @@ static VLCAudioEffects *_o_sharedInstance = nil; } } +- (void)resetProfileSelector +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [o_profile_pop removeAllItems]; + + NSArray * profileNames = [defaults objectForKey:@"AudioEffectProfileNames"]; + [o_profile_pop addItemsWithTitles:profileNames]; + + [[o_profile_pop menu] addItem:[NSMenuItem separatorItem]]; + [o_profile_pop addItemWithTitle:_NS("Save selection as new profile...")]; + [[o_profile_pop lastItem] setTarget: self]; + [[o_profile_pop lastItem] setAction: @selector(addAudioEffectsProfile:)]; + + if ([profileNames count] > 1) { + [o_profile_pop addItemWithTitle:_NS("Organize Profiles...")]; + [[o_profile_pop lastItem] setTarget: self]; + [[o_profile_pop lastItem] setAction: @selector(removeAudioEffectsProfile:)]; + } + + [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]]; + [self profileSelectorAction:self]; +} + +#pragma mark - +#pragma mark generic code +- (IBAction)toggleWindow:(id)sender +{ + if ([o_window isVisible]) + [o_window orderOut:sender]; + else + [o_window makeKeyAndOrderFront:sender]; +} + +- (IBAction)profileSelectorAction:(id)sender +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSUInteger selectedProfile = [o_profile_pop indexOfSelectedItem]; + + audio_output_t * p_aout = getAout(); + playlist_t * p_playlist = pl_Get(p_intf); + + if (p_aout) { + /* disable existing filters */ + aout_EnableFilter(p_playlist, "equalizer", false); + aout_EnableFilter(p_playlist, "compressor", false); + aout_EnableFilter(p_playlist, "spatializer", false); + aout_EnableFilter(p_playlist, "compressor", false); + aout_EnableFilter(p_playlist, "headphone", false); + aout_EnableFilter(p_playlist, "normvol", false); + } + + /* fetch preset */ + NSArray *items = [[[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"]; + + /* eq preset */ + vlc_object_t *p_object = VLC_OBJECT(getAout()); + if (p_object == NULL) + p_object = vlc_object_hold(pl_Get(p_intf)); + /* sanity check here, since the user may have removed the custom preset in the mean time */ + if ([[items objectAtIndex:0] intValue] < [[defaults objectForKey:@"EQNames"] count]) + var_SetString(p_object,"equalizer-preset",[[[defaults objectForKey:@"EQNames"] objectAtIndex:[[items objectAtIndex:0] intValue]]UTF8String]); + else + var_SetString(p_object,"equalizer-preset","flat"); + vlc_object_release(p_object); + + /* filter handling */ + NSString *tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:1] UTF8String])]; + NSArray *tempArray; + NSUInteger count; + /* enable the new filters, if we have an aout */ + if (p_aout) { + if ([tempString length] > 0) { + tempArray = [tempString componentsSeparatedByString:@":"]; + count = [tempArray count]; + for (NSUInteger x = 0; x < count; x++) + aout_EnableFilter(p_playlist, (char *)[[tempArray objectAtIndex:x] UTF8String], true); + } + } + config_PutPsz(p_intf,"audio-filter",[tempString UTF8String]); + + /* values */ + config_PutFloat(p_intf, "compressor-rms-peak",[[items objectAtIndex:2] floatValue]); + config_PutFloat(p_intf, "compressor-attack",[[items objectAtIndex:3] floatValue]); + config_PutFloat(p_intf, "compressor-release",[[items objectAtIndex:4] floatValue]); + config_PutFloat(p_intf, "compressor-threshold",[[items objectAtIndex:5] floatValue]); + config_PutFloat(p_intf, "compressor-ratio",[[items objectAtIndex:6] floatValue]); + config_PutFloat(p_intf, "compressor-knee",[[items objectAtIndex:7] floatValue]); + config_PutFloat(p_intf, "compressor-makeup-gain",[[items objectAtIndex:8] floatValue]); + config_PutFloat(p_intf, "spatializer-roomsize",[[items objectAtIndex:9] floatValue]); + config_PutFloat(p_intf, "spatializer-width",[[items objectAtIndex:10] floatValue]); + config_PutFloat(p_intf, "spatializer-wet",[[items objectAtIndex:11] floatValue]); + config_PutFloat(p_intf, "spatializer-dry",[[items objectAtIndex:12] floatValue]); + config_PutFloat(p_intf, "spatializer-damp",[[items objectAtIndex:13] floatValue]); + config_PutFloat(p_intf, "norm-max-level",[[items objectAtIndex:14] floatValue]); + config_PutInt(p_intf, "equalizer-2pass",[[items objectAtIndex:15] intValue]); + + /* set values on-the-fly if we have an aout */ + if (p_aout) { + var_SetFloat(p_aout, "compressor-rms-peak", [[items objectAtIndex:2] floatValue]); + var_SetFloat(p_aout, "compressor-attack", [[items objectAtIndex:3] floatValue]); + var_SetFloat(p_aout, "compressor-release", [[items objectAtIndex:4] floatValue]); + var_SetFloat(p_aout, "compressor-threshold", [[items objectAtIndex:5] floatValue]); + var_SetFloat(p_aout, "compressor-ratio", [[items objectAtIndex:6] floatValue]); + var_SetFloat(p_aout, "compressor-knee", [[items objectAtIndex:7] floatValue]); + var_SetFloat(p_aout, "compressor-makeup-gain", [[items objectAtIndex:8] floatValue]); + var_SetFloat(p_aout, "spatializer-roomsize", [[items objectAtIndex:9] floatValue]); + var_SetFloat(p_aout, "spatializer-width", [[items objectAtIndex:10] floatValue]); + var_SetFloat(p_aout, "spatializer-wet", [[items objectAtIndex:11] floatValue]); + var_SetFloat(p_aout, "spatializer-dry", [[items objectAtIndex:12] floatValue]); + var_SetFloat(p_aout, "spatializer-damp", [[items objectAtIndex:13] floatValue]); + var_SetFloat(p_aout, "norm-max-level", [[items objectAtIndex:14] floatValue]); + var_SetBool(p_aout, "equalizer-2pass", (BOOL)[[items objectAtIndex:15] intValue]); + } + + /* update UI */ + if ([tempString rangeOfString:@"equalizer"].location == NSNotFound) + [o_eq_enable_ckb setState:NSOffState]; + else + [o_eq_enable_ckb setState:NSOnState]; + [o_eq_twopass_ckb setState:[[items objectAtIndex:15] intValue]]; + [self resetCompressor]; + [self resetSpatializer]; + [self resetAudioFilters]; + [self updatePresetSelector]; + + /* store current profile selection */ + [defaults setInteger:selectedProfile forKey:@"AudioEffectSelectedProfile"]; + [defaults synchronize]; + + if (p_aout) + vlc_object_release(p_aout); +} + +- (IBAction)addAudioEffectsProfile:(id)sender +{ + /* show panel */ + VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance]; + [panel setTitle: _NS("Save current selection as new profile")]; + [panel setSubTitle: _NS("Enter a name for the new profile:")]; + [panel setCancelButtonLabel: _NS("Cancel")]; + [panel setOKButtonLabel: _NS("Save")]; + [panel setTarget:self]; + b_genericAudioProfileInInteraction = YES; + + [panel runModalForWindow:o_window]; +} + +- (IBAction)removeAudioEffectsProfile:(id)sender +{ + /* show panel */ + VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance]; + [panel setTitle:_NS("Remove a preset")]; + [panel setSubTitle:_NS("Select the preset you would like to remove:")]; + [panel setOKButtonLabel:_NS("Remove")]; + [panel setCancelButtonLabel:_NS("Cancel")]; + [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]]; + [panel setTarget:self]; + b_genericAudioProfileInInteraction = YES; + + [panel runModalForWindow:o_window]; +} + #pragma mark - #pragma mark Equalizer static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, @@ -224,10 +386,13 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; NSArray * presets = [defaults objectForKey:@"EQNames"]; - NSString * currentPreset = [NSString stringWithUTF8String:var_GetNonEmptyString(p_object, "equalizer-preset")]; - NSInteger currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { - return [obj isEqualToString:currentPreset]; - }]; + NSString * currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_object, "equalizer-preset")]; + NSInteger currentPresetIndex = 0; + if ([currentPreset length] > 0) { + currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { + return [obj isEqualToString:currentPreset]; + }]; + } char psz_bands[100]; snprintf(psz_bands, sizeof(psz_bands), @@ -273,10 +438,13 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; NSArray * presets = [defaults objectForKey:@"EQNames"]; - NSString * currentPreset = [NSString stringWithUTF8String:var_GetNonEmptyString(p_object, "equalizer-preset")]; - NSInteger currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { - return [obj isEqualToString:currentPreset]; - }]; + NSString * currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_object, "equalizer-preset")]; + NSInteger currentPresetIndex = 0; + if ([currentPreset length] > 0) { + currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { + return [obj isEqualToString:currentPreset]; + }]; + } [o_eq_presets_popup selectItemAtIndex:currentPresetIndex]; [o_eq_preamp_sld setFloatValue:[[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:currentPresetIndex] floatValue]]; @@ -466,6 +634,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, [panel setCancelButtonLabel: _NS("Cancel")]; [panel setOKButtonLabel: _NS("Save")]; [panel setTarget:self]; + b_genericAudioProfileInInteraction = NO; [panel runModalForWindow:o_window]; } @@ -475,38 +644,90 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, if (value == NSOKButton) { if ([text length] > 0) { NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]]; - [workArray addObject:[self generatePresetString]]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"]; - [workArray release]; - workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]]; - [workArray addObject:text]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"]; - [workArray release]; - workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]]; - [workArray addObject:[NSString stringWithFormat:@"%.1f", [o_eq_preamp_sld floatValue]]]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"]; - [workArray release]; - workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]]; - [workArray addObject:[text decomposedStringWithCanonicalMapping]]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"]; - [workArray release]; - [defaults synchronize]; - /* update VLC internals */ - vlc_object_t *p_object= VLC_OBJECT(getAout()); - if (p_object == NULL) - p_object = vlc_object_hold(pl_Get(p_intf)); + if (!b_genericAudioProfileInInteraction) { - var_SetString(p_object , "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]); - config_PutPsz(p_object, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]); + NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]]; + [workArray addObject:[self generatePresetString]]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]]; + [workArray addObject:text]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]]; + [workArray addObject:[NSString stringWithFormat:@"%.1f", [o_eq_preamp_sld floatValue]]]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]]; + [workArray addObject:[text decomposedStringWithCanonicalMapping]]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"]; + [workArray release]; + [defaults synchronize]; - vlc_object_release(p_object); + /* update VLC internals */ + vlc_object_t *p_object= VLC_OBJECT(getAout()); + if (p_object == NULL) + p_object = vlc_object_hold(pl_Get(p_intf)); - /* update UI */ - [self updatePresetSelector]; + var_SetString(p_object , "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]); + config_PutPsz(p_object, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]); + + vlc_object_release(p_object); + + /* update UI */ + [self updatePresetSelector]; + } else { + vlc_object_t *p_object = VLC_OBJECT(getAout()); + if (p_object == NULL) + p_object = vlc_object_hold(pl_Get(p_intf)); + + NSArray * presets = [defaults objectForKey:@"EQNames"]; + NSString * currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_object, "equalizer-preset")]; + NSInteger currentPresetIndex = 0; + if ([currentPreset length] > 0) { + currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { + return [obj isEqualToString:currentPreset]; + }]; + } + NSString *newProfile = [NSString stringWithFormat:@"%li;%s;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%lli", + currentPresetIndex, + vlc_b64_encode(config_GetPsz(p_intf, "audio-filter")), + config_GetFloat(p_intf, "compressor-rms-peak"), + config_GetFloat(p_intf, "compressor-attack"), + config_GetFloat(p_intf, "compressor-release"), + config_GetFloat(p_intf, "compressor-threshold"), + config_GetFloat(p_intf, "compressor-ratio"), + config_GetFloat(p_intf, "compressor-knee"), + config_GetFloat(p_intf, "compressor-makeup-gain"), + config_GetFloat(p_intf, "spatializer-roomsize"), + config_GetFloat(p_intf, "spatializer-width"), + config_GetFloat(p_intf, "spatializer-wet"), + config_GetFloat(p_intf, "spatializer-dry"), + config_GetFloat(p_intf, "spatializer-damp"), + config_GetFloat(p_intf, "norm-max-level"), + config_GetInt(p_intf,"equalizer-2pass")]; + + /* add string to user defaults as well as a label */ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + 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 release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]]; + [workArray addObject:text]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"]; + [workArray release]; + + /* save defaults */ + [defaults synchronize]; + vlc_object_release(p_object); + } } } + + [self resetProfileSelector]; } - (IBAction)deletePresetAction:(id)sender @@ -518,6 +739,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, [panel setCancelButtonLabel:_NS("Cancel")]; [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]]; [panel setTarget:self]; + b_genericAudioProfileInInteraction = NO; [panel runModalForWindow:o_window]; } @@ -525,28 +747,45 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item { if (value == NSOKButton) { - /* remove requested profile from the arrays */ - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]]; - [workArray removeObjectAtIndex:item]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"]; - [workArray release]; - workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]]; - [workArray removeObjectAtIndex:item]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"]; - [workArray release]; - workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]]; - [workArray removeObjectAtIndex:item]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"]; - [workArray release]; - workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]]; - [workArray removeObjectAtIndex:item]; - [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"]; - [workArray release]; - [defaults synchronize]; + if (!b_genericAudioProfileInInteraction) { + /* remove requested profile from the arrays */ + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]]; + [workArray removeObjectAtIndex:item]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]]; + [workArray removeObjectAtIndex:item]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]]; + [workArray removeObjectAtIndex:item]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]]; + [workArray removeObjectAtIndex:item]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"]; + [workArray release]; + [defaults synchronize]; - /* update UI */ - [self updatePresetSelector]; + /* update UI */ + [self updatePresetSelector]; + } else { + /* remove selected profile from settings */ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]]; + [workArray removeObjectAtIndex:item]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"]; + [workArray release]; + workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]]; + [workArray removeObjectAtIndex:item]; + [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"]; + [workArray release]; + + /* save defaults */ + [defaults synchronize]; + [self resetProfileSelector]; + } } }