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 module_release (p_obj);
321 msg_Err( p_intf, "Unknown video filter type." );
324 module_release (p_obj);
326 psz_string = config_GetPsz( p_intf, psz_filter_type );
328 if( !psz_string ) psz_string = strdup( "" );
330 psz_parser = strstr( psz_string, psz_name );
336 psz_parser = psz_string;
337 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
338 psz_string, psz_name ) == -1 )
354 if( *( psz_parser + strlen( psz_name ) ) == ':' )
356 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
357 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
364 /* Remove trailing : : */
365 if( strlen( psz_string ) > 0 &&
366 *( psz_string + strlen( psz_string ) -1 ) == ':' )
368 *( psz_string + strlen( psz_string ) -1 ) = '\0';
377 /* Vout is not kept, so put that in the config */
378 config_PutPsz( p_intf, psz_filter_type, psz_string );
380 /* Try to set on the fly */
381 if( !strcmp( psz_filter_type, "video-splitter" ) )
383 playlist_t *p_playlist = pl_Get( p_intf );
384 var_SetString( p_playlist, psz_filter_type, psz_string );
388 vout_thread_t *p_vout = THEMIM->getVout();
391 var_SetString( p_vout, psz_filter_type, psz_string );
392 vlc_object_release( p_vout );
399 void ExtVideo::updateFilters()
401 QString module = ModuleFromWidgetName( sender() );
403 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
404 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
406 ChangeVFiltersString( p_intf, qtu( module ),
407 checkbox ? checkbox->isChecked()
408 : groupbox->isChecked() );
411 void ExtVideo::browseLogo()
413 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
414 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
415 ui.logoFileText->setText( toNativeSeparators( file ) );
418 void ExtVideo::browseEraseFile()
420 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
421 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
422 ui.eraseMaskText->setText( toNativeSeparators( file ) );
425 void ExtVideo::initComboBoxItems( QObject *widget )
427 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
428 if( !combobox ) return;
430 QString option = OptionFromWidgetName( widget );
431 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
435 int i_type = p_item->i_type;
436 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
438 if( i_type == CONFIG_ITEM_INTEGER
439 || i_type == CONFIG_ITEM_BOOL )
440 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
441 p_item->pi_list[i_index] );
442 else if( i_type == CONFIG_ITEM_STRING )
443 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
444 p_item->ppsz_list[i_index] );
449 msg_Err( p_intf, "Couldn't find option \"%s\".",
454 void ExtVideo::setWidgetValue( QObject *widget )
456 QString module = ModuleFromWidgetName( widget->parent() );
457 //std::cout << "Module name: " << module.toStdString() << std::endl;
458 QString option = OptionFromWidgetName( widget );
459 //std::cout << "Option name: " << option.toStdString() << std::endl;
461 vlc_object_t *p_obj = ( vlc_object_t * )
462 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
470 "Module instance %s not found, looking in config values.",
473 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
476 case VLC_VAR_INTEGER:
478 val.i_int = config_GetInt( p_intf, qtu( option ) );
481 val.f_float = config_GetFloat( p_intf, qtu( option ) );
484 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
490 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
491 var_Get( p_obj, qtu( option ), &val );
492 vlc_object_release( p_obj );
495 /* Try to cast to all the widgets we're likely to encounter. Only
496 * one of the casts is expected to work. */
497 QSlider *slider = qobject_cast<QSlider*> ( widget );
498 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
499 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
500 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
501 QDial *dial = qobject_cast<QDial*> ( widget );
502 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
503 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
505 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
507 if( slider ) slider->setValue( val.i_int );
508 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
510 else if( spinbox ) spinbox->setValue( val.i_int );
511 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
515 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
516 lineedit->setText( str );
518 else if( combobox ) combobox->setCurrentIndex(
519 combobox->findData( qlonglong(val.i_int) ) );
520 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
522 else if( i_type == VLC_VAR_FLOAT )
524 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
525 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
526 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
528 else if( i_type == VLC_VAR_STRING )
530 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
531 else if( combobox ) combobox->setCurrentIndex(
532 combobox->findData( qfu( val.psz_string ) ) );
533 else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
534 free( val.psz_string );
539 "Module %s's %s variable is of an unsupported type ( %d )",
545 void ExtVideo::updateFilterOptions()
547 QString module = ModuleFromWidgetName( sender()->parent() );
548 //std::cout << "Module name: " << module.toStdString() << std::endl;
549 QString option = OptionFromWidgetName( sender() );
550 //std::cout << "Option name: " << option.toStdString() << std::endl;
552 vlc_object_t *p_obj = ( vlc_object_t * )
553 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
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 )
624 val = lineedit->text();
626 val = combobox->itemData( combobox->currentIndex() ).toString();
628 msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
629 config_PutPsz( p_intf, qtu( option ), qtu( val ) );
631 var_SetString( p_obj, qtu( option ), qtu( val ) );
635 "Module %s's %s variable is of an unsupported type ( %d )",
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 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1467 QWidget( _parent ) , p_intf( _p_intf )
1469 QGroupBox *AVBox, *subsBox;
1471 QToolButton *moinsAV, *plusAV;
1472 QToolButton *moinssubs, *plussubs;
1473 QToolButton *moinssubSpeed, *plussubSpeed;
1474 QToolButton *moinssubDuration, *plussubDuration;
1476 QToolButton *updateButton;
1478 b_userAction = true;
1480 QGridLayout *mainLayout = new QGridLayout( this );
1483 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1484 QGridLayout *AVLayout = new QGridLayout( AVBox );
1486 moinsAV = new QToolButton;
1487 moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1488 moinsAV->setAutoRaise( true );
1489 moinsAV->setText( "-" );
1490 AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1492 plusAV = new QToolButton;
1493 plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1494 plusAV->setAutoRaise( true );
1495 plusAV->setText( "+" );
1496 AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1498 QLabel *AVLabel = new QLabel;
1499 AVLabel->setText( qtr( "Advance of audio over video:" ) );
1500 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1502 AVSpin = new QDoubleSpinBox;
1503 AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1504 AVSpin->setDecimals( 3 );
1505 AVSpin->setMinimum( -600.0 );
1506 AVSpin->setMaximum( 600.0 );
1507 AVSpin->setSingleStep( 0.1 );
1508 AVSpin->setToolTip( qtr( "A positive value means that\n"
1509 "the audio is ahead of the video" ) );
1510 AVSpin->setSuffix( " s" );
1511 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1512 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1516 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1517 QGridLayout *subsLayout = new QGridLayout( subsBox );
1519 moinssubs = new QToolButton;
1520 moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1521 moinssubs->setAutoRaise( true );
1522 moinssubs->setText( "-" );
1523 subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1525 plussubs = new QToolButton;
1526 plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1527 plussubs->setAutoRaise( true );
1528 plussubs->setText( "+" );
1529 subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1531 QLabel *subsLabel = new QLabel;
1532 subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1533 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1535 subsSpin = new QDoubleSpinBox;
1536 subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1537 subsSpin->setDecimals( 3 );
1538 subsSpin->setMinimum( -600.0 );
1539 subsSpin->setMaximum( 600.0 );
1540 subsSpin->setSingleStep( 0.1 );
1541 subsSpin->setToolTip( qtr( "A positive value means that\n"
1542 "the subtitles are ahead of the video" ) );
1543 subsSpin->setSuffix( " s" );
1544 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1547 moinssubSpeed = new QToolButton;
1548 moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1549 moinssubSpeed->setAutoRaise( true );
1550 moinssubSpeed->setText( "-" );
1551 subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1553 plussubSpeed = new QToolButton;
1554 plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1555 plussubSpeed->setAutoRaise( true );
1556 plussubSpeed->setText( "+" );
1557 subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1559 QLabel *subSpeedLabel = new QLabel;
1560 subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1561 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1563 subSpeedSpin = new QDoubleSpinBox;
1564 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1565 subSpeedSpin->setDecimals( 3 );
1566 subSpeedSpin->setMinimum( 1 );
1567 subSpeedSpin->setMaximum( 100 );
1568 subSpeedSpin->setSingleStep( 0.2 );
1569 subSpeedSpin->setSuffix( " fps" );
1570 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1572 moinssubDuration = new QToolButton;
1573 moinssubDuration->setToolButtonStyle( Qt::ToolButtonTextOnly );
1574 moinssubDuration->setAutoRaise( true );
1575 moinssubDuration->setText( "-" );
1576 subsLayout->addWidget( moinssubDuration, 2, 1, 1, 1 );
1578 plussubDuration = new QToolButton;
1579 plussubDuration->setToolButtonStyle( Qt::ToolButtonTextOnly );
1580 plussubDuration->setAutoRaise( true );
1581 plussubDuration->setText( "+" );
1582 subsLayout->addWidget( plussubDuration, 2, 3, 1, 1 );
1584 QLabel *subDurationLabel = new QLabel;
1585 subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
1586 subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
1588 subDurationSpin = new QDoubleSpinBox;
1589 subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1590 subDurationSpin->setDecimals( 3 );
1591 subDurationSpin->setMinimum( 0 );
1592 subDurationSpin->setMaximum( 20 );
1593 subDurationSpin->setSingleStep( 0.2 );
1594 subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
1596 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1598 updateButton = new QToolButton;
1599 updateButton->setAutoRaise( true );
1600 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1603 /* Various Connects */
1604 CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1605 CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1606 CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1607 CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1608 CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1609 CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1610 CONNECT( moinssubDuration, clicked(), subDurationSpin, stepDown () );
1611 CONNECT( plussubDuration, clicked(), subDurationSpin, stepUp () );
1612 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1613 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1614 CONNECT( subSpeedSpin, valueChanged ( double ),
1615 this, adjustSubsSpeed( double ) );
1616 CONNECT( subDurationSpin, valueChanged ( double ),
1617 this, adjustSubsDuration( double ) );
1619 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1620 BUTTON_SET_ACT_I( updateButton, "", update,
1621 qtr( "Force update of this dialog's values" ), update() );
1629 SyncControls::~SyncControls()
1634 void SyncControls::clean()
1636 b_userAction = false;
1637 AVSpin->setValue( 0.0 );
1638 subsSpin->setValue( 0.0 );
1639 subSpeedSpin->setValue( 1.0 );
1641 b_userAction = true;
1644 void SyncControls::update()
1646 b_userAction = false;
1649 if( THEMIM->getInput() )
1651 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1652 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1653 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1654 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1655 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1656 subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
1658 b_userAction = true;
1661 void SyncControls::advanceAudio( double f_advance )
1663 if( THEMIM->getInput() && b_userAction )
1665 int64_t i_delay = f_advance * 1000000;
1666 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1670 void SyncControls::advanceSubs( double f_advance )
1672 if( THEMIM->getInput() && b_userAction )
1674 int64_t i_delay = f_advance * 1000000;
1675 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1679 void SyncControls::adjustSubsSpeed( double f_fps )
1681 if( THEMIM->getInput() && b_userAction )
1683 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1687 void SyncControls::adjustSubsDuration( double f_factor )
1689 if( THEMIM->getInput() && b_userAction )
1691 subsdelaySetFactor( f_factor );
1692 ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
1696 void SyncControls::initSubsDuration()
1698 int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
1703 case SUBSDELAY_MODE_ABSOLUTE:
1704 subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
1705 "Set 0 to disable." ) );
1706 subDurationSpin->setSuffix( " s" );
1708 case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
1709 subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
1710 "Set 0 to disable." ) );
1711 subDurationSpin->setSuffix( "" );
1713 case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
1714 subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
1715 "to their content and this value.\n"
1716 "Set 0 to disable." ) );
1717 subDurationSpin->setSuffix( "" );
1722 void SyncControls::subsdelayClean()
1724 /* Remove subsdelay filter */
1725 ChangeVFiltersString( p_intf, "subsdelay", false );
1728 void SyncControls::subsdelaySetFactor( double f_factor )
1730 /* Set the factor in the preferences */
1731 config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
1733 /* Try to find an instance of subsdelay, and set its factor */
1734 vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
1737 var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
1738 vlc_object_release( p_obj );
1743 /**********************************************************************
1744 * Video filters / Adjust
1745 **********************************************************************/
1747 /**********************************************************************
1748 * Extended playbak controls
1749 **********************************************************************/