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