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>
41 class ConfClickHandler : public QObject
44 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject (_e) {
45 e = _e; p_intf = _p_intf;
47 virtual ~ConfClickHandler() {}
48 bool eventFilter( QObject *obj, QEvent *evt )
50 if( evt->type() == QEvent::MouseButtonPress )
59 intf_thread_t *p_intf;
62 #define SETUP_VFILTER( widget, conf, tooltip, labtooltip ) \
63 ui.widget##Check->setToolTip( tooltip ); \
65 ui.widget##Label->setToolTip( labtooltip ); \
66 ui.widget##Label->setPixmap( QPixmap(":/pixmaps/go-next.png") ); \
67 ui.widget##Label->installEventFilter(h); \
69 CONNECT( ui.widget##Check, clicked(), this, updateFilters() ); \
71 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QWidget *_parent ) :
72 QWidget( _parent ) , p_intf( _p_intf )
74 ConfClickHandler* h = new ConfClickHandler( p_intf, this );
78 SETUP_VFILTER( clone, true, qtr(I_CLONE_TIP),
79 qtr("Configure the clone filter") );
80 SETUP_VFILTER( magnify, false, qtr(I_MAGNIFY_TIP),
81 qtr("Configure the magnification effect"));
82 SETUP_VFILTER( wave, false, qtr(I_WAVE_TIP),
83 qtr("Configure the waves effect"));
84 SETUP_VFILTER( ripple, false, qtr(I_RIPPLE_TIP),
85 qtr("Configure the \"water\" effect"));
86 SETUP_VFILTER( invert, false, qtr(I_INVERT_TIP),
87 qtr("Configure the color inversion effect"));
88 SETUP_VFILTER( puzzle, true, qtr(I_PUZZLE_TIP),
89 qtr("Configure the puzzle effect"));
90 SETUP_VFILTER( wall, true, qtr(I_WALL_TIP),
91 qtr("Configure the wall filter") );
92 SETUP_VFILTER( gradient, true, qtr(I_GRADIENT_TIP),
93 qtr("Configure the \"gradient\" effect"));
94 SETUP_VFILTER( colorthres, true, qtr(I_COLORTHRES_TIP),
95 qtr("Configure the color detection effect"));
102 static void ChangeVFiltersString( intf_thread_t *p_intf,
103 char *psz_name, vlc_bool_t b_add )
105 vout_thread_t *p_vout;
106 char *psz_parser, *psz_string;
108 psz_string = config_GetPsz( p_intf, "video-filter" );
110 if( !psz_string ) psz_string = strdup("");
112 psz_parser = strstr( psz_string, psz_name );
118 psz_parser = psz_string;
119 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
120 psz_string, psz_name );
132 if( *(psz_parser + strlen(psz_name)) == ':' )
134 memmove( psz_parser, psz_parser + strlen(psz_name) + 1,
135 strlen(psz_parser + strlen(psz_name) + 1 ) + 1 );
142 /* Remove trailing : : */
143 if( strlen( psz_string ) > 0 &&
144 *( psz_string + strlen( psz_string ) -1 ) == ':' )
146 *( psz_string + strlen( psz_string ) -1 ) = '\0';
155 /* Vout is not kept, so put that in the config */
156 config_PutPsz( p_intf, "video-filter", psz_string );
158 /* Try to set on the fly */
159 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
163 var_SetString( p_vout, "video-filter", psz_string );
164 vlc_object_release( p_vout );
170 void ExtVideo::updateFilters()
172 QCheckBox* filter = qobject_cast<QCheckBox*>(sender());
173 QString module = filter->objectName().replace("Check", "");
175 ChangeVFiltersString( p_intf, qtu(module), filter->isChecked() );
178 void ExtVideo::gotoConf( QObject* src )
180 #define SHOWCONF(module) \
181 if( src->objectName().contains(module) ) \
183 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
187 SHOWCONF( "magnify" );
189 SHOWCONF( "ripple" );
190 SHOWCONF( "invert" );
191 SHOWCONF( "puzzle" );
193 SHOWCONF( "gradient" );
194 SHOWCONF( "colorthres" )
197 /**********************************************************************
199 **********************************************************************/
201 static const QString band_frequencies[] =
203 " 60Hz ", " 170 Hz " , " 310 Hz ", " 600 Hz ", " 1 kHz ",
204 " 3 kHz " , " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
207 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
208 QWidget( _parent ) , p_intf( _p_intf )
210 QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
211 smallFont.setPointSize( smallFont.pointSize() - 3 );
215 ui.preampLabel->setFont( smallFont );
216 ui.preampSlider->setMaximum( 400 );
217 for( int i = 0 ; i < NB_PRESETS ; i ++ )
219 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
222 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
224 BUTTONACT( ui.enableCheck, enable() );
225 BUTTONACT( ui.eq2PassCheck, set2Pass() );
227 CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
229 QGridLayout *grid = new QGridLayout( ui.frame );
230 grid->setMargin( 0 );
231 for( int i = 0 ; i < BANDS ; i++ )
233 bands[i] = new QSlider( Qt::Vertical );
234 bands[i]->setMaximum( 400 );
235 bands[i]->setValue( 200 );
236 CONNECT( bands[i], valueChanged(int), this, setBand() );
237 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
238 band_texts[i]->setFont( smallFont );
239 grid->addWidget( bands[i], 0, i );
240 grid->addWidget( band_texts[i], 1, i );
243 /* Write down initial values */
244 aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
245 VLC_OBJECT_AOUT, FIND_ANYWHERE);
251 psz_af = var_GetString( p_aout, "audio-filter" );
252 if( var_GetBool( p_aout, "equalizer-2pass" ) )
253 ui.eq2PassCheck->setChecked( true );
254 psz_bands = var_GetString( p_aout, "equalizer-bands" );
255 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
256 vlc_object_release( p_aout );
260 psz_af = config_GetPsz( p_intf, "audio-filter" );
261 if( config_GetInt( p_intf, "equalizer-2pass" ) )
262 ui.eq2PassCheck->setChecked( true );
263 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
264 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
266 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
267 ui.enableCheck->setChecked( true );
268 enable( ui.enableCheck->isChecked() );
270 setValues( psz_bands, f_preamp );
273 Equalizer::~Equalizer()
277 void Equalizer::enable()
279 bool en = ui.enableCheck->isChecked();
280 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
281 en ? VLC_TRUE : VLC_FALSE );
285 void Equalizer::enable( bool en )
287 ui.eq2PassCheck->setEnabled( en );
288 ui.preampLabel->setEnabled( en );
289 ui.preampSlider->setEnabled( en );
290 for( int i = 0 ; i< BANDS; i++ )
292 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
296 void Equalizer::set2Pass()
298 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
299 VLC_OBJECT_AOUT, FIND_ANYWHERE);
300 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
303 config_PutInt( p_intf, "equalizer-2pass", b_2p );
306 var_SetBool( p_aout, "equalizer-2pass", b_2p );
307 config_PutInt( p_intf, "equalizer-2pass", b_2p );
308 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
310 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
312 vlc_object_release( p_aout );
316 void Equalizer::setPreamp()
318 float f= (float)( ui.preampSlider->value() ) /10 - 20;
320 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
321 VLC_OBJECT_AOUT, FIND_ANYWHERE);
323 sprintf( psz_val, "%.1f", f );
324 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
327 delCallbacks( p_aout );
328 var_SetFloat( p_aout, "equalizer-preamp", f );
329 addCallbacks( p_aout );
330 vlc_object_release( p_aout );
332 config_PutFloat( p_intf, "equalizer-preamp", f );
335 void Equalizer::setBand()
337 char psz_values[102]; memset( psz_values, 0, 102 );
339 /**\todo smoothing */
341 for( int i = 0 ; i< BANDS ; i++ )
344 float f_val = (float)( bands[i]->value() ) / 10 - 20 ;
345 sprintf( psz_values, "%s %f", psz_values, f_val );
346 sprintf( psz_val, "% 5.1f", f_val );
347 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
349 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
350 VLC_OBJECT_AOUT, FIND_ANYWHERE);
353 delCallbacks( p_aout );
354 var_SetString( p_aout, "equalizer-bands", psz_values );
355 addCallbacks( p_aout );
356 vlc_object_release( p_aout );
359 void Equalizer::setValues( char *psz_bands, float f_preamp )
364 for( int i = 0; i < 10; i++ )
367 float f = strtof( p, &p );
368 int i_val= (int)( ( f + 20 ) * 10 );
369 bands[i]->setValue( i_val );
370 sprintf( psz_val, "% 5.1f", f );
371 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
373 if( p == NULL || *p == '\0' ) break;
375 if( *p == '\0' ) break;
379 int i_val = (int)( ( f_preamp + 20 ) * 10 );
380 sprintf( psz_val, "%.1f", f_preamp );
381 ui.preampSlider->setValue( i_val );
382 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
385 void Equalizer::setPreset( int preset )
387 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
388 VLC_OBJECT_AOUT, FIND_ANYWHERE);
390 char psz_values[102]; memset( psz_values, 0, 102 );
391 for( int i = 0 ; i< 10 ;i++ )
392 sprintf( psz_values, "%s %.1f", psz_values,
393 eqz_preset_10b[preset]->f_amp[i] );
397 delCallbacks( p_aout );
398 var_SetString( p_aout, "equalizer-bands", psz_values );
399 var_SetFloat( p_aout, "equalizer-preamp",
400 eqz_preset_10b[preset]->f_preamp );
401 addCallbacks( p_aout );
402 vlc_object_release( p_aout );
404 config_PutPsz( p_intf, "equalizer-bands", psz_values );
405 config_PutFloat( p_intf, "equalizer-preamp",
406 eqz_preset_10b[preset]->f_preamp );
408 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
411 void Equalizer::delCallbacks( aout_instance_t *p_aout )
413 // var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
414 // var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
417 void Equalizer::addCallbacks( aout_instance_t *p_aout )
419 // var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
420 // var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
424 /**********************************************************************
425 * Video filters / Adjust
426 **********************************************************************/
428 /**********************************************************************
430 **********************************************************************/
432 /**********************************************************************
433 * Extended playbak controls
434 **********************************************************************/