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