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