1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006-2012 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea .t videolan d@t org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #define __STDC_FORMAT_MACROS 1
36 #include <QGridLayout>
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>
53 #include <vlc_plugin.h>
55 #include <vlc_charset.h> /* us_strtod */
57 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
60 class ConfClickHandler : public QObject
63 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
64 e = _e; p_intf = _p_intf;
66 virtual ~ConfClickHandler() {}
67 bool eventFilter( QObject *obj, QEvent *evt )
69 if( evt->type() == QEvent::MouseButtonPress )
78 intf_thread_t *p_intf;
82 const QString ModuleFromWidgetName( QObject *obj )
84 return obj->objectName().replace( "Enable","" );
87 QString OptionFromWidgetName( QObject *obj )
90 QString option = obj->objectName().replace( "Slider", "" )
91 .replace( "Combo" , "" )
92 .replace( "Dial" , "" )
93 .replace( "Check" , "" )
94 .replace( "Spin" , "" )
95 .replace( "Text" , "" );
96 for( char a = 'A'; a <= 'Z'; a++ )
98 option = option.replace( QString( a ),
99 QString( '-' ) + QString( a + 'a' - 'A' ) );
104 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
105 QObject( _parent ), p_intf( _p_intf )
107 ui.setupUi( _parent );
109 #define SETUP_VFILTER( widget ) \
111 vlc_object_t *p_obj = ( vlc_object_t * ) \
112 vlc_object_find_name( p_intf->p_libvlc, \
114 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
115 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
118 vlc_object_release( p_obj ); \
119 if( checkbox ) checkbox->setChecked( true ); \
120 else if (groupbox) groupbox->setChecked( true ); \
124 if( checkbox ) checkbox->setChecked( false ); \
125 else if (groupbox) groupbox->setChecked( false ); \
128 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
131 #define SETUP_VFILTER_OPTION( widget, signal ) \
132 initComboBoxItems( ui.widget ); \
133 setWidgetValue( ui.widget ); \
134 CONNECT( ui.widget, signal, this, updateFilterOptions() );
136 SETUP_VFILTER( adjust )
137 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
138 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
139 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
140 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
141 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
142 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
144 SETUP_VFILTER( extract )
145 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
147 SETUP_VFILTER( posterize )
149 SETUP_VFILTER( colorthres )
150 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
151 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
152 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
154 SETUP_VFILTER( sepia )
155 SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )
157 SETUP_VFILTER( invert )
159 SETUP_VFILTER( gradient )
160 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
161 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
162 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
164 SETUP_VFILTER( motionblur )
165 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
167 SETUP_VFILTER( motiondetect )
169 SETUP_VFILTER( psychedelic )
171 SETUP_VFILTER( sharpen )
172 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
174 SETUP_VFILTER( ripple )
176 SETUP_VFILTER( wave )
178 SETUP_VFILTER( transform )
179 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
181 SETUP_VFILTER( rotate )
182 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
183 ui.rotateAngleDial->setWrapping( true );
184 ui.rotateAngleDial->setNotchesVisible( true );
186 SETUP_VFILTER( puzzle )
187 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
188 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
189 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
191 SETUP_VFILTER( magnify )
193 SETUP_VFILTER( clone )
194 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
196 SETUP_VFILTER( wall )
197 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
198 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
201 SETUP_VFILTER( erase )
202 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
203 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
204 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
205 BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
207 SETUP_VFILTER( marq )
208 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
209 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
211 SETUP_VFILTER( logo )
212 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
213 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
214 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
215 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
216 BUTTONACT( ui.logoBrowseBtn, browseLogo() );
218 SETUP_VFILTER( gradfun )
219 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
221 SETUP_VFILTER( grain )
222 SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
224 SETUP_VFILTER( mirror )
226 SETUP_VFILTER( gaussianblur )
227 SETUP_VFILTER_OPTION( gaussianbluSigmaSlider, valueChanged( int ) )
229 SETUP_VFILTER( antiflicker )
230 SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )
233 if( module_exists( "atmo" ) )
235 SETUP_VFILTER( atmo )
236 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
237 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
238 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
239 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
240 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
241 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
242 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
243 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
247 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
251 #undef SETUP_VFILTER_OPTION
253 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
254 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
255 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
256 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
257 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
258 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
259 CONNECT( ui.topBotCropSync, toggled( bool ),
260 ui.cropBotPx, setDisabled( bool ) );
261 CONNECT( ui.leftRightCropSync, toggled( bool ),
262 ui.cropRightPx, setDisabled( bool ) );
265 void ExtVideo::cropChange()
267 if( ui.topBotCropSync->isChecked() )
268 ui.cropBotPx->setValue( ui.cropTopPx->value() );
269 if( ui.leftRightCropSync->isChecked() )
270 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
272 vout_thread_t *p_vout = THEMIM->getVout();
275 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
276 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
277 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
278 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
279 vlc_object_release( p_vout );
283 void ExtVideo::clean()
285 ui.cropTopPx->setValue( 0 );
286 ui.cropBotPx->setValue( 0 );
287 ui.cropLeftPx->setValue( 0 );
288 ui.cropRightPx->setValue( 0 );
291 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
293 char *psz_parser, *psz_string;
294 const char *psz_filter_type;
296 module_t *p_obj = module_find( psz_name );
299 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
303 if( module_provides( p_obj, "video splitter" ) )
305 psz_filter_type = "video-splitter";
307 else if( module_provides( p_obj, "video filter2" ) )
309 psz_filter_type = "video-filter";
311 else if( module_provides( p_obj, "sub source" ) )
313 psz_filter_type = "sub-source";
315 else if( module_provides( p_obj, "sub filter" ) )
317 psz_filter_type = "sub-filter";
321 msg_Err( p_intf, "Unknown video filter type." );
325 psz_string = config_GetPsz( p_intf, psz_filter_type );
327 if( !psz_string ) psz_string = strdup( "" );
329 psz_parser = strstr( psz_string, psz_name );
335 psz_parser = psz_string;
336 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
337 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 #define UPDATE_AND_APPLY_TEXT( widget, file ) \
412 CONNECT( ui.widget, textChanged( const QString& ), \
413 this, updateFilterOptions() ); \
414 ui.widget->setText( toNativeSeparators( file ) ); \
415 ui.widget->disconnect( SIGNAL( textChanged( const QString& ) ) );
417 void ExtVideo::browseLogo()
419 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
420 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
422 UPDATE_AND_APPLY_TEXT( logoFileText, file );
425 void ExtVideo::browseEraseFile()
427 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
428 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
430 UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
433 #undef UPDATE_AND_APPLY_TEXT
435 void ExtVideo::initComboBoxItems( QObject *widget )
437 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
438 if( !combobox ) return;
440 QString option = OptionFromWidgetName( widget );
441 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
445 int i_type = p_item->i_type;
446 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
448 if( i_type == CONFIG_ITEM_INTEGER
449 || i_type == CONFIG_ITEM_BOOL )
450 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
451 p_item->pi_list[i_index] );
452 else if( i_type == CONFIG_ITEM_STRING )
453 combobox->addItem( qtr( p_item->ppsz_list_text[i_index] ),
454 p_item->ppsz_list[i_index] );
459 msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
463 void ExtVideo::setWidgetValue( QObject *widget )
465 QString module = ModuleFromWidgetName( widget->parent() );
466 //std::cout << "Module name: " << module.toStdString() << std::endl;
467 QString option = OptionFromWidgetName( widget );
468 //std::cout << "Option name: " << option.toStdString() << std::endl;
470 vlc_object_t *p_obj = ( vlc_object_t * )
471 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
479 "Module instance %s not found, looking in config values.",
482 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
485 case VLC_VAR_INTEGER:
487 val.i_int = config_GetInt( p_intf, qtu( option ) );
490 val.f_float = config_GetFloat( p_intf, qtu( option ) );
493 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
499 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
500 var_Get( p_obj, qtu( option ), &val );
501 vlc_object_release( p_obj );
504 /* Try to cast to all the widgets we're likely to encounter. Only
505 * one of the casts is expected to work. */
506 QSlider *slider = qobject_cast<QSlider*> ( widget );
507 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
508 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
509 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
510 QDial *dial = qobject_cast<QDial*> ( widget );
511 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
512 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
514 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
516 if( slider ) slider->setValue( val.i_int );
517 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
519 else if( spinbox ) spinbox->setValue( val.i_int );
520 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
524 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
525 lineedit->setText( str );
527 else if( combobox ) combobox->setCurrentIndex(
528 combobox->findData( qlonglong(val.i_int) ) );
529 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
531 else if( i_type == VLC_VAR_FLOAT )
533 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
534 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
535 else msg_Warn( p_intf, "Could not find the correct Float widget" );
537 else if( i_type == VLC_VAR_STRING )
539 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
540 else if( combobox ) combobox->setCurrentIndex(
541 combobox->findData( qfu( val.psz_string ) ) );
542 else msg_Warn( p_intf, "Could not find the correct String widget" );
543 free( val.psz_string );
548 "Module %s's %s variable is of an unsupported type ( %d )",
554 void ExtVideo::updateFilterOptions()
556 QString module = ModuleFromWidgetName( sender()->parent() );
557 //std::cout << "Module name: " << module.toStdString() << std::endl;
558 QString option = OptionFromWidgetName( sender() );
559 //std::cout << "Option name: " << option.toStdString() << std::endl;
561 vlc_object_t *p_obj = ( vlc_object_t * )
562 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
567 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
568 i_type = config_GetType( p_intf, qtu( option ) );
569 b_is_command = false;
573 i_type = var_Type( p_obj, qtu( option ) );
575 i_type = config_GetType( p_intf, qtu( option ) );
576 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
579 /* Try to cast to all the widgets we're likely to encounter. Only
580 * one of the casts is expected to work. */
581 QSlider *slider = qobject_cast<QSlider*> ( sender() );
582 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
583 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
584 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
585 QDial *dial = qobject_cast<QDial*> ( sender() );
586 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
587 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
589 i_type &= VLC_VAR_CLASS;
590 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
593 if( slider ) i_int = slider->value();
594 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
595 else if( spinbox ) i_int = spinbox->value();
596 else if( dial ) i_int = ( 540-dial->value() )%360;
597 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
598 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
599 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
600 config_PutInt( p_intf, qtu( option ), i_int );
603 if( i_type == VLC_VAR_INTEGER )
604 var_SetInteger( p_obj, qtu( option ), i_int );
606 var_SetBool( p_obj, qtu( option ), i_int );
609 else if( i_type == VLC_VAR_FLOAT )
612 if( slider ) f_float = ( double )slider->value()
613 / ( double )slider->tickInterval(); /* hack alert! */
614 else if( doublespinbox ) f_float = doublespinbox->value();
615 else if( lineedit ) f_float = lineedit->text().toDouble();
616 else msg_Warn( p_intf, "Could not find the correct Float widget" );
617 config_PutFloat( p_intf, qtu( option ), f_float );
619 var_SetFloat( p_obj, qtu( option ), f_float );
621 else if( i_type == VLC_VAR_STRING )
625 val = lineedit->text();
627 val = combobox->itemData( combobox->currentIndex() ).toString();
629 msg_Warn( p_intf, "Could not find the correct String widget" );
630 config_PutPsz( p_intf, qtu( option ), qtu( val ) );
632 var_SetString( p_obj, qtu( option ), qtu( val ) );
636 "Module %s's %s variable is of an unsupported type ( %d )",
643 msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
646 ChangeVFiltersString( p_intf, qtu( module ), false );
647 ChangeVFiltersString( p_intf, qtu( module ), true );
650 if( p_obj ) vlc_object_release( p_obj );
654 void ExtVideo::gotoConf( QObject* src )
656 #define SHOWCONF( module ) \
657 if( src->objectName().contains( module ) ) \
659 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
663 SHOWCONF( "magnify" );
665 SHOWCONF( "ripple" );
666 SHOWCONF( "invert" );
667 SHOWCONF( "puzzle" );
669 SHOWCONF( "gradient" );
670 SHOWCONF( "colorthres" )
674 /**********************************************************************
676 **********************************************************************/
678 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
679 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
681 QVBoxLayout *layout = new QVBoxLayout( this );
682 help = new QLabel( qtr("No v4l2 instance found.\n"
683 "Please check that the device has been opened with VLC and is playing.\n\n"
684 "Controls will automatically appear here.")
686 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
687 layout->addWidget( help );
691 void ExtV4l2::showEvent( QShowEvent *event )
693 QWidget::showEvent( event );
697 void ExtV4l2::Refresh( void )
699 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
703 layout()->removeWidget( box );
709 vlc_value_t val, text;
710 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
714 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
716 vlc_object_release( p_obj );
720 box = new QGroupBox( this );
721 layout()->addWidget( box );
722 QVBoxLayout *layout = new QVBoxLayout( box );
723 box->setLayout( layout );
725 for( int i = 0; i < val.p_list->i_count; i++ )
728 const char *psz_var = text.p_list->p_values[i].psz_string;
730 if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
733 QString name = qtr( vartext.psz_string );
734 free( vartext.psz_string );
735 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
736 val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
738 int i_type = var_Type( p_obj, psz_var );
739 switch( i_type & VLC_VAR_TYPE )
741 case VLC_VAR_INTEGER:
743 QLabel *label = new QLabel( name, box );
744 QHBoxLayout *hlayout = new QHBoxLayout();
745 hlayout->addWidget( label );
746 int i_val = var_GetInteger( p_obj, psz_var );
747 if( i_type & VLC_VAR_HASCHOICE )
749 QComboBox *combobox = new QComboBox( box );
750 combobox->setObjectName( qfu( psz_var ) );
752 vlc_value_t val2, text2;
753 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
755 for( int j = 0; j < val2.p_list->i_count; j++ )
758 text2.p_list->p_values[j].psz_string,
759 qlonglong( val2.p_list->p_values[j].i_int) );
760 if( i_val == val2.p_list->p_values[j].i_int )
761 combobox->setCurrentIndex( j );
763 var_FreeList( &val2, &text2 );
765 CONNECT( combobox, currentIndexChanged( int ), this,
766 ValueChange( int ) );
767 hlayout->addWidget( combobox );
770 if( (i_type & VLC_VAR_HASMIN) && (i_type & VLC_VAR_HASMAX) )
772 QSlider *slider = new QSlider( box );
773 slider->setObjectName( qfu( psz_var ) );
774 slider->setOrientation( Qt::Horizontal );
776 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
778 if( val2.i_int < INT_MIN )
779 val2.i_int = INT_MIN; /* FIXME */
780 slider->setMinimum( val2.i_int );
781 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
783 if( val2.i_int > INT_MAX )
784 val2.i_int = INT_MAX; /* FIXME */
785 slider->setMaximum( val2.i_int );
786 if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
788 slider->setSingleStep( val2.i_int );
789 slider->setValue( i_val );
790 CONNECT( slider, valueChanged( int ), this,
791 ValueChange( int ) );
792 hlayout->addWidget( slider );
796 QSpinBox *spinBox = new QSpinBox( box );
797 spinBox->setObjectName( qfu( psz_var ) );
798 spinBox->setMinimum( INT_MIN );
799 spinBox->setMaximum( INT_MAX );
800 spinBox->setValue( i_val );
801 CONNECT( spinBox, valueChanged( int ), this,
802 ValueChange( int ) );
803 hlayout->addWidget( spinBox );
805 layout->addLayout( hlayout );
810 QCheckBox *button = new QCheckBox( name, box );
811 button->setObjectName( qfu( psz_var ) );
812 button->setChecked( var_GetBool( p_obj, psz_var ) );
814 CONNECT( button, clicked( bool ), this,
815 ValueChange( bool ) );
816 layout->addWidget( button );
821 if( i_type & VLC_VAR_ISCOMMAND )
823 QPushButton *button = new QPushButton( name, box );
824 button->setObjectName( qfu( psz_var ) );
826 CONNECT( button, clicked( bool ), this,
827 ValueChange( bool ) );
828 layout->addWidget( button );
832 QLabel *label = new QLabel( name, box );
833 layout->addWidget( label );
838 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
842 var_FreeList( &val, &text );
843 vlc_object_release( p_obj );
847 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
850 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
854 void ExtV4l2::ValueChange( bool value )
856 ValueChange( (int)value );
859 void ExtV4l2::ValueChange( int value )
861 QObject *s = sender();
862 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
865 QString var = s->objectName();
866 int i_type = var_Type( p_obj, qtu( var ) );
867 switch( i_type & VLC_VAR_TYPE )
869 case VLC_VAR_INTEGER:
870 if( i_type & VLC_VAR_HASCHOICE )
872 QComboBox *combobox = qobject_cast<QComboBox*>( s );
873 value = combobox->itemData( value ).toInt();
875 var_SetInteger( p_obj, qtu( var ), value );
878 var_SetBool( p_obj, qtu( var ), value );
881 var_TriggerCallback( p_obj, qtu( var ) );
884 vlc_object_release( p_obj );
888 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
893 /**********************************************************************
895 **********************************************************************/
897 static const QString vlc_band_frequencies[] =
899 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
900 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
903 static const QString iso_band_frequencies[] =
905 " 31.25 Hz ", " 62.5 Hz ", " 125 Hz ", " 250 Hz ", " 500 Hz ",
906 " 1 kHz ", " 2 kHz ", " 4 kHz ", " 8 kHz ", " 16 kHz "
909 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
910 QWidget( _parent ) , p_intf( _p_intf )
912 QFont smallFont = QApplication::font();
913 smallFont.setPointSize( smallFont.pointSize() - 3 );
916 ui.preampLabel->setFont( smallFont );
918 /* Setup of presetsComboBox */
919 presetsComboBox = ui.presetsCombo;
920 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
922 b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
924 /* Add the sliders for the Bands */
925 QGridLayout *grid = new QGridLayout( ui.frame );
926 grid->setMargin( 0 );
927 for( int i = 0 ; i < BANDS ; i++ )
929 bands[i] = new QSlider( Qt::Vertical );
930 bands[i]->setMaximum( 400 );
931 bands[i]->setValue( 200 );
932 bands[i]->setMinimumWidth(40);
933 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
935 band_texts[i] = new QLabel( (b_vlcBands ? vlc_band_frequencies[i]
936 : iso_band_frequencies[i]) + "\n0.0dB" );
937 band_texts[i]->setFont( smallFont );
938 band_texts[i]->setAlignment( Qt::AlignRight );
939 bands[i]->setMinimumWidth(40);
941 grid->addWidget( bands[i], 0, i );
942 grid->addWidget( band_texts[i], 1, i );
945 /* Add the listed presets */
946 for( int i = 0 ; i < NB_PRESETS ; i ++ )
948 presetsComboBox->addItem( qtr( preset_list_text[i] ),
949 QVariant( preset_list[i] ) );
953 BUTTONACT( ui.enableCheck, enable() );
954 BUTTONACT( ui.eq2PassCheck, set2Pass() );
955 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
957 /* Do the update from the value of the core */
961 /* Write down initial values */
962 void Equalizer::updateUIFromCore()
964 char *psz_af, *psz_pres, *psz_bands;
968 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
971 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
972 psz_pres = var_GetString( p_aout, "equalizer-preset" );
973 if( var_GetBool( p_aout, "equalizer-2pass" ) )
974 ui.eq2PassCheck->setChecked( true );
975 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
976 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
977 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
978 vlc_object_release( p_aout );
982 psz_af = config_GetPsz( p_intf, "audio-filter" );
983 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
984 if( config_GetInt( p_intf, "equalizer-2pass" ) )
985 ui.eq2PassCheck->setChecked( true );
986 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
987 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
988 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
990 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
991 ui.enableCheck->setChecked( true );
992 enable( ui.enableCheck->isChecked() );
994 presetsComboBox->setCurrentIndex( i_preset );
996 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
998 if( psz_bands && strlen( psz_bands ) > 1 )
1000 char *psz_bands_orig = psz_bands;
1001 for( int i = 0; i < BANDS; i++ )
1003 const float f = us_strtod(psz_bands, &psz_bands );
1004 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1005 if( psz_bands == NULL || *psz_bands == '\0' ) break;
1007 if( *psz_bands == '\0' ) break;
1009 free( psz_bands_orig );
1011 else free( psz_bands );
1017 void Equalizer::changeFreqLabels( bool b_useVlcBands )
1019 b_vlcBands = b_useVlcBands;
1021 const QString *band_frequencies = b_vlcBands
1022 ? vlc_band_frequencies
1023 : iso_band_frequencies;
1025 for( int i = 0; i < BANDS; i++ )
1027 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1028 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1029 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1033 /* Function called when enableButton is toggled */
1034 void Equalizer::enable()
1036 bool en = ui.enableCheck->isChecked();
1037 aout_EnableFilter( THEPL, "equalizer", en );
1038 // aout_EnableFilter( THEPL, "upmixer", en );
1039 // aout_EnableFilter( THEPL, "vsurround", en );
1042 if( presetsComboBox->currentIndex() < 0 )
1043 presetsComboBox->setCurrentIndex( 0 );
1047 void Equalizer::enable( bool en )
1049 ui.eq2PassCheck->setEnabled( en );
1050 presetsComboBox->setEnabled( en );
1051 ui.presetLabel->setEnabled( en );
1052 ui.preampLabel->setEnabled( en );
1053 ui.preampSlider->setEnabled( en );
1054 for( int i = 0 ; i< BANDS; i++ )
1056 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
1060 /* Function called when the set2Pass button is activated */
1061 void Equalizer::set2Pass()
1063 vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
1064 bool b_2p = ui.eq2PassCheck->isChecked();
1068 var_SetBool( p_aout, "equalizer-2pass", b_2p );
1069 vlc_object_release( p_aout );
1071 config_PutInt( p_intf, "equalizer-2pass", b_2p );
1074 /* Function called when the preamp slider is moved */
1075 void Equalizer::setPreamp()
1077 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
1078 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1080 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
1084 //delCallbacks( p_aout );
1085 var_SetFloat( p_aout, "equalizer-preamp", f );
1086 //addCallbacks( p_aout );
1087 vlc_object_release( p_aout );
1089 config_PutFloat( p_intf, "equalizer-preamp", f );
1092 void Equalizer::setCoreBands()
1094 /**\todo smoothing */
1096 const QString *band_frequencies = b_vlcBands
1097 ? vlc_band_frequencies
1098 : iso_band_frequencies;
1101 for( int i = 0; i < BANDS; i++ )
1103 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1104 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1106 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1107 values += " " + val;
1110 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1113 //delCallbacks( p_aout );
1114 var_SetString( p_aout, "equalizer-bands", qtu( values ) );
1115 //addCallbacks( p_aout );
1116 vlc_object_release( p_aout );
1120 char * Equalizer::createValuesFromPreset( int i_preset )
1124 /* Create the QString in Qt */
1125 for( int i = 0 ; i< BANDS ;i++ )
1126 values += QString( " %1" ).arg( eqz_preset_10b[i_preset].f_amp[i], 5, 'f', 1 );
1128 /* Convert it to char * */
1129 return strdup( values.toAscii().constData() );
1132 void Equalizer::setCorePreset( int i_preset )
1137 /* Update pre-amplification in the UI */
1138 float f_preamp = eqz_preset_10b[i_preset].f_preamp;
1139 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1140 ui.preampLabel->setText( qtr( "Preamp\n" )
1141 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1143 char *psz_values = createValuesFromPreset( i_preset );
1144 if( !psz_values ) return ;
1146 const QString *band_frequencies = b_vlcBands
1147 ? vlc_band_frequencies
1148 : iso_band_frequencies;
1150 char *p = psz_values;
1151 for( int i = 0; i < BANDS && *p; i++ )
1153 const float f = us_strtod( p, &p );
1155 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1156 band_texts[i]->setText( band_frequencies[i] + "\n"
1157 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1159 p++; /* skip separator */
1162 /* Apply presets to audio output */
1163 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1166 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1168 var_SetString( p_aout, "equalizer-bands", psz_values );
1169 var_SetFloat( p_aout, "equalizer-preamp",
1170 eqz_preset_10b[i_preset].f_preamp );
1171 vlc_object_release( p_aout );
1173 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1174 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1175 config_PutFloat( p_intf, "equalizer-preamp",
1176 eqz_preset_10b[i_preset].f_preamp );
1180 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1181 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1183 VLC_UNUSED( p_this ); VLC_UNUSED( psz_cmd ); VLC_UNUSED( oldval );
1185 char *psz_preset = newval.psz_string;
1186 Equalizer *eq = ( Equalizer * )p_data;
1187 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1188 eq->presetsComboBox->setCurrentIndex( i_preset );
1192 void Equalizer::delCallbacks( vlc_object_t *p_aout )
1194 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1195 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1196 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1199 void Equalizer::addCallbacks( vlc_object_t *p_aout )
1201 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1202 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1203 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1206 /**********************************************************************
1208 **********************************************************************/
1210 /**********************************************************************
1211 * Dynamic range compressor
1212 **********************************************************************/
1216 const char *psz_name;
1217 const char *psz_descs;
1218 const char *psz_units;
1219 const float f_min; // min
1220 const float f_max; // max
1221 const float f_value; // value
1222 const float f_resolution; // resolution
1225 static const comp_controls_t comp_controls[] =
1227 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1228 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1229 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1230 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1231 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1232 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1233 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1236 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1237 : QWidget( _parent ) , p_intf( _p_intf )
1239 QFont smallFont = QApplication::font();
1240 smallFont.setPointSize( smallFont.pointSize() - 2 );
1242 QGridLayout *layout = new QGridLayout( this );
1244 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1245 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1247 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1249 const int i_min = (int)( comp_controls[i].f_min
1250 / comp_controls[i].f_resolution );
1251 const int i_max = (int)( comp_controls[i].f_max
1252 / comp_controls[i].f_resolution );
1253 const int i_val = (int)( comp_controls[i].f_value
1254 / comp_controls[i].f_resolution );
1256 compCtrl[i] = new QSlider( Qt::Vertical );
1257 compCtrl[i]->setMinimum( i_min );
1258 compCtrl[i]->setMaximum( i_max );
1259 compCtrl[i]->setValue( i_val );
1261 oldControlVars[i] = comp_controls[i].f_value;
1263 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1265 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1266 ctrl_texts[i]->setFont( smallFont );
1267 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1269 ctrl_readout[i] = new QLabel;
1270 ctrl_readout[i]->setFont( smallFont );
1271 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1273 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1274 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1275 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1278 BUTTONACT( enableCheck, enable() );
1280 /* Write down initial values */
1281 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1286 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1287 for( int i = 0; i < NUM_CP_CTRL; i++ )
1289 controlVars[i] = var_GetFloat( p_aout,
1290 comp_controls[i].psz_name );
1292 vlc_object_release( p_aout );
1296 psz_af = config_GetPsz( p_intf, "audio-filter" );
1297 for( int i = 0; i < NUM_CP_CTRL; i++ )
1299 controlVars[i] = config_GetFloat( p_intf,
1300 comp_controls[i].psz_name );
1303 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1305 enableCheck->setChecked( true );
1308 enable( enableCheck->isChecked() );
1309 updateSliders( controlVars );
1313 void Compressor::enable()
1315 bool en = enableCheck->isChecked();
1316 aout_EnableFilter( THEPL, "compressor", en );
1320 void Compressor::enable( bool en )
1322 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1324 compCtrl[i]->setEnabled( en );
1325 ctrl_texts[i]->setEnabled( en );
1326 ctrl_readout[i]->setEnabled( en );
1330 void Compressor::updateSliders( float * p_controlVars )
1332 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1334 if( oldControlVars[i] != p_controlVars[i] )
1336 compCtrl[i]->setValue(
1337 (int)( p_controlVars[i] / comp_controls[i].f_resolution ) );
1342 void Compressor::setInitValues()
1347 void Compressor::setValues()
1349 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1351 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1353 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1354 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1355 + qtr( comp_controls[i].psz_units ) );
1356 if( oldControlVars[i] != f )
1360 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1362 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1363 oldControlVars[i] = f;
1368 vlc_object_release( p_aout );
1372 /**********************************************************************
1374 **********************************************************************/
1377 const char *psz_name;
1378 const char *psz_desc;
1381 static const spat_controls_t spat_controls[] =
1383 { "spatializer-roomsize", _("Size") },
1384 { "spatializer-width", _("Width") },
1385 { "spatializer-wet", _("Wet") },
1386 { "spatializer-dry", _("Dry") },
1387 { "spatializer-damp", _("Damp") },
1390 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1391 : QWidget( _parent ) , p_intf( _p_intf )
1393 QFont smallFont = QApplication::font();
1394 smallFont.setPointSize( smallFont.pointSize() - 1 );
1396 QGridLayout *layout = new QGridLayout( this );
1398 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1399 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1401 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1403 spatCtrl[i] = new QSlider( Qt::Vertical );
1404 spatCtrl[i]->setValue( (int)var_InheritFloat( p_intf, spat_controls[i].psz_name ) * 10. );
1405 oldControlVars[i] = spatCtrl[i]->value();
1407 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1409 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1410 ctrl_texts[i]->setFont( smallFont );
1412 ctrl_readout[i] = new QLabel;
1413 ctrl_readout[i]->setFont( smallFont );
1415 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1416 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1417 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1418 spatCtrl[i]->setRange( 0, 10 );
1420 spatCtrl[0]->setRange( 0, 11 );
1422 BUTTONACT( enableCheck, enable() );
1424 /* Write down initial values */
1425 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1430 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1431 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1433 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1435 vlc_object_release( p_aout );
1439 psz_af = config_GetPsz( p_intf, "audio-filter" );
1440 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1442 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1445 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1446 enableCheck->setChecked( true );
1448 enable( enableCheck->isChecked() );
1452 void Spatializer::enable()
1454 bool en = enableCheck->isChecked();
1455 aout_EnableFilter( THEPL, "spatializer", en );
1459 void Spatializer::enable( bool en )
1461 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1463 spatCtrl[i]->setEnabled( en );
1464 ctrl_texts[i]->setEnabled( en );
1465 ctrl_readout[i]->setEnabled( en );
1468 void Spatializer::setInitValues()
1473 void Spatializer::setValues()
1475 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1477 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1479 float f = (float)( spatCtrl[i]->value() ) / 10;
1480 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1485 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1487 float f = (float)( spatCtrl[i]->value() ) / 10 ;
1488 if( oldControlVars[i] != spatCtrl[i]->value() )
1490 var_SetFloat( p_aout, spat_controls[i].psz_name, f );
1491 config_PutFloat( p_intf, spat_controls[i].psz_name, f );
1492 oldControlVars[i] = spatCtrl[i]->value();
1495 vlc_object_release( p_aout );
1499 void Spatializer::delCallbacks( vlc_object_t *p_aout )
1501 VLC_UNUSED( p_aout );
1502 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1503 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1506 void Spatializer::addCallbacks( vlc_object_t *p_aout )
1508 VLC_UNUSED( p_aout );
1509 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1510 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1513 #include <QToolButton>
1514 #include <QGridLayout>
1516 #define SUBSDELAY_CFG_MODE "subsdelay-mode"
1517 #define SUBSDELAY_CFG_FACTOR "subsdelay-factor"
1518 #define SUBSDELAY_MODE_ABSOLUTE 0
1519 #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY 1
1520 #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
1522 SyncWidget::SyncWidget( QWidget *_parent ) : QWidget( _parent )
1524 QHBoxLayout *layout = new QHBoxLayout;
1525 spinBox.setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1526 spinBox.setDecimals( 3 );
1527 spinBox.setMinimum( -600.0 );
1528 spinBox.setMaximum( 600.0 );
1529 spinBox.setSingleStep( 0.1 );
1530 spinBox.setSuffix( " s" );
1531 spinBox.setButtonSymbols( QDoubleSpinBox::PlusMinus );
1532 CONNECT( &spinBox, valueChanged( double ), this, valueChangedHandler( double ) );
1533 layout->addWidget( &spinBox );
1534 layout->addWidget( &spinLabel );
1535 layout->setContentsMargins( 0, 0, 0, 0 );
1536 setLayout( layout );
1539 void SyncWidget::valueChangedHandler( double d )
1542 spinLabel.setText( qtr("(Hastened)") );
1544 spinLabel.setText( qtr("(Delayed)") );
1546 spinLabel.setText( "" );
1547 emit valueChanged( d );
1550 void SyncWidget::setValue( double d )
1552 spinBox.setValue( d );
1555 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1556 QWidget( _parent ) , p_intf( _p_intf )
1558 QGroupBox *AVBox, *subsBox;
1559 QToolButton *updateButton;
1561 b_userAction = true;
1563 QGridLayout *mainLayout = new QGridLayout( this );
1566 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1567 QGridLayout *AVLayout = new QGridLayout( AVBox );
1569 QLabel *AVLabel = new QLabel;
1570 AVLabel->setText( qtr( "Audio track synchronization:" ) );
1571 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1573 AVSpin = new SyncWidget( this );
1574 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1575 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1578 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1579 QGridLayout *subsLayout = new QGridLayout( subsBox );
1581 QLabel *subsLabel = new QLabel;
1582 subsLabel->setText( qtr( "Subtitle track syncronization:" ) );
1583 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1585 subsSpin = new SyncWidget( this );
1586 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1588 QLabel *subSpeedLabel = new QLabel;
1589 subSpeedLabel->setText( qtr( "Subtitles speed:" ) );
1590 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1592 subSpeedSpin = new QDoubleSpinBox;
1593 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1594 subSpeedSpin->setDecimals( 3 );
1595 subSpeedSpin->setMinimum( 1 );
1596 subSpeedSpin->setMaximum( 100 );
1597 subSpeedSpin->setSingleStep( 0.2 );
1598 subSpeedSpin->setSuffix( " fps" );
1599 subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1600 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1602 QLabel *subDurationLabel = new QLabel;
1603 subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
1604 subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
1606 subDurationSpin = new QDoubleSpinBox;
1607 subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1608 subDurationSpin->setDecimals( 3 );
1609 subDurationSpin->setMinimum( 0 );
1610 subDurationSpin->setMaximum( 20 );
1611 subDurationSpin->setSingleStep( 0.2 );
1612 subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1613 subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
1615 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1617 updateButton = new QToolButton;
1618 updateButton->setAutoRaise( true );
1619 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1621 /* Various Connects */
1622 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1623 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1624 CONNECT( subSpeedSpin, valueChanged ( double ),
1625 this, adjustSubsSpeed( double ) );
1626 CONNECT( subDurationSpin, valueChanged ( double ),
1627 this, adjustSubsDuration( double ) );
1629 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1630 BUTTON_SET_ACT_I( updateButton, "", update,
1631 qtr( "Force update of this dialog's values" ), update() );
1639 SyncControls::~SyncControls()
1644 void SyncControls::clean()
1646 b_userAction = false;
1647 AVSpin->setValue( 0.0 );
1648 subsSpin->setValue( 0.0 );
1649 subSpeedSpin->setValue( 1.0 );
1651 b_userAction = true;
1654 void SyncControls::update()
1656 b_userAction = false;
1659 if( THEMIM->getInput() )
1661 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1662 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1663 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1664 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1665 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1666 subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
1668 b_userAction = true;
1671 void SyncControls::advanceAudio( double f_advance )
1673 if( THEMIM->getInput() && b_userAction )
1675 int64_t i_delay = f_advance * 1000000;
1676 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1680 void SyncControls::advanceSubs( double f_advance )
1682 if( THEMIM->getInput() && b_userAction )
1684 int64_t i_delay = f_advance * 1000000;
1685 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1689 void SyncControls::adjustSubsSpeed( double f_fps )
1691 if( THEMIM->getInput() && b_userAction )
1693 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1697 void SyncControls::adjustSubsDuration( double f_factor )
1699 if( THEMIM->getInput() && b_userAction )
1701 subsdelaySetFactor( f_factor );
1702 ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
1706 void SyncControls::initSubsDuration()
1708 int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
1713 case SUBSDELAY_MODE_ABSOLUTE:
1714 subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
1715 "Set 0 to disable." ) );
1716 subDurationSpin->setSuffix( " s" );
1718 case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
1719 subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
1720 "Set 0 to disable." ) );
1721 subDurationSpin->setSuffix( "" );
1723 case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
1724 subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
1725 "to their content and this value.\n"
1726 "Set 0 to disable." ) );
1727 subDurationSpin->setSuffix( "" );
1732 void SyncControls::subsdelayClean()
1734 /* Remove subsdelay filter */
1735 ChangeVFiltersString( p_intf, "subsdelay", false );
1738 void SyncControls::subsdelaySetFactor( double f_factor )
1740 /* Set the factor in the preferences */
1741 config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
1743 /* Try to find an instance of subsdelay, and set its factor */
1744 vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
1747 var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
1748 vlc_object_release( p_obj );
1753 /**********************************************************************
1754 * Video filters / Adjust
1755 **********************************************************************/
1757 /**********************************************************************
1758 * Extended playbak controls
1759 **********************************************************************/