1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006-2012 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea .t videolan d@t org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #define __STDC_FORMAT_MACROS 1
38 #include <QGridLayout>
41 #include <QFileDialog>
43 #include "components/extended_panels.hpp"
44 #include "dialogs/preferences.hpp"
46 #include "input_manager.hpp"
47 #include "util/qt_dirs.hpp"
49 #include "../../audio_filter/equalizer_presets.h"
50 #include <vlc_intf_strings.h>
52 #include <vlc_modules.h>
53 #include <vlc_plugin.h>
55 #include <vlc_charset.h> /* us_strtod */
57 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
60 class ConfClickHandler : public QObject
63 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
64 e = _e; p_intf = _p_intf;
66 virtual ~ConfClickHandler() {}
67 bool eventFilter( QObject *obj, QEvent *evt )
69 if( evt->type() == QEvent::MouseButtonPress )
78 intf_thread_t *p_intf;
82 const QString ModuleFromWidgetName( QObject *obj )
84 return obj->objectName().replace( "Enable","" );
87 QString OptionFromWidgetName( QObject *obj )
90 QString option = obj->objectName().replace( "Slider", "" )
91 .replace( "Combo" , "" )
92 .replace( "Dial" , "" )
93 .replace( "Check" , "" )
94 .replace( "Spin" , "" )
95 .replace( "Text" , "" );
96 for( char a = 'A'; a <= 'Z'; a++ )
98 option = option.replace( QString( a ),
99 QString( '-' ) + QString( a + 'a' - 'A' ) );
104 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
105 QObject( _parent ), p_intf( _p_intf )
107 ui.setupUi( _parent );
109 #define SETUP_VFILTER( widget ) \
111 vlc_object_t *p_obj = ( vlc_object_t * ) \
112 vlc_object_find_name( p_intf->p_libvlc, \
114 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
115 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
118 vlc_object_release( p_obj ); \
119 if( checkbox ) checkbox->setChecked( true ); \
120 else if (groupbox) groupbox->setChecked( true ); \
124 if( checkbox ) checkbox->setChecked( false ); \
125 else if (groupbox) groupbox->setChecked( false ); \
128 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
131 #define SETUP_VFILTER_OPTION( widget, signal ) \
132 initComboBoxItems( ui.widget ); \
133 setWidgetValue( ui.widget ); \
134 CONNECT( ui.widget, signal, this, updateFilterOptions() );
136 SETUP_VFILTER( adjust )
137 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
138 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
139 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
140 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
141 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
142 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
144 SETUP_VFILTER( extract )
145 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
147 SETUP_VFILTER( posterize )
149 SETUP_VFILTER( colorthres )
150 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
151 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
152 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
154 SETUP_VFILTER( sepia )
155 SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )
157 SETUP_VFILTER( invert )
159 SETUP_VFILTER( gradient )
160 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
161 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
162 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
164 SETUP_VFILTER( motionblur )
165 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
167 SETUP_VFILTER( motiondetect )
169 SETUP_VFILTER( psychedelic )
171 SETUP_VFILTER( sharpen )
172 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
174 SETUP_VFILTER( ripple )
176 SETUP_VFILTER( wave )
178 SETUP_VFILTER( transform )
179 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
181 SETUP_VFILTER( rotate )
182 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
183 ui.rotateAngleDial->setWrapping( true );
184 ui.rotateAngleDial->setNotchesVisible( true );
186 SETUP_VFILTER( puzzle )
187 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
188 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
189 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
191 SETUP_VFILTER( magnify )
193 SETUP_VFILTER( clone )
194 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
196 SETUP_VFILTER( wall )
197 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
198 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
201 SETUP_VFILTER( erase )
202 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
203 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
204 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
205 BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
207 SETUP_VFILTER( marq )
208 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
209 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
211 SETUP_VFILTER( logo )
212 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
213 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
214 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
215 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
216 BUTTONACT( ui.logoBrowseBtn, browseLogo() );
218 SETUP_VFILTER( gradfun )
219 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
221 SETUP_VFILTER( grain )
222 SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
224 SETUP_VFILTER( mirror )
226 SETUP_VFILTER( gaussianblur )
227 SETUP_VFILTER_OPTION( gaussianbluSigmaSlider, valueChanged( int ) )
229 SETUP_VFILTER( antiflicker )
230 SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )
233 if( module_exists( "atmo" ) )
235 SETUP_VFILTER( atmo )
236 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
237 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
238 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
239 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
240 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
241 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
242 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
243 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
247 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
250 SETUP_VFILTER( anaglyph )
253 #undef SETUP_VFILTER_OPTION
255 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
256 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
257 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
258 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
259 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
260 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
261 CONNECT( ui.topBotCropSync, toggled( bool ),
262 ui.cropBotPx, setDisabled( bool ) );
263 CONNECT( ui.leftRightCropSync, toggled( bool ),
264 ui.cropRightPx, setDisabled( bool ) );
267 void ExtVideo::cropChange()
269 if( ui.topBotCropSync->isChecked() )
270 ui.cropBotPx->setValue( ui.cropTopPx->value() );
271 if( ui.leftRightCropSync->isChecked() )
272 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
274 vout_thread_t *p_vout = THEMIM->getVout();
277 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
278 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
279 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
280 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
281 vlc_object_release( p_vout );
285 void ExtVideo::clean()
287 ui.cropTopPx->setValue( 0 );
288 ui.cropBotPx->setValue( 0 );
289 ui.cropLeftPx->setValue( 0 );
290 ui.cropRightPx->setValue( 0 );
293 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
295 char *psz_parser, *psz_string;
296 const char *psz_filter_type;
298 module_t *p_obj = module_find( psz_name );
301 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
305 if( module_provides( p_obj, "video splitter" ) )
307 psz_filter_type = "video-splitter";
309 else if( module_provides( p_obj, "video filter2" ) )
311 psz_filter_type = "video-filter";
313 else if( module_provides( p_obj, "sub source" ) )
315 psz_filter_type = "sub-source";
317 else if( module_provides( p_obj, "sub filter" ) )
319 psz_filter_type = "sub-filter";
323 msg_Err( p_intf, "Unknown video filter type." );
327 psz_string = config_GetPsz( p_intf, psz_filter_type );
329 if( !psz_string ) psz_string = strdup( "" );
331 psz_parser = strstr( psz_string, psz_name );
337 psz_parser = psz_string;
338 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
339 psz_string, psz_name ) == -1 )
356 if( *( psz_parser + strlen( psz_name ) ) == ':' )
358 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
359 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
366 /* Remove trailing : : */
367 size_t i_len = strlen( psz_string );
368 if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
370 *( psz_string + i_len - 1 ) = '\0';
379 /* Vout is not kept, so put that in the config */
380 config_PutPsz( p_intf, psz_filter_type, psz_string );
382 /* Try to set on the fly */
383 if( !strcmp( psz_filter_type, "video-splitter" ) )
385 playlist_t *p_playlist = pl_Get( p_intf );
386 var_SetString( p_playlist, psz_filter_type, psz_string );
390 vout_thread_t *p_vout = THEMIM->getVout();
393 var_SetString( p_vout, psz_filter_type, psz_string );
394 vlc_object_release( p_vout );
401 void ExtVideo::updateFilters()
403 QString module = ModuleFromWidgetName( sender() );
405 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
406 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
408 ChangeVFiltersString( p_intf, qtu( module ),
409 checkbox ? checkbox->isChecked()
410 : groupbox->isChecked() );
413 #define UPDATE_AND_APPLY_TEXT( widget, file ) \
414 CONNECT( ui.widget, textChanged( const QString& ), \
415 this, updateFilterOptions() ); \
416 ui.widget->setText( toNativeSeparators( file ) ); \
417 ui.widget->disconnect( SIGNAL( textChanged( const QString& ) ) );
419 void ExtVideo::browseLogo()
421 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
422 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
424 UPDATE_AND_APPLY_TEXT( logoFileText, file );
427 void ExtVideo::browseEraseFile()
429 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
430 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
432 UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
435 #undef UPDATE_AND_APPLY_TEXT
437 void ExtVideo::initComboBoxItems( QObject *widget )
439 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
440 if( !combobox ) return;
442 QString option = OptionFromWidgetName( widget );
443 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
447 msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
451 if( p_item->i_type == CONFIG_ITEM_INTEGER
452 || p_item->i_type == CONFIG_ITEM_BOOL )
456 ssize_t count = config_GetIntChoices( VLC_OBJECT( p_intf ),
457 qtu( option ), &values, &texts );
458 for( ssize_t i = 0; i < count; i++ )
460 combobox->addItem( qtr( texts[i] ), qlonglong(values[i]) );
466 else if( p_item->i_type == CONFIG_ITEM_STRING )
470 ssize_t count = config_GetPszChoices( VLC_OBJECT( p_intf ),
471 qtu( option ), &values, &texts );
472 for( ssize_t i = 0; i < count; i++ )
474 combobox->addItem( qtr( texts[i] ), qfu(values[i]) );
483 void ExtVideo::setWidgetValue( QObject *widget )
485 QString module = ModuleFromWidgetName( widget->parent() );
486 //std::cout << "Module name: " << module.toStdString() << std::endl;
487 QString option = OptionFromWidgetName( widget );
488 //std::cout << "Option name: " << option.toStdString() << std::endl;
490 vlc_object_t *p_obj = ( vlc_object_t * )
491 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
499 "Module instance %s not found, looking in config values.",
502 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
505 case VLC_VAR_INTEGER:
507 val.i_int = config_GetInt( p_intf, qtu( option ) );
510 val.f_float = config_GetFloat( p_intf, qtu( option ) );
513 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
519 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
520 var_Get( p_obj, qtu( option ), &val );
521 vlc_object_release( p_obj );
524 /* Try to cast to all the widgets we're likely to encounter. Only
525 * one of the casts is expected to work. */
526 QSlider *slider = qobject_cast<QSlider*> ( widget );
527 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
528 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
529 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
530 QDial *dial = qobject_cast<QDial*> ( widget );
531 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
532 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
534 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
536 if( slider ) slider->setValue( val.i_int );
537 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
539 else if( spinbox ) spinbox->setValue( val.i_int );
540 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
544 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
545 lineedit->setText( str );
547 else if( combobox ) combobox->setCurrentIndex(
548 combobox->findData( qlonglong(val.i_int) ) );
549 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
551 else if( i_type == VLC_VAR_FLOAT )
553 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
554 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
555 else if( dial ) dial->setValue( (540 - lroundf(val.f_float)) % 360 );
556 else msg_Warn( p_intf, "Could not find the correct Float widget" );
558 else if( i_type == VLC_VAR_STRING )
560 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
561 else if( combobox ) combobox->setCurrentIndex(
562 combobox->findData( qfu( val.psz_string ) ) );
563 else msg_Warn( p_intf, "Could not find the correct String widget" );
564 free( val.psz_string );
569 "Module %s's %s variable is of an unsupported type ( %d )",
575 void ExtVideo::updateFilterOptions()
577 QString module = ModuleFromWidgetName( sender()->parent() );
578 //std::cout << "Module name: " << module.toStdString() << std::endl;
579 QString option = OptionFromWidgetName( sender() );
580 //std::cout << "Option name: " << option.toStdString() << std::endl;
582 vlc_object_t *p_obj = ( vlc_object_t * )
583 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
588 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
589 i_type = config_GetType( p_intf, qtu( option ) );
590 b_is_command = false;
594 i_type = var_Type( p_obj, qtu( option ) );
596 i_type = config_GetType( p_intf, qtu( option ) );
597 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
600 /* Try to cast to all the widgets we're likely to encounter. Only
601 * one of the casts is expected to work. */
602 QSlider *slider = qobject_cast<QSlider*> ( sender() );
603 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
604 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
605 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
606 QDial *dial = qobject_cast<QDial*> ( sender() );
607 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
608 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
610 i_type &= VLC_VAR_CLASS;
611 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
614 if( slider ) i_int = slider->value();
615 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
616 else if( spinbox ) i_int = spinbox->value();
617 else if( dial ) i_int = ( 540-dial->value() )%360;
618 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
619 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
620 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
621 config_PutInt( p_intf, qtu( option ), i_int );
624 if( i_type == VLC_VAR_INTEGER )
625 var_SetInteger( p_obj, qtu( option ), i_int );
627 var_SetBool( p_obj, qtu( option ), i_int );
630 else if( i_type == VLC_VAR_FLOAT )
633 if( slider ) f_float = ( double )slider->value()
634 / ( double )slider->tickInterval(); /* hack alert! */
635 else if( doublespinbox ) f_float = doublespinbox->value();
636 else if( dial ) f_float = (540 - dial->value()) % 360;
637 else if( lineedit ) f_float = lineedit->text().toDouble();
638 else msg_Warn( p_intf, "Could not find the correct Float widget" );
639 config_PutFloat( p_intf, qtu( option ), f_float );
641 var_SetFloat( p_obj, qtu( option ), f_float );
643 else if( i_type == VLC_VAR_STRING )
647 val = lineedit->text();
649 val = combobox->itemData( combobox->currentIndex() ).toString();
651 msg_Warn( p_intf, "Could not find the correct String widget" );
652 config_PutPsz( p_intf, qtu( option ), qtu( val ) );
654 var_SetString( p_obj, qtu( option ), qtu( val ) );
658 "Module %s's %s variable is of an unsupported type ( %d )",
665 msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
668 ChangeVFiltersString( p_intf, qtu( module ), false );
669 ChangeVFiltersString( p_intf, qtu( module ), true );
672 if( p_obj ) vlc_object_release( p_obj );
676 void ExtVideo::gotoConf( QObject* src )
678 #define SHOWCONF( module ) \
679 if( src->objectName().contains( module ) ) \
681 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
685 SHOWCONF( "magnify" );
687 SHOWCONF( "ripple" );
688 SHOWCONF( "invert" );
689 SHOWCONF( "puzzle" );
691 SHOWCONF( "gradient" );
692 SHOWCONF( "colorthres" );
693 SHOWCONF( "anaglyph" )
697 /**********************************************************************
699 **********************************************************************/
701 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
702 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
704 QVBoxLayout *layout = new QVBoxLayout( this );
705 help = new QLabel( qtr("No v4l2 instance found.\n"
706 "Please check that the device has been opened with VLC and is playing.\n\n"
707 "Controls will automatically appear here.")
709 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
710 layout->addWidget( help );
714 void ExtV4l2::showEvent( QShowEvent *event )
716 QWidget::showEvent( event );
720 void ExtV4l2::Refresh( void )
722 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
726 layout()->removeWidget( box );
732 vlc_value_t val, text;
733 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
737 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
739 vlc_object_release( p_obj );
743 box = new QGroupBox( this );
744 layout()->addWidget( box );
745 QVBoxLayout *layout = new QVBoxLayout( box );
746 box->setLayout( layout );
748 for( int i = 0; i < val.p_list->i_count; i++ )
751 const char *psz_var = text.p_list->p_values[i].psz_string;
753 if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
756 QString name = qtr( vartext.psz_string );
757 free( vartext.psz_string );
758 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
759 val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
761 int i_type = var_Type( p_obj, psz_var );
762 switch( i_type & VLC_VAR_TYPE )
764 case VLC_VAR_INTEGER:
766 QLabel *label = new QLabel( name, box );
767 QHBoxLayout *hlayout = new QHBoxLayout();
768 hlayout->addWidget( label );
769 int i_val = var_GetInteger( p_obj, psz_var );
770 if( i_type & VLC_VAR_HASCHOICE )
772 QComboBox *combobox = new QComboBox( box );
773 combobox->setObjectName( qfu( psz_var ) );
775 vlc_value_t val2, text2;
776 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
778 for( int j = 0; j < val2.p_list->i_count; j++ )
781 text2.p_list->p_values[j].psz_string,
782 qlonglong( val2.p_list->p_values[j].i_int) );
783 if( i_val == val2.p_list->p_values[j].i_int )
784 combobox->setCurrentIndex( j );
786 var_FreeList( &val2, &text2 );
788 CONNECT( combobox, currentIndexChanged( int ), this,
789 ValueChange( int ) );
790 hlayout->addWidget( combobox );
793 if( (i_type & VLC_VAR_HASMIN) && (i_type & VLC_VAR_HASMAX) )
795 QSlider *slider = new QSlider( box );
796 slider->setObjectName( qfu( psz_var ) );
797 slider->setOrientation( Qt::Horizontal );
799 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
801 if( val2.i_int < INT_MIN )
802 val2.i_int = INT_MIN; /* FIXME */
803 slider->setMinimum( val2.i_int );
804 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
806 if( val2.i_int > INT_MAX )
807 val2.i_int = INT_MAX; /* FIXME */
808 slider->setMaximum( val2.i_int );
809 if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
811 slider->setSingleStep( val2.i_int );
812 slider->setValue( i_val );
813 CONNECT( slider, valueChanged( int ), this,
814 ValueChange( int ) );
815 hlayout->addWidget( slider );
819 QSpinBox *spinBox = new QSpinBox( box );
820 spinBox->setObjectName( qfu( psz_var ) );
821 spinBox->setMinimum( INT_MIN );
822 spinBox->setMaximum( INT_MAX );
823 spinBox->setValue( i_val );
824 CONNECT( spinBox, valueChanged( int ), this,
825 ValueChange( int ) );
826 hlayout->addWidget( spinBox );
828 layout->addLayout( hlayout );
833 QCheckBox *button = new QCheckBox( name, box );
834 button->setObjectName( qfu( psz_var ) );
835 button->setChecked( var_GetBool( p_obj, psz_var ) );
837 CONNECT( button, clicked( bool ), this,
838 ValueChange( bool ) );
839 layout->addWidget( button );
844 if( i_type & VLC_VAR_ISCOMMAND )
846 QPushButton *button = new QPushButton( name, box );
847 button->setObjectName( qfu( psz_var ) );
849 CONNECT( button, clicked( bool ), this,
850 ValueChange( bool ) );
851 layout->addWidget( button );
855 QLabel *label = new QLabel( name, box );
856 layout->addWidget( label );
861 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
865 var_FreeList( &val, &text );
866 vlc_object_release( p_obj );
870 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
873 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
877 void ExtV4l2::ValueChange( bool value )
879 ValueChange( (int)value );
882 void ExtV4l2::ValueChange( int value )
884 QObject *s = sender();
885 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
888 QString var = s->objectName();
889 int i_type = var_Type( p_obj, qtu( var ) );
890 switch( i_type & VLC_VAR_TYPE )
892 case VLC_VAR_INTEGER:
893 if( i_type & VLC_VAR_HASCHOICE )
895 QComboBox *combobox = qobject_cast<QComboBox*>( s );
896 value = combobox->itemData( value ).toInt();
898 var_SetInteger( p_obj, qtu( var ), value );
901 var_SetBool( p_obj, qtu( var ), value );
904 var_TriggerCallback( p_obj, qtu( var ) );
907 vlc_object_release( p_obj );
911 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
916 /**********************************************************************
918 **********************************************************************/
920 FilterSliderData::FilterSliderData( QObject *parent,
921 intf_thread_t *_p_intf,
923 QLabel *_label, QLabel *_nameLabel,
924 const slider_data_t *_p_data ):
925 QObject( parent ), slider( _slider ), p_intf( _p_intf ),
926 valueLabel( _label ), nameLabel( _nameLabel ), p_data( _p_data )
928 slider->setMinimum( p_data->f_min / p_data->f_resolution );
929 slider->setMaximum( p_data->f_max / p_data->f_resolution );
930 nameLabel->setText( p_data->descs );
931 CONNECT( slider, valueChanged( int ), this, updateText( int ) );
932 setValue( initialValue() );
933 /* In case current == min|max text would not be first updated */
934 if ( slider->value() == slider->maximum() ||
935 slider->value() == slider->minimum() )
936 updateText( slider->value() );
937 CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
940 void FilterSliderData::setValue( float f )
942 slider->setValue( f / p_data->f_resolution );
945 void FilterSliderData::updateText( int i )
947 float f = ((float) i) * p_data->f_resolution * p_data->f_visual_multiplier;
948 valueLabel->setText( QString( p_data->units )
950 .arg( QString::number( f, 'f', 1 ) ) );
953 float FilterSliderData::initialValue()
955 vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
956 float f = p_data->f_value;
959 if ( var_Type( p_aout, qtu(p_data->name) ) == 0 )
961 vlc_object_release( p_aout );
962 /* Not found, will try in config */
966 f = var_GetFloat( p_aout, qtu(p_data->name) );
967 vlc_object_release( p_aout );
972 if ( ! config_FindConfig( VLC_OBJECT(p_intf), qtu(p_data->name) ) )
975 f = config_GetFloat( p_intf, qtu(p_data->name) );
979 void FilterSliderData::onValueChanged( int i )
981 float f = ((float) i) * p_data->f_resolution;
982 vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
985 var_SetFloat( p_aout, qtu(p_data->name), f );
986 vlc_object_release( p_aout );
991 void FilterSliderData::writeToConfig()
993 float f = ((float) slider->value()) * p_data->f_resolution;
994 config_PutFloat( p_intf, qtu(p_data->name), f );
997 AudioFilterControlWidget::AudioFilterControlWidget
998 ( intf_thread_t *_p_intf, QWidget *parent, const char *_name ) :
999 QWidget( parent ), p_intf( _p_intf ), name( _name ), i_smallfont(0)
1002 void AudioFilterControlWidget::build()
1004 QFont smallFont = QApplication::font();
1005 smallFont.setPointSize( smallFont.pointSize() + i_smallfont );
1007 QVBoxLayout *layout = new QVBoxLayout( this );
1008 slidersBox = new QGroupBox( qtr( "Enable" ) );
1009 slidersBox->setCheckable( true );
1010 layout->addWidget( slidersBox );
1012 QGridLayout *ctrlLayout = new QGridLayout( slidersBox );
1015 foreach( const FilterSliderData::slider_data_t &data, controls )
1017 QSlider *slider = new QSlider( Qt::Vertical );
1018 QLabel *valueLabel = new QLabel();
1019 valueLabel->setFont( smallFont );
1020 valueLabel->setAlignment( Qt::AlignHCenter );
1021 QLabel *nameLabel = new QLabel();
1022 nameLabel->setFont( smallFont );
1023 nameLabel->setAlignment( Qt::AlignHCenter );
1024 FilterSliderData *filter =
1025 new FilterSliderData( this, p_intf,
1026 slider, valueLabel, nameLabel, & data );
1027 ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
1028 ctrlLayout->addWidget( valueLabel, 1, i, Qt::AlignHCenter );
1029 ctrlLayout->addWidget( nameLabel, 2, i, Qt::AlignHCenter );
1033 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1037 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1038 vlc_object_release( p_aout );
1041 psz_af = config_GetPsz( p_intf, "audio-filter" );
1043 if( psz_af && strstr( psz_af, qtu(name) ) != NULL )
1044 slidersBox->setChecked( true );
1046 slidersBox->setChecked( false );
1047 CONNECT( slidersBox, toggled(bool), this, enable() );
1052 AudioFilterControlWidget::~AudioFilterControlWidget()
1057 void AudioFilterControlWidget::enable()
1059 playlist_EnableAudioFilter( THEPL, qtu(name), slidersBox->isChecked() );
1062 /**********************************************************************
1064 **********************************************************************/
1066 static const QString vlc_band_frequencies[] =
1068 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
1069 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
1072 static const QString iso_band_frequencies[] =
1074 " 31 Hz ", " 63 Hz ", " 125 Hz ", " 250 Hz ", " 500 Hz ",
1075 " 1 kHz ", " 2 kHz ", " 4 kHz ", " 8 kHz ", " 16 kHz "
1078 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
1079 QWidget( _parent ) , p_intf( _p_intf )
1081 QFont smallFont = QApplication::font();
1082 smallFont.setPointSize( smallFont.pointSize() - 3 );
1085 ui.preampLabel->setFont( smallFont );
1087 /* Setup of presetsComboBox */
1088 presetsComboBox = ui.presetsCombo;
1089 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
1091 b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
1093 /* Add the sliders for the Bands */
1094 QGridLayout *grid = new QGridLayout( ui.slidersPlaceholder );
1095 grid->setMargin( 0 );
1096 for( int i = 0 ; i < BANDS ; i++ )
1098 bands[i] = new QSlider( Qt::Vertical );
1099 bands[i]->setMaximum( 400 );
1100 bands[i]->setValue( 200 );
1101 bands[i]->setMinimumWidth(36);
1102 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
1104 QString val = QString("%1").arg( 0.0, 5, 'f', 1 );
1105 band_texts[i] = new QLabel( (b_vlcBands ? vlc_band_frequencies[i]
1106 : iso_band_frequencies[i]) + "\n" + val + "dB" );
1107 band_texts[i]->setFont( smallFont );
1109 grid->addWidget( bands[i], 0, i );
1110 grid->addWidget( band_texts[i], 1, i );
1113 /* Add the listed presets */
1114 for( int i = 0 ; i < NB_PRESETS ; i ++ )
1116 presetsComboBox->addItem( qtr( preset_list_text[i] ),
1117 QVariant( preset_list[i] ) );
1121 BUTTONACT( ui.enableCheck, enable() );
1122 BUTTONACT( ui.eq2PassCheck, set2Pass() );
1123 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
1125 /* Do the update from the value of the core */
1129 /* Write down initial values */
1130 void Equalizer::updateUIFromCore()
1132 char *psz_af, *psz_pres, *psz_bands;
1136 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1139 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1140 vlc_object_release( p_aout );
1144 psz_af = config_GetPsz( p_intf, "audio-filter" );
1147 psz_pres = var_InheritString( p_aout, "equalizer-preset" );
1148 if( var_InheritBool( p_aout, "equalizer-2pass" ) )
1149 ui.eq2PassCheck->setChecked( true );
1150 f_preamp = var_InheritFloat( p_aout, "equalizer-preamp" );
1151 psz_bands = var_InheritString( p_aout, "equalizer-bands" );
1152 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
1154 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
1155 ui.enableCheck->setChecked( true );
1156 enable( ui.enableCheck->isChecked() );
1158 presetsComboBox->setCurrentIndex( i_preset );
1160 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1162 if( psz_bands && strlen( psz_bands ) > 1 )
1164 char *psz_bands_orig = psz_bands;
1165 for( int i = 0; i < BANDS; i++ )
1167 const float f = us_strtod(psz_bands, &psz_bands );
1168 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1169 if( psz_bands == NULL || *psz_bands == '\0' ) break;
1171 if( *psz_bands == '\0' ) break;
1173 free( psz_bands_orig );
1175 else free( psz_bands );
1181 void Equalizer::changeFreqLabels( bool b_useVlcBands )
1183 b_vlcBands = b_useVlcBands;
1185 const QString *band_frequencies = b_vlcBands
1186 ? vlc_band_frequencies
1187 : iso_band_frequencies;
1189 for( int i = 0; i < BANDS; i++ )
1191 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1192 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1193 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1197 /* Function called when enableButton is toggled */
1198 void Equalizer::enable()
1200 bool en = ui.enableCheck->isChecked();
1201 playlist_EnableAudioFilter( THEPL, "equalizer", en );
1202 //playlist_EnableAudioFilter( THEPL, "upmixer", en );
1203 //playlist_EnableAudioFilter( THEPL, "vsurround", en );
1206 if( presetsComboBox->currentIndex() < 0 )
1207 presetsComboBox->setCurrentIndex( 0 );
1211 void Equalizer::enable( bool en )
1213 ui.eq2PassCheck->setEnabled( en );
1214 presetsComboBox->setEnabled( en );
1215 ui.presetLabel->setEnabled( en );
1216 ui.preampLabel->setEnabled( en );
1217 ui.preampSlider->setEnabled( en );
1218 for( int i = 0 ; i< BANDS; i++ )
1220 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
1224 /* Function called when the set2Pass button is activated */
1225 void Equalizer::set2Pass()
1227 vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
1228 bool b_2p = ui.eq2PassCheck->isChecked();
1232 var_SetBool( p_aout, "equalizer-2pass", b_2p );
1233 vlc_object_release( p_aout );
1235 config_PutInt( p_intf, "equalizer-2pass", b_2p );
1238 /* Function called when the preamp slider is moved */
1239 void Equalizer::setPreamp()
1241 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
1242 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1244 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
1248 //delCallbacks( p_aout );
1249 var_SetFloat( p_aout, "equalizer-preamp", f );
1250 //addCallbacks( p_aout );
1251 vlc_object_release( p_aout );
1253 config_PutFloat( p_intf, "equalizer-preamp", f );
1256 void Equalizer::setCoreBands()
1258 /**\todo smoothing */
1260 const QString *band_frequencies = b_vlcBands
1261 ? vlc_band_frequencies
1262 : iso_band_frequencies;
1265 for( int i = 0; i < BANDS; i++ )
1267 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1268 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1270 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1271 values += " " + val;
1274 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1277 //delCallbacks( p_aout );
1278 var_SetString( p_aout, "equalizer-bands", qtu( values ) );
1279 //addCallbacks( p_aout );
1280 vlc_object_release( p_aout );
1284 char * Equalizer::createValuesFromPreset( int i_preset )
1288 /* Create the QString in Qt */
1289 for( int i = 0 ; i< BANDS ;i++ )
1290 values += QString( " %1" ).arg( eqz_preset_10b[i_preset].f_amp[i], 5, 'f', 1 );
1292 /* Convert it to char * */
1293 return strdup( values.toAscii().constData() );
1296 void Equalizer::setCorePreset( int i_preset )
1301 /* Update pre-amplification in the UI */
1302 float f_preamp = eqz_preset_10b[i_preset].f_preamp;
1303 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1304 ui.preampLabel->setText( qtr( "Preamp\n" )
1305 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1307 char *psz_values = createValuesFromPreset( i_preset );
1308 if( !psz_values ) return ;
1310 const QString *band_frequencies = b_vlcBands
1311 ? vlc_band_frequencies
1312 : iso_band_frequencies;
1314 char *p = psz_values;
1315 for( int i = 0; i < BANDS && *p; i++ )
1317 const float f = us_strtod( p, &p );
1319 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1320 band_texts[i]->setText( band_frequencies[i] + "\n"
1321 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1323 p++; /* skip separator */
1326 /* Apply presets to audio output */
1327 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1330 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1332 var_SetString( p_aout, "equalizer-bands", psz_values );
1333 var_SetFloat( p_aout, "equalizer-preamp",
1334 eqz_preset_10b[i_preset].f_preamp );
1335 vlc_object_release( p_aout );
1337 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1338 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1339 config_PutFloat( p_intf, "equalizer-preamp",
1340 eqz_preset_10b[i_preset].f_preamp );
1344 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1345 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1347 VLC_UNUSED( p_this ); VLC_UNUSED( psz_cmd ); VLC_UNUSED( oldval );
1349 char *psz_preset = newval.psz_string;
1350 Equalizer *eq = ( Equalizer * )p_data;
1351 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1352 eq->presetsComboBox->setCurrentIndex( i_preset );
1356 void Equalizer::delCallbacks( vlc_object_t *p_aout )
1358 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1359 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1360 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1363 void Equalizer::addCallbacks( vlc_object_t *p_aout )
1365 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1366 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1367 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1370 /**********************************************************************
1372 **********************************************************************/
1374 /**********************************************************************
1375 * Dynamic range compressor
1376 **********************************************************************/
1378 Compressor::Compressor( intf_thread_t *p_intf, QWidget *parent )
1379 : AudioFilterControlWidget( p_intf, parent, "compressor" )
1382 const FilterSliderData::slider_data_t a[7] =
1384 { "compressor-rms-peak", qtr("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f, 1.0 },
1385 { "compressor-attack", qtr("Attack"), qtr(" ms"), 1.5f, 400.0f, 25.00f, 0.100f, 1.0 },
1386 { "compressor-release", qtr("Release"), qtr(" ms"), 2.0f, 800.0f, 100.00f, 0.100f, 1.0 },
1387 { "compressor-threshold", qtr("Threshold"), qtr(" dB"), -30.0f, 0.0f, -11.00f, 0.010f, 1.0 },
1388 { "compressor-ratio", qtr("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f, 1.0 },
1389 { "compressor-knee", qtr("Knee\nradius"), qtr(" dB"), 1.0f, 10.0f, 2.50f, 0.010f, 1.0 },
1390 { "compressor-makeup-gain", qtr("Makeup\ngain"), qtr(" dB"), 0.0f, 24.0f, 7.00f, 0.010f, 1.0 },
1392 for( int i=0; i<7 ;i++ ) controls.append( a[i] );
1396 /**********************************************************************
1398 **********************************************************************/
1400 Spatializer::Spatializer( intf_thread_t *p_intf, QWidget *parent )
1401 : AudioFilterControlWidget( p_intf, parent, "spatializer" )
1404 const FilterSliderData::slider_data_t a[5] =
1406 { "spatializer-roomsize", qtr("Size"), "", 0.0f, 1.1f, 0.85f, 0.1f, 10.0 },
1407 { "spatializer-width", qtr("Width"), "", 0.0f, 1.0f, 1.0f, 0.1f, 10.0 },
1408 { "spatializer-wet", qtr("Wet"), "", 0.0f, 1.0f, 0.4f, 0.1f, 10.0 },
1409 { "spatializer-dry", qtr("Dry"), "", 0.0f, 1.0f, 0.5f, 0.1f, 10.0 },
1410 { "spatializer-damp", qtr("Damp"), "", 0.0f, 1.0f, 0.5f, 0.1f, 10.0 },
1412 for( int i=0; i<5 ;i++ ) controls.append( a[i] );
1416 #include <QToolButton>
1417 #include <QGridLayout>
1419 #define SUBSDELAY_CFG_MODE "subsdelay-mode"
1420 #define SUBSDELAY_CFG_FACTOR "subsdelay-factor"
1421 #define SUBSDELAY_MODE_ABSOLUTE 0
1422 #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY 1
1423 #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
1425 SyncWidget::SyncWidget( QWidget *_parent ) : QWidget( _parent )
1427 QHBoxLayout *layout = new QHBoxLayout;
1428 spinBox.setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1429 spinBox.setDecimals( 3 );
1430 spinBox.setMinimum( -600.0 );
1431 spinBox.setMaximum( 600.0 );
1432 spinBox.setSingleStep( 0.1 );
1433 spinBox.setSuffix( " s" );
1434 spinBox.setButtonSymbols( QDoubleSpinBox::PlusMinus );
1435 CONNECT( &spinBox, valueChanged( double ), this, valueChangedHandler( double ) );
1436 layout->addWidget( &spinBox );
1437 layout->addWidget( &spinLabel );
1438 layout->setContentsMargins( 0, 0, 0, 0 );
1439 setLayout( layout );
1442 void SyncWidget::valueChangedHandler( double d )
1445 spinLabel.setText( qtr("(Hastened)") );
1447 spinLabel.setText( qtr("(Delayed)") );
1449 spinLabel.setText( "" );
1450 emit valueChanged( d );
1453 void SyncWidget::setValue( double d )
1455 spinBox.setValue( d );
1458 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1459 QWidget( _parent ) , p_intf( _p_intf )
1461 QGroupBox *AVBox, *subsBox;
1462 QToolButton *updateButton;
1464 b_userAction = true;
1466 QGridLayout *mainLayout = new QGridLayout( this );
1469 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1470 QGridLayout *AVLayout = new QGridLayout( AVBox );
1472 QLabel *AVLabel = new QLabel;
1473 AVLabel->setText( qtr( "Audio track synchronization:" ) );
1474 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1476 AVSpin = new SyncWidget( this );
1477 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1478 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1481 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1482 QGridLayout *subsLayout = new QGridLayout( subsBox );
1484 QLabel *subsLabel = new QLabel;
1485 subsLabel->setText( qtr( "Subtitle track syncronization:" ) );
1486 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1488 subsSpin = new SyncWidget( this );
1489 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1491 QLabel *subSpeedLabel = new QLabel;
1492 subSpeedLabel->setText( qtr( "Subtitles speed:" ) );
1493 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1495 subSpeedSpin = new QDoubleSpinBox;
1496 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1497 subSpeedSpin->setDecimals( 3 );
1498 subSpeedSpin->setMinimum( 1 );
1499 subSpeedSpin->setMaximum( 100 );
1500 subSpeedSpin->setSingleStep( 0.2 );
1501 subSpeedSpin->setSuffix( " fps" );
1502 subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1503 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1505 QLabel *subDurationLabel = new QLabel;
1506 subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
1507 subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
1509 subDurationSpin = new QDoubleSpinBox;
1510 subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1511 subDurationSpin->setDecimals( 3 );
1512 subDurationSpin->setMinimum( 0 );
1513 subDurationSpin->setMaximum( 20 );
1514 subDurationSpin->setSingleStep( 0.2 );
1515 subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1516 subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
1518 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1520 updateButton = new QToolButton;
1521 updateButton->setAutoRaise( true );
1522 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1524 /* Various Connects */
1525 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1526 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1527 CONNECT( subSpeedSpin, valueChanged ( double ),
1528 this, adjustSubsSpeed( double ) );
1529 CONNECT( subDurationSpin, valueChanged ( double ),
1530 this, adjustSubsDuration( double ) );
1532 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1533 BUTTON_SET_ACT_I( updateButton, "", update,
1534 qtr( "Force update of this dialog's values" ), update() );
1542 SyncControls::~SyncControls()
1547 void SyncControls::clean()
1549 b_userAction = false;
1550 AVSpin->setValue( 0.0 );
1551 subsSpin->setValue( 0.0 );
1552 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" ) );
1569 subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
1571 b_userAction = true;
1574 void SyncControls::advanceAudio( double f_advance )
1576 if( THEMIM->getInput() && b_userAction )
1578 int64_t i_delay = f_advance * 1000000;
1579 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1583 void SyncControls::advanceSubs( double f_advance )
1585 if( THEMIM->getInput() && b_userAction )
1587 int64_t i_delay = f_advance * 1000000;
1588 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1592 void SyncControls::adjustSubsSpeed( double f_fps )
1594 if( THEMIM->getInput() && b_userAction )
1596 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1600 void SyncControls::adjustSubsDuration( double f_factor )
1602 if( THEMIM->getInput() && b_userAction )
1604 subsdelaySetFactor( f_factor );
1605 ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
1609 void SyncControls::initSubsDuration()
1611 int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
1616 case SUBSDELAY_MODE_ABSOLUTE:
1617 subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
1618 "Set 0 to disable." ) );
1619 subDurationSpin->setSuffix( " s" );
1621 case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
1622 subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
1623 "Set 0 to disable." ) );
1624 subDurationSpin->setSuffix( "" );
1626 case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
1627 subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
1628 "to their content and this value.\n"
1629 "Set 0 to disable." ) );
1630 subDurationSpin->setSuffix( "" );
1635 void SyncControls::subsdelayClean()
1637 /* Remove subsdelay filter */
1638 ChangeVFiltersString( p_intf, "subsdelay", false );
1641 void SyncControls::subsdelaySetFactor( double f_factor )
1643 /* Set the factor in the preferences */
1644 config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
1646 /* Try to find an instance of subsdelay, and set its factor */
1647 vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
1650 var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
1651 vlc_object_release( p_obj );
1656 /**********************************************************************
1657 * Video filters / Adjust
1658 **********************************************************************/
1660 /**********************************************************************
1661 * Extended playbak controls
1662 **********************************************************************/