1 /*****************************************************************************
2 * equalizer.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
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( playlist_t *p_playlist,
43 aout_instance_t *p_aout,
44 char *psz_name, vlc_bool_t b_add )
46 char *psz_parser, *psz_string;
47 vlc_object_t *p_object = NULL;
50 if( p_playlist != NULL )
51 p_object = ( vlc_object_t* )p_playlist;
53 p_object = ( vlc_object_t* )p_aout;
54 if( p_object == NULL )
57 psz_string = var_GetString( p_object, "audio-filter" );
59 if( !psz_string ) psz_string = strdup( "" );
61 psz_parser = strstr( psz_string, psz_name );
67 psz_parser = psz_string;
68 asprintf( &psz_string, ( *psz_string ) ? "%s,%s" : "%s%s",
69 psz_string, psz_name );
81 memmove( psz_parser, psz_parser + strlen( psz_name ) +
82 ( *( psz_parser + strlen( psz_name ) ) == ',' ? 1 : 0 ),
83 strlen( psz_parser + strlen( psz_name ) ) + 1 );
85 if( *( psz_string+strlen( psz_string ) - 1 ) == ',' )
87 *( psz_string+strlen( psz_string ) - 1 ) = '\0';
97 var_SetString( p_object, "audio-filter", psz_string );
100 for( i = 0; i < p_aout->i_nb_inputs; i++ )
102 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
108 static vlc_bool_t GetFiltersStatus( playlist_t *p_playlist,
109 aout_instance_t *p_aout,
112 char *psz_parser, *psz_string;
113 vlc_object_t *p_object = NULL;
115 if( p_playlist != NULL )
116 p_object = ( vlc_object_t* )p_playlist;
118 p_object = ( vlc_object_t* )p_aout;
119 if( p_object == NULL )
122 psz_string = var_GetString( p_object, "audio-filter" );
124 if( !psz_string ) psz_string = strdup("");
126 psz_parser = strstr( psz_string, psz_name );
136 - (IBAction)bandSliderUpdated:(id)sender
138 intf_thread_t *p_intf = VLCIntf;
139 aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
140 VLC_OBJECT_AOUT, FIND_ANYWHERE );
141 playlist_t *p_playlist = ( playlist_t * )vlc_object_find( p_intf,
142 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
143 vlc_object_t *p_object = NULL;
145 char psz_values[102];
146 memset( psz_values, 0, 102 );
148 if( p_playlist != NULL )
149 p_object = ( vlc_object_t* )p_playlist;
151 p_object = ( vlc_object_t* )p_aout;
152 if( p_object == NULL )
155 /* Write the new bands values */
156 /* TODO: write a generic code instead of ten times the same thing */
158 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band1 floatValue] );
159 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band2 floatValue] );
160 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band3 floatValue] );
161 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band4 floatValue] );
162 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band5 floatValue] );
163 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band6 floatValue] );
164 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band7 floatValue] );
165 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band8 floatValue] );
166 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band9 floatValue] );
167 sprintf( psz_values, "%s %.1f", psz_values, [o_slider_band10 floatValue] );
169 var_SetString( p_object, "equalizer-bands", psz_values );
171 vlc_object_release( p_aout );
173 vlc_object_release( p_playlist );
176 - (IBAction)changePreset:(id)sender
178 intf_thread_t *p_intf = VLCIntf;
179 float f_preamp, f_band[10];
180 char *psz_bands, *p_next;
183 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
184 VLC_OBJECT_AOUT, FIND_ANYWHERE );
185 playlist_t *p_playlist = ( playlist_t * )vlc_object_find( p_intf,
186 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
187 vlc_object_t *p_object = NULL;
188 vlc_bool_t b_enabled = GetFiltersStatus( p_playlist, p_aout, "equalizer" );
190 static char *preset_list[] = {
191 "flat", "classical", "club", "dance", "fullbass", "fullbasstreble",
192 "fulltreble", "headphones","largehall", "live", "party", "pop", "reggae",
193 "rock", "ska", "soft", "softrock", "techno"
196 if( p_playlist != NULL )
197 p_object = ( vlc_object_t* )p_playlist;
199 p_object = ( vlc_object_t* )p_aout;
200 if( p_object == NULL )
202 msg_Dbg( p_intf, "equalizer settings not set: no playlist nor aout found");
206 var_SetString( p_object , "equalizer-preset" , preset_list[[sender indexOfSelectedItem]] );
208 f_preamp = var_GetFloat( p_object, "equalizer-preamp" );
209 psz_bands = var_GetString( p_object, "equalizer-bands" );
210 b_2p = var_GetBool( p_object, "equalizer-2pass" );
211 vlc_object_release( p_object );
213 /* Set the preamp slider */
214 [o_slider_preamp setFloatValue: f_preamp];
216 /* Set the bands slider */
217 for( i = 0; i < 10; i++ )
221 f_band[i] = strtof( psz_bands, &p_next );
223 f_band[i] = (float)strtod( psz_bands, &p_next );
225 if( !p_next || p_next == psz_bands ) break; /* strtof() failed */
227 if( !*psz_bands ) break; /* end of line */
228 psz_bands = p_next+1;
230 [o_slider_band1 setFloatValue: f_band[0]];
231 [o_slider_band2 setFloatValue: f_band[1]];
232 [o_slider_band3 setFloatValue: f_band[2]];
233 [o_slider_band4 setFloatValue: f_band[3]];
234 [o_slider_band5 setFloatValue: f_band[4]];
235 [o_slider_band6 setFloatValue: f_band[5]];
236 [o_slider_band7 setFloatValue: f_band[6]];
237 [o_slider_band8 setFloatValue: f_band[7]];
238 [o_slider_band9 setFloatValue: f_band[8]];
239 [o_slider_band10 setFloatValue: f_band[9]];
241 if( b_enabled == VLC_TRUE )
242 [o_btn_enable setState:NSOnState];
244 [o_btn_enable setState:NSOffState];
246 [o_btn_2pass setState:( ( b_2p == VLC_TRUE ) ? NSOnState : NSOffState )];
249 - (IBAction)enable:(id)sender
251 intf_thread_t *p_intf = VLCIntf;
252 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find( p_intf,
253 VLC_OBJECT_AOUT, FIND_ANYWHERE );
254 playlist_t *p_playlist = ( playlist_t * )vlc_object_find( p_intf,
255 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
256 ChangeFiltersString( p_playlist, p_aout, "equalizer", [sender state] );
258 [o_popup_presets setEnabled: [sender state]];
260 vlc_object_release( p_aout );
261 if( p_playlist != NULL )
262 vlc_object_release( p_playlist );
265 - (IBAction)preampSliderUpdated:(id)sender
267 intf_thread_t *p_intf = VLCIntf;
268 float f_preamp= [sender floatValue] ;
270 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
271 VLC_OBJECT_AOUT, FIND_ANYWHERE );
272 playlist_t *p_playlist = ( playlist_t * )vlc_object_find( p_intf,
273 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
275 vlc_object_t *p_object = NULL;
277 if( p_playlist != NULL )
278 p_object = ( vlc_object_t* )p_playlist;
280 p_object = ( vlc_object_t* )p_aout;
281 if( p_object == NULL )
283 msg_Dbg( p_intf, "equalizer settings not set: no playlist nor aout found");
287 var_SetFloat( p_object, "equalizer-preamp", f_preamp );
290 vlc_object_release( p_aout );
291 if( p_playlist != NULL )
292 vlc_object_release( p_playlist );
295 - (IBAction)toggleWindow:(id)sender
297 if( [o_window isVisible] )
299 [o_window orderOut:sender];
300 [o_btn_equalizer setState:NSOffState];
304 intf_thread_t *p_intf = VLCIntf;
305 float f_preamp, f_band[10];
306 char *psz_bands, *p_next;
309 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
310 VLC_OBJECT_AOUT, FIND_ANYWHERE );
311 playlist_t *p_playlist = ( playlist_t * )vlc_object_find( p_intf,
312 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
314 vlc_object_t *p_object = NULL;
316 vlc_bool_t b_enabled = GetFiltersStatus( p_playlist, p_aout, "equalizer" );
318 if( p_playlist != NULL )
319 p_object = ( vlc_object_t* )p_playlist;
321 p_object = ( vlc_object_t* )p_aout;
322 if( p_object == NULL )
324 msg_Dbg( p_intf, "equalizer settings not set: no playlist nor aout found");
328 f_preamp = var_GetFloat( p_object, "equalizer-preamp" );
329 psz_bands = var_GetString( p_object, "equalizer-bands" );
330 b_2p = var_GetBool( p_object, "equalizer-2pass" );
333 vlc_object_release( p_aout );
334 if( p_playlist != NULL )
335 vlc_object_release( p_playlist );
338 psz_bands = "0 0 0 0 0 0 0 0 0 0";
340 /* Set the preamp slider */
341 [o_slider_preamp setFloatValue: f_preamp];
343 /* Set the bands slider */
344 for( i = 0; i < 10; i++ )
348 f_band[i] = strtof( psz_bands, &p_next );
350 f_band[i] = (float)strtod( psz_bands, &p_next );
352 if( !p_next || p_next == psz_bands ) break; /* strtof() failed */
354 if( !*psz_bands ) break; /* end of line */
355 psz_bands = p_next+1;
357 [o_slider_band1 setFloatValue: f_band[0]];
358 [o_slider_band2 setFloatValue: f_band[1]];
359 [o_slider_band3 setFloatValue: f_band[2]];
360 [o_slider_band4 setFloatValue: f_band[3]];
361 [o_slider_band5 setFloatValue: f_band[4]];
362 [o_slider_band6 setFloatValue: f_band[5]];
363 [o_slider_band7 setFloatValue: f_band[6]];
364 [o_slider_band8 setFloatValue: f_band[7]];
365 [o_slider_band9 setFloatValue: f_band[8]];
366 [o_slider_band10 setFloatValue: f_band[9]];
368 if( b_enabled == VLC_TRUE )
369 [o_btn_enable setState:NSOnState];
371 [o_btn_enable setState:NSOffState];
373 [o_btn_2pass setState:( ( b_2p == VLC_TRUE ) ? NSOnState : NSOffState )];
375 [o_window makeKeyAndOrderFront:sender];
376 [o_btn_equalizer setState:NSOnState];
380 - (IBAction)twopass:(id)sender
382 intf_thread_t *p_intf = VLCIntf;
383 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
384 VLC_OBJECT_AOUT, FIND_ANYWHERE );
385 playlist_t *p_playlist = ( playlist_t * )vlc_object_find( p_intf,
386 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
387 vlc_object_t *p_object = NULL;
389 vlc_bool_t b_2p = [sender state] ? VLC_TRUE : VLC_FALSE;
391 if( p_playlist != NULL )
392 p_object = ( vlc_object_t* )p_playlist;
394 p_object = ( vlc_object_t* )p_aout;
395 if( p_object == NULL )
397 msg_Dbg( p_intf, "equalizer settings not set: no playlist nor aout found");
401 var_SetBool( p_object, "equalizer-2pass", b_2p );
402 if( ( [o_btn_enable state] ) && ( p_aout != NULL ) )
405 for( i = 0; i < p_aout->i_nb_inputs; i++ )
407 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
412 vlc_object_release( p_aout );
413 if( p_playlist != NULL )
414 vlc_object_release( p_playlist );