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( erase )
189 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
190 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
191 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
193 SETUP_VFILTER( marq )
194 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( QString ) )
195 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
197 SETUP_VFILTER( logo )
198 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
199 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
200 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
201 SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
204 #undef SETUP_VFILTER_OPTION
207 ExtVideo::~ExtVideo()
211 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
213 vout_thread_t *p_vout;
214 char *psz_parser, *psz_string;
215 const char *psz_filter_type;
217 /* Please leave p_libvlc_global. This is where cached modules are
218 * stored. We're not trying to find a module instance. */
219 module_t *p_obj = module_Find( p_intf, psz_name );
222 msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
226 if( module_IsCapable( p_obj, "video filter2" ) )
228 psz_filter_type = "video-filter";
230 else if( module_IsCapable( p_obj, "video filter" ) )
232 psz_filter_type = "vout-filter";
234 else if( module_IsCapable( p_obj, "sub filter" ) )
236 psz_filter_type = "sub-filter";
241 msg_Err( p_intf, "Unknown video filter type." );
246 psz_string = config_GetPsz( p_intf, psz_filter_type );
248 if( !psz_string ) psz_string = strdup( "" );
250 psz_parser = strstr( psz_string, psz_name );
256 psz_parser = psz_string;
257 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
258 psz_string, psz_name ) == -1 )
271 if( *( psz_parser + strlen( psz_name ) ) == ':' )
273 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
274 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
281 /* Remove trailing : : */
282 if( strlen( psz_string ) > 0 &&
283 *( psz_string + strlen( psz_string ) -1 ) == ':' )
285 *( psz_string + strlen( psz_string ) -1 ) = '\0';
294 /* Vout is not kept, so put that in the config */
295 config_PutPsz( p_intf, psz_filter_type, psz_string );
296 if( !strcmp( psz_filter_type, "video-filter" ) )
297 ui.videoFilterText->setText( psz_string );
298 else if( !strcmp( psz_filter_type, "vout-filter" ) )
299 ui.voutFilterText->setText( psz_string );
300 else if( !strcmp( psz_filter_type, "sub-filter" ) )
301 ui.subpictureFilterText->setText( psz_string );
303 /* Try to set on the fly */
304 p_vout = ( vout_thread_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
308 if( !strcmp( psz_filter_type, "sub-filter" ) )
309 var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
311 var_SetString( p_vout, psz_filter_type, psz_string );
312 vlc_object_release( p_vout );
318 void ExtVideo::updateFilters()
320 QString module = ModuleFromWidgetName( sender() );
321 //std::cout << "Module name: " << module.toStdString() << std::endl;
323 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
324 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
326 ChangeVFiltersString( qtu( module ),
327 checkbox ? checkbox->isChecked()
328 : groupbox->isChecked() );
331 void ExtVideo::initComboBoxItems( QObject *widget )
333 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
334 if( !combobox ) return;
335 QString option = OptionFromWidgetName( widget );
336 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
340 int i_type = p_item->i_type & CONFIG_ITEM;
341 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
343 if( i_type == CONFIG_ITEM_INTEGER
344 || i_type == CONFIG_ITEM_BOOL )
345 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
346 p_item->pi_list[i_index] );
347 else if( i_type == CONFIG_ITEM_STRING )
348 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
349 p_item->ppsz_list[i_index] );
354 msg_Err( p_intf, "Couldn't find option \"%s\".",
359 void ExtVideo::setWidgetValue( QObject *widget )
361 QString module = ModuleFromWidgetName( widget->parent() );
362 //std::cout << "Module name: " << module.toStdString() << std::endl;
363 QString option = OptionFromWidgetName( widget );
364 //std::cout << "Option name: " << option.toStdString() << std::endl;
366 vlc_object_t *p_obj = ( vlc_object_t * )
367 vlc_object_find_name( p_intf->p_libvlc,
377 "Module instance %s not found, looking in config values.",
380 i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
383 case VLC_VAR_INTEGER:
385 val.i_int = config_GetInt( p_intf, qtu( option ) );
388 val.f_float = config_GetFloat( p_intf, qtu( option ) );
391 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
397 i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
398 var_Get( p_obj, qtu( option ), &val );
399 vlc_object_release( p_obj );
402 /* Try to cast to all the widgets we're likely to encounter. Only
403 * one of the casts is expected to work. */
404 QSlider *slider = qobject_cast<QSlider*> ( widget );
405 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
406 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
407 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
408 QDial *dial = qobject_cast<QDial*> ( widget );
409 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
410 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
412 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
415 if( slider ) slider->setValue( val.i_int );
416 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
418 else if( spinbox ) spinbox->setValue( val.i_int );
419 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
423 sprintf( str, "%06X", val.i_int );
424 lineedit->setText( str );
426 else if( combobox ) combobox->setCurrentIndex(
427 combobox->findData( val.i_int ) );
428 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
430 else if( i_type == VLC_VAR_FLOAT )
433 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
434 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
435 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
437 else if( i_type == VLC_VAR_STRING )
439 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
440 else if( combobox ) combobox->setCurrentIndex(
441 combobox->findData( qfu( val.psz_string ) ) );
442 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
443 free( val.psz_string );
447 "Module %s's %s variable is of an unsupported type ( %d )",
453 void ExtVideo::updateFilterOptions()
455 QString module = ModuleFromWidgetName( sender()->parent() );
456 //std::cout << "Module name: " << module.toStdString() << std::endl;
457 QString option = OptionFromWidgetName( sender() );
458 //std::cout << "Option name: " << option.toStdString() << std::endl;
460 vlc_object_t *p_obj = ( vlc_object_t * )
461 vlc_object_find_name( p_intf->p_libvlc,
466 msg_Err( p_intf, "Module %s not found.", qtu( module ) );
470 int i_type = var_Type( p_obj, qtu( option ) );
471 bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
474 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.",
477 /* FIXME: restart automatically somewhere near the end of this function */
480 /* Try to cast to all the widgets we're likely to encounter. Only
481 * one of the casts is expected to work. */
482 QSlider *slider = qobject_cast<QSlider*> ( sender() );
483 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
484 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
485 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
486 QDial *dial = qobject_cast<QDial*> ( sender() );
487 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
488 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
491 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
494 if( slider ) i_int = slider->value();
495 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
496 else if( spinbox ) i_int = spinbox->value();
497 else if( dial ) i_int = ( 540-dial->value() )%360;
498 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
499 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
500 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
501 config_PutInt( p_intf, qtu( option ), i_int );
504 if( i_type == VLC_VAR_INTEGER )
505 var_SetInteger( p_obj, qtu( option ), i_int );
507 var_SetBool( p_obj, qtu( option ), i_int );
510 else if( i_type == VLC_VAR_FLOAT )
513 if( slider ) f_float = ( double )slider->value()
514 / ( double )slider->tickInterval(); /* hack alert! */
515 else if( doublespinbox ) f_float = doublespinbox->value();
516 else if( lineedit ) f_float = lineedit->text().toDouble();
517 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
518 config_PutFloat( p_intf, qtu( option ), f_float );
520 var_SetFloat( p_obj, qtu( option ), f_float );
522 else if( i_type == VLC_VAR_STRING )
524 char *psz_string = NULL;
525 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
526 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
527 combobox->currentIndex() ).toString() ) );
528 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
529 config_PutPsz( p_intf, qtu( option ), psz_string );
531 var_SetString( p_obj, qtu( option ), psz_string );
536 "Module %s's %s variable is of an unsupported type ( %d )",
541 vlc_object_release( p_obj );
545 void ExtVideo::gotoConf( QObject* src )
547 #define SHOWCONF( module ) \
548 if( src->objectName().contains( module ) ) \
550 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
554 SHOWCONF( "magnify" );
556 SHOWCONF( "ripple" );
557 SHOWCONF( "invert" );
558 SHOWCONF( "puzzle" );
560 SHOWCONF( "gradient" );
561 SHOWCONF( "colorthres" )
565 /**********************************************************************
567 **********************************************************************/
569 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
570 : QWidget( _parent ), p_intf( _p_intf )
574 BUTTONACT( ui.refresh, Refresh() );
585 void ExtV4l2::showEvent( QShowEvent *event )
587 QWidget::showEvent( event );
591 void ExtV4l2::Refresh( void )
593 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
597 ui.vboxLayout->removeWidget( box );
603 msg_Dbg( p_intf, "Found v4l2 instance" );
604 vlc_value_t val, text, name;
605 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
609 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
611 vlc_object_release( p_obj );
615 box = new QGroupBox( this );
616 ui.vboxLayout->addWidget( box );
617 QVBoxLayout *layout = new QVBoxLayout( box );
618 box->setLayout( layout );
620 for( int i = 0; i < val.p_list->i_count; i++ )
622 const char *psz_var = text.p_list->p_values[i].psz_string;
623 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
624 const char *psz_label = name.psz_string;
625 msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
626 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
628 int i_type = var_Type( p_obj, psz_var );
629 switch( i_type & VLC_VAR_TYPE )
631 case VLC_VAR_INTEGER:
633 QLabel *label = new QLabel( psz_label, box );
634 QHBoxLayout *hlayout = new QHBoxLayout();
635 hlayout->addWidget( label );
636 int i_val = var_GetInteger( p_obj, psz_var );
637 if( i_type & VLC_VAR_HASCHOICE )
639 QComboBox *combobox = new QComboBox( box );
640 combobox->setObjectName( psz_var );
642 vlc_value_t val2, text2;
643 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
645 for( int j = 0; j < val2.p_list->i_count; j++ )
648 text2.p_list->p_values[j].psz_string,
649 val2.p_list->p_values[j].i_int );
650 if( i_val == val2.p_list->p_values[j].i_int )
651 combobox->setCurrentIndex( j );
653 var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
656 CONNECT( combobox, currentIndexChanged( int ), this,
657 ValueChange( int ) );
658 hlayout->addWidget( combobox );
662 QSlider *slider = new QSlider( box );
663 slider->setObjectName( psz_var );
664 slider->setOrientation( Qt::Horizontal );
666 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
668 slider->setMinimum( val2.i_int );
669 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
671 slider->setMaximum( val2.i_int );
672 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
674 slider->setSingleStep( val2.i_int );
675 slider->setValue( i_val );
677 CONNECT( slider, valueChanged( int ), this,
678 ValueChange( int ) );
679 hlayout->addWidget( slider );
681 layout->addLayout( hlayout );
686 QCheckBox *button = new QCheckBox( psz_label, box );
687 button->setObjectName( psz_var );
688 button->setChecked( var_GetBool( p_obj, psz_var ) );
690 CONNECT( button, clicked( bool ), this,
691 ValueChange( bool ) );
692 layout->addWidget( button );
697 if( i_type & VLC_VAR_ISCOMMAND )
699 QPushButton *button = new QPushButton( psz_label, box );
700 button->setObjectName( psz_var );
702 CONNECT( button, clicked( bool ), this,
703 ValueChange( bool ) );
704 layout->addWidget( button );
708 QLabel *label = new QLabel( psz_label, box );
709 layout->addWidget( label );
714 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
717 free( name.psz_string );
719 var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
720 vlc_object_release( p_obj );
724 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
730 void ExtV4l2::ValueChange( bool value )
732 ValueChange( (int)value );
735 void ExtV4l2::ValueChange( int value )
737 QObject *s = sender();
738 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
741 char *psz_var = strdup( qtu( s->objectName() ) );
742 int i_type = var_Type( p_obj, psz_var );
743 switch( i_type & VLC_VAR_TYPE )
745 case VLC_VAR_INTEGER:
746 if( i_type & VLC_VAR_HASCHOICE )
748 QComboBox *combobox = qobject_cast<QComboBox*>( s );
749 value = combobox->itemData( value ).toInt();
751 var_SetInteger( p_obj, psz_var, value );
754 var_SetBool( p_obj, psz_var, value );
757 var_SetVoid( p_obj, psz_var );
761 vlc_object_release( p_obj );
765 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
770 /**********************************************************************
772 **********************************************************************/
774 static const QString band_frequencies[] =
776 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
777 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
780 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
781 QWidget( _parent ) , p_intf( _p_intf )
783 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
784 smallFont.setPointSize( smallFont.pointSize() - 3 );
787 presetsComboBox = ui.presetsCombo;
789 ui.preampLabel->setFont( smallFont );
790 ui.preampSlider->setMaximum( 400 );
791 for( int i = 0 ; i < NB_PRESETS ; i ++ )
793 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
796 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
798 BUTTONACT( ui.enableCheck, enable() );
799 BUTTONACT( ui.eq2PassCheck, set2Pass() );
801 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
803 QGridLayout *grid = new QGridLayout( ui.frame );
804 grid->setMargin( 0 );
805 for( int i = 0 ; i < BANDS ; i++ )
807 bands[i] = new QSlider( Qt::Vertical );
808 bands[i]->setMaximum( 400 );
809 bands[i]->setValue( 200 );
810 CONNECT( bands[i], valueChanged( int ), this, setBand() );
811 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
812 band_texts[i]->setFont( smallFont );
813 grid->addWidget( bands[i], 0, i );
814 grid->addWidget( band_texts[i], 1, i );
817 /* Write down initial values */
818 aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
819 VLC_OBJECT_AOUT, FIND_ANYWHERE );
825 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
826 if( var_GetBool( p_aout, "equalizer-2pass" ) )
827 ui.eq2PassCheck->setChecked( true );
828 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
829 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
830 vlc_object_release( p_aout );
834 psz_af = config_GetPsz( p_intf, "audio-filter" );
835 if( config_GetInt( p_intf, "equalizer-2pass" ) )
836 ui.eq2PassCheck->setChecked( true );
837 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
838 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
840 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
841 ui.enableCheck->setChecked( true );
843 enable( ui.enableCheck->isChecked() );
845 setValues( psz_bands, f_preamp );
848 Equalizer::~Equalizer()
852 void Equalizer::enable()
854 bool en = ui.enableCheck->isChecked();
855 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
856 en ? VLC_TRUE : VLC_FALSE );
857 // aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
858 // en ? VLC_TRUE : VLC_FALSE );
859 // aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
860 // en ? VLC_TRUE : VLC_FALSE );
864 void Equalizer::enable( bool en )
866 ui.eq2PassCheck->setEnabled( en );
867 ui.preampLabel->setEnabled( en );
868 ui.preampSlider->setEnabled( en );
869 for( int i = 0 ; i< BANDS; i++ )
871 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
875 void Equalizer::set2Pass()
877 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
878 VLC_OBJECT_AOUT, FIND_ANYWHERE );
879 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
882 config_PutInt( p_intf, "equalizer-2pass", b_2p );
885 var_SetBool( p_aout, "equalizer-2pass", b_2p );
886 config_PutInt( p_intf, "equalizer-2pass", b_2p );
887 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
889 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
891 vlc_object_release( p_aout );
895 void Equalizer::setPreamp()
897 float f= ( float )( ui.preampSlider->value() ) /10 - 20;
899 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
900 VLC_OBJECT_AOUT, FIND_ANYWHERE );
902 sprintf( psz_val, "%.1f", f );
903 ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
906 delCallbacks( p_aout );
907 var_SetFloat( p_aout, "equalizer-preamp", f );
908 addCallbacks( p_aout );
909 vlc_object_release( p_aout );
911 config_PutFloat( p_intf, "equalizer-preamp", f );
914 void Equalizer::setBand()
916 char psz_values[102]; memset( psz_values, 0, 102 );
918 /**\todo smoothing */
920 for( int i = 0 ; i< BANDS ; i++ )
923 float f_val = ( float )( bands[i]->value() ) / 10 - 20 ;
924 sprintf( psz_values, "%s %f", psz_values, f_val );
925 sprintf( psz_val, "% 5.1f", f_val );
926 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
928 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
929 VLC_OBJECT_AOUT, FIND_ANYWHERE );
932 delCallbacks( p_aout );
933 var_SetString( p_aout, "equalizer-bands", psz_values );
934 addCallbacks( p_aout );
935 vlc_object_release( p_aout );
938 void Equalizer::setValues( char *psz_bands, float f_preamp )
943 for( int i = 0; i < 10; i++ )
946 float f = strtof( p, &p );
947 int i_val= ( int )( ( f + 20 ) * 10 );
948 bands[i]->setValue( i_val );
949 sprintf( psz_val, "% 5.1f", f );
950 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
952 if( p == NULL || *p == '\0' ) break;
954 if( *p == '\0' ) break;
958 int i_val = ( int )( ( f_preamp + 20 ) * 10 );
959 sprintf( psz_val, "%.1f", f_preamp );
960 ui.preampSlider->setValue( i_val );
961 ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
964 void Equalizer::setPreset( int preset )
966 aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
967 VLC_OBJECT_AOUT, FIND_ANYWHERE );
969 char psz_values[102]; memset( psz_values, 0, 102 );
970 for( int i = 0 ; i< 10 ;i++ )
971 sprintf( psz_values, "%s %.1f", psz_values,
972 eqz_preset_10b[preset]->f_amp[i] );
976 delCallbacks( p_aout );
977 var_SetString( p_aout, "equalizer-bands", psz_values );
978 var_SetFloat( p_aout, "equalizer-preamp",
979 eqz_preset_10b[preset]->f_preamp );
980 addCallbacks( p_aout );
981 vlc_object_release( p_aout );
983 config_PutPsz( p_intf, "equalizer-bands", psz_values );
984 config_PutFloat( p_intf, "equalizer-preamp",
985 eqz_preset_10b[preset]->f_preamp );
987 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
990 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
991 vlc_value_t oldval, vlc_value_t newval, void *p_data )
993 char *psz_preset = newval.psz_string;
994 Equalizer *eq = ( Equalizer * )p_data;
995 eq->presetsComboBox->setCurrentIndex( eq->presetsComboBox->findText( qfu( psz_preset ) ) );
999 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1001 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1002 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1003 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1006 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1008 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1009 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1010 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1013 /**********************************************************************
1015 **********************************************************************/
1017 /**********************************************************************
1019 **********************************************************************/
1020 static const char *psz_control_names[] =
1022 "Roomsize", "Width" , "Wet", "Dry", "Damp"
1025 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1026 QWidget( _parent ) , p_intf( _p_intf )
1028 QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1029 smallFont.setPointSize( smallFont.pointSize() - 3 );
1031 QGridLayout *layout = new QGridLayout( this );
1032 layout->setMargin( 0 );
1034 enableCheck = new QCheckBox( qfu( "Enable spatializer" ) );
1035 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1037 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1039 spatCtrl[i] = new QSlider( Qt::Vertical );
1042 spatCtrl[i]->setMaximum( 10 );
1043 spatCtrl[i]->setValue( 2 );
1047 spatCtrl[i]->setMaximum( 10 );
1048 spatCtrl[i]->setValue( 0 );
1049 spatCtrl[i]->setMinimum( -10 );
1051 oldControlVars[i] = spatCtrl[i]->value();
1052 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1053 ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1054 ctrl_texts[i]->setFont( smallFont );
1055 ctrl_readout[i] = new QLabel( "" );
1056 ctrl_readout[i]->setFont( smallFont );
1057 layout->addWidget( spatCtrl[i], 1, i );
1058 layout->addWidget( ctrl_readout[i], 2, i );
1059 layout->addWidget( ctrl_texts[i], 3, i );
1062 BUTTONACT( enableCheck, enable() );
1064 /* Write down initial values */
1065 aout_instance_t *p_aout = ( aout_instance_t * )
1066 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1071 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1072 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1074 controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1076 vlc_object_release( p_aout );
1080 psz_af = config_GetPsz( p_intf, "audio-filter" );
1081 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1083 controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1086 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1087 enableCheck->setChecked( true );
1089 enable( enableCheck->isChecked() );
1090 setValues( controlVars );
1093 Spatializer::~Spatializer()
1097 void Spatializer::enable()
1099 bool en = enableCheck->isChecked();
1100 aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1101 en ? VLC_TRUE : VLC_FALSE );
1105 void Spatializer::enable( bool en )
1107 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1109 spatCtrl[i]->setEnabled( en );
1110 ctrl_texts[i]->setEnabled( en );
1111 ctrl_readout[i]->setEnabled( en );
1114 void Spatializer::setInitValues()
1116 setValues( controlVars );
1119 void Spatializer::setValues( float *controlVars )
1123 aout_instance_t *p_aout= ( aout_instance_t * )
1124 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1126 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1128 float f= ( float )( spatCtrl[i]->value() );
1129 sprintf( psz_val, "%.1f", f );
1130 ctrl_readout[i]->setText( psz_val );
1134 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1136 if( oldControlVars[i] != spatCtrl[i]->value() )
1138 var_SetFloat( p_aout, psz_control_names[i],
1139 ( float )spatCtrl[i]->value() );
1140 config_PutFloat( p_intf, psz_control_names[i],
1141 ( float ) spatCtrl[i]->value() );
1142 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1145 vlc_object_release( p_aout );
1149 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1151 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1152 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1155 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1157 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1158 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1161 #include <QToolButton>
1162 #include <QGridLayout>
1164 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1165 QWidget( _parent ) , p_intf( _p_intf )
1167 QGroupBox *AVBox, *subsBox;
1169 QToolButton *moinsAV, *plusAV;
1170 QToolButton *moinssubs, *plussubs;
1171 QToolButton *moinssubSpeed, *plussubSpeed;
1173 QToolButton *updateButton;
1175 QGridLayout *mainLayout = new QGridLayout( this );
1178 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1179 QGridLayout *AVLayout = new QGridLayout( AVBox );
1181 moinsAV = new QToolButton;
1182 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1183 moinsAV->setAutoRaise( true );
1184 moinsAV->setText( "-" );
1185 AVLayout->addWidget( moinsAV, 1, 0, 1, 1 );
1187 plusAV = new QToolButton;
1188 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1189 plusAV->setAutoRaise( true );
1190 plusAV->setText( "+" );
1191 AVLayout->addWidget( plusAV, 1, 2, 1, 1 );
1193 QLabel *AVLabel = new QLabel;
1194 AVLabel->setText( qtr( "Advance of audio over video" ) );
1195 AVLayout->addWidget( AVLabel, 0, 0, 1, 3 );
1197 AVSpin = new QDoubleSpinBox;
1198 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1199 AVSpin->setDecimals( 3 );
1200 AVSpin->setMinimum( -100 );
1201 AVSpin->setMaximum( 100 );
1202 AVSpin->setSingleStep( 0.1 );
1203 AVSpin->setToolTip( qtr( "A positive value means that\n"
1204 "the audio is ahead of the video" ) );
1205 AVSpin->setSuffix( "s" );
1206 AVLayout->addWidget( AVSpin, 1, 1, 1, 1 );
1207 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1211 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1212 QGridLayout *subsLayout = new QGridLayout( subsBox );
1214 moinssubs = new QToolButton;
1215 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1216 moinssubs->setAutoRaise( true );
1217 moinssubs->setText( "-" );
1218 subsLayout->addWidget( moinssubs, 1, 0, 1, 1 );
1220 plussubs = new QToolButton;
1221 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1222 plussubs->setAutoRaise( true );
1223 plussubs->setText( "+" );
1224 subsLayout->addWidget( plussubs, 1, 2, 1, 1 );
1226 QLabel *subsLabel = new QLabel;
1227 subsLabel->setText( qtr( "Advance of subtitles over video" ) );
1228 subsLayout->addWidget( subsLabel, 0, 0, 1, 3 );
1230 subsSpin = new QDoubleSpinBox;
1231 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1232 subsSpin->setDecimals( 3 );
1233 subsSpin->setMinimum( -100 );
1234 subsSpin->setMaximum( 100 );
1235 subsSpin->setSingleStep( 0.1 );
1236 subsSpin->setToolTip( qtr( "A positive value means that\n"
1237 "the subtitles are ahead of the video" ) );
1238 subsSpin->setSuffix( "s" );
1239 subsLayout->addWidget( subsSpin, 1, 1, 1, 1 );
1242 moinssubSpeed = new QToolButton;
1243 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1244 moinssubSpeed->setAutoRaise( true );
1245 moinssubSpeed->setText( "-" );
1246 subsLayout->addWidget( moinssubSpeed, 3, 0, 1, 1 );
1248 plussubSpeed = new QToolButton;
1249 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1250 plussubSpeed->setAutoRaise( true );
1251 plussubSpeed->setText( "+" );
1252 subsLayout->addWidget( plussubSpeed, 3, 2, 1, 1 );
1254 QLabel *subSpeedLabel = new QLabel;
1255 subSpeedLabel->setText( qtr( "Speed of the subtitles" ) );
1256 subsLayout->addWidget( subSpeedLabel, 2, 0, 1, 3 );
1258 subSpeedSpin = new QDoubleSpinBox;
1259 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1260 subSpeedSpin->setDecimals( 3 );
1261 subSpeedSpin->setMinimum( 1 );
1262 subSpeedSpin->setMaximum( 100 );
1263 subSpeedSpin->setSingleStep( 0.2 );
1264 subsLayout->addWidget( subSpeedSpin, 3, 1, 1, 1 );
1266 mainLayout->addWidget( subsBox, 2, 0, 1, 5 );
1268 /* Various Connects */
1269 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1270 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1271 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1272 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1273 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1274 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1275 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1276 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1277 CONNECT( subSpeedSpin, alueChanged ( double ),
1278 this, adjustSubsSpeed( double ) );
1284 void SyncControls::update()
1287 if( THEMIM->getInput() )
1289 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1290 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1291 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1292 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1293 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1297 void SyncControls::advanceAudio( double f_advance )
1299 if( THEMIM->getInput() )
1301 int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1302 i_delay += f_advance * 1000000;
1303 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1304 msg_Dbg( p_intf, "I am advancing Audio %d", f_advance );
1308 void SyncControls::advanceSubs( double f_advance )
1310 if( THEMIM->getInput() )
1312 int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1313 i_delay += f_advance * 1000000;
1314 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1315 msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
1319 void SyncControls::adjustSubsSpeed( double f_fps )
1321 if( THEMIM->getInput() )
1323 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1327 /**********************************************************************
1328 * Video filters / Adjust
1329 **********************************************************************/
1331 /**********************************************************************
1332 * Extended playbak controls
1333 **********************************************************************/