00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <vlc/vlc.h>
00028 #include <vlc/aout.h>
00029 #include <aout_internal.h>
00030
00031 #include "intf.h"
00032
00033 #include <math.h>
00034
00035 #include "equalizer.h"
00036 #include "../../audio_filter/equalizer_presets.h"
00037
00038
00039
00040
00041 @implementation VLCEqualizer
00042
00043 static void ChangeFiltersString( intf_thread_t *p_intf,
00044 char *psz_name, vlc_bool_t b_add )
00045 {
00046 char *psz_parser, *psz_string;
00047 int i;
00048 vlc_object_t *p_object = vlc_object_find( p_intf,
00049 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00050 aout_instance_t *p_aout = (aout_instance_t *)p_object;
00051 if( p_object == NULL )
00052 p_object = vlc_object_find( p_intf,
00053 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00054 if( p_object == NULL )
00055 return;
00056
00057 psz_string = var_GetString( p_object, "audio-filter" );
00058
00059 if( !psz_string ) psz_string = strdup( "" );
00060
00061 psz_parser = strstr( psz_string, psz_name );
00062
00063 if( b_add )
00064 {
00065 if( !psz_parser )
00066 {
00067 psz_parser = psz_string;
00068 asprintf( &psz_string, ( *psz_string ) ? "%s,%s" : "%s%s",
00069 psz_string, psz_name );
00070 free( psz_parser );
00071 }
00072 else
00073 {
00074 return;
00075 }
00076 }
00077 else
00078 {
00079 if( psz_parser )
00080 {
00081 memmove( psz_parser, psz_parser + strlen( psz_name ) +
00082 ( *( psz_parser + strlen( psz_name ) ) == ',' ? 1 : 0 ),
00083 strlen( psz_parser + strlen( psz_name ) ) + 1 );
00084
00085 if( *( psz_string+strlen( psz_string ) - 1 ) == ',' )
00086 {
00087 *( psz_string+strlen( psz_string ) - 1 ) = '\0';
00088 }
00089 }
00090 else
00091 {
00092 free( psz_string );
00093 return;
00094 }
00095 }
00096
00097 var_SetString( p_object, "audio-filter", psz_string );
00098 if( p_aout )
00099 {
00100 for( i = 0; i < p_aout->i_nb_inputs; i++ )
00101 {
00102 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
00103 }
00104 }
00105 free( psz_string );
00106 vlc_object_release( p_object );
00107 }
00108
00109 static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
00110 char *psz_name )
00111 {
00112 char *psz_parser, *psz_string;
00113 vlc_object_t *p_object = vlc_object_find( p_intf,
00114 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00115 if( p_object == NULL )
00116 p_object = vlc_object_find( p_intf,
00117 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00118 if( p_object == NULL )
00119 return VLC_FALSE;
00120
00121 psz_string = var_GetString( p_object, "audio-filter" );
00122
00123 vlc_object_release( p_object );
00124
00125 if( !psz_string ) return VLC_FALSE;
00126
00127 psz_parser = strstr( psz_string, psz_name );
00128
00129 free( psz_string );
00130
00131 if ( psz_parser )
00132 return VLC_TRUE;
00133 else
00134 return VLC_FALSE;
00135 }
00136
00137 - (void)initStrings
00138 {
00139 int i;
00140 [o_btn_equalizer setToolTip: _NS("Equalizer")];
00141 [o_ckb_2pass setTitle: _NS("2 Pass")];
00142 [o_ckb_2pass setToolTip: _NS("If you enable this settting, the "
00143 "equalizer filter will be applied twice. The effect will be sharper.")];
00144 [o_ckb_enable setTitle: _NS("Enable")];
00145 [o_ckb_enable setToolTip: _NS("Enable the equalizer. You can either "
00146 "manually change the bands or use a preset.")];
00147 [o_fld_preamp setStringValue: _NS("Preamp")];
00148
00149 [o_popup_presets removeAllItems];
00150 for( i = 0; i < 18 ; i++ )
00151 {
00152 [o_popup_presets insertItemWithTitle: _NS(preset_list_text[i]) atIndex: i];
00153 }
00154 [o_window setTitle: _NS("Equalizer")];
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 [self initBandSliders];
00169 [o_ckb_enable setState: NSOffState];
00170 [o_ckb_2pass setState: NSOffState];
00171 }
00172
00173 - (void)equalizerUpdated
00174 {
00175 intf_thread_t *p_intf = VLCIntf;
00176 float f_preamp, f_band[10];
00177 char *psz_bands, *psz_bands_init, *p_next;
00178 vlc_bool_t b_2p;
00179 int i;
00180 vlc_bool_t b_enabled = GetFiltersStatus( p_intf, "equalizer" );
00181 vlc_object_t *p_object = vlc_object_find( p_intf,
00182 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00183
00184 if( p_object == NULL )
00185 p_object = vlc_object_find( p_intf,
00186 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00187 if( p_object == NULL )
00188 return;
00189
00190 var_Create( p_object, "equalizer-preamp", VLC_VAR_FLOAT |
00191 VLC_VAR_DOINHERIT );
00192 var_Create( p_object, "equalizer-bands", VLC_VAR_STRING |
00193 VLC_VAR_DOINHERIT );
00194
00195 f_preamp = var_GetFloat( p_object, "equalizer-preamp" );
00196 psz_bands = var_GetString( p_object, "equalizer-bands" );
00197
00198 if( !strcmp( psz_bands, "" ) )
00199 psz_bands = strdup( "0 0 0 0 0 0 0 0 0 0" );
00200
00201 b_2p = var_GetBool( p_object, "equalizer-2pass" );
00202
00203 vlc_object_release( p_object );
00204
00205
00206 [o_slider_preamp setFloatValue: f_preamp];
00207
00208
00209 psz_bands_init = psz_bands;
00210
00211 for( i = 0; i < 10; i++ )
00212 {
00213
00214 #ifdef HAVE_STRTOF
00215 f_band[i] = strtof( psz_bands, &p_next );
00216 #else
00217 f_band[i] = (float)strtod( psz_bands, &p_next );
00218 #endif
00219 if( !p_next || p_next == psz_bands ) break;
00220
00221 if( !*psz_bands ) break;
00222 psz_bands = p_next+1;
00223 }
00224 free( psz_bands_init );
00225 [self setBandSlidersValues:f_band];
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 if( b_enabled == VLC_TRUE )
00242 [o_ckb_enable setState:NSOnState];
00243 else
00244 [o_ckb_enable setState:NSOffState];
00245
00246 [o_ckb_2pass setState:( ( b_2p == VLC_TRUE ) ? NSOnState : NSOffState )];
00247 }
00248
00249 - (IBAction)bandSliderUpdated:(id)sender
00250 {
00251 intf_thread_t *p_intf = VLCIntf;
00252 vlc_object_t *p_object = vlc_object_find( p_intf,
00253 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00254 char psz_values[102];
00255 memset( psz_values, 0, 102 );
00256
00257 if( p_object == NULL )
00258 p_object = vlc_object_find( p_intf,
00259 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00260 if( p_object == NULL )
00261 return;
00262
00263
00264
00265
00266 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band1 floatValue] );
00267 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band2 floatValue] );
00268 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band3 floatValue] );
00269 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band4 floatValue] );
00270 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band5 floatValue] );
00271 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band6 floatValue] );
00272 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band7 floatValue] );
00273 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band8 floatValue] );
00274 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band9 floatValue] );
00275 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band10 floatValue] );
00276
00277 var_SetString( p_object, "equalizer-bands", psz_values );
00278 vlc_object_release( p_object );
00279 }
00280
00281 - (IBAction)changePreset:(id)sender
00282 {
00283 intf_thread_t *p_intf = VLCIntf;
00284 int i;
00285 vlc_object_t *p_object= vlc_object_find( p_intf,
00286 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00287 char psz_values[102];
00288 memset( psz_values, 0, 102 );
00289
00290 if( p_object == NULL )
00291 p_object = vlc_object_find( p_intf,
00292 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00293 if( p_object == NULL )
00294 return;
00295
00296 var_SetString( p_object , "equalizer-preset" , preset_list[[sender indexOfSelectedItem]] );
00297
00298 for( i = 0; i < 10; i++ )
00299 sprintf( psz_values, "%s %.1f", psz_values, eqz_preset_10b[[sender indexOfSelectedItem]]->f_amp[i] );
00300 var_SetString( p_object, "equalizer-bands", psz_values );
00301 var_SetFloat( p_object, "equalizer-preamp", eqz_preset_10b[[sender indexOfSelectedItem]]->f_preamp);
00302
00303 [o_slider_preamp setFloatValue: eqz_preset_10b[[sender indexOfSelectedItem]]->f_preamp];
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 [self setBandSlidersValues:(float *)eqz_preset_10b[[sender indexOfSelectedItem]]->f_amp];
00317
00318 vlc_object_release( p_object );
00319 }
00320
00321 - (IBAction)enable:(id)sender
00322 {
00323 ChangeFiltersString( VLCIntf, "equalizer", [sender state] );
00324 }
00325
00326 - (IBAction)preampSliderUpdated:(id)sender
00327 {
00328 intf_thread_t *p_intf = VLCIntf;
00329 float f_preamp = [sender floatValue] ;
00330
00331 vlc_object_t *p_object = vlc_object_find( p_intf,
00332 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00333 if( p_object == NULL )
00334 p_object = vlc_object_find( p_intf,
00335 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00336 if( p_object == NULL )
00337 return;
00338
00339 var_SetFloat( p_object, "equalizer-preamp", f_preamp );
00340
00341 vlc_object_release( p_object );
00342 }
00343
00344 - (IBAction)toggleWindow:(id)sender
00345 {
00346 if( [o_window isVisible] )
00347 {
00348 [o_window orderOut:sender];
00349 [o_btn_equalizer setState:NSOffState];
00350 }
00351 else
00352 {
00353 [o_window makeKeyAndOrderFront:sender];
00354 [o_btn_equalizer setState:NSOnState];
00355 }
00356 }
00357
00358 - (IBAction)twopass:(id)sender
00359 {
00360 intf_thread_t *p_intf = VLCIntf;
00361 vlc_bool_t b_2p = [sender state] ? VLC_TRUE : VLC_FALSE;
00362 vlc_object_t *p_object= vlc_object_find( p_intf,
00363 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00364 aout_instance_t *p_aout = (aout_instance_t *)p_object;
00365 if( p_object == NULL )
00366 p_object = vlc_object_find( p_intf,
00367 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00368 if( p_object == NULL )
00369 return;
00370
00371 var_SetBool( p_object, "equalizer-2pass", b_2p );
00372 if( ( [o_ckb_enable state] ) && ( p_aout != NULL ) )
00373 {
00374 int i;
00375 for( i = 0; i < p_aout->i_nb_inputs; i++ )
00376 {
00377 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
00378 }
00379 }
00380
00381 vlc_object_release( p_object );
00382 }
00383
00384 - (void)windowWillClose:(NSNotification *)aNotification
00385 {
00386 [o_btn_equalizer setState: NSOffState];
00387 }
00388
00389 - (void)awakeFromNib
00390 {
00391 int i;
00392 vlc_object_t *p_object= vlc_object_find( VLCIntf,
00393 VLC_OBJECT_AOUT, FIND_ANYWHERE );
00394 if( p_object == NULL )
00395 p_object = vlc_object_find( VLCIntf,
00396 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00397
00398 [o_window setExcludedFromWindowsMenu: TRUE];
00399
00400 [self initStrings];
00401
00402 if( p_object )
00403 {
00404 char *psz_preset;
00405
00406 var_Create( p_object, "equalizer-preset", VLC_VAR_STRING |
00407 VLC_VAR_DOINHERIT );
00408 psz_preset = var_GetString( p_object, "equalizer-preset" );
00409
00410 for( i = 0 ; i < 18 ; i++ )
00411 {
00412 if( !strcmp( preset_list[i], psz_preset ) )
00413 {
00414 [o_popup_presets selectItemAtIndex: i];
00415
00416 [o_slider_preamp setFloatValue: eqz_preset_10b[i]->f_preamp];
00417 [self setBandSlidersValues: (float *)eqz_preset_10b[i]->f_amp];
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 if( strcmp( psz_preset, "flat" ) )
00433 {
00434 char psz_bands[100];
00435 memset( psz_bands, 0, 100 );
00436
00437 sprintf( psz_bands, "%.1f %.1f %.1f %.1f %.1f %.1f %.1f "
00438 "%.1f %.1f %.1f",
00439 eqz_preset_10b[i]->f_amp[0],
00440 eqz_preset_10b[i]->f_amp[1],
00441 eqz_preset_10b[i]->f_amp[2],
00442 eqz_preset_10b[i]->f_amp[3],
00443 eqz_preset_10b[i]->f_amp[4],
00444 eqz_preset_10b[i]->f_amp[5],
00445 eqz_preset_10b[i]->f_amp[6],
00446 eqz_preset_10b[i]->f_amp[7],
00447 eqz_preset_10b[i]->f_amp[8],
00448 eqz_preset_10b[i]->f_amp[9] );
00449
00450 var_Create( p_object, "equalizer-preamp", VLC_VAR_FLOAT |
00451 VLC_VAR_DOINHERIT );
00452 var_Create( p_object, "equalizer-bands", VLC_VAR_STRING |
00453 VLC_VAR_DOINHERIT );
00454 var_SetFloat( p_object, "equalizer-preamp",
00455 eqz_preset_10b[i]->f_preamp );
00456 var_SetString( p_object, "equalizer-bands", psz_bands );
00457 }
00458 }
00459 }
00460 free( psz_preset );
00461 vlc_object_release( p_object );
00462 }
00463
00464 [self equalizerUpdated];
00465
00466 }
00467
00468
00469 - (id)getSliderByIndex:(int)index
00470 {
00471 switch(index)
00472 {
00473 case 0 : return o_slider_band1;
00474 case 1 : return o_slider_band2;
00475 case 2 : return o_slider_band3;
00476 case 3 : return o_slider_band4;
00477 case 4 : return o_slider_band5;
00478 case 5 : return o_slider_band6;
00479 case 6 : return o_slider_band7;
00480 case 7 : return o_slider_band8;
00481 case 8 : return o_slider_band9;
00482 case 9 : return o_slider_band10;
00483 default : return nil;
00484 }
00485 }
00486
00487 - (void)setBandSlidersValues:(float *)values
00488 {
00489 int i = 0;
00490 for (i = 0 ; i<= 9 ; i++)
00491 {
00492 [self setValue:values[i] forSlider:i];
00493 }
00494 }
00495
00496 - (void)initBandSliders
00497 {
00498 int i = 0;
00499 for (i = 0 ; i< 9 ; i++)
00500 {
00501 [self setValue:0.0 forSlider:i];
00502 }
00503 }
00504
00505 - (void)setValue:(float)value forSlider:(int)index
00506 {
00507 id slider = [self getSliderByIndex:index];
00508
00509 if (slider != nil)
00510 {
00511 [slider setFloatValue:value];
00512 }
00513 }
00514
00515 @end