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>
39 #include "components/extended_panels.hpp"
40 #include "dialogs/preferences.hpp"
42 #include "input_manager.hpp"
44 #include "../../audio_filter/equalizer_presets.h"
46 #include <vlc_intf_strings.h>
49 #include <vlc_modules.h>
51 #include <vlc_charset.h> /* us_strtod */
54 class ConfClickHandler : public QObject
57 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
58 e = _e; p_intf = _p_intf;
60 virtual ~ConfClickHandler() {}
61 bool eventFilter( QObject *obj, QEvent *evt )
63 if( evt->type() == QEvent::MouseButtonPress )
72 intf_thread_t *p_intf;
76 const QString ModuleFromWidgetName( QObject *obj )
78 return obj->objectName().replace( "Enable","" );
81 QString OptionFromWidgetName( QObject *obj )
84 QString option = obj->objectName().replace( "Slider", "" )
85 .replace( "Combo" , "" )
86 .replace( "Dial" , "" )
87 .replace( "Check" , "" )
88 .replace( "Spin" , "" )
89 .replace( "Text" , "" );
90 for( char a = 'A'; a <= 'Z'; a++ )
92 option = option.replace( QString( a ),
93 QString( '-' ) + QString( a + 'a' - 'A' ) );
98 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
99 QObject( _parent ), p_intf( _p_intf )
101 ui.setupUi( _parent );
104 #define SETUP_VFILTER( widget ) \
106 vlc_object_t *p_obj = ( vlc_object_t * ) \
107 vlc_object_find_name( p_intf->p_libvlc, \
110 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
111 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
114 vlc_object_release( p_obj ); \
115 if( checkbox ) checkbox->setChecked( true ); \
116 else groupbox->setChecked( true ); \
120 if( checkbox ) checkbox->setChecked( false ); \
121 else groupbox->setChecked( false ); \
124 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
125 #define SETUP_VFILTER_OPTION( widget, signal ) \
126 initComboBoxItems( ui.widget ); \
127 setWidgetValue( ui.widget ); \
128 CONNECT( ui.widget, signal, this, updateFilterOptions() );
130 SETUP_VFILTER( adjust )
131 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
132 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
133 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
134 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
135 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
136 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
138 SETUP_VFILTER( extract )
139 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
141 SETUP_VFILTER( colorthres )
142 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
143 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
144 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
146 SETUP_VFILTER( invert )
148 SETUP_VFILTER( gradient )
149 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
150 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
151 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
153 SETUP_VFILTER( motionblur )
154 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
156 SETUP_VFILTER( motiondetect )
158 SETUP_VFILTER( noise )
160 SETUP_VFILTER( psychedelic )
162 SETUP_VFILTER( sharpen )
163 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
165 SETUP_VFILTER( ripple )
167 SETUP_VFILTER( wave )
169 SETUP_VFILTER( transform )
170 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
172 SETUP_VFILTER( rotate )
173 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
174 ui.rotateAngleDial->setWrapping( true );
175 ui.rotateAngleDial->setNotchesVisible( true );
177 SETUP_VFILTER( puzzle )
178 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
179 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
180 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
182 SETUP_VFILTER( magnify )
184 SETUP_VFILTER( clone )
185 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
187 SETUP_VFILTER( wall )
188 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
189 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
191 SETUP_VFILTER( panoramix )
192 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
193 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
196 SETUP_VFILTER( erase )
197 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
198 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
199 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
201 SETUP_VFILTER( marq )
202 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
203 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
205 SETUP_VFILTER( logo )
206 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
207 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
208 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
209 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
211 if( module_exists( "atmo" ) )
213 SETUP_VFILTER( atmo )
214 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
215 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
216 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
217 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
218 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
219 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
220 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
221 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
225 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
229 #undef SETUP_VFILTER_OPTION
231 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
232 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
233 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
234 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
235 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
236 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
237 CONNECT( ui.topBotCropSync, toggled( bool ),
238 ui.cropBotPx, setDisabled( bool ) );
239 CONNECT( ui.leftRightCropSync, toggled( bool ),
240 ui.cropRightPx, setDisabled( bool ) );
243 void ExtVideo::cropChange()
245 if( ui.topBotCropSync->isChecked() )
246 ui.cropBotPx->setValue( ui.cropTopPx->value() );
247 if( ui.leftRightCropSync->isChecked() )
248 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
250 p_vout = THEMIM->getVout();
253 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
254 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
255 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
256 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
257 vlc_object_release( p_vout );
261 void ExtVideo::clean()
263 ui.cropTopPx->setValue( 0 );
264 ui.cropBotPx->setValue( 0 );
265 ui.cropLeftPx->setValue( 0 );
266 ui.cropRightPx->setValue( 0 );
269 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
271 char *psz_parser, *psz_string;
272 const char *psz_filter_type;
274 /* FIXME temporary hack */
275 const char *psz_module_name = psz_name;
276 if( !strcmp( psz_name, "wall" ) ||
277 !strcmp( psz_name, "panoramix" ) ||
278 !strcmp( psz_name, "clone" ) )
279 psz_module_name = "video_filter_wrapper";
281 module_t *p_obj = module_find( psz_module_name );
284 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
288 if( module_provides( p_obj, "video filter" ) )
290 psz_filter_type = "vout-filter";
292 else if( module_provides( p_obj, "video filter2" ) )
294 psz_filter_type = "video-filter";
296 else if( module_provides( p_obj, "sub filter" ) )
298 psz_filter_type = "sub-filter";
302 module_release (p_obj);
303 msg_Err( p_intf, "Unknown video filter type." );
306 module_release (p_obj);
308 psz_string = config_GetPsz( p_intf, psz_filter_type );
310 if( !psz_string ) psz_string = strdup( "" );
312 psz_parser = strstr( psz_string, psz_name );
318 psz_parser = psz_string;
319 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
320 psz_string, psz_name ) == -1 )
336 if( *( psz_parser + strlen( psz_name ) ) == ':' )
338 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
339 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
346 /* Remove trailing : : */
347 if( strlen( psz_string ) > 0 &&
348 *( psz_string + strlen( psz_string ) -1 ) == ':' )
350 *( psz_string + strlen( psz_string ) -1 ) = '\0';
359 /* Vout is not kept, so put that in the config */
360 config_PutPsz( p_intf, psz_filter_type, psz_string );
362 /* Try to set on the fly */
363 p_vout = THEMIM->getVout();
366 var_SetString( p_vout, psz_filter_type, psz_string );
367 vlc_object_release( p_vout );
373 void ExtVideo::updateFilters()
375 QString module = ModuleFromWidgetName( sender() );
377 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
378 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
380 ChangeVFiltersString( qtu( module ),
381 checkbox ? checkbox->isChecked()
382 : groupbox->isChecked() );
385 void ExtVideo::initComboBoxItems( QObject *widget )
387 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
388 if( !combobox ) return;
390 QString option = OptionFromWidgetName( widget );
391 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
395 int i_type = p_item->i_type & CONFIG_ITEM;
396 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
398 if( i_type == CONFIG_ITEM_INTEGER
399 || i_type == CONFIG_ITEM_BOOL )
400 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
401 p_item->pi_list[i_index] );
402 else if( i_type == CONFIG_ITEM_STRING )
403 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
404 p_item->ppsz_list[i_index] );
409 msg_Err( p_intf, "Couldn't find option \"%s\".",
414 void ExtVideo::setWidgetValue( QObject *widget )
416 QString module = ModuleFromWidgetName( widget->parent() );
417 //std::cout << "Module name: " << module.toStdString() << std::endl;
418 QString option = OptionFromWidgetName( widget );
419 //std::cout << "Option name: " << option.toStdString() << std::endl;
421 vlc_object_t *p_obj = ( vlc_object_t * )
422 vlc_object_find_name( p_intf->p_libvlc,
432 "Module instance %s not found, looking in config values.",
435 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
438 case VLC_VAR_INTEGER:
440 val.i_int = config_GetInt( p_intf, qtu( option ) );
443 val.f_float = config_GetFloat( p_intf, qtu( option ) );
446 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
452 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
453 var_Get( p_obj, qtu( option ), &val );
454 vlc_object_release( p_obj );
457 /* Try to cast to all the widgets we're likely to encounter. Only
458 * one of the casts is expected to work. */
459 QSlider *slider = qobject_cast<QSlider*> ( widget );
460 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
461 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
462 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
463 QDial *dial = qobject_cast<QDial*> ( widget );
464 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
465 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
467 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
469 if( slider ) slider->setValue( val.i_int );
470 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
472 else if( spinbox ) spinbox->setValue( val.i_int );
473 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
477 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
478 lineedit->setText( str );
480 else if( combobox ) combobox->setCurrentIndex(
481 combobox->findData( qlonglong(val.i_int) ) );
482 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
484 else if( i_type == VLC_VAR_FLOAT )
486 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
487 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
488 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
490 else if( i_type == VLC_VAR_STRING )
492 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
493 else if( combobox ) combobox->setCurrentIndex(
494 combobox->findData( qfu( val.psz_string ) ) );
495 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
496 free( val.psz_string );
501 "Module %s's %s variable is of an unsupported type ( %d )",
507 void ExtVideo::updateFilterOptions()
509 QString module = ModuleFromWidgetName( sender()->parent() );
510 //std::cout << "Module name: " << module.toStdString() << std::endl;
511 QString option = OptionFromWidgetName( sender() );
512 //std::cout << "Option name: " << option.toStdString() << std::endl;
514 vlc_object_t *p_obj = ( vlc_object_t * )
515 vlc_object_find_name( p_intf->p_libvlc,
522 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
523 i_type = config_GetType( p_intf, qtu( option ) );
524 b_is_command = false;
528 i_type = var_Type( p_obj, qtu( option ) );
529 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
534 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.",
537 /* FIXME: restart automatically somewhere near the end of this function */
540 /* Try to cast to all the widgets we're likely to encounter. Only
541 * one of the casts is expected to work. */
542 QSlider *slider = qobject_cast<QSlider*> ( sender() );
543 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
544 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
545 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
546 QDial *dial = qobject_cast<QDial*> ( sender() );
547 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
548 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
550 i_type &= VLC_VAR_CLASS;
551 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
554 if( slider ) i_int = slider->value();
555 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
556 else if( spinbox ) i_int = spinbox->value();
557 else if( dial ) i_int = ( 540-dial->value() )%360;
558 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
559 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
560 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
561 config_PutInt( p_intf, qtu( option ), i_int );
564 if( i_type == VLC_VAR_INTEGER )
565 var_SetInteger( p_obj, qtu( option ), i_int );
567 var_SetBool( p_obj, qtu( option ), i_int );
570 else if( i_type == VLC_VAR_FLOAT )
573 if( slider ) f_float = ( double )slider->value()
574 / ( double )slider->tickInterval(); /* hack alert! */
575 else if( doublespinbox ) f_float = doublespinbox->value();
576 else if( lineedit ) f_float = lineedit->text().toDouble();
577 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
578 config_PutFloat( p_intf, qtu( option ), f_float );
580 var_SetFloat( p_obj, qtu( option ), f_float );
582 else if( i_type == VLC_VAR_STRING )
584 char *psz_string = NULL;
585 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
586 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
587 combobox->currentIndex() ).toString() ) );
588 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
589 config_PutPsz( p_intf, qtu( option ), psz_string );
591 var_SetString( p_obj, qtu( option ), psz_string );
596 "Module %s's %s variable is of an unsupported type ( %d )",
601 if( p_obj ) vlc_object_release( p_obj );
605 void ExtVideo::gotoConf( QObject* src )
607 #define SHOWCONF( module ) \
608 if( src->objectName().contains( module ) ) \
610 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
614 SHOWCONF( "magnify" );
616 SHOWCONF( "ripple" );
617 SHOWCONF( "invert" );
618 SHOWCONF( "puzzle" );
620 SHOWCONF( "gradient" );
621 SHOWCONF( "colorthres" )
625 /**********************************************************************
627 **********************************************************************/
629 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
630 : QWidget( _parent ), p_intf( _p_intf )
634 BUTTONACT( ui.refresh, Refresh() );
639 void ExtV4l2::showEvent( QShowEvent *event )
641 QWidget::showEvent( event );
645 void ExtV4l2::Refresh( void )
647 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
651 ui.vboxLayout->removeWidget( box );
657 vlc_value_t val, text, name;
658 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
662 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
664 vlc_object_release( p_obj );
668 box = new QGroupBox( this );
669 ui.vboxLayout->addWidget( box );
670 QVBoxLayout *layout = new QVBoxLayout( box );
671 box->setLayout( layout );
673 for( int i = 0; i < val.p_list->i_count; i++ )
675 const char *psz_var = text.p_list->p_values[i].psz_string;
676 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
677 const char *psz_label = name.psz_string;
678 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
679 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
681 int i_type = var_Type( p_obj, psz_var );
682 switch( i_type & VLC_VAR_TYPE )
684 case VLC_VAR_INTEGER:
686 QLabel *label = new QLabel( psz_label, box );
687 QHBoxLayout *hlayout = new QHBoxLayout();
688 hlayout->addWidget( label );
689 int i_val = var_GetInteger( p_obj, psz_var );
690 if( i_type & VLC_VAR_HASCHOICE )
692 QComboBox *combobox = new QComboBox( box );
693 combobox->setObjectName( psz_var );
695 vlc_value_t val2, text2;
696 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
698 for( int j = 0; j < val2.p_list->i_count; j++ )
701 text2.p_list->p_values[j].psz_string,
702 qlonglong( val2.p_list->p_values[j].i_int) );
703 if( i_val == val2.p_list->p_values[j].i_int )
704 combobox->setCurrentIndex( j );
706 var_FreeList( &val2, &text2 );
708 CONNECT( combobox, currentIndexChanged( int ), this,
709 ValueChange( int ) );
710 hlayout->addWidget( combobox );
714 QSlider *slider = new QSlider( box );
715 slider->setObjectName( psz_var );
716 slider->setOrientation( Qt::Horizontal );
718 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
720 slider->setMinimum( val2.i_int );
721 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
723 slider->setMaximum( val2.i_int );
724 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
726 slider->setSingleStep( val2.i_int );
727 slider->setValue( i_val );
729 CONNECT( slider, valueChanged( int ), this,
730 ValueChange( int ) );
731 hlayout->addWidget( slider );
733 layout->addLayout( hlayout );
738 QCheckBox *button = new QCheckBox( psz_label, box );
739 button->setObjectName( psz_var );
740 button->setChecked( var_GetBool( p_obj, psz_var ) );
742 CONNECT( button, clicked( bool ), this,
743 ValueChange( bool ) );
744 layout->addWidget( button );
749 if( i_type & VLC_VAR_ISCOMMAND )
751 QPushButton *button = new QPushButton( psz_label, box );
752 button->setObjectName( psz_var );
754 CONNECT( button, clicked( bool ), this,
755 ValueChange( bool ) );
756 layout->addWidget( button );
760 QLabel *label = new QLabel( psz_label, box );
761 layout->addWidget( label );
766 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
769 free( name.psz_string );
771 var_FreeList( &val, &text );
772 vlc_object_release( p_obj );
776 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
781 void ExtV4l2::ValueChange( bool value )
783 ValueChange( (int)value );
786 void ExtV4l2::ValueChange( int value )
788 QObject *s = sender();
789 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
792 char *psz_var = strdup( qtu( s->objectName() ) );
793 int i_type = var_Type( p_obj, psz_var );
794 switch( i_type & VLC_VAR_TYPE )
796 case VLC_VAR_INTEGER:
797 if( i_type & VLC_VAR_HASCHOICE )
799 QComboBox *combobox = qobject_cast<QComboBox*>( s );
800 value = combobox->itemData( value ).toInt();
802 var_SetInteger( p_obj, psz_var, value );
805 var_SetBool( p_obj, psz_var, value );
808 var_TriggerCallback( p_obj, psz_var );
812 vlc_object_release( p_obj );
816 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
821 /**********************************************************************
823 **********************************************************************/
825 static const QString band_frequencies[] =
827 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
828 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
831 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
832 QWidget( _parent ) , p_intf( _p_intf )
834 QFont smallFont = QApplication::font();
835 smallFont.setPointSize( smallFont.pointSize() - 3 );
838 ui.preampLabel->setFont( smallFont );
840 /* Setup of presetsComboBox */
841 presetsComboBox = ui.presetsCombo;
842 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
844 /* Add the sliders for the Bands */
845 QGridLayout *grid = new QGridLayout( ui.frame );
846 grid->setMargin( 0 );
847 for( int i = 0 ; i < BANDS ; i++ )
849 bands[i] = new QSlider( Qt::Vertical );
850 bands[i]->setMaximum( 400 );
851 bands[i]->setValue( 200 );
852 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
854 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
855 band_texts[i]->setFont( smallFont );
857 grid->addWidget( bands[i], 0, i );
858 grid->addWidget( band_texts[i], 1, i );
861 /* Add the listed presets */
862 for( int i = 0 ; i < NB_PRESETS ; i ++ )
864 presetsComboBox->addItem( qtr( preset_list_text[i] ),
865 QVariant( preset_list[i] ) );
869 BUTTONACT( ui.enableCheck, enable() );
870 BUTTONACT( ui.eq2PassCheck, set2Pass() );
871 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
873 /* Do the update from the value of the core */
877 /* Write down initial values */
878 void Equalizer::updateUIFromCore()
880 char *psz_af, *psz_pres, *psz_bands;
884 aout_instance_t *p_aout = THEMIM->getAout();
887 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
888 psz_pres = var_GetString( p_aout, "equalizer-preset" );
889 if( var_GetBool( p_aout, "equalizer-2pass" ) )
890 ui.eq2PassCheck->setChecked( true );
891 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
892 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
893 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
894 vlc_object_release( p_aout );
898 psz_af = config_GetPsz( p_intf, "audio-filter" );
899 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
900 if( config_GetInt( p_intf, "equalizer-2pass" ) )
901 ui.eq2PassCheck->setChecked( true );
902 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
903 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
904 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
906 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
907 ui.enableCheck->setChecked( true );
908 enable( ui.enableCheck->isChecked() );
910 presetsComboBox->setCurrentIndex( i_preset );
912 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
914 if( psz_bands && strlen( psz_bands ) > 1 )
916 char *psz_bands_orig = psz_bands;
917 for( int i = 0; i < BANDS; i++ )
919 const float f = us_strtod(psz_bands, &psz_bands );
920 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
921 if( psz_bands == NULL || *psz_bands == '\0' ) break;
923 if( *psz_bands == '\0' ) break;
925 free( psz_bands_orig );
927 else free( psz_bands );
933 /* Functin called when enableButton is toggled */
934 void Equalizer::enable()
936 bool en = ui.enableCheck->isChecked();
937 aout_EnableFilter( THEPL, "equalizer", en );
938 // aout_EnableFilter( THEPL, "upmixer", en );
939 // aout_EnableFilter( THEPL, "vsurround", en );
942 if( presetsComboBox->currentIndex() < 0 )
943 presetsComboBox->setCurrentIndex( 0 );
947 void Equalizer::enable( bool en )
949 ui.eq2PassCheck->setEnabled( en );
950 presetsComboBox->setEnabled( en );
951 ui.presetLabel->setEnabled( en );
952 ui.preampLabel->setEnabled( en );
953 ui.preampSlider->setEnabled( en );
954 for( int i = 0 ; i< BANDS; i++ )
956 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
960 /* Function called when the set2Pass button is activated */
961 void Equalizer::set2Pass()
963 aout_instance_t *p_aout= THEMIM->getAout();
964 bool b_2p = ui.eq2PassCheck->isChecked();
968 var_SetBool( p_aout, "equalizer-2pass", b_2p );
969 vlc_object_release( p_aout );
971 config_PutInt( p_intf, "equalizer-2pass", b_2p );
974 /* Function called when the preamp slider is moved */
975 void Equalizer::setPreamp()
977 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
978 aout_instance_t *p_aout = THEMIM->getAout();
980 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
984 //delCallbacks( p_aout );
985 var_SetFloat( p_aout, "equalizer-preamp", f );
986 //addCallbacks( p_aout );
987 vlc_object_release( p_aout );
989 config_PutFloat( p_intf, "equalizer-preamp", f );
992 void Equalizer::setCoreBands()
994 /**\todo smoothing */
997 for( int i = 0; i < BANDS; i++ )
999 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1000 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1002 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1003 values += " " + val;
1005 const char *psz_values = values.toAscii().constData();
1007 aout_instance_t *p_aout = THEMIM->getAout();
1010 //delCallbacks( p_aout );
1011 var_SetString( p_aout, "equalizer-bands", psz_values );
1012 //addCallbacks( p_aout );
1013 vlc_object_release( p_aout );
1017 char * Equalizer::createValuesFromPreset( int i_preset )
1021 /* Create the QString in Qt */
1022 for( int i = 0 ; i< BANDS ;i++ )
1023 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1025 /* Convert it to char * */
1026 return strdup( values.toAscii().constData() );
1029 void Equalizer::setCorePreset( int i_preset )
1034 /* Update pre-amplification in the UI */
1035 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1036 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1037 ui.preampLabel->setText( qtr( "Preamp\n" )
1038 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1040 char *psz_values = createValuesFromPreset( i_preset );
1041 if( !psz_values ) return ;
1043 char *p = psz_values;
1044 for( int i = 0; i < BANDS && *p; i++ )
1046 const float f = us_strtod( p, &p );
1048 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1049 band_texts[i]->setText( band_frequencies[i] + "\n"
1050 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1052 p++; /* skip separator */
1055 /* Apply presets to audio output */
1056 aout_instance_t *p_aout= THEMIM->getAout();
1059 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1061 var_SetString( p_aout, "equalizer-bands", psz_values );
1062 var_SetFloat( p_aout, "equalizer-preamp",
1063 eqz_preset_10b[i_preset]->f_preamp );
1064 vlc_object_release( p_aout );
1066 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1067 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1068 config_PutFloat( p_intf, "equalizer-preamp",
1069 eqz_preset_10b[i_preset]->f_preamp );
1073 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1074 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1076 char *psz_preset = newval.psz_string;
1077 Equalizer *eq = ( Equalizer * )p_data;
1078 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1079 eq->presetsComboBox->setCurrentIndex( i_preset );
1083 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1085 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1086 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1087 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1090 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1092 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1093 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1094 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1097 /**********************************************************************
1099 **********************************************************************/
1101 /**********************************************************************
1102 * Dynamic range compressor
1103 **********************************************************************/
1107 const char *psz_name;
1108 const char *psz_descs;
1109 const char *psz_units;
1110 const float f_min; // min
1111 const float f_max; // max
1112 const float f_value; // value
1113 const float f_resolution; // resolution
1116 static const comp_controls_t comp_controls[] =
1118 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1119 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1120 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1121 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1122 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1123 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1124 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1127 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1128 : QWidget( _parent ) , p_intf( _p_intf )
1130 QFont smallFont = QApplication::font();
1131 smallFont.setPointSize( smallFont.pointSize() - 3 );
1133 QGridLayout *layout = new QGridLayout( this );
1134 layout->setMargin( 0 );
1136 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1137 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1139 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1141 const int i_min = (int)( comp_controls[i].f_min
1142 / comp_controls[i].f_resolution );
1143 const int i_max = (int)( comp_controls[i].f_max
1144 / comp_controls[i].f_resolution );
1145 const int i_val = (int)( comp_controls[i].f_value
1146 / comp_controls[i].f_resolution );
1148 compCtrl[i] = new QSlider( Qt::Vertical );
1149 compCtrl[i]->setMinimum( i_min );
1150 compCtrl[i]->setMaximum( i_max );
1151 compCtrl[i]->setValue( i_val );
1153 oldControlVars[i] = comp_controls[i].f_value;
1155 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1157 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1158 ctrl_texts[i]->setFont( smallFont );
1159 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1161 ctrl_readout[i] = new QLabel;
1162 ctrl_readout[i]->setFont( smallFont );
1163 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1165 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1166 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1167 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1170 BUTTONACT( enableCheck, enable() );
1172 /* Write down initial values */
1173 aout_instance_t *p_aout = THEMIM->getAout();
1178 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1179 for( int i = 0; i < NUM_CP_CTRL; i++ )
1181 controlVars[i] = var_GetFloat( p_aout,
1182 comp_controls[i].psz_name );
1184 vlc_object_release( p_aout );
1188 psz_af = config_GetPsz( p_intf, "audio-filter" );
1189 for( int i = 0; i < NUM_CP_CTRL; i++ )
1191 controlVars[i] = config_GetFloat( p_intf,
1192 comp_controls[i].psz_name );
1195 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1197 enableCheck->setChecked( true );
1200 enable( enableCheck->isChecked() );
1201 updateSliders( controlVars );
1202 setValues( controlVars );
1205 void Compressor::enable()
1207 bool en = enableCheck->isChecked();
1208 aout_EnableFilter( THEPL, "compressor", en );
1212 void Compressor::enable( bool en )
1214 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1216 compCtrl[i]->setEnabled( en );
1217 ctrl_texts[i]->setEnabled( en );
1218 ctrl_readout[i]->setEnabled( en );
1222 void Compressor::updateSliders( float * controlVars )
1224 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1226 if( oldControlVars[i] != controlVars[i] )
1228 compCtrl[i]->setValue(
1229 (int)( controlVars[i] / comp_controls[i].f_resolution ) );
1234 void Compressor::setInitValues()
1236 setValues( controlVars );
1239 void Compressor::setValues( float * controlVars )
1241 aout_instance_t *p_aout = THEMIM->getAout();
1243 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1245 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1246 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1247 + qtr( comp_controls[i].psz_units ) );
1248 if( oldControlVars[i] != f )
1252 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1254 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1255 oldControlVars[i] = f;
1260 vlc_object_release( p_aout );
1264 /**********************************************************************
1266 **********************************************************************/
1269 const char *psz_name;
1270 const char *psz_desc;
1273 static const spat_controls_t spat_controls[] =
1275 { "spatializer-roomsize", _("Size") },
1276 { "spatializer-width", _("Width") },
1277 { "spatializer-wet", _("Wet") },
1278 { "spatializer-dry", _("Dry") },
1279 { "spatializer-damp", _("Damp") },
1282 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1283 : QWidget( _parent ) , p_intf( _p_intf )
1285 QFont smallFont = QApplication::font();
1286 smallFont.setPointSize( smallFont.pointSize() - 3 );
1288 QGridLayout *layout = new QGridLayout( this );
1289 layout->setMargin( 0 );
1291 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1292 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1294 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1296 spatCtrl[i] = new QSlider( Qt::Vertical );
1299 spatCtrl[i]->setMaximum( 10 );
1300 spatCtrl[i]->setValue( 2 );
1304 spatCtrl[i]->setMaximum( 10 );
1305 spatCtrl[i]->setValue( 0 );
1306 spatCtrl[i]->setMinimum( -10 );
1309 oldControlVars[i] = spatCtrl[i]->value();
1311 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1313 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1314 ctrl_texts[i]->setFont( smallFont );
1316 ctrl_readout[i] = new QLabel;
1317 ctrl_readout[i]->setFont( smallFont );
1319 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1320 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1321 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1324 BUTTONACT( enableCheck, enable() );
1326 /* Write down initial values */
1327 aout_instance_t *p_aout = THEMIM->getAout();
1332 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1333 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1335 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1337 vlc_object_release( p_aout );
1341 psz_af = config_GetPsz( p_intf, "audio-filter" );
1342 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1344 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1347 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1348 enableCheck->setChecked( true );
1350 enable( enableCheck->isChecked() );
1351 setValues( controlVars );
1354 void Spatializer::enable()
1356 bool en = enableCheck->isChecked();
1357 aout_EnableFilter( THEPL, "spatializer", en );
1361 void Spatializer::enable( bool en )
1363 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1365 spatCtrl[i]->setEnabled( en );
1366 ctrl_texts[i]->setEnabled( en );
1367 ctrl_readout[i]->setEnabled( en );
1370 void Spatializer::setInitValues()
1372 setValues( controlVars );
1375 void Spatializer::setValues( float *controlVars )
1377 aout_instance_t *p_aout = THEMIM->getAout();
1379 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1381 float f = (float)( spatCtrl[i]->value() );
1382 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1386 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1388 if( oldControlVars[i] != spatCtrl[i]->value() )
1390 var_SetFloat( p_aout, spat_controls[i].psz_name,
1391 ( float )spatCtrl[i]->value() );
1392 config_PutFloat( p_intf, spat_controls[i].psz_name,
1393 ( float ) spatCtrl[i]->value() );
1394 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1397 vlc_object_release( p_aout );
1401 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1403 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1404 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1407 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1409 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1410 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1413 #include <QToolButton>
1414 #include <QGridLayout>
1416 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1417 QWidget( _parent ) , p_intf( _p_intf )
1419 QGroupBox *AVBox, *subsBox;
1421 QToolButton *moinsAV, *plusAV;
1422 QToolButton *moinssubs, *plussubs;
1423 QToolButton *moinssubSpeed, *plussubSpeed;
1425 QToolButton *updateButton;
1427 b_userAction = true;
1429 QGridLayout *mainLayout = new QGridLayout( this );
1432 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1433 QGridLayout *AVLayout = new QGridLayout( AVBox );
1435 moinsAV = new QToolButton;
1436 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1437 moinsAV->setAutoRaise( true );
1438 moinsAV->setText( "-" );
1439 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1441 plusAV = new QToolButton;
1442 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1443 plusAV->setAutoRaise( true );
1444 plusAV->setText( "+" );
1445 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1447 QLabel *AVLabel = new QLabel;
1448 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1449 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1451 AVSpin = new QDoubleSpinBox;
1452 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1453 AVSpin->setDecimals( 3 );
1454 AVSpin->setMinimum( -600.0 );
1455 AVSpin->setMaximum( 600.0 );
1456 AVSpin->setSingleStep( 0.1 );
1457 AVSpin->setToolTip( qtr( "A positive value means that\n"
1458 "the audio is ahead of the video" ) );
1459 AVSpin->setSuffix( " s" );
1460 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1461 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1465 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1466 QGridLayout *subsLayout = new QGridLayout( subsBox );
1468 moinssubs = new QToolButton;
1469 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1470 moinssubs->setAutoRaise( true );
1471 moinssubs->setText( "-" );
1472 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1474 plussubs = new QToolButton;
1475 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1476 plussubs->setAutoRaise( true );
1477 plussubs->setText( "+" );
1478 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1480 QLabel *subsLabel = new QLabel;
1481 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1482 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1484 subsSpin = new QDoubleSpinBox;
1485 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1486 subsSpin->setDecimals( 3 );
1487 subsSpin->setMinimum( -600.0 );
1488 subsSpin->setMaximum( 600.0 );
1489 subsSpin->setSingleStep( 0.1 );
1490 subsSpin->setToolTip( qtr( "A positive value means that\n"
1491 "the subtitles are ahead of the video" ) );
1492 subsSpin->setSuffix( " s" );
1493 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1496 moinssubSpeed = new QToolButton;
1497 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1498 moinssubSpeed->setAutoRaise( true );
1499 moinssubSpeed->setText( "-" );
1500 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1502 plussubSpeed = new QToolButton;
1503 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1504 plussubSpeed->setAutoRaise( true );
1505 plussubSpeed->setText( "+" );
1506 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1508 QLabel *subSpeedLabel = new QLabel;
1509 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1510 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1512 subSpeedSpin = new QDoubleSpinBox;
1513 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1514 subSpeedSpin->setDecimals( 3 );
1515 subSpeedSpin->setMinimum( 1 );
1516 subSpeedSpin->setMaximum( 100 );
1517 subSpeedSpin->setSingleStep( 0.2 );
1518 subSpeedSpin->setSuffix( " fps" );
1519 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1521 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1523 updateButton = new QToolButton;
1524 updateButton->setAutoRaise( true );
1525 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1528 /* Various Connects */
1529 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1530 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1531 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1532 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1533 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1534 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1535 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1536 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1537 CONNECT( subSpeedSpin, valueChanged ( double ),
1538 this, adjustSubsSpeed( double ) );
1540 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1541 BUTTON_SET_ACT_I( updateButton, "", update,
1542 qtr( "Force update of this dialog's values" ), update() );
1548 void SyncControls::clean()
1550 b_userAction = false;
1551 AVSpin->setValue( 0.0 );
1552 subsSpin->setValue( 0.0 );
1553 subSpeedSpin->setValue( 1.0 );
1554 b_userAction = true;
1557 void SyncControls::update()
1559 b_userAction = false;
1562 if( THEMIM->getInput() )
1564 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1565 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1566 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1567 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1568 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1570 b_userAction = true;
1573 void SyncControls::advanceAudio( double f_advance )
1575 if( THEMIM->getInput() && b_userAction )
1577 int64_t i_delay = f_advance * 1000000;
1578 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1582 void SyncControls::advanceSubs( double f_advance )
1584 if( THEMIM->getInput() && b_userAction )
1586 int64_t i_delay = f_advance * 1000000;
1587 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1591 void SyncControls::adjustSubsSpeed( double f_fps )
1593 if( THEMIM->getInput() && b_userAction )
1595 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1599 /**********************************************************************
1600 * Video filters / Adjust
1601 **********************************************************************/
1603 /**********************************************************************
1604 * Extended playbak controls
1605 **********************************************************************/