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