1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id: preferences.cpp 16643 2006-09-13 12:45:46Z zorglub $
7 * Authors: Clément Stenac <zorglub@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <QGridLayout>
29 #include <QSignalMapper>
31 #include "components/extended_panels.hpp"
32 #include "dialogs/prefs_dialog.hpp"
33 #include "dialogs_provider.hpp"
36 #include "../../audio_filter/equalizer_presets.h"
38 #include <vlc_intf_strings.h>
42 class ConfClickHandler : public QObject
45 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject (_e) {
46 e = _e; p_intf = _p_intf;
48 virtual ~ConfClickHandler() {}
49 bool eventFilter( QObject *obj, QEvent *evt )
51 if( evt->type() == QEvent::MouseButtonPress )
60 intf_thread_t *p_intf;
63 #define SETUP_VFILTER( widget, conf, tooltip, labtooltip ) \
64 ui.widget##Check->setToolTip( tooltip ); \
66 ui.widget##Label->setToolTip( labtooltip ); \
67 ui.widget##Label->setPixmap( QPixmap(":/pixmaps/go-next.png") ); \
68 ui.widget##Label->installEventFilter(h); \
70 CONNECT( ui.widget##Check, clicked(), this, updateFilters() ); \
72 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QWidget *_parent ) :
73 QWidget( _parent ) , p_intf( _p_intf )
75 ConfClickHandler* h = new ConfClickHandler( p_intf, this );
79 SETUP_VFILTER( clone, true, qtr(I_CLONE_TIP),
80 qtr("Configure the clone filter") );
81 SETUP_VFILTER( magnify, false, qtr(I_MAGNIFY_TIP),
82 qtr("Configure the magnification effect"));
83 SETUP_VFILTER( wave, false, qtr(I_WAVE_TIP),
84 qtr("Configure the waves effect"));
85 SETUP_VFILTER( ripple, false, qtr(I_RIPPLE_TIP),
86 qtr("Configure the \"water\" effect"));
87 SETUP_VFILTER( invert, false, qtr(I_INVERT_TIP),
88 qtr("Configure the color inversion effect"));
89 SETUP_VFILTER( puzzle, true, qtr(I_PUZZLE_TIP),
90 qtr("Configure the puzzle effect"));
91 SETUP_VFILTER( wall, true, qtr(I_WALL_TIP),
92 qtr("Configure the wall filter") );
93 SETUP_VFILTER( gradient, true, qtr(I_GRADIENT_TIP),
94 qtr("Configure the \"gradient\" effect"));
95 SETUP_VFILTER( colorthres, true, qtr(I_COLORTHRES_TIP),
96 qtr("Configure the color detection effect"));
103 static void ChangeVFiltersString( intf_thread_t *p_intf,
104 char *psz_name, vlc_bool_t b_add )
106 vout_thread_t *p_vout;
107 char *psz_parser, *psz_string;
109 psz_string = config_GetPsz( p_intf, "video-filter" );
111 if( !psz_string ) psz_string = strdup("");
113 psz_parser = strstr( psz_string, psz_name );
119 psz_parser = psz_string;
120 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
121 psz_string, psz_name );
133 memmove( psz_parser, psz_parser + strlen(psz_name) +
134 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
135 strlen(psz_parser + strlen(psz_name)) + 1 );
137 /* Remove trailing : : */
138 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
140 *(psz_string+strlen(psz_string ) -1 ) = '\0';
149 /* Vout is not kept, so put that in the config */
150 config_PutPsz( p_intf, "video-filter", psz_string );
152 /* Try to set on the fly */
153 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
157 var_SetString( p_vout, "video-filter", psz_string );
158 vlc_object_release( p_vout );
164 void ExtVideo::updateFilters()
166 QCheckBox* filter = qobject_cast<QCheckBox*>(sender());
167 QString module = filter->objectName().replace("Check", "");
169 ChangeVFiltersString( p_intf, qtu(module), filter->isChecked() );
172 void ExtVideo::gotoConf( QObject* src )
174 #define SHOWCONF(module) \
175 if( src->objectName().contains(module) ) \
177 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
181 SHOWCONF( "magnify" );
183 SHOWCONF( "ripple" );
184 SHOWCONF( "invert" );
185 SHOWCONF( "puzzle" );
187 SHOWCONF( "gradient" );
188 SHOWCONF( "colorthres" )
191 /**********************************************************************
193 **********************************************************************/
195 static const QString band_frequencies[] =
197 " 60Hz ", " 170 Hz " , " 310 Hz ", " 600 Hz ", " 1 kHz ",
198 " 3 kHz " , " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
201 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
202 QWidget( _parent ) , p_intf( _p_intf )
204 QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
205 smallFont.setPointSize( smallFont.pointSize() - 3 );
209 ui.preampLabel->setFont( smallFont );
210 ui.preampSlider->setMaximum( 400 );
211 for( int i = 0 ; i < NB_PRESETS ; i ++ )
213 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
216 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
218 BUTTONACT( ui.enableCheck, enable() );
219 BUTTONACT( ui.eq2PassCheck, set2Pass() );
221 CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
223 QGridLayout *grid = new QGridLayout( ui.frame );
224 grid->setMargin( 0 );
225 for( int i = 0 ; i < BANDS ; i++ )
227 bands[i] = new QSlider( Qt::Vertical );
228 bands[i]->setMaximum( 400 );
229 bands[i]->setValue( 200 );
230 CONNECT( bands[i], valueChanged(int), this, setBand() );
231 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
232 band_texts[i]->setFont( smallFont );
233 grid->addWidget( bands[i], 0, i );
234 grid->addWidget( band_texts[i], 1, i );
237 /* Write down initial values */
238 aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
239 VLC_OBJECT_AOUT, FIND_ANYWHERE);
245 psz_af = var_GetString( p_aout, "audio-filter" );
246 if( var_GetBool( p_aout, "equalizer-2pass" ) )
247 ui.eq2PassCheck->setChecked( true );
248 psz_bands = var_GetString( p_aout, "equalizer-bands" );
249 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
250 vlc_object_release( p_aout );
254 psz_af = config_GetPsz( p_intf, "audio-filter" );
255 if( config_GetInt( p_intf, "equalizer-2pass" ) )
256 ui.eq2PassCheck->setChecked( true );
257 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
258 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
260 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
261 ui.enableCheck->setChecked( true );
262 enable( ui.enableCheck->isChecked() );
264 setValues( psz_bands, f_preamp );
267 Equalizer::~Equalizer()
271 void Equalizer::enable()
273 bool en = ui.enableCheck->isChecked();
274 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
275 en ? VLC_TRUE : VLC_FALSE );
279 void Equalizer::enable( bool en )
281 ui.eq2PassCheck->setEnabled( en );
282 ui.preampLabel->setEnabled( en );
283 ui.preampSlider->setEnabled( en );
284 for( int i = 0 ; i< BANDS; i++ )
286 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
290 void Equalizer::set2Pass()
292 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
293 VLC_OBJECT_AOUT, FIND_ANYWHERE);
294 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
297 config_PutInt( p_intf, "equalizer-2pass", b_2p );
300 var_SetBool( p_aout, "equalizer-2pass", b_2p );
301 config_PutInt( p_intf, "equalizer-2pass", b_2p );
302 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
304 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
306 vlc_object_release( p_aout );
310 void Equalizer::setPreamp()
312 float f= (float)( ui.preampSlider->value() ) /10 - 20;
314 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
315 VLC_OBJECT_AOUT, FIND_ANYWHERE);
317 sprintf( psz_val, "%.1f", f );
318 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
321 delCallbacks( p_aout );
322 var_SetFloat( p_aout, "equalizer-preamp", f );
323 addCallbacks( p_aout );
324 vlc_object_release( p_aout );
326 config_PutFloat( p_intf, "equalizer-preamp", f );
329 void Equalizer::setBand()
331 char psz_values[102]; memset( psz_values, 0, 102 );
333 /**\todo smoothing */
335 for( int i = 0 ; i< BANDS ; i++ )
338 float f_val = (float)( bands[i]->value() ) / 10 - 20 ;
339 sprintf( psz_values, "%s %f", psz_values, f_val );
340 sprintf( psz_val, "% 5.1f", f_val );
341 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
343 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
344 VLC_OBJECT_AOUT, FIND_ANYWHERE);
347 delCallbacks( p_aout );
348 var_SetString( p_aout, "equalizer-bands", psz_values );
349 addCallbacks( p_aout );
350 vlc_object_release( p_aout );
353 void Equalizer::setValues( char *psz_bands, float f_preamp )
358 for( int i = 0; i < 10; i++ )
361 float f = strtof( p, &p );
362 int i_val= (int)( ( f + 20 ) * 10 );
363 bands[i]->setValue( i_val );
364 sprintf( psz_val, "% 5.1f", f );
365 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
367 if( p == NULL ) break;
373 int i_val = (int)( ( f_preamp + 20 ) * 10 );
374 sprintf( psz_val, "%.1f", f_preamp );
375 ui.preampSlider->setValue( i_val );
376 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
379 void Equalizer::setPreset( int preset )
381 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
382 VLC_OBJECT_AOUT, FIND_ANYWHERE);
384 char psz_values[102]; memset( psz_values, 0, 102 );
385 for( int i = 0 ; i< 10 ;i++ )
386 sprintf( psz_values, "%s %.1f", psz_values,
387 eqz_preset_10b[preset]->f_amp[i] );
391 delCallbacks( p_aout );
392 var_SetString( p_aout, "equalizer-bands", psz_values );
393 var_SetFloat( p_aout, "equalizer-preamp",
394 eqz_preset_10b[preset]->f_preamp );
395 addCallbacks( p_aout );
396 vlc_object_release( p_aout );
398 config_PutPsz( p_intf, "equalizer-bands", psz_values );
399 config_PutFloat( p_intf, "equalizer-preamp",
400 eqz_preset_10b[preset]->f_preamp );
402 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
405 void Equalizer::delCallbacks( aout_instance_t *p_aout )
407 // var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
408 // var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
411 void Equalizer::addCallbacks( aout_instance_t *p_aout )
413 // var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
414 // var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
418 /**********************************************************************
419 * Video filters / Adjust
420 **********************************************************************/
422 /**********************************************************************
424 **********************************************************************/
426 /**********************************************************************
427 * Extended playbak controls
428 **********************************************************************/