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