1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea .t videolan d@t org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #define __STDC_FORMAT_MACROS 1
35 #include <QGridLayout>
36 #include <QSignalMapper>
40 #include "components/extended_panels.hpp"
41 #include "dialogs/preferences.hpp"
43 #include "input_manager.hpp"
45 #include "../../audio_filter/equalizer_presets.h"
47 #include <vlc_intf_strings.h>
50 #include <vlc_modules.h>
52 #include <vlc_charset.h> /* us_strtod */
55 class ConfClickHandler : public QObject
58 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
59 e = _e; p_intf = _p_intf;
61 virtual ~ConfClickHandler() {}
62 bool eventFilter( QObject *obj, QEvent *evt )
64 if( evt->type() == QEvent::MouseButtonPress )
73 intf_thread_t *p_intf;
77 const QString ModuleFromWidgetName( QObject *obj )
79 return obj->objectName().replace( "Enable","" );
82 QString OptionFromWidgetName( QObject *obj )
85 QString option = obj->objectName().replace( "Slider", "" )
86 .replace( "Combo" , "" )
87 .replace( "Dial" , "" )
88 .replace( "Check" , "" )
89 .replace( "Spin" , "" )
90 .replace( "Text" , "" );
91 for( char a = 'A'; a <= 'Z'; a++ )
93 option = option.replace( QString( a ),
94 QString( '-' ) + QString( a + 'a' - 'A' ) );
99 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
100 QObject( _parent ), p_intf( _p_intf )
102 ui.setupUi( _parent );
105 #define SETUP_VFILTER( widget ) \
107 vlc_object_t *p_obj = ( vlc_object_t * ) \
108 vlc_object_find_name( p_intf->p_libvlc, \
111 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
112 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
115 vlc_object_release( p_obj ); \
116 if( checkbox ) checkbox->setChecked( true ); \
117 else groupbox->setChecked( true ); \
121 if( checkbox ) checkbox->setChecked( false ); \
122 else groupbox->setChecked( false ); \
125 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
126 #define SETUP_VFILTER_OPTION( widget, signal ) \
127 initComboBoxItems( ui.widget ); \
128 setWidgetValue( ui.widget ); \
129 CONNECT( ui.widget, signal, this, updateFilterOptions() );
131 SETUP_VFILTER( adjust )
132 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
133 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
134 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
135 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
136 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
137 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
139 SETUP_VFILTER( extract )
140 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
142 SETUP_VFILTER( posterize )
143 SETUP_VFILTER_OPTION( posterizeLevelSpin, valueChanged( int ) )
145 SETUP_VFILTER( colorthres )
146 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
147 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
148 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
150 SETUP_VFILTER( invert )
152 SETUP_VFILTER( gradient )
153 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
154 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
155 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
157 SETUP_VFILTER( motionblur )
158 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
160 SETUP_VFILTER( motiondetect )
162 SETUP_VFILTER( noise )
164 SETUP_VFILTER( psychedelic )
166 SETUP_VFILTER( sharpen )
167 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
169 SETUP_VFILTER( ripple )
171 SETUP_VFILTER( wave )
173 SETUP_VFILTER( transform )
174 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
176 SETUP_VFILTER( rotate )
177 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
178 ui.rotateAngleDial->setWrapping( true );
179 ui.rotateAngleDial->setNotchesVisible( true );
181 SETUP_VFILTER( puzzle )
182 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
183 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
184 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
186 SETUP_VFILTER( magnify )
188 SETUP_VFILTER( clone )
189 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
191 SETUP_VFILTER( wall )
192 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
193 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
195 SETUP_VFILTER( panoramix )
196 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
197 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
200 SETUP_VFILTER( erase )
201 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
202 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
203 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
205 SETUP_VFILTER( marq )
206 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
207 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
209 SETUP_VFILTER( logo )
210 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
211 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
212 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
213 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
215 SETUP_VFILTER( gradfun )
216 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
218 if( module_exists( "atmo" ) )
220 SETUP_VFILTER( atmo )
221 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
222 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
223 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
224 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
225 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
226 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
227 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
228 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
232 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
236 #undef SETUP_VFILTER_OPTION
238 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
239 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
240 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
241 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
242 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
243 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
244 CONNECT( ui.topBotCropSync, toggled( bool ),
245 ui.cropBotPx, setDisabled( bool ) );
246 CONNECT( ui.leftRightCropSync, toggled( bool ),
247 ui.cropRightPx, setDisabled( bool ) );
250 void ExtVideo::cropChange()
252 if( ui.topBotCropSync->isChecked() )
253 ui.cropBotPx->setValue( ui.cropTopPx->value() );
254 if( ui.leftRightCropSync->isChecked() )
255 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
257 p_vout = THEMIM->getVout();
260 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
261 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
262 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
263 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
264 vlc_object_release( p_vout );
268 void ExtVideo::clean()
270 ui.cropTopPx->setValue( 0 );
271 ui.cropBotPx->setValue( 0 );
272 ui.cropLeftPx->setValue( 0 );
273 ui.cropRightPx->setValue( 0 );
276 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
278 char *psz_parser, *psz_string;
279 const char *psz_filter_type;
281 /* FIXME temporary hack */
282 const char *psz_module_name = psz_name;
283 if( !strcmp( psz_name, "wall" ) ||
284 !strcmp( psz_name, "panoramix" ) ||
285 !strcmp( psz_name, "clone" ) )
286 psz_module_name = "video_filter_wrapper";
288 module_t *p_obj = module_find( psz_module_name );
291 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
295 if( module_provides( p_obj, "video filter" ) )
297 psz_filter_type = "vout-filter";
299 else if( module_provides( p_obj, "video filter2" ) )
301 psz_filter_type = "video-filter";
303 else if( module_provides( p_obj, "sub filter" ) )
305 psz_filter_type = "sub-filter";
309 module_release (p_obj);
310 msg_Err( p_intf, "Unknown video filter type." );
313 module_release (p_obj);
315 psz_string = config_GetPsz( p_intf, psz_filter_type );
317 if( !psz_string ) psz_string = strdup( "" );
319 psz_parser = strstr( psz_string, psz_name );
325 psz_parser = psz_string;
326 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
327 psz_string, psz_name ) == -1 )
343 if( *( psz_parser + strlen( psz_name ) ) == ':' )
345 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
346 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
353 /* Remove trailing : : */
354 if( strlen( psz_string ) > 0 &&
355 *( psz_string + strlen( psz_string ) -1 ) == ':' )
357 *( psz_string + strlen( psz_string ) -1 ) = '\0';
366 /* Vout is not kept, so put that in the config */
367 config_PutPsz( p_intf, psz_filter_type, psz_string );
369 /* Try to set on the fly */
370 p_vout = THEMIM->getVout();
373 var_SetString( p_vout, psz_filter_type, psz_string );
374 vlc_object_release( p_vout );
380 void ExtVideo::updateFilters()
382 QString module = ModuleFromWidgetName( sender() );
384 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
385 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
387 ChangeVFiltersString( qtu( module ),
388 checkbox ? checkbox->isChecked()
389 : groupbox->isChecked() );
392 void ExtVideo::initComboBoxItems( QObject *widget )
394 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
395 if( !combobox ) return;
397 QString option = OptionFromWidgetName( widget );
398 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
402 int i_type = p_item->i_type & CONFIG_ITEM;
403 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
405 if( i_type == CONFIG_ITEM_INTEGER
406 || i_type == CONFIG_ITEM_BOOL )
407 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
408 p_item->pi_list[i_index] );
409 else if( i_type == CONFIG_ITEM_STRING )
410 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
411 p_item->ppsz_list[i_index] );
416 msg_Err( p_intf, "Couldn't find option \"%s\".",
421 void ExtVideo::setWidgetValue( QObject *widget )
423 QString module = ModuleFromWidgetName( widget->parent() );
424 //std::cout << "Module name: " << module.toStdString() << std::endl;
425 QString option = OptionFromWidgetName( widget );
426 //std::cout << "Option name: " << option.toStdString() << std::endl;
428 vlc_object_t *p_obj = ( vlc_object_t * )
429 vlc_object_find_name( p_intf->p_libvlc,
439 "Module instance %s not found, looking in config values.",
442 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
445 case VLC_VAR_INTEGER:
447 val.i_int = config_GetInt( p_intf, qtu( option ) );
450 val.f_float = config_GetFloat( p_intf, qtu( option ) );
453 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
459 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
460 var_Get( p_obj, qtu( option ), &val );
461 vlc_object_release( p_obj );
464 /* Try to cast to all the widgets we're likely to encounter. Only
465 * one of the casts is expected to work. */
466 QSlider *slider = qobject_cast<QSlider*> ( widget );
467 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
468 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
469 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
470 QDial *dial = qobject_cast<QDial*> ( widget );
471 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
472 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
474 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
476 if( slider ) slider->setValue( val.i_int );
477 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
479 else if( spinbox ) spinbox->setValue( val.i_int );
480 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
484 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
485 lineedit->setText( str );
487 else if( combobox ) combobox->setCurrentIndex(
488 combobox->findData( qlonglong(val.i_int) ) );
489 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
491 else if( i_type == VLC_VAR_FLOAT )
493 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
494 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
495 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
497 else if( i_type == VLC_VAR_STRING )
499 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
500 else if( combobox ) combobox->setCurrentIndex(
501 combobox->findData( qfu( val.psz_string ) ) );
502 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
503 free( val.psz_string );
508 "Module %s's %s variable is of an unsupported type ( %d )",
514 void ExtVideo::updateFilterOptions()
516 QString module = ModuleFromWidgetName( sender()->parent() );
517 //std::cout << "Module name: " << module.toStdString() << std::endl;
518 QString option = OptionFromWidgetName( sender() );
519 //std::cout << "Option name: " << option.toStdString() << std::endl;
521 vlc_object_t *p_obj = ( vlc_object_t * )
522 vlc_object_find_name( p_intf->p_libvlc,
529 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
530 i_type = config_GetType( p_intf, qtu( option ) );
531 b_is_command = false;
535 i_type = var_Type( p_obj, qtu( option ) );
536 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
541 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.",
544 /* FIXME: restart automatically somewhere near the end of this function */
547 /* Try to cast to all the widgets we're likely to encounter. Only
548 * one of the casts is expected to work. */
549 QSlider *slider = qobject_cast<QSlider*> ( sender() );
550 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
551 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
552 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
553 QDial *dial = qobject_cast<QDial*> ( sender() );
554 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
555 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
557 i_type &= VLC_VAR_CLASS;
558 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
561 if( slider ) i_int = slider->value();
562 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
563 else if( spinbox ) i_int = spinbox->value();
564 else if( dial ) i_int = ( 540-dial->value() )%360;
565 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
566 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
567 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
568 config_PutInt( p_intf, qtu( option ), i_int );
571 if( i_type == VLC_VAR_INTEGER )
572 var_SetInteger( p_obj, qtu( option ), i_int );
574 var_SetBool( p_obj, qtu( option ), i_int );
577 else if( i_type == VLC_VAR_FLOAT )
580 if( slider ) f_float = ( double )slider->value()
581 / ( double )slider->tickInterval(); /* hack alert! */
582 else if( doublespinbox ) f_float = doublespinbox->value();
583 else if( lineedit ) f_float = lineedit->text().toDouble();
584 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
585 config_PutFloat( p_intf, qtu( option ), f_float );
587 var_SetFloat( p_obj, qtu( option ), f_float );
589 else if( i_type == VLC_VAR_STRING )
591 char *psz_string = NULL;
592 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
593 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
594 combobox->currentIndex() ).toString() ) );
595 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
596 config_PutPsz( p_intf, qtu( option ), psz_string );
598 var_SetString( p_obj, qtu( option ), psz_string );
603 "Module %s's %s variable is of an unsupported type ( %d )",
608 if( p_obj ) vlc_object_release( p_obj );
612 void ExtVideo::gotoConf( QObject* src )
614 #define SHOWCONF( module ) \
615 if( src->objectName().contains( module ) ) \
617 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
621 SHOWCONF( "magnify" );
623 SHOWCONF( "ripple" );
624 SHOWCONF( "invert" );
625 SHOWCONF( "puzzle" );
627 SHOWCONF( "gradient" );
628 SHOWCONF( "colorthres" )
632 /**********************************************************************
634 **********************************************************************/
636 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
637 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
639 QVBoxLayout *layout = new QVBoxLayout( this );
640 help = new QLabel( qtr("No v4l2 instance found.\n"
641 "Please check that the device has been opened with VLC and is playing.\n\n"
642 "Controls will automatically appear here.")
644 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
645 layout->addWidget( help );
649 void ExtV4l2::showEvent( QShowEvent *event )
651 QWidget::showEvent( event );
655 void ExtV4l2::Refresh( void )
657 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
661 layout()->removeWidget( box );
667 vlc_value_t val, text, name;
668 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
672 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
674 vlc_object_release( p_obj );
678 box = new QGroupBox( this );
679 layout()->addWidget( box );
680 QVBoxLayout *layout = new QVBoxLayout( box );
681 box->setLayout( layout );
683 for( int i = 0; i < val.p_list->i_count; i++ )
685 const char *psz_var = text.p_list->p_values[i].psz_string;
686 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
687 const char *psz_label = name.psz_string;
688 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
689 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
691 int i_type = var_Type( p_obj, psz_var );
692 switch( i_type & VLC_VAR_TYPE )
694 case VLC_VAR_INTEGER:
696 QLabel *label = new QLabel( psz_label, box );
697 QHBoxLayout *hlayout = new QHBoxLayout();
698 hlayout->addWidget( label );
699 int i_val = var_GetInteger( p_obj, psz_var );
700 if( i_type & VLC_VAR_HASCHOICE )
702 QComboBox *combobox = new QComboBox( box );
703 combobox->setObjectName( psz_var );
705 vlc_value_t val2, text2;
706 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
708 for( int j = 0; j < val2.p_list->i_count; j++ )
711 text2.p_list->p_values[j].psz_string,
712 qlonglong( val2.p_list->p_values[j].i_int) );
713 if( i_val == val2.p_list->p_values[j].i_int )
714 combobox->setCurrentIndex( j );
716 var_FreeList( &val2, &text2 );
718 CONNECT( combobox, currentIndexChanged( int ), this,
719 ValueChange( int ) );
720 hlayout->addWidget( combobox );
724 QSlider *slider = new QSlider( box );
725 slider->setObjectName( psz_var );
726 slider->setOrientation( Qt::Horizontal );
728 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
730 slider->setMinimum( val2.i_int );
731 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
733 slider->setMaximum( val2.i_int );
734 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
736 slider->setSingleStep( val2.i_int );
737 slider->setValue( i_val );
739 CONNECT( slider, valueChanged( int ), this,
740 ValueChange( int ) );
741 hlayout->addWidget( slider );
743 layout->addLayout( hlayout );
748 QCheckBox *button = new QCheckBox( psz_label, box );
749 button->setObjectName( psz_var );
750 button->setChecked( var_GetBool( p_obj, psz_var ) );
752 CONNECT( button, clicked( bool ), this,
753 ValueChange( bool ) );
754 layout->addWidget( button );
759 if( i_type & VLC_VAR_ISCOMMAND )
761 QPushButton *button = new QPushButton( psz_label, box );
762 button->setObjectName( psz_var );
764 CONNECT( button, clicked( bool ), this,
765 ValueChange( bool ) );
766 layout->addWidget( button );
770 QLabel *label = new QLabel( psz_label, box );
771 layout->addWidget( label );
776 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
779 free( name.psz_string );
781 var_FreeList( &val, &text );
782 vlc_object_release( p_obj );
786 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
789 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
793 void ExtV4l2::ValueChange( bool value )
795 ValueChange( (int)value );
798 void ExtV4l2::ValueChange( int value )
800 QObject *s = sender();
801 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
804 char *psz_var = strdup( qtu( s->objectName() ) );
805 int i_type = var_Type( p_obj, psz_var );
806 switch( i_type & VLC_VAR_TYPE )
808 case VLC_VAR_INTEGER:
809 if( i_type & VLC_VAR_HASCHOICE )
811 QComboBox *combobox = qobject_cast<QComboBox*>( s );
812 value = combobox->itemData( value ).toInt();
814 var_SetInteger( p_obj, psz_var, value );
817 var_SetBool( p_obj, psz_var, value );
820 var_TriggerCallback( p_obj, psz_var );
824 vlc_object_release( p_obj );
828 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
833 /**********************************************************************
835 **********************************************************************/
837 static const QString band_frequencies[] =
839 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
840 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
843 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
844 QWidget( _parent ) , p_intf( _p_intf )
846 QFont smallFont = QApplication::font();
847 smallFont.setPointSize( smallFont.pointSize() - 3 );
850 ui.preampLabel->setFont( smallFont );
852 /* Setup of presetsComboBox */
853 presetsComboBox = ui.presetsCombo;
854 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
856 /* Add the sliders for the Bands */
857 QGridLayout *grid = new QGridLayout( ui.frame );
858 grid->setMargin( 0 );
859 for( int i = 0 ; i < BANDS ; i++ )
861 bands[i] = new QSlider( Qt::Vertical );
862 bands[i]->setMaximum( 400 );
863 bands[i]->setValue( 200 );
864 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
866 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
867 band_texts[i]->setFont( smallFont );
869 grid->addWidget( bands[i], 0, i );
870 grid->addWidget( band_texts[i], 1, i );
873 /* Add the listed presets */
874 for( int i = 0 ; i < NB_PRESETS ; i ++ )
876 presetsComboBox->addItem( qtr( preset_list_text[i] ),
877 QVariant( preset_list[i] ) );
881 BUTTONACT( ui.enableCheck, enable() );
882 BUTTONACT( ui.eq2PassCheck, set2Pass() );
883 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
885 /* Do the update from the value of the core */
889 /* Write down initial values */
890 void Equalizer::updateUIFromCore()
892 char *psz_af, *psz_pres, *psz_bands;
896 aout_instance_t *p_aout = THEMIM->getAout();
899 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
900 psz_pres = var_GetString( p_aout, "equalizer-preset" );
901 if( var_GetBool( p_aout, "equalizer-2pass" ) )
902 ui.eq2PassCheck->setChecked( true );
903 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
904 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
905 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
906 vlc_object_release( p_aout );
910 psz_af = config_GetPsz( p_intf, "audio-filter" );
911 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
912 if( config_GetInt( p_intf, "equalizer-2pass" ) )
913 ui.eq2PassCheck->setChecked( true );
914 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
915 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
916 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
918 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
919 ui.enableCheck->setChecked( true );
920 enable( ui.enableCheck->isChecked() );
922 presetsComboBox->setCurrentIndex( i_preset );
924 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
926 if( psz_bands && strlen( psz_bands ) > 1 )
928 char *psz_bands_orig = psz_bands;
929 for( int i = 0; i < BANDS; i++ )
931 const float f = us_strtod(psz_bands, &psz_bands );
932 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
933 if( psz_bands == NULL || *psz_bands == '\0' ) break;
935 if( *psz_bands == '\0' ) break;
937 free( psz_bands_orig );
939 else free( psz_bands );
945 /* Functin called when enableButton is toggled */
946 void Equalizer::enable()
948 bool en = ui.enableCheck->isChecked();
949 aout_EnableFilter( THEPL, "equalizer", en );
950 // aout_EnableFilter( THEPL, "upmixer", en );
951 // aout_EnableFilter( THEPL, "vsurround", en );
954 if( presetsComboBox->currentIndex() < 0 )
955 presetsComboBox->setCurrentIndex( 0 );
959 void Equalizer::enable( bool en )
961 ui.eq2PassCheck->setEnabled( en );
962 presetsComboBox->setEnabled( en );
963 ui.presetLabel->setEnabled( en );
964 ui.preampLabel->setEnabled( en );
965 ui.preampSlider->setEnabled( en );
966 for( int i = 0 ; i< BANDS; i++ )
968 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
972 /* Function called when the set2Pass button is activated */
973 void Equalizer::set2Pass()
975 aout_instance_t *p_aout= THEMIM->getAout();
976 bool b_2p = ui.eq2PassCheck->isChecked();
980 var_SetBool( p_aout, "equalizer-2pass", b_2p );
981 vlc_object_release( p_aout );
983 config_PutInt( p_intf, "equalizer-2pass", b_2p );
986 /* Function called when the preamp slider is moved */
987 void Equalizer::setPreamp()
989 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
990 aout_instance_t *p_aout = THEMIM->getAout();
992 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
996 //delCallbacks( p_aout );
997 var_SetFloat( p_aout, "equalizer-preamp", f );
998 //addCallbacks( p_aout );
999 vlc_object_release( p_aout );
1001 config_PutFloat( p_intf, "equalizer-preamp", f );
1004 void Equalizer::setCoreBands()
1006 /**\todo smoothing */
1009 for( int i = 0; i < BANDS; i++ )
1011 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1012 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1014 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1015 values += " " + val;
1017 const char *psz_values = values.toAscii().constData();
1019 aout_instance_t *p_aout = THEMIM->getAout();
1022 //delCallbacks( p_aout );
1023 var_SetString( p_aout, "equalizer-bands", psz_values );
1024 //addCallbacks( p_aout );
1025 vlc_object_release( p_aout );
1029 char * Equalizer::createValuesFromPreset( int i_preset )
1033 /* Create the QString in Qt */
1034 for( int i = 0 ; i< BANDS ;i++ )
1035 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1037 /* Convert it to char * */
1038 return strdup( values.toAscii().constData() );
1041 void Equalizer::setCorePreset( int i_preset )
1046 /* Update pre-amplification in the UI */
1047 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1048 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1049 ui.preampLabel->setText( qtr( "Preamp\n" )
1050 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1052 char *psz_values = createValuesFromPreset( i_preset );
1053 if( !psz_values ) return ;
1055 char *p = psz_values;
1056 for( int i = 0; i < BANDS && *p; i++ )
1058 const float f = us_strtod( p, &p );
1060 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1061 band_texts[i]->setText( band_frequencies[i] + "\n"
1062 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1064 p++; /* skip separator */
1067 /* Apply presets to audio output */
1068 aout_instance_t *p_aout= THEMIM->getAout();
1071 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1073 var_SetString( p_aout, "equalizer-bands", psz_values );
1074 var_SetFloat( p_aout, "equalizer-preamp",
1075 eqz_preset_10b[i_preset]->f_preamp );
1076 vlc_object_release( p_aout );
1078 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1079 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1080 config_PutFloat( p_intf, "equalizer-preamp",
1081 eqz_preset_10b[i_preset]->f_preamp );
1085 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1086 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1088 char *psz_preset = newval.psz_string;
1089 Equalizer *eq = ( Equalizer * )p_data;
1090 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1091 eq->presetsComboBox->setCurrentIndex( i_preset );
1095 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1097 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1098 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1099 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1102 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1104 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1105 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1106 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1109 /**********************************************************************
1111 **********************************************************************/
1113 /**********************************************************************
1114 * Dynamic range compressor
1115 **********************************************************************/
1119 const char *psz_name;
1120 const char *psz_descs;
1121 const char *psz_units;
1122 const float f_min; // min
1123 const float f_max; // max
1124 const float f_value; // value
1125 const float f_resolution; // resolution
1128 static const comp_controls_t comp_controls[] =
1130 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1131 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1132 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1133 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1134 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1135 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1136 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1139 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1140 : QWidget( _parent ) , p_intf( _p_intf )
1142 QFont smallFont = QApplication::font();
1143 smallFont.setPointSize( smallFont.pointSize() - 3 );
1145 QGridLayout *layout = new QGridLayout( this );
1147 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1148 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1150 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1152 const int i_min = (int)( comp_controls[i].f_min
1153 / comp_controls[i].f_resolution );
1154 const int i_max = (int)( comp_controls[i].f_max
1155 / comp_controls[i].f_resolution );
1156 const int i_val = (int)( comp_controls[i].f_value
1157 / comp_controls[i].f_resolution );
1159 compCtrl[i] = new QSlider( Qt::Vertical );
1160 compCtrl[i]->setMinimum( i_min );
1161 compCtrl[i]->setMaximum( i_max );
1162 compCtrl[i]->setValue( i_val );
1164 oldControlVars[i] = comp_controls[i].f_value;
1166 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1168 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1169 ctrl_texts[i]->setFont( smallFont );
1170 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1172 ctrl_readout[i] = new QLabel;
1173 ctrl_readout[i]->setFont( smallFont );
1174 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1176 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1177 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1178 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1181 BUTTONACT( enableCheck, enable() );
1183 /* Write down initial values */
1184 aout_instance_t *p_aout = THEMIM->getAout();
1189 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1190 for( int i = 0; i < NUM_CP_CTRL; i++ )
1192 controlVars[i] = var_GetFloat( p_aout,
1193 comp_controls[i].psz_name );
1195 vlc_object_release( p_aout );
1199 psz_af = config_GetPsz( p_intf, "audio-filter" );
1200 for( int i = 0; i < NUM_CP_CTRL; i++ )
1202 controlVars[i] = config_GetFloat( p_intf,
1203 comp_controls[i].psz_name );
1206 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1208 enableCheck->setChecked( true );
1211 enable( enableCheck->isChecked() );
1212 updateSliders( controlVars );
1213 setValues( controlVars );
1216 void Compressor::enable()
1218 bool en = enableCheck->isChecked();
1219 aout_EnableFilter( THEPL, "compressor", en );
1223 void Compressor::enable( bool en )
1225 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1227 compCtrl[i]->setEnabled( en );
1228 ctrl_texts[i]->setEnabled( en );
1229 ctrl_readout[i]->setEnabled( en );
1233 void Compressor::updateSliders( float * controlVars )
1235 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1237 if( oldControlVars[i] != controlVars[i] )
1239 compCtrl[i]->setValue(
1240 (int)( controlVars[i] / comp_controls[i].f_resolution ) );
1245 void Compressor::setInitValues()
1247 setValues( controlVars );
1250 void Compressor::setValues( float * controlVars )
1252 aout_instance_t *p_aout = THEMIM->getAout();
1254 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1256 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1257 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1258 + qtr( comp_controls[i].psz_units ) );
1259 if( oldControlVars[i] != f )
1263 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1265 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1266 oldControlVars[i] = f;
1271 vlc_object_release( p_aout );
1275 /**********************************************************************
1277 **********************************************************************/
1280 const char *psz_name;
1281 const char *psz_desc;
1284 static const spat_controls_t spat_controls[] =
1286 { "spatializer-roomsize", _("Size") },
1287 { "spatializer-width", _("Width") },
1288 { "spatializer-wet", _("Wet") },
1289 { "spatializer-dry", _("Dry") },
1290 { "spatializer-damp", _("Damp") },
1293 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1294 : QWidget( _parent ) , p_intf( _p_intf )
1296 QFont smallFont = QApplication::font();
1297 smallFont.setPointSize( smallFont.pointSize() - 3 );
1299 QGridLayout *layout = new QGridLayout( this );
1301 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1302 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1304 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1306 spatCtrl[i] = new QSlider( Qt::Vertical );
1309 spatCtrl[i]->setMaximum( 10 );
1310 spatCtrl[i]->setValue( 2 );
1314 spatCtrl[i]->setMaximum( 10 );
1315 spatCtrl[i]->setValue( 0 );
1316 spatCtrl[i]->setMinimum( -10 );
1319 oldControlVars[i] = spatCtrl[i]->value();
1321 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1323 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1324 ctrl_texts[i]->setFont( smallFont );
1326 ctrl_readout[i] = new QLabel;
1327 ctrl_readout[i]->setFont( smallFont );
1329 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1330 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1331 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1334 BUTTONACT( enableCheck, enable() );
1336 /* Write down initial values */
1337 aout_instance_t *p_aout = THEMIM->getAout();
1342 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1343 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1345 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1347 vlc_object_release( p_aout );
1351 psz_af = config_GetPsz( p_intf, "audio-filter" );
1352 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1354 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1357 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1358 enableCheck->setChecked( true );
1360 enable( enableCheck->isChecked() );
1361 setValues( controlVars );
1364 void Spatializer::enable()
1366 bool en = enableCheck->isChecked();
1367 aout_EnableFilter( THEPL, "spatializer", en );
1371 void Spatializer::enable( bool en )
1373 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1375 spatCtrl[i]->setEnabled( en );
1376 ctrl_texts[i]->setEnabled( en );
1377 ctrl_readout[i]->setEnabled( en );
1380 void Spatializer::setInitValues()
1382 setValues( controlVars );
1385 void Spatializer::setValues( float *controlVars )
1387 aout_instance_t *p_aout = THEMIM->getAout();
1389 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1391 float f = (float)( spatCtrl[i]->value() );
1392 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1396 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1398 if( oldControlVars[i] != spatCtrl[i]->value() )
1400 var_SetFloat( p_aout, spat_controls[i].psz_name,
1401 ( float )spatCtrl[i]->value() );
1402 config_PutFloat( p_intf, spat_controls[i].psz_name,
1403 ( float ) spatCtrl[i]->value() );
1404 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1407 vlc_object_release( p_aout );
1411 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1413 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1414 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1417 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1419 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1420 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1423 #include <QToolButton>
1424 #include <QGridLayout>
1426 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1427 QWidget( _parent ) , p_intf( _p_intf )
1429 QGroupBox *AVBox, *subsBox;
1431 QToolButton *moinsAV, *plusAV;
1432 QToolButton *moinssubs, *plussubs;
1433 QToolButton *moinssubSpeed, *plussubSpeed;
1435 QToolButton *updateButton;
1437 b_userAction = true;
1439 QGridLayout *mainLayout = new QGridLayout( this );
1442 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1443 QGridLayout *AVLayout = new QGridLayout( AVBox );
1445 moinsAV = new QToolButton;
1446 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1447 moinsAV->setAutoRaise( true );
1448 moinsAV->setText( "-" );
1449 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1451 plusAV = new QToolButton;
1452 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1453 plusAV->setAutoRaise( true );
1454 plusAV->setText( "+" );
1455 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1457 QLabel *AVLabel = new QLabel;
1458 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1459 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1461 AVSpin = new QDoubleSpinBox;
1462 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1463 AVSpin->setDecimals( 3 );
1464 AVSpin->setMinimum( -600.0 );
1465 AVSpin->setMaximum( 600.0 );
1466 AVSpin->setSingleStep( 0.1 );
1467 AVSpin->setToolTip( qtr( "A positive value means that\n"
1468 "the audio is ahead of the video" ) );
1469 AVSpin->setSuffix( " s" );
1470 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1471 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1475 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1476 QGridLayout *subsLayout = new QGridLayout( subsBox );
1478 moinssubs = new QToolButton;
1479 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1480 moinssubs->setAutoRaise( true );
1481 moinssubs->setText( "-" );
1482 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1484 plussubs = new QToolButton;
1485 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1486 plussubs->setAutoRaise( true );
1487 plussubs->setText( "+" );
1488 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1490 QLabel *subsLabel = new QLabel;
1491 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1492 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1494 subsSpin = new QDoubleSpinBox;
1495 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1496 subsSpin->setDecimals( 3 );
1497 subsSpin->setMinimum( -600.0 );
1498 subsSpin->setMaximum( 600.0 );
1499 subsSpin->setSingleStep( 0.1 );
1500 subsSpin->setToolTip( qtr( "A positive value means that\n"
1501 "the subtitles are ahead of the video" ) );
1502 subsSpin->setSuffix( " s" );
1503 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1506 moinssubSpeed = new QToolButton;
1507 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1508 moinssubSpeed->setAutoRaise( true );
1509 moinssubSpeed->setText( "-" );
1510 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1512 plussubSpeed = new QToolButton;
1513 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1514 plussubSpeed->setAutoRaise( true );
1515 plussubSpeed->setText( "+" );
1516 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1518 QLabel *subSpeedLabel = new QLabel;
1519 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1520 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1522 subSpeedSpin = new QDoubleSpinBox;
1523 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1524 subSpeedSpin->setDecimals( 3 );
1525 subSpeedSpin->setMinimum( 1 );
1526 subSpeedSpin->setMaximum( 100 );
1527 subSpeedSpin->setSingleStep( 0.2 );
1528 subSpeedSpin->setSuffix( " fps" );
1529 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1531 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1533 updateButton = new QToolButton;
1534 updateButton->setAutoRaise( true );
1535 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1538 /* Various Connects */
1539 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1540 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1541 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1542 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1543 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1544 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1545 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1546 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1547 CONNECT( subSpeedSpin, valueChanged ( double ),
1548 this, adjustSubsSpeed( double ) );
1550 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1551 BUTTON_SET_ACT_I( updateButton, "", update,
1552 qtr( "Force update of this dialog's values" ), update() );
1558 void SyncControls::clean()
1560 b_userAction = false;
1561 AVSpin->setValue( 0.0 );
1562 subsSpin->setValue( 0.0 );
1563 subSpeedSpin->setValue( 1.0 );
1564 b_userAction = true;
1567 void SyncControls::update()
1569 b_userAction = false;
1572 if( THEMIM->getInput() )
1574 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1575 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1576 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1577 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1578 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1580 b_userAction = true;
1583 void SyncControls::advanceAudio( double f_advance )
1585 if( THEMIM->getInput() && b_userAction )
1587 int64_t i_delay = f_advance * 1000000;
1588 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1592 void SyncControls::advanceSubs( double f_advance )
1594 if( THEMIM->getInput() && b_userAction )
1596 int64_t i_delay = f_advance * 1000000;
1597 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1601 void SyncControls::adjustSubsSpeed( double f_fps )
1603 if( THEMIM->getInput() && b_userAction )
1605 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1609 /**********************************************************************
1610 * Video filters / Adjust
1611 **********************************************************************/
1613 /**********************************************************************
1614 * Extended playbak controls
1615 **********************************************************************/