]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
1d6bc24ae92474e308e49d66dea2ce18238e8a8f
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
1 /*****************************************************************************
2  * extended_panels.cpp : Extended controls panels
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea .t videolan d@t org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * ( at your option ) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <QLabel>
30 #include <QVariant>
31 #include <QString>
32 #include <QFont>
33 #include <QGridLayout>
34 #include <QSignalMapper>
35 #include <QComboBox>
36
37 #include "components/extended_panels.hpp"
38 #include "dialogs/preferences.hpp"
39 #include "qt4.hpp"
40 #include "input_manager.hpp"
41
42 #include <vlc_aout.h>
43 #include <vlc_intf_strings.h>
44 #include <vlc_vout.h>
45 #include <vlc_osd.h>
46
47 #include <vlc_charset.h> /* us_strtod */
48
49 #if 0
50 class ConfClickHandler : public QObject
51 {
52 public:
53     ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
54         e = _e; p_intf = _p_intf;
55     }
56     virtual ~ConfClickHandler() {}
57     bool eventFilter( QObject *obj, QEvent *evt )
58     {
59         if( evt->type() == QEvent::MouseButtonPress )
60         {
61             e->gotoConf( obj );
62             return true;
63         }
64         return false;
65     }
66 private:
67     ExtVideo* e;
68     intf_thread_t *p_intf;
69 };
70 #endif
71
72 QString ModuleFromWidgetName( QObject *obj )
73 {
74     return obj->objectName().replace( "Enable","" );
75 }
76
77 QString OptionFromWidgetName( QObject *obj )
78 {
79     /* Gruik ? ... nah */
80     QString option = obj->objectName().replace( "Slider", "" )
81                                       .replace( "Combo" , "" )
82                                       .replace( "Dial"  , "" )
83                                       .replace( "Check" , "" )
84                                       .replace( "Spin"  , "" )
85                                       .replace( "Text"  , "" );
86     for( char a = 'A'; a <= 'Z'; a++ )
87     {
88         option = option.replace( QString( a ),
89                                  QString( '-' ) + QString( a + 'a' - 'A' ) );
90     }
91     return option;
92 }
93
94 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
95                            p_intf( _p_intf )
96 {
97     ui.setupUi( _parent );
98     p_vout = NULL;
99
100 #define SETUP_VFILTER( widget ) \
101     { \
102         vlc_object_t *p_obj = ( vlc_object_t * ) \
103             vlc_object_find_name( p_intf->p_libvlc, \
104                                   #widget, \
105                                   FIND_CHILD ); \
106         QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
107         QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
108         if( p_obj ) \
109         { \
110             vlc_object_release( p_obj ); \
111             if( checkbox ) checkbox->setChecked( true ); \
112             else groupbox->setChecked( true ); \
113         } \
114         else \
115         { \
116             if( checkbox ) checkbox->setChecked( false ); \
117             else groupbox->setChecked( false ); \
118         } \
119     } \
120     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
121 #define SETUP_VFILTER_OPTION( widget, signal ) \
122     initComboBoxItems( ui.widget ); \
123     setWidgetValue( ui.widget ); \
124     CONNECT( ui.widget, signal, this, updateFilterOptions() );
125
126     SETUP_VFILTER( adjust )
127     SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
128     SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
129     SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
130     SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
131     SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
132     SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
133
134     SETUP_VFILTER( extract )
135     SETUP_VFILTER_OPTION( extractComponentText, textChanged( QString ) )
136
137     SETUP_VFILTER( colorthres )
138     SETUP_VFILTER_OPTION( colorthresColorText, textChanged( QString ) )
139     SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
140     SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
141
142     SETUP_VFILTER( invert )
143
144     SETUP_VFILTER( gradient )
145     SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
146     SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
147     SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
148
149     SETUP_VFILTER( motionblur )
150     SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
151
152     SETUP_VFILTER( motiondetect )
153
154     SETUP_VFILTER( noise )
155
156     SETUP_VFILTER( psychedelic )
157
158     SETUP_VFILTER( sharpen )
159     SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
160
161     SETUP_VFILTER( ripple )
162
163     SETUP_VFILTER( wave )
164
165     SETUP_VFILTER( transform )
166     SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
167
168     SETUP_VFILTER( rotate )
169     SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
170     ui.rotateAngleDial->setWrapping( true );
171     ui.rotateAngleDial->setNotchesVisible( true );
172
173     SETUP_VFILTER( puzzle )
174     SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
175     SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
176     SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
177
178     SETUP_VFILTER( magnify )
179
180     SETUP_VFILTER( clone )
181     SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
182
183     SETUP_VFILTER( wall )
184     SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
185     SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
186
187     SETUP_VFILTER( panoramix )
188     SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
189     SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
190
191
192     SETUP_VFILTER( erase )
193     SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
194     SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
195     SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
196
197     SETUP_VFILTER( marq )
198     SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( QString ) )
199     SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
200
201     SETUP_VFILTER( logo )
202     SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
203     SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
204     SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
205     SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
206
207 #undef SETUP_VFILTER
208 #undef SETUP_VFILTER_OPTION
209
210     CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
211     CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
212     CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
213     CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
214     CONNECT( ui.topBotCropSync, toggled( bool ),
215              ui.cropBotPx, setDisabled( bool ) );
216     CONNECT( ui.leftRightCropSync, toggled( bool ),
217              ui.cropRightPx, setDisabled( bool ) );
218 }
219
220 ExtVideo::~ExtVideo()
221 {
222 }
223
224 void ExtVideo::cropChange()
225 {
226     if( THEMIM->getInput() )
227     {
228         p_vout = ( vout_thread_t * )vlc_object_find( THEMIM->getInput(),
229                 VLC_OBJECT_VOUT, FIND_CHILD );
230         if( p_vout )
231         {
232             var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
233             var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
234             var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
235             var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
236         }
237         vlc_object_release( p_vout );
238     }
239 }
240
241 void ExtVideo::clean()
242 {
243     ui.cropTopPx->setValue( 0 );
244     ui.cropBotPx->setValue( 0 );
245     ui.cropLeftPx->setValue( 0 );
246     ui.cropRightPx->setValue( 0 );
247 }
248
249 void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
250 {
251     char *psz_parser, *psz_string;
252     const char *psz_filter_type;
253
254     module_t *p_obj = module_find( psz_name );
255     if( !p_obj )
256     {
257         msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
258         return;
259     }
260
261     if( module_provides( p_obj, "video filter2" ) )
262     {
263         psz_filter_type = "video-filter";
264     }
265     else if( module_provides( p_obj, "video filter" ) )
266     {
267         psz_filter_type = "vout-filter";
268     }
269     else if( module_provides( p_obj, "sub filter" ) )
270     {
271         psz_filter_type = "sub-filter";
272     }
273     else
274     {
275         module_release (p_obj);
276         msg_Err( p_intf, "Unknown video filter type." );
277         return;
278     }
279     module_release (p_obj);
280
281     psz_string = config_GetPsz( p_intf, psz_filter_type );
282
283     if( !psz_string ) psz_string = strdup( "" );
284
285     psz_parser = strstr( psz_string, psz_name );
286
287     if( b_add )
288     {
289         if( !psz_parser )
290         {
291             psz_parser = psz_string;
292             if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
293                             psz_string, psz_name ) == -1 )
294             {
295                 free( psz_parser );
296                 return;
297             }
298             free( psz_parser );
299         }
300         else
301         {
302             return;
303         }
304     }
305     else
306     {
307         if( psz_parser )
308         {
309             if( *( psz_parser + strlen( psz_name ) ) == ':' )
310             {
311                 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
312                          strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
313             }
314             else
315             {
316                 *psz_parser = '\0';
317             }
318
319             /* Remove trailing : : */
320             if( strlen( psz_string ) > 0 &&
321                 *( psz_string + strlen( psz_string ) -1 ) == ':' )
322             {
323                 *( psz_string + strlen( psz_string ) -1 ) = '\0';
324             }
325         }
326         else
327         {
328             free( psz_string );
329             return;
330         }
331     }
332     /* Vout is not kept, so put that in the config */
333     config_PutPsz( p_intf, psz_filter_type, psz_string );
334     if( !strcmp( psz_filter_type, "video-filter" ) )
335         ui.videoFilterText->setText( psz_string );
336     else if( !strcmp( psz_filter_type, "vout-filter" ) )
337         ui.voutFilterText->setText( psz_string );
338     else if( !strcmp( psz_filter_type, "sub-filter" ) )
339         ui.subpictureFilterText->setText( psz_string );
340
341     /* Try to set on the fly */
342     if( THEMIM->getInput() )
343         p_vout = ( vout_thread_t * )vlc_object_find( THEMIM->getInput(),
344                 VLC_OBJECT_VOUT, FIND_CHILD );
345     /* If you have stopped the video, p_vout is still at its old value */
346     else
347         p_vout = NULL;
348
349     if( p_vout )
350     {
351         if( !strcmp( psz_filter_type, "sub-filter" ) )
352             var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
353         else
354             var_SetString( p_vout, psz_filter_type, psz_string );
355         vlc_object_release( p_vout );
356     }
357
358     free( psz_string );
359 }
360
361 void ExtVideo::updateFilters()
362 {
363     QString module = ModuleFromWidgetName( sender() );
364
365     QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
366     QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
367
368     ChangeVFiltersString( qtu( module ),
369                           checkbox ? checkbox->isChecked()
370                                    : groupbox->isChecked() );
371 }
372
373 void ExtVideo::initComboBoxItems( QObject *widget )
374 {
375     QComboBox *combobox = qobject_cast<QComboBox*>( widget );
376     if( !combobox ) return;
377     QString option = OptionFromWidgetName( widget );
378     module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
379                                                  qtu( option ) );
380     if( p_item )
381     {
382         int i_type = p_item->i_type & CONFIG_ITEM;
383         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
384         {
385             if( i_type == CONFIG_ITEM_INTEGER
386              || i_type == CONFIG_ITEM_BOOL )
387                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
388                                    p_item->pi_list[i_index] );
389             else if( i_type == CONFIG_ITEM_STRING )
390                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
391                                    p_item->ppsz_list[i_index] );
392         }
393     }
394     else
395     {
396         msg_Err( p_intf, "Couldn't find option \"%s\".",
397                  qtu( option ) );
398     }
399 }
400
401 void ExtVideo::setWidgetValue( QObject *widget )
402 {
403     QString module = ModuleFromWidgetName( widget->parent() );
404     //std::cout << "Module name: " << module.toStdString() << std::endl;
405     QString option = OptionFromWidgetName( widget );
406     //std::cout << "Option name: " << option.toStdString() << std::endl;
407
408     vlc_object_t *p_obj = ( vlc_object_t * )
409         vlc_object_find_name( p_intf->p_libvlc,
410                               qtu( module ),
411                               FIND_CHILD );
412     int i_type;
413     vlc_value_t val;
414
415     if( !p_obj )
416     {
417 #if 0
418         msg_Dbg( p_intf,
419                  "Module instance %s not found, looking in config values.",
420                  qtu( module ) );
421 #endif
422         i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
423         switch( i_type )
424         {
425             case VLC_VAR_INTEGER:
426             case VLC_VAR_BOOL:
427                 val.i_int = config_GetInt( p_intf, qtu( option ) );
428                 break;
429             case VLC_VAR_FLOAT:
430                 val.f_float = config_GetFloat( p_intf, qtu( option ) );
431                 break;
432             case VLC_VAR_STRING:
433                 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
434                 break;
435         }
436     }
437     else
438     {
439         i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
440         var_Get( p_obj, qtu( option ), &val );
441         vlc_object_release( p_obj );
442     }
443
444     /* Try to cast to all the widgets we're likely to encounter. Only
445      * one of the casts is expected to work. */
446     QSlider        *slider        = qobject_cast<QSlider*>       ( widget );
447     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( widget );
448     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( widget );
449     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
450     QDial          *dial          = qobject_cast<QDial*>         ( widget );
451     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( widget );
452     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( widget );
453
454     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
455     {
456         int i_int = 0;
457         if( slider )        slider->setValue( val.i_int );
458         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
459                                                               : Qt::Unchecked );
460         else if( spinbox )  spinbox->setValue( val.i_int );
461         else if( dial )     dial->setValue( ( 540-val.i_int )%360 );
462         else if( lineedit )
463         {
464             char str[30];
465             snprintf( str, sizeof(str), "%06X", val.i_int );
466             lineedit->setText( str );
467         }
468         else if( combobox ) combobox->setCurrentIndex(
469                             combobox->findData( val.i_int ) );
470         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
471     }
472     else if( i_type == VLC_VAR_FLOAT )
473     {
474         double f_float = 0;
475         if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
476         else if( doublespinbox ) doublespinbox->setValue( val.f_float );
477         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
478     }
479     else if( i_type == VLC_VAR_STRING )
480     {
481         if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
482         else if( combobox ) combobox->setCurrentIndex(
483                             combobox->findData( qfu( val.psz_string ) ) );
484         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
485         free( val.psz_string );
486     }
487     else
488         msg_Err( p_intf,
489                  "Module %s's %s variable is of an unsupported type ( %d )",
490                  qtu( module ),
491                  qtu( option ),
492                  i_type );
493 }
494
495 void ExtVideo::updateFilterOptions()
496 {
497     QString module = ModuleFromWidgetName( sender()->parent() );
498     //std::cout << "Module name: " << module.toStdString() << std::endl;
499     QString option = OptionFromWidgetName( sender() );
500     //std::cout << "Option name: " << option.toStdString() << std::endl;
501
502     vlc_object_t *p_obj = ( vlc_object_t * )
503         vlc_object_find_name( p_intf->p_libvlc,
504                               qtu( module ),
505                               FIND_CHILD );
506     int i_type;
507     bool b_is_command;
508     if( !p_obj )
509     {
510         msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
511         i_type = config_GetType( p_intf, qtu( option ) );
512         b_is_command = false;
513     }
514     else
515     {
516         i_type = var_Type( p_obj, qtu( option ) );
517         b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
518     }
519
520     if( !b_is_command )
521     {
522         msg_Warn( p_intf, "Module %s's %s variable isn't a command. You'll need to restart the filter to take change into account.",
523                  qtu( module ),
524                  qtu( option ) );
525         /* FIXME: restart automatically somewhere near the end of this function */
526     }
527
528     /* Try to cast to all the widgets we're likely to encounter. Only
529      * one of the casts is expected to work. */
530     QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
531     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
532     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
533     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
534     QDial          *dial          = qobject_cast<QDial*>         ( sender() );
535     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
536     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );
537
538     i_type &= 0xf0;
539     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
540     {
541         int i_int = 0;
542         if( slider )        i_int = slider->value();
543         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
544         else if( spinbox )  i_int = spinbox->value();
545         else if( dial )     i_int = ( 540-dial->value() )%360;
546         else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
547         else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
548         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
549         config_PutInt( p_intf, qtu( option ), i_int );
550         if( b_is_command )
551         {
552             if( i_type == VLC_VAR_INTEGER )
553                 var_SetInteger( p_obj, qtu( option ), i_int );
554             else
555                 var_SetBool( p_obj, qtu( option ), i_int );
556         }
557     }
558     else if( i_type == VLC_VAR_FLOAT )
559     {
560         double f_float = 0;
561         if( slider )             f_float = ( double )slider->value()
562                                          / ( double )slider->tickInterval(); /* hack alert! */
563         else if( doublespinbox ) f_float = doublespinbox->value();
564         else if( lineedit ) f_float = lineedit->text().toDouble();
565         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
566         config_PutFloat( p_intf, qtu( option ), f_float );
567         if( b_is_command )
568             var_SetFloat( p_obj, qtu( option ), f_float );
569     }
570     else if( i_type == VLC_VAR_STRING )
571     {
572         char *psz_string = NULL;
573         if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
574         else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
575                                        combobox->currentIndex() ).toString() ) );
576         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
577         config_PutPsz( p_intf, qtu( option ), psz_string );
578         if( b_is_command )
579             var_SetString( p_obj, qtu( option ), psz_string );
580         free( psz_string );
581     }
582     else
583         msg_Err( p_intf,
584                  "Module %s's %s variable is of an unsupported type ( %d )",
585                  qtu( module ),
586                  qtu( option ),
587                  i_type );
588
589     if( p_obj ) vlc_object_release( p_obj );
590 }
591
592 #if 0
593 void ExtVideo::gotoConf( QObject* src )
594 {
595 #define SHOWCONF( module ) \
596     if( src->objectName().contains( module ) ) \
597     { \
598         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
599         return; \
600     }
601     SHOWCONF( "clone" );
602     SHOWCONF( "magnify" );
603     SHOWCONF( "wave" );
604     SHOWCONF( "ripple" );
605     SHOWCONF( "invert" );
606     SHOWCONF( "puzzle" );
607     SHOWCONF( "wall" );
608     SHOWCONF( "gradient" );
609     SHOWCONF( "colorthres" )
610 }
611 #endif
612
613 /**********************************************************************
614  * v4l2 controls
615  **********************************************************************/
616
617 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
618     : QWidget( _parent ), p_intf( _p_intf )
619 {
620     ui.setupUi( this );
621
622     BUTTONACT( ui.refresh, Refresh() );
623
624     box = NULL;
625 }
626
627 ExtV4l2::~ExtV4l2()
628 {
629     if( box )
630         delete box;
631 }
632
633 void ExtV4l2::showEvent( QShowEvent *event )
634 {
635     QWidget::showEvent( event );
636     Refresh();
637 }
638
639 void ExtV4l2::Refresh( void )
640 {
641     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
642     ui.help->hide();
643     if( box )
644     {
645         ui.vboxLayout->removeWidget( box );
646         delete box;
647         box = NULL;
648     }
649     if( p_obj )
650     {
651         vlc_value_t val, text, name;
652         int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
653                                 &val, &text );
654         if( i_ret < 0 )
655         {
656             msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
657             ui.help->show();
658             vlc_object_release( p_obj );
659             return;
660         }
661
662         box = new QGroupBox( this );
663         ui.vboxLayout->addWidget( box );
664         QVBoxLayout *layout = new QVBoxLayout( box );
665         box->setLayout( layout );
666
667         for( int i = 0; i < val.p_list->i_count; i++ )
668         {
669             const char *psz_var = text.p_list->p_values[i].psz_string;
670             var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
671             const char *psz_label = name.psz_string;
672             msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
673                      val.p_list->p_values[i].i_int, psz_var, name.psz_string );
674
675             int i_type = var_Type( p_obj, psz_var );
676             switch( i_type & VLC_VAR_TYPE )
677             {
678                 case VLC_VAR_INTEGER:
679                 {
680                     QLabel *label = new QLabel( psz_label, box );
681                     QHBoxLayout *hlayout = new QHBoxLayout();
682                     hlayout->addWidget( label );
683                     int i_val = var_GetInteger( p_obj, psz_var );
684                     if( i_type & VLC_VAR_HASCHOICE )
685                     {
686                         QComboBox *combobox = new QComboBox( box );
687                         combobox->setObjectName( psz_var );
688
689                         vlc_value_t val2, text2;
690                         var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
691                                     &val2, &text2 );
692                         for( int j = 0; j < val2.p_list->i_count; j++ )
693                         {
694                             combobox->addItem(
695                                        text2.p_list->p_values[j].psz_string,
696                                        val2.p_list->p_values[j].i_int );
697                             if( i_val == val2.p_list->p_values[j].i_int )
698                                 combobox->setCurrentIndex( j );
699                         }
700                         var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
701                                     &val2, &text2 );
702
703                         CONNECT( combobox, currentIndexChanged( int ), this,
704                                  ValueChange( int ) );
705                         hlayout->addWidget( combobox );
706                     }
707                     else
708                     {
709                         QSlider *slider = new QSlider( box );
710                         slider->setObjectName( psz_var );
711                         slider->setOrientation( Qt::Horizontal );
712                         vlc_value_t val2;
713                         var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
714                                     &val2, NULL );
715                         slider->setMinimum( val2.i_int );
716                         var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
717                                     &val2, NULL );
718                         slider->setMaximum( val2.i_int );
719                         var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
720                                     &val2, NULL );
721                         slider->setSingleStep( val2.i_int );
722                         slider->setValue( i_val );
723
724                         CONNECT( slider, valueChanged( int ), this,
725                                  ValueChange( int ) );
726                         hlayout->addWidget( slider );
727                     }
728                     layout->addLayout( hlayout );
729                     break;
730                 }
731                 case VLC_VAR_BOOL:
732                 {
733                     QCheckBox *button = new QCheckBox( psz_label, box );
734                     button->setObjectName( psz_var );
735                     button->setChecked( var_GetBool( p_obj, psz_var ) );
736
737                     CONNECT( button, clicked( bool ), this,
738                              ValueChange( bool ) );
739                     layout->addWidget( button );
740                     break;
741                 }
742                 case VLC_VAR_VOID:
743                 {
744                     if( i_type & VLC_VAR_ISCOMMAND )
745                     {
746                         QPushButton *button = new QPushButton( psz_label, box );
747                         button->setObjectName( psz_var );
748
749                         CONNECT( button, clicked( bool ), this,
750                                  ValueChange( bool ) );
751                         layout->addWidget( button );
752                     }
753                     else
754                     {
755                         QLabel *label = new QLabel( psz_label, box );
756                         layout->addWidget( label );
757                     }
758                     break;
759                 }
760                 default:
761                     msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
762                     break;
763             }
764             free( name.psz_string );
765         }
766         var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
767         vlc_object_release( p_obj );
768     }
769     else
770     {
771         msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
772         ui.help->show();
773     }
774 }
775
776 void ExtV4l2::ValueChange( bool value )
777 {
778     ValueChange( (int)value );
779 }
780
781 void ExtV4l2::ValueChange( int value )
782 {
783     QObject *s = sender();
784     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
785     if( p_obj )
786     {
787         char *psz_var = strdup( qtu( s->objectName() ) );
788         int i_type = var_Type( p_obj, psz_var );
789         switch( i_type & VLC_VAR_TYPE )
790         {
791             case VLC_VAR_INTEGER:
792                 if( i_type & VLC_VAR_HASCHOICE )
793                 {
794                     QComboBox *combobox = qobject_cast<QComboBox*>( s );
795                     value = combobox->itemData( value ).toInt();
796                 }
797                 var_SetInteger( p_obj, psz_var, value );
798                 break;
799             case VLC_VAR_BOOL:
800                 var_SetBool( p_obj, psz_var, value );
801                 break;
802             case VLC_VAR_VOID:
803                 var_SetVoid( p_obj, psz_var );
804                 break;
805         }
806         free( psz_var );
807         vlc_object_release( p_obj );
808     }
809     else
810     {
811         msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
812         Refresh();
813     }
814 }
815
816 /**********************************************************************
817  * Equalizer
818  **********************************************************************/
819
820 static const QString band_frequencies[] =
821 {
822     "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
823     "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
824 };
825
826 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
827                             QWidget( _parent ) , p_intf( _p_intf )
828 {
829     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
830     smallFont.setPointSize( smallFont.pointSize() - 3 );
831
832     ui.setupUi( this );
833     ui.preampLabel->setFont( smallFont );
834
835     /* Setup of presetsComboBox */
836     presetsComboBox = ui.presetsCombo;
837     CONNECT( presetsComboBox, currentIndexChanged( int ),
838              this, updateUISliderValues( int ) );
839     CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
840
841     /* Add the sliders for the Bands */
842     QGridLayout *grid = new QGridLayout( ui.frame );
843     grid->setMargin( 0 );
844     for( int i = 0 ; i < BANDS ; i++ )
845     {
846         bands[i] = new QSlider( Qt::Vertical );
847         bands[i]->setMaximum( 400 );
848         bands[i]->setValue( 200 );
849         CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
850
851         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
852         band_texts[i]->setFont( smallFont );
853
854         grid->addWidget( bands[i], 0, i );
855         grid->addWidget( band_texts[i], 1, i );
856     }
857
858     /* Add the listed presets */
859     for( int i = 0 ; i < NB_PRESETS ; i ++ )
860     {
861         presetsComboBox->addItem( qtr( preset_list_text[i] ),
862                                   QVariant( preset_list[i] ) );
863     }
864
865     /* Connects */
866     BUTTONACT( ui.enableCheck, enable() );
867     BUTTONACT( ui.eq2PassCheck, set2Pass() );
868     CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
869
870     /* Do the update from the value of the core */
871     updateUIFromCore();
872 }
873
874 Equalizer::~Equalizer()
875 {
876 }
877
878 void Equalizer::clean()
879 {
880     enable();
881 }
882 /* Write down initial values */
883 void Equalizer::updateUIFromCore()
884 {
885     char *psz_af;
886     float f_preamp;
887     int i_preset;
888
889     aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
890                                     VLC_OBJECT_AOUT, FIND_ANYWHERE );
891     if( p_aout )
892     {
893         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
894         if( var_GetBool( p_aout, "equalizer-2pass" ) )
895             ui.eq2PassCheck->setChecked( true );
896         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
897         i_preset = presetsComboBox->findData( QVariant(
898                     var_GetString( p_aout, "equalizer-preset" ) ) );
899         vlc_object_release( p_aout );
900     }
901     else
902     {
903         psz_af = config_GetPsz( p_intf, "audio-filter" );
904         if( config_GetInt( p_intf, "equalizer-2pass" ) )
905             ui.eq2PassCheck->setChecked( true );
906         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
907         i_preset = presetsComboBox->findData( QVariant(
908                     config_GetPsz( p_intf, "equalizer-preset" ) ) );
909     }
910     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
911         ui.enableCheck->setChecked( true );
912     enable( ui.enableCheck->isChecked() );
913
914     presetsComboBox->setCurrentIndex( i_preset );
915
916     free( psz_af );
917 }
918
919 /* Functin called when enableButton is toggled */
920 void Equalizer::enable()
921 {
922     bool en = ui.enableCheck->isChecked();
923     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
924                        en ? true : false );
925 //    aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
926 //                       en ? true : false );
927 //     aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
928 //                       en ? true : false );
929     enable( en );
930
931     if( presetsComboBox->currentIndex() < 0 )
932         presetsComboBox->setCurrentIndex( 0 );
933
934 }
935
936 void Equalizer::enable( bool en )
937 {
938     ui.eq2PassCheck->setEnabled( en );
939     presetsComboBox->setEnabled( en );
940     ui.presetLabel->setEnabled( en );
941     ui.preampLabel->setEnabled( en );
942     ui.preampSlider->setEnabled( en  );
943     for( int i = 0 ; i< BANDS; i++ )
944     {
945         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
946     }
947 }
948
949 /* Function called when the set2Pass button is activated */
950 void Equalizer::set2Pass()
951 {
952     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
953                                  VLC_OBJECT_AOUT, FIND_ANYWHERE );
954     bool b_2p = ui.eq2PassCheck->isChecked();
955
956     if( p_aout == NULL )
957         config_PutInt( p_intf, "equalizer-2pass", b_2p );
958     else
959     {
960         var_SetBool( p_aout, "equalizer-2pass", b_2p );
961         config_PutInt( p_intf, "equalizer-2pass", b_2p );
962         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
963         {
964             p_aout->pp_inputs[i]->b_restart = true;
965         }
966         vlc_object_release( p_aout );
967     }
968 }
969
970 /* Function called when the preamp slider is moved */
971 void Equalizer::setPreamp()
972 {
973     const float f = ( float )(  ui.preampSlider->value() ) /10 - 20;
974     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
975                                        VLC_OBJECT_AOUT, FIND_ANYWHERE );
976
977     ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
978                                                + qtr( "dB" ) );
979     if( p_aout )
980     {
981         //delCallbacks( p_aout );
982         var_SetFloat( p_aout, "equalizer-preamp", f );
983         //addCallbacks( p_aout );
984         vlc_object_release( p_aout );
985     }
986     config_PutFloat( p_intf, "equalizer-preamp", f );
987 }
988
989 void Equalizer::setCoreBands()
990 {
991     /**\todo smoothing */
992
993     QString values;
994     for( int i = 0; i < BANDS; i++ )
995     {
996         const float f_val = (float)( bands[i]->value() ) / 10 - 20;
997         QString val = QString("%1").arg( f_val, 5, 'f', 1 );
998
999         band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1000         values += " " + val;
1001     }
1002     const char *psz_values = values.toAscii().constData();
1003
1004     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
1005                                           VLC_OBJECT_AOUT, FIND_ANYWHERE );
1006     if( p_aout )
1007     {
1008         //delCallbacks( p_aout );
1009         var_SetString( p_aout, "equalizer-bands", psz_values );
1010         //addCallbacks( p_aout );
1011         vlc_object_release( p_aout );
1012     }
1013 }
1014
1015 void Equalizer::updateUISliderValues( int i_preset )
1016 {
1017     if( i_preset < 0 ) return;
1018
1019     char *p = createValuesFromPreset( i_preset );
1020     char *psz = p;
1021     float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1022
1023     if ( p )
1024     {
1025         for( int i = 0; i < BANDS; i++ )
1026         {
1027             const float f = us_strtod(p, &p );
1028
1029             bands[i]->setValue( (int)( ( f + 20 ) * 10 )  );
1030
1031             band_texts[i]->setText( band_frequencies[i] + "\n"
1032                                   + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1033             if( p == NULL || *p == '\0' )
1034                 break;
1035             p++;
1036             if( *p == '\0' )
1037                 break;
1038         }
1039         free( psz );
1040     }
1041     ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1042     ui.preampLabel->setText( qtr( "Preamp\n" )
1043                    + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1044 }
1045
1046 char * Equalizer::createValuesFromPreset( int i_preset )
1047 {
1048     char *psz_values;
1049     QString values;
1050
1051     /* Create the QString in Qt */
1052     for( int i = 0 ; i< BANDS ;i++ )
1053         values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1054
1055     /* Convert it to char * */
1056     if( !asprintf( &psz_values, "%s", values.toAscii().constData() ) )
1057         return NULL;
1058
1059     return psz_values;
1060 }
1061
1062 void Equalizer::setCorePreset( int i_preset )
1063 {
1064     char *psz_values = createValuesFromPreset( i_preset );
1065     if( !psz_values ) return ;
1066
1067     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
1068                                                VLC_OBJECT_AOUT, FIND_ANYWHERE );
1069     if( p_aout )
1070     {
1071         delCallbacks( p_aout );
1072         var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1073
1074         var_SetString( p_aout, "equalizer-bands", psz_values );
1075         var_SetFloat( p_aout, "equalizer-preamp",
1076                       eqz_preset_10b[i_preset]->f_preamp );
1077         addCallbacks( p_aout );
1078         vlc_object_release( p_aout );
1079     }
1080     config_PutPsz( p_intf, "equalizer-bands", psz_values );
1081     config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1082     config_PutFloat( p_intf, "equalizer-preamp",
1083                     eqz_preset_10b[i_preset]->f_preamp );
1084 }
1085
1086 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1087                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1088 {
1089     char *psz_preset = newval.psz_string;
1090     Equalizer *eq = ( Equalizer * )p_data;
1091     int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1092     eq->presetsComboBox->setCurrentIndex( i_preset );
1093     return VLC_SUCCESS;
1094 }
1095
1096 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1097 {
1098     //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1099     //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1100     var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1101 }
1102
1103 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1104 {
1105     //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1106     //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1107     var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1108 }
1109
1110 /**********************************************************************
1111  * Audio filters
1112  **********************************************************************/
1113
1114 /**********************************************************************
1115  * Spatializer
1116  **********************************************************************/
1117 static const char *psz_control_names[] =
1118 {
1119     "Roomsize", "Width" , "Wet", "Dry", "Damp"
1120 };
1121
1122 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1123     QWidget( _parent ) , p_intf( _p_intf )
1124 {
1125     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1126     smallFont.setPointSize( smallFont.pointSize() - 3 );
1127
1128     QGridLayout *layout = new QGridLayout( this );
1129     layout->setMargin( 0 );
1130
1131     enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1132     layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1133
1134     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1135     {
1136         spatCtrl[i] = new QSlider( Qt::Vertical );
1137         if( i < 2 )
1138         {
1139             spatCtrl[i]->setMaximum( 10 );
1140             spatCtrl[i]->setValue( 2 );
1141         }
1142         else
1143         {
1144             spatCtrl[i]->setMaximum( 10 );
1145             spatCtrl[i]->setValue( 0 );
1146             spatCtrl[i]->setMinimum( -10 );
1147         }
1148         oldControlVars[i] = spatCtrl[i]->value();
1149         CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1150         ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1151         ctrl_texts[i]->setFont( smallFont );
1152         ctrl_readout[i] = new QLabel( "" );
1153         ctrl_readout[i]->setFont( smallFont );
1154         layout->addWidget( spatCtrl[i], 1, i );
1155         layout->addWidget( ctrl_readout[i], 2, i );
1156         layout->addWidget( ctrl_texts[i], 3, i );
1157     }
1158
1159     BUTTONACT( enableCheck, enable() );
1160
1161     /* Write down initial values */
1162     aout_instance_t *p_aout = ( aout_instance_t * )
1163         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1164     char *psz_af;
1165
1166     if( p_aout )
1167     {
1168         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1169         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1170         {
1171             controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1172         }
1173         vlc_object_release( p_aout );
1174     }
1175     else
1176     {
1177         psz_af = config_GetPsz( p_intf, "audio-filter" );
1178         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1179         {
1180             controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1181         }
1182     }
1183     if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1184         enableCheck->setChecked( true );
1185     free( psz_af );
1186     enable( enableCheck->isChecked() );
1187     setValues( controlVars );
1188 }
1189
1190 Spatializer::~Spatializer()
1191 {
1192 }
1193
1194 void Spatializer::enable()
1195 {
1196     bool en = enableCheck->isChecked();
1197     aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1198             en ? true : false );
1199     enable( en );
1200 }
1201
1202 void Spatializer::enable( bool en )
1203 {
1204     for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1205     {
1206         spatCtrl[i]->setEnabled( en );
1207         ctrl_texts[i]->setEnabled( en );
1208         ctrl_readout[i]->setEnabled( en );
1209     }
1210 }
1211 void Spatializer::setInitValues()
1212 {
1213     setValues( controlVars );
1214 }
1215
1216 void Spatializer::setValues( float *controlVars )
1217 {
1218     aout_instance_t *p_aout= ( aout_instance_t * )
1219         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1220
1221     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1222     {
1223         float f = (float)(  spatCtrl[i]->value() );
1224         ctrl_readout[i]->setText( QString::number( f, 'f',  1 ) );
1225     }
1226     if( p_aout )
1227     {
1228         for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1229         {
1230             if( oldControlVars[i] != spatCtrl[i]->value() )
1231             {
1232                 var_SetFloat( p_aout, psz_control_names[i],
1233                         ( float )spatCtrl[i]->value() );
1234                 config_PutFloat( p_intf, psz_control_names[i],
1235                         ( float ) spatCtrl[i]->value() );
1236                 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1237             }
1238         }
1239         vlc_object_release( p_aout );
1240     }
1241
1242 }
1243 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1244 {
1245     //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1246     //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1247 }
1248
1249 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1250 {
1251     //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1252     //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1253 }
1254
1255 #include <QToolButton>
1256 #include <QGridLayout>
1257
1258 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1259                             QWidget( _parent ) , p_intf( _p_intf )
1260 {
1261     QGroupBox *AVBox, *subsBox;
1262
1263     QToolButton *moinsAV, *plusAV;
1264     QToolButton *moinssubs, *plussubs;
1265     QToolButton *moinssubSpeed, *plussubSpeed;
1266
1267     QToolButton *updateButton;
1268
1269     b_userAction = true;
1270
1271     QGridLayout *mainLayout = new QGridLayout( this );
1272
1273     /* AV sync */
1274     AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1275     QGridLayout *AVLayout = new QGridLayout( AVBox );
1276
1277     moinsAV = new QToolButton;
1278     moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1279     moinsAV->setAutoRaise( true );
1280     moinsAV->setText( "-" );
1281     AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1282
1283     plusAV = new QToolButton;
1284     plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1285     plusAV->setAutoRaise( true );
1286     plusAV->setText( "+" );
1287     AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1288
1289     QLabel *AVLabel = new QLabel;
1290     AVLabel->setText( qtr( "Advance of audio over video:" ) );
1291     AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1292
1293     AVSpin = new QDoubleSpinBox;
1294     AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1295     AVSpin->setDecimals( 3 );
1296     AVSpin->setMinimum( -100.0 );
1297     AVSpin->setMaximum( 100.0 );
1298     AVSpin->setSingleStep( 0.1 );
1299     AVSpin->setToolTip( qtr( "A positive value means that\n"
1300                              "the audio is ahead of the video" ) );
1301     AVSpin->setSuffix( " s" );
1302     AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1303     mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1304
1305
1306     /* Subs */
1307     subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1308     QGridLayout *subsLayout = new QGridLayout( subsBox );
1309
1310     moinssubs = new QToolButton;
1311     moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1312     moinssubs->setAutoRaise( true );
1313     moinssubs->setText( "-" );
1314     subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1315
1316     plussubs = new QToolButton;
1317     plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1318     plussubs->setAutoRaise( true );
1319     plussubs->setText( "+" );
1320     subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1321
1322     QLabel *subsLabel = new QLabel;
1323     subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1324     subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1325
1326     subsSpin = new QDoubleSpinBox;
1327     subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1328     subsSpin->setDecimals( 3 );
1329     subsSpin->setMinimum( -100.0 );
1330     subsSpin->setMaximum( 100.0 );
1331     subsSpin->setSingleStep( 0.1 );
1332     subsSpin->setToolTip( qtr( "A positive value means that\n"
1333                              "the subtitles are ahead of the video" ) );
1334     subsSpin->setSuffix( " s" );
1335     subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1336
1337
1338     moinssubSpeed = new QToolButton;
1339     moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1340     moinssubSpeed->setAutoRaise( true );
1341     moinssubSpeed->setText( "-" );
1342     subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1343
1344     plussubSpeed = new QToolButton;
1345     plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1346     plussubSpeed->setAutoRaise( true );
1347     plussubSpeed->setText( "+" );
1348     subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1349
1350     QLabel *subSpeedLabel = new QLabel;
1351     subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1352     subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1353
1354     subSpeedSpin = new QDoubleSpinBox;
1355     subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1356     subSpeedSpin->setDecimals( 3 );
1357     subSpeedSpin->setMinimum( 1 );
1358     subSpeedSpin->setMaximum( 100 );
1359     subSpeedSpin->setSingleStep( 0.2 );
1360     subSpeedSpin->setSuffix( " fps" );
1361     subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1362
1363     mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1364
1365     updateButton = new QToolButton;
1366     updateButton->setAutoRaise( true );
1367     mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1368
1369
1370     /* Various Connects */
1371     CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1372     CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1373     CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1374     CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1375     CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1376     CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1377     CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1378     CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1379     CONNECT( subSpeedSpin, valueChanged ( double ),
1380              this, adjustSubsSpeed( double ) );
1381
1382     CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
1383     BUTTON_SET_ACT_I( updateButton, "", update,
1384             qtr( "Force update of this dialog's values" ), update() );
1385
1386     /* Set it */
1387     update();
1388 }
1389
1390 void SyncControls::clean()
1391 {
1392     b_userAction = false;
1393     AVSpin->setValue( 0.0 );
1394     subsSpin->setValue( 0.0 );
1395     subSpeedSpin->setValue( 1.0 );
1396     b_userAction = true;
1397 }
1398
1399 void SyncControls::update()
1400 {
1401     b_userAction = false;
1402
1403     int64_t i_delay;
1404     if( THEMIM->getInput() )
1405     {
1406         i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1407         AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1408         i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1409         subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1410         subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1411     }
1412     b_userAction = true;
1413 }
1414
1415 void SyncControls::advanceAudio( double f_advance )
1416 {
1417     if( THEMIM->getInput() && b_userAction )
1418     {
1419         int64_t i_delay = f_advance * 1000000;
1420         var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1421     }
1422 }
1423
1424 void SyncControls::advanceSubs( double f_advance )
1425 {
1426     if( THEMIM->getInput() && b_userAction )
1427     {
1428         int64_t i_delay = f_advance * 1000000;
1429         var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1430     }
1431 }
1432
1433 void SyncControls::adjustSubsSpeed( double f_fps )
1434 {
1435     if( THEMIM->getInput() && b_userAction )
1436     {
1437         var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1438     }
1439 }
1440
1441 /**********************************************************************
1442  * Video filters / Adjust
1443  **********************************************************************/
1444
1445 /**********************************************************************
1446  * Extended playbak controls
1447  **********************************************************************/