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"
49 #include <vlc_intf_strings.h>
52 #include <vlc_modules.h>
54 #include <vlc_charset.h> /* us_strtod */
57 class ConfClickHandler : public QObject
60 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
61 e = _e; p_intf = _p_intf;
63 virtual ~ConfClickHandler() {}
64 bool eventFilter( QObject *obj, QEvent *evt )
66 if( evt->type() == QEvent::MouseButtonPress )
75 intf_thread_t *p_intf;
79 const QString ModuleFromWidgetName( QObject *obj )
81 return obj->objectName().replace( "Enable","" );
84 QString OptionFromWidgetName( QObject *obj )
87 QString option = obj->objectName().replace( "Slider", "" )
88 .replace( "Combo" , "" )
89 .replace( "Dial" , "" )
90 .replace( "Check" , "" )
91 .replace( "Spin" , "" )
92 .replace( "Text" , "" );
93 for( char a = 'A'; a <= 'Z'; a++ )
95 option = option.replace( QString( a ),
96 QString( '-' ) + QString( a + 'a' - 'A' ) );
101 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
102 QObject( _parent ), p_intf( _p_intf )
104 ui.setupUi( _parent );
107 #define SETUP_VFILTER( widget ) \
109 vlc_object_t *p_obj = ( vlc_object_t * ) \
110 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 groupbox->setChecked( true ); \
123 if( checkbox ) checkbox->setChecked( false ); \
124 else groupbox->setChecked( false ); \
127 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
128 #define SETUP_VFILTER_OPTION( widget, signal ) \
129 initComboBoxItems( ui.widget ); \
130 setWidgetValue( ui.widget ); \
131 CONNECT( ui.widget, signal, this, updateFilterOptions() );
133 SETUP_VFILTER( adjust )
134 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
135 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
136 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
137 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
138 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
139 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
141 SETUP_VFILTER( extract )
142 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
144 SETUP_VFILTER( posterize )
145 SETUP_VFILTER_OPTION( posterizeLevelSpin, valueChanged( int ) )
147 SETUP_VFILTER( colorthres )
148 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
149 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
150 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
152 SETUP_VFILTER( sepia )
153 SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )
155 SETUP_VFILTER( invert )
157 SETUP_VFILTER( gradient )
158 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
159 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
160 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
162 SETUP_VFILTER( motionblur )
163 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
165 SETUP_VFILTER( motiondetect )
167 // SETUP_VFILTER( noise )
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 ) )
200 SETUP_VFILTER( panoramix )
201 SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
202 SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
205 SETUP_VFILTER( erase )
206 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
207 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
208 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
209 BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
211 SETUP_VFILTER( marq )
212 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
213 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
215 SETUP_VFILTER( logo )
216 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
217 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
218 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
219 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
220 BUTTONACT( ui.logoBrowseBtn, browseLogo() );
222 SETUP_VFILTER( gradfun )
223 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
225 SETUP_VFILTER( grain )
226 SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
228 if( module_exists( "atmo" ) )
230 SETUP_VFILTER( atmo )
231 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
232 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
233 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
234 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
235 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
236 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
237 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
238 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
242 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
246 #undef SETUP_VFILTER_OPTION
248 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
249 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
250 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
251 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
252 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
253 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
254 CONNECT( ui.topBotCropSync, toggled( bool ),
255 ui.cropBotPx, setDisabled( bool ) );
256 CONNECT( ui.leftRightCropSync, toggled( bool ),
257 ui.cropRightPx, setDisabled( bool ) );
260 void ExtVideo::cropChange()
262 if( ui.topBotCropSync->isChecked() )
263 ui.cropBotPx->setValue( ui.cropTopPx->value() );
264 if( ui.leftRightCropSync->isChecked() )
265 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
267 p_vout = THEMIM->getVout();
270 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
271 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
272 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
273 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
274 vlc_object_release( p_vout );
278 void ExtVideo::clean()
280 ui.cropTopPx->setValue( 0 );
281 ui.cropBotPx->setValue( 0 );
282 ui.cropLeftPx->setValue( 0 );
283 ui.cropRightPx->setValue( 0 );
286 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
288 char *psz_parser, *psz_string;
289 const char *psz_filter_type;
291 module_t *p_obj = module_find( psz_name );
294 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
298 if( module_provides( p_obj, "video splitter" ) )
300 psz_filter_type = "video-splitter";
302 else if( module_provides( p_obj, "video filter2" ) )
304 psz_filter_type = "video-filter";
306 else if( module_provides( p_obj, "sub source" ) )
308 psz_filter_type = "sub-source";
310 else if( module_provides( p_obj, "sub filter" ) )
312 psz_filter_type = "sub-filter";
316 module_release (p_obj);
317 msg_Err( p_intf, "Unknown video filter type." );
320 module_release (p_obj);
322 psz_string = config_GetPsz( p_intf, psz_filter_type );
324 if( !psz_string ) psz_string = strdup( "" );
326 psz_parser = strstr( psz_string, psz_name );
332 psz_parser = psz_string;
333 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
334 psz_string, psz_name ) == -1 )
350 if( *( psz_parser + strlen( psz_name ) ) == ':' )
352 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
353 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
360 /* Remove trailing : : */
361 if( strlen( psz_string ) > 0 &&
362 *( psz_string + strlen( psz_string ) -1 ) == ':' )
364 *( psz_string + strlen( psz_string ) -1 ) = '\0';
373 /* Vout is not kept, so put that in the config */
374 config_PutPsz( p_intf, psz_filter_type, psz_string );
376 /* Try to set on the fly */
377 if( !strcmp( psz_filter_type, "video-splitter" ) )
379 playlist_t *p_playlist = pl_Get( p_intf );
380 var_SetString( p_playlist, psz_filter_type, psz_string );
384 p_vout = THEMIM->getVout();
387 var_SetString( p_vout, psz_filter_type, psz_string );
388 vlc_object_release( p_vout );
395 void ExtVideo::updateFilters()
397 QString module = ModuleFromWidgetName( sender() );
399 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
400 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
402 ChangeVFiltersString( qtu( module ),
403 checkbox ? checkbox->isChecked()
404 : groupbox->isChecked() );
407 void ExtVideo::browseLogo()
409 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
410 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
411 ui.logoFileText->setText( toNativeSeparators( file ) );
414 void ExtVideo::browseEraseFile()
416 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
417 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
418 ui.eraseMaskText->setText( toNativeSeparators( file ) );
421 void ExtVideo::initComboBoxItems( QObject *widget )
423 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
424 if( !combobox ) return;
426 QString option = OptionFromWidgetName( widget );
427 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
431 int i_type = p_item->i_type & CONFIG_ITEM;
432 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
434 if( i_type == CONFIG_ITEM_INTEGER
435 || i_type == CONFIG_ITEM_BOOL )
436 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
437 p_item->pi_list[i_index] );
438 else if( i_type == CONFIG_ITEM_STRING )
439 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
440 p_item->ppsz_list[i_index] );
445 msg_Err( p_intf, "Couldn't find option \"%s\".",
450 void ExtVideo::setWidgetValue( QObject *widget )
452 QString module = ModuleFromWidgetName( widget->parent() );
453 //std::cout << "Module name: " << module.toStdString() << std::endl;
454 QString option = OptionFromWidgetName( widget );
455 //std::cout << "Option name: " << option.toStdString() << std::endl;
457 vlc_object_t *p_obj = ( vlc_object_t * )
458 vlc_object_find_name( p_intf->p_libvlc,
468 "Module instance %s not found, looking in config values.",
471 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
474 case VLC_VAR_INTEGER:
476 val.i_int = config_GetInt( p_intf, qtu( option ) );
479 val.f_float = config_GetFloat( p_intf, qtu( option ) );
482 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
488 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
489 var_Get( p_obj, qtu( option ), &val );
490 vlc_object_release( p_obj );
493 /* Try to cast to all the widgets we're likely to encounter. Only
494 * one of the casts is expected to work. */
495 QSlider *slider = qobject_cast<QSlider*> ( widget );
496 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
497 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
498 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
499 QDial *dial = qobject_cast<QDial*> ( widget );
500 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
501 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
503 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
505 if( slider ) slider->setValue( val.i_int );
506 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
508 else if( spinbox ) spinbox->setValue( val.i_int );
509 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
513 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
514 lineedit->setText( str );
516 else if( combobox ) combobox->setCurrentIndex(
517 combobox->findData( qlonglong(val.i_int) ) );
518 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
520 else if( i_type == VLC_VAR_FLOAT )
522 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
523 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
524 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
526 else if( i_type == VLC_VAR_STRING )
528 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
529 else if( combobox ) combobox->setCurrentIndex(
530 combobox->findData( qfu( val.psz_string ) ) );
531 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
532 free( val.psz_string );
537 "Module %s's %s variable is of an unsupported type ( %d )",
543 void ExtVideo::updateFilterOptions()
545 QString module = ModuleFromWidgetName( sender()->parent() );
546 //std::cout << "Module name: " << module.toStdString() << std::endl;
547 QString option = OptionFromWidgetName( sender() );
548 //std::cout << "Option name: " << option.toStdString() << std::endl;
550 vlc_object_t *p_obj = ( vlc_object_t * )
551 vlc_object_find_name( p_intf->p_libvlc,
558 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
559 i_type = config_GetType( p_intf, qtu( option ) );
560 b_is_command = false;
564 i_type = var_Type( p_obj, qtu( option ) );
566 i_type = config_GetType( p_intf, qtu( option ) );
567 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
572 msg_Warn( p_intf, "Module %s's %s variable isn't a command. You'll need to restart the filter to take change into account.",
575 /* FIXME: restart automatically somewhere near the end of this function */
578 /* Try to cast to all the widgets we're likely to encounter. Only
579 * one of the casts is expected to work. */
580 QSlider *slider = qobject_cast<QSlider*> ( sender() );
581 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
582 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
583 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
584 QDial *dial = qobject_cast<QDial*> ( sender() );
585 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
586 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
588 i_type &= VLC_VAR_CLASS;
589 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
592 if( slider ) i_int = slider->value();
593 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
594 else if( spinbox ) i_int = spinbox->value();
595 else if( dial ) i_int = ( 540-dial->value() )%360;
596 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
597 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
598 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
599 config_PutInt( p_intf, qtu( option ), i_int );
602 if( i_type == VLC_VAR_INTEGER )
603 var_SetInteger( p_obj, qtu( option ), i_int );
605 var_SetBool( p_obj, qtu( option ), i_int );
608 else if( i_type == VLC_VAR_FLOAT )
611 if( slider ) f_float = ( double )slider->value()
612 / ( double )slider->tickInterval(); /* hack alert! */
613 else if( doublespinbox ) f_float = doublespinbox->value();
614 else if( lineedit ) f_float = lineedit->text().toDouble();
615 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
616 config_PutFloat( p_intf, qtu( option ), f_float );
618 var_SetFloat( p_obj, qtu( option ), f_float );
620 else if( i_type == VLC_VAR_STRING )
622 char *psz_string = NULL;
623 if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
624 else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
625 combobox->currentIndex() ).toString() ) );
626 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
627 config_PutPsz( p_intf, qtu( option ), psz_string );
629 var_SetString( p_obj, qtu( option ), psz_string );
634 "Module %s's %s variable is of an unsupported type ( %d )",
639 if( p_obj ) vlc_object_release( p_obj );
643 void ExtVideo::gotoConf( QObject* src )
645 #define SHOWCONF( module ) \
646 if( src->objectName().contains( module ) ) \
648 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
652 SHOWCONF( "magnify" );
654 SHOWCONF( "ripple" );
655 SHOWCONF( "invert" );
656 SHOWCONF( "puzzle" );
658 SHOWCONF( "gradient" );
659 SHOWCONF( "colorthres" )
663 /**********************************************************************
665 **********************************************************************/
667 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
668 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
670 QVBoxLayout *layout = new QVBoxLayout( this );
671 help = new QLabel( qtr("No v4l2 instance found.\n"
672 "Please check that the device has been opened with VLC and is playing.\n\n"
673 "Controls will automatically appear here.")
675 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
676 layout->addWidget( help );
680 void ExtV4l2::showEvent( QShowEvent *event )
682 QWidget::showEvent( event );
686 void ExtV4l2::Refresh( void )
688 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
692 layout()->removeWidget( box );
698 vlc_value_t val, text, name;
699 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
703 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
705 vlc_object_release( p_obj );
709 box = new QGroupBox( this );
710 layout()->addWidget( box );
711 QVBoxLayout *layout = new QVBoxLayout( box );
712 box->setLayout( layout );
714 for( int i = 0; i < val.p_list->i_count; i++ )
716 const char *psz_var = text.p_list->p_values[i].psz_string;
717 var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
718 const char *psz_label = name.psz_string;
719 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
720 val.p_list->p_values[i].i_int, psz_var, name.psz_string );
722 int i_type = var_Type( p_obj, psz_var );
723 switch( i_type & VLC_VAR_TYPE )
725 case VLC_VAR_INTEGER:
727 QLabel *label = new QLabel( qtr( psz_label ), box );
728 QHBoxLayout *hlayout = new QHBoxLayout();
729 hlayout->addWidget( label );
730 int i_val = var_GetInteger( p_obj, psz_var );
731 if( i_type & VLC_VAR_HASCHOICE )
733 QComboBox *combobox = new QComboBox( box );
734 combobox->setObjectName( qtr( psz_var ) );
736 vlc_value_t val2, text2;
737 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
739 for( int j = 0; j < val2.p_list->i_count; j++ )
742 text2.p_list->p_values[j].psz_string,
743 qlonglong( val2.p_list->p_values[j].i_int) );
744 if( i_val == val2.p_list->p_values[j].i_int )
745 combobox->setCurrentIndex( j );
747 var_FreeList( &val2, &text2 );
749 CONNECT( combobox, currentIndexChanged( int ), this,
750 ValueChange( int ) );
751 hlayout->addWidget( combobox );
755 QSlider *slider = new QSlider( box );
756 slider->setObjectName( qtr( psz_var ) );
757 slider->setOrientation( Qt::Horizontal );
759 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
761 slider->setMinimum( val2.i_int );
762 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
764 slider->setMaximum( val2.i_int );
765 var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
767 slider->setSingleStep( val2.i_int );
768 slider->setValue( i_val );
770 CONNECT( slider, valueChanged( int ), this,
771 ValueChange( int ) );
772 hlayout->addWidget( slider );
774 layout->addLayout( hlayout );
779 QCheckBox *button = new QCheckBox( qtr( psz_label ), box );
780 button->setObjectName( qtr( psz_var ) );
781 button->setChecked( var_GetBool( p_obj, psz_var ) );
783 CONNECT( button, clicked( bool ), this,
784 ValueChange( bool ) );
785 layout->addWidget( button );
790 if( i_type & VLC_VAR_ISCOMMAND )
792 QPushButton *button = new QPushButton( qtr( psz_label ), box );
793 button->setObjectName( qtr( psz_var ) );
795 CONNECT( button, clicked( bool ), this,
796 ValueChange( bool ) );
797 layout->addWidget( button );
801 QLabel *label = new QLabel( qtr( psz_label ), box );
802 layout->addWidget( label );
807 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
810 free( name.psz_string );
812 var_FreeList( &val, &text );
813 vlc_object_release( p_obj );
817 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
820 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
824 void ExtV4l2::ValueChange( bool value )
826 ValueChange( (int)value );
829 void ExtV4l2::ValueChange( int value )
831 QObject *s = sender();
832 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
835 char *psz_var = strdup( qtu( s->objectName() ) );
836 int i_type = var_Type( p_obj, psz_var );
837 switch( i_type & VLC_VAR_TYPE )
839 case VLC_VAR_INTEGER:
840 if( i_type & VLC_VAR_HASCHOICE )
842 QComboBox *combobox = qobject_cast<QComboBox*>( s );
843 value = combobox->itemData( value ).toInt();
845 var_SetInteger( p_obj, psz_var, value );
848 var_SetBool( p_obj, psz_var, value );
851 var_TriggerCallback( p_obj, psz_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 aout_instance_t *p_aout = 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 aout_instance_t *p_aout= 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 aout_instance_t *p_aout = 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;
1048 const char *psz_values = values.toAscii().constData();
1050 aout_instance_t *p_aout = THEMIM->getAout();
1053 //delCallbacks( p_aout );
1054 var_SetString( p_aout, "equalizer-bands", psz_values );
1055 //addCallbacks( p_aout );
1056 vlc_object_release( p_aout );
1060 char * Equalizer::createValuesFromPreset( int i_preset )
1064 /* Create the QString in Qt */
1065 for( int i = 0 ; i< BANDS ;i++ )
1066 values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1068 /* Convert it to char * */
1069 return strdup( values.toAscii().constData() );
1072 void Equalizer::setCorePreset( int i_preset )
1077 /* Update pre-amplification in the UI */
1078 float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1079 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1080 ui.preampLabel->setText( qtr( "Preamp\n" )
1081 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1083 char *psz_values = createValuesFromPreset( i_preset );
1084 if( !psz_values ) return ;
1086 char *p = psz_values;
1087 for( int i = 0; i < BANDS && *p; i++ )
1089 const float f = us_strtod( p, &p );
1091 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1092 band_texts[i]->setText( band_frequencies[i] + "\n"
1093 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1095 p++; /* skip separator */
1098 /* Apply presets to audio output */
1099 aout_instance_t *p_aout= THEMIM->getAout();
1102 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1104 var_SetString( p_aout, "equalizer-bands", psz_values );
1105 var_SetFloat( p_aout, "equalizer-preamp",
1106 eqz_preset_10b[i_preset]->f_preamp );
1107 vlc_object_release( p_aout );
1109 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1110 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1111 config_PutFloat( p_intf, "equalizer-preamp",
1112 eqz_preset_10b[i_preset]->f_preamp );
1116 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1117 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1119 char *psz_preset = newval.psz_string;
1120 Equalizer *eq = ( Equalizer * )p_data;
1121 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1122 eq->presetsComboBox->setCurrentIndex( i_preset );
1126 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1128 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1129 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1130 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1133 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1135 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1136 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1137 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1140 /**********************************************************************
1142 **********************************************************************/
1144 /**********************************************************************
1145 * Dynamic range compressor
1146 **********************************************************************/
1150 const char *psz_name;
1151 const char *psz_descs;
1152 const char *psz_units;
1153 const float f_min; // min
1154 const float f_max; // max
1155 const float f_value; // value
1156 const float f_resolution; // resolution
1159 static const comp_controls_t comp_controls[] =
1161 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1162 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1163 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1164 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1165 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1166 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1167 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1170 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1171 : QWidget( _parent ) , p_intf( _p_intf )
1173 QFont smallFont = QApplication::font();
1174 smallFont.setPointSize( smallFont.pointSize() - 2 );
1176 QGridLayout *layout = new QGridLayout( this );
1178 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1179 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1181 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1183 const int i_min = (int)( comp_controls[i].f_min
1184 / comp_controls[i].f_resolution );
1185 const int i_max = (int)( comp_controls[i].f_max
1186 / comp_controls[i].f_resolution );
1187 const int i_val = (int)( comp_controls[i].f_value
1188 / comp_controls[i].f_resolution );
1190 compCtrl[i] = new QSlider( Qt::Vertical );
1191 compCtrl[i]->setMinimum( i_min );
1192 compCtrl[i]->setMaximum( i_max );
1193 compCtrl[i]->setValue( i_val );
1195 oldControlVars[i] = comp_controls[i].f_value;
1197 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1199 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1200 ctrl_texts[i]->setFont( smallFont );
1201 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1203 ctrl_readout[i] = new QLabel;
1204 ctrl_readout[i]->setFont( smallFont );
1205 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1207 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1208 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1209 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1212 BUTTONACT( enableCheck, enable() );
1214 /* Write down initial values */
1215 aout_instance_t *p_aout = THEMIM->getAout();
1220 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1221 for( int i = 0; i < NUM_CP_CTRL; i++ )
1223 controlVars[i] = var_GetFloat( p_aout,
1224 comp_controls[i].psz_name );
1226 vlc_object_release( p_aout );
1230 psz_af = config_GetPsz( p_intf, "audio-filter" );
1231 for( int i = 0; i < NUM_CP_CTRL; i++ )
1233 controlVars[i] = config_GetFloat( p_intf,
1234 comp_controls[i].psz_name );
1237 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1239 enableCheck->setChecked( true );
1242 enable( enableCheck->isChecked() );
1243 updateSliders( controlVars );
1244 setValues( controlVars );
1247 void Compressor::enable()
1249 bool en = enableCheck->isChecked();
1250 aout_EnableFilter( THEPL, "compressor", en );
1254 void Compressor::enable( bool en )
1256 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1258 compCtrl[i]->setEnabled( en );
1259 ctrl_texts[i]->setEnabled( en );
1260 ctrl_readout[i]->setEnabled( en );
1264 void Compressor::updateSliders( float * controlVars )
1266 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1268 if( oldControlVars[i] != controlVars[i] )
1270 compCtrl[i]->setValue(
1271 (int)( controlVars[i] / comp_controls[i].f_resolution ) );
1276 void Compressor::setInitValues()
1278 setValues( controlVars );
1281 void Compressor::setValues( float * controlVars )
1283 aout_instance_t *p_aout = THEMIM->getAout();
1285 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1287 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1288 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1289 + qtr( comp_controls[i].psz_units ) );
1290 if( oldControlVars[i] != f )
1294 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1296 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1297 oldControlVars[i] = f;
1302 vlc_object_release( p_aout );
1306 /**********************************************************************
1308 **********************************************************************/
1311 const char *psz_name;
1312 const char *psz_desc;
1315 static const spat_controls_t spat_controls[] =
1317 { "spatializer-roomsize", _("Size") },
1318 { "spatializer-width", _("Width") },
1319 { "spatializer-wet", _("Wet") },
1320 { "spatializer-dry", _("Dry") },
1321 { "spatializer-damp", _("Damp") },
1324 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1325 : QWidget( _parent ) , p_intf( _p_intf )
1327 QFont smallFont = QApplication::font();
1328 smallFont.setPointSize( smallFont.pointSize() - 2 );
1330 QGridLayout *layout = new QGridLayout( this );
1332 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1333 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1335 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1337 spatCtrl[i] = new QSlider( Qt::Vertical );
1340 spatCtrl[i]->setMaximum( 10 );
1341 spatCtrl[i]->setValue( 2 );
1345 spatCtrl[i]->setMaximum( 10 );
1346 spatCtrl[i]->setValue( 0 );
1347 spatCtrl[i]->setMinimum( -10 );
1350 oldControlVars[i] = spatCtrl[i]->value();
1352 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1354 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1355 ctrl_texts[i]->setFont( smallFont );
1357 ctrl_readout[i] = new QLabel;
1358 ctrl_readout[i]->setFont( smallFont );
1360 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1361 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1362 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1365 BUTTONACT( enableCheck, enable() );
1367 /* Write down initial values */
1368 aout_instance_t *p_aout = THEMIM->getAout();
1373 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1374 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1376 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1378 vlc_object_release( p_aout );
1382 psz_af = config_GetPsz( p_intf, "audio-filter" );
1383 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1385 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1388 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1389 enableCheck->setChecked( true );
1391 enable( enableCheck->isChecked() );
1392 setValues( controlVars );
1395 void Spatializer::enable()
1397 bool en = enableCheck->isChecked();
1398 aout_EnableFilter( THEPL, "spatializer", en );
1402 void Spatializer::enable( bool en )
1404 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1406 spatCtrl[i]->setEnabled( en );
1407 ctrl_texts[i]->setEnabled( en );
1408 ctrl_readout[i]->setEnabled( en );
1411 void Spatializer::setInitValues()
1413 setValues( controlVars );
1416 void Spatializer::setValues( float *controlVars )
1418 aout_instance_t *p_aout = THEMIM->getAout();
1420 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1422 float f = (float)( spatCtrl[i]->value() );
1423 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1427 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1429 if( oldControlVars[i] != spatCtrl[i]->value() )
1431 var_SetFloat( p_aout, spat_controls[i].psz_name,
1432 ( float )spatCtrl[i]->value() );
1433 config_PutFloat( p_intf, spat_controls[i].psz_name,
1434 ( float ) spatCtrl[i]->value() );
1435 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1438 vlc_object_release( p_aout );
1442 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1444 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1445 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1448 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1450 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1451 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1454 #include <QToolButton>
1455 #include <QGridLayout>
1457 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1458 QWidget( _parent ) , p_intf( _p_intf )
1460 QGroupBox *AVBox, *subsBox;
1462 QToolButton *moinsAV, *plusAV;
1463 QToolButton *moinssubs, *plussubs;
1464 QToolButton *moinssubSpeed, *plussubSpeed;
1466 QToolButton *updateButton;
1468 b_userAction = true;
1470 QGridLayout *mainLayout = new QGridLayout( this );
1473 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1474 QGridLayout *AVLayout = new QGridLayout( AVBox );
1476 moinsAV = new QToolButton;
1477 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1478 moinsAV->setAutoRaise( true );
1479 moinsAV->setText( "-" );
1480 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1482 plusAV = new QToolButton;
1483 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1484 plusAV->setAutoRaise( true );
1485 plusAV->setText( "+" );
1486 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1488 QLabel *AVLabel = new QLabel;
1489 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1490 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1492 AVSpin = new QDoubleSpinBox;
1493 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1494 AVSpin->setDecimals( 3 );
1495 AVSpin->setMinimum( -600.0 );
1496 AVSpin->setMaximum( 600.0 );
1497 AVSpin->setSingleStep( 0.1 );
1498 AVSpin->setToolTip( qtr( "A positive value means that\n"
1499 "the audio is ahead of the video" ) );
1500 AVSpin->setSuffix( " s" );
1501 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1502 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1506 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1507 QGridLayout *subsLayout = new QGridLayout( subsBox );
1509 moinssubs = new QToolButton;
1510 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1511 moinssubs->setAutoRaise( true );
1512 moinssubs->setText( "-" );
1513 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1515 plussubs = new QToolButton;
1516 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1517 plussubs->setAutoRaise( true );
1518 plussubs->setText( "+" );
1519 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1521 QLabel *subsLabel = new QLabel;
1522 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1523 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1525 subsSpin = new QDoubleSpinBox;
1526 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1527 subsSpin->setDecimals( 3 );
1528 subsSpin->setMinimum( -600.0 );
1529 subsSpin->setMaximum( 600.0 );
1530 subsSpin->setSingleStep( 0.1 );
1531 subsSpin->setToolTip( qtr( "A positive value means that\n"
1532 "the subtitles are ahead of the video" ) );
1533 subsSpin->setSuffix( " s" );
1534 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1537 moinssubSpeed = new QToolButton;
1538 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1539 moinssubSpeed->setAutoRaise( true );
1540 moinssubSpeed->setText( "-" );
1541 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1543 plussubSpeed = new QToolButton;
1544 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1545 plussubSpeed->setAutoRaise( true );
1546 plussubSpeed->setText( "+" );
1547 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1549 QLabel *subSpeedLabel = new QLabel;
1550 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1551 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1553 subSpeedSpin = new QDoubleSpinBox;
1554 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1555 subSpeedSpin->setDecimals( 3 );
1556 subSpeedSpin->setMinimum( 1 );
1557 subSpeedSpin->setMaximum( 100 );
1558 subSpeedSpin->setSingleStep( 0.2 );
1559 subSpeedSpin->setSuffix( " fps" );
1560 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1562 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1564 updateButton = new QToolButton;
1565 updateButton->setAutoRaise( true );
1566 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1569 /* Various Connects */
1570 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1571 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1572 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1573 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1574 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1575 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1576 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1577 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1578 CONNECT( subSpeedSpin, valueChanged ( double ),
1579 this, adjustSubsSpeed( double ) );
1581 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1582 BUTTON_SET_ACT_I( updateButton, "", update,
1583 qtr( "Force update of this dialog's values" ), update() );
1589 void SyncControls::clean()
1591 b_userAction = false;
1592 AVSpin->setValue( 0.0 );
1593 subsSpin->setValue( 0.0 );
1594 subSpeedSpin->setValue( 1.0 );
1595 b_userAction = true;
1598 void SyncControls::update()
1600 b_userAction = false;
1603 if( THEMIM->getInput() )
1605 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1606 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1607 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1608 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1609 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1611 b_userAction = true;
1614 void SyncControls::advanceAudio( double f_advance )
1616 if( THEMIM->getInput() && b_userAction )
1618 int64_t i_delay = f_advance * 1000000;
1619 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1623 void SyncControls::advanceSubs( double f_advance )
1625 if( THEMIM->getInput() && b_userAction )
1627 int64_t i_delay = f_advance * 1000000;
1628 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1632 void SyncControls::adjustSubsSpeed( double f_fps )
1634 if( THEMIM->getInput() && b_userAction )
1636 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1640 /**********************************************************************
1641 * Video filters / Adjust
1642 **********************************************************************/
1644 /**********************************************************************
1645 * Extended playbak controls
1646 **********************************************************************/