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"
42 #include "../../audio_filter/equalizer_presets.h"
44 #include <vlc_intf_strings.h>
52 class ConfClickHandler : public QObject
55 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
56 e = _e; p_intf = _p_intf;
58 virtual ~ConfClickHandler() {}
59 bool eventFilter( QObject *obj, QEvent *evt )
61 if( evt->type() == QEvent::MouseButtonPress )
70 intf_thread_t *p_intf;
74 QString ModuleFromWidgetName( QObject *obj )
76 return obj->objectName().replace( "Enable","" );
79 QString OptionFromWidgetName( QObject *obj )
82 QString option = obj->objectName().replace( "Slider", "" )
83 .replace( "Combo" , "" )
84 .replace( "Dial" , "" )
85 .replace( "Check" , "" )
86 .replace( "Spin" , "" )
87 .replace( "Text" , "" );
88 for( char a = 'A'; a <= 'Z'; a++ )
90 option = option.replace( QString( a ),
91 QString( '-' ) + QString( a + 'a' - 'A' ) );
96 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
99 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( QString ) )
138 SETUP_VFILTER( colorthres )
139 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( 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( panorRowsSpin, valueChanged( int ) )
190 SETUP_VFILTER_OPTION( panorColsSpin, 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( 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
212 ExtVideo::~ExtVideo()
216 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
218 vout_thread_t *p_vout;
219 char *psz_parser, *psz_string;
220 const char *psz_filter_type;
222 /* Please leave p_libvlc_global. This is where cached modules are
223 * stored. We're not trying to find a module instance. */
224 module_t *p_obj = module_Find( p_intf, psz_name );
227 msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
231 if( module_IsCapable( p_obj, "video filter2" ) )
233 psz_filter_type = "video-filter";
235 else if( module_IsCapable( p_obj, "video filter" ) )
237 psz_filter_type = "vout-filter";
239 else if( module_IsCapable( p_obj, "sub filter" ) )
241 psz_filter_type = "sub-filter";
246 msg_Err( p_intf, "Unknown video filter type." );
251 psz_string = config_GetPsz( p_intf, psz_filter_type );
253 if( !psz_string ) psz_string = strdup( "" );
255 psz_parser = strstr( psz_string, psz_name );
261 psz_parser = psz_string;
262 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
263 psz_string, psz_name ) == -1 )
276 if( *( psz_parser + strlen( psz_name ) ) == ':' )
278 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
279 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
286 /* Remove trailing : : */
287 if( strlen( psz_string ) > 0 &&
288 *( psz_string + strlen( psz_string ) -1 ) == ':' )
290 *( psz_string + strlen( psz_string ) -1 ) = '\0';
299 /* Vout is not kept, so put that in the config */
300 config_PutPsz( p_intf, psz_filter_type, psz_string );
301 if( !strcmp( psz_filter_type, "video-filter" ) )
302 ui.videoFilterText->setText( psz_string );
303 else if( !strcmp( psz_filter_type, "vout-filter" ) )
304 ui.voutFilterText->setText( psz_string );
305 else if( !strcmp( psz_filter_type, "sub-filter" ) )
306 ui.subpictureFilterText->setText( psz_string );
308 /* Try to set on the fly */
309 p_vout = ( vout_thread_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
313 if( !strcmp( psz_filter_type, "sub-filter" ) )
314 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
316 var_SetString( p_vout, psz_filter_type, psz_string );
317 vlc_object_release( p_vout );
323 void ExtVideo::updateFilters()
325 QString module = ModuleFromWidgetName( sender() );
326 //std::cout << "Module name: " << module.toStdString() << std::endl;
328 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
329 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
331 ChangeVFiltersString( qtu( module ),
332 checkbox ? checkbox->isChecked()
333 : groupbox->isChecked() );
336 void ExtVideo::initComboBoxItems( QObject *widget )
338 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
339 if( !combobox ) return;
340 QString option = OptionFromWidgetName( widget );
341 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
345 int i_type = p_item->i_type & CONFIG_ITEM;
346 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
348 if( i_type == CONFIG_ITEM_INTEGER
349 || i_type == CONFIG_ITEM_BOOL )
350 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
351 p_item->pi_list[i_index] );
352 else if( i_type == CONFIG_ITEM_STRING )
353 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
354 p_item->ppsz_list[i_index] );
359 msg_Err( p_intf, "Couldn't find option \"%s\".",
364 void ExtVideo::setWidgetValue( QObject *widget )
366 QString module = ModuleFromWidgetName( widget->parent() );
367 //std::cout << "Module name: " << module.toStdString() << std::endl;
368 QString option = OptionFromWidgetName( widget );
369 //std::cout << "Option name: " << option.toStdString() << std::endl;
371 vlc_object_t *p_obj = ( vlc_object_t * )
372 vlc_object_find_name( p_intf->p_libvlc,
382 "Module instance %s not found, looking in config values.",
385 i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
388 case VLC_VAR_INTEGER:
390 val.i_int = config_GetInt( p_intf, qtu( option ) );
393 val.f_float = config_GetFloat( p_intf, qtu( option ) );
396 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
402 i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
403 var_Get( p_obj, qtu( option ), &val );
404 vlc_object_release( p_obj );
407 /* Try to cast to all the widgets we're likely to encounter. Only
408 * one of the casts is expected to work. */
409 QSlider *slider = qobject_cast<QSlider*> ( widget );
410 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
411 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
412 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
413 QDial *dial = qobject_cast<QDial*> ( widget );
414 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
415 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
417 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
420 if( slider ) slider->setValue( val.i_int );
421 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
423 else if( spinbox ) spinbox->setValue( val.i_int );
424 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
428 sprintf( str, "%06X", val.i_int );
429 lineedit->setText( str );
431 else if( combobox ) combobox->setCurrentIndex(
432 combobox->findData( val.i_int ) );
433 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
435 else if( i_type == VLC_VAR_FLOAT )
438 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
439 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
440 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
442 else if( i_type == VLC_VAR_STRING )
444 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
445 else if( combobox ) combobox->setCurrentIndex(
446 combobox->findData( qfu( val.psz_string ) ) );
447 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
448 free( val.psz_string );
452 "Module %s's %s variable is of an unsupported type ( %d )",
458 void ExtVideo::updateFilterOptions()
460 QString module = ModuleFromWidgetName( sender()->parent() );
461 //std::cout << "Module name: " << module.toStdString() << std::endl;
462 QString option = OptionFromWidgetName( sender() );
463 //std::cout << "Option name: " << option.toStdString() << std::endl;
465 vlc_object_t *p_obj = ( vlc_object_t * )
466 vlc_object_find_name( p_intf->p_libvlc,
471 msg_Err( p_intf, "Module %s not found.", qtu( module ) );
475 int i_type = var_Type( p_obj, qtu( option ) );
476 bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
479 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.",
482 /* FIXME: restart automatically somewhere near the end of this function */
485 /* Try to cast to all the widgets we're likely to encounter. Only
486 * one of the casts is expected to work. */
487 QSlider *slider = qobject_cast<QSlider*> ( sender() );
488 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
489 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
490 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
491 QDial *dial = qobject_cast<QDial*> ( sender() );
492 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
493 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
496 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
499 if( slider ) i_int = slider->value();
500 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
501 else if( spinbox ) i_int = spinbox->value();
502 else if( dial ) i_int = ( 540-dial->value() )%360;
503 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
504 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
505 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
506 config_PutInt( p_intf, qtu( option ), i_int );
509 if( i_type == VLC_VAR_INTEGER )
510 var_SetInteger( p_obj, qtu( option ), i_int );
512 var_SetBool( p_obj, qtu( option ), i_int );
515 else if( i_type == VLC_VAR_FLOAT )
518 if( slider ) f_float = ( double )slider->value()
519 / ( double )slider->tickInterval(); /* hack alert! */
520 else if( doublespinbox ) f_float = doublespinbox->value();
521 else if( lineedit ) f_float = lineedit->text().toDouble();
522 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
523 config_PutFloat( p_intf, qtu( option ), f_float );
525 var_SetFloat( p_obj, qtu( option ), f_float );
527 else if( i_type == VLC_VAR_STRING )
529 char *psz_string = NULL;
530 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
531 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
532 combobox->currentIndex() ).toString() ) );
533 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
534 config_PutPsz( p_intf, qtu( option ), psz_string );
536 var_SetString( p_obj, qtu( option ), psz_string );
541 "Module %s's %s variable is of an unsupported type ( %d )",
546 vlc_object_release( p_obj );
550 void ExtVideo::gotoConf( QObject* src )
552 #define SHOWCONF( module ) \
553 if( src->objectName().contains( module ) ) \
555 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
559 SHOWCONF( "magnify" );
561 SHOWCONF( "ripple" );
562 SHOWCONF( "invert" );
563 SHOWCONF( "puzzle" );
565 SHOWCONF( "gradient" );
566 SHOWCONF( "colorthres" )
570 /**********************************************************************
572 **********************************************************************/
574 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
575 : QWidget( _parent ), p_intf( _p_intf )
579 BUTTONACT( ui.refresh, Refresh() );
590 void ExtV4l2::showEvent( QShowEvent *event )
592 QWidget::showEvent( event );
596 void ExtV4l2::Refresh( void )
598 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
602 ui.vboxLayout->removeWidget( box );
608 msg_Dbg( p_intf, "Found v4l2 instance" );
609 vlc_value_t val, text, name;
610 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
614 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
616 vlc_object_release( p_obj );
620 box = new QGroupBox( this );
621 ui.vboxLayout->addWidget( box );
622 QVBoxLayout *layout = new QVBoxLayout( box );
623 box->setLayout( layout );
625 for( int i = 0; i < val.p_list->i_count; i++ )
627 const char *psz_var = text.p_list->p_values[i].psz_string;
628 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
629 const char *psz_label = name.psz_string;
630 msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
631 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
633 int i_type = var_Type( p_obj, psz_var );
634 switch( i_type & VLC_VAR_TYPE )
636 case VLC_VAR_INTEGER:
638 QLabel *label = new QLabel( psz_label, box );
639 QHBoxLayout *hlayout = new QHBoxLayout();
640 hlayout->addWidget( label );
641 int i_val = var_GetInteger( p_obj, psz_var );
642 if( i_type & VLC_VAR_HASCHOICE )
644 QComboBox *combobox = new QComboBox( box );
645 combobox->setObjectName( psz_var );
647 vlc_value_t val2, text2;
648 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
650 for( int j = 0; j < val2.p_list->i_count; j++ )
653 text2.p_list->p_values[j].psz_string,
654 val2.p_list->p_values[j].i_int );
655 if( i_val == val2.p_list->p_values[j].i_int )
656 combobox->setCurrentIndex( j );
658 var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
661 CONNECT( combobox, currentIndexChanged( int ), this,
662 ValueChange( int ) );
663 hlayout->addWidget( combobox );
667 QSlider *slider = new QSlider( box );
668 slider->setObjectName( psz_var );
669 slider->setOrientation( Qt::Horizontal );
671 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
673 slider->setMinimum( val2.i_int );
674 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
676 slider->setMaximum( val2.i_int );
677 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
679 slider->setSingleStep( val2.i_int );
680 slider->setValue( i_val );
682 CONNECT( slider, valueChanged( int ), this,
683 ValueChange( int ) );
684 hlayout->addWidget( slider );
686 layout->addLayout( hlayout );
691 QCheckBox *button = new QCheckBox( psz_label, box );
692 button->setObjectName( psz_var );
693 button->setChecked( var_GetBool( p_obj, psz_var ) );
695 CONNECT( button, clicked( bool ), this,
696 ValueChange( bool ) );
697 layout->addWidget( button );
702 if( i_type & VLC_VAR_ISCOMMAND )
704 QPushButton *button = new QPushButton( psz_label, box );
705 button->setObjectName( psz_var );
707 CONNECT( button, clicked( bool ), this,
708 ValueChange( bool ) );
709 layout->addWidget( button );
713 QLabel *label = new QLabel( psz_label, box );
714 layout->addWidget( label );
719 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
722 free( name.psz_string );
724 var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
725 vlc_object_release( p_obj );
729 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
735 void ExtV4l2::ValueChange( bool value )
737 ValueChange( (int)value );
740 void ExtV4l2::ValueChange( int value )
742 QObject *s = sender();
743 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
746 char *psz_var = strdup( qtu( s->objectName() ) );
747 int i_type = var_Type( p_obj, psz_var );
748 switch( i_type & VLC_VAR_TYPE )
750 case VLC_VAR_INTEGER:
751 if( i_type & VLC_VAR_HASCHOICE )
753 QComboBox *combobox = qobject_cast<QComboBox*>( s );
754 value = combobox->itemData( value ).toInt();
756 var_SetInteger( p_obj, psz_var, value );
759 var_SetBool( p_obj, psz_var, value );
762 var_SetVoid( p_obj, psz_var );
766 vlc_object_release( p_obj );
770 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
775 /**********************************************************************
777 **********************************************************************/
779 static const QString band_frequencies[] =
781 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
782 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
785 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
786 QWidget( _parent ) , p_intf( _p_intf )
788 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
789 smallFont.setPointSize( smallFont.pointSize() - 3 );
792 presetsComboBox = ui.presetsCombo;
794 ui.preampLabel->setFont( smallFont );
795 ui.preampSlider->setMaximum( 400 );
796 for( int i = 0 ; i < NB_PRESETS ; i ++ )
798 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
801 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
803 BUTTONACT( ui.enableCheck, enable() );
804 BUTTONACT( ui.eq2PassCheck, set2Pass() );
806 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
808 QGridLayout *grid = new QGridLayout( ui.frame );
809 grid->setMargin( 0 );
810 for( int i = 0 ; i < BANDS ; i++ )
812 bands[i] = new QSlider( Qt::Vertical );
813 bands[i]->setMaximum( 400 );
814 bands[i]->setValue( 200 );
815 CONNECT( bands[i], valueChanged( int ), this, setBand() );
816 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
817 band_texts[i]->setFont( smallFont );
818 grid->addWidget( bands[i], 0, i );
819 grid->addWidget( band_texts[i], 1, i );
822 /* Write down initial values */
823 aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
824 VLC_OBJECT_AOUT, FIND_ANYWHERE );
830 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
831 if( var_GetBool( p_aout, "equalizer-2pass" ) )
832 ui.eq2PassCheck->setChecked( true );
833 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
834 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
835 vlc_object_release( p_aout );
839 psz_af = config_GetPsz( p_intf, "audio-filter" );
840 if( config_GetInt( p_intf, "equalizer-2pass" ) )
841 ui.eq2PassCheck->setChecked( true );
842 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
843 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
845 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
846 ui.enableCheck->setChecked( true );
848 enable( ui.enableCheck->isChecked() );
850 setValues( psz_bands, f_preamp );
853 Equalizer::~Equalizer()
857 void Equalizer::enable()
859 bool en = ui.enableCheck->isChecked();
860 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
861 en ? VLC_TRUE : VLC_FALSE );
862 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
863 // en ? VLC_TRUE : VLC_FALSE );
864 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
865 // en ? VLC_TRUE : VLC_FALSE );
869 void Equalizer::enable( bool en )
871 ui.eq2PassCheck->setEnabled( en );
872 ui.preampLabel->setEnabled( en );
873 ui.preampSlider->setEnabled( en );
874 for( int i = 0 ; i< BANDS; i++ )
876 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
880 void Equalizer::set2Pass()
882 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
883 VLC_OBJECT_AOUT, FIND_ANYWHERE );
884 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
887 config_PutInt( p_intf, "equalizer-2pass", b_2p );
890 var_SetBool( p_aout, "equalizer-2pass", b_2p );
891 config_PutInt( p_intf, "equalizer-2pass", b_2p );
892 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
894 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
896 vlc_object_release( p_aout );
900 void Equalizer::setPreamp()
902 float f= ( float )( ui.preampSlider->value() ) /10 - 20;
904 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
905 VLC_OBJECT_AOUT, FIND_ANYWHERE );
907 sprintf( psz_val, "%.1f", f );
908 ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
911 delCallbacks( p_aout );
912 var_SetFloat( p_aout, "equalizer-preamp", f );
913 addCallbacks( p_aout );
914 vlc_object_release( p_aout );
916 config_PutFloat( p_intf, "equalizer-preamp", f );
919 void Equalizer::setBand()
921 char psz_values[102]; memset( psz_values, 0, 102 );
923 /**\todo smoothing */
925 for( int i = 0 ; i< BANDS ; i++ )
928 float f_val = ( float )( bands[i]->value() ) / 10 - 20 ;
929 sprintf( psz_values, "%s %f", psz_values, f_val );
930 sprintf( psz_val, "% 5.1f", f_val );
931 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
933 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
934 VLC_OBJECT_AOUT, FIND_ANYWHERE );
937 delCallbacks( p_aout );
938 var_SetString( p_aout, "equalizer-bands", psz_values );
939 addCallbacks( p_aout );
940 vlc_object_release( p_aout );
943 void Equalizer::setValues( char *psz_bands, float f_preamp )
948 for( int i = 0; i < 10; i++ )
951 float f = strtof( p, &p );
952 int i_val= ( int )( ( f + 20 ) * 10 );
953 bands[i]->setValue( i_val );
954 sprintf( psz_val, "% 5.1f", f );
955 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
957 if( p == NULL || *p == '\0' ) break;
959 if( *p == '\0' ) break;
963 int i_val = ( int )( ( f_preamp + 20 ) * 10 );
964 sprintf( psz_val, "%.1f", f_preamp );
965 ui.preampSlider->setValue( i_val );
966 ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
969 void Equalizer::setPreset( int preset )
971 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
972 VLC_OBJECT_AOUT, FIND_ANYWHERE );
974 char psz_values[102]; memset( psz_values, 0, 102 );
975 for( int i = 0 ; i< 10 ;i++ )
976 sprintf( psz_values, "%s %.1f", psz_values,
977 eqz_preset_10b[preset]->f_amp[i] );
981 delCallbacks( p_aout );
982 var_SetString( p_aout, "equalizer-bands", psz_values );
983 var_SetFloat( p_aout, "equalizer-preamp",
984 eqz_preset_10b[preset]->f_preamp );
985 addCallbacks( p_aout );
986 vlc_object_release( p_aout );
988 config_PutPsz( p_intf, "equalizer-bands", psz_values );
989 config_PutFloat( p_intf, "equalizer-preamp",
990 eqz_preset_10b[preset]->f_preamp );
992 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
995 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
996 vlc_value_t oldval, vlc_value_t newval, void *p_data )
998 char *psz_preset = newval.psz_string;
999 Equalizer *eq = ( Equalizer * )p_data;
1000 eq->presetsComboBox->setCurrentIndex( eq->presetsComboBox->findText( qfu( psz_preset ) ) );
1004 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1006 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1007 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1008 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1011 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1013 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1014 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1015 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1018 /**********************************************************************
1020 **********************************************************************/
1022 /**********************************************************************
1024 **********************************************************************/
1025 static const char *psz_control_names[] =
1027 "Roomsize", "Width" , "Wet", "Dry", "Damp"
1030 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1031 QWidget( _parent ) , p_intf( _p_intf )
1033 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1034 smallFont.setPointSize( smallFont.pointSize() - 3 );
1036 QGridLayout *layout = new QGridLayout( this );
1037 layout->setMargin( 0 );
1039 enableCheck = new QCheckBox( qfu( "Enable spatializer" ) );
1040 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1042 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1044 spatCtrl[i] = new QSlider( Qt::Vertical );
1047 spatCtrl[i]->setMaximum( 10 );
1048 spatCtrl[i]->setValue( 2 );
1052 spatCtrl[i]->setMaximum( 10 );
1053 spatCtrl[i]->setValue( 0 );
1054 spatCtrl[i]->setMinimum( -10 );
1056 oldControlVars[i] = spatCtrl[i]->value();
1057 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1058 ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1059 ctrl_texts[i]->setFont( smallFont );
1060 ctrl_readout[i] = new QLabel( "" );
1061 ctrl_readout[i]->setFont( smallFont );
1062 layout->addWidget( spatCtrl[i], 1, i );
1063 layout->addWidget( ctrl_readout[i], 2, i );
1064 layout->addWidget( ctrl_texts[i], 3, i );
1067 BUTTONACT( enableCheck, enable() );
1069 /* Write down initial values */
1070 aout_instance_t *p_aout = ( aout_instance_t * )
1071 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1076 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1077 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1079 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1081 vlc_object_release( p_aout );
1085 psz_af = config_GetPsz( p_intf, "audio-filter" );
1086 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1088 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1091 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1092 enableCheck->setChecked( true );
1094 enable( enableCheck->isChecked() );
1095 setValues( controlVars );
1098 Spatializer::~Spatializer()
1102 void Spatializer::enable()
1104 bool en = enableCheck->isChecked();
1105 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1106 en ? VLC_TRUE : VLC_FALSE );
1110 void Spatializer::enable( bool en )
1112 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1114 spatCtrl[i]->setEnabled( en );
1115 ctrl_texts[i]->setEnabled( en );
1116 ctrl_readout[i]->setEnabled( en );
1119 void Spatializer::setInitValues()
1121 setValues( controlVars );
1124 void Spatializer::setValues( float *controlVars )
1128 aout_instance_t *p_aout= ( aout_instance_t * )
1129 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1131 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1133 float f= ( float )( spatCtrl[i]->value() );
1134 sprintf( psz_val, "%.1f", f );
1135 ctrl_readout[i]->setText( psz_val );
1139 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1141 if( oldControlVars[i] != spatCtrl[i]->value() )
1143 var_SetFloat( p_aout, psz_control_names[i],
1144 ( float )spatCtrl[i]->value() );
1145 config_PutFloat( p_intf, psz_control_names[i],
1146 ( float ) spatCtrl[i]->value() );
1147 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1150 vlc_object_release( p_aout );
1154 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1156 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1157 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1160 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1162 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1163 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1166 #include <QToolButton>
1167 #include <QGridLayout>
1169 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1170 QWidget( _parent ) , p_intf( _p_intf )
1172 QGroupBox *AVBox, *subsBox;
1174 QToolButton *moinsAV, *plusAV;
1175 QToolButton *moinssubs, *plussubs;
1176 QToolButton *moinssubSpeed, *plussubSpeed;
1178 QToolButton *updateButton;
1180 QGridLayout *mainLayout = new QGridLayout( this );
1183 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1184 QGridLayout *AVLayout = new QGridLayout( AVBox );
1186 moinsAV = new QToolButton;
1187 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1188 moinsAV->setAutoRaise( true );
1189 moinsAV->setText( "-" );
1190 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1192 plusAV = new QToolButton;
1193 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1194 plusAV->setAutoRaise( true );
1195 plusAV->setText( "+" );
1196 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1198 QLabel *AVLabel = new QLabel;
1199 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1200 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1202 AVSpin = new QDoubleSpinBox;
1203 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1204 AVSpin->setDecimals( 3 );
1205 AVSpin->setMinimum( -100 );
1206 AVSpin->setMaximum( 100 );
1207 AVSpin->setSingleStep( 0.1 );
1208 AVSpin->setToolTip( qtr( "A positive value means that\n"
1209 "the audio is ahead of the video" ) );
1210 AVSpin->setSuffix( "s" );
1211 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1212 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1216 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1217 QGridLayout *subsLayout = new QGridLayout( subsBox );
1219 moinssubs = new QToolButton;
1220 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1221 moinssubs->setAutoRaise( true );
1222 moinssubs->setText( "-" );
1223 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1225 plussubs = new QToolButton;
1226 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1227 plussubs->setAutoRaise( true );
1228 plussubs->setText( "+" );
1229 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1231 QLabel *subsLabel = new QLabel;
1232 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1233 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1235 subsSpin = new QDoubleSpinBox;
1236 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1237 subsSpin->setDecimals( 3 );
1238 subsSpin->setMinimum( -100 );
1239 subsSpin->setMaximum( 100 );
1240 subsSpin->setSingleStep( 0.1 );
1241 subsSpin->setToolTip( qtr( "A positive value means that\n"
1242 "the subtitles are ahead of the video" ) );
1243 subsSpin->setSuffix( "s" );
1244 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1247 moinssubSpeed = new QToolButton;
1248 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1249 moinssubSpeed->setAutoRaise( true );
1250 moinssubSpeed->setText( "-" );
1251 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1253 plussubSpeed = new QToolButton;
1254 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1255 plussubSpeed->setAutoRaise( true );
1256 plussubSpeed->setText( "+" );
1257 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1259 QLabel *subSpeedLabel = new QLabel;
1260 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1261 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1263 subSpeedSpin = new QDoubleSpinBox;
1264 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1265 subSpeedSpin->setDecimals( 3 );
1266 subSpeedSpin->setMinimum( 1 );
1267 subSpeedSpin->setMaximum( 100 );
1268 subSpeedSpin->setSingleStep( 0.2 );
1269 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1271 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1273 updateButton = new QToolButton;
1274 updateButton->setAutoRaise( true );
1275 updateButton->setText( "u" );
1276 updateButton->setToolTip( qtr( "Force update of the values in this dialog" ) );
1277 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1280 /* Various Connects */
1281 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1282 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1283 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1284 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1285 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1286 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1287 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1288 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1289 CONNECT( subSpeedSpin, valueChanged ( double ),
1290 this, adjustSubsSpeed( double ) );
1291 BUTTONACT( updateButton, update() );
1297 void SyncControls::update()
1300 if( THEMIM->getInput() )
1302 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1303 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1304 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1305 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1306 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1310 void SyncControls::advanceAudio( double f_advance )
1312 if( THEMIM->getInput() )
1314 int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1315 i_delay += f_advance * 1000000;
1316 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1317 msg_Dbg( p_intf, "I am advancing Audio %d", f_advance );
1321 void SyncControls::advanceSubs( double f_advance )
1323 if( THEMIM->getInput() )
1325 int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1326 i_delay += f_advance * 1000000;
1327 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1328 msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
1332 void SyncControls::adjustSubsSpeed( double f_fps )
1334 if( THEMIM->getInput() )
1336 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1340 /**********************************************************************
1341 * Video filters / Adjust
1342 **********************************************************************/
1344 /**********************************************************************
1345 * Extended playbak controls
1346 **********************************************************************/