1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006-2008 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 *****************************************************************************/
33 #include <QGridLayout>
34 #include <QSignalMapper>
37 #include "components/extended_panels.hpp"
38 #include "dialogs/preferences.hpp"
40 #include "input_manager.hpp"
42 #include "../../audio_filter/equalizer_presets.h"
44 #include <vlc_intf_strings.h>
48 #include <vlc_charset.h> /* us_strtod */
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 ) :
96 QObject( _parent ), p_intf( _p_intf )
98 ui.setupUi( _parent );
101 #define SETUP_VFILTER( widget ) \
103 vlc_object_t *p_obj = ( vlc_object_t * ) \
104 vlc_object_find_name( p_intf->p_libvlc, \
107 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
108 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
111 vlc_object_release( p_obj ); \
112 if( checkbox ) checkbox->setChecked( true ); \
113 else groupbox->setChecked( true ); \
117 if( checkbox ) checkbox->setChecked( false ); \
118 else groupbox->setChecked( false ); \
121 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
122 #define SETUP_VFILTER_OPTION( widget, signal ) \
123 initComboBoxItems( ui.widget ); \
124 setWidgetValue( ui.widget ); \
125 CONNECT( ui.widget, signal, this, updateFilterOptions() );
127 SETUP_VFILTER( adjust )
128 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
129 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
130 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
131 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
132 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
133 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
135 SETUP_VFILTER( extract )
136 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
138 SETUP_VFILTER( colorthres )
139 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
140 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
141 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
143 SETUP_VFILTER( invert )
145 SETUP_VFILTER( gradient )
146 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
147 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
148 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
150 SETUP_VFILTER( motionblur )
151 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
153 SETUP_VFILTER( motiondetect )
155 SETUP_VFILTER( noise )
157 SETUP_VFILTER( psychedelic )
159 SETUP_VFILTER( sharpen )
160 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
162 SETUP_VFILTER( ripple )
164 SETUP_VFILTER( wave )
166 SETUP_VFILTER( transform )
167 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
169 SETUP_VFILTER( rotate )
170 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
171 ui.rotateAngleDial->setWrapping( true );
172 ui.rotateAngleDial->setNotchesVisible( true );
174 SETUP_VFILTER( puzzle )
175 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
176 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
177 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
179 SETUP_VFILTER( magnify )
181 SETUP_VFILTER( clone )
182 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
184 SETUP_VFILTER( wall )
185 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
186 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
188 SETUP_VFILTER( panoramix )
189 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
190 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
193 SETUP_VFILTER( erase )
194 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
195 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
196 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
198 SETUP_VFILTER( marq )
199 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
200 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
202 SETUP_VFILTER( logo )
203 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
204 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
205 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
206 SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
209 #undef SETUP_VFILTER_OPTION
211 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
212 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
213 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
214 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
215 CONNECT( ui.topBotCropSync, toggled( bool ),
216 ui.cropBotPx, setDisabled( bool ) );
217 CONNECT( ui.leftRightCropSync, toggled( bool ),
218 ui.cropRightPx, setDisabled( bool ) );
221 ExtVideo::~ExtVideo()
225 void ExtVideo::cropChange()
227 p_vout = THEMIM->getVout();
230 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
231 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
232 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
233 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
234 vlc_object_release( p_vout );
238 void ExtVideo::clean()
240 ui.cropTopPx->setValue( 0 );
241 ui.cropBotPx->setValue( 0 );
242 ui.cropLeftPx->setValue( 0 );
243 ui.cropRightPx->setValue( 0 );
246 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
248 char *psz_parser, *psz_string;
249 const char *psz_filter_type;
251 module_t *p_obj = module_find( psz_name );
254 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
258 if( module_provides( p_obj, "video filter2" ) )
260 psz_filter_type = "video-filter";
262 else if( module_provides( p_obj, "video filter" ) )
264 psz_filter_type = "vout-filter";
266 else if( module_provides( p_obj, "sub filter" ) )
268 psz_filter_type = "sub-filter";
272 module_release (p_obj);
273 msg_Err( p_intf, "Unknown video filter type." );
276 module_release (p_obj);
278 psz_string = config_GetPsz( p_intf, psz_filter_type );
280 if( !psz_string ) psz_string = strdup( "" );
282 psz_parser = strstr( psz_string, psz_name );
288 psz_parser = psz_string;
289 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
290 psz_string, psz_name ) == -1 )
306 if( *( psz_parser + strlen( psz_name ) ) == ':' )
308 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
309 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
316 /* Remove trailing : : */
317 if( strlen( psz_string ) > 0 &&
318 *( psz_string + strlen( psz_string ) -1 ) == ':' )
320 *( psz_string + strlen( psz_string ) -1 ) = '\0';
329 /* Vout is not kept, so put that in the config */
330 config_PutPsz( p_intf, psz_filter_type, psz_string );
331 if( !strcmp( psz_filter_type, "video-filter" ) )
332 ui.videoFilterText->setText( psz_string );
333 else if( !strcmp( psz_filter_type, "vout-filter" ) )
334 ui.voutFilterText->setText( psz_string );
335 else if( !strcmp( psz_filter_type, "sub-filter" ) )
336 ui.subpictureFilterText->setText( psz_string );
338 /* Try to set on the fly */
339 p_vout = THEMIM->getVout();
342 if( !strcmp( psz_filter_type, "sub-filter" ) )
343 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
345 var_SetString( p_vout, psz_filter_type, psz_string );
346 vlc_object_release( p_vout );
352 void ExtVideo::updateFilters()
354 QString module = ModuleFromWidgetName( sender() );
356 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
357 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
359 ChangeVFiltersString( qtu( module ),
360 checkbox ? checkbox->isChecked()
361 : groupbox->isChecked() );
364 void ExtVideo::initComboBoxItems( QObject *widget )
366 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
367 if( !combobox ) return;
368 QString option = OptionFromWidgetName( widget );
369 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
373 int i_type = p_item->i_type & CONFIG_ITEM;
374 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
376 if( i_type == CONFIG_ITEM_INTEGER
377 || i_type == CONFIG_ITEM_BOOL )
378 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
379 p_item->pi_list[i_index] );
380 else if( i_type == CONFIG_ITEM_STRING )
381 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
382 p_item->ppsz_list[i_index] );
387 msg_Err( p_intf, "Couldn't find option \"%s\".",
392 void ExtVideo::setWidgetValue( QObject *widget )
394 QString module = ModuleFromWidgetName( widget->parent() );
395 //std::cout << "Module name: " << module.toStdString() << std::endl;
396 QString option = OptionFromWidgetName( widget );
397 //std::cout << "Option name: " << option.toStdString() << std::endl;
399 vlc_object_t *p_obj = ( vlc_object_t * )
400 vlc_object_find_name( p_intf->p_libvlc,
410 "Module instance %s not found, looking in config values.",
413 i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
416 case VLC_VAR_INTEGER:
418 val.i_int = config_GetInt( p_intf, qtu( option ) );
421 val.f_float = config_GetFloat( p_intf, qtu( option ) );
424 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
430 i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
431 var_Get( p_obj, qtu( option ), &val );
432 vlc_object_release( p_obj );
435 /* Try to cast to all the widgets we're likely to encounter. Only
436 * one of the casts is expected to work. */
437 QSlider *slider = qobject_cast<QSlider*> ( widget );
438 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
439 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
440 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
441 QDial *dial = qobject_cast<QDial*> ( widget );
442 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
443 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
445 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
447 if( slider ) slider->setValue( val.i_int );
448 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
450 else if( spinbox ) spinbox->setValue( val.i_int );
451 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
455 snprintf( str, sizeof(str), "%06X", val.i_int );
456 lineedit->setText( str );
458 else if( combobox ) combobox->setCurrentIndex(
459 combobox->findData( val.i_int ) );
460 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
462 else if( i_type == VLC_VAR_FLOAT )
464 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
465 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
466 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
468 else if( i_type == VLC_VAR_STRING )
470 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
471 else if( combobox ) combobox->setCurrentIndex(
472 combobox->findData( qfu( val.psz_string ) ) );
473 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
474 free( val.psz_string );
478 "Module %s's %s variable is of an unsupported type ( %d )",
484 void ExtVideo::updateFilterOptions()
486 QString module = ModuleFromWidgetName( sender()->parent() );
487 //std::cout << "Module name: " << module.toStdString() << std::endl;
488 QString option = OptionFromWidgetName( sender() );
489 //std::cout << "Option name: " << option.toStdString() << std::endl;
491 vlc_object_t *p_obj = ( vlc_object_t * )
492 vlc_object_find_name( p_intf->p_libvlc,
499 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
500 i_type = config_GetType( p_intf, qtu( option ) );
501 b_is_command = false;
505 i_type = var_Type( p_obj, qtu( option ) );
506 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
511 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.",
514 /* FIXME: restart automatically somewhere near the end of this function */
517 /* Try to cast to all the widgets we're likely to encounter. Only
518 * one of the casts is expected to work. */
519 QSlider *slider = qobject_cast<QSlider*> ( sender() );
520 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
521 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
522 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
523 QDial *dial = qobject_cast<QDial*> ( sender() );
524 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
525 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
528 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
531 if( slider ) i_int = slider->value();
532 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
533 else if( spinbox ) i_int = spinbox->value();
534 else if( dial ) i_int = ( 540-dial->value() )%360;
535 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
536 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
537 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
538 config_PutInt( p_intf, qtu( option ), i_int );
541 if( i_type == VLC_VAR_INTEGER )
542 var_SetInteger( p_obj, qtu( option ), i_int );
544 var_SetBool( p_obj, qtu( option ), i_int );
547 else if( i_type == VLC_VAR_FLOAT )
550 if( slider ) f_float = ( double )slider->value()
551 / ( double )slider->tickInterval(); /* hack alert! */
552 else if( doublespinbox ) f_float = doublespinbox->value();
553 else if( lineedit ) f_float = lineedit->text().toDouble();
554 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
555 config_PutFloat( p_intf, qtu( option ), f_float );
557 var_SetFloat( p_obj, qtu( option ), f_float );
559 else if( i_type == VLC_VAR_STRING )
561 char *psz_string = NULL;
562 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
563 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
564 combobox->currentIndex() ).toString() ) );
565 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
566 config_PutPsz( p_intf, qtu( option ), psz_string );
568 var_SetString( p_obj, qtu( option ), psz_string );
573 "Module %s's %s variable is of an unsupported type ( %d )",
578 if( p_obj ) vlc_object_release( p_obj );
582 void ExtVideo::gotoConf( QObject* src )
584 #define SHOWCONF( module ) \
585 if( src->objectName().contains( module ) ) \
587 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
591 SHOWCONF( "magnify" );
593 SHOWCONF( "ripple" );
594 SHOWCONF( "invert" );
595 SHOWCONF( "puzzle" );
597 SHOWCONF( "gradient" );
598 SHOWCONF( "colorthres" )
602 /**********************************************************************
604 **********************************************************************/
606 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
607 : QWidget( _parent ), p_intf( _p_intf )
611 BUTTONACT( ui.refresh, Refresh() );
621 void ExtV4l2::showEvent( QShowEvent *event )
623 QWidget::showEvent( event );
627 void ExtV4l2::Refresh( void )
629 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
633 ui.vboxLayout->removeWidget( box );
639 vlc_value_t val, text, name;
640 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
644 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
646 vlc_object_release( p_obj );
650 box = new QGroupBox( this );
651 ui.vboxLayout->addWidget( box );
652 QVBoxLayout *layout = new QVBoxLayout( box );
653 box->setLayout( layout );
655 for( int i = 0; i < val.p_list->i_count; i++ )
657 const char *psz_var = text.p_list->p_values[i].psz_string;
658 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
659 const char *psz_label = name.psz_string;
660 msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
661 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
663 int i_type = var_Type( p_obj, psz_var );
664 switch( i_type & VLC_VAR_TYPE )
666 case VLC_VAR_INTEGER:
668 QLabel *label = new QLabel( psz_label, box );
669 QHBoxLayout *hlayout = new QHBoxLayout();
670 hlayout->addWidget( label );
671 int i_val = var_GetInteger( p_obj, psz_var );
672 if( i_type & VLC_VAR_HASCHOICE )
674 QComboBox *combobox = new QComboBox( box );
675 combobox->setObjectName( psz_var );
677 vlc_value_t val2, text2;
678 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
680 for( int j = 0; j < val2.p_list->i_count; j++ )
683 text2.p_list->p_values[j].psz_string,
684 val2.p_list->p_values[j].i_int );
685 if( i_val == val2.p_list->p_values[j].i_int )
686 combobox->setCurrentIndex( j );
688 var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
691 CONNECT( combobox, currentIndexChanged( int ), this,
692 ValueChange( int ) );
693 hlayout->addWidget( combobox );
697 QSlider *slider = new QSlider( box );
698 slider->setObjectName( psz_var );
699 slider->setOrientation( Qt::Horizontal );
701 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
703 slider->setMinimum( val2.i_int );
704 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
706 slider->setMaximum( val2.i_int );
707 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
709 slider->setSingleStep( val2.i_int );
710 slider->setValue( i_val );
712 CONNECT( slider, valueChanged( int ), this,
713 ValueChange( int ) );
714 hlayout->addWidget( slider );
716 layout->addLayout( hlayout );
721 QCheckBox *button = new QCheckBox( psz_label, box );
722 button->setObjectName( psz_var );
723 button->setChecked( var_GetBool( p_obj, psz_var ) );
725 CONNECT( button, clicked( bool ), this,
726 ValueChange( bool ) );
727 layout->addWidget( button );
732 if( i_type & VLC_VAR_ISCOMMAND )
734 QPushButton *button = new QPushButton( psz_label, box );
735 button->setObjectName( psz_var );
737 CONNECT( button, clicked( bool ), this,
738 ValueChange( bool ) );
739 layout->addWidget( button );
743 QLabel *label = new QLabel( psz_label, box );
744 layout->addWidget( label );
749 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
752 free( name.psz_string );
754 var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
755 vlc_object_release( p_obj );
759 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
764 void ExtV4l2::ValueChange( bool value )
766 ValueChange( (int)value );
769 void ExtV4l2::ValueChange( int value )
771 QObject *s = sender();
772 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
775 char *psz_var = strdup( qtu( s->objectName() ) );
776 int i_type = var_Type( p_obj, psz_var );
777 switch( i_type & VLC_VAR_TYPE )
779 case VLC_VAR_INTEGER:
780 if( i_type & VLC_VAR_HASCHOICE )
782 QComboBox *combobox = qobject_cast<QComboBox*>( s );
783 value = combobox->itemData( value ).toInt();
785 var_SetInteger( p_obj, psz_var, value );
788 var_SetBool( p_obj, psz_var, value );
791 var_SetVoid( p_obj, psz_var );
795 vlc_object_release( p_obj );
799 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
804 /**********************************************************************
806 **********************************************************************/
808 static const QString band_frequencies[] =
810 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
811 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
814 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
815 QWidget( _parent ) , p_intf( _p_intf )
817 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
818 smallFont.setPointSize( smallFont.pointSize() - 3 );
821 ui.preampLabel->setFont( smallFont );
823 /* Setup of presetsComboBox */
824 presetsComboBox = ui.presetsCombo;
825 CONNECT( presetsComboBox, currentIndexChanged( int ),
826 this, updateUISliderValues( int ) );
827 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
829 /* Add the sliders for the Bands */
830 QGridLayout *grid = new QGridLayout( ui.frame );
831 grid->setMargin( 0 );
832 for( int i = 0 ; i < BANDS ; i++ )
834 bands[i] = new QSlider( Qt::Vertical );
835 bands[i]->setMaximum( 400 );
836 bands[i]->setValue( 200 );
837 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
839 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
840 band_texts[i]->setFont( smallFont );
842 grid->addWidget( bands[i], 0, i );
843 grid->addWidget( band_texts[i], 1, i );
846 /* Add the listed presets */
847 for( int i = 0 ; i < NB_PRESETS ; i ++ )
849 presetsComboBox->addItem( qtr( preset_list_text[i] ),
850 QVariant( preset_list[i] ) );
854 BUTTONACT( ui.enableCheck, enable() );
855 BUTTONACT( ui.eq2PassCheck, set2Pass() );
856 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
858 /* Do the update from the value of the core */
862 Equalizer::~Equalizer()
866 void Equalizer::clean()
870 /* Write down initial values */
871 void Equalizer::updateUIFromCore()
873 char *psz_af, *psz_pres;
877 aout_instance_t *p_aout = THEMIM->getAout();
880 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
881 psz_pres = var_GetString( p_aout, "equalizer-preset" );
882 if( var_GetBool( p_aout, "equalizer-2pass" ) )
883 ui.eq2PassCheck->setChecked( true );
884 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
885 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
886 vlc_object_release( p_aout );
890 psz_af = config_GetPsz( p_intf, "audio-filter" );
891 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
892 if( config_GetInt( p_intf, "equalizer-2pass" ) )
893 ui.eq2PassCheck->setChecked( true );
894 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
895 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
897 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
898 ui.enableCheck->setChecked( true );
899 enable( ui.enableCheck->isChecked() );
901 presetsComboBox->setCurrentIndex( i_preset );
907 /* Functin called when enableButton is toggled */
908 void Equalizer::enable()
910 bool en = ui.enableCheck->isChecked();
911 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
913 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
914 // en ? true : false );
915 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
916 // en ? true : false );
919 if( presetsComboBox->currentIndex() < 0 )
920 presetsComboBox->setCurrentIndex( 0 );
924 void Equalizer::enable( bool en )
926 ui.eq2PassCheck->setEnabled( en );
927 presetsComboBox->setEnabled( en );
928 ui.presetLabel->setEnabled( en );
929 ui.preampLabel->setEnabled( en );
930 ui.preampSlider->setEnabled( en );
931 for( int i = 0 ; i< BANDS; i++ )
933 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
937 /* Function called when the set2Pass button is activated */
938 void Equalizer::set2Pass()
940 aout_instance_t *p_aout= THEMIM->getAout();
941 bool b_2p = ui.eq2PassCheck->isChecked();
944 config_PutInt( p_intf, "equalizer-2pass", b_2p );
947 var_SetBool( p_aout, "equalizer-2pass", b_2p );
948 config_PutInt( p_intf, "equalizer-2pass", b_2p );
949 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
951 p_aout->pp_inputs[i]->b_restart = true;
953 vlc_object_release( p_aout );
957 /* Function called when the preamp slider is moved */
958 void Equalizer::setPreamp()
960 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
961 aout_instance_t *p_aout = THEMIM->getAout();
963 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
967 //delCallbacks( p_aout );
968 var_SetFloat( p_aout, "equalizer-preamp", f );
969 //addCallbacks( p_aout );
970 vlc_object_release( p_aout );
972 config_PutFloat( p_intf, "equalizer-preamp", f );
975 void Equalizer::setCoreBands()
977 /**\todo smoothing */
980 for( int i = 0; i < BANDS; i++ )
982 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
983 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
985 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
988 const char *psz_values = values.toAscii().constData();
990 aout_instance_t *p_aout = THEMIM->getAout();
993 //delCallbacks( p_aout );
994 var_SetString( p_aout, "equalizer-bands", psz_values );
995 //addCallbacks( p_aout );
996 vlc_object_release( p_aout );
1000 void Equalizer::updateUISliderValues( int i_preset )
1002 if( i_preset < 0 ) return;
1004 char *p = createValuesFromPreset( i_preset );
1006 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1010 for( int i = 0; i < BANDS; i++ )
1012 const float f = us_strtod(p, &p );
1014 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1016 band_texts[i]->setText( band_frequencies[i] + "\n"
1017 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1018 if( p == NULL || *p == '\0' )
1026 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1027 ui.preampLabel->setText( qtr( "Preamp\n" )
1028 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1031 char * Equalizer::createValuesFromPreset( int i_preset )
1036 /* Create the QString in Qt */
1037 for( int i = 0 ; i< BANDS ;i++ )
1038 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1040 /* Convert it to char * */
1041 if( !asprintf( &psz_values, "%s", values.toAscii().constData() ) )
1047 void Equalizer::setCorePreset( int i_preset )
1049 char *psz_values = createValuesFromPreset( i_preset );
1050 if( !psz_values ) return ;
1052 aout_instance_t *p_aout= THEMIM->getAout();
1055 delCallbacks( p_aout );
1056 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1058 var_SetString( p_aout, "equalizer-bands", psz_values );
1059 var_SetFloat( p_aout, "equalizer-preamp",
1060 eqz_preset_10b[i_preset]->f_preamp );
1061 addCallbacks( p_aout );
1062 vlc_object_release( p_aout );
1064 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1065 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1066 config_PutFloat( p_intf, "equalizer-preamp",
1067 eqz_preset_10b[i_preset]->f_preamp );
1070 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1071 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1073 char *psz_preset = newval.psz_string;
1074 Equalizer *eq = ( Equalizer * )p_data;
1075 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1076 eq->presetsComboBox->setCurrentIndex( i_preset );
1080 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1082 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1083 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1084 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1087 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1089 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1090 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1091 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1094 /**********************************************************************
1096 **********************************************************************/
1098 /**********************************************************************
1100 **********************************************************************/
1101 static const char *psz_control_names[] =
1103 "spatializer-roomsize", "spatializer-width",
1104 "spatializer-wet", "spatializer-dry", "spatializer-damp"
1107 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1108 QWidget( _parent ) , p_intf( _p_intf )
1110 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1111 smallFont.setPointSize( smallFont.pointSize() - 3 );
1113 QGridLayout *layout = new QGridLayout( this );
1114 layout->setMargin( 0 );
1116 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1117 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1119 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1121 spatCtrl[i] = new QSlider( Qt::Vertical );
1124 spatCtrl[i]->setMaximum( 10 );
1125 spatCtrl[i]->setValue( 2 );
1129 spatCtrl[i]->setMaximum( 10 );
1130 spatCtrl[i]->setValue( 0 );
1131 spatCtrl[i]->setMinimum( -10 );
1133 oldControlVars[i] = spatCtrl[i]->value();
1134 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1135 ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1136 ctrl_texts[i]->setFont( smallFont );
1137 ctrl_readout[i] = new QLabel( "" );
1138 ctrl_readout[i]->setFont( smallFont );
1139 layout->addWidget( spatCtrl[i], 1, i );
1140 layout->addWidget( ctrl_readout[i], 2, i );
1141 layout->addWidget( ctrl_texts[i], 3, i );
1144 BUTTONACT( enableCheck, enable() );
1146 /* Write down initial values */
1147 aout_instance_t *p_aout = THEMIM->getAout();
1152 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1153 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1155 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1157 vlc_object_release( p_aout );
1161 psz_af = config_GetPsz( p_intf, "audio-filter" );
1162 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1164 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1167 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1168 enableCheck->setChecked( true );
1170 enable( enableCheck->isChecked() );
1171 setValues( controlVars );
1174 Spatializer::~Spatializer()
1178 void Spatializer::enable()
1180 bool en = enableCheck->isChecked();
1181 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1182 en ? true : false );
1186 void Spatializer::enable( bool en )
1188 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1190 spatCtrl[i]->setEnabled( en );
1191 ctrl_texts[i]->setEnabled( en );
1192 ctrl_readout[i]->setEnabled( en );
1195 void Spatializer::setInitValues()
1197 setValues( controlVars );
1200 void Spatializer::setValues( float *controlVars )
1202 aout_instance_t *p_aout = THEMIM->getAout();
1204 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1206 float f = (float)( spatCtrl[i]->value() );
1207 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1211 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1213 if( oldControlVars[i] != spatCtrl[i]->value() )
1215 var_SetFloat( p_aout, psz_control_names[i],
1216 ( float )spatCtrl[i]->value() );
1217 config_PutFloat( p_intf, psz_control_names[i],
1218 ( float ) spatCtrl[i]->value() );
1219 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1222 vlc_object_release( p_aout );
1226 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1228 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1229 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1232 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1234 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1235 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1238 #include <QToolButton>
1239 #include <QGridLayout>
1241 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1242 QWidget( _parent ) , p_intf( _p_intf )
1244 QGroupBox *AVBox, *subsBox;
1246 QToolButton *moinsAV, *plusAV;
1247 QToolButton *moinssubs, *plussubs;
1248 QToolButton *moinssubSpeed, *plussubSpeed;
1250 QToolButton *updateButton;
1252 b_userAction = true;
1254 QGridLayout *mainLayout = new QGridLayout( this );
1257 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1258 QGridLayout *AVLayout = new QGridLayout( AVBox );
1260 moinsAV = new QToolButton;
1261 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1262 moinsAV->setAutoRaise( true );
1263 moinsAV->setText( "-" );
1264 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1266 plusAV = new QToolButton;
1267 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1268 plusAV->setAutoRaise( true );
1269 plusAV->setText( "+" );
1270 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1272 QLabel *AVLabel = new QLabel;
1273 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1274 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1276 AVSpin = new QDoubleSpinBox;
1277 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1278 AVSpin->setDecimals( 3 );
1279 AVSpin->setMinimum( -100.0 );
1280 AVSpin->setMaximum( 100.0 );
1281 AVSpin->setSingleStep( 0.1 );
1282 AVSpin->setToolTip( qtr( "A positive value means that\n"
1283 "the audio is ahead of the video" ) );
1284 AVSpin->setSuffix( " s" );
1285 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1286 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1290 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1291 QGridLayout *subsLayout = new QGridLayout( subsBox );
1293 moinssubs = new QToolButton;
1294 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1295 moinssubs->setAutoRaise( true );
1296 moinssubs->setText( "-" );
1297 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1299 plussubs = new QToolButton;
1300 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1301 plussubs->setAutoRaise( true );
1302 plussubs->setText( "+" );
1303 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1305 QLabel *subsLabel = new QLabel;
1306 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1307 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1309 subsSpin = new QDoubleSpinBox;
1310 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1311 subsSpin->setDecimals( 3 );
1312 subsSpin->setMinimum( -100.0 );
1313 subsSpin->setMaximum( 100.0 );
1314 subsSpin->setSingleStep( 0.1 );
1315 subsSpin->setToolTip( qtr( "A positive value means that\n"
1316 "the subtitles are ahead of the video" ) );
1317 subsSpin->setSuffix( " s" );
1318 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1321 moinssubSpeed = new QToolButton;
1322 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1323 moinssubSpeed->setAutoRaise( true );
1324 moinssubSpeed->setText( "-" );
1325 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1327 plussubSpeed = new QToolButton;
1328 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1329 plussubSpeed->setAutoRaise( true );
1330 plussubSpeed->setText( "+" );
1331 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1333 QLabel *subSpeedLabel = new QLabel;
1334 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1335 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1337 subSpeedSpin = new QDoubleSpinBox;
1338 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1339 subSpeedSpin->setDecimals( 3 );
1340 subSpeedSpin->setMinimum( 1 );
1341 subSpeedSpin->setMaximum( 100 );
1342 subSpeedSpin->setSingleStep( 0.2 );
1343 subSpeedSpin->setSuffix( " fps" );
1344 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1346 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1348 updateButton = new QToolButton;
1349 updateButton->setAutoRaise( true );
1350 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1353 /* Various Connects */
1354 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1355 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1356 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1357 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1358 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1359 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1360 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1361 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1362 CONNECT( subSpeedSpin, valueChanged ( double ),
1363 this, adjustSubsSpeed( double ) );
1365 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1366 BUTTON_SET_ACT_I( updateButton, "", update,
1367 qtr( "Force update of this dialog's values" ), update() );
1373 void SyncControls::clean()
1375 b_userAction = false;
1376 AVSpin->setValue( 0.0 );
1377 subsSpin->setValue( 0.0 );
1378 subSpeedSpin->setValue( 1.0 );
1379 b_userAction = true;
1382 void SyncControls::update()
1384 b_userAction = false;
1387 if( THEMIM->getInput() )
1389 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1390 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1391 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1392 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1393 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1395 b_userAction = true;
1398 void SyncControls::advanceAudio( double f_advance )
1400 if( THEMIM->getInput() && b_userAction )
1402 int64_t i_delay = f_advance * 1000000;
1403 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1407 void SyncControls::advanceSubs( double f_advance )
1409 if( THEMIM->getInput() && b_userAction )
1411 int64_t i_delay = f_advance * 1000000;
1412 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1416 void SyncControls::adjustSubsSpeed( double f_fps )
1418 if( THEMIM->getInput() && b_userAction )
1420 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1424 /**********************************************************************
1425 * Video filters / Adjust
1426 **********************************************************************/
1428 /**********************************************************************
1429 * Extended playbak controls
1430 **********************************************************************/