1 /*****************************************************************************
2 * equalizer.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
5 * $Id: equalizer.m 1 2004-08-07 23:50:00Z djc $
7 * Authors: J
\8er
\99me Decoodt <djc@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include <aout_internal.h>
35 #include "equalizer.h"
37 /*****************************************************************************
38 * VLCEqualizer implementation
39 *****************************************************************************/
40 @implementation VLCEqualizer
42 static void ChangeFiltersString( intf_thread_t *p_intf,
43 aout_instance_t * p_aout,
44 char *psz_name, vlc_bool_t b_add )
46 char *psz_parser, *psz_string;
50 psz_string = var_GetString( p_aout, "audio-filter" );
54 psz_string = config_GetPsz( p_intf, "audio-filter" );
57 if( !psz_string ) psz_string = strdup("");
59 psz_parser = strstr( psz_string, psz_name );
65 psz_parser = psz_string;
66 asprintf( &psz_string, (*psz_string) ? "%s,%s" : "%s%s",
67 psz_string, psz_name );
79 memmove( psz_parser, psz_parser + strlen(psz_name) +
80 (*(psz_parser + strlen(psz_name)) == ',' ? 1 : 0 ),
81 strlen(psz_parser + strlen(psz_name)) + 1 );
83 if( *(psz_string+strlen(psz_string ) -1 ) == ',' )
85 *(psz_string+strlen(psz_string ) -1 ) = '\0';
97 config_PutPsz( p_intf, "audio-filter", psz_string );
102 var_SetString( p_aout, "audio-filter", psz_string );
103 for( i = 0; i < p_aout->i_nb_inputs; i++ )
105 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
111 static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
112 aout_instance_t * p_aout,
115 char *psz_parser, *psz_string;
119 psz_string = var_GetString( p_aout, "audio-filter" );
123 psz_string = config_GetPsz( p_intf, "audio-filter" );
126 if( !psz_string ) psz_string = strdup("");
128 psz_parser = strstr( psz_string, psz_name );
138 - (IBAction)bandSliderUpdated:(id)sender
140 intf_thread_t * p_intf = VLCIntf;
141 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
142 VLC_OBJECT_AOUT, FIND_ANYWHERE);
143 char psz_values[102];
144 memset( psz_values, 0, 102 );
146 /* Write the new bands values */
147 /* TODO: write a generic code instead of ten times the same thing */
149 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band1 floatValue] );
150 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band2 floatValue] );
151 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band3 floatValue] );
152 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band4 floatValue] );
153 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band5 floatValue] );
154 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band6 floatValue] );
155 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band7 floatValue] );
156 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band8 floatValue] );
157 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band9 floatValue] );
158 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band10 floatValue] );
162 config_PutPsz( p_intf, "equalizer-bands", psz_values );
163 msg_Dbg( p_intf, "equalizer settings set to %s", psz_values);
167 var_SetString( p_aout, "equalizer-bands", psz_values );
168 msg_Dbg( p_intf, "equalizer settings changed to %s", psz_values);
169 vlc_object_release( p_aout );
173 - (IBAction)changePreset:(id)sender
175 intf_thread_t * p_intf = VLCIntf;
176 float preamp, band[10];
180 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
181 VLC_OBJECT_AOUT, FIND_ANYWHERE);
183 vlc_bool_t enabled = GetFiltersStatus( p_intf, p_aout, "equalizer" );
185 static char *preset_list[] = {
186 "flat", "classical", "club", "dance", "fullbass", "fullbasstreeble",
187 "fulltreeble", "headphones","largehall", "live", "party", "pop", "reggae",
188 "rock", "ska", "soft", "softrock", "techno"
193 config_PutPsz( p_intf, "equalizer-preset",preset_list[[sender indexOfSelectedItem]] );
197 var_SetString( p_aout , "equalizer-preset" ,preset_list[[sender indexOfSelectedItem]] );
198 vlc_object_release( p_aout );
202 if( ( p_aout == NULL ) || ( enabled == VLC_FALSE ) )
204 preamp = config_GetFloat( p_intf, "equalizer-preamp" );
205 p = config_GetPsz( p_intf, "equalizer-bands");
206 b_2p = config_GetInt( p_intf, "equalizer-2pass" );
210 preamp = var_GetFloat( p_aout, "equalizer-preamp" );
211 p = var_GetString( p_aout, "equalizer-bands" );
212 b_2p = var_GetBool( p_aout, "equalizer-2pass" );
213 vlc_object_release( p_aout );
216 /* Set the preamp slider */
217 [o_slider_preamp setFloatValue: preamp];
219 /* Set the bands slider */
220 for( i = 0; i < 10; i++ )
224 band[i] = strtof( p, &p_next );
226 band[i] = (float) strtod( p, &p_next );
228 if( !p_next || p_next == p ) break; /* strtof() failed */
230 if( !*p ) break; /* end of line */
233 [o_slider_band1 setFloatValue: band[0]];
234 [o_slider_band2 setFloatValue: band[1]];
235 [o_slider_band3 setFloatValue: band[2]];
236 [o_slider_band4 setFloatValue: band[3]];
237 [o_slider_band5 setFloatValue: band[4]];
238 [o_slider_band6 setFloatValue: band[5]];
239 [o_slider_band7 setFloatValue: band[6]];
240 [o_slider_band8 setFloatValue: band[7]];
241 [o_slider_band9 setFloatValue: band[8]];
242 [o_slider_band10 setFloatValue: band[9]];
244 if( enabled == VLC_TRUE )
245 [o_btn_enable setState:NSOnState];
247 [o_btn_enable setState:NSOffState];
249 [o_btn_2pass setState:( ( b_2p == VLC_TRUE )?NSOnState:NSOffState )];
252 - (IBAction)enable:(id)sender
254 intf_thread_t * p_intf = VLCIntf;
255 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
256 VLC_OBJECT_AOUT, FIND_ANYWHERE);
257 ChangeFiltersString( p_intf,p_aout, "equalizer", [sender state]);
260 vlc_object_release( p_aout );
263 - (IBAction)preampSliderUpdated:(id)sender
265 intf_thread_t * p_intf = VLCIntf;
266 float f= [sender floatValue] ;
268 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
269 VLC_OBJECT_AOUT, FIND_ANYWHERE);
273 config_PutFloat( p_intf, "equalizer-preamp", f );
277 var_SetFloat( p_aout, "equalizer-preamp", f );
278 vlc_object_release( p_aout );
282 - (IBAction)toggleWindow:(id)sender
284 if( [o_window isVisible] )
286 [o_window orderOut:sender];
287 [o_btn_equalizer setState:NSOffState];
291 intf_thread_t * p_intf = VLCIntf;
292 float preamp, band[10];
296 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
297 VLC_OBJECT_AOUT, FIND_ANYWHERE);
299 vlc_bool_t enabled = GetFiltersStatus( p_intf, p_aout, "equalizer" );
301 if( ( p_aout == NULL ) || ( enabled == VLC_FALSE ) )
303 preamp = config_GetFloat( p_intf, "equalizer-preamp" );
304 p = config_GetPsz( p_intf, "equalizer-bands");
305 b_2p = config_GetInt( p_intf, "equalizer-2pass" );
309 preamp = var_GetFloat( p_aout, "equalizer-preamp" );
310 p = var_GetString( p_aout, "equalizer-bands" );
311 b_2p = var_GetBool( p_aout, "equalizer-2pass" );
312 vlc_object_release( p_aout );
315 /* Set the preamp slider */
316 [o_slider_preamp setFloatValue: preamp];
318 /* Set the bands slider */
319 for( i = 0; i < 10; i++ )
323 band[i] = strtof( p, &p_next );
325 band[i] = (float) strtod( p, &p_next );
327 if( !p_next || p_next == p ) break; /* strtof() failed */
329 if( !*p ) break; /* end of line */
332 [o_slider_band1 setFloatValue: band[0]];
333 [o_slider_band2 setFloatValue: band[1]];
334 [o_slider_band3 setFloatValue: band[2]];
335 [o_slider_band4 setFloatValue: band[3]];
336 [o_slider_band5 setFloatValue: band[4]];
337 [o_slider_band6 setFloatValue: band[5]];
338 [o_slider_band7 setFloatValue: band[6]];
339 [o_slider_band8 setFloatValue: band[7]];
340 [o_slider_band9 setFloatValue: band[8]];
341 [o_slider_band10 setFloatValue: band[9]];
343 if( enabled == VLC_TRUE )
344 [o_btn_enable setState:NSOnState];
346 [o_btn_enable setState:NSOffState];
348 [o_btn_2pass setState:( ( b_2p == VLC_TRUE )?NSOnState:NSOffState )];
350 [o_window makeKeyAndOrderFront:sender];
351 [o_btn_equalizer setState:NSOnState];
355 - (IBAction)twopass:(id)sender
357 intf_thread_t * p_intf = VLCIntf;
358 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
359 VLC_OBJECT_AOUT, FIND_ANYWHERE);
361 vlc_bool_t b_2p = [sender state] ? VLC_TRUE : VLC_FALSE;
365 config_PutInt( p_intf, "equalizer-2pass", b_2p );
369 var_SetBool( p_aout, "equalizer-2pass", b_2p );
370 if( [o_btn_enable state] )
373 for( i = 0; i < p_aout->i_nb_inputs; i++ )
375 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
378 vlc_object_release( p_aout );