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