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_intf_strings.h>
51 #include <vlc_modules.h>
52 #include <vlc_plugin.h>
54 #include <vlc_charset.h> /* us_strtod */
56 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
59 class ConfClickHandler : public QObject
62 ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
63 e = _e; p_intf = _p_intf;
65 virtual ~ConfClickHandler() {}
66 bool eventFilter( QObject *obj, QEvent *evt )
68 if( evt->type() == QEvent::MouseButtonPress )
77 intf_thread_t *p_intf;
81 const QString ModuleFromWidgetName( QObject *obj )
83 return obj->objectName().replace( "Enable","" );
86 QString OptionFromWidgetName( QObject *obj )
89 QString option = obj->objectName().replace( "Slider", "" )
90 .replace( "Combo" , "" )
91 .replace( "Dial" , "" )
92 .replace( "Check" , "" )
93 .replace( "Spin" , "" )
94 .replace( "Text" , "" );
95 for( char a = 'A'; a <= 'Z'; a++ )
97 option = option.replace( QString( a ),
98 QString( '-' ) + QString( a + 'a' - 'A' ) );
103 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
104 QObject( _parent ), p_intf( _p_intf )
106 ui.setupUi( _parent );
108 #define SETUP_VFILTER( widget ) \
110 vlc_object_t *p_obj = ( vlc_object_t * ) \
111 vlc_object_find_name( p_intf->p_libvlc, \
113 QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
114 QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
117 vlc_object_release( p_obj ); \
118 if( checkbox ) checkbox->setChecked( true ); \
119 else if (groupbox) groupbox->setChecked( true ); \
123 if( checkbox ) checkbox->setChecked( false ); \
124 else if (groupbox) groupbox->setChecked( false ); \
127 CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
130 #define SETUP_VFILTER_OPTION( widget, signal ) \
131 initComboBoxItems( ui.widget ); \
132 setWidgetValue( ui.widget ); \
133 CONNECT( ui.widget, signal, this, updateFilterOptions() );
135 SETUP_VFILTER( adjust )
136 SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
137 SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
138 SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
139 SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
140 SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
141 SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
143 SETUP_VFILTER( extract )
144 SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
146 SETUP_VFILTER( posterize )
148 SETUP_VFILTER( colorthres )
149 SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
150 SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
151 SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
153 SETUP_VFILTER( sepia )
154 SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )
156 SETUP_VFILTER( invert )
158 SETUP_VFILTER( gradient )
159 SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
160 SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
161 SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
163 SETUP_VFILTER( motionblur )
164 SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
166 SETUP_VFILTER( motiondetect )
168 SETUP_VFILTER( psychedelic )
170 SETUP_VFILTER( sharpen )
171 SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
173 SETUP_VFILTER( ripple )
175 SETUP_VFILTER( wave )
177 SETUP_VFILTER( transform )
178 SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
180 SETUP_VFILTER( rotate )
181 SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
182 ui.rotateAngleDial->setWrapping( true );
183 ui.rotateAngleDial->setNotchesVisible( true );
185 SETUP_VFILTER( puzzle )
186 SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
187 SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
188 SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
190 SETUP_VFILTER( magnify )
192 SETUP_VFILTER( clone )
193 SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
195 SETUP_VFILTER( wall )
196 SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
197 SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
200 SETUP_VFILTER( erase )
201 SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
202 SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
203 SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
204 BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
206 SETUP_VFILTER( marq )
207 SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
208 SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
210 SETUP_VFILTER( logo )
211 SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
212 SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
213 SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
214 SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
215 BUTTONACT( ui.logoBrowseBtn, browseLogo() );
217 SETUP_VFILTER( gradfun )
218 SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
220 SETUP_VFILTER( grain )
221 SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
223 SETUP_VFILTER( mirror )
225 SETUP_VFILTER( gaussianblur )
226 SETUP_VFILTER_OPTION( gaussianbluSigmaSlider, valueChanged( int ) )
228 SETUP_VFILTER( antiflicker )
229 SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )
232 if( module_exists( "atmo" ) )
234 SETUP_VFILTER( atmo )
235 SETUP_VFILTER_OPTION( atmoEdgeweightningSlider, valueChanged( int ) )
236 SETUP_VFILTER_OPTION( atmoBrightnessSlider, valueChanged( int ) )
237 SETUP_VFILTER_OPTION( atmoDarknesslimitSlider, valueChanged( int ) )
238 SETUP_VFILTER_OPTION( atmoMeanlengthSlider, valueChanged( int ) )
239 SETUP_VFILTER_OPTION( atmoMeanthresholdSlider, valueChanged( int ) )
240 SETUP_VFILTER_OPTION( atmoPercentnewSlider, valueChanged( int ) )
241 SETUP_VFILTER_OPTION( atmoFiltermodeCombo, currentIndexChanged( int ) )
242 SETUP_VFILTER_OPTION( atmoShowdotsCheck, stateChanged( int ) )
246 _parent->removeTab( _parent->indexOf( ui.tab_atmo ) );
249 SETUP_VFILTER( anaglyph )
252 #undef SETUP_VFILTER_OPTION
254 CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
255 CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
256 CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
257 CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
258 CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
259 CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
260 CONNECT( ui.topBotCropSync, toggled( bool ),
261 ui.cropBotPx, setDisabled( bool ) );
262 CONNECT( ui.leftRightCropSync, toggled( bool ),
263 ui.cropRightPx, setDisabled( bool ) );
266 void ExtVideo::cropChange()
268 if( ui.topBotCropSync->isChecked() )
269 ui.cropBotPx->setValue( ui.cropTopPx->value() );
270 if( ui.leftRightCropSync->isChecked() )
271 ui.cropRightPx->setValue( ui.cropLeftPx->value() );
273 vout_thread_t *p_vout = THEMIM->getVout();
276 var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
277 var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
278 var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
279 var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
280 vlc_object_release( p_vout );
284 void ExtVideo::clean()
286 ui.cropTopPx->setValue( 0 );
287 ui.cropBotPx->setValue( 0 );
288 ui.cropLeftPx->setValue( 0 );
289 ui.cropRightPx->setValue( 0 );
292 static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
294 char *psz_parser, *psz_string;
295 const char *psz_filter_type;
297 module_t *p_obj = module_find( psz_name );
300 msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
304 if( module_provides( p_obj, "video splitter" ) )
306 psz_filter_type = "video-splitter";
308 else if( module_provides( p_obj, "video filter2" ) )
310 psz_filter_type = "video-filter";
312 else if( module_provides( p_obj, "sub source" ) )
314 psz_filter_type = "sub-source";
316 else if( module_provides( p_obj, "sub filter" ) )
318 psz_filter_type = "sub-filter";
322 msg_Err( p_intf, "Unknown video filter type." );
326 psz_string = config_GetPsz( p_intf, psz_filter_type );
328 if( !psz_string ) psz_string = strdup( "" );
330 psz_parser = strstr( psz_string, psz_name );
336 psz_parser = psz_string;
337 if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
338 psz_string, psz_name ) == -1 )
355 if( *( psz_parser + strlen( psz_name ) ) == ':' )
357 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
358 strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
365 /* Remove trailing : : */
366 size_t i_len = strlen( psz_string );
367 if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
369 *( psz_string + i_len - 1 ) = '\0';
378 /* Vout is not kept, so put that in the config */
379 config_PutPsz( p_intf, psz_filter_type, psz_string );
381 /* Try to set on the fly */
382 if( !strcmp( psz_filter_type, "video-splitter" ) )
384 playlist_t *p_playlist = pl_Get( p_intf );
385 var_SetString( p_playlist, psz_filter_type, psz_string );
389 vout_thread_t *p_vout = THEMIM->getVout();
392 var_SetString( p_vout, psz_filter_type, psz_string );
393 vlc_object_release( p_vout );
400 void ExtVideo::updateFilters()
402 QString module = ModuleFromWidgetName( sender() );
404 QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
405 QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
407 ChangeVFiltersString( p_intf, qtu( module ),
408 checkbox ? checkbox->isChecked()
409 : groupbox->isChecked() );
412 #define UPDATE_AND_APPLY_TEXT( widget, file ) \
413 CONNECT( ui.widget, textChanged( const QString& ), \
414 this, updateFilterOptions() ); \
415 ui.widget->setText( toNativeSeparators( file ) ); \
416 ui.widget->disconnect( SIGNAL( textChanged( const QString& ) ) );
418 void ExtVideo::browseLogo()
420 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
421 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
423 UPDATE_AND_APPLY_TEXT( logoFileText, file );
426 void ExtVideo::browseEraseFile()
428 QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
429 p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
431 UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
434 #undef UPDATE_AND_APPLY_TEXT
436 void ExtVideo::initComboBoxItems( QObject *widget )
438 QComboBox *combobox = qobject_cast<QComboBox*>( widget );
439 if( !combobox ) return;
441 QString option = OptionFromWidgetName( widget );
442 module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
446 msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
450 if( p_item->i_type == CONFIG_ITEM_INTEGER
451 || p_item->i_type == CONFIG_ITEM_BOOL )
455 ssize_t count = config_GetIntChoices( VLC_OBJECT( p_intf ),
456 qtu( option ), &values, &texts );
457 for( ssize_t i = 0; i < count; i++ )
459 combobox->addItem( qtr( texts[i] ), qlonglong(values[i]) );
465 else if( p_item->i_type == CONFIG_ITEM_STRING )
469 ssize_t count = config_GetPszChoices( VLC_OBJECT( p_intf ),
470 qtu( option ), &values, &texts );
471 for( ssize_t i = 0; i < count; i++ )
473 combobox->addItem( qtr( texts[i] ), qfu(values[i]) );
482 void ExtVideo::setWidgetValue( QObject *widget )
484 QString module = ModuleFromWidgetName( widget->parent() );
485 //std::cout << "Module name: " << module.toStdString() << std::endl;
486 QString option = OptionFromWidgetName( widget );
487 //std::cout << "Option name: " << option.toStdString() << std::endl;
489 vlc_object_t *p_obj = ( vlc_object_t * )
490 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
498 "Module instance %s not found, looking in config values.",
501 i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
504 case VLC_VAR_INTEGER:
506 val.i_int = config_GetInt( p_intf, qtu( option ) );
509 val.f_float = config_GetFloat( p_intf, qtu( option ) );
512 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
518 i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
519 var_Get( p_obj, qtu( option ), &val );
520 vlc_object_release( p_obj );
523 /* Try to cast to all the widgets we're likely to encounter. Only
524 * one of the casts is expected to work. */
525 QSlider *slider = qobject_cast<QSlider*> ( widget );
526 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
527 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
528 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
529 QDial *dial = qobject_cast<QDial*> ( widget );
530 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
531 QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
533 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
535 if( slider ) slider->setValue( val.i_int );
536 else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
538 else if( spinbox ) spinbox->setValue( val.i_int );
539 else if( dial ) dial->setValue( ( 540-val.i_int )%360 );
543 snprintf( str, sizeof(str), "%06"PRIX64, val.i_int );
544 lineedit->setText( str );
546 else if( combobox ) combobox->setCurrentIndex(
547 combobox->findData( qlonglong(val.i_int) ) );
548 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
550 else if( i_type == VLC_VAR_FLOAT )
552 if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
553 else if( doublespinbox ) doublespinbox->setValue( val.f_float );
554 else msg_Warn( p_intf, "Could not find the correct Float widget" );
556 else if( i_type == VLC_VAR_STRING )
558 if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
559 else if( combobox ) combobox->setCurrentIndex(
560 combobox->findData( qfu( val.psz_string ) ) );
561 else msg_Warn( p_intf, "Could not find the correct String widget" );
562 free( val.psz_string );
567 "Module %s's %s variable is of an unsupported type ( %d )",
573 void ExtVideo::updateFilterOptions()
575 QString module = ModuleFromWidgetName( sender()->parent() );
576 //std::cout << "Module name: " << module.toStdString() << std::endl;
577 QString option = OptionFromWidgetName( sender() );
578 //std::cout << "Option name: " << option.toStdString() << std::endl;
580 vlc_object_t *p_obj = ( vlc_object_t * )
581 vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
586 msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
587 i_type = config_GetType( p_intf, qtu( option ) );
588 b_is_command = false;
592 i_type = var_Type( p_obj, qtu( option ) );
594 i_type = config_GetType( p_intf, qtu( option ) );
595 b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
598 /* Try to cast to all the widgets we're likely to encounter. Only
599 * one of the casts is expected to work. */
600 QSlider *slider = qobject_cast<QSlider*> ( sender() );
601 QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
602 QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
603 QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
604 QDial *dial = qobject_cast<QDial*> ( sender() );
605 QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
606 QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
608 i_type &= VLC_VAR_CLASS;
609 if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
612 if( slider ) i_int = slider->value();
613 else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
614 else if( spinbox ) i_int = spinbox->value();
615 else if( dial ) i_int = ( 540-dial->value() )%360;
616 else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
617 else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
618 else msg_Warn( p_intf, "Could not find the correct Integer widget" );
619 config_PutInt( p_intf, qtu( option ), i_int );
622 if( i_type == VLC_VAR_INTEGER )
623 var_SetInteger( p_obj, qtu( option ), i_int );
625 var_SetBool( p_obj, qtu( option ), i_int );
628 else if( i_type == VLC_VAR_FLOAT )
631 if( slider ) f_float = ( double )slider->value()
632 / ( double )slider->tickInterval(); /* hack alert! */
633 else if( doublespinbox ) f_float = doublespinbox->value();
634 else if( lineedit ) f_float = lineedit->text().toDouble();
635 else msg_Warn( p_intf, "Could not find the correct Float widget" );
636 config_PutFloat( p_intf, qtu( option ), f_float );
638 var_SetFloat( p_obj, qtu( option ), f_float );
640 else if( i_type == VLC_VAR_STRING )
644 val = lineedit->text();
646 val = combobox->itemData( combobox->currentIndex() ).toString();
648 msg_Warn( p_intf, "Could not find the correct String widget" );
649 config_PutPsz( p_intf, qtu( option ), qtu( val ) );
651 var_SetString( p_obj, qtu( option ), qtu( val ) );
655 "Module %s's %s variable is of an unsupported type ( %d )",
662 msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
665 ChangeVFiltersString( p_intf, qtu( module ), false );
666 ChangeVFiltersString( p_intf, qtu( module ), true );
669 if( p_obj ) vlc_object_release( p_obj );
673 void ExtVideo::gotoConf( QObject* src )
675 #define SHOWCONF( module ) \
676 if( src->objectName().contains( module ) ) \
678 PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
682 SHOWCONF( "magnify" );
684 SHOWCONF( "ripple" );
685 SHOWCONF( "invert" );
686 SHOWCONF( "puzzle" );
688 SHOWCONF( "gradient" );
689 SHOWCONF( "colorthres" );
690 SHOWCONF( "anaglyph" )
694 /**********************************************************************
696 **********************************************************************/
698 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
699 : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
701 QVBoxLayout *layout = new QVBoxLayout( this );
702 help = new QLabel( qtr("No v4l2 instance found.\n"
703 "Please check that the device has been opened with VLC and is playing.\n\n"
704 "Controls will automatically appear here.")
706 help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
707 layout->addWidget( help );
711 void ExtV4l2::showEvent( QShowEvent *event )
713 QWidget::showEvent( event );
717 void ExtV4l2::Refresh( void )
719 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
723 layout()->removeWidget( box );
729 vlc_value_t val, text;
730 int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
734 msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
736 vlc_object_release( p_obj );
740 box = new QGroupBox( this );
741 layout()->addWidget( box );
742 QVBoxLayout *layout = new QVBoxLayout( box );
743 box->setLayout( layout );
745 for( int i = 0; i < val.p_list->i_count; i++ )
748 const char *psz_var = text.p_list->p_values[i].psz_string;
750 if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
753 QString name = qtr( vartext.psz_string );
754 free( vartext.psz_string );
755 msg_Dbg( p_intf, "v4l2 control \"%"PRIx64"\": %s (%s)",
756 val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
758 int i_type = var_Type( p_obj, psz_var );
759 switch( i_type & VLC_VAR_TYPE )
761 case VLC_VAR_INTEGER:
763 QLabel *label = new QLabel( name, box );
764 QHBoxLayout *hlayout = new QHBoxLayout();
765 hlayout->addWidget( label );
766 int i_val = var_GetInteger( p_obj, psz_var );
767 if( i_type & VLC_VAR_HASCHOICE )
769 QComboBox *combobox = new QComboBox( box );
770 combobox->setObjectName( qfu( psz_var ) );
772 vlc_value_t val2, text2;
773 var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
775 for( int j = 0; j < val2.p_list->i_count; j++ )
778 text2.p_list->p_values[j].psz_string,
779 qlonglong( val2.p_list->p_values[j].i_int) );
780 if( i_val == val2.p_list->p_values[j].i_int )
781 combobox->setCurrentIndex( j );
783 var_FreeList( &val2, &text2 );
785 CONNECT( combobox, currentIndexChanged( int ), this,
786 ValueChange( int ) );
787 hlayout->addWidget( combobox );
790 if( (i_type & VLC_VAR_HASMIN) && (i_type & VLC_VAR_HASMAX) )
792 QSlider *slider = new QSlider( box );
793 slider->setObjectName( qfu( psz_var ) );
794 slider->setOrientation( Qt::Horizontal );
796 var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
798 if( val2.i_int < INT_MIN )
799 val2.i_int = INT_MIN; /* FIXME */
800 slider->setMinimum( val2.i_int );
801 var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
803 if( val2.i_int > INT_MAX )
804 val2.i_int = INT_MAX; /* FIXME */
805 slider->setMaximum( val2.i_int );
806 if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
808 slider->setSingleStep( val2.i_int );
809 slider->setValue( i_val );
810 CONNECT( slider, valueChanged( int ), this,
811 ValueChange( int ) );
812 hlayout->addWidget( slider );
816 QSpinBox *spinBox = new QSpinBox( box );
817 spinBox->setObjectName( qfu( psz_var ) );
818 spinBox->setMinimum( INT_MIN );
819 spinBox->setMaximum( INT_MAX );
820 spinBox->setValue( i_val );
821 CONNECT( spinBox, valueChanged( int ), this,
822 ValueChange( int ) );
823 hlayout->addWidget( spinBox );
825 layout->addLayout( hlayout );
830 QCheckBox *button = new QCheckBox( name, box );
831 button->setObjectName( qfu( psz_var ) );
832 button->setChecked( var_GetBool( p_obj, psz_var ) );
834 CONNECT( button, clicked( bool ), this,
835 ValueChange( bool ) );
836 layout->addWidget( button );
841 if( i_type & VLC_VAR_ISCOMMAND )
843 QPushButton *button = new QPushButton( name, box );
844 button->setObjectName( qfu( psz_var ) );
846 CONNECT( button, clicked( bool ), this,
847 ValueChange( bool ) );
848 layout->addWidget( button );
852 QLabel *label = new QLabel( name, box );
853 layout->addWidget( label );
858 msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
862 var_FreeList( &val, &text );
863 vlc_object_release( p_obj );
867 msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
870 QTimer::singleShot( 2000, this, SLOT(Refresh()) );
874 void ExtV4l2::ValueChange( bool value )
876 ValueChange( (int)value );
879 void ExtV4l2::ValueChange( int value )
881 QObject *s = sender();
882 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
885 QString var = s->objectName();
886 int i_type = var_Type( p_obj, qtu( var ) );
887 switch( i_type & VLC_VAR_TYPE )
889 case VLC_VAR_INTEGER:
890 if( i_type & VLC_VAR_HASCHOICE )
892 QComboBox *combobox = qobject_cast<QComboBox*>( s );
893 value = combobox->itemData( value ).toInt();
895 var_SetInteger( p_obj, qtu( var ), value );
898 var_SetBool( p_obj, qtu( var ), value );
901 var_TriggerCallback( p_obj, qtu( var ) );
904 vlc_object_release( p_obj );
908 msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
913 /**********************************************************************
915 **********************************************************************/
917 static const QString vlc_band_frequencies[] =
919 " 60 Hz ", " 170 Hz ", " 310 Hz ", " 600 Hz ", " 1 kHz ",
920 " 3 kHz ", " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
923 static const QString iso_band_frequencies[] =
925 " 31.25 Hz ", " 62.5 Hz ", " 125 Hz ", " 250 Hz ", " 500 Hz ",
926 " 1 kHz ", " 2 kHz ", " 4 kHz ", " 8 kHz ", " 16 kHz "
929 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
930 QWidget( _parent ) , p_intf( _p_intf )
932 QFont smallFont = QApplication::font();
933 smallFont.setPointSize( smallFont.pointSize() - 3 );
936 ui.preampLabel->setFont( smallFont );
938 /* Setup of presetsComboBox */
939 presetsComboBox = ui.presetsCombo;
940 CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
942 b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
944 /* Add the sliders for the Bands */
945 QGridLayout *grid = new QGridLayout( ui.frame );
946 grid->setMargin( 0 );
947 for( int i = 0 ; i < BANDS ; i++ )
949 bands[i] = new QSlider( Qt::Vertical );
950 bands[i]->setMaximum( 400 );
951 bands[i]->setValue( 200 );
952 bands[i]->setMinimumWidth(36);
953 CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
955 QString val = QString("%1").arg( 0.0, 5, 'f', 1 );
956 band_texts[i] = new QLabel( (b_vlcBands ? vlc_band_frequencies[i]
957 : iso_band_frequencies[i]) + "\n" + val + "dB" );
958 band_texts[i]->setFont( smallFont );
960 grid->addWidget( bands[i], 0, i );
961 grid->addWidget( band_texts[i], 1, i );
964 /* Add the listed presets */
965 for( int i = 0 ; i < NB_PRESETS ; i ++ )
967 presetsComboBox->addItem( qtr( preset_list_text[i] ),
968 QVariant( preset_list[i] ) );
972 BUTTONACT( ui.enableCheck, enable() );
973 BUTTONACT( ui.eq2PassCheck, set2Pass() );
974 CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
976 /* Do the update from the value of the core */
980 /* Write down initial values */
981 void Equalizer::updateUIFromCore()
983 char *psz_af, *psz_pres, *psz_bands;
987 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
990 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
991 psz_pres = var_GetString( p_aout, "equalizer-preset" );
992 if( var_GetBool( p_aout, "equalizer-2pass" ) )
993 ui.eq2PassCheck->setChecked( true );
994 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
995 psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
996 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
997 vlc_object_release( p_aout );
1001 psz_af = config_GetPsz( p_intf, "audio-filter" );
1002 psz_pres = config_GetPsz( p_intf, "equalizer-preset" );
1003 if( config_GetInt( p_intf, "equalizer-2pass" ) )
1004 ui.eq2PassCheck->setChecked( true );
1005 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
1006 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
1007 i_preset = presetsComboBox->findData( QVariant( psz_pres ) );
1009 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
1010 ui.enableCheck->setChecked( true );
1011 enable( ui.enableCheck->isChecked() );
1013 presetsComboBox->setCurrentIndex( i_preset );
1015 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1017 if( psz_bands && strlen( psz_bands ) > 1 )
1019 char *psz_bands_orig = psz_bands;
1020 for( int i = 0; i < BANDS; i++ )
1022 const float f = us_strtod(psz_bands, &psz_bands );
1023 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1024 if( psz_bands == NULL || *psz_bands == '\0' ) break;
1026 if( *psz_bands == '\0' ) break;
1028 free( psz_bands_orig );
1030 else free( psz_bands );
1036 void Equalizer::changeFreqLabels( bool b_useVlcBands )
1038 b_vlcBands = b_useVlcBands;
1040 const QString *band_frequencies = b_vlcBands
1041 ? vlc_band_frequencies
1042 : iso_band_frequencies;
1044 for( int i = 0; i < BANDS; i++ )
1046 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1047 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1048 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1052 /* Function called when enableButton is toggled */
1053 void Equalizer::enable()
1055 bool en = ui.enableCheck->isChecked();
1056 playlist_EnableAudioFilter( THEPL, "equalizer", en );
1057 //playlist_EnableAudioFilter( THEPL, "upmixer", en );
1058 //playlist_EnableAudioFilter( THEPL, "vsurround", en );
1061 if( presetsComboBox->currentIndex() < 0 )
1062 presetsComboBox->setCurrentIndex( 0 );
1066 void Equalizer::enable( bool en )
1068 ui.eq2PassCheck->setEnabled( en );
1069 presetsComboBox->setEnabled( en );
1070 ui.presetLabel->setEnabled( en );
1071 ui.preampLabel->setEnabled( en );
1072 ui.preampSlider->setEnabled( en );
1073 for( int i = 0 ; i< BANDS; i++ )
1075 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
1079 /* Function called when the set2Pass button is activated */
1080 void Equalizer::set2Pass()
1082 vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
1083 bool b_2p = ui.eq2PassCheck->isChecked();
1087 var_SetBool( p_aout, "equalizer-2pass", b_2p );
1088 vlc_object_release( p_aout );
1090 config_PutInt( p_intf, "equalizer-2pass", b_2p );
1093 /* Function called when the preamp slider is moved */
1094 void Equalizer::setPreamp()
1096 const float f = ( float )( ui.preampSlider->value() ) /10 - 20;
1097 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1099 ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
1103 //delCallbacks( p_aout );
1104 var_SetFloat( p_aout, "equalizer-preamp", f );
1105 //addCallbacks( p_aout );
1106 vlc_object_release( p_aout );
1108 config_PutFloat( p_intf, "equalizer-preamp", f );
1111 void Equalizer::setCoreBands()
1113 /**\todo smoothing */
1115 const QString *band_frequencies = b_vlcBands
1116 ? vlc_band_frequencies
1117 : iso_band_frequencies;
1120 for( int i = 0; i < BANDS; i++ )
1122 const float f_val = (float)( bands[i]->value() ) / 10 - 20;
1123 QString val = QString("%1").arg( f_val, 5, 'f', 1 );
1125 band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1126 values += " " + val;
1129 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1132 //delCallbacks( p_aout );
1133 var_SetString( p_aout, "equalizer-bands", qtu( values ) );
1134 //addCallbacks( p_aout );
1135 vlc_object_release( p_aout );
1139 char * Equalizer::createValuesFromPreset( int i_preset )
1143 /* Create the QString in Qt */
1144 for( int i = 0 ; i< BANDS ;i++ )
1145 values += QString( " %1" ).arg( eqz_preset_10b[i_preset].f_amp[i], 5, 'f', 1 );
1147 /* Convert it to char * */
1148 return strdup( values.toAscii().constData() );
1151 void Equalizer::setCorePreset( int i_preset )
1156 /* Update pre-amplification in the UI */
1157 float f_preamp = eqz_preset_10b[i_preset].f_preamp;
1158 ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1159 ui.preampLabel->setText( qtr( "Preamp\n" )
1160 + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1162 char *psz_values = createValuesFromPreset( i_preset );
1163 if( !psz_values ) return ;
1165 const QString *band_frequencies = b_vlcBands
1166 ? vlc_band_frequencies
1167 : iso_band_frequencies;
1169 char *p = psz_values;
1170 for( int i = 0; i < BANDS && *p; i++ )
1172 const float f = us_strtod( p, &p );
1174 bands[i]->setValue( (int)( ( f + 20 ) * 10 ) );
1175 band_texts[i]->setText( band_frequencies[i] + "\n"
1176 + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1178 p++; /* skip separator */
1181 /* Apply presets to audio output */
1182 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1185 var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1187 var_SetString( p_aout, "equalizer-bands", psz_values );
1188 var_SetFloat( p_aout, "equalizer-preamp",
1189 eqz_preset_10b[i_preset].f_preamp );
1190 vlc_object_release( p_aout );
1192 config_PutPsz( p_intf, "equalizer-bands", psz_values );
1193 config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1194 config_PutFloat( p_intf, "equalizer-preamp",
1195 eqz_preset_10b[i_preset].f_preamp );
1199 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1200 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1202 VLC_UNUSED( p_this ); VLC_UNUSED( psz_cmd ); VLC_UNUSED( oldval );
1204 char *psz_preset = newval.psz_string;
1205 Equalizer *eq = ( Equalizer * )p_data;
1206 int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1207 eq->presetsComboBox->setCurrentIndex( i_preset );
1211 void Equalizer::delCallbacks( vlc_object_t *p_aout )
1213 //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1214 //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1215 var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1218 void Equalizer::addCallbacks( vlc_object_t *p_aout )
1220 //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1221 //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1222 var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1225 /**********************************************************************
1227 **********************************************************************/
1229 /**********************************************************************
1230 * Dynamic range compressor
1231 **********************************************************************/
1235 const char *psz_name;
1236 const char *psz_descs;
1237 const char *psz_units;
1238 const float f_min; // min
1239 const float f_max; // max
1240 const float f_value; // value
1241 const float f_resolution; // resolution
1244 static const comp_controls_t comp_controls[] =
1246 { "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
1247 { "compressor-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
1248 { "compressor-release", _("Release"), _(" ms"), 2.0f, 800.0f, 100.00f, 0.100f },
1249 { "compressor-threshold", _("Threshold"), _(" dB"), -30.0f, 0.0f, -11.00f, 0.010f },
1250 { "compressor-ratio", _("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f },
1251 { "compressor-knee", _("Knee\nradius"), _(" dB"), 1.0f, 10.0f, 2.50f, 0.010f },
1252 { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"), 0.0f, 24.0f, 7.00f, 0.010f },
1255 Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
1256 : QWidget( _parent ) , p_intf( _p_intf )
1258 QFont smallFont = QApplication::font();
1259 smallFont.setPointSize( smallFont.pointSize() - 2 );
1261 QGridLayout *layout = new QGridLayout( this );
1263 enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
1264 layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
1266 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1268 const int i_min = (int)( comp_controls[i].f_min
1269 / comp_controls[i].f_resolution );
1270 const int i_max = (int)( comp_controls[i].f_max
1271 / comp_controls[i].f_resolution );
1272 const int i_val = (int)( comp_controls[i].f_value
1273 / comp_controls[i].f_resolution );
1275 compCtrl[i] = new QSlider( Qt::Vertical );
1276 compCtrl[i]->setMinimum( i_min );
1277 compCtrl[i]->setMaximum( i_max );
1278 compCtrl[i]->setValue( i_val );
1280 oldControlVars[i] = comp_controls[i].f_value;
1282 ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
1283 ctrl_texts[i]->setFont( smallFont );
1284 ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
1286 ctrl_readout[i] = new QLabel;
1287 ctrl_readout[i]->setFont( smallFont );
1288 ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
1290 layout->addWidget( compCtrl[i], 1, i, Qt::AlignHCenter );
1291 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1292 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1295 for( int i = 0; i < NUM_CP_CTRL; i++ )
1296 CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
1298 BUTTONACT( enableCheck, enable() );
1300 /* Write down initial values */
1301 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1306 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1307 for( int i = 0; i < NUM_CP_CTRL; i++ )
1309 controlVars[i] = var_GetFloat( p_aout,
1310 comp_controls[i].psz_name );
1312 vlc_object_release( p_aout );
1316 psz_af = config_GetPsz( p_intf, "audio-filter" );
1317 for( int i = 0; i < NUM_CP_CTRL; i++ )
1319 controlVars[i] = config_GetFloat( p_intf,
1320 comp_controls[i].psz_name );
1323 if( psz_af && strstr( psz_af, "compressor" ) != NULL )
1325 enableCheck->setChecked( true );
1328 enable( enableCheck->isChecked() );
1329 updateSliders( controlVars );
1333 void Compressor::enable()
1335 bool en = enableCheck->isChecked();
1336 playlist_EnableAudioFilter( THEPL, "compressor", en );
1340 void Compressor::enable( bool en )
1342 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1344 compCtrl[i]->setEnabled( en );
1345 ctrl_texts[i]->setEnabled( en );
1346 ctrl_readout[i]->setEnabled( en );
1350 void Compressor::updateSliders( float * p_controlVars )
1352 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1354 if( oldControlVars[i] != p_controlVars[i] )
1356 compCtrl[i]->setValue(
1357 (int)( p_controlVars[i] / comp_controls[i].f_resolution ) );
1362 void Compressor::setInitValues()
1367 void Compressor::setValues()
1369 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1371 for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
1373 float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
1374 ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
1375 + qtr( comp_controls[i].psz_units ) );
1376 if( oldControlVars[i] != f )
1380 var_SetFloat( p_aout, comp_controls[i].psz_name, f );
1382 config_PutFloat( p_intf, comp_controls[i].psz_name, f );
1383 oldControlVars[i] = f;
1388 vlc_object_release( p_aout );
1392 /**********************************************************************
1394 **********************************************************************/
1397 const char *psz_name;
1398 const char *psz_desc;
1401 static const spat_controls_t spat_controls[] =
1403 { "spatializer-roomsize", _("Size") },
1404 { "spatializer-width", _("Width") },
1405 { "spatializer-wet", _("Wet") },
1406 { "spatializer-dry", _("Dry") },
1407 { "spatializer-damp", _("Damp") },
1410 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
1411 : QWidget( _parent ) , p_intf( _p_intf )
1413 QFont smallFont = QApplication::font();
1414 smallFont.setPointSize( smallFont.pointSize() - 1 );
1416 QGridLayout *layout = new QGridLayout( this );
1418 enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1419 layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1421 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1423 spatCtrl[i] = new QSlider( Qt::Vertical );
1424 spatCtrl[i]->setValue( (int)var_InheritFloat( p_intf, spat_controls[i].psz_name ) * 10. );
1425 oldControlVars[i] = spatCtrl[i]->value();
1427 ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
1428 ctrl_texts[i]->setFont( smallFont );
1430 ctrl_readout[i] = new QLabel;
1431 ctrl_readout[i]->setFont( smallFont );
1433 layout->addWidget( spatCtrl[i], 1, i, Qt::AlignHCenter );
1434 layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
1435 layout->addWidget( ctrl_texts[i], 3, i, Qt::AlignHCenter );
1436 spatCtrl[i]->setRange( 0, 10 );
1438 spatCtrl[0]->setRange( 0, 11 );
1440 for( int i = 0; i < NUM_SP_CTRL; i++ )
1441 CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1443 BUTTONACT( enableCheck, enable() );
1445 /* Write down initial values */
1446 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1451 psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1452 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1454 controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
1456 vlc_object_release( p_aout );
1460 psz_af = config_GetPsz( p_intf, "audio-filter" );
1461 for( int i = 0; i < NUM_SP_CTRL ; i++ )
1463 controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
1466 if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1467 enableCheck->setChecked( true );
1469 enable( enableCheck->isChecked() );
1473 void Spatializer::enable()
1475 bool en = enableCheck->isChecked();
1476 playlist_EnableAudioFilter( THEPL, "spatializer", en );
1480 void Spatializer::enable( bool en )
1482 for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1484 spatCtrl[i]->setEnabled( en );
1485 ctrl_texts[i]->setEnabled( en );
1486 ctrl_readout[i]->setEnabled( en );
1489 void Spatializer::setInitValues()
1494 void Spatializer::setValues()
1496 vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
1498 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1500 float f = (float)( spatCtrl[i]->value() ) / 10;
1501 ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
1506 for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1508 float f = (float)( spatCtrl[i]->value() ) / 10 ;
1509 if( oldControlVars[i] != spatCtrl[i]->value() )
1511 var_SetFloat( p_aout, spat_controls[i].psz_name, f );
1512 config_PutFloat( p_intf, spat_controls[i].psz_name, f );
1513 oldControlVars[i] = spatCtrl[i]->value();
1516 vlc_object_release( p_aout );
1520 void Spatializer::delCallbacks( vlc_object_t *p_aout )
1522 VLC_UNUSED( p_aout );
1523 // var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1524 // var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1527 void Spatializer::addCallbacks( vlc_object_t *p_aout )
1529 VLC_UNUSED( p_aout );
1530 // var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1531 // var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1534 #include <QToolButton>
1535 #include <QGridLayout>
1537 #define SUBSDELAY_CFG_MODE "subsdelay-mode"
1538 #define SUBSDELAY_CFG_FACTOR "subsdelay-factor"
1539 #define SUBSDELAY_MODE_ABSOLUTE 0
1540 #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY 1
1541 #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
1543 SyncWidget::SyncWidget( QWidget *_parent ) : QWidget( _parent )
1545 QHBoxLayout *layout = new QHBoxLayout;
1546 spinBox.setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1547 spinBox.setDecimals( 3 );
1548 spinBox.setMinimum( -600.0 );
1549 spinBox.setMaximum( 600.0 );
1550 spinBox.setSingleStep( 0.1 );
1551 spinBox.setSuffix( " s" );
1552 spinBox.setButtonSymbols( QDoubleSpinBox::PlusMinus );
1553 CONNECT( &spinBox, valueChanged( double ), this, valueChangedHandler( double ) );
1554 layout->addWidget( &spinBox );
1555 layout->addWidget( &spinLabel );
1556 layout->setContentsMargins( 0, 0, 0, 0 );
1557 setLayout( layout );
1560 void SyncWidget::valueChangedHandler( double d )
1563 spinLabel.setText( qtr("(Hastened)") );
1565 spinLabel.setText( qtr("(Delayed)") );
1567 spinLabel.setText( "" );
1568 emit valueChanged( d );
1571 void SyncWidget::setValue( double d )
1573 spinBox.setValue( d );
1576 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1577 QWidget( _parent ) , p_intf( _p_intf )
1579 QGroupBox *AVBox, *subsBox;
1580 QToolButton *updateButton;
1582 b_userAction = true;
1584 QGridLayout *mainLayout = new QGridLayout( this );
1587 AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1588 QGridLayout *AVLayout = new QGridLayout( AVBox );
1590 QLabel *AVLabel = new QLabel;
1591 AVLabel->setText( qtr( "Audio track synchronization:" ) );
1592 AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1594 AVSpin = new SyncWidget( this );
1595 AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1596 mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1599 subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1600 QGridLayout *subsLayout = new QGridLayout( subsBox );
1602 QLabel *subsLabel = new QLabel;
1603 subsLabel->setText( qtr( "Subtitle track syncronization:" ) );
1604 subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1606 subsSpin = new SyncWidget( this );
1607 subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1609 QLabel *subSpeedLabel = new QLabel;
1610 subSpeedLabel->setText( qtr( "Subtitles speed:" ) );
1611 subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
1613 subSpeedSpin = new QDoubleSpinBox;
1614 subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1615 subSpeedSpin->setDecimals( 3 );
1616 subSpeedSpin->setMinimum( 1 );
1617 subSpeedSpin->setMaximum( 100 );
1618 subSpeedSpin->setSingleStep( 0.2 );
1619 subSpeedSpin->setSuffix( " fps" );
1620 subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1621 subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1623 QLabel *subDurationLabel = new QLabel;
1624 subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
1625 subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
1627 subDurationSpin = new QDoubleSpinBox;
1628 subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1629 subDurationSpin->setDecimals( 3 );
1630 subDurationSpin->setMinimum( 0 );
1631 subDurationSpin->setMaximum( 20 );
1632 subDurationSpin->setSingleStep( 0.2 );
1633 subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
1634 subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
1636 mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1638 updateButton = new QToolButton;
1639 updateButton->setAutoRaise( true );
1640 mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1642 /* Various Connects */
1643 CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1644 CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1645 CONNECT( subSpeedSpin, valueChanged ( double ),
1646 this, adjustSubsSpeed( double ) );
1647 CONNECT( subDurationSpin, valueChanged ( double ),
1648 this, adjustSubsDuration( double ) );
1650 CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1651 BUTTON_SET_ACT_I( updateButton, "", update,
1652 qtr( "Force update of this dialog's values" ), update() );
1660 SyncControls::~SyncControls()
1665 void SyncControls::clean()
1667 b_userAction = false;
1668 AVSpin->setValue( 0.0 );
1669 subsSpin->setValue( 0.0 );
1670 subSpeedSpin->setValue( 1.0 );
1672 b_userAction = true;
1675 void SyncControls::update()
1677 b_userAction = false;
1680 if( THEMIM->getInput() )
1682 i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1683 AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1684 i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1685 subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1686 subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1687 subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
1689 b_userAction = true;
1692 void SyncControls::advanceAudio( double f_advance )
1694 if( THEMIM->getInput() && b_userAction )
1696 int64_t i_delay = f_advance * 1000000;
1697 var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1701 void SyncControls::advanceSubs( double f_advance )
1703 if( THEMIM->getInput() && b_userAction )
1705 int64_t i_delay = f_advance * 1000000;
1706 var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1710 void SyncControls::adjustSubsSpeed( double f_fps )
1712 if( THEMIM->getInput() && b_userAction )
1714 var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1718 void SyncControls::adjustSubsDuration( double f_factor )
1720 if( THEMIM->getInput() && b_userAction )
1722 subsdelaySetFactor( f_factor );
1723 ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
1727 void SyncControls::initSubsDuration()
1729 int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
1734 case SUBSDELAY_MODE_ABSOLUTE:
1735 subDurationSpin->setToolTip( qtr( "Extend subtitles duration by this value.\n"
1736 "Set 0 to disable." ) );
1737 subDurationSpin->setSuffix( " s" );
1739 case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
1740 subDurationSpin->setToolTip( qtr( "Multiply subtitles duration by this value.\n"
1741 "Set 0 to disable." ) );
1742 subDurationSpin->setSuffix( "" );
1744 case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
1745 subDurationSpin->setToolTip( qtr( "Recalculate subtitles duration according\n"
1746 "to their content and this value.\n"
1747 "Set 0 to disable." ) );
1748 subDurationSpin->setSuffix( "" );
1753 void SyncControls::subsdelayClean()
1755 /* Remove subsdelay filter */
1756 ChangeVFiltersString( p_intf, "subsdelay", false );
1759 void SyncControls::subsdelaySetFactor( double f_factor )
1761 /* Set the factor in the preferences */
1762 config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
1764 /* Try to find an instance of subsdelay, and set its factor */
1765 vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay" );
1768 var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
1769 vlc_object_release( p_obj );
1774 /**********************************************************************
1775 * Video filters / Adjust
1776 **********************************************************************/
1778 /**********************************************************************
1779 * Extended playbak controls
1780 **********************************************************************/