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