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