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"
40 #include "input_manager.hpp"
43 #include <vlc_intf_strings.h>
49 class ConfClickHandler : public QObject
52 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
53 e = _e; p_intf = _p_intf;
55 virtual ~ConfClickHandler() {}
56 bool eventFilter( QObject *obj, QEvent *evt )
58 if( evt->type() == QEvent::MouseButtonPress )
67 intf_thread_t *p_intf;
71 QString ModuleFromWidgetName( QObject *obj )
73 return obj->objectName().replace( "Enable","" );
76 QString OptionFromWidgetName( QObject *obj )
79 QString option = obj->objectName().replace( "Slider", "" )
80 .replace( "Combo" , "" )
81 .replace( "Dial" , "" )
82 .replace( "Check" , "" )
83 .replace( "Spin" , "" )
84 .replace( "Text" , "" );
85 for( char a = 'A'; a <= 'Z'; a++ )
87 option = option.replace( QString( a ),
88 QString( '-' ) + QString( a + 'a' - 'A' ) );
93 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
96 ui.setupUi( _parent );
98 #define SETUP_VFILTER( widget ) \
100 vlc_object_t *p_obj = ( vlc_object_t * ) \
101 vlc_object_find_name( p_intf->p_libvlc, \
104 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
105 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
108 vlc_object_release( p_obj ); \
109 if( checkbox ) checkbox->setChecked( true ); \
110 else groupbox->setChecked( true ); \
114 if( checkbox ) checkbox->setChecked( false ); \
115 else groupbox->setChecked( false ); \
118 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
119 #define SETUP_VFILTER_OPTION( widget, signal ) \
120 initComboBoxItems( ui.widget ); \
121 setWidgetValue( ui.widget ); \
122 CONNECT( ui.widget, signal, this, updateFilterOptions() );
124 SETUP_VFILTER( adjust )
125 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
126 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
127 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
128 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
129 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
130 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
132 SETUP_VFILTER( extract )
133 SETUP_VFILTER_OPTION( extractComponentText, textChanged( QString ) )
135 SETUP_VFILTER( colorthres )
136 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( QString ) )
137 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
138 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
140 SETUP_VFILTER( invert )
142 SETUP_VFILTER( gradient )
143 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
144 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
145 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
147 SETUP_VFILTER( motionblur )
148 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
150 SETUP_VFILTER( motiondetect )
152 SETUP_VFILTER( noise )
154 SETUP_VFILTER( psychedelic )
156 SETUP_VFILTER( sharpen )
157 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
159 SETUP_VFILTER( ripple )
161 SETUP_VFILTER( wave )
163 SETUP_VFILTER( transform )
164 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
166 SETUP_VFILTER( rotate )
167 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
168 ui.rotateAngleDial->setWrapping( true );
169 ui.rotateAngleDial->setNotchesVisible( true );
171 SETUP_VFILTER( puzzle )
172 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
173 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
174 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
176 SETUP_VFILTER( magnify )
178 SETUP_VFILTER( clone )
179 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
181 SETUP_VFILTER( wall )
182 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
183 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
185 SETUP_VFILTER( panoramix )
186 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
187 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
190 SETUP_VFILTER( erase )
191 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
192 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
193 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
195 SETUP_VFILTER( marq )
196 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( QString ) )
197 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
199 SETUP_VFILTER( logo )
200 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
201 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
202 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
203 SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
206 #undef SETUP_VFILTER_OPTION
208 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
209 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
210 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
211 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
212 CONNECT( ui.topBotCropSync, toggled( bool ),
213 ui.cropBotPx, setDisabled( bool ) );
214 CONNECT( ui.leftRightCropSync, toggled( bool ),
215 ui.cropRightPx, setDisabled( bool ) );
218 ExtVideo::~ExtVideo()
222 void ExtVideo::cropChange()
224 p_vout = ( vout_thread_t * )vlc_object_find( p_intf,
225 VLC_OBJECT_VOUT, FIND_CHILD );
228 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
229 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
230 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
231 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
235 void ExtVideo::ChangeVFiltersString( char *psz_name, bool b_add )
237 char *psz_parser, *psz_string;
238 const char *psz_filter_type;
240 /* Please leave p_libvlc_global. This is where cached modules are
241 * stored. We're not trying to find a module instance. */
242 module_t *p_obj = module_Find( p_intf, psz_name );
245 msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
249 if( module_IsCapable( p_obj, "video filter2" ) )
251 psz_filter_type = "video-filter";
253 else if( module_IsCapable( p_obj, "video filter" ) )
255 psz_filter_type = "vout-filter";
257 else if( module_IsCapable( p_obj, "sub filter" ) )
259 psz_filter_type = "sub-filter";
264 msg_Err( p_intf, "Unknown video filter type." );
269 psz_string = config_GetPsz( p_intf, psz_filter_type );
271 if( !psz_string ) psz_string = strdup( "" );
273 psz_parser = strstr( psz_string, psz_name );
279 psz_parser = psz_string;
280 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
281 psz_string, psz_name ) == -1 )
297 if( *( psz_parser + strlen( psz_name ) ) == ':' )
299 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
300 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
307 /* Remove trailing : : */
308 if( strlen( psz_string ) > 0 &&
309 *( psz_string + strlen( psz_string ) -1 ) == ':' )
311 *( psz_string + strlen( psz_string ) -1 ) = '\0';
320 /* Vout is not kept, so put that in the config */
321 config_PutPsz( p_intf, psz_filter_type, psz_string );
322 if( !strcmp( psz_filter_type, "video-filter" ) )
323 ui.videoFilterText->setText( psz_string );
324 else if( !strcmp( psz_filter_type, "vout-filter" ) )
325 ui.voutFilterText->setText( psz_string );
326 else if( !strcmp( psz_filter_type, "sub-filter" ) )
327 ui.subpictureFilterText->setText( psz_string );
329 /* Try to set on the fly */
330 p_vout = ( vout_thread_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
334 if( !strcmp( psz_filter_type, "sub-filter" ) )
335 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
337 var_SetString( p_vout, psz_filter_type, psz_string );
338 vlc_object_release( p_vout );
344 void ExtVideo::updateFilters()
346 QString module = ModuleFromWidgetName( sender() );
347 //std::cout << "Module name: " << module.toStdString() << std::endl;
349 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
350 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
352 ChangeVFiltersString( qtu( module ),
353 checkbox ? checkbox->isChecked()
354 : groupbox->isChecked() );
357 void ExtVideo::initComboBoxItems( QObject *widget )
359 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
360 if( !combobox ) return;
361 QString option = OptionFromWidgetName( widget );
362 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
366 int i_type = p_item->i_type & CONFIG_ITEM;
367 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
369 if( i_type == CONFIG_ITEM_INTEGER
370 || i_type == CONFIG_ITEM_BOOL )
371 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
372 p_item->pi_list[i_index] );
373 else if( i_type == CONFIG_ITEM_STRING )
374 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
375 p_item->ppsz_list[i_index] );
380 msg_Err( p_intf, "Couldn't find option \"%s\".",
385 void ExtVideo::setWidgetValue( QObject *widget )
387 QString module = ModuleFromWidgetName( widget->parent() );
388 //std::cout << "Module name: " << module.toStdString() << std::endl;
389 QString option = OptionFromWidgetName( widget );
390 //std::cout << "Option name: " << option.toStdString() << std::endl;
392 vlc_object_t *p_obj = ( vlc_object_t * )
393 vlc_object_find_name( p_intf->p_libvlc,
403 "Module instance %s not found, looking in config values.",
406 i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
409 case VLC_VAR_INTEGER:
411 val.i_int = config_GetInt( p_intf, qtu( option ) );
414 val.f_float = config_GetFloat( p_intf, qtu( option ) );
417 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
423 i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
424 var_Get( p_obj, qtu( option ), &val );
425 vlc_object_release( p_obj );
428 /* Try to cast to all the widgets we're likely to encounter. Only
429 * one of the casts is expected to work. */
430 QSlider *slider = qobject_cast<QSlider*> ( widget );
431 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
432 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
433 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
434 QDial *dial = qobject_cast<QDial*> ( widget );
435 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
436 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
438 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
441 if( slider ) slider->setValue( val.i_int );
442 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
444 else if( spinbox ) spinbox->setValue( val.i_int );
445 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
449 snprintf( str, sizeof(str), "%06X", val.i_int );
450 lineedit->setText( str );
452 else if( combobox ) combobox->setCurrentIndex(
453 combobox->findData( val.i_int ) );
454 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
456 else if( i_type == VLC_VAR_FLOAT )
459 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
460 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
461 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
463 else if( i_type == VLC_VAR_STRING )
465 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
466 else if( combobox ) combobox->setCurrentIndex(
467 combobox->findData( qfu( val.psz_string ) ) );
468 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
469 free( val.psz_string );
473 "Module %s's %s variable is of an unsupported type ( %d )",
479 void ExtVideo::updateFilterOptions()
481 QString module = ModuleFromWidgetName( sender()->parent() );
482 //std::cout << "Module name: " << module.toStdString() << std::endl;
483 QString option = OptionFromWidgetName( sender() );
484 //std::cout << "Option name: " << option.toStdString() << std::endl;
486 vlc_object_t *p_obj = ( vlc_object_t * )
487 vlc_object_find_name( p_intf->p_libvlc,
492 msg_Err( p_intf, "Module %s not found.", qtu( module ) );
496 int i_type = var_Type( p_obj, qtu( option ) );
497 bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
500 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.",
503 /* FIXME: restart automatically somewhere near the end of this function */
506 /* Try to cast to all the widgets we're likely to encounter. Only
507 * one of the casts is expected to work. */
508 QSlider *slider = qobject_cast<QSlider*> ( sender() );
509 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
510 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
511 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
512 QDial *dial = qobject_cast<QDial*> ( sender() );
513 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
514 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
517 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
520 if( slider ) i_int = slider->value();
521 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
522 else if( spinbox ) i_int = spinbox->value();
523 else if( dial ) i_int = ( 540-dial->value() )%360;
524 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
525 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
526 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
527 config_PutInt( p_intf, qtu( option ), i_int );
530 if( i_type == VLC_VAR_INTEGER )
531 var_SetInteger( p_obj, qtu( option ), i_int );
533 var_SetBool( p_obj, qtu( option ), i_int );
536 else if( i_type == VLC_VAR_FLOAT )
539 if( slider ) f_float = ( double )slider->value()
540 / ( double )slider->tickInterval(); /* hack alert! */
541 else if( doublespinbox ) f_float = doublespinbox->value();
542 else if( lineedit ) f_float = lineedit->text().toDouble();
543 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
544 config_PutFloat( p_intf, qtu( option ), f_float );
546 var_SetFloat( p_obj, qtu( option ), f_float );
548 else if( i_type == VLC_VAR_STRING )
550 char *psz_string = NULL;
551 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
552 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
553 combobox->currentIndex() ).toString() ) );
554 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
555 config_PutPsz( p_intf, qtu( option ), psz_string );
557 var_SetString( p_obj, qtu( option ), psz_string );
562 "Module %s's %s variable is of an unsupported type ( %d )",
567 vlc_object_release( p_obj );
571 void ExtVideo::gotoConf( QObject* src )
573 #define SHOWCONF( module ) \
574 if( src->objectName().contains( module ) ) \
576 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
580 SHOWCONF( "magnify" );
582 SHOWCONF( "ripple" );
583 SHOWCONF( "invert" );
584 SHOWCONF( "puzzle" );
586 SHOWCONF( "gradient" );
587 SHOWCONF( "colorthres" )
591 /**********************************************************************
593 **********************************************************************/
595 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
596 : QWidget( _parent ), p_intf( _p_intf )
600 BUTTONACT( ui.refresh, Refresh() );
611 void ExtV4l2::showEvent( QShowEvent *event )
613 QWidget::showEvent( event );
617 void ExtV4l2::Refresh( void )
619 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
623 ui.vboxLayout->removeWidget( box );
629 vlc_value_t val, text, name;
630 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
634 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
636 vlc_object_release( p_obj );
640 box = new QGroupBox( this );
641 ui.vboxLayout->addWidget( box );
642 QVBoxLayout *layout = new QVBoxLayout( box );
643 box->setLayout( layout );
645 for( int i = 0; i < val.p_list->i_count; i++ )
647 const char *psz_var = text.p_list->p_values[i].psz_string;
648 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
649 const char *psz_label = name.psz_string;
650 msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
651 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
653 int i_type = var_Type( p_obj, psz_var );
654 switch( i_type & VLC_VAR_TYPE )
656 case VLC_VAR_INTEGER:
658 QLabel *label = new QLabel( psz_label, box );
659 QHBoxLayout *hlayout = new QHBoxLayout();
660 hlayout->addWidget( label );
661 int i_val = var_GetInteger( p_obj, psz_var );
662 if( i_type & VLC_VAR_HASCHOICE )
664 QComboBox *combobox = new QComboBox( box );
665 combobox->setObjectName( psz_var );
667 vlc_value_t val2, text2;
668 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
670 for( int j = 0; j < val2.p_list->i_count; j++ )
673 text2.p_list->p_values[j].psz_string,
674 val2.p_list->p_values[j].i_int );
675 if( i_val == val2.p_list->p_values[j].i_int )
676 combobox->setCurrentIndex( j );
678 var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
681 CONNECT( combobox, currentIndexChanged( int ), this,
682 ValueChange( int ) );
683 hlayout->addWidget( combobox );
687 QSlider *slider = new QSlider( box );
688 slider->setObjectName( psz_var );
689 slider->setOrientation( Qt::Horizontal );
691 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
693 slider->setMinimum( val2.i_int );
694 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
696 slider->setMaximum( val2.i_int );
697 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
699 slider->setSingleStep( val2.i_int );
700 slider->setValue( i_val );
702 CONNECT( slider, valueChanged( int ), this,
703 ValueChange( int ) );
704 hlayout->addWidget( slider );
706 layout->addLayout( hlayout );
711 QCheckBox *button = new QCheckBox( psz_label, box );
712 button->setObjectName( psz_var );
713 button->setChecked( var_GetBool( p_obj, psz_var ) );
715 CONNECT( button, clicked( bool ), this,
716 ValueChange( bool ) );
717 layout->addWidget( button );
722 if( i_type & VLC_VAR_ISCOMMAND )
724 QPushButton *button = new QPushButton( psz_label, box );
725 button->setObjectName( psz_var );
727 CONNECT( button, clicked( bool ), this,
728 ValueChange( bool ) );
729 layout->addWidget( button );
733 QLabel *label = new QLabel( psz_label, box );
734 layout->addWidget( label );
739 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
742 free( name.psz_string );
744 var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
745 vlc_object_release( p_obj );
749 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
754 void ExtV4l2::ValueChange( bool value )
756 ValueChange( (int)value );
759 void ExtV4l2::ValueChange( int value )
761 QObject *s = sender();
762 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
765 char *psz_var = strdup( qtu( s->objectName() ) );
766 int i_type = var_Type( p_obj, psz_var );
767 switch( i_type & VLC_VAR_TYPE )
769 case VLC_VAR_INTEGER:
770 if( i_type & VLC_VAR_HASCHOICE )
772 QComboBox *combobox = qobject_cast<QComboBox*>( s );
773 value = combobox->itemData( value ).toInt();
775 var_SetInteger( p_obj, psz_var, value );
778 var_SetBool( p_obj, psz_var, value );
781 var_SetVoid( p_obj, psz_var );
785 vlc_object_release( p_obj );
789 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
794 /**********************************************************************
796 **********************************************************************/
798 static const QString band_frequencies[] =
800 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
801 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
804 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
805 QWidget( _parent ) , p_intf( _p_intf )
807 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
808 smallFont.setPointSize( smallFont.pointSize() - 3 );
811 ui.preampLabel->setFont( smallFont );
813 /* Setup of presetsComboBox */
814 presetsComboBox = ui.presetsCombo;
815 CONNECT( presetsComboBox, currentIndexChanged( int ),
816 this, updateUISliderValues( int ) );
817 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
819 /* Add the sliders for the Bands */
820 QGridLayout *grid = new QGridLayout( ui.frame );
821 grid->setMargin( 0 );
822 for( int i = 0 ; i < BANDS ; i++ )
824 bands[i] = new QSlider( Qt::Vertical );
825 bands[i]->setMaximum( 400 );
826 bands[i]->setValue( 200 );
827 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
829 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
830 band_texts[i]->setFont( smallFont );
832 grid->addWidget( bands[i], 0, i );
833 grid->addWidget( band_texts[i], 1, i );
836 /* Add the listed presets */
837 for( int i = 0 ; i < NB_PRESETS ; i ++ )
839 presetsComboBox->addItem( qtr( preset_list_text[i] ),
840 QVariant( preset_list[i] ) );
844 BUTTONACT( ui.enableCheck, enable() );
845 BUTTONACT( ui.eq2PassCheck, set2Pass() );
846 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
848 /* Do the update from the value of the core */
852 Equalizer::~Equalizer()
856 /* Write down initial values */
857 void Equalizer::updateUIFromCore()
859 char *psz_af;//, *psz_bands; Don't use it ?
863 aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
864 VLC_OBJECT_AOUT, FIND_ANYWHERE );
867 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
868 if( var_GetBool( p_aout, "equalizer-2pass" ) )
869 ui.eq2PassCheck->setChecked( true );
870 // psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
871 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
872 i_preset = presetsComboBox->findData( QVariant(
873 var_GetString( p_aout, "equalizer-preset" ) ) );
874 vlc_object_release( p_aout );
878 psz_af = config_GetPsz( p_intf, "audio-filter" );
879 if( config_GetInt( p_intf, "equalizer-2pass" ) )
880 ui.eq2PassCheck->setChecked( true );
881 // psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
882 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
883 i_preset = presetsComboBox->findData( QVariant(
884 config_GetPsz( p_intf, "equalizer-preset" ) ) );
886 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
887 ui.enableCheck->setChecked( true );
888 enable( ui.enableCheck->isChecked() );
890 presetsComboBox->setCurrentIndex( i_preset );
895 /* Functin called when enableButton is toggled */
896 void Equalizer::enable()
898 bool en = ui.enableCheck->isChecked();
899 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
901 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
902 // en ? true : false );
903 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
904 // en ? true : false );
907 if( presetsComboBox->currentIndex() < 0 )
908 presetsComboBox->setCurrentIndex( 0 );
912 void Equalizer::enable( bool en )
914 ui.eq2PassCheck->setEnabled( en );
915 presetsComboBox->setEnabled( en );
916 ui.presetLabel->setEnabled( en );
917 ui.preampLabel->setEnabled( en );
918 ui.preampSlider->setEnabled( en );
919 for( int i = 0 ; i< BANDS; i++ )
921 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
925 /* Function called when the set2Pass button is activated */
926 void Equalizer::set2Pass()
928 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
929 VLC_OBJECT_AOUT, FIND_ANYWHERE );
930 bool b_2p = ui.eq2PassCheck->isChecked();
933 config_PutInt( p_intf, "equalizer-2pass", b_2p );
936 var_SetBool( p_aout, "equalizer-2pass", b_2p );
937 config_PutInt( p_intf, "equalizer-2pass", b_2p );
938 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
940 p_aout->pp_inputs[i]->b_restart = true;
942 vlc_object_release( p_aout );
946 /* Function called when the preamp slider is moved */
947 void Equalizer::setPreamp()
949 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
950 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
951 VLC_OBJECT_AOUT, FIND_ANYWHERE );
953 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
957 //delCallbacks( p_aout );
958 var_SetFloat( p_aout, "equalizer-preamp", f );
959 //addCallbacks( p_aout );
960 vlc_object_release( p_aout );
962 config_PutFloat( p_intf, "equalizer-preamp", f );
965 void Equalizer::setCoreBands()
967 /**\todo smoothing */
970 for( int i = 0; i < BANDS; i++ )
972 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
973 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
975 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
978 const char *psz_values = values.toAscii().constData();
980 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
981 VLC_OBJECT_AOUT, FIND_ANYWHERE );
984 //delCallbacks( p_aout );
985 var_SetString( p_aout, "equalizer-bands", psz_values );
986 //addCallbacks( p_aout );
987 vlc_object_release( p_aout );
991 void Equalizer::updateUISliderValues( int i_preset )
993 if( i_preset < 0 ) return;
995 char *p = createValuesFromPreset( i_preset );
997 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1001 for( int i = 0; i < BANDS; i++ )
1003 const float f = us_strtod(p, &p );
1005 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1007 band_texts[i]->setText( band_frequencies[i] + "\n"
1008 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1009 if( p == NULL || *p == '\0' )
1017 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1018 ui.preampLabel->setText( qtr( "Preamp\n" )
1019 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1022 char * Equalizer::createValuesFromPreset( int i_preset )
1027 /* Create the QString in Qt */
1028 for( int i = 0 ; i< BANDS ;i++ )
1029 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1031 /* Convert it to char * */
1032 if( !asprintf( &psz_values, "%s", values.toAscii().constData() ) )
1038 void Equalizer::setCorePreset( int i_preset )
1040 char *psz_values = createValuesFromPreset( i_preset );
1041 if( !psz_values ) return ;
1043 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
1044 VLC_OBJECT_AOUT, FIND_ANYWHERE );
1047 delCallbacks( p_aout );
1048 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1050 var_SetString( p_aout, "equalizer-bands", psz_values );
1051 var_SetFloat( p_aout, "equalizer-preamp",
1052 eqz_preset_10b[i_preset]->f_preamp );
1053 addCallbacks( p_aout );
1054 vlc_object_release( p_aout );
1056 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1057 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1058 config_PutFloat( p_intf, "equalizer-preamp",
1059 eqz_preset_10b[i_preset]->f_preamp );
1062 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1063 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1065 char *psz_preset = newval.psz_string;
1066 Equalizer *eq = ( Equalizer * )p_data;
1067 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1068 eq->presetsComboBox->setCurrentIndex( i_preset );
1072 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1074 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1075 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1076 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1079 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1081 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1082 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1083 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1086 /**********************************************************************
1088 **********************************************************************/
1090 /**********************************************************************
1092 **********************************************************************/
1093 static const char *psz_control_names[] =
1095 "Roomsize", "Width" , "Wet", "Dry", "Damp"
1098 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1099 QWidget( _parent ) , p_intf( _p_intf )
1101 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1102 smallFont.setPointSize( smallFont.pointSize() - 3 );
1104 QGridLayout *layout = new QGridLayout( this );
1105 layout->setMargin( 0 );
1107 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1108 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1110 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1112 spatCtrl[i] = new QSlider( Qt::Vertical );
1115 spatCtrl[i]->setMaximum( 10 );
1116 spatCtrl[i]->setValue( 2 );
1120 spatCtrl[i]->setMaximum( 10 );
1121 spatCtrl[i]->setValue( 0 );
1122 spatCtrl[i]->setMinimum( -10 );
1124 oldControlVars[i] = spatCtrl[i]->value();
1125 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1126 ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1127 ctrl_texts[i]->setFont( smallFont );
1128 ctrl_readout[i] = new QLabel( "" );
1129 ctrl_readout[i]->setFont( smallFont );
1130 layout->addWidget( spatCtrl[i], 1, i );
1131 layout->addWidget( ctrl_readout[i], 2, i );
1132 layout->addWidget( ctrl_texts[i], 3, i );
1135 BUTTONACT( enableCheck, enable() );
1137 /* Write down initial values */
1138 aout_instance_t *p_aout = ( aout_instance_t * )
1139 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1144 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1145 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1147 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1149 vlc_object_release( p_aout );
1153 psz_af = config_GetPsz( p_intf, "audio-filter" );
1154 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1156 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1159 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1160 enableCheck->setChecked( true );
1162 enable( enableCheck->isChecked() );
1163 setValues( controlVars );
1166 Spatializer::~Spatializer()
1170 void Spatializer::enable()
1172 bool en = enableCheck->isChecked();
1173 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1174 en ? true : false );
1178 void Spatializer::enable( bool en )
1180 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1182 spatCtrl[i]->setEnabled( en );
1183 ctrl_texts[i]->setEnabled( en );
1184 ctrl_readout[i]->setEnabled( en );
1187 void Spatializer::setInitValues()
1189 setValues( controlVars );
1192 void Spatializer::setValues( float *controlVars )
1194 aout_instance_t *p_aout= ( aout_instance_t * )
1195 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1197 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1199 float f = (float)( spatCtrl[i]->value() );
1200 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1204 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1206 if( oldControlVars[i] != spatCtrl[i]->value() )
1208 var_SetFloat( p_aout, psz_control_names[i],
1209 ( float )spatCtrl[i]->value() );
1210 config_PutFloat( p_intf, psz_control_names[i],
1211 ( float ) spatCtrl[i]->value() );
1212 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1215 vlc_object_release( p_aout );
1219 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1221 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1222 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1225 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1227 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1228 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1231 #include <QToolButton>
1232 #include <QGridLayout>
1234 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1235 QWidget( _parent ) , p_intf( _p_intf )
1237 QGroupBox *AVBox, *subsBox;
1239 QToolButton *moinsAV, *plusAV;
1240 QToolButton *moinssubs, *plussubs;
1241 QToolButton *moinssubSpeed, *plussubSpeed;
1243 QToolButton *updateButton;
1245 QGridLayout *mainLayout = new QGridLayout( this );
1248 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1249 QGridLayout *AVLayout = new QGridLayout( AVBox );
1251 moinsAV = new QToolButton;
1252 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1253 moinsAV->setAutoRaise( true );
1254 moinsAV->setText( "-" );
1255 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1257 plusAV = new QToolButton;
1258 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1259 plusAV->setAutoRaise( true );
1260 plusAV->setText( "+" );
1261 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1263 QLabel *AVLabel = new QLabel;
1264 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1265 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1267 AVSpin = new QDoubleSpinBox;
1268 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1269 AVSpin->setDecimals( 3 );
1270 AVSpin->setMinimum( -100 );
1271 AVSpin->setMaximum( 100 );
1272 AVSpin->setSingleStep( 0.1 );
1273 AVSpin->setToolTip( qtr( "A positive value means that\n"
1274 "the audio is ahead of the video" ) );
1275 AVSpin->setSuffix( "s" );
1276 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1277 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1281 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1282 QGridLayout *subsLayout = new QGridLayout( subsBox );
1284 moinssubs = new QToolButton;
1285 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1286 moinssubs->setAutoRaise( true );
1287 moinssubs->setText( "-" );
1288 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1290 plussubs = new QToolButton;
1291 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1292 plussubs->setAutoRaise( true );
1293 plussubs->setText( "+" );
1294 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1296 QLabel *subsLabel = new QLabel;
1297 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1298 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1300 subsSpin = new QDoubleSpinBox;
1301 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1302 subsSpin->setDecimals( 3 );
1303 subsSpin->setMinimum( -100 );
1304 subsSpin->setMaximum( 100 );
1305 subsSpin->setSingleStep( 0.1 );
1306 subsSpin->setToolTip( qtr( "A positive value means that\n"
1307 "the subtitles are ahead of the video" ) );
1308 subsSpin->setSuffix( "s" );
1309 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1312 moinssubSpeed = new QToolButton;
1313 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1314 moinssubSpeed->setAutoRaise( true );
1315 moinssubSpeed->setText( "-" );
1316 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1318 plussubSpeed = new QToolButton;
1319 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1320 plussubSpeed->setAutoRaise( true );
1321 plussubSpeed->setText( "+" );
1322 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1324 QLabel *subSpeedLabel = new QLabel;
1325 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1326 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1328 subSpeedSpin = new QDoubleSpinBox;
1329 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1330 subSpeedSpin->setDecimals( 3 );
1331 subSpeedSpin->setMinimum( 1 );
1332 subSpeedSpin->setMaximum( 100 );
1333 subSpeedSpin->setSingleStep( 0.2 );
1334 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1336 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1338 updateButton = new QToolButton;
1339 updateButton->setAutoRaise( true );
1340 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1343 /* Various Connects */
1344 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1345 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1346 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1347 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1348 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1349 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1350 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1351 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1352 CONNECT( subSpeedSpin, valueChanged ( double ),
1353 this, adjustSubsSpeed( double ) );
1354 BUTTON_SET_ACT_I( updateButton, "", update,
1355 qtr( "Force update of this dialog's values" ), update() );
1361 void SyncControls::update()
1364 if( THEMIM->getInput() )
1366 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1367 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1368 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1369 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1370 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1374 void SyncControls::advanceAudio( double f_advance )
1376 if( THEMIM->getInput() )
1378 int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1379 i_delay += f_advance * 1000000;
1380 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1381 msg_Dbg( p_intf, "I am advancing Audio %d", f_advance );
1385 void SyncControls::advanceSubs( double f_advance )
1387 if( THEMIM->getInput() )
1389 int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1390 i_delay += f_advance * 1000000;
1391 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1392 msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
1396 void SyncControls::adjustSubsSpeed( double f_fps )
1398 if( THEMIM->getInput() )
1400 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1404 /**********************************************************************
1405 * Video filters / Adjust
1406 **********************************************************************/
1408 /**********************************************************************
1409 * Extended playbak controls
1410 **********************************************************************/