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 size_t i_len = strlen( psz_string );
366 if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
368 *( psz_string + i_len - 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 msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
449 if( p_item->i_type == CONFIG_ITEM_INTEGER
450 || p_item->i_type == CONFIG_ITEM_BOOL )
454 ssize_t count = config_GetIntChoices( VLC_OBJECT( p_intf ),
455 qtu( option ), &values, &texts );
456 for( ssize_t i = 0; i < count; i++ )
458 combobox->addItem( qtr( texts[i] ), qlonglong(values[i]) );
464 else if( p_item->i_type == CONFIG_ITEM_STRING )
468 ssize_t count = config_GetPszChoices( VLC_OBJECT( p_intf ),
469 qtu( option ), &values, &texts );
470 for( ssize_t i = 0; i < count; i++ )
472 combobox->addItem( qtr( texts[i] ), qfu(values[i]) );
481 void ExtVideo::setWidgetValue( QObject *widget )
483 QString module = ModuleFromWidgetName( widget->parent() );
484 //std::cout << "Module name: " << module.toStdString() << std::endl;
485 QString option = OptionFromWidgetName( widget );
486 //std::cout << "Option name: " << option.toStdString() << std::endl;
488 vlc_object_t *p_obj = ( vlc_object_t * )
489 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
497 "Module instance %s not found, looking in config values.",
500 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
503 case VLC_VAR_INTEGER:
505 val.i_int = config_GetInt( p_intf, qtu( option ) );
508 val.f_float = config_GetFloat( p_intf, qtu( option ) );
511 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
517 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
518 var_Get( p_obj, qtu( option ), &val );
519 vlc_object_release( p_obj );
522 /* Try to cast to all the widgets we're likely to encounter. Only
523 * one of the casts is expected to work. */
524 QSlider *slider = qobject_cast<QSlider*> ( widget );
525 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
526 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
527 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
528 QDial *dial = qobject_cast<QDial*> ( widget );
529 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
530 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
532 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
534 if( slider ) slider->setValue( val.i_int );
535 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
537 else if( spinbox ) spinbox->setValue( val.i_int );
538 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
542 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
543 lineedit->setText( str );
545 else if( combobox ) combobox->setCurrentIndex(
546 combobox->findData( qlonglong(val.i_int) ) );
547 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
549 else if( i_type == VLC_VAR_FLOAT )
551 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
552 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
553 else msg_Warn( p_intf, "Could not find the correct Float widget" );
555 else if( i_type == VLC_VAR_STRING )
557 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
558 else if( combobox ) combobox->setCurrentIndex(
559 combobox->findData( qfu( val.psz_string ) ) );
560 else msg_Warn( p_intf, "Could not find the correct String widget" );
561 free( val.psz_string );
566 "Module %s's %s variable is of an unsupported type ( %d )",
572 void ExtVideo::updateFilterOptions()
574 QString module = ModuleFromWidgetName( sender()->parent() );
575 //std::cout << "Module name: " << module.toStdString() << std::endl;
576 QString option = OptionFromWidgetName( sender() );
577 //std::cout << "Option name: " << option.toStdString() << std::endl;
579 vlc_object_t *p_obj = ( vlc_object_t * )
580 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
585 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
586 i_type = config_GetType( p_intf, qtu( option ) );
587 b_is_command = false;
591 i_type = var_Type( p_obj, qtu( option ) );
593 i_type = config_GetType( p_intf, qtu( option ) );
594 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
597 /* Try to cast to all the widgets we're likely to encounter. Only
598 * one of the casts is expected to work. */
599 QSlider *slider = qobject_cast<QSlider*> ( sender() );
600 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
601 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
602 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
603 QDial *dial = qobject_cast<QDial*> ( sender() );
604 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
605 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
607 i_type &= VLC_VAR_CLASS;
608 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
611 if( slider ) i_int = slider->value();
612 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
613 else if( spinbox ) i_int = spinbox->value();
614 else if( dial ) i_int = ( 540-dial->value() )%360;
615 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
616 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
617 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
618 config_PutInt( p_intf, qtu( option ), i_int );
621 if( i_type == VLC_VAR_INTEGER )
622 var_SetInteger( p_obj, qtu( option ), i_int );
624 var_SetBool( p_obj, qtu( option ), i_int );
627 else if( i_type == VLC_VAR_FLOAT )
630 if( slider ) f_float = ( double )slider->value()
631 / ( double )slider->tickInterval(); /* hack alert! */
632 else if( doublespinbox ) f_float = doublespinbox->value();
633 else if( lineedit ) f_float = lineedit->text().toDouble();
634 else msg_Warn( p_intf, "Could not find the correct Float widget" );
635 config_PutFloat( p_intf, qtu( option ), f_float );
637 var_SetFloat( p_obj, qtu( option ), f_float );
639 else if( i_type == VLC_VAR_STRING )
643 val = lineedit->text();
645 val = combobox->itemData( combobox->currentIndex() ).toString();
647 msg_Warn( p_intf, "Could not find the correct String widget" );
648 config_PutPsz( p_intf, qtu( option ), qtu( val ) );
650 var_SetString( p_obj, qtu( option ), qtu( val ) );
654 "Module %s's %s variable is of an unsupported type ( %d )",
661 msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
664 ChangeVFiltersString( p_intf, qtu( module ), false );
665 ChangeVFiltersString( p_intf, qtu( module ), true );
668 if( p_obj ) vlc_object_release( p_obj );
672 void ExtVideo::gotoConf( QObject* src )
674 #define SHOWCONF( module ) \
675 if( src->objectName().contains( module ) ) \
677 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
681 SHOWCONF( "magnify" );
683 SHOWCONF( "ripple" );
684 SHOWCONF( "invert" );
685 SHOWCONF( "puzzle" );
687 SHOWCONF( "gradient" );
688 SHOWCONF( "colorthres" )
692 /**********************************************************************
694 **********************************************************************/
696 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
697 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
699 QVBoxLayout *layout = new QVBoxLayout( this );
700 help = new QLabel( qtr("No v4l2 instance found.\n"
701 "Please check that the device has been opened with VLC and is playing.\n\n"
702 "Controls will automatically appear here.")
704 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
705 layout->addWidget( help );
709 void ExtV4l2::showEvent( QShowEvent *event )
711 QWidget::showEvent( event );
715 void ExtV4l2::Refresh( void )
717 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
721 layout()->removeWidget( box );
727 vlc_value_t val, text;
728 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
732 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
734 vlc_object_release( p_obj );
738 box = new QGroupBox( this );
739 layout()->addWidget( box );
740 QVBoxLayout *layout = new QVBoxLayout( box );
741 box->setLayout( layout );
743 for( int i = 0; i < val.p_list->i_count; i++ )
746 const char *psz_var = text.p_list->p_values[i].psz_string;
748 if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
751 QString name = qtr( vartext.psz_string );
752 free( vartext.psz_string );
753 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
754 val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
756 int i_type = var_Type( p_obj, psz_var );
757 switch( i_type & VLC_VAR_TYPE )
759 case VLC_VAR_INTEGER:
761 QLabel *label = new QLabel( name, box );
762 QHBoxLayout *hlayout = new QHBoxLayout();
763 hlayout->addWidget( label );
764 int i_val = var_GetInteger( p_obj, psz_var );
765 if( i_type & VLC_VAR_HASCHOICE )
767 QComboBox *combobox = new QComboBox( box );
768 combobox->setObjectName( qfu( psz_var ) );
770 vlc_value_t val2, text2;
771 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
773 for( int j = 0; j < val2.p_list->i_count; j++ )
776 text2.p_list->p_values[j].psz_string,
777 qlonglong( val2.p_list->p_values[j].i_int) );
778 if( i_val == val2.p_list->p_values[j].i_int )
779 combobox->setCurrentIndex( j );
781 var_FreeList( &val2, &text2 );
783 CONNECT( combobox, currentIndexChanged( int ), this,
784 ValueChange( int ) );
785 hlayout->addWidget( combobox );
788 if( (i_type & VLC_VAR_HASMIN) && (i_type & VLC_VAR_HASMAX) )
790 QSlider *slider = new QSlider( box );
791 slider->setObjectName( qfu( psz_var ) );
792 slider->setOrientation( Qt::Horizontal );
794 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
796 if( val2.i_int < INT_MIN )
797 val2.i_int = INT_MIN; /* FIXME */
798 slider->setMinimum( val2.i_int );
799 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
801 if( val2.i_int > INT_MAX )
802 val2.i_int = INT_MAX; /* FIXME */
803 slider->setMaximum( val2.i_int );
804 if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
806 slider->setSingleStep( val2.i_int );
807 slider->setValue( i_val );
808 CONNECT( slider, valueChanged( int ), this,
809 ValueChange( int ) );
810 hlayout->addWidget( slider );
814 QSpinBox *spinBox = new QSpinBox( box );
815 spinBox->setObjectName( qfu( psz_var ) );
816 spinBox->setMinimum( INT_MIN );
817 spinBox->setMaximum( INT_MAX );
818 spinBox->setValue( i_val );
819 CONNECT( spinBox, valueChanged( int ), this,
820 ValueChange( int ) );
821 hlayout->addWidget( spinBox );
823 layout->addLayout( hlayout );
828 QCheckBox *button = new QCheckBox( name, box );
829 button->setObjectName( qfu( psz_var ) );
830 button->setChecked( var_GetBool( p_obj, psz_var ) );
832 CONNECT( button, clicked( bool ), this,
833 ValueChange( bool ) );
834 layout->addWidget( button );
839 if( i_type & VLC_VAR_ISCOMMAND )
841 QPushButton *button = new QPushButton( name, box );
842 button->setObjectName( qfu( psz_var ) );
844 CONNECT( button, clicked( bool ), this,
845 ValueChange( bool ) );
846 layout->addWidget( button );
850 QLabel *label = new QLabel( name, box );
851 layout->addWidget( label );
856 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
860 var_FreeList( &val, &text );
861 vlc_object_release( p_obj );
865 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
868 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
872 void ExtV4l2::ValueChange( bool value )
874 ValueChange( (int)value );
877 void ExtV4l2::ValueChange( int value )
879 QObject *s = sender();
880 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
883 QString var = s->objectName();
884 int i_type = var_Type( p_obj, qtu( var ) );
885 switch( i_type & VLC_VAR_TYPE )
887 case VLC_VAR_INTEGER:
888 if( i_type & VLC_VAR_HASCHOICE )
890 QComboBox *combobox = qobject_cast<QComboBox*>( s );
891 value = combobox->itemData( value ).toInt();
893 var_SetInteger( p_obj, qtu( var ), value );
896 var_SetBool( p_obj, qtu( var ), value );
899 var_TriggerCallback( p_obj, qtu( var ) );
902 vlc_object_release( p_obj );
906 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
911 /**********************************************************************
913 **********************************************************************/
915 static const QString vlc_band_frequencies[] =
917 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
918 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
921 static const QString iso_band_frequencies[] =
923 " 31.25 Hz ", " 62.5 Hz ", " 125 Hz ", " 250 Hz ", " 500 Hz ",
924 " 1 kHz ", " 2 kHz ", " 4 kHz ", " 8 kHz ", " 16 kHz "
927 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
928 QWidget( _parent ) , p_intf( _p_intf )
930 QFont smallFont = QApplication::font();
931 smallFont.setPointSize( smallFont.pointSize() - 3 );
934 ui.preampLabel->setFont( smallFont );
936 /* Setup of presetsComboBox */
937 presetsComboBox = ui.presetsCombo;
938 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
940 b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
942 /* Add the sliders for the Bands */
943 QGridLayout *grid = new QGridLayout( ui.frame );
944 grid->setMargin( 0 );
945 for( int i = 0 ; i < BANDS ; i++ )
947 bands[i] = new QSlider( Qt::Vertical );
948 bands[i]->setMaximum( 400 );
949 bands[i]->setValue( 200 );
950 bands[i]->setMinimumWidth(36);
951 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
953 QString val = QString("%1").arg( 0.0, 5, 'f', 1 );
954 band_texts[i] = new QLabel( (b_vlcBands ? vlc_band_frequencies[i]
955 : iso_band_frequencies[i]) + "\n" + val + "dB" );
956 band_texts[i]->setFont( smallFont );
958 grid->addWidget( bands[i], 0, i );
959 grid->addWidget( band_texts[i], 1, i );
962 /* Add the listed presets */
963 for( int i = 0 ; i < NB_PRESETS ; i ++ )
965 presetsComboBox->addItem( qtr( preset_list_text[i] ),
966 QVariant( preset_list[i] ) );
970 BUTTONACT( ui.enableCheck, enable() );
971 BUTTONACT( ui.eq2PassCheck, set2Pass() );
972 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
974 /* Do the update from the value of the core */
978 /* Write down initial values */
979 void Equalizer::updateUIFromCore()
981 char *psz_af, *psz_pres, *psz_bands;
985 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
988 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
989 psz_pres = var_GetString( p_aout, "equalizer-preset" );
990 if( var_GetBool( p_aout, "equalizer-2pass" ) )
991 ui.eq2PassCheck->setChecked( true );
992 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
993 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
994 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
995 vlc_object_release( p_aout );
999 psz_af = config_GetPsz( p_intf, "audio-filter" );
1000 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
1001 if( config_GetInt( p_intf, "equalizer-2pass" ) )
1002 ui.eq2PassCheck->setChecked( true );
1003 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
1004 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
1005 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
1007 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
1008 ui.enableCheck->setChecked( true );
1009 enable( ui.enableCheck->isChecked() );
1011 presetsComboBox->setCurrentIndex( i_preset );
1013 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1015 if( psz_bands && strlen( psz_bands ) > 1 )
1017 char *psz_bands_orig = psz_bands;
1018 for( int i = 0; i < BANDS; i++ )
1020 const float f = us_strtod(psz_bands, &psz_bands );
1021 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1022 if( psz_bands == NULL || *psz_bands == '\0' ) break;
1024 if( *psz_bands == '\0' ) break;
1026 free( psz_bands_orig );
1028 else free( psz_bands );
1034 void Equalizer::changeFreqLabels( bool b_useVlcBands )
1036 b_vlcBands = b_useVlcBands;
1038 const QString *band_frequencies = b_vlcBands
1039 ? vlc_band_frequencies
1040 : iso_band_frequencies;
1042 for( int i = 0; i < BANDS; i++ )
1044 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1045 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1046 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1050 /* Function called when enableButton is toggled */
1051 void Equalizer::enable()
1053 bool en = ui.enableCheck->isChecked();
1054 aout_EnableFilter( THEPL, "equalizer", en );
1055 // aout_EnableFilter( THEPL, "upmixer", en );
1056 // aout_EnableFilter( THEPL, "vsurround", en );
1059 if( presetsComboBox->currentIndex() < 0 )
1060 presetsComboBox->setCurrentIndex( 0 );
1064 void Equalizer::enable( bool en )
1066 ui.eq2PassCheck->setEnabled( en );
1067 presetsComboBox->setEnabled( en );
1068 ui.presetLabel->setEnabled( en );
1069 ui.preampLabel->setEnabled( en );
1070 ui.preampSlider->setEnabled( en );
1071 for( int i = 0 ; i< BANDS; i++ )
1073 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
1077 /* Function called when the set2Pass button is activated */
1078 void Equalizer::set2Pass()
1080 vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
1081 bool b_2p = ui.eq2PassCheck->isChecked();
1085 var_SetBool( p_aout, "equalizer-2pass", b_2p );
1086 vlc_object_release( p_aout );
1088 config_PutInt( p_intf, "equalizer-2pass", b_2p );
1091 /* Function called when the preamp slider is moved */
1092 void Equalizer::setPreamp()
1094 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
1095 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1097 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
1101 //delCallbacks( p_aout );
1102 var_SetFloat( p_aout, "equalizer-preamp", f );
1103 //addCallbacks( p_aout );
1104 vlc_object_release( p_aout );
1106 config_PutFloat( p_intf, "equalizer-preamp", f );
1109 void Equalizer::setCoreBands()
1111 /**\todo smoothing */
1113 const QString *band_frequencies = b_vlcBands
1114 ? vlc_band_frequencies
1115 : iso_band_frequencies;
1118 for( int i = 0; i < BANDS; i++ )
1120 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1121 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1123 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1124 values += " " + val;
1127 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1130 //delCallbacks( p_aout );
1131 var_SetString( p_aout, "equalizer-bands", qtu( values ) );
1132 //addCallbacks( p_aout );
1133 vlc_object_release( p_aout );
1137 char * Equalizer::createValuesFromPreset( int i_preset )
1141 /* Create the QString in Qt */
1142 for( int i = 0 ; i< BANDS ;i++ )
1143 values += QString( " %1" ).arg( eqz_preset_10b[i_preset].f_amp[i], 5, 'f', 1 );
1145 /* Convert it to char * */
1146 return strdup( values.toAscii().constData() );
1149 void Equalizer::setCorePreset( int i_preset )
1154 /* Update pre-amplification in the UI */
1155 float f_preamp = eqz_preset_10b[i_preset].f_preamp;
1156 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1157 ui.preampLabel->setText( qtr( "Preamp\n" )
1158 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1160 char *psz_values = createValuesFromPreset( i_preset );
1161 if( !psz_values ) return ;
1163 const QString *band_frequencies = b_vlcBands
1164 ? vlc_band_frequencies
1165 : iso_band_frequencies;
1167 char *p = psz_values;
1168 for( int i = 0; i < BANDS && *p; i++ )
1170 const float f = us_strtod( p, &p );
1172 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1173 band_texts[i]->setText( band_frequencies[i] + "\n"
1174 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1176 p++; /* skip separator */
1179 /* Apply presets to audio output */
1180 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1183 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1185 var_SetString( p_aout, "equalizer-bands", psz_values );
1186 var_SetFloat( p_aout, "equalizer-preamp",
1187 eqz_preset_10b[i_preset].f_preamp );
1188 vlc_object_release( p_aout );
1190 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1191 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1192 config_PutFloat( p_intf, "equalizer-preamp",
1193 eqz_preset_10b[i_preset].f_preamp );
1197 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1198 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1200 VLC_UNUSED( p_this ); VLC_UNUSED( psz_cmd ); VLC_UNUSED( oldval );
1202 char *psz_preset = newval.psz_string;
1203 Equalizer *eq = ( Equalizer * )p_data;
1204 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1205 eq->presetsComboBox->setCurrentIndex( i_preset );
1209 void Equalizer::delCallbacks( vlc_object_t *p_aout )
1211 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1212 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1213 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1216 void Equalizer::addCallbacks( vlc_object_t *p_aout )
1218 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1219 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1220 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1223 /**********************************************************************
1225 **********************************************************************/
1227 /**********************************************************************
1228 * Dynamic range compressor
1229 **********************************************************************/
1233 const char *psz_name;
1234 const char *psz_descs;
1235 const char *psz_units;
1236 const float f_min; // min
1237 const float f_max; // max
1238 const float f_value; // value
1239 const float f_resolution; // resolution
1242 static const comp_controls_t comp_controls[] =
1244 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1245 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1246 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1247 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1248 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1249 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1250 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1253 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1254 : QWidget( _parent ) , p_intf( _p_intf )
1256 QFont smallFont = QApplication::font();
1257 smallFont.setPointSize( smallFont.pointSize() - 2 );
1259 QGridLayout *layout = new QGridLayout( this );
1261 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1262 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1264 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1266 const int i_min = (int)( comp_controls[i].f_min
1267 / comp_controls[i].f_resolution );
1268 const int i_max = (int)( comp_controls[i].f_max
1269 / comp_controls[i].f_resolution );
1270 const int i_val = (int)( comp_controls[i].f_value
1271 / comp_controls[i].f_resolution );
1273 compCtrl[i] = new QSlider( Qt::Vertical );
1274 compCtrl[i]->setMinimum( i_min );
1275 compCtrl[i]->setMaximum( i_max );
1276 compCtrl[i]->setValue( i_val );
1278 oldControlVars[i] = comp_controls[i].f_value;
1280 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1281 ctrl_texts[i]->setFont( smallFont );
1282 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1284 ctrl_readout[i] = new QLabel;
1285 ctrl_readout[i]->setFont( smallFont );
1286 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1288 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1289 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1290 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1293 for( int i = 0; i < NUM_CP_CTRL; i++ )
1294 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1296 BUTTONACT( enableCheck, enable() );
1298 /* Write down initial values */
1299 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1304 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1305 for( int i = 0; i < NUM_CP_CTRL; i++ )
1307 controlVars[i] = var_GetFloat( p_aout,
1308 comp_controls[i].psz_name );
1310 vlc_object_release( p_aout );
1314 psz_af = config_GetPsz( p_intf, "audio-filter" );
1315 for( int i = 0; i < NUM_CP_CTRL; i++ )
1317 controlVars[i] = config_GetFloat( p_intf,
1318 comp_controls[i].psz_name );
1321 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1323 enableCheck->setChecked( true );
1326 enable( enableCheck->isChecked() );
1327 updateSliders( controlVars );
1331 void Compressor::enable()
1333 bool en = enableCheck->isChecked();
1334 aout_EnableFilter( THEPL, "compressor", en );
1338 void Compressor::enable( bool en )
1340 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1342 compCtrl[i]->setEnabled( en );
1343 ctrl_texts[i]->setEnabled( en );
1344 ctrl_readout[i]->setEnabled( en );
1348 void Compressor::updateSliders( float * p_controlVars )
1350 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1352 if( oldControlVars[i] != p_controlVars[i] )
1354 compCtrl[i]->setValue(
1355 (int)( p_controlVars[i] / comp_controls[i].f_resolution ) );
1360 void Compressor::setInitValues()
1365 void Compressor::setValues()
1367 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1369 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1371 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1372 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1373 + qtr( comp_controls[i].psz_units ) );
1374 if( oldControlVars[i] != f )
1378 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1380 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1381 oldControlVars[i] = f;
1386 vlc_object_release( p_aout );
1390 /**********************************************************************
1392 **********************************************************************/
1395 const char *psz_name;
1396 const char *psz_desc;
1399 static const spat_controls_t spat_controls[] =
1401 { "spatializer-roomsize", _("Size") },
1402 { "spatializer-width", _("Width") },
1403 { "spatializer-wet", _("Wet") },
1404 { "spatializer-dry", _("Dry") },
1405 { "spatializer-damp", _("Damp") },
1408 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1409 : QWidget( _parent ) , p_intf( _p_intf )
1411 QFont smallFont = QApplication::font();
1412 smallFont.setPointSize( smallFont.pointSize() - 1 );
1414 QGridLayout *layout = new QGridLayout( this );
1416 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1417 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1419 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1421 spatCtrl[i] = new QSlider( Qt::Vertical );
1422 spatCtrl[i]->setValue( (int)var_InheritFloat( p_intf, spat_controls[i].psz_name ) * 10. );
1423 oldControlVars[i] = spatCtrl[i]->value();
1425 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1426 ctrl_texts[i]->setFont( smallFont );
1428 ctrl_readout[i] = new QLabel;
1429 ctrl_readout[i]->setFont( smallFont );
1431 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1432 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1433 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1434 spatCtrl[i]->setRange( 0, 10 );
1436 spatCtrl[0]->setRange( 0, 11 );
1438 for( int i = 0; i < NUM_SP_CTRL; i++ )
1439 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1441 BUTTONACT( enableCheck, enable() );
1443 /* Write down initial values */
1444 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1449 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1450 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1452 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1454 vlc_object_release( p_aout );
1458 psz_af = config_GetPsz( p_intf, "audio-filter" );
1459 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1461 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1464 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1465 enableCheck->setChecked( true );
1467 enable( enableCheck->isChecked() );
1471 void Spatializer::enable()
1473 bool en = enableCheck->isChecked();
1474 aout_EnableFilter( THEPL, "spatializer", en );
1478 void Spatializer::enable( bool en )
1480 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1482 spatCtrl[i]->setEnabled( en );
1483 ctrl_texts[i]->setEnabled( en );
1484 ctrl_readout[i]->setEnabled( en );
1487 void Spatializer::setInitValues()
1492 void Spatializer::setValues()
1494 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1496 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1498 float f = (float)( spatCtrl[i]->value() ) / 10;
1499 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1504 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1506 float f = (float)( spatCtrl[i]->value() ) / 10 ;
1507 if( oldControlVars[i] != spatCtrl[i]->value() )
1509 var_SetFloat( p_aout, spat_controls[i].psz_name, f );
1510 config_PutFloat( p_intf, spat_controls[i].psz_name, f );
1511 oldControlVars[i] = spatCtrl[i]->value();
1514 vlc_object_release( p_aout );
1518 void Spatializer::delCallbacks( vlc_object_t *p_aout )
1520 VLC_UNUSED( p_aout );
1521 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1522 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1525 void Spatializer::addCallbacks( vlc_object_t *p_aout )
1527 VLC_UNUSED( p_aout );
1528 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1529 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1532 #include <QToolButton>
1533 #include <QGridLayout>
1535 #define SUBSDELAY_CFG_MODE "subsdelay-mode"
1536 #define SUBSDELAY_CFG_FACTOR "subsdelay-factor"
1537 #define SUBSDELAY_MODE_ABSOLUTE 0
1538 #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY 1
1539 #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
1541 SyncWidget::SyncWidget( QWidget *_parent ) : QWidget( _parent )
1543 QHBoxLayout *layout = new QHBoxLayout;
1544 spinBox.setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1545 spinBox.setDecimals( 3 );
1546 spinBox.setMinimum( -600.0 );
1547 spinBox.setMaximum( 600.0 );
1548 spinBox.setSingleStep( 0.1 );
1549 spinBox.setSuffix( " s" );
1550 spinBox.setButtonSymbols( QDoubleSpinBox::PlusMinus );
1551 CONNECT( &spinBox, valueChanged( double ), this, valueChangedHandler( double ) );
1552 layout->addWidget( &spinBox );
1553 layout->addWidget( &spinLabel );
1554 layout->setContentsMargins( 0, 0, 0, 0 );
1555 setLayout( layout );
1558 void SyncWidget::valueChangedHandler( double d )
1561 spinLabel.setText( qtr("(Hastened)") );
1563 spinLabel.setText( qtr("(Delayed)") );
1565 spinLabel.setText( "" );
1566 emit valueChanged( d );
1569 void SyncWidget::setValue( double d )
1571 spinBox.setValue( d );
1574 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1575 QWidget( _parent ) , p_intf( _p_intf )
1577 QGroupBox *AVBox, *subsBox;
1578 QToolButton *updateButton;
1580 b_userAction = true;
1582 QGridLayout *mainLayout = new QGridLayout( this );
1585 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1586 QGridLayout *AVLayout = new QGridLayout( AVBox );
1588 QLabel *AVLabel = new QLabel;
1589 AVLabel->setText( qtr( "Audio track synchronization:" ) );
1590 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1592 AVSpin = new SyncWidget( this );
1593 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1594 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1597 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1598 QGridLayout *subsLayout = new QGridLayout( subsBox );
1600 QLabel *subsLabel = new QLabel;
1601 subsLabel->setText( qtr( "Subtitle track syncronization:" ) );
1602 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1604 subsSpin = new SyncWidget( this );
1605 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1607 QLabel *subSpeedLabel = new QLabel;
1608 subSpeedLabel->setText( qtr( "Subtitles speed:" ) );
1609 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1611 subSpeedSpin = new QDoubleSpinBox;
1612 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1613 subSpeedSpin->setDecimals( 3 );
1614 subSpeedSpin->setMinimum( 1 );
1615 subSpeedSpin->setMaximum( 100 );
1616 subSpeedSpin->setSingleStep( 0.2 );
1617 subSpeedSpin->setSuffix( " fps" );
1618 subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1619 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1621 QLabel *subDurationLabel = new QLabel;
1622 subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
1623 subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
1625 subDurationSpin = new QDoubleSpinBox;
1626 subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1627 subDurationSpin->setDecimals( 3 );
1628 subDurationSpin->setMinimum( 0 );
1629 subDurationSpin->setMaximum( 20 );
1630 subDurationSpin->setSingleStep( 0.2 );
1631 subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1632 subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
1634 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1636 updateButton = new QToolButton;
1637 updateButton->setAutoRaise( true );
1638 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1640 /* Various Connects */
1641 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1642 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1643 CONNECT( subSpeedSpin, valueChanged ( double ),
1644 this, adjustSubsSpeed( double ) );
1645 CONNECT( subDurationSpin, valueChanged ( double ),
1646 this, adjustSubsDuration( double ) );
1648 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1649 BUTTON_SET_ACT_I( updateButton, "", update,
1650 qtr( "Force update of this dialog's values" ), update() );
1658 SyncControls::~SyncControls()
1663 void SyncControls::clean()
1665 b_userAction = false;
1666 AVSpin->setValue( 0.0 );
1667 subsSpin->setValue( 0.0 );
1668 subSpeedSpin->setValue( 1.0 );
1670 b_userAction = true;
1673 void SyncControls::update()
1675 b_userAction = false;
1678 if( THEMIM->getInput() )
1680 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1681 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1682 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1683 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1684 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1685 subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
1687 b_userAction = true;
1690 void SyncControls::advanceAudio( double f_advance )
1692 if( THEMIM->getInput() && b_userAction )
1694 int64_t i_delay = f_advance * 1000000;
1695 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1699 void SyncControls::advanceSubs( double f_advance )
1701 if( THEMIM->getInput() && b_userAction )
1703 int64_t i_delay = f_advance * 1000000;
1704 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1708 void SyncControls::adjustSubsSpeed( double f_fps )
1710 if( THEMIM->getInput() && b_userAction )
1712 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1716 void SyncControls::adjustSubsDuration( double f_factor )
1718 if( THEMIM->getInput() && b_userAction )
1720 subsdelaySetFactor( f_factor );
1721 ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
1725 void SyncControls::initSubsDuration()
1727 int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
1732 case SUBSDELAY_MODE_ABSOLUTE:
1733 subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
1734 "Set 0 to disable." ) );
1735 subDurationSpin->setSuffix( " s" );
1737 case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
1738 subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
1739 "Set 0 to disable." ) );
1740 subDurationSpin->setSuffix( "" );
1742 case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
1743 subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
1744 "to their content and this value.\n"
1745 "Set 0 to disable." ) );
1746 subDurationSpin->setSuffix( "" );
1751 void SyncControls::subsdelayClean()
1753 /* Remove subsdelay filter */
1754 ChangeVFiltersString( p_intf, "subsdelay", false );
1757 void SyncControls::subsdelaySetFactor( double f_factor )
1759 /* Set the factor in the preferences */
1760 config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
1762 /* Try to find an instance of subsdelay, and set its factor */
1763 vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
1766 var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
1767 vlc_object_release( p_obj );
1772 /**********************************************************************
1773 * Video filters / Adjust
1774 **********************************************************************/
1776 /**********************************************************************
1777 * Extended playbak controls
1778 **********************************************************************/