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