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