1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea .t videolan d@t org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <QGridLayout>
30 #include <QSignalMapper>
32 #include "components/extended_panels.hpp"
33 #include "dialogs/preferences.hpp"
34 #include "dialogs_provider.hpp"
37 #include "../../audio_filter/equalizer_presets.h"
39 #include <vlc_intf_strings.h>
47 class ConfClickHandler : public QObject
50 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject (_e) {
51 e = _e; p_intf = _p_intf;
53 virtual ~ConfClickHandler() {}
54 bool eventFilter( QObject *obj, QEvent *evt )
56 if( evt->type() == QEvent::MouseButtonPress )
65 intf_thread_t *p_intf;
69 QString ModuleFromWidgetName( QObject *obj )
71 return obj->objectName().replace("Enable","");
74 QString OptionFromWidgetName( QObject *obj )
77 QString option = obj->objectName().replace( "Slider", "" )
78 .replace( "Combo" , "" )
79 .replace( "Dial" , "" )
80 .replace( "Check" , "" )
81 .replace( "Spin" , "" )
82 .replace( "Text" , "" );
83 for( char a = 'A'; a <= 'Z'; a++ )
85 option = option.replace( QString( a ),
86 QString( '-' ) + QString( a + 'a' - 'A' ) );
91 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QWidget *_parent ) :
92 QWidget( _parent ) , p_intf( _p_intf )
96 #define SETUP_VFILTER( widget ) \
98 vlc_object_t *p_obj = (vlc_object_t *) \
99 vlc_object_find_name( p_intf->p_libvlc, \
102 QCheckBox *checkbox = qobject_cast<QCheckBox*>(ui.widget##Enable); \
103 QGroupBox *groupbox = qobject_cast<QGroupBox*>(ui.widget##Enable); \
106 vlc_object_release( p_obj ); \
107 if( checkbox ) checkbox->setCheckState( Qt::Checked ); \
108 else groupbox->setChecked( true ); \
112 if( checkbox ) checkbox->setCheckState( Qt::Unchecked ); \
113 else groupbox->setChecked( false ); \
116 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
117 #define SETUP_VFILTER_OPTION( widget, signal ) \
118 initComboBoxItems( ui.widget ); \
119 setWidgetValue( ui.widget ); \
120 CONNECT( ui.widget, signal, this, updateFilterOptions() );
122 SETUP_VFILTER( adjust )
123 SETUP_VFILTER_OPTION( hueSlider, valueChanged(int) )
124 SETUP_VFILTER_OPTION( contrastSlider, valueChanged(int) )
125 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged(int) )
126 SETUP_VFILTER_OPTION( saturationSlider, valueChanged(int) )
127 SETUP_VFILTER_OPTION( gammaSlider, valueChanged(int) )
128 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged(int) )
130 SETUP_VFILTER( extract )
131 SETUP_VFILTER_OPTION( extractComponentText, textChanged(QString) )
133 SETUP_VFILTER( colorthres )
134 SETUP_VFILTER_OPTION( colorthresColorText, textChanged(QString) )
135 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged(int) )
136 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged(int) )
138 SETUP_VFILTER( invert )
140 SETUP_VFILTER( gradient )
141 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged(QString) )
142 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged(int) )
143 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged(int) )
145 SETUP_VFILTER( motionblur )
146 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged(int) )
148 SETUP_VFILTER( motiondetect )
150 SETUP_VFILTER( noise )
152 SETUP_VFILTER( psychedelic )
154 SETUP_VFILTER( sharpen )
155 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged(int) )
157 SETUP_VFILTER( ripple )
159 SETUP_VFILTER( wave )
161 SETUP_VFILTER( transform )
162 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged(QString) )
164 SETUP_VFILTER( rotate )
165 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged(int) )
166 ui.rotateAngleDial->setWrapping( true );
167 ui.rotateAngleDial->setNotchesVisible( true );
169 SETUP_VFILTER( puzzle )
170 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged(int) )
171 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged(int) )
172 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged(int) )
174 SETUP_VFILTER( magnify )
176 SETUP_VFILTER( clone )
177 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged(int) )
179 SETUP_VFILTER( wall )
180 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged(int) )
181 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged(int) )
183 SETUP_VFILTER( erase )
184 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
185 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged(int) )
186 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged(int) )
188 SETUP_VFILTER( marq )
189 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged(QString) )
190 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged(QString) )
192 SETUP_VFILTER( logo )
193 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
194 SETUP_VFILTER_OPTION( logoYSpin, valueChanged(int) )
195 SETUP_VFILTER_OPTION( logoXSpin, valueChanged(int) )
196 SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged(int) )
199 #undef SETUP_VFILTER_OPTION
202 ExtVideo::~ExtVideo()
206 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
208 vout_thread_t *p_vout;
209 char *psz_parser, *psz_string;
210 const char *psz_filter_type;
212 /* Please leave p_libvlc_global. This is where cached modules are
213 * stored. We're not trying to find a module instance. */
214 module_t *p_obj = module_FindName( p_intf, psz_name );
217 msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
221 if( module_IsCapable( p_obj, "video filter2" ) )
223 psz_filter_type = "video-filter";
225 else if( module_IsCapable( p_obj, "video filter" ) )
227 psz_filter_type = "vout-filter";
229 else if( module_IsCapable( p_obj, "sub filter" ) )
231 psz_filter_type = "sub-filter";
235 vlc_object_release( p_obj );
236 msg_Err( p_intf, "Unknown video filter type." );
239 vlc_object_release( p_obj );
241 psz_string = config_GetPsz( p_intf, psz_filter_type );
243 if( !psz_string ) psz_string = strdup("");
245 psz_parser = strstr( psz_string, psz_name );
251 psz_parser = psz_string;
252 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
253 psz_string, psz_name );
265 if( *(psz_parser + strlen(psz_name)) == ':' )
267 memmove( psz_parser, psz_parser + strlen(psz_name) + 1,
268 strlen(psz_parser + strlen(psz_name) + 1 ) + 1 );
275 /* Remove trailing : : */
276 if( strlen( psz_string ) > 0 &&
277 *( psz_string + strlen( psz_string ) -1 ) == ':' )
279 *( psz_string + strlen( psz_string ) -1 ) = '\0';
288 /* Vout is not kept, so put that in the config */
289 config_PutPsz( p_intf, psz_filter_type, psz_string );
290 if( !strcmp( psz_filter_type, "video-filter" ) )
291 ui.videoFilterText->setText( psz_string );
292 else if( !strcmp( psz_filter_type, "vout-filter" ) )
293 ui.voutFilterText->setText( psz_string );
294 else if( !strcmp( psz_filter_type, "sub-filter" ) )
295 ui.subpictureFilterText->setText( psz_string );
297 /* Try to set on the fly */
298 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
302 if( !strcmp( psz_filter_type, "sub-filter" ) )
303 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
305 var_SetString( p_vout, psz_filter_type, psz_string );
306 vlc_object_release( p_vout );
312 void ExtVideo::updateFilters()
314 QString module = ModuleFromWidgetName( sender() );
315 //std::cout << "Module name: " << module.toStdString() << std::endl;
317 QCheckBox *checkbox = qobject_cast<QCheckBox*>(sender());
318 QGroupBox *groupbox = qobject_cast<QGroupBox*>(sender());
320 ChangeVFiltersString( qtu(module),
321 checkbox ? checkbox->isChecked()
322 : groupbox->isChecked() );
325 void ExtVideo::initComboBoxItems( QObject *widget )
327 QComboBox *combobox = qobject_cast<QComboBox*>(widget);
328 if( !combobox ) return;
329 QString option = OptionFromWidgetName( widget );
330 module_config_t *p_item = config_FindConfig( VLC_OBJECT(p_intf),
331 option.toStdString().c_str() );
334 int i_type = p_item->i_type & CONFIG_ITEM;
335 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
337 if( i_type == CONFIG_ITEM_INTEGER
338 || i_type == CONFIG_ITEM_BOOL )
339 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->pi_list[i_index] );
340 else if( i_type == CONFIG_ITEM_STRING )
341 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->ppsz_list[i_index] );
346 msg_Err( p_intf, "Couldn't find option \"%s\".",
347 option.toStdString().c_str() );
351 void ExtVideo::setWidgetValue( QObject *widget )
353 QString module = ModuleFromWidgetName( widget->parent() );
354 //std::cout << "Module name: " << module.toStdString() << std::endl;
355 QString option = OptionFromWidgetName( widget );
356 //std::cout << "Option name: " << option.toStdString() << std::endl;
358 vlc_object_t *p_obj = (vlc_object_t *)
359 vlc_object_find_name( p_intf->p_libvlc,
360 module.toStdString().c_str(),
368 "Module instance %s not found, looking in config values.",
369 module.toStdString().c_str() );
370 i_type = config_GetType( p_intf, option.toStdString().c_str() ) & 0xf0;
373 case VLC_VAR_INTEGER:
375 val.i_int = config_GetInt( p_intf, option.toStdString().c_str() );
378 val.f_float = config_GetFloat( p_intf, option.toStdString().c_str() );
381 val.psz_string = config_GetPsz( p_intf, option.toStdString().c_str() );
387 i_type = var_Type( p_obj, option.toStdString().c_str() ) & 0xf0;
388 var_Get( p_obj, option.toStdString().c_str(), &val );
389 vlc_object_release( p_obj );
392 /* Try to cast to all the widgets we're likely to encounter. Only
393 * one of the casts is expected to work. */
394 QSlider *slider = qobject_cast<QSlider*> (widget);
395 QCheckBox *checkbox = qobject_cast<QCheckBox*> (widget);
396 QSpinBox *spinbox = qobject_cast<QSpinBox*> (widget);
397 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(widget);
398 QDial *dial = qobject_cast<QDial*> (widget);
399 QLineEdit *lineedit = qobject_cast<QLineEdit*> (widget);
400 QComboBox *combobox = qobject_cast<QComboBox*> (widget);
402 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
405 if( slider ) slider->setValue( val.i_int );
406 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
408 else if( spinbox ) spinbox->setValue( val.i_int );
409 else if( dial ) dial->setValue( (540-val.i_int)%360 );
413 sprintf( str, "%06X", val.i_int );
414 lineedit->setText( str );
416 else if( combobox ) combobox->setCurrentIndex(
417 combobox->findData( val.i_int ) );
418 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
420 else if( i_type == VLC_VAR_FLOAT )
423 if( slider ) slider->setValue( (int)(val.f_float*(double)slider->tickInterval())); /* hack alert! */
424 else if( doublespinbox ) doublespinbox->setValue(val.f_float);
425 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
427 else if( i_type == VLC_VAR_STRING )
429 if( lineedit ) lineedit->setText( qfu(val.psz_string) );
430 else if( combobox ) combobox->setCurrentIndex(
431 combobox->findData( qfu( val.psz_string ) ) );
432 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
433 free( val.psz_string );
437 "Module %s's %s variable is of an unsupported type (%d)",
438 module.toStdString().c_str(),
439 option.toStdString().c_str(),
443 void ExtVideo::updateFilterOptions()
445 QString module = ModuleFromWidgetName( sender()->parent() );
446 //std::cout << "Module name: " << module.toStdString() << std::endl;
447 QString option = OptionFromWidgetName( sender() );
448 //std::cout << "Option name: " << option.toStdString() << std::endl;
450 vlc_object_t *p_obj = (vlc_object_t *)
451 vlc_object_find_name( p_intf->p_libvlc,
452 module.toStdString().c_str(),
456 msg_Err( p_intf, "Module %s not found.", module.toStdString().c_str() );
460 int i_type = var_Type( p_obj, option.toStdString().c_str() );
461 bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
464 msg_Warn( p_intf, "Module %s's %s variable isn't a command. You'll need to restart the filter to take change into account.",
465 module.toStdString().c_str(),
466 option.toStdString().c_str() );
467 /* FIXME: restart automatically somewhere near the end of this function */
470 /* Try to cast to all the widgets we're likely to encounter. Only
471 * one of the casts is expected to work. */
472 QSlider *slider = qobject_cast<QSlider*> (sender());
473 QCheckBox *checkbox = qobject_cast<QCheckBox*> (sender());
474 QSpinBox *spinbox = qobject_cast<QSpinBox*> (sender());
475 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(sender());
476 QDial *dial = qobject_cast<QDial*> (sender());
477 QLineEdit *lineedit = qobject_cast<QLineEdit*> (sender());
478 QComboBox *combobox = qobject_cast<QComboBox*> (sender());
481 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
484 if( slider ) i_int = slider->value();
485 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
486 else if( spinbox ) i_int = spinbox->value();
487 else if( dial ) i_int = (540-dial->value())%360;
488 else if( lineedit ) i_int = lineedit->text().toInt(NULL,16);
489 else if( combobox ) i_int = combobox->itemData(combobox->currentIndex()).toInt();
490 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
491 config_PutInt( p_intf, option.toStdString().c_str(), i_int );
494 if( i_type == VLC_VAR_INTEGER )
495 var_SetInteger( p_obj, option.toStdString().c_str(), i_int );
497 var_SetBool( p_obj, option.toStdString().c_str(), i_int );
500 else if( i_type == VLC_VAR_FLOAT )
503 if( slider ) f_float = (double)slider->value()
504 / (double)slider->tickInterval(); /* hack alert! */
505 else if( doublespinbox ) f_float = doublespinbox->value();
506 else if( lineedit ) f_float = lineedit->text().toDouble();
507 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
508 config_PutFloat( p_intf, option.toStdString().c_str(), f_float );
510 var_SetFloat( p_obj, option.toStdString().c_str(), f_float );
512 else if( i_type == VLC_VAR_STRING )
514 char *psz_string = NULL;
515 if( lineedit ) psz_string = strdup(qtu(lineedit->text()));
516 else if( combobox ) psz_string = strdup(qtu(combobox->itemData(
517 combobox->currentIndex()).toString()));
518 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
519 config_PutPsz( p_intf, option.toStdString().c_str(), psz_string );
521 var_SetString( p_obj, option.toStdString().c_str(), psz_string );
526 "Module %s's %s variable is of an unsupported type (%d)",
527 module.toStdString().c_str(),
528 option.toStdString().c_str(),
531 vlc_object_release( p_obj );
535 void ExtVideo::gotoConf( QObject* src )
537 #define SHOWCONF(module) \
538 if( src->objectName().contains(module) ) \
540 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
544 SHOWCONF( "magnify" );
546 SHOWCONF( "ripple" );
547 SHOWCONF( "invert" );
548 SHOWCONF( "puzzle" );
550 SHOWCONF( "gradient" );
551 SHOWCONF( "colorthres" )
555 /**********************************************************************
557 **********************************************************************/
559 static const QString band_frequencies[] =
561 " 60Hz ", " 170 Hz " , " 310 Hz ", " 600 Hz ", " 1 kHz ",
562 " 3 kHz " , " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
565 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
566 QWidget( _parent ) , p_intf( _p_intf )
568 QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
569 smallFont.setPointSize( smallFont.pointSize() - 3 );
573 ui.preampLabel->setFont( smallFont );
574 ui.preampSlider->setMaximum( 400 );
575 for( int i = 0 ; i < NB_PRESETS ; i ++ )
577 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
580 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
582 BUTTONACT( ui.enableCheck, enable() );
583 BUTTONACT( ui.eq2PassCheck, set2Pass() );
585 CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
587 QGridLayout *grid = new QGridLayout( ui.frame );
588 grid->setMargin( 0 );
589 for( int i = 0 ; i < BANDS ; i++ )
591 bands[i] = new QSlider( Qt::Vertical );
592 bands[i]->setMaximum( 400 );
593 bands[i]->setValue( 200 );
594 CONNECT( bands[i], valueChanged(int), this, setBand() );
595 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
596 band_texts[i]->setFont( smallFont );
597 grid->addWidget( bands[i], 0, i );
598 grid->addWidget( band_texts[i], 1, i );
601 /* Write down initial values */
602 aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
603 VLC_OBJECT_AOUT, FIND_ANYWHERE);
609 psz_af = var_GetString( p_aout, "audio-filter" );
610 if( var_GetBool( p_aout, "equalizer-2pass" ) )
611 ui.eq2PassCheck->setChecked( true );
612 psz_bands = var_GetString( p_aout, "equalizer-bands" );
613 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
614 vlc_object_release( p_aout );
618 psz_af = config_GetPsz( p_intf, "audio-filter" );
619 if( config_GetInt( p_intf, "equalizer-2pass" ) )
620 ui.eq2PassCheck->setChecked( true );
621 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
622 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
624 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
625 ui.enableCheck->setChecked( true );
626 enable( ui.enableCheck->isChecked() );
628 setValues( psz_bands, f_preamp );
631 Equalizer::~Equalizer()
635 void Equalizer::enable()
637 bool en = ui.enableCheck->isChecked();
638 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
639 en ? VLC_TRUE : VLC_FALSE );
640 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
641 // en ? VLC_TRUE : VLC_FALSE );
642 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
643 // en ? VLC_TRUE : VLC_FALSE );
647 void Equalizer::enable( bool en )
649 ui.eq2PassCheck->setEnabled( en );
650 ui.preampLabel->setEnabled( en );
651 ui.preampSlider->setEnabled( en );
652 for( int i = 0 ; i< BANDS; i++ )
654 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
658 void Equalizer::set2Pass()
660 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
661 VLC_OBJECT_AOUT, FIND_ANYWHERE);
662 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
665 config_PutInt( p_intf, "equalizer-2pass", b_2p );
668 var_SetBool( p_aout, "equalizer-2pass", b_2p );
669 config_PutInt( p_intf, "equalizer-2pass", b_2p );
670 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
672 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
674 vlc_object_release( p_aout );
678 void Equalizer::setPreamp()
680 float f= (float)( ui.preampSlider->value() ) /10 - 20;
682 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
683 VLC_OBJECT_AOUT, FIND_ANYWHERE);
685 sprintf( psz_val, "%.1f", f );
686 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
689 delCallbacks( p_aout );
690 var_SetFloat( p_aout, "equalizer-preamp", f );
691 addCallbacks( p_aout );
692 vlc_object_release( p_aout );
694 config_PutFloat( p_intf, "equalizer-preamp", f );
697 void Equalizer::setBand()
699 char psz_values[102]; memset( psz_values, 0, 102 );
701 /**\todo smoothing */
703 for( int i = 0 ; i< BANDS ; i++ )
706 float f_val = (float)( bands[i]->value() ) / 10 - 20 ;
707 sprintf( psz_values, "%s %f", psz_values, f_val );
708 sprintf( psz_val, "% 5.1f", f_val );
709 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
711 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
712 VLC_OBJECT_AOUT, FIND_ANYWHERE);
715 delCallbacks( p_aout );
716 var_SetString( p_aout, "equalizer-bands", psz_values );
717 addCallbacks( p_aout );
718 vlc_object_release( p_aout );
721 void Equalizer::setValues( char *psz_bands, float f_preamp )
726 for( int i = 0; i < 10; i++ )
729 float f = strtof( p, &p );
730 int i_val= (int)( ( f + 20 ) * 10 );
731 bands[i]->setValue( i_val );
732 sprintf( psz_val, "% 5.1f", f );
733 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
735 if( p == NULL || *p == '\0' ) break;
737 if( *p == '\0' ) break;
741 int i_val = (int)( ( f_preamp + 20 ) * 10 );
742 sprintf( psz_val, "%.1f", f_preamp );
743 ui.preampSlider->setValue( i_val );
744 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
747 void Equalizer::setPreset( int preset )
749 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
750 VLC_OBJECT_AOUT, FIND_ANYWHERE);
752 char psz_values[102]; memset( psz_values, 0, 102 );
753 for( int i = 0 ; i< 10 ;i++ )
754 sprintf( psz_values, "%s %.1f", psz_values,
755 eqz_preset_10b[preset]->f_amp[i] );
759 delCallbacks( p_aout );
760 var_SetString( p_aout, "equalizer-bands", psz_values );
761 var_SetFloat( p_aout, "equalizer-preamp",
762 eqz_preset_10b[preset]->f_preamp );
763 addCallbacks( p_aout );
764 vlc_object_release( p_aout );
766 config_PutPsz( p_intf, "equalizer-bands", psz_values );
767 config_PutFloat( p_intf, "equalizer-preamp",
768 eqz_preset_10b[preset]->f_preamp );
770 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
773 void Equalizer::delCallbacks( aout_instance_t *p_aout )
775 // var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
776 // var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
779 void Equalizer::addCallbacks( aout_instance_t *p_aout )
781 // var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
782 // var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
786 /**********************************************************************
788 **********************************************************************/
789 static const char *psz_control_names[] =
791 "Roomsize", "Width" , "Wet", "Dry", "Damp"
793 static const QString control_names[] =
795 "Roomsize", "Width" , "Wet", "Dry", "Damp"
798 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
799 QWidget( _parent ) , p_intf( _p_intf )
801 QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
802 smallFont.setPointSize( smallFont.pointSize() - 3 );
806 QGridLayout *grid = new QGridLayout( ui.frame );
807 grid->setMargin( 0 );
809 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
811 spatCtrl[i] = new QSlider( Qt::Vertical );
814 spatCtrl[i]->setMaximum( 10 );
815 spatCtrl[i]->setValue( 2 );
819 spatCtrl[i]->setMaximum( 10 );
820 spatCtrl[i]->setValue( 0 );
821 spatCtrl[i]->setMinimum( -10 );
823 oldControlVars[i] = spatCtrl[i]->value();
824 CONNECT( spatCtrl[i], valueChanged(int), this, setInitValues() );
825 ctrl_texts[i] = new QLabel( control_names[i] + "\n" );
826 ctrl_texts[i]->setFont( smallFont );
827 ctrl_readout[i] = new QLabel( "" );
828 ctrl_readout[i]->setFont( smallFont );
829 grid->addWidget( spatCtrl[i], 0, i );
830 grid->addWidget( ctrl_readout[i],1,i);
831 grid->addWidget( ctrl_texts[i], 2, i );
834 BUTTONACT( ui.enableCheck, enable() );
836 /* Write down initial values */
837 aout_instance_t *p_aout = (aout_instance_t *)
838 vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
843 psz_af = var_GetString( p_aout, "audio-filter" );
844 for( int i = 0; i < NUM_SP_CTRL ; i++)
846 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
848 vlc_object_release( p_aout );
852 psz_af = config_GetPsz( p_aout, "audio-filter" );
853 for( int i = 0; i < NUM_SP_CTRL ; i++)
855 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
858 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
859 ui.enableCheck->setChecked( true );
860 enable( ui.enableCheck->isChecked() );
861 setValues( controlVars );
865 Spatializer::~Spatializer()
869 void Spatializer::enable()
871 bool en = ui.enableCheck->isChecked();
872 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
873 en ? VLC_TRUE : VLC_FALSE );
877 void Spatializer::enable( bool en )
879 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
881 spatCtrl[i]->setEnabled( en );
882 ctrl_texts[i]->setEnabled( en );
883 ctrl_readout[i]->setEnabled( en );
886 void Spatializer::setInitValues()
888 setValues(controlVars);
891 void Spatializer::setValues(float *controlVars)
895 aout_instance_t *p_aout= (aout_instance_t *)
896 vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
898 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
900 float f= (float)( spatCtrl[i]->value() );
901 sprintf( psz_val, "%.1f", f );
902 ctrl_readout[i]->setText( psz_val );
906 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
908 if( oldControlVars[i] != spatCtrl[i]->value() )
910 var_SetFloat( p_aout, psz_control_names[i],
911 (float)spatCtrl[i]->value() );
912 config_PutFloat( p_intf, psz_control_names[i],
913 (float) spatCtrl[i]->value());
914 oldControlVars[i] = (float) spatCtrl[i]->value();
917 vlc_object_release( p_aout );
919 // printf("set callback values %s %s %d\n", __FILE__,__func__,__LINE__);
922 void Spatializer::delCallbacks( aout_instance_t *p_aout )
924 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
925 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
928 void Spatializer::addCallbacks( aout_instance_t *p_aout )
930 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
931 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
934 /**********************************************************************
935 * Video filters / Adjust
936 **********************************************************************/
938 /**********************************************************************
940 **********************************************************************/
942 /**********************************************************************
943 * Extended playbak controls
944 **********************************************************************/