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 );
99 #define SETUP_VFILTER( widget ) \
101 vlc_object_t *p_obj = ( vlc_object_t * ) \
102 vlc_object_find_name( p_intf->p_libvlc, \
105 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
106 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
109 vlc_object_release( p_obj ); \
110 if( checkbox ) checkbox->setChecked( true ); \
111 else groupbox->setChecked( true ); \
115 if( checkbox ) checkbox->setChecked( false ); \
116 else groupbox->setChecked( false ); \
119 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
120 #define SETUP_VFILTER_OPTION( widget, signal ) \
121 initComboBoxItems( ui.widget ); \
122 setWidgetValue( ui.widget ); \
123 CONNECT( ui.widget, signal, this, updateFilterOptions() );
125 SETUP_VFILTER( adjust )
126 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
127 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
128 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
129 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
130 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
131 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
133 SETUP_VFILTER( extract )
134 SETUP_VFILTER_OPTION( extractComponentText, textChanged( QString ) )
136 SETUP_VFILTER( colorthres )
137 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( QString ) )
138 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
139 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
141 SETUP_VFILTER( invert )
143 SETUP_VFILTER( gradient )
144 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
145 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
146 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
148 SETUP_VFILTER( motionblur )
149 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
151 SETUP_VFILTER( motiondetect )
153 SETUP_VFILTER( noise )
155 SETUP_VFILTER( psychedelic )
157 SETUP_VFILTER( sharpen )
158 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
160 SETUP_VFILTER( ripple )
162 SETUP_VFILTER( wave )
164 SETUP_VFILTER( transform )
165 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
167 SETUP_VFILTER( rotate )
168 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
169 ui.rotateAngleDial->setWrapping( true );
170 ui.rotateAngleDial->setNotchesVisible( true );
172 SETUP_VFILTER( puzzle )
173 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
174 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
175 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
177 SETUP_VFILTER( magnify )
179 SETUP_VFILTER( clone )
180 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
182 SETUP_VFILTER( wall )
183 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
184 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
186 SETUP_VFILTER( panoramix )
187 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
188 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
191 SETUP_VFILTER( erase )
192 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
193 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
194 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
196 SETUP_VFILTER( marq )
197 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( QString ) )
198 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
200 SETUP_VFILTER( logo )
201 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
202 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
203 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
204 SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
207 #undef SETUP_VFILTER_OPTION
209 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
210 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
211 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
212 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
213 CONNECT( ui.topBotCropSync, toggled( bool ),
214 ui.cropBotPx, setDisabled( bool ) );
215 CONNECT( ui.leftRightCropSync, toggled( bool ),
216 ui.cropRightPx, setDisabled( bool ) );
219 ExtVideo::~ExtVideo()
223 void ExtVideo::cropChange()
225 if( THEMIM->getInput() )
227 p_vout = ( vout_thread_t * )vlc_object_find( THEMIM->getInput(),
228 VLC_OBJECT_VOUT, FIND_CHILD );
231 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
232 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
233 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
234 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
236 vlc_object_release( p_vout );
240 void ExtVideo::ChangeVFiltersString( char *psz_name, bool b_add )
242 char *psz_parser, *psz_string;
243 const char *psz_filter_type;
245 /* Please leave p_libvlc_global. This is where cached modules are
246 * stored. We're not trying to find a module instance. */
247 module_t *p_obj = module_Find( p_intf, psz_name );
250 msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
254 if( module_IsCapable( p_obj, "video filter2" ) )
256 psz_filter_type = "video-filter";
258 else if( module_IsCapable( p_obj, "video filter" ) )
260 psz_filter_type = "vout-filter";
262 else if( module_IsCapable( p_obj, "sub filter" ) )
264 psz_filter_type = "sub-filter";
269 msg_Err( p_intf, "Unknown video filter type." );
274 psz_string = config_GetPsz( p_intf, psz_filter_type );
276 if( !psz_string ) psz_string = strdup( "" );
278 psz_parser = strstr( psz_string, psz_name );
284 psz_parser = psz_string;
285 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
286 psz_string, psz_name ) == -1 )
302 if( *( psz_parser + strlen( psz_name ) ) == ':' )
304 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
305 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
312 /* Remove trailing : : */
313 if( strlen( psz_string ) > 0 &&
314 *( psz_string + strlen( psz_string ) -1 ) == ':' )
316 *( psz_string + strlen( psz_string ) -1 ) = '\0';
325 /* Vout is not kept, so put that in the config */
326 config_PutPsz( p_intf, psz_filter_type, psz_string );
327 if( !strcmp( psz_filter_type, "video-filter" ) )
328 ui.videoFilterText->setText( psz_string );
329 else if( !strcmp( psz_filter_type, "vout-filter" ) )
330 ui.voutFilterText->setText( psz_string );
331 else if( !strcmp( psz_filter_type, "sub-filter" ) )
332 ui.subpictureFilterText->setText( psz_string );
334 /* Try to set on the fly */
335 if( THEMIM->getInput() )
336 p_vout = ( vout_thread_t * )vlc_object_find( THEMIM->getInput(),
337 VLC_OBJECT_VOUT, FIND_CHILD );
340 if( !strcmp( psz_filter_type, "sub-filter" ) )
341 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
343 var_SetString( p_vout, psz_filter_type, psz_string );
344 vlc_object_release( p_vout );
350 void ExtVideo::updateFilters()
352 QString module = ModuleFromWidgetName( sender() );
354 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
355 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
357 ChangeVFiltersString( qtu( module ),
358 checkbox ? checkbox->isChecked()
359 : groupbox->isChecked() );
362 void ExtVideo::initComboBoxItems( QObject *widget )
364 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
365 if( !combobox ) return;
366 QString option = OptionFromWidgetName( widget );
367 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
371 int i_type = p_item->i_type & CONFIG_ITEM;
372 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
374 if( i_type == CONFIG_ITEM_INTEGER
375 || i_type == CONFIG_ITEM_BOOL )
376 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
377 p_item->pi_list[i_index] );
378 else if( i_type == CONFIG_ITEM_STRING )
379 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
380 p_item->ppsz_list[i_index] );
385 msg_Err( p_intf, "Couldn't find option \"%s\".",
390 void ExtVideo::setWidgetValue( QObject *widget )
392 QString module = ModuleFromWidgetName( widget->parent() );
393 //std::cout << "Module name: " << module.toStdString() << std::endl;
394 QString option = OptionFromWidgetName( widget );
395 //std::cout << "Option name: " << option.toStdString() << std::endl;
397 vlc_object_t *p_obj = ( vlc_object_t * )
398 vlc_object_find_name( p_intf->p_libvlc,
408 "Module instance %s not found, looking in config values.",
411 i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
414 case VLC_VAR_INTEGER:
416 val.i_int = config_GetInt( p_intf, qtu( option ) );
419 val.f_float = config_GetFloat( p_intf, qtu( option ) );
422 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
428 i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
429 var_Get( p_obj, qtu( option ), &val );
430 vlc_object_release( p_obj );
433 /* Try to cast to all the widgets we're likely to encounter. Only
434 * one of the casts is expected to work. */
435 QSlider *slider = qobject_cast<QSlider*> ( widget );
436 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
437 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
438 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
439 QDial *dial = qobject_cast<QDial*> ( widget );
440 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
441 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
443 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
446 if( slider ) slider->setValue( val.i_int );
447 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
449 else if( spinbox ) spinbox->setValue( val.i_int );
450 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
454 snprintf( str, sizeof(str), "%06X", val.i_int );
455 lineedit->setText( str );
457 else if( combobox ) combobox->setCurrentIndex(
458 combobox->findData( val.i_int ) );
459 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
461 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,
497 msg_Err( p_intf, "Module %s not found.", qtu( module ) );
501 int i_type = var_Type( p_obj, qtu( option ) );
502 bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
505 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.",
508 /* FIXME: restart automatically somewhere near the end of this function */
511 /* Try to cast to all the widgets we're likely to encounter. Only
512 * one of the casts is expected to work. */
513 QSlider *slider = qobject_cast<QSlider*> ( sender() );
514 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
515 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
516 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
517 QDial *dial = qobject_cast<QDial*> ( sender() );
518 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
519 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
522 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
525 if( slider ) i_int = slider->value();
526 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
527 else if( spinbox ) i_int = spinbox->value();
528 else if( dial ) i_int = ( 540-dial->value() )%360;
529 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
530 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
531 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
532 config_PutInt( p_intf, qtu( option ), i_int );
535 if( i_type == VLC_VAR_INTEGER )
536 var_SetInteger( p_obj, qtu( option ), i_int );
538 var_SetBool( p_obj, qtu( option ), i_int );
541 else if( i_type == VLC_VAR_FLOAT )
544 if( slider ) f_float = ( double )slider->value()
545 / ( double )slider->tickInterval(); /* hack alert! */
546 else if( doublespinbox ) f_float = doublespinbox->value();
547 else if( lineedit ) f_float = lineedit->text().toDouble();
548 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
549 config_PutFloat( p_intf, qtu( option ), f_float );
551 var_SetFloat( p_obj, qtu( option ), f_float );
553 else if( i_type == VLC_VAR_STRING )
555 char *psz_string = NULL;
556 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
557 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
558 combobox->currentIndex() ).toString() ) );
559 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
560 config_PutPsz( p_intf, qtu( option ), psz_string );
562 var_SetString( p_obj, qtu( option ), psz_string );
567 "Module %s's %s variable is of an unsupported type ( %d )",
572 vlc_object_release( p_obj );
576 void ExtVideo::gotoConf( QObject* src )
578 #define SHOWCONF( module ) \
579 if( src->objectName().contains( module ) ) \
581 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
585 SHOWCONF( "magnify" );
587 SHOWCONF( "ripple" );
588 SHOWCONF( "invert" );
589 SHOWCONF( "puzzle" );
591 SHOWCONF( "gradient" );
592 SHOWCONF( "colorthres" )
596 /**********************************************************************
598 **********************************************************************/
600 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
601 : QWidget( _parent ), p_intf( _p_intf )
605 BUTTONACT( ui.refresh, Refresh() );
616 void ExtV4l2::showEvent( QShowEvent *event )
618 QWidget::showEvent( event );
622 void ExtV4l2::Refresh( void )
624 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
628 ui.vboxLayout->removeWidget( box );
634 vlc_value_t val, text, name;
635 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
639 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
641 vlc_object_release( p_obj );
645 box = new QGroupBox( this );
646 ui.vboxLayout->addWidget( box );
647 QVBoxLayout *layout = new QVBoxLayout( box );
648 box->setLayout( layout );
650 for( int i = 0; i < val.p_list->i_count; i++ )
652 const char *psz_var = text.p_list->p_values[i].psz_string;
653 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
654 const char *psz_label = name.psz_string;
655 msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
656 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
658 int i_type = var_Type( p_obj, psz_var );
659 switch( i_type & VLC_VAR_TYPE )
661 case VLC_VAR_INTEGER:
663 QLabel *label = new QLabel( psz_label, box );
664 QHBoxLayout *hlayout = new QHBoxLayout();
665 hlayout->addWidget( label );
666 int i_val = var_GetInteger( p_obj, psz_var );
667 if( i_type & VLC_VAR_HASCHOICE )
669 QComboBox *combobox = new QComboBox( box );
670 combobox->setObjectName( psz_var );
672 vlc_value_t val2, text2;
673 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
675 for( int j = 0; j < val2.p_list->i_count; j++ )
678 text2.p_list->p_values[j].psz_string,
679 val2.p_list->p_values[j].i_int );
680 if( i_val == val2.p_list->p_values[j].i_int )
681 combobox->setCurrentIndex( j );
683 var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
686 CONNECT( combobox, currentIndexChanged( int ), this,
687 ValueChange( int ) );
688 hlayout->addWidget( combobox );
692 QSlider *slider = new QSlider( box );
693 slider->setObjectName( psz_var );
694 slider->setOrientation( Qt::Horizontal );
696 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
698 slider->setMinimum( val2.i_int );
699 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
701 slider->setMaximum( val2.i_int );
702 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
704 slider->setSingleStep( val2.i_int );
705 slider->setValue( i_val );
707 CONNECT( slider, valueChanged( int ), this,
708 ValueChange( int ) );
709 hlayout->addWidget( slider );
711 layout->addLayout( hlayout );
716 QCheckBox *button = new QCheckBox( psz_label, box );
717 button->setObjectName( psz_var );
718 button->setChecked( var_GetBool( p_obj, psz_var ) );
720 CONNECT( button, clicked( bool ), this,
721 ValueChange( bool ) );
722 layout->addWidget( button );
727 if( i_type & VLC_VAR_ISCOMMAND )
729 QPushButton *button = new QPushButton( psz_label, box );
730 button->setObjectName( psz_var );
732 CONNECT( button, clicked( bool ), this,
733 ValueChange( bool ) );
734 layout->addWidget( button );
738 QLabel *label = new QLabel( psz_label, box );
739 layout->addWidget( label );
744 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
747 free( name.psz_string );
749 var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
750 vlc_object_release( p_obj );
754 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
759 void ExtV4l2::ValueChange( bool value )
761 ValueChange( (int)value );
764 void ExtV4l2::ValueChange( int value )
766 QObject *s = sender();
767 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
770 char *psz_var = strdup( qtu( s->objectName() ) );
771 int i_type = var_Type( p_obj, psz_var );
772 switch( i_type & VLC_VAR_TYPE )
774 case VLC_VAR_INTEGER:
775 if( i_type & VLC_VAR_HASCHOICE )
777 QComboBox *combobox = qobject_cast<QComboBox*>( s );
778 value = combobox->itemData( value ).toInt();
780 var_SetInteger( p_obj, psz_var, value );
783 var_SetBool( p_obj, psz_var, value );
786 var_SetVoid( p_obj, psz_var );
790 vlc_object_release( p_obj );
794 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
799 /**********************************************************************
801 **********************************************************************/
803 static const QString band_frequencies[] =
805 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
806 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
809 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
810 QWidget( _parent ) , p_intf( _p_intf )
812 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
813 smallFont.setPointSize( smallFont.pointSize() - 3 );
816 ui.preampLabel->setFont( smallFont );
818 /* Setup of presetsComboBox */
819 presetsComboBox = ui.presetsCombo;
820 CONNECT( presetsComboBox, currentIndexChanged( int ),
821 this, updateUISliderValues( int ) );
822 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
824 /* Add the sliders for the Bands */
825 QGridLayout *grid = new QGridLayout( ui.frame );
826 grid->setMargin( 0 );
827 for( int i = 0 ; i < BANDS ; i++ )
829 bands[i] = new QSlider( Qt::Vertical );
830 bands[i]->setMaximum( 400 );
831 bands[i]->setValue( 200 );
832 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
834 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
835 band_texts[i]->setFont( smallFont );
837 grid->addWidget( bands[i], 0, i );
838 grid->addWidget( band_texts[i], 1, i );
841 /* Add the listed presets */
842 for( int i = 0 ; i < NB_PRESETS ; i ++ )
844 presetsComboBox->addItem( qtr( preset_list_text[i] ),
845 QVariant( preset_list[i] ) );
849 BUTTONACT( ui.enableCheck, enable() );
850 BUTTONACT( ui.eq2PassCheck, set2Pass() );
851 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
853 /* Do the update from the value of the core */
857 Equalizer::~Equalizer()
861 /* Write down initial values */
862 void Equalizer::updateUIFromCore()
868 aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
869 VLC_OBJECT_AOUT, FIND_ANYWHERE );
872 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
873 if( var_GetBool( p_aout, "equalizer-2pass" ) )
874 ui.eq2PassCheck->setChecked( true );
875 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
876 i_preset = presetsComboBox->findData( QVariant(
877 var_GetString( p_aout, "equalizer-preset" ) ) );
878 vlc_object_release( p_aout );
882 psz_af = config_GetPsz( p_intf, "audio-filter" );
883 if( config_GetInt( p_intf, "equalizer-2pass" ) )
884 ui.eq2PassCheck->setChecked( true );
885 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
886 i_preset = presetsComboBox->findData( QVariant(
887 config_GetPsz( p_intf, "equalizer-preset" ) ) );
889 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
890 ui.enableCheck->setChecked( true );
891 enable( ui.enableCheck->isChecked() );
893 presetsComboBox->setCurrentIndex( i_preset );
898 /* Functin called when enableButton is toggled */
899 void Equalizer::enable()
901 bool en = ui.enableCheck->isChecked();
902 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
904 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
905 // en ? true : false );
906 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
907 // en ? true : false );
910 if( presetsComboBox->currentIndex() < 0 )
911 presetsComboBox->setCurrentIndex( 0 );
915 void Equalizer::enable( bool en )
917 ui.eq2PassCheck->setEnabled( en );
918 presetsComboBox->setEnabled( en );
919 ui.presetLabel->setEnabled( en );
920 ui.preampLabel->setEnabled( en );
921 ui.preampSlider->setEnabled( en );
922 for( int i = 0 ; i< BANDS; i++ )
924 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
928 /* Function called when the set2Pass button is activated */
929 void Equalizer::set2Pass()
931 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
932 VLC_OBJECT_AOUT, FIND_ANYWHERE );
933 bool b_2p = ui.eq2PassCheck->isChecked();
936 config_PutInt( p_intf, "equalizer-2pass", b_2p );
939 var_SetBool( p_aout, "equalizer-2pass", b_2p );
940 config_PutInt( p_intf, "equalizer-2pass", b_2p );
941 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
943 p_aout->pp_inputs[i]->b_restart = true;
945 vlc_object_release( p_aout );
949 /* Function called when the preamp slider is moved */
950 void Equalizer::setPreamp()
952 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
953 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
954 VLC_OBJECT_AOUT, FIND_ANYWHERE );
956 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
960 //delCallbacks( p_aout );
961 var_SetFloat( p_aout, "equalizer-preamp", f );
962 //addCallbacks( p_aout );
963 vlc_object_release( p_aout );
965 config_PutFloat( p_intf, "equalizer-preamp", f );
968 void Equalizer::setCoreBands()
970 /**\todo smoothing */
973 for( int i = 0; i < BANDS; i++ )
975 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
976 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
978 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
981 const char *psz_values = values.toAscii().constData();
983 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
984 VLC_OBJECT_AOUT, FIND_ANYWHERE );
987 //delCallbacks( p_aout );
988 var_SetString( p_aout, "equalizer-bands", psz_values );
989 //addCallbacks( p_aout );
990 vlc_object_release( p_aout );
994 void Equalizer::updateUISliderValues( int i_preset )
996 if( i_preset < 0 ) return;
998 char *p = createValuesFromPreset( i_preset );
1000 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1004 for( int i = 0; i < BANDS; i++ )
1006 const float f = us_strtod(p, &p );
1008 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1010 band_texts[i]->setText( band_frequencies[i] + "\n"
1011 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1012 if( p == NULL || *p == '\0' )
1020 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1021 ui.preampLabel->setText( qtr( "Preamp\n" )
1022 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1025 char * Equalizer::createValuesFromPreset( int i_preset )
1030 /* Create the QString in Qt */
1031 for( int i = 0 ; i< BANDS ;i++ )
1032 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1034 /* Convert it to char * */
1035 if( !asprintf( &psz_values, "%s", values.toAscii().constData() ) )
1041 void Equalizer::setCorePreset( int i_preset )
1043 char *psz_values = createValuesFromPreset( i_preset );
1044 if( !psz_values ) return ;
1046 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
1047 VLC_OBJECT_AOUT, FIND_ANYWHERE );
1050 delCallbacks( p_aout );
1051 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1053 var_SetString( p_aout, "equalizer-bands", psz_values );
1054 var_SetFloat( p_aout, "equalizer-preamp",
1055 eqz_preset_10b[i_preset]->f_preamp );
1056 addCallbacks( p_aout );
1057 vlc_object_release( p_aout );
1059 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1060 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1061 config_PutFloat( p_intf, "equalizer-preamp",
1062 eqz_preset_10b[i_preset]->f_preamp );
1065 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1066 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1068 char *psz_preset = newval.psz_string;
1069 Equalizer *eq = ( Equalizer * )p_data;
1070 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1071 eq->presetsComboBox->setCurrentIndex( i_preset );
1075 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1077 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1078 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1079 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1082 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1084 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1085 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1086 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1089 /**********************************************************************
1091 **********************************************************************/
1093 /**********************************************************************
1095 **********************************************************************/
1096 static const char *psz_control_names[] =
1098 "Roomsize", "Width" , "Wet", "Dry", "Damp"
1101 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1102 QWidget( _parent ) , p_intf( _p_intf )
1104 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1105 smallFont.setPointSize( smallFont.pointSize() - 3 );
1107 QGridLayout *layout = new QGridLayout( this );
1108 layout->setMargin( 0 );
1110 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1111 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1113 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1115 spatCtrl[i] = new QSlider( Qt::Vertical );
1118 spatCtrl[i]->setMaximum( 10 );
1119 spatCtrl[i]->setValue( 2 );
1123 spatCtrl[i]->setMaximum( 10 );
1124 spatCtrl[i]->setValue( 0 );
1125 spatCtrl[i]->setMinimum( -10 );
1127 oldControlVars[i] = spatCtrl[i]->value();
1128 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1129 ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1130 ctrl_texts[i]->setFont( smallFont );
1131 ctrl_readout[i] = new QLabel( "" );
1132 ctrl_readout[i]->setFont( smallFont );
1133 layout->addWidget( spatCtrl[i], 1, i );
1134 layout->addWidget( ctrl_readout[i], 2, i );
1135 layout->addWidget( ctrl_texts[i], 3, i );
1138 BUTTONACT( enableCheck, enable() );
1140 /* Write down initial values */
1141 aout_instance_t *p_aout = ( aout_instance_t * )
1142 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1147 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1148 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1150 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1152 vlc_object_release( p_aout );
1156 psz_af = config_GetPsz( p_intf, "audio-filter" );
1157 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1159 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1162 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1163 enableCheck->setChecked( true );
1165 enable( enableCheck->isChecked() );
1166 setValues( controlVars );
1169 Spatializer::~Spatializer()
1173 void Spatializer::enable()
1175 bool en = enableCheck->isChecked();
1176 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1177 en ? true : false );
1181 void Spatializer::enable( bool en )
1183 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1185 spatCtrl[i]->setEnabled( en );
1186 ctrl_texts[i]->setEnabled( en );
1187 ctrl_readout[i]->setEnabled( en );
1190 void Spatializer::setInitValues()
1192 setValues( controlVars );
1195 void Spatializer::setValues( float *controlVars )
1197 aout_instance_t *p_aout= ( aout_instance_t * )
1198 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1200 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1202 float f = (float)( spatCtrl[i]->value() );
1203 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1207 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1209 if( oldControlVars[i] != spatCtrl[i]->value() )
1211 var_SetFloat( p_aout, psz_control_names[i],
1212 ( float )spatCtrl[i]->value() );
1213 config_PutFloat( p_intf, psz_control_names[i],
1214 ( float ) spatCtrl[i]->value() );
1215 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1218 vlc_object_release( p_aout );
1222 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1224 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1225 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1228 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1230 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1231 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1234 #include <QToolButton>
1235 #include <QGridLayout>
1237 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1238 QWidget( _parent ) , p_intf( _p_intf )
1240 QGroupBox *AVBox, *subsBox;
1242 QToolButton *moinsAV, *plusAV;
1243 QToolButton *moinssubs, *plussubs;
1244 QToolButton *moinssubSpeed, *plussubSpeed;
1246 QToolButton *updateButton;
1248 QGridLayout *mainLayout = new QGridLayout( this );
1251 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1252 QGridLayout *AVLayout = new QGridLayout( AVBox );
1254 moinsAV = new QToolButton;
1255 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1256 moinsAV->setAutoRaise( true );
1257 moinsAV->setText( "-" );
1258 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1260 plusAV = new QToolButton;
1261 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1262 plusAV->setAutoRaise( true );
1263 plusAV->setText( "+" );
1264 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1266 QLabel *AVLabel = new QLabel;
1267 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1268 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1270 AVSpin = new QDoubleSpinBox;
1271 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1272 AVSpin->setDecimals( 3 );
1273 AVSpin->setMinimum( -100.0 );
1274 AVSpin->setMaximum( 100.0 );
1275 AVSpin->setSingleStep( 0.1 );
1276 AVSpin->setToolTip( qtr( "A positive value means that\n"
1277 "the audio is ahead of the video" ) );
1278 AVSpin->setSuffix( "s" );
1279 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1280 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1284 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1285 QGridLayout *subsLayout = new QGridLayout( subsBox );
1287 moinssubs = new QToolButton;
1288 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1289 moinssubs->setAutoRaise( true );
1290 moinssubs->setText( "-" );
1291 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1293 plussubs = new QToolButton;
1294 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1295 plussubs->setAutoRaise( true );
1296 plussubs->setText( "+" );
1297 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1299 QLabel *subsLabel = new QLabel;
1300 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1301 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1303 subsSpin = new QDoubleSpinBox;
1304 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1305 subsSpin->setDecimals( 3 );
1306 subsSpin->setMinimum( -100.0 );
1307 subsSpin->setMaximum( 100.0 );
1308 subsSpin->setSingleStep( 0.1 );
1309 subsSpin->setToolTip( qtr( "A positive value means that\n"
1310 "the subtitles are ahead of the video" ) );
1311 subsSpin->setSuffix( "s" );
1312 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1315 moinssubSpeed = new QToolButton;
1316 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1317 moinssubSpeed->setAutoRaise( true );
1318 moinssubSpeed->setText( "-" );
1319 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1321 plussubSpeed = new QToolButton;
1322 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1323 plussubSpeed->setAutoRaise( true );
1324 plussubSpeed->setText( "+" );
1325 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1327 QLabel *subSpeedLabel = new QLabel;
1328 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1329 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1331 subSpeedSpin = new QDoubleSpinBox;
1332 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1333 subSpeedSpin->setDecimals( 3 );
1334 subSpeedSpin->setMinimum( 1 );
1335 subSpeedSpin->setMaximum( 100 );
1336 subSpeedSpin->setSingleStep( 0.2 );
1337 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1339 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1341 updateButton = new QToolButton;
1342 updateButton->setAutoRaise( true );
1343 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1346 /* Various Connects */
1347 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1348 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1349 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1350 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1351 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1352 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1353 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1354 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1355 CONNECT( subSpeedSpin, valueChanged ( double ),
1356 this, adjustSubsSpeed( double ) );
1357 BUTTON_SET_ACT_I( updateButton, "", update,
1358 qtr( "Force update of this dialog's values" ), update() );
1364 void SyncControls::update()
1367 if( THEMIM->getInput() )
1369 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1370 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1371 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1372 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1373 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1377 void SyncControls::advanceAudio( double f_advance )
1379 if( THEMIM->getInput() )
1381 int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1382 i_delay = f_advance * 1000000;
1383 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1387 void SyncControls::advanceSubs( double f_advance )
1389 if( THEMIM->getInput() )
1391 int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1392 i_delay = f_advance * 1000000;
1393 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1394 msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
1398 void SyncControls::adjustSubsSpeed( double f_fps )
1400 if( THEMIM->getInput() )
1402 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1406 /**********************************************************************
1407 * Video filters / Adjust
1408 **********************************************************************/
1410 /**********************************************************************
1411 * Extended playbak controls
1412 **********************************************************************/