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 <QFileDialog>
41 #include "components/extended_panels.hpp"
42 #include "dialogs/preferences.hpp"
44 #include "input_manager.hpp"
45 #include "util/qt_dirs.hpp"
47 #include "../../audio_filter/equalizer_presets.h"
48 #include <vlc_aout_intf.h>
49 #include <vlc_intf_strings.h>
52 #include <vlc_modules.h>
54 #include <vlc_charset.h> /* us_strtod */
56 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
59 class ConfClickHandler : public QObject
62 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
63 e = _e; p_intf = _p_intf;
65 virtual ~ConfClickHandler() {}
66 bool eventFilter( QObject *obj, QEvent *evt )
68 if( evt->type() == QEvent::MouseButtonPress )
77 intf_thread_t *p_intf;
81 const QString ModuleFromWidgetName( QObject *obj )
83 return obj->objectName().replace( "Enable","" );
86 QString OptionFromWidgetName( QObject *obj )
89 QString option = obj->objectName().replace( "Slider", "" )
90 .replace( "Combo" , "" )
91 .replace( "Dial" , "" )
92 .replace( "Check" , "" )
93 .replace( "Spin" , "" )
94 .replace( "Text" , "" );
95 for( char a = 'A'; a <= 'Z'; a++ )
97 option = option.replace( QString( a ),
98 QString( '-' ) + QString( a + 'a' - 'A' ) );
103 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
104 QObject( _parent ), p_intf( _p_intf )
106 ui.setupUi( _parent );
108 #define SETUP_VFILTER( widget ) \
110 vlc_object_t *p_obj = ( vlc_object_t * ) \
111 vlc_object_find_name( p_intf->p_libvlc, \
113 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
114 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
117 vlc_object_release( p_obj ); \
118 if( checkbox ) checkbox->setChecked( true ); \
119 else if (groupbox) groupbox->setChecked( true ); \
123 if( checkbox ) checkbox->setChecked( false ); \
124 else if (groupbox) groupbox->setChecked( false ); \
127 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
130 #define SETUP_VFILTER_OPTION( widget, signal ) \
131 initComboBoxItems( ui.widget ); \
132 setWidgetValue( ui.widget ); \
133 CONNECT( ui.widget, signal, this, updateFilterOptions() );
135 SETUP_VFILTER( adjust )
136 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
137 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
138 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
139 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
140 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
141 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
143 SETUP_VFILTER( extract )
144 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
146 SETUP_VFILTER( posterize )
148 SETUP_VFILTER( colorthres )
149 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
150 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
151 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
153 SETUP_VFILTER( sepia )
154 SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )
156 SETUP_VFILTER( invert )
158 SETUP_VFILTER( gradient )
159 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
160 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
161 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
163 SETUP_VFILTER( motionblur )
164 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
166 SETUP_VFILTER( motiondetect )
168 SETUP_VFILTER( psychedelic )
170 SETUP_VFILTER( sharpen )
171 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
173 SETUP_VFILTER( ripple )
175 SETUP_VFILTER( wave )
177 SETUP_VFILTER( transform )
178 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
180 SETUP_VFILTER( rotate )
181 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
182 ui.rotateAngleDial->setWrapping( true );
183 ui.rotateAngleDial->setNotchesVisible( true );
185 SETUP_VFILTER( puzzle )
186 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
187 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
188 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
190 SETUP_VFILTER( magnify )
192 SETUP_VFILTER( clone )
193 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
195 SETUP_VFILTER( wall )
196 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
197 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
200 SETUP_VFILTER( erase )
201 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
202 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
203 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
204 BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
206 SETUP_VFILTER( marq )
207 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
208 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
210 SETUP_VFILTER( logo )
211 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
212 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
213 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
214 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
215 BUTTONACT( ui.logoBrowseBtn, browseLogo() );
217 SETUP_VFILTER( gradfun )
218 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
220 SETUP_VFILTER( grain )
221 SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
223 SETUP_VFILTER( mirror )
225 SETUP_VFILTER( gaussianblur )
226 SETUP_VFILTER_OPTION( gaussianbluSigmaSlider, valueChanged( int ) )
228 SETUP_VFILTER( antiflicker )
229 SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )
232 if( module_exists( "atmo" ) )
234 SETUP_VFILTER( atmo )
235 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
236 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
237 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
238 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
239 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
240 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
241 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
242 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
246 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
250 #undef SETUP_VFILTER_OPTION
252 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
253 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
254 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
255 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
256 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
257 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
258 CONNECT( ui.topBotCropSync, toggled( bool ),
259 ui.cropBotPx, setDisabled( bool ) );
260 CONNECT( ui.leftRightCropSync, toggled( bool ),
261 ui.cropRightPx, setDisabled( bool ) );
264 void ExtVideo::cropChange()
266 if( ui.topBotCropSync->isChecked() )
267 ui.cropBotPx->setValue( ui.cropTopPx->value() );
268 if( ui.leftRightCropSync->isChecked() )
269 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
271 vout_thread_t *p_vout = THEMIM->getVout();
274 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
275 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
276 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
277 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
278 vlc_object_release( p_vout );
282 void ExtVideo::clean()
284 ui.cropTopPx->setValue( 0 );
285 ui.cropBotPx->setValue( 0 );
286 ui.cropLeftPx->setValue( 0 );
287 ui.cropRightPx->setValue( 0 );
290 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
292 char *psz_parser, *psz_string;
293 const char *psz_filter_type;
295 module_t *p_obj = module_find( psz_name );
298 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
302 if( module_provides( p_obj, "video splitter" ) )
304 psz_filter_type = "video-splitter";
306 else if( module_provides( p_obj, "video filter2" ) )
308 psz_filter_type = "video-filter";
310 else if( module_provides( p_obj, "sub source" ) )
312 psz_filter_type = "sub-source";
314 else if( module_provides( p_obj, "sub filter" ) )
316 psz_filter_type = "sub-filter";
320 msg_Err( p_intf, "Unknown video filter type." );
324 psz_string = config_GetPsz( p_intf, psz_filter_type );
326 if( !psz_string ) psz_string = strdup( "" );
328 psz_parser = strstr( psz_string, psz_name );
334 psz_parser = psz_string;
335 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
336 psz_string, psz_name ) == -1 )
353 if( *( psz_parser + strlen( psz_name ) ) == ':' )
355 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
356 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
363 /* Remove trailing : : */
364 if( strlen( psz_string ) > 0 &&
365 *( psz_string + strlen( psz_string ) -1 ) == ':' )
367 *( psz_string + strlen( psz_string ) -1 ) = '\0';
376 /* Vout is not kept, so put that in the config */
377 config_PutPsz( p_intf, psz_filter_type, psz_string );
379 /* Try to set on the fly */
380 if( !strcmp( psz_filter_type, "video-splitter" ) )
382 playlist_t *p_playlist = pl_Get( p_intf );
383 var_SetString( p_playlist, psz_filter_type, psz_string );
387 vout_thread_t *p_vout = THEMIM->getVout();
390 var_SetString( p_vout, psz_filter_type, psz_string );
391 vlc_object_release( p_vout );
398 void ExtVideo::updateFilters()
400 QString module = ModuleFromWidgetName( sender() );
402 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
403 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
405 ChangeVFiltersString( p_intf, qtu( module ),
406 checkbox ? checkbox->isChecked()
407 : groupbox->isChecked() );
410 void ExtVideo::browseLogo()
412 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
413 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
414 ui.logoFileText->setText( toNativeSeparators( file ) );
417 void ExtVideo::browseEraseFile()
419 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
420 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
421 ui.eraseMaskText->setText( toNativeSeparators( file ) );
424 void ExtVideo::initComboBoxItems( QObject *widget )
426 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
427 if( !combobox ) return;
429 QString option = OptionFromWidgetName( widget );
430 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
434 int i_type = p_item->i_type;
435 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
437 if( i_type == CONFIG_ITEM_INTEGER
438 || i_type == CONFIG_ITEM_BOOL )
439 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
440 p_item->pi_list[i_index] );
441 else if( i_type == CONFIG_ITEM_STRING )
442 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
443 p_item->ppsz_list[i_index] );
448 msg_Err( p_intf, "Couldn't find option \"%s\".",
453 void ExtVideo::setWidgetValue( QObject *widget )
455 QString module = ModuleFromWidgetName( widget->parent() );
456 //std::cout << "Module name: " << module.toStdString() << std::endl;
457 QString option = OptionFromWidgetName( widget );
458 //std::cout << "Option name: " << option.toStdString() << std::endl;
460 vlc_object_t *p_obj = ( vlc_object_t * )
461 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
469 "Module instance %s not found, looking in config values.",
472 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
475 case VLC_VAR_INTEGER:
477 val.i_int = config_GetInt( p_intf, qtu( option ) );
480 val.f_float = config_GetFloat( p_intf, qtu( option ) );
483 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
489 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
490 var_Get( p_obj, qtu( option ), &val );
491 vlc_object_release( p_obj );
494 /* Try to cast to all the widgets we're likely to encounter. Only
495 * one of the casts is expected to work. */
496 QSlider *slider = qobject_cast<QSlider*> ( widget );
497 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
498 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
499 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
500 QDial *dial = qobject_cast<QDial*> ( widget );
501 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
502 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
504 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
506 if( slider ) slider->setValue( val.i_int );
507 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
509 else if( spinbox ) spinbox->setValue( val.i_int );
510 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
514 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
515 lineedit->setText( str );
517 else if( combobox ) combobox->setCurrentIndex(
518 combobox->findData( qlonglong(val.i_int) ) );
519 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
521 else if( i_type == VLC_VAR_FLOAT )
523 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
524 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
525 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
527 else if( i_type == VLC_VAR_STRING )
529 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
530 else if( combobox ) combobox->setCurrentIndex(
531 combobox->findData( qfu( val.psz_string ) ) );
532 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
533 free( val.psz_string );
538 "Module %s's %s variable is of an unsupported type ( %d )",
544 void ExtVideo::updateFilterOptions()
546 QString module = ModuleFromWidgetName( sender()->parent() );
547 //std::cout << "Module name: " << module.toStdString() << std::endl;
548 QString option = OptionFromWidgetName( sender() );
549 //std::cout << "Option name: " << option.toStdString() << std::endl;
551 vlc_object_t *p_obj = ( vlc_object_t * )
552 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
557 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
558 i_type = config_GetType( p_intf, qtu( option ) );
559 b_is_command = false;
563 i_type = var_Type( p_obj, qtu( option ) );
565 i_type = config_GetType( p_intf, qtu( option ) );
566 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
569 /* Try to cast to all the widgets we're likely to encounter. Only
570 * one of the casts is expected to work. */
571 QSlider *slider = qobject_cast<QSlider*> ( sender() );
572 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
573 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
574 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
575 QDial *dial = qobject_cast<QDial*> ( sender() );
576 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
577 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
579 i_type &= VLC_VAR_CLASS;
580 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
583 if( slider ) i_int = slider->value();
584 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
585 else if( spinbox ) i_int = spinbox->value();
586 else if( dial ) i_int = ( 540-dial->value() )%360;
587 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
588 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
589 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
590 config_PutInt( p_intf, qtu( option ), i_int );
593 if( i_type == VLC_VAR_INTEGER )
594 var_SetInteger( p_obj, qtu( option ), i_int );
596 var_SetBool( p_obj, qtu( option ), i_int );
599 else if( i_type == VLC_VAR_FLOAT )
602 if( slider ) f_float = ( double )slider->value()
603 / ( double )slider->tickInterval(); /* hack alert! */
604 else if( doublespinbox ) f_float = doublespinbox->value();
605 else if( lineedit ) f_float = lineedit->text().toDouble();
606 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
607 config_PutFloat( p_intf, qtu( option ), f_float );
609 var_SetFloat( p_obj, qtu( option ), f_float );
611 else if( i_type == VLC_VAR_STRING )
615 val = lineedit->text();
617 val = combobox->itemData( combobox->currentIndex() ).toString();
619 msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
620 config_PutPsz( p_intf, qtu( option ), qtu( val ) );
622 var_SetString( p_obj, qtu( option ), qtu( val ) );
626 "Module %s's %s variable is of an unsupported type ( %d )",
633 msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
636 ChangeVFiltersString( p_intf, qtu( module ), false );
637 ChangeVFiltersString( p_intf, qtu( module ), true );
640 if( p_obj ) vlc_object_release( p_obj );
644 void ExtVideo::gotoConf( QObject* src )
646 #define SHOWCONF( module ) \
647 if( src->objectName().contains( module ) ) \
649 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
653 SHOWCONF( "magnify" );
655 SHOWCONF( "ripple" );
656 SHOWCONF( "invert" );
657 SHOWCONF( "puzzle" );
659 SHOWCONF( "gradient" );
660 SHOWCONF( "colorthres" )
664 /**********************************************************************
666 **********************************************************************/
668 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
669 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
671 QVBoxLayout *layout = new QVBoxLayout( this );
672 help = new QLabel( qtr("No v4l2 instance found.\n"
673 "Please check that the device has been opened with VLC and is playing.\n\n"
674 "Controls will automatically appear here.")
676 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
677 layout->addWidget( help );
681 void ExtV4l2::showEvent( QShowEvent *event )
683 QWidget::showEvent( event );
687 void ExtV4l2::Refresh( void )
689 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
693 layout()->removeWidget( box );
699 vlc_value_t val, text, name;
700 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
704 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
706 vlc_object_release( p_obj );
710 box = new QGroupBox( this );
711 layout()->addWidget( box );
712 QVBoxLayout *layout = new QVBoxLayout( box );
713 box->setLayout( layout );
715 for( int i = 0; i < val.p_list->i_count; i++ )
717 const char *psz_var = text.p_list->p_values[i].psz_string;
718 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
719 const char *psz_label = name.psz_string;
720 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
721 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
723 int i_type = var_Type( p_obj, psz_var );
724 switch( i_type & VLC_VAR_TYPE )
726 case VLC_VAR_INTEGER:
728 QLabel *label = new QLabel( qtr( psz_label ), box );
729 QHBoxLayout *hlayout = new QHBoxLayout();
730 hlayout->addWidget( label );
731 int i_val = var_GetInteger( p_obj, psz_var );
732 if( i_type & VLC_VAR_HASCHOICE )
734 QComboBox *combobox = new QComboBox( box );
735 combobox->setObjectName( qtr( psz_var ) );
737 vlc_value_t val2, text2;
738 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
740 for( int j = 0; j < val2.p_list->i_count; j++ )
743 text2.p_list->p_values[j].psz_string,
744 qlonglong( val2.p_list->p_values[j].i_int) );
745 if( i_val == val2.p_list->p_values[j].i_int )
746 combobox->setCurrentIndex( j );
748 var_FreeList( &val2, &text2 );
750 CONNECT( combobox, currentIndexChanged( int ), this,
751 ValueChange( int ) );
752 hlayout->addWidget( combobox );
756 QSlider *slider = new QSlider( box );
757 slider->setObjectName( qtr( psz_var ) );
758 slider->setOrientation( Qt::Horizontal );
760 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
762 slider->setMinimum( val2.i_int );
763 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
765 slider->setMaximum( val2.i_int );
766 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
768 slider->setSingleStep( val2.i_int );
769 slider->setValue( i_val );
771 CONNECT( slider, valueChanged( int ), this,
772 ValueChange( int ) );
773 hlayout->addWidget( slider );
775 layout->addLayout( hlayout );
780 QCheckBox *button = new QCheckBox( qtr( psz_label ), box );
781 button->setObjectName( qtr( psz_var ) );
782 button->setChecked( var_GetBool( p_obj, psz_var ) );
784 CONNECT( button, clicked( bool ), this,
785 ValueChange( bool ) );
786 layout->addWidget( button );
791 if( i_type & VLC_VAR_ISCOMMAND )
793 QPushButton *button = new QPushButton( qtr( psz_label ), box );
794 button->setObjectName( qtr( psz_var ) );
796 CONNECT( button, clicked( bool ), this,
797 ValueChange( bool ) );
798 layout->addWidget( button );
802 QLabel *label = new QLabel( qtr( psz_label ), box );
803 layout->addWidget( label );
808 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
811 free( name.psz_string );
813 var_FreeList( &val, &text );
814 vlc_object_release( p_obj );
818 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
821 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
825 void ExtV4l2::ValueChange( bool value )
827 ValueChange( (int)value );
830 void ExtV4l2::ValueChange( int value )
832 QObject *s = sender();
833 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
836 QString var = s->objectName();
837 int i_type = var_Type( p_obj, qtu( var ) );
838 switch( i_type & VLC_VAR_TYPE )
840 case VLC_VAR_INTEGER:
841 if( i_type & VLC_VAR_HASCHOICE )
843 QComboBox *combobox = qobject_cast<QComboBox*>( s );
844 value = combobox->itemData( value ).toInt();
846 var_SetInteger( p_obj, qtu( var ), value );
849 var_SetBool( p_obj, qtu( var ), value );
852 var_TriggerCallback( p_obj, qtu( var ) );
855 vlc_object_release( p_obj );
859 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
864 /**********************************************************************
866 **********************************************************************/
868 static const QString band_frequencies[] =
870 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
871 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
874 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
875 QWidget( _parent ) , p_intf( _p_intf )
877 QFont smallFont = QApplication::font();
878 smallFont.setPointSize( smallFont.pointSize() - 3 );
881 ui.preampLabel->setFont( smallFont );
883 /* Setup of presetsComboBox */
884 presetsComboBox = ui.presetsCombo;
885 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
887 /* Add the sliders for the Bands */
888 QGridLayout *grid = new QGridLayout( ui.frame );
889 grid->setMargin( 0 );
890 for( int i = 0 ; i < BANDS ; i++ )
892 bands[i] = new QSlider( Qt::Vertical );
893 bands[i]->setMaximum( 400 );
894 bands[i]->setValue( 200 );
895 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
897 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
898 band_texts[i]->setFont( smallFont );
900 grid->addWidget( bands[i], 0, i );
901 grid->addWidget( band_texts[i], 1, i );
904 /* Add the listed presets */
905 for( int i = 0 ; i < NB_PRESETS ; i ++ )
907 presetsComboBox->addItem( qtr( preset_list_text[i] ),
908 QVariant( preset_list[i] ) );
912 BUTTONACT( ui.enableCheck, enable() );
913 BUTTONACT( ui.eq2PassCheck, set2Pass() );
914 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
916 /* Do the update from the value of the core */
920 /* Write down initial values */
921 void Equalizer::updateUIFromCore()
923 char *psz_af, *psz_pres, *psz_bands;
927 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
930 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
931 psz_pres = var_GetString( p_aout, "equalizer-preset" );
932 if( var_GetBool( p_aout, "equalizer-2pass" ) )
933 ui.eq2PassCheck->setChecked( true );
934 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
935 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
936 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
937 vlc_object_release( p_aout );
941 psz_af = config_GetPsz( p_intf, "audio-filter" );
942 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
943 if( config_GetInt( p_intf, "equalizer-2pass" ) )
944 ui.eq2PassCheck->setChecked( true );
945 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
946 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
947 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
949 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
950 ui.enableCheck->setChecked( true );
951 enable( ui.enableCheck->isChecked() );
953 presetsComboBox->setCurrentIndex( i_preset );
955 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
957 if( psz_bands && strlen( psz_bands ) > 1 )
959 char *psz_bands_orig = psz_bands;
960 for( int i = 0; i < BANDS; i++ )
962 const float f = us_strtod(psz_bands, &psz_bands );
963 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
964 if( psz_bands == NULL || *psz_bands == '\0' ) break;
966 if( *psz_bands == '\0' ) break;
968 free( psz_bands_orig );
970 else free( psz_bands );
976 /* Functin called when enableButton is toggled */
977 void Equalizer::enable()
979 bool en = ui.enableCheck->isChecked();
980 aout_EnableFilter( THEPL, "equalizer", en );
981 // aout_EnableFilter( THEPL, "upmixer", en );
982 // aout_EnableFilter( THEPL, "vsurround", en );
985 if( presetsComboBox->currentIndex() < 0 )
986 presetsComboBox->setCurrentIndex( 0 );
990 void Equalizer::enable( bool en )
992 ui.eq2PassCheck->setEnabled( en );
993 presetsComboBox->setEnabled( en );
994 ui.presetLabel->setEnabled( en );
995 ui.preampLabel->setEnabled( en );
996 ui.preampSlider->setEnabled( en );
997 for( int i = 0 ; i< BANDS; i++ )
999 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
1003 /* Function called when the set2Pass button is activated */
1004 void Equalizer::set2Pass()
1006 vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
1007 bool b_2p = ui.eq2PassCheck->isChecked();
1011 var_SetBool( p_aout, "equalizer-2pass", b_2p );
1012 vlc_object_release( p_aout );
1014 config_PutInt( p_intf, "equalizer-2pass", b_2p );
1017 /* Function called when the preamp slider is moved */
1018 void Equalizer::setPreamp()
1020 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
1021 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1023 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
1027 //delCallbacks( p_aout );
1028 var_SetFloat( p_aout, "equalizer-preamp", f );
1029 //addCallbacks( p_aout );
1030 vlc_object_release( p_aout );
1032 config_PutFloat( p_intf, "equalizer-preamp", f );
1035 void Equalizer::setCoreBands()
1037 /**\todo smoothing */
1040 for( int i = 0; i < BANDS; i++ )
1042 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1043 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1045 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1046 values += " " + val;
1049 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1052 //delCallbacks( p_aout );
1053 var_SetString( p_aout, "equalizer-bands", qtu( values ) );
1054 //addCallbacks( p_aout );
1055 vlc_object_release( p_aout );
1059 char * Equalizer::createValuesFromPreset( int i_preset )
1063 /* Create the QString in Qt */
1064 for( int i = 0 ; i< BANDS ;i++ )
1065 values += QString( " %1" ).arg( eqz_preset_10b[i_preset].f_amp[i], 5, 'f', 1 );
1067 /* Convert it to char * */
1068 return strdup( values.toAscii().constData() );
1071 void Equalizer::setCorePreset( int i_preset )
1076 /* Update pre-amplification in the UI */
1077 float f_preamp = eqz_preset_10b[i_preset].f_preamp;
1078 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1079 ui.preampLabel->setText( qtr( "Preamp\n" )
1080 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1082 char *psz_values = createValuesFromPreset( i_preset );
1083 if( !psz_values ) return ;
1085 char *p = psz_values;
1086 for( int i = 0; i < BANDS && *p; i++ )
1088 const float f = us_strtod( p, &p );
1090 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1091 band_texts[i]->setText( band_frequencies[i] + "\n"
1092 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1094 p++; /* skip separator */
1097 /* Apply presets to audio output */
1098 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1101 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1103 var_SetString( p_aout, "equalizer-bands", psz_values );
1104 var_SetFloat( p_aout, "equalizer-preamp",
1105 eqz_preset_10b[i_preset].f_preamp );
1106 vlc_object_release( p_aout );
1108 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1109 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1110 config_PutFloat( p_intf, "equalizer-preamp",
1111 eqz_preset_10b[i_preset].f_preamp );
1115 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1116 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1118 VLC_UNUSED( p_this ); VLC_UNUSED( psz_cmd ); VLC_UNUSED( oldval );
1120 char *psz_preset = newval.psz_string;
1121 Equalizer *eq = ( Equalizer * )p_data;
1122 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1123 eq->presetsComboBox->setCurrentIndex( i_preset );
1127 void Equalizer::delCallbacks( vlc_object_t *p_aout )
1129 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1130 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1131 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1134 void Equalizer::addCallbacks( vlc_object_t *p_aout )
1136 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1137 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1138 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1141 /**********************************************************************
1143 **********************************************************************/
1145 /**********************************************************************
1146 * Dynamic range compressor
1147 **********************************************************************/
1151 const char *psz_name;
1152 const char *psz_descs;
1153 const char *psz_units;
1154 const float f_min; // min
1155 const float f_max; // max
1156 const float f_value; // value
1157 const float f_resolution; // resolution
1160 static const comp_controls_t comp_controls[] =
1162 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1163 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1164 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1165 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1166 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1167 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1168 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1171 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1172 : QWidget( _parent ) , p_intf( _p_intf )
1174 QFont smallFont = QApplication::font();
1175 smallFont.setPointSize( smallFont.pointSize() - 2 );
1177 QGridLayout *layout = new QGridLayout( this );
1179 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1180 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1182 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1184 const int i_min = (int)( comp_controls[i].f_min
1185 / comp_controls[i].f_resolution );
1186 const int i_max = (int)( comp_controls[i].f_max
1187 / comp_controls[i].f_resolution );
1188 const int i_val = (int)( comp_controls[i].f_value
1189 / comp_controls[i].f_resolution );
1191 compCtrl[i] = new QSlider( Qt::Vertical );
1192 compCtrl[i]->setMinimum( i_min );
1193 compCtrl[i]->setMaximum( i_max );
1194 compCtrl[i]->setValue( i_val );
1196 oldControlVars[i] = comp_controls[i].f_value;
1198 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1200 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1201 ctrl_texts[i]->setFont( smallFont );
1202 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1204 ctrl_readout[i] = new QLabel;
1205 ctrl_readout[i]->setFont( smallFont );
1206 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1208 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1209 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1210 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1213 BUTTONACT( enableCheck, enable() );
1215 /* Write down initial values */
1216 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1221 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1222 for( int i = 0; i < NUM_CP_CTRL; i++ )
1224 controlVars[i] = var_GetFloat( p_aout,
1225 comp_controls[i].psz_name );
1227 vlc_object_release( p_aout );
1231 psz_af = config_GetPsz( p_intf, "audio-filter" );
1232 for( int i = 0; i < NUM_CP_CTRL; i++ )
1234 controlVars[i] = config_GetFloat( p_intf,
1235 comp_controls[i].psz_name );
1238 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1240 enableCheck->setChecked( true );
1243 enable( enableCheck->isChecked() );
1244 updateSliders( controlVars );
1248 void Compressor::enable()
1250 bool en = enableCheck->isChecked();
1251 aout_EnableFilter( THEPL, "compressor", en );
1255 void Compressor::enable( bool en )
1257 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1259 compCtrl[i]->setEnabled( en );
1260 ctrl_texts[i]->setEnabled( en );
1261 ctrl_readout[i]->setEnabled( en );
1265 void Compressor::updateSliders( float * controlVars )
1267 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1269 if( oldControlVars[i] != controlVars[i] )
1271 compCtrl[i]->setValue(
1272 (int)( controlVars[i] / comp_controls[i].f_resolution ) );
1277 void Compressor::setInitValues()
1282 void Compressor::setValues()
1284 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1286 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1288 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1289 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1290 + qtr( comp_controls[i].psz_units ) );
1291 if( oldControlVars[i] != f )
1295 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1297 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1298 oldControlVars[i] = f;
1303 vlc_object_release( p_aout );
1307 /**********************************************************************
1309 **********************************************************************/
1312 const char *psz_name;
1313 const char *psz_desc;
1316 static const spat_controls_t spat_controls[] =
1318 { "spatializer-roomsize", _("Size") },
1319 { "spatializer-width", _("Width") },
1320 { "spatializer-wet", _("Wet") },
1321 { "spatializer-dry", _("Dry") },
1322 { "spatializer-damp", _("Damp") },
1325 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1326 : QWidget( _parent ) , p_intf( _p_intf )
1328 QFont smallFont = QApplication::font();
1329 smallFont.setPointSize( smallFont.pointSize() - 2 );
1331 QGridLayout *layout = new QGridLayout( this );
1333 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1334 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1336 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1338 spatCtrl[i] = new QSlider( Qt::Vertical );
1341 spatCtrl[i]->setMaximum( 10 );
1342 spatCtrl[i]->setValue( 2 );
1346 spatCtrl[i]->setMaximum( 10 );
1347 spatCtrl[i]->setValue( 0 );
1348 spatCtrl[i]->setMinimum( -10 );
1351 oldControlVars[i] = spatCtrl[i]->value();
1353 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1355 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1356 ctrl_texts[i]->setFont( smallFont );
1358 ctrl_readout[i] = new QLabel;
1359 ctrl_readout[i]->setFont( smallFont );
1361 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1362 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1363 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1366 BUTTONACT( enableCheck, enable() );
1368 /* Write down initial values */
1369 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1374 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1375 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1377 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1379 vlc_object_release( p_aout );
1383 psz_af = config_GetPsz( p_intf, "audio-filter" );
1384 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1386 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1389 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1390 enableCheck->setChecked( true );
1392 enable( enableCheck->isChecked() );
1396 void Spatializer::enable()
1398 bool en = enableCheck->isChecked();
1399 aout_EnableFilter( THEPL, "spatializer", en );
1403 void Spatializer::enable( bool en )
1405 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1407 spatCtrl[i]->setEnabled( en );
1408 ctrl_texts[i]->setEnabled( en );
1409 ctrl_readout[i]->setEnabled( en );
1412 void Spatializer::setInitValues()
1417 void Spatializer::setValues()
1419 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1421 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1423 float f = (float)( spatCtrl[i]->value() );
1424 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1428 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1430 if( oldControlVars[i] != spatCtrl[i]->value() )
1432 var_SetFloat( p_aout, spat_controls[i].psz_name,
1433 ( float )spatCtrl[i]->value() );
1434 config_PutFloat( p_intf, spat_controls[i].psz_name,
1435 ( float ) spatCtrl[i]->value() );
1436 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1439 vlc_object_release( p_aout );
1443 void Spatializer::delCallbacks( vlc_object_t *p_aout )
1445 VLC_UNUSED( p_aout );
1446 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1447 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1450 void Spatializer::addCallbacks( vlc_object_t *p_aout )
1452 VLC_UNUSED( p_aout );
1453 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1454 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1457 #include <QToolButton>
1458 #include <QGridLayout>
1460 #define SUBSDELAY_CFG_MODE "subsdelay-mode"
1461 #define SUBSDELAY_CFG_FACTOR "subsdelay-factor"
1462 #define SUBSDELAY_MODE_ABSOLUTE 0
1463 #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY 1
1464 #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
1466 SyncWidget::SyncWidget( QWidget *_parent ) : QDoubleSpinBox( _parent )
1468 setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1470 setMinimum( -600.0 );
1471 setMaximum( 600.0 );
1472 setSingleStep( 0.1 );
1473 setButtonSymbols( QDoubleSpinBox::PlusMinus );
1474 CONNECT( this, valueChanged( double ), this, valueChangedHandler( double ) );
1477 void SyncWidget::valueChangedHandler( double d )
1480 setPrefix( qtr("Hastened by ") );
1482 setPrefix( qtr("Delayed by ") );
1487 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1488 QWidget( _parent ) , p_intf( _p_intf )
1490 QGroupBox *AVBox, *subsBox;
1491 QToolButton *updateButton;
1493 b_userAction = true;
1495 QGridLayout *mainLayout = new QGridLayout( this );
1498 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1499 QGridLayout *AVLayout = new QGridLayout( AVBox );
1501 QLabel *AVLabel = new QLabel;
1502 AVLabel->setText( qtr( "Audio track synchronization:" ) );
1503 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1505 AVSpin = new SyncWidget( this );
1506 AVSpin->setSuffix( " s" );
1507 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1508 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1511 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1512 QGridLayout *subsLayout = new QGridLayout( subsBox );
1514 QLabel *subsLabel = new QLabel;
1515 subsLabel->setText( qtr( "Subtitle track syncronization:" ) );
1516 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1518 subsSpin = new SyncWidget( this );
1519 subsSpin->setSuffix( " s" );
1520 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1522 QLabel *subSpeedLabel = new QLabel;
1523 subSpeedLabel->setText( qtr( "Subtitles speed:" ) );
1524 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1526 subSpeedSpin = new QDoubleSpinBox;
1527 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1528 subSpeedSpin->setDecimals( 3 );
1529 subSpeedSpin->setMinimum( 1 );
1530 subSpeedSpin->setMaximum( 100 );
1531 subSpeedSpin->setSingleStep( 0.2 );
1532 subSpeedSpin->setSuffix( " fps" );
1533 subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1534 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1536 QLabel *subDurationLabel = new QLabel;
1537 subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
1538 subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
1540 subDurationSpin = new QDoubleSpinBox;
1541 subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1542 subDurationSpin->setDecimals( 3 );
1543 subDurationSpin->setMinimum( 0 );
1544 subDurationSpin->setMaximum( 20 );
1545 subDurationSpin->setSingleStep( 0.2 );
1546 subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1547 subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
1549 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1551 updateButton = new QToolButton;
1552 updateButton->setAutoRaise( true );
1553 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1555 /* Various Connects */
1556 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1557 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1558 CONNECT( subSpeedSpin, valueChanged ( double ),
1559 this, adjustSubsSpeed( double ) );
1560 CONNECT( subDurationSpin, valueChanged ( double ),
1561 this, adjustSubsDuration( double ) );
1563 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1564 BUTTON_SET_ACT_I( updateButton, "", update,
1565 qtr( "Force update of this dialog's values" ), update() );
1573 SyncControls::~SyncControls()
1578 void SyncControls::clean()
1580 b_userAction = false;
1581 AVSpin->setValue( 0.0 );
1582 subsSpin->setValue( 0.0 );
1583 subSpeedSpin->setValue( 1.0 );
1585 b_userAction = true;
1588 void SyncControls::update()
1590 b_userAction = false;
1593 if( THEMIM->getInput() )
1595 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1596 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1597 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1598 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1599 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1600 subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
1602 b_userAction = true;
1605 void SyncControls::advanceAudio( double f_advance )
1607 if( THEMIM->getInput() && b_userAction )
1609 int64_t i_delay = f_advance * 1000000;
1610 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1614 void SyncControls::advanceSubs( double f_advance )
1616 if( THEMIM->getInput() && b_userAction )
1618 int64_t i_delay = f_advance * 1000000;
1619 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1623 void SyncControls::adjustSubsSpeed( double f_fps )
1625 if( THEMIM->getInput() && b_userAction )
1627 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1631 void SyncControls::adjustSubsDuration( double f_factor )
1633 if( THEMIM->getInput() && b_userAction )
1635 subsdelaySetFactor( f_factor );
1636 ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
1640 void SyncControls::initSubsDuration()
1642 int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
1647 case SUBSDELAY_MODE_ABSOLUTE:
1648 subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
1649 "Set 0 to disable." ) );
1650 subDurationSpin->setSuffix( " s" );
1652 case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
1653 subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
1654 "Set 0 to disable." ) );
1655 subDurationSpin->setSuffix( "" );
1657 case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
1658 subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
1659 "to their content and this value.\n"
1660 "Set 0 to disable." ) );
1661 subDurationSpin->setSuffix( "" );
1666 void SyncControls::subsdelayClean()
1668 /* Remove subsdelay filter */
1669 ChangeVFiltersString( p_intf, "subsdelay", false );
1672 void SyncControls::subsdelaySetFactor( double f_factor )
1674 /* Set the factor in the preferences */
1675 config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
1677 /* Try to find an instance of subsdelay, and set its factor */
1678 vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
1681 var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
1682 vlc_object_release( p_obj );
1687 /**********************************************************************
1688 * Video filters / Adjust
1689 **********************************************************************/
1691 /**********************************************************************
1692 * Extended playbak controls
1693 **********************************************************************/