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 *****************************************************************************/
32 #include <QGridLayout>
33 #include <QSignalMapper>
36 #include "components/extended_panels.hpp"
37 #include "dialogs/preferences.hpp"
38 #include "dialogs_provider.hpp"
41 #include "../../audio_filter/equalizer_presets.h"
43 #include <vlc_intf_strings.h>
51 class ConfClickHandler : public QObject
54 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
55 e = _e; p_intf = _p_intf;
57 virtual ~ConfClickHandler() {}
58 bool eventFilter( QObject *obj, QEvent *evt )
60 if( evt->type() == QEvent::MouseButtonPress )
69 intf_thread_t *p_intf;
73 QString ModuleFromWidgetName( QObject *obj )
75 return obj->objectName().replace( "Enable","" );
78 QString OptionFromWidgetName( QObject *obj )
81 QString option = obj->objectName().replace( "Slider", "" )
82 .replace( "Combo" , "" )
83 .replace( "Dial" , "" )
84 .replace( "Check" , "" )
85 .replace( "Spin" , "" )
86 .replace( "Text" , "" );
87 for( char a = 'A'; a <= 'Z'; a++ )
89 option = option.replace( QString( a ),
90 QString( '-' ) + QString( a + 'a' - 'A' ) );
95 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
98 ui.setupUi( _parent );
100 #define SETUP_VFILTER( widget ) \
102 vlc_object_t *p_obj = ( vlc_object_t * ) \
103 vlc_object_find_name( p_intf->p_libvlc, \
106 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
107 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
110 vlc_object_release( p_obj ); \
111 if( checkbox ) checkbox->setChecked( true ); \
112 else groupbox->setChecked( true ); \
116 if( checkbox ) checkbox->setChecked( false ); \
117 else groupbox->setChecked( false ); \
120 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
121 #define SETUP_VFILTER_OPTION( widget, signal ) \
122 initComboBoxItems( ui.widget ); \
123 setWidgetValue( ui.widget ); \
124 CONNECT( ui.widget, signal, this, updateFilterOptions() );
126 SETUP_VFILTER( adjust )
127 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
128 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
129 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
130 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
131 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
132 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
134 SETUP_VFILTER( extract )
135 SETUP_VFILTER_OPTION( extractComponentText, textChanged( QString ) )
137 SETUP_VFILTER( colorthres )
138 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( QString ) )
139 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
140 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
142 SETUP_VFILTER( invert )
144 SETUP_VFILTER( gradient )
145 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
146 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
147 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
149 SETUP_VFILTER( motionblur )
150 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
152 SETUP_VFILTER( motiondetect )
154 SETUP_VFILTER( noise )
156 SETUP_VFILTER( psychedelic )
158 SETUP_VFILTER( sharpen )
159 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
161 SETUP_VFILTER( ripple )
163 SETUP_VFILTER( wave )
165 SETUP_VFILTER( transform )
166 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
168 SETUP_VFILTER( rotate )
169 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
170 ui.rotateAngleDial->setWrapping( true );
171 ui.rotateAngleDial->setNotchesVisible( true );
173 SETUP_VFILTER( puzzle )
174 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
175 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
176 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
178 SETUP_VFILTER( magnify )
180 SETUP_VFILTER( clone )
181 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
183 SETUP_VFILTER( wall )
184 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
185 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
187 SETUP_VFILTER( erase )
188 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
189 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
190 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
192 SETUP_VFILTER( marq )
193 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( QString ) )
194 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
196 SETUP_VFILTER( logo )
197 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
198 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
199 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
200 SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
203 #undef SETUP_VFILTER_OPTION
206 ExtVideo::~ExtVideo()
210 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
212 vout_thread_t *p_vout;
213 char *psz_parser, *psz_string;
214 const char *psz_filter_type;
216 /* Please leave p_libvlc_global. This is where cached modules are
217 * stored. We're not trying to find a module instance. */
218 module_t *p_obj = module_Find( p_intf, psz_name );
221 msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
225 if( module_IsCapable( p_obj, "video filter2" ) )
227 psz_filter_type = "video-filter";
229 else if( module_IsCapable( p_obj, "video filter" ) )
231 psz_filter_type = "vout-filter";
233 else if( module_IsCapable( p_obj, "sub filter" ) )
235 psz_filter_type = "sub-filter";
240 msg_Err( p_intf, "Unknown video filter type." );
245 psz_string = config_GetPsz( p_intf, psz_filter_type );
247 if( !psz_string ) psz_string = strdup( "" );
249 psz_parser = strstr( psz_string, psz_name );
255 psz_parser = psz_string;
256 asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
257 psz_string, psz_name );
269 if( *( psz_parser + strlen( psz_name ) ) == ':' )
271 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
272 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
279 /* Remove trailing : : */
280 if( strlen( psz_string ) > 0 &&
281 *( psz_string + strlen( psz_string ) -1 ) == ':' )
283 *( psz_string + strlen( psz_string ) -1 ) = '\0';
292 /* Vout is not kept, so put that in the config */
293 config_PutPsz( p_intf, psz_filter_type, psz_string );
294 if( !strcmp( psz_filter_type, "video-filter" ) )
295 ui.videoFilterText->setText( psz_string );
296 else if( !strcmp( psz_filter_type, "vout-filter" ) )
297 ui.voutFilterText->setText( psz_string );
298 else if( !strcmp( psz_filter_type, "sub-filter" ) )
299 ui.subpictureFilterText->setText( psz_string );
301 /* Try to set on the fly */
302 p_vout = ( vout_thread_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
306 if( !strcmp( psz_filter_type, "sub-filter" ) )
307 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
309 var_SetString( p_vout, psz_filter_type, psz_string );
310 vlc_object_release( p_vout );
316 void ExtVideo::updateFilters()
318 QString module = ModuleFromWidgetName( sender() );
319 //std::cout << "Module name: " << module.toStdString() << std::endl;
321 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
322 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
324 ChangeVFiltersString( qtu( module ),
325 checkbox ? checkbox->isChecked()
326 : groupbox->isChecked() );
329 void ExtVideo::initComboBoxItems( QObject *widget )
331 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
332 if( !combobox ) return;
333 QString option = OptionFromWidgetName( widget );
334 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
338 int i_type = p_item->i_type & CONFIG_ITEM;
339 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
341 if( i_type == CONFIG_ITEM_INTEGER
342 || i_type == CONFIG_ITEM_BOOL )
343 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
344 p_item->pi_list[i_index] );
345 else if( i_type == CONFIG_ITEM_STRING )
346 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
347 p_item->ppsz_list[i_index] );
352 msg_Err( p_intf, "Couldn't find option \"%s\".",
357 void ExtVideo::setWidgetValue( QObject *widget )
359 QString module = ModuleFromWidgetName( widget->parent() );
360 //std::cout << "Module name: " << module.toStdString() << std::endl;
361 QString option = OptionFromWidgetName( widget );
362 //std::cout << "Option name: " << option.toStdString() << std::endl;
364 vlc_object_t *p_obj = ( vlc_object_t * )
365 vlc_object_find_name( p_intf->p_libvlc,
375 "Module instance %s not found, looking in config values.",
378 i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
381 case VLC_VAR_INTEGER:
383 val.i_int = config_GetInt( p_intf, qtu( option ) );
386 val.f_float = config_GetFloat( p_intf, qtu( option ) );
389 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
395 i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
396 var_Get( p_obj, qtu( option ), &val );
397 vlc_object_release( p_obj );
400 /* Try to cast to all the widgets we're likely to encounter. Only
401 * one of the casts is expected to work. */
402 QSlider *slider = qobject_cast<QSlider*> ( widget );
403 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
404 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
405 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
406 QDial *dial = qobject_cast<QDial*> ( widget );
407 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
408 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
410 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
413 if( slider ) slider->setValue( val.i_int );
414 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
416 else if( spinbox ) spinbox->setValue( val.i_int );
417 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
421 sprintf( str, "%06X", val.i_int );
422 lineedit->setText( str );
424 else if( combobox ) combobox->setCurrentIndex(
425 combobox->findData( val.i_int ) );
426 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
428 else if( i_type == VLC_VAR_FLOAT )
431 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
432 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
433 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
435 else if( i_type == VLC_VAR_STRING )
437 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
438 else if( combobox ) combobox->setCurrentIndex(
439 combobox->findData( qfu( val.psz_string ) ) );
440 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
441 free( val.psz_string );
445 "Module %s's %s variable is of an unsupported type ( %d )",
451 void ExtVideo::updateFilterOptions()
453 QString module = ModuleFromWidgetName( sender()->parent() );
454 //std::cout << "Module name: " << module.toStdString() << std::endl;
455 QString option = OptionFromWidgetName( sender() );
456 //std::cout << "Option name: " << option.toStdString() << std::endl;
458 vlc_object_t *p_obj = ( vlc_object_t * )
459 vlc_object_find_name( p_intf->p_libvlc,
464 msg_Err( p_intf, "Module %s not found.", qtu( module ) );
468 int i_type = var_Type( p_obj, qtu( option ) );
469 bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
472 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.",
475 /* FIXME: restart automatically somewhere near the end of this function */
478 /* Try to cast to all the widgets we're likely to encounter. Only
479 * one of the casts is expected to work. */
480 QSlider *slider = qobject_cast<QSlider*> ( sender() );
481 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
482 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
483 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
484 QDial *dial = qobject_cast<QDial*> ( sender() );
485 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
486 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
489 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
492 if( slider ) i_int = slider->value();
493 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
494 else if( spinbox ) i_int = spinbox->value();
495 else if( dial ) i_int = ( 540-dial->value() )%360;
496 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
497 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
498 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
499 config_PutInt( p_intf, qtu( option ), i_int );
502 if( i_type == VLC_VAR_INTEGER )
503 var_SetInteger( p_obj, qtu( option ), i_int );
505 var_SetBool( p_obj, qtu( option ), i_int );
508 else if( i_type == VLC_VAR_FLOAT )
511 if( slider ) f_float = ( double )slider->value()
512 / ( double )slider->tickInterval(); /* hack alert! */
513 else if( doublespinbox ) f_float = doublespinbox->value();
514 else if( lineedit ) f_float = lineedit->text().toDouble();
515 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
516 config_PutFloat( p_intf, qtu( option ), f_float );
518 var_SetFloat( p_obj, qtu( option ), f_float );
520 else if( i_type == VLC_VAR_STRING )
522 char *psz_string = NULL;
523 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
524 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
525 combobox->currentIndex() ).toString() ) );
526 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
527 config_PutPsz( p_intf, qtu( option ), psz_string );
529 var_SetString( p_obj, qtu( option ), psz_string );
534 "Module %s's %s variable is of an unsupported type ( %d )",
539 vlc_object_release( p_obj );
543 void ExtVideo::gotoConf( QObject* src )
545 #define SHOWCONF( module ) \
546 if( src->objectName().contains( module ) ) \
548 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
552 SHOWCONF( "magnify" );
554 SHOWCONF( "ripple" );
555 SHOWCONF( "invert" );
556 SHOWCONF( "puzzle" );
558 SHOWCONF( "gradient" );
559 SHOWCONF( "colorthres" )
563 /**********************************************************************
565 **********************************************************************/
567 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
568 : QWidget( _parent ), p_intf( _p_intf )
572 BUTTONACT( ui.refresh, Refresh() );
583 void ExtV4l2::showEvent( QShowEvent *event )
585 QWidget::showEvent( event );
589 void ExtV4l2::Refresh( void )
591 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
595 ui.vboxLayout->removeWidget( box );
601 msg_Dbg( p_intf, "Found v4l2 instance" );
602 vlc_value_t val, text, name;
603 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
607 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
609 vlc_object_release( p_obj );
613 box = new QGroupBox( this );
614 ui.vboxLayout->addWidget( box );
615 QVBoxLayout *layout = new QVBoxLayout( box );
616 box->setLayout( layout );
618 for( int i = 0; i < val.p_list->i_count; i++ )
620 const char *psz_var = text.p_list->p_values[i].psz_string;
621 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
622 const char *psz_label = name.psz_string;
623 msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
624 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
626 int i_type = var_Type( p_obj, psz_var );
627 switch( i_type & VLC_VAR_TYPE )
629 case VLC_VAR_INTEGER:
631 QLabel *label = new QLabel( psz_label, box );
632 QHBoxLayout *hlayout = new QHBoxLayout();
633 hlayout->addWidget( label );
634 int i_val = var_GetInteger( p_obj, psz_var );
635 if( i_type & VLC_VAR_HASCHOICE )
637 QComboBox *combobox = new QComboBox( box );
638 combobox->setObjectName( psz_var );
640 vlc_value_t val2, text2;
641 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
643 for( int j = 0; j < val2.p_list->i_count; j++ )
646 text2.p_list->p_values[j].psz_string,
647 val2.p_list->p_values[j].i_int );
648 if( i_val == val2.p_list->p_values[j].i_int )
649 combobox->setCurrentIndex( j );
651 var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
654 CONNECT( combobox, currentIndexChanged( int ), this,
655 ValueChange( int ) );
656 hlayout->addWidget( combobox );
660 QSlider *slider = new QSlider( box );
661 slider->setObjectName( psz_var );
662 slider->setOrientation( Qt::Horizontal );
664 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
666 slider->setMinimum( val2.i_int );
667 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
669 slider->setMaximum( val2.i_int );
670 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
672 slider->setSingleStep( val2.i_int );
673 slider->setValue( i_val );
675 CONNECT( slider, valueChanged( int ), this,
676 ValueChange( int ) );
677 hlayout->addWidget( slider );
679 layout->addLayout( hlayout );
684 QCheckBox *button = new QCheckBox( psz_label, box );
685 button->setObjectName( psz_var );
686 button->setChecked( var_GetBool( p_obj, psz_var ) );
688 CONNECT( button, clicked( bool ), this,
689 ValueChange( bool ) );
690 layout->addWidget( button );
695 if( i_type & VLC_VAR_ISCOMMAND )
697 QPushButton *button = new QPushButton( psz_label, box );
698 button->setObjectName( psz_var );
700 CONNECT( button, clicked( bool ), this,
701 ValueChange( bool ) );
702 layout->addWidget( button );
706 QLabel *label = new QLabel( psz_label, box );
707 layout->addWidget( label );
712 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
715 free( name.psz_string );
717 var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
718 vlc_object_release( p_obj );
722 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
728 void ExtV4l2::ValueChange( bool value )
730 ValueChange( (int)value );
733 void ExtV4l2::ValueChange( int value )
735 QObject *s = sender();
736 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
739 char *psz_var = strdup( qtu( s->objectName() ) );
740 int i_type = var_Type( p_obj, psz_var );
741 switch( i_type & VLC_VAR_TYPE )
743 case VLC_VAR_INTEGER:
744 if( i_type & VLC_VAR_HASCHOICE )
746 QComboBox *combobox = qobject_cast<QComboBox*>( s );
747 value = combobox->itemData( value ).toInt();
749 var_SetInteger( p_obj, psz_var, value );
752 var_SetBool( p_obj, psz_var, value );
755 var_SetVoid( p_obj, psz_var );
759 vlc_object_release( p_obj );
763 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
768 /**********************************************************************
770 **********************************************************************/
772 static const QString band_frequencies[] =
774 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
775 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
778 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
779 QWidget( _parent ) , p_intf( _p_intf )
781 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
782 smallFont.setPointSize( smallFont.pointSize() - 3 );
785 presetsComboBox = ui.presetsCombo;
787 ui.preampLabel->setFont( smallFont );
788 ui.preampSlider->setMaximum( 400 );
789 for( int i = 0 ; i < NB_PRESETS ; i ++ )
791 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
794 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
796 BUTTONACT( ui.enableCheck, enable() );
797 BUTTONACT( ui.eq2PassCheck, set2Pass() );
799 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
801 QGridLayout *grid = new QGridLayout( ui.frame );
802 grid->setMargin( 0 );
803 for( int i = 0 ; i < BANDS ; i++ )
805 bands[i] = new QSlider( Qt::Vertical );
806 bands[i]->setMaximum( 400 );
807 bands[i]->setValue( 200 );
808 CONNECT( bands[i], valueChanged( int ), this, setBand() );
809 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
810 band_texts[i]->setFont( smallFont );
811 grid->addWidget( bands[i], 0, i );
812 grid->addWidget( band_texts[i], 1, i );
815 /* Write down initial values */
816 aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
817 VLC_OBJECT_AOUT, FIND_ANYWHERE );
823 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
824 if( var_GetBool( p_aout, "equalizer-2pass" ) )
825 ui.eq2PassCheck->setChecked( true );
826 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
827 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
828 vlc_object_release( p_aout );
832 psz_af = config_GetPsz( p_intf, "audio-filter" );
833 if( config_GetInt( p_intf, "equalizer-2pass" ) )
834 ui.eq2PassCheck->setChecked( true );
835 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
836 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
838 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
839 ui.enableCheck->setChecked( true );
841 enable( ui.enableCheck->isChecked() );
843 setValues( psz_bands, f_preamp );
846 Equalizer::~Equalizer()
850 void Equalizer::enable()
852 bool en = ui.enableCheck->isChecked();
853 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
854 en ? VLC_TRUE : VLC_FALSE );
855 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
856 // en ? VLC_TRUE : VLC_FALSE );
857 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
858 // en ? VLC_TRUE : VLC_FALSE );
862 void Equalizer::enable( bool en )
864 ui.eq2PassCheck->setEnabled( en );
865 ui.preampLabel->setEnabled( en );
866 ui.preampSlider->setEnabled( en );
867 for( int i = 0 ; i< BANDS; i++ )
869 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
873 void Equalizer::set2Pass()
875 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
876 VLC_OBJECT_AOUT, FIND_ANYWHERE );
877 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
880 config_PutInt( p_intf, "equalizer-2pass", b_2p );
883 var_SetBool( p_aout, "equalizer-2pass", b_2p );
884 config_PutInt( p_intf, "equalizer-2pass", b_2p );
885 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
887 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
889 vlc_object_release( p_aout );
893 void Equalizer::setPreamp()
895 float f= ( float )( ui.preampSlider->value() ) /10 - 20;
897 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
898 VLC_OBJECT_AOUT, FIND_ANYWHERE );
900 sprintf( psz_val, "%.1f", f );
901 ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
904 delCallbacks( p_aout );
905 var_SetFloat( p_aout, "equalizer-preamp", f );
906 addCallbacks( p_aout );
907 vlc_object_release( p_aout );
909 config_PutFloat( p_intf, "equalizer-preamp", f );
912 void Equalizer::setBand()
914 char psz_values[102]; memset( psz_values, 0, 102 );
916 /**\todo smoothing */
918 for( int i = 0 ; i< BANDS ; i++ )
921 float f_val = ( float )( bands[i]->value() ) / 10 - 20 ;
922 sprintf( psz_values, "%s %f", psz_values, f_val );
923 sprintf( psz_val, "% 5.1f", f_val );
924 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
926 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
927 VLC_OBJECT_AOUT, FIND_ANYWHERE );
930 delCallbacks( p_aout );
931 var_SetString( p_aout, "equalizer-bands", psz_values );
932 addCallbacks( p_aout );
933 vlc_object_release( p_aout );
936 void Equalizer::setValues( char *psz_bands, float f_preamp )
941 for( int i = 0; i < 10; i++ )
944 float f = strtof( p, &p );
945 int i_val= ( int )( ( f + 20 ) * 10 );
946 bands[i]->setValue( i_val );
947 sprintf( psz_val, "% 5.1f", f );
948 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
950 if( p == NULL || *p == '\0' ) break;
952 if( *p == '\0' ) break;
956 int i_val = ( int )( ( f_preamp + 20 ) * 10 );
957 sprintf( psz_val, "%.1f", f_preamp );
958 ui.preampSlider->setValue( i_val );
959 ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
962 void Equalizer::setPreset( int preset )
964 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
965 VLC_OBJECT_AOUT, FIND_ANYWHERE );
967 char psz_values[102]; memset( psz_values, 0, 102 );
968 for( int i = 0 ; i< 10 ;i++ )
969 sprintf( psz_values, "%s %.1f", psz_values,
970 eqz_preset_10b[preset]->f_amp[i] );
974 delCallbacks( p_aout );
975 var_SetString( p_aout, "equalizer-bands", psz_values );
976 var_SetFloat( p_aout, "equalizer-preamp",
977 eqz_preset_10b[preset]->f_preamp );
978 addCallbacks( p_aout );
979 vlc_object_release( p_aout );
981 config_PutPsz( p_intf, "equalizer-bands", psz_values );
982 config_PutFloat( p_intf, "equalizer-preamp",
983 eqz_preset_10b[preset]->f_preamp );
985 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
988 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
989 vlc_value_t oldval, vlc_value_t newval, void *p_data )
991 char *psz_preset = newval.psz_string;
992 Equalizer *eq = ( Equalizer * )p_data;
993 eq->presetsComboBox->setCurrentIndex( eq->presetsComboBox->findText( qfu( psz_preset ) ) );
997 void Equalizer::delCallbacks( aout_instance_t *p_aout )
999 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1000 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1001 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1004 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1006 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1007 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1008 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1011 /**********************************************************************
1013 **********************************************************************/
1015 /**********************************************************************
1017 **********************************************************************/
1018 static const char *psz_control_names[] =
1020 "Roomsize", "Width" , "Wet", "Dry", "Damp"
1023 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1024 QWidget( _parent ) , p_intf( _p_intf )
1026 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1027 smallFont.setPointSize( smallFont.pointSize() - 3 );
1029 QGridLayout *layout = new QGridLayout( this );
1030 layout->setMargin( 0 );
1032 enableCheck = new QCheckBox( qfu( "Enable spatializer" ) );
1033 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1035 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1037 spatCtrl[i] = new QSlider( Qt::Vertical );
1040 spatCtrl[i]->setMaximum( 10 );
1041 spatCtrl[i]->setValue( 2 );
1045 spatCtrl[i]->setMaximum( 10 );
1046 spatCtrl[i]->setValue( 0 );
1047 spatCtrl[i]->setMinimum( -10 );
1049 oldControlVars[i] = spatCtrl[i]->value();
1050 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1051 ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1052 ctrl_texts[i]->setFont( smallFont );
1053 ctrl_readout[i] = new QLabel( "" );
1054 ctrl_readout[i]->setFont( smallFont );
1055 layout->addWidget( spatCtrl[i], 1, i );
1056 layout->addWidget( ctrl_readout[i], 2, i );
1057 layout->addWidget( ctrl_texts[i], 3, i );
1060 BUTTONACT( enableCheck, enable() );
1062 /* Write down initial values */
1063 aout_instance_t *p_aout = ( aout_instance_t * )
1064 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1069 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1070 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1072 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1074 vlc_object_release( p_aout );
1078 psz_af = config_GetPsz( p_aout, "audio-filter" );
1079 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1081 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1084 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1085 enableCheck->setChecked( true );
1087 enable( enableCheck->isChecked() );
1088 setValues( controlVars );
1091 Spatializer::~Spatializer()
1095 void Spatializer::enable()
1097 bool en = enableCheck->isChecked();
1098 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1099 en ? VLC_TRUE : VLC_FALSE );
1103 void Spatializer::enable( bool en )
1105 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1107 spatCtrl[i]->setEnabled( en );
1108 ctrl_texts[i]->setEnabled( en );
1109 ctrl_readout[i]->setEnabled( en );
1112 void Spatializer::setInitValues()
1114 setValues( controlVars );
1117 void Spatializer::setValues( float *controlVars )
1121 aout_instance_t *p_aout= ( aout_instance_t * )
1122 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1124 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1126 float f= ( float )( spatCtrl[i]->value() );
1127 sprintf( psz_val, "%.1f", f );
1128 ctrl_readout[i]->setText( psz_val );
1132 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1134 if( oldControlVars[i] != spatCtrl[i]->value() )
1136 var_SetFloat( p_aout, psz_control_names[i],
1137 ( float )spatCtrl[i]->value() );
1138 config_PutFloat( p_intf, psz_control_names[i],
1139 ( float ) spatCtrl[i]->value() );
1140 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1143 vlc_object_release( p_aout );
1147 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1149 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1150 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1153 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1155 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1156 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1159 /**********************************************************************
1160 * Video filters / Adjust
1161 **********************************************************************/
1163 /**********************************************************************
1164 * Extended playbak controls
1165 **********************************************************************/