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