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( posterize )
142 SETUP_VFILTER_OPTION( posterizeLevelSpin, valueChanged( int ) )
144 SETUP_VFILTER( colorthres )
145 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
146 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
147 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
149 SETUP_VFILTER( invert )
151 SETUP_VFILTER( gradient )
152 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
153 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
154 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
156 SETUP_VFILTER( motionblur )
157 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
159 SETUP_VFILTER( motiondetect )
161 SETUP_VFILTER( noise )
163 SETUP_VFILTER( psychedelic )
165 SETUP_VFILTER( sharpen )
166 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
168 SETUP_VFILTER( ripple )
170 SETUP_VFILTER( wave )
172 SETUP_VFILTER( transform )
173 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
175 SETUP_VFILTER( rotate )
176 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
177 ui.rotateAngleDial->setWrapping( true );
178 ui.rotateAngleDial->setNotchesVisible( true );
180 SETUP_VFILTER( puzzle )
181 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
182 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
183 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
185 SETUP_VFILTER( magnify )
187 SETUP_VFILTER( clone )
188 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
190 SETUP_VFILTER( wall )
191 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
192 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
194 SETUP_VFILTER( panoramix )
195 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
196 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
199 SETUP_VFILTER( erase )
200 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
201 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
202 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
204 SETUP_VFILTER( marq )
205 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
206 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
208 SETUP_VFILTER( logo )
209 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
210 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
211 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
212 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
214 SETUP_VFILTER( gradfun )
215 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
217 if( module_exists( "atmo" ) )
219 SETUP_VFILTER( atmo )
220 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
221 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
222 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
223 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
224 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
225 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
226 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
227 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
231 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
235 #undef SETUP_VFILTER_OPTION
237 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
238 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
239 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
240 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
241 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
242 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
243 CONNECT( ui.topBotCropSync, toggled( bool ),
244 ui.cropBotPx, setDisabled( bool ) );
245 CONNECT( ui.leftRightCropSync, toggled( bool ),
246 ui.cropRightPx, setDisabled( bool ) );
249 void ExtVideo::cropChange()
251 if( ui.topBotCropSync->isChecked() )
252 ui.cropBotPx->setValue( ui.cropTopPx->value() );
253 if( ui.leftRightCropSync->isChecked() )
254 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
256 p_vout = THEMIM->getVout();
259 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
260 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
261 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
262 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
263 vlc_object_release( p_vout );
267 void ExtVideo::clean()
269 ui.cropTopPx->setValue( 0 );
270 ui.cropBotPx->setValue( 0 );
271 ui.cropLeftPx->setValue( 0 );
272 ui.cropRightPx->setValue( 0 );
275 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
277 char *psz_parser, *psz_string;
278 const char *psz_filter_type;
280 /* FIXME temporary hack */
281 const char *psz_module_name = psz_name;
282 if( !strcmp( psz_name, "wall" ) ||
283 !strcmp( psz_name, "panoramix" ) ||
284 !strcmp( psz_name, "clone" ) )
285 psz_module_name = "video_filter_wrapper";
287 module_t *p_obj = module_find( psz_module_name );
290 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
294 if( module_provides( p_obj, "video filter" ) )
296 psz_filter_type = "vout-filter";
298 else if( module_provides( p_obj, "video filter2" ) )
300 psz_filter_type = "video-filter";
302 else if( module_provides( p_obj, "sub filter" ) )
304 psz_filter_type = "sub-filter";
308 module_release (p_obj);
309 msg_Err( p_intf, "Unknown video filter type." );
312 module_release (p_obj);
314 psz_string = config_GetPsz( p_intf, psz_filter_type );
316 if( !psz_string ) psz_string = strdup( "" );
318 psz_parser = strstr( psz_string, psz_name );
324 psz_parser = psz_string;
325 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
326 psz_string, psz_name ) == -1 )
342 if( *( psz_parser + strlen( psz_name ) ) == ':' )
344 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
345 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
352 /* Remove trailing : : */
353 if( strlen( psz_string ) > 0 &&
354 *( psz_string + strlen( psz_string ) -1 ) == ':' )
356 *( psz_string + strlen( psz_string ) -1 ) = '\0';
365 /* Vout is not kept, so put that in the config */
366 config_PutPsz( p_intf, psz_filter_type, psz_string );
368 /* Try to set on the fly */
369 p_vout = THEMIM->getVout();
372 var_SetString( p_vout, psz_filter_type, psz_string );
373 vlc_object_release( p_vout );
379 void ExtVideo::updateFilters()
381 QString module = ModuleFromWidgetName( sender() );
383 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
384 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
386 ChangeVFiltersString( qtu( module ),
387 checkbox ? checkbox->isChecked()
388 : groupbox->isChecked() );
391 void ExtVideo::initComboBoxItems( QObject *widget )
393 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
394 if( !combobox ) return;
396 QString option = OptionFromWidgetName( widget );
397 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
401 int i_type = p_item->i_type & CONFIG_ITEM;
402 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
404 if( i_type == CONFIG_ITEM_INTEGER
405 || i_type == CONFIG_ITEM_BOOL )
406 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
407 p_item->pi_list[i_index] );
408 else if( i_type == CONFIG_ITEM_STRING )
409 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
410 p_item->ppsz_list[i_index] );
415 msg_Err( p_intf, "Couldn't find option \"%s\".",
420 void ExtVideo::setWidgetValue( QObject *widget )
422 QString module = ModuleFromWidgetName( widget->parent() );
423 //std::cout << "Module name: " << module.toStdString() << std::endl;
424 QString option = OptionFromWidgetName( widget );
425 //std::cout << "Option name: " << option.toStdString() << std::endl;
427 vlc_object_t *p_obj = ( vlc_object_t * )
428 vlc_object_find_name( p_intf->p_libvlc,
438 "Module instance %s not found, looking in config values.",
441 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
444 case VLC_VAR_INTEGER:
446 val.i_int = config_GetInt( p_intf, qtu( option ) );
449 val.f_float = config_GetFloat( p_intf, qtu( option ) );
452 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
458 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
459 var_Get( p_obj, qtu( option ), &val );
460 vlc_object_release( p_obj );
463 /* Try to cast to all the widgets we're likely to encounter. Only
464 * one of the casts is expected to work. */
465 QSlider *slider = qobject_cast<QSlider*> ( widget );
466 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
467 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
468 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
469 QDial *dial = qobject_cast<QDial*> ( widget );
470 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
471 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
473 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
475 if( slider ) slider->setValue( val.i_int );
476 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
478 else if( spinbox ) spinbox->setValue( val.i_int );
479 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
483 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
484 lineedit->setText( str );
486 else if( combobox ) combobox->setCurrentIndex(
487 combobox->findData( qlonglong(val.i_int) ) );
488 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
490 else if( i_type == VLC_VAR_FLOAT )
492 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
493 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
494 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
496 else if( i_type == VLC_VAR_STRING )
498 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
499 else if( combobox ) combobox->setCurrentIndex(
500 combobox->findData( qfu( val.psz_string ) ) );
501 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
502 free( val.psz_string );
507 "Module %s's %s variable is of an unsupported type ( %d )",
513 void ExtVideo::updateFilterOptions()
515 QString module = ModuleFromWidgetName( sender()->parent() );
516 //std::cout << "Module name: " << module.toStdString() << std::endl;
517 QString option = OptionFromWidgetName( sender() );
518 //std::cout << "Option name: " << option.toStdString() << std::endl;
520 vlc_object_t *p_obj = ( vlc_object_t * )
521 vlc_object_find_name( p_intf->p_libvlc,
528 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
529 i_type = config_GetType( p_intf, qtu( option ) );
530 b_is_command = false;
534 i_type = var_Type( p_obj, qtu( option ) );
535 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
540 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.",
543 /* FIXME: restart automatically somewhere near the end of this function */
546 /* Try to cast to all the widgets we're likely to encounter. Only
547 * one of the casts is expected to work. */
548 QSlider *slider = qobject_cast<QSlider*> ( sender() );
549 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
550 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
551 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
552 QDial *dial = qobject_cast<QDial*> ( sender() );
553 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
554 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
556 i_type &= VLC_VAR_CLASS;
557 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
560 if( slider ) i_int = slider->value();
561 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
562 else if( spinbox ) i_int = spinbox->value();
563 else if( dial ) i_int = ( 540-dial->value() )%360;
564 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
565 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
566 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
567 config_PutInt( p_intf, qtu( option ), i_int );
570 if( i_type == VLC_VAR_INTEGER )
571 var_SetInteger( p_obj, qtu( option ), i_int );
573 var_SetBool( p_obj, qtu( option ), i_int );
576 else if( i_type == VLC_VAR_FLOAT )
579 if( slider ) f_float = ( double )slider->value()
580 / ( double )slider->tickInterval(); /* hack alert! */
581 else if( doublespinbox ) f_float = doublespinbox->value();
582 else if( lineedit ) f_float = lineedit->text().toDouble();
583 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
584 config_PutFloat( p_intf, qtu( option ), f_float );
586 var_SetFloat( p_obj, qtu( option ), f_float );
588 else if( i_type == VLC_VAR_STRING )
590 char *psz_string = NULL;
591 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
592 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
593 combobox->currentIndex() ).toString() ) );
594 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
595 config_PutPsz( p_intf, qtu( option ), psz_string );
597 var_SetString( p_obj, qtu( option ), psz_string );
602 "Module %s's %s variable is of an unsupported type ( %d )",
607 if( p_obj ) vlc_object_release( p_obj );
611 void ExtVideo::gotoConf( QObject* src )
613 #define SHOWCONF( module ) \
614 if( src->objectName().contains( module ) ) \
616 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
620 SHOWCONF( "magnify" );
622 SHOWCONF( "ripple" );
623 SHOWCONF( "invert" );
624 SHOWCONF( "puzzle" );
626 SHOWCONF( "gradient" );
627 SHOWCONF( "colorthres" )
631 /**********************************************************************
633 **********************************************************************/
635 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
636 : QWidget( _parent ), p_intf( _p_intf )
640 BUTTONACT( ui.refresh, Refresh() );
645 void ExtV4l2::showEvent( QShowEvent *event )
647 QWidget::showEvent( event );
651 void ExtV4l2::Refresh( void )
653 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
657 ui.vboxLayout->removeWidget( box );
663 vlc_value_t val, text, name;
664 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
668 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
670 vlc_object_release( p_obj );
674 box = new QGroupBox( this );
675 ui.vboxLayout->addWidget( box );
676 QVBoxLayout *layout = new QVBoxLayout( box );
677 box->setLayout( layout );
679 for( int i = 0; i < val.p_list->i_count; i++ )
681 const char *psz_var = text.p_list->p_values[i].psz_string;
682 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
683 const char *psz_label = name.psz_string;
684 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
685 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
687 int i_type = var_Type( p_obj, psz_var );
688 switch( i_type & VLC_VAR_TYPE )
690 case VLC_VAR_INTEGER:
692 QLabel *label = new QLabel( psz_label, box );
693 QHBoxLayout *hlayout = new QHBoxLayout();
694 hlayout->addWidget( label );
695 int i_val = var_GetInteger( p_obj, psz_var );
696 if( i_type & VLC_VAR_HASCHOICE )
698 QComboBox *combobox = new QComboBox( box );
699 combobox->setObjectName( psz_var );
701 vlc_value_t val2, text2;
702 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
704 for( int j = 0; j < val2.p_list->i_count; j++ )
707 text2.p_list->p_values[j].psz_string,
708 qlonglong( val2.p_list->p_values[j].i_int) );
709 if( i_val == val2.p_list->p_values[j].i_int )
710 combobox->setCurrentIndex( j );
712 var_FreeList( &val2, &text2 );
714 CONNECT( combobox, currentIndexChanged( int ), this,
715 ValueChange( int ) );
716 hlayout->addWidget( combobox );
720 QSlider *slider = new QSlider( box );
721 slider->setObjectName( psz_var );
722 slider->setOrientation( Qt::Horizontal );
724 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
726 slider->setMinimum( val2.i_int );
727 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
729 slider->setMaximum( val2.i_int );
730 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
732 slider->setSingleStep( val2.i_int );
733 slider->setValue( i_val );
735 CONNECT( slider, valueChanged( int ), this,
736 ValueChange( int ) );
737 hlayout->addWidget( slider );
739 layout->addLayout( hlayout );
744 QCheckBox *button = new QCheckBox( psz_label, box );
745 button->setObjectName( psz_var );
746 button->setChecked( var_GetBool( p_obj, psz_var ) );
748 CONNECT( button, clicked( bool ), this,
749 ValueChange( bool ) );
750 layout->addWidget( button );
755 if( i_type & VLC_VAR_ISCOMMAND )
757 QPushButton *button = new QPushButton( psz_label, box );
758 button->setObjectName( psz_var );
760 CONNECT( button, clicked( bool ), this,
761 ValueChange( bool ) );
762 layout->addWidget( button );
766 QLabel *label = new QLabel( psz_label, box );
767 layout->addWidget( label );
772 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
775 free( name.psz_string );
777 var_FreeList( &val, &text );
778 vlc_object_release( p_obj );
782 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
787 void ExtV4l2::ValueChange( bool value )
789 ValueChange( (int)value );
792 void ExtV4l2::ValueChange( int value )
794 QObject *s = sender();
795 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
798 char *psz_var = strdup( qtu( s->objectName() ) );
799 int i_type = var_Type( p_obj, psz_var );
800 switch( i_type & VLC_VAR_TYPE )
802 case VLC_VAR_INTEGER:
803 if( i_type & VLC_VAR_HASCHOICE )
805 QComboBox *combobox = qobject_cast<QComboBox*>( s );
806 value = combobox->itemData( value ).toInt();
808 var_SetInteger( p_obj, psz_var, value );
811 var_SetBool( p_obj, psz_var, value );
814 var_TriggerCallback( p_obj, psz_var );
818 vlc_object_release( p_obj );
822 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
827 /**********************************************************************
829 **********************************************************************/
831 static const QString band_frequencies[] =
833 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
834 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
837 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
838 QWidget( _parent ) , p_intf( _p_intf )
840 QFont smallFont = QApplication::font();
841 smallFont.setPointSize( smallFont.pointSize() - 3 );
844 ui.preampLabel->setFont( smallFont );
846 /* Setup of presetsComboBox */
847 presetsComboBox = ui.presetsCombo;
848 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
850 /* Add the sliders for the Bands */
851 QGridLayout *grid = new QGridLayout( ui.frame );
852 grid->setMargin( 0 );
853 for( int i = 0 ; i < BANDS ; i++ )
855 bands[i] = new QSlider( Qt::Vertical );
856 bands[i]->setMaximum( 400 );
857 bands[i]->setValue( 200 );
858 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
860 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
861 band_texts[i]->setFont( smallFont );
863 grid->addWidget( bands[i], 0, i );
864 grid->addWidget( band_texts[i], 1, i );
867 /* Add the listed presets */
868 for( int i = 0 ; i < NB_PRESETS ; i ++ )
870 presetsComboBox->addItem( qtr( preset_list_text[i] ),
871 QVariant( preset_list[i] ) );
875 BUTTONACT( ui.enableCheck, enable() );
876 BUTTONACT( ui.eq2PassCheck, set2Pass() );
877 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
879 /* Do the update from the value of the core */
883 /* Write down initial values */
884 void Equalizer::updateUIFromCore()
886 char *psz_af, *psz_pres, *psz_bands;
890 aout_instance_t *p_aout = THEMIM->getAout();
893 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
894 psz_pres = var_GetString( p_aout, "equalizer-preset" );
895 if( var_GetBool( p_aout, "equalizer-2pass" ) )
896 ui.eq2PassCheck->setChecked( true );
897 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
898 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
899 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
900 vlc_object_release( p_aout );
904 psz_af = config_GetPsz( p_intf, "audio-filter" );
905 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
906 if( config_GetInt( p_intf, "equalizer-2pass" ) )
907 ui.eq2PassCheck->setChecked( true );
908 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
909 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
910 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
912 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
913 ui.enableCheck->setChecked( true );
914 enable( ui.enableCheck->isChecked() );
916 presetsComboBox->setCurrentIndex( i_preset );
918 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
920 if( psz_bands && strlen( psz_bands ) > 1 )
922 char *psz_bands_orig = psz_bands;
923 for( int i = 0; i < BANDS; i++ )
925 const float f = us_strtod(psz_bands, &psz_bands );
926 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
927 if( psz_bands == NULL || *psz_bands == '\0' ) break;
929 if( *psz_bands == '\0' ) break;
931 free( psz_bands_orig );
933 else free( psz_bands );
939 /* Functin called when enableButton is toggled */
940 void Equalizer::enable()
942 bool en = ui.enableCheck->isChecked();
943 aout_EnableFilter( THEPL, "equalizer", en );
944 // aout_EnableFilter( THEPL, "upmixer", en );
945 // aout_EnableFilter( THEPL, "vsurround", en );
948 if( presetsComboBox->currentIndex() < 0 )
949 presetsComboBox->setCurrentIndex( 0 );
953 void Equalizer::enable( bool en )
955 ui.eq2PassCheck->setEnabled( en );
956 presetsComboBox->setEnabled( en );
957 ui.presetLabel->setEnabled( en );
958 ui.preampLabel->setEnabled( en );
959 ui.preampSlider->setEnabled( en );
960 for( int i = 0 ; i< BANDS; i++ )
962 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
966 /* Function called when the set2Pass button is activated */
967 void Equalizer::set2Pass()
969 aout_instance_t *p_aout= THEMIM->getAout();
970 bool b_2p = ui.eq2PassCheck->isChecked();
974 var_SetBool( p_aout, "equalizer-2pass", b_2p );
975 vlc_object_release( p_aout );
977 config_PutInt( p_intf, "equalizer-2pass", b_2p );
980 /* Function called when the preamp slider is moved */
981 void Equalizer::setPreamp()
983 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
984 aout_instance_t *p_aout = THEMIM->getAout();
986 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
990 //delCallbacks( p_aout );
991 var_SetFloat( p_aout, "equalizer-preamp", f );
992 //addCallbacks( p_aout );
993 vlc_object_release( p_aout );
995 config_PutFloat( p_intf, "equalizer-preamp", f );
998 void Equalizer::setCoreBands()
1000 /**\todo smoothing */
1003 for( int i = 0; i < BANDS; i++ )
1005 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1006 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1008 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1009 values += " " + val;
1011 const char *psz_values = values.toAscii().constData();
1013 aout_instance_t *p_aout = THEMIM->getAout();
1016 //delCallbacks( p_aout );
1017 var_SetString( p_aout, "equalizer-bands", psz_values );
1018 //addCallbacks( p_aout );
1019 vlc_object_release( p_aout );
1023 char * Equalizer::createValuesFromPreset( int i_preset )
1027 /* Create the QString in Qt */
1028 for( int i = 0 ; i< BANDS ;i++ )
1029 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1031 /* Convert it to char * */
1032 return strdup( values.toAscii().constData() );
1035 void Equalizer::setCorePreset( int i_preset )
1040 /* Update pre-amplification in the UI */
1041 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1042 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1043 ui.preampLabel->setText( qtr( "Preamp\n" )
1044 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1046 char *psz_values = createValuesFromPreset( i_preset );
1047 if( !psz_values ) return ;
1049 char *p = psz_values;
1050 for( int i = 0; i < BANDS && *p; i++ )
1052 const float f = us_strtod( p, &p );
1054 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1055 band_texts[i]->setText( band_frequencies[i] + "\n"
1056 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1058 p++; /* skip separator */
1061 /* Apply presets to audio output */
1062 aout_instance_t *p_aout= THEMIM->getAout();
1065 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1067 var_SetString( p_aout, "equalizer-bands", psz_values );
1068 var_SetFloat( p_aout, "equalizer-preamp",
1069 eqz_preset_10b[i_preset]->f_preamp );
1070 vlc_object_release( p_aout );
1072 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1073 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1074 config_PutFloat( p_intf, "equalizer-preamp",
1075 eqz_preset_10b[i_preset]->f_preamp );
1079 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1080 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1082 char *psz_preset = newval.psz_string;
1083 Equalizer *eq = ( Equalizer * )p_data;
1084 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1085 eq->presetsComboBox->setCurrentIndex( i_preset );
1089 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1091 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1092 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1093 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1096 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1098 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1099 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1100 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1103 /**********************************************************************
1105 **********************************************************************/
1107 /**********************************************************************
1108 * Dynamic range compressor
1109 **********************************************************************/
1113 const char *psz_name;
1114 const char *psz_descs;
1115 const char *psz_units;
1116 const float f_min; // min
1117 const float f_max; // max
1118 const float f_value; // value
1119 const float f_resolution; // resolution
1122 static const comp_controls_t comp_controls[] =
1124 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1125 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1126 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1127 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1128 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1129 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1130 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1133 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1134 : QWidget( _parent ) , p_intf( _p_intf )
1136 QFont smallFont = QApplication::font();
1137 smallFont.setPointSize( smallFont.pointSize() - 3 );
1139 QGridLayout *layout = new QGridLayout( this );
1141 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1142 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1144 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1146 const int i_min = (int)( comp_controls[i].f_min
1147 / comp_controls[i].f_resolution );
1148 const int i_max = (int)( comp_controls[i].f_max
1149 / comp_controls[i].f_resolution );
1150 const int i_val = (int)( comp_controls[i].f_value
1151 / comp_controls[i].f_resolution );
1153 compCtrl[i] = new QSlider( Qt::Vertical );
1154 compCtrl[i]->setMinimum( i_min );
1155 compCtrl[i]->setMaximum( i_max );
1156 compCtrl[i]->setValue( i_val );
1158 oldControlVars[i] = comp_controls[i].f_value;
1160 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1162 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1163 ctrl_texts[i]->setFont( smallFont );
1164 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1166 ctrl_readout[i] = new QLabel;
1167 ctrl_readout[i]->setFont( smallFont );
1168 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1170 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1171 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1172 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1175 BUTTONACT( enableCheck, enable() );
1177 /* Write down initial values */
1178 aout_instance_t *p_aout = THEMIM->getAout();
1183 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1184 for( int i = 0; i < NUM_CP_CTRL; i++ )
1186 controlVars[i] = var_GetFloat( p_aout,
1187 comp_controls[i].psz_name );
1189 vlc_object_release( p_aout );
1193 psz_af = config_GetPsz( p_intf, "audio-filter" );
1194 for( int i = 0; i < NUM_CP_CTRL; i++ )
1196 controlVars[i] = config_GetFloat( p_intf,
1197 comp_controls[i].psz_name );
1200 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1202 enableCheck->setChecked( true );
1205 enable( enableCheck->isChecked() );
1206 updateSliders( controlVars );
1207 setValues( controlVars );
1210 void Compressor::enable()
1212 bool en = enableCheck->isChecked();
1213 aout_EnableFilter( THEPL, "compressor", en );
1217 void Compressor::enable( bool en )
1219 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1221 compCtrl[i]->setEnabled( en );
1222 ctrl_texts[i]->setEnabled( en );
1223 ctrl_readout[i]->setEnabled( en );
1227 void Compressor::updateSliders( float * controlVars )
1229 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1231 if( oldControlVars[i] != controlVars[i] )
1233 compCtrl[i]->setValue(
1234 (int)( controlVars[i] / comp_controls[i].f_resolution ) );
1239 void Compressor::setInitValues()
1241 setValues( controlVars );
1244 void Compressor::setValues( float * controlVars )
1246 aout_instance_t *p_aout = THEMIM->getAout();
1248 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1250 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1251 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1252 + qtr( comp_controls[i].psz_units ) );
1253 if( oldControlVars[i] != f )
1257 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1259 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1260 oldControlVars[i] = f;
1265 vlc_object_release( p_aout );
1269 /**********************************************************************
1271 **********************************************************************/
1274 const char *psz_name;
1275 const char *psz_desc;
1278 static const spat_controls_t spat_controls[] =
1280 { "spatializer-roomsize", _("Size") },
1281 { "spatializer-width", _("Width") },
1282 { "spatializer-wet", _("Wet") },
1283 { "spatializer-dry", _("Dry") },
1284 { "spatializer-damp", _("Damp") },
1287 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1288 : QWidget( _parent ) , p_intf( _p_intf )
1290 QFont smallFont = QApplication::font();
1291 smallFont.setPointSize( smallFont.pointSize() - 3 );
1293 QGridLayout *layout = new QGridLayout( this );
1295 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1296 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1298 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1300 spatCtrl[i] = new QSlider( Qt::Vertical );
1303 spatCtrl[i]->setMaximum( 10 );
1304 spatCtrl[i]->setValue( 2 );
1308 spatCtrl[i]->setMaximum( 10 );
1309 spatCtrl[i]->setValue( 0 );
1310 spatCtrl[i]->setMinimum( -10 );
1313 oldControlVars[i] = spatCtrl[i]->value();
1315 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1317 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1318 ctrl_texts[i]->setFont( smallFont );
1320 ctrl_readout[i] = new QLabel;
1321 ctrl_readout[i]->setFont( smallFont );
1323 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1324 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1325 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1328 BUTTONACT( enableCheck, enable() );
1330 /* Write down initial values */
1331 aout_instance_t *p_aout = THEMIM->getAout();
1336 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1337 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1339 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1341 vlc_object_release( p_aout );
1345 psz_af = config_GetPsz( p_intf, "audio-filter" );
1346 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1348 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1351 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1352 enableCheck->setChecked( true );
1354 enable( enableCheck->isChecked() );
1355 setValues( controlVars );
1358 void Spatializer::enable()
1360 bool en = enableCheck->isChecked();
1361 aout_EnableFilter( THEPL, "spatializer", en );
1365 void Spatializer::enable( bool en )
1367 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1369 spatCtrl[i]->setEnabled( en );
1370 ctrl_texts[i]->setEnabled( en );
1371 ctrl_readout[i]->setEnabled( en );
1374 void Spatializer::setInitValues()
1376 setValues( controlVars );
1379 void Spatializer::setValues( float *controlVars )
1381 aout_instance_t *p_aout = THEMIM->getAout();
1383 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1385 float f = (float)( spatCtrl[i]->value() );
1386 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1390 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1392 if( oldControlVars[i] != spatCtrl[i]->value() )
1394 var_SetFloat( p_aout, spat_controls[i].psz_name,
1395 ( float )spatCtrl[i]->value() );
1396 config_PutFloat( p_intf, spat_controls[i].psz_name,
1397 ( float ) spatCtrl[i]->value() );
1398 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1401 vlc_object_release( p_aout );
1405 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1407 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1408 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1411 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1413 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1414 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1417 #include <QToolButton>
1418 #include <QGridLayout>
1420 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1421 QWidget( _parent ) , p_intf( _p_intf )
1423 QGroupBox *AVBox, *subsBox;
1425 QToolButton *moinsAV, *plusAV;
1426 QToolButton *moinssubs, *plussubs;
1427 QToolButton *moinssubSpeed, *plussubSpeed;
1429 QToolButton *updateButton;
1431 b_userAction = true;
1433 QGridLayout *mainLayout = new QGridLayout( this );
1436 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1437 QGridLayout *AVLayout = new QGridLayout( AVBox );
1439 moinsAV = new QToolButton;
1440 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1441 moinsAV->setAutoRaise( true );
1442 moinsAV->setText( "-" );
1443 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1445 plusAV = new QToolButton;
1446 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1447 plusAV->setAutoRaise( true );
1448 plusAV->setText( "+" );
1449 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1451 QLabel *AVLabel = new QLabel;
1452 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1453 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1455 AVSpin = new QDoubleSpinBox;
1456 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1457 AVSpin->setDecimals( 3 );
1458 AVSpin->setMinimum( -600.0 );
1459 AVSpin->setMaximum( 600.0 );
1460 AVSpin->setSingleStep( 0.1 );
1461 AVSpin->setToolTip( qtr( "A positive value means that\n"
1462 "the audio is ahead of the video" ) );
1463 AVSpin->setSuffix( " s" );
1464 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1465 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1469 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1470 QGridLayout *subsLayout = new QGridLayout( subsBox );
1472 moinssubs = new QToolButton;
1473 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1474 moinssubs->setAutoRaise( true );
1475 moinssubs->setText( "-" );
1476 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1478 plussubs = new QToolButton;
1479 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1480 plussubs->setAutoRaise( true );
1481 plussubs->setText( "+" );
1482 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1484 QLabel *subsLabel = new QLabel;
1485 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1486 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1488 subsSpin = new QDoubleSpinBox;
1489 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1490 subsSpin->setDecimals( 3 );
1491 subsSpin->setMinimum( -600.0 );
1492 subsSpin->setMaximum( 600.0 );
1493 subsSpin->setSingleStep( 0.1 );
1494 subsSpin->setToolTip( qtr( "A positive value means that\n"
1495 "the subtitles are ahead of the video" ) );
1496 subsSpin->setSuffix( " s" );
1497 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1500 moinssubSpeed = new QToolButton;
1501 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1502 moinssubSpeed->setAutoRaise( true );
1503 moinssubSpeed->setText( "-" );
1504 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1506 plussubSpeed = new QToolButton;
1507 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1508 plussubSpeed->setAutoRaise( true );
1509 plussubSpeed->setText( "+" );
1510 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1512 QLabel *subSpeedLabel = new QLabel;
1513 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1514 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1516 subSpeedSpin = new QDoubleSpinBox;
1517 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1518 subSpeedSpin->setDecimals( 3 );
1519 subSpeedSpin->setMinimum( 1 );
1520 subSpeedSpin->setMaximum( 100 );
1521 subSpeedSpin->setSingleStep( 0.2 );
1522 subSpeedSpin->setSuffix( " fps" );
1523 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1525 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1527 updateButton = new QToolButton;
1528 updateButton->setAutoRaise( true );
1529 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1532 /* Various Connects */
1533 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1534 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1535 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1536 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1537 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1538 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1539 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1540 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1541 CONNECT( subSpeedSpin, valueChanged ( double ),
1542 this, adjustSubsSpeed( double ) );
1544 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1545 BUTTON_SET_ACT_I( updateButton, "", update,
1546 qtr( "Force update of this dialog's values" ), update() );
1552 void SyncControls::clean()
1554 b_userAction = false;
1555 AVSpin->setValue( 0.0 );
1556 subsSpin->setValue( 0.0 );
1557 subSpeedSpin->setValue( 1.0 );
1558 b_userAction = true;
1561 void SyncControls::update()
1563 b_userAction = false;
1566 if( THEMIM->getInput() )
1568 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1569 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1570 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1571 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1572 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1574 b_userAction = true;
1577 void SyncControls::advanceAudio( double f_advance )
1579 if( THEMIM->getInput() && b_userAction )
1581 int64_t i_delay = f_advance * 1000000;
1582 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1586 void SyncControls::advanceSubs( double f_advance )
1588 if( THEMIM->getInput() && b_userAction )
1590 int64_t i_delay = f_advance * 1000000;
1591 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1595 void SyncControls::adjustSubsSpeed( double f_fps )
1597 if( THEMIM->getInput() && b_userAction )
1599 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1603 /**********************************************************************
1604 * Video filters / Adjust
1605 **********************************************************************/
1607 /**********************************************************************
1608 * Extended playbak controls
1609 **********************************************************************/