]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Qt: input slider and other widgets cleaning.
[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
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 "dialogs_provider.hpp"
40 #include "qt4.hpp"
41 #include "input_manager.hpp"
42
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                            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( QString ) )
137
138     SETUP_VFILTER( colorthres )
139     SETUP_VFILTER_OPTION( colorthresColorText, textChanged( 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( 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.topBotCropSync, toggled( bool ),
216              ui.cropBotPx, setDisabled( bool ) );
217     CONNECT( ui.leftRightCropSync, toggled( bool ),
218              ui.cropRightPx, setDisabled( bool ) );
219 }
220
221 ExtVideo::~ExtVideo()
222 {
223 }
224
225 void ExtVideo::cropChange()
226 {
227     if( THEMIM->getInput() )
228     {
229         p_vout = ( vout_thread_t * )vlc_object_find( THEMIM->getInput(),
230                 VLC_OBJECT_VOUT, FIND_CHILD );
231         if( p_vout )
232         {
233             var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
234             var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
235             var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
236             var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
237         }
238         vlc_object_release( p_vout );
239     }
240 }
241
242 void ExtVideo::clean()
243 {
244     ui.cropTopPx->setValue( 0 );
245     ui.cropBotPx->setValue( 0 );
246     ui.cropLeftPx->setValue( 0 );
247     ui.cropRightPx->setValue( 0 );
248 }
249
250 void ExtVideo::ChangeVFiltersString( char *psz_name, bool b_add )
251 {
252     char *psz_parser, *psz_string;
253     const char *psz_filter_type;
254
255     module_t *p_obj = module_find( 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_provides( p_obj, "video filter2" ) )
263     {
264         psz_filter_type = "video-filter";
265     }
266     else if( module_provides( p_obj, "video filter" ) )
267     {
268         psz_filter_type = "vout-filter";
269     }
270     else if( module_provides( p_obj, "sub filter" ) )
271     {
272         psz_filter_type = "sub-filter";
273     }
274     else
275     {
276         module_release (p_obj);
277         msg_Err( p_intf, "Unknown video filter type." );
278         return;
279     }
280     module_release (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     int i_type;
508     bool b_is_command;
509     if( !p_obj )
510     {
511         msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
512         i_type = config_GetType( p_intf, qtu( option ) );
513         b_is_command = false;
514     }
515     else
516     {
517         i_type = var_Type( p_obj, qtu( option ) );
518         b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
519     }
520
521     if( !b_is_command )
522     {
523         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.",
524                  qtu( module ),
525                  qtu( option ) );
526         /* FIXME: restart automatically somewhere near the end of this function */
527     }
528
529     /* Try to cast to all the widgets we're likely to encounter. Only
530      * one of the casts is expected to work. */
531     QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
532     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
533     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
534     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
535     QDial          *dial          = qobject_cast<QDial*>         ( sender() );
536     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
537     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );
538
539     i_type &= 0xf0;
540     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
541     {
542         int i_int = 0;
543         if( slider )        i_int = slider->value();
544         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
545         else if( spinbox )  i_int = spinbox->value();
546         else if( dial )     i_int = ( 540-dial->value() )%360;
547         else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
548         else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
549         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
550         config_PutInt( p_intf, qtu( option ), i_int );
551         if( b_is_command )
552         {
553             if( i_type == VLC_VAR_INTEGER )
554                 var_SetInteger( p_obj, qtu( option ), i_int );
555             else
556                 var_SetBool( p_obj, qtu( option ), i_int );
557         }
558     }
559     else if( i_type == VLC_VAR_FLOAT )
560     {
561         double f_float = 0;
562         if( slider )             f_float = ( double )slider->value()
563                                          / ( double )slider->tickInterval(); /* hack alert! */
564         else if( doublespinbox ) f_float = doublespinbox->value();
565         else if( lineedit ) f_float = lineedit->text().toDouble();
566         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
567         config_PutFloat( p_intf, qtu( option ), f_float );
568         if( b_is_command )
569             var_SetFloat( p_obj, qtu( option ), f_float );
570     }
571     else if( i_type == VLC_VAR_STRING )
572     {
573         char *psz_string = NULL;
574         if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
575         else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
576                                        combobox->currentIndex() ).toString() ) );
577         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
578         config_PutPsz( p_intf, qtu( option ), psz_string );
579         if( b_is_command )
580             var_SetString( p_obj, qtu( option ), psz_string );
581         free( psz_string );
582     }
583     else
584         msg_Err( p_intf,
585                  "Module %s's %s variable is of an unsupported type ( %d )",
586                  qtu( module ),
587                  qtu( option ),
588                  i_type );
589
590     if( p_obj ) vlc_object_release( p_obj );
591 }
592
593 #if 0
594 void ExtVideo::gotoConf( QObject* src )
595 {
596 #define SHOWCONF( module ) \
597     if( src->objectName().contains( module ) ) \
598     { \
599         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
600         return; \
601     }
602     SHOWCONF( "clone" );
603     SHOWCONF( "magnify" );
604     SHOWCONF( "wave" );
605     SHOWCONF( "ripple" );
606     SHOWCONF( "invert" );
607     SHOWCONF( "puzzle" );
608     SHOWCONF( "wall" );
609     SHOWCONF( "gradient" );
610     SHOWCONF( "colorthres" )
611 }
612 #endif
613
614 /**********************************************************************
615  * v4l2 controls
616  **********************************************************************/
617
618 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
619     : QWidget( _parent ), p_intf( _p_intf )
620 {
621     ui.setupUi( this );
622
623     BUTTONACT( ui.refresh, Refresh() );
624
625     box = NULL;
626 }
627
628 ExtV4l2::~ExtV4l2()
629 {
630     if( box )
631         delete box;
632 }
633
634 void ExtV4l2::showEvent( QShowEvent *event )
635 {
636     QWidget::showEvent( event );
637     Refresh();
638 }
639
640 void ExtV4l2::Refresh( void )
641 {
642     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
643     ui.help->hide();
644     if( box )
645     {
646         ui.vboxLayout->removeWidget( box );
647         delete box;
648         box = NULL;
649     }
650     if( p_obj )
651     {
652         vlc_value_t val, text, name;
653         int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
654                                 &val, &text );
655         if( i_ret < 0 )
656         {
657             msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
658             ui.help->show();
659             vlc_object_release( p_obj );
660             return;
661         }
662
663         box = new QGroupBox( this );
664         ui.vboxLayout->addWidget( box );
665         QVBoxLayout *layout = new QVBoxLayout( box );
666         box->setLayout( layout );
667
668         for( int i = 0; i < val.p_list->i_count; i++ )
669         {
670             const char *psz_var = text.p_list->p_values[i].psz_string;
671             var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
672             const char *psz_label = name.psz_string;
673             msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
674                      val.p_list->p_values[i].i_int, psz_var, name.psz_string );
675
676             int i_type = var_Type( p_obj, psz_var );
677             switch( i_type & VLC_VAR_TYPE )
678             {
679                 case VLC_VAR_INTEGER:
680                 {
681                     QLabel *label = new QLabel( psz_label, box );
682                     QHBoxLayout *hlayout = new QHBoxLayout();
683                     hlayout->addWidget( label );
684                     int i_val = var_GetInteger( p_obj, psz_var );
685                     if( i_type & VLC_VAR_HASCHOICE )
686                     {
687                         QComboBox *combobox = new QComboBox( box );
688                         combobox->setObjectName( psz_var );
689
690                         vlc_value_t val2, text2;
691                         var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
692                                     &val2, &text2 );
693                         for( int j = 0; j < val2.p_list->i_count; j++ )
694                         {
695                             combobox->addItem(
696                                        text2.p_list->p_values[j].psz_string,
697                                        val2.p_list->p_values[j].i_int );
698                             if( i_val == val2.p_list->p_values[j].i_int )
699                                 combobox->setCurrentIndex( j );
700                         }
701                         var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
702                                     &val2, &text2 );
703
704                         CONNECT( combobox, currentIndexChanged( int ), this,
705                                  ValueChange( int ) );
706                         hlayout->addWidget( combobox );
707                     }
708                     else
709                     {
710                         QSlider *slider = new QSlider( box );
711                         slider->setObjectName( psz_var );
712                         slider->setOrientation( Qt::Horizontal );
713                         vlc_value_t val2;
714                         var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
715                                     &val2, NULL );
716                         slider->setMinimum( val2.i_int );
717                         var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
718                                     &val2, NULL );
719                         slider->setMaximum( val2.i_int );
720                         var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
721                                     &val2, NULL );
722                         slider->setSingleStep( val2.i_int );
723                         slider->setValue( i_val );
724
725                         CONNECT( slider, valueChanged( int ), this,
726                                  ValueChange( int ) );
727                         hlayout->addWidget( slider );
728                     }
729                     layout->addLayout( hlayout );
730                     break;
731                 }
732                 case VLC_VAR_BOOL:
733                 {
734                     QCheckBox *button = new QCheckBox( psz_label, box );
735                     button->setObjectName( psz_var );
736                     button->setChecked( var_GetBool( p_obj, psz_var ) );
737
738                     CONNECT( button, clicked( bool ), this,
739                              ValueChange( bool ) );
740                     layout->addWidget( button );
741                     break;
742                 }
743                 case VLC_VAR_VOID:
744                 {
745                     if( i_type & VLC_VAR_ISCOMMAND )
746                     {
747                         QPushButton *button = new QPushButton( psz_label, box );
748                         button->setObjectName( psz_var );
749
750                         CONNECT( button, clicked( bool ), this,
751                                  ValueChange( bool ) );
752                         layout->addWidget( button );
753                     }
754                     else
755                     {
756                         QLabel *label = new QLabel( psz_label, box );
757                         layout->addWidget( label );
758                     }
759                     break;
760                 }
761                 default:
762                     msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
763                     break;
764             }
765             free( name.psz_string );
766         }
767         var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
768         vlc_object_release( p_obj );
769     }
770     else
771     {
772         msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
773         ui.help->show();
774     }
775 }
776
777 void ExtV4l2::ValueChange( bool value )
778 {
779     ValueChange( (int)value );
780 }
781
782 void ExtV4l2::ValueChange( int value )
783 {
784     QObject *s = sender();
785     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
786     if( p_obj )
787     {
788         char *psz_var = strdup( qtu( s->objectName() ) );
789         int i_type = var_Type( p_obj, psz_var );
790         switch( i_type & VLC_VAR_TYPE )
791         {
792             case VLC_VAR_INTEGER:
793                 if( i_type & VLC_VAR_HASCHOICE )
794                 {
795                     QComboBox *combobox = qobject_cast<QComboBox*>( s );
796                     value = combobox->itemData( value ).toInt();
797                 }
798                 var_SetInteger( p_obj, psz_var, value );
799                 break;
800             case VLC_VAR_BOOL:
801                 var_SetBool( p_obj, psz_var, value );
802                 break;
803             case VLC_VAR_VOID:
804                 var_SetVoid( p_obj, psz_var );
805                 break;
806         }
807         free( psz_var );
808         vlc_object_release( p_obj );
809     }
810     else
811     {
812         msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
813         Refresh();
814     }
815 }
816
817 /**********************************************************************
818  * Equalizer
819  **********************************************************************/
820
821 static const QString band_frequencies[] =
822 {
823     "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
824     "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
825 };
826
827 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
828                             QWidget( _parent ) , p_intf( _p_intf )
829 {
830     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
831     smallFont.setPointSize( smallFont.pointSize() - 3 );
832
833     ui.setupUi( this );
834     ui.preampLabel->setFont( smallFont );
835
836     /* Setup of presetsComboBox */
837     presetsComboBox = ui.presetsCombo;
838     CONNECT( presetsComboBox, currentIndexChanged( int ),
839              this, updateUISliderValues( int ) );
840     CONNECT( presetsComboBox, activated( int ), this, setCorePreset( int ) );
841
842     /* Add the sliders for the Bands */
843     QGridLayout *grid = new QGridLayout( ui.frame );
844     grid->setMargin( 0 );
845     for( int i = 0 ; i < BANDS ; i++ )
846     {
847         bands[i] = new QSlider( Qt::Vertical );
848         bands[i]->setMaximum( 400 );
849         bands[i]->setValue( 200 );
850         CONNECT( bands[i], valueChanged( int ), this, setCoreBands() );
851
852         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
853         band_texts[i]->setFont( smallFont );
854
855         grid->addWidget( bands[i], 0, i );
856         grid->addWidget( band_texts[i], 1, i );
857     }
858
859     /* Add the listed presets */
860     for( int i = 0 ; i < NB_PRESETS ; i ++ )
861     {
862         presetsComboBox->addItem( qtr( preset_list_text[i] ),
863                                   QVariant( preset_list[i] ) );
864     }
865
866     /* Connects */
867     BUTTONACT( ui.enableCheck, enable() );
868     BUTTONACT( ui.eq2PassCheck, set2Pass() );
869     CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
870
871     /* Do the update from the value of the core */
872     updateUIFromCore();
873 }
874
875 Equalizer::~Equalizer()
876 {
877 }
878
879 void Equalizer::clean()
880 {
881     enable();
882 }
883 /* Write down initial values */
884 void Equalizer::updateUIFromCore()
885 {
886     char *psz_af;
887     float f_preamp;
888     int i_preset;
889
890     aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
891                                     VLC_OBJECT_AOUT, FIND_ANYWHERE );
892     if( p_aout )
893     {
894         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
895         if( var_GetBool( p_aout, "equalizer-2pass" ) )
896             ui.eq2PassCheck->setChecked( true );
897         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
898         i_preset = presetsComboBox->findData( QVariant(
899                     var_GetString( p_aout, "equalizer-preset" ) ) );
900         vlc_object_release( p_aout );
901     }
902     else
903     {
904         psz_af = config_GetPsz( p_intf, "audio-filter" );
905         if( config_GetInt( p_intf, "equalizer-2pass" ) )
906             ui.eq2PassCheck->setChecked( true );
907         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
908         i_preset = presetsComboBox->findData( QVariant(
909                     config_GetPsz( p_intf, "equalizer-preset" ) ) );
910     }
911     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
912         ui.enableCheck->setChecked( true );
913     enable( ui.enableCheck->isChecked() );
914
915     presetsComboBox->setCurrentIndex( i_preset );
916
917     free( psz_af );
918 }
919
920 /* Functin called when enableButton is toggled */
921 void Equalizer::enable()
922 {
923     bool en = ui.enableCheck->isChecked();
924     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
925                        en ? true : false );
926 //    aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
927 //                       en ? true : false );
928 //     aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
929 //                       en ? true : false );
930     enable( en );
931
932     if( presetsComboBox->currentIndex() < 0 )
933         presetsComboBox->setCurrentIndex( 0 );
934
935 }
936
937 void Equalizer::enable( bool en )
938 {
939     ui.eq2PassCheck->setEnabled( en );
940     presetsComboBox->setEnabled( en );
941     ui.presetLabel->setEnabled( en );
942     ui.preampLabel->setEnabled( en );
943     ui.preampSlider->setEnabled( en  );
944     for( int i = 0 ; i< BANDS; i++ )
945     {
946         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
947     }
948 }
949
950 /* Function called when the set2Pass button is activated */
951 void Equalizer::set2Pass()
952 {
953     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
954                                  VLC_OBJECT_AOUT, FIND_ANYWHERE );
955     bool b_2p = ui.eq2PassCheck->isChecked();
956
957     if( p_aout == NULL )
958         config_PutInt( p_intf, "equalizer-2pass", b_2p );
959     else
960     {
961         var_SetBool( p_aout, "equalizer-2pass", b_2p );
962         config_PutInt( p_intf, "equalizer-2pass", b_2p );
963         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
964         {
965             p_aout->pp_inputs[i]->b_restart = true;
966         }
967         vlc_object_release( p_aout );
968     }
969 }
970
971 /* Function called when the preamp slider is moved */
972 void Equalizer::setPreamp()
973 {
974     const float f = ( float )(  ui.preampSlider->value() ) /10 - 20;
975     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
976                                        VLC_OBJECT_AOUT, FIND_ANYWHERE );
977
978     ui.preampLabel->setText( qtr( "Preamp\n" ) + QString::number( f, 'f', 1 )
979                                                + qtr( "dB" ) );
980     if( p_aout )
981     {
982         //delCallbacks( p_aout );
983         var_SetFloat( p_aout, "equalizer-preamp", f );
984         //addCallbacks( p_aout );
985         vlc_object_release( p_aout );
986     }
987     config_PutFloat( p_intf, "equalizer-preamp", f );
988 }
989
990 void Equalizer::setCoreBands()
991 {
992     /**\todo smoothing */
993
994     QString values;
995     for( int i = 0; i < BANDS; i++ )
996     {
997         const float f_val = (float)( bands[i]->value() ) / 10 - 20;
998         QString val = QString("%1").arg( f_val, 5, 'f', 1 );
999
1000         band_texts[i]->setText( band_frequencies[i] + "\n" + val + "dB" );
1001         values += " " + val;
1002     }
1003     const char *psz_values = values.toAscii().constData();
1004
1005     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
1006                                           VLC_OBJECT_AOUT, FIND_ANYWHERE );
1007     if( p_aout )
1008     {
1009         //delCallbacks( p_aout );
1010         var_SetString( p_aout, "equalizer-bands", psz_values );
1011         //addCallbacks( p_aout );
1012         vlc_object_release( p_aout );
1013     }
1014 }
1015
1016 void Equalizer::updateUISliderValues( int i_preset )
1017 {
1018     if( i_preset < 0 ) return;
1019
1020     char *p = createValuesFromPreset( i_preset );
1021     char *psz = p;
1022     float f_preamp = eqz_preset_10b[i_preset]->f_preamp;
1023
1024     if ( p )
1025     {
1026         for( int i = 0; i < BANDS; i++ )
1027         {
1028             const float f = us_strtod(p, &p );
1029
1030             bands[i]->setValue( (int)( ( f + 20 ) * 10 )  );
1031
1032             band_texts[i]->setText( band_frequencies[i] + "\n"
1033                                   + QString("%1").arg( f, 5, 'f', 1 ) + "dB" );
1034             if( p == NULL || *p == '\0' )
1035                 break;
1036             p++;
1037             if( *p == '\0' )
1038                 break;
1039         }
1040         free( psz );
1041     }
1042     ui.preampSlider->setValue( (int)( ( f_preamp + 20 ) * 10 ) );
1043     ui.preampLabel->setText( qtr( "Preamp\n" )
1044                    + QString::number( f_preamp, 'f', 1 ) + qtr( "dB" ) );
1045 }
1046
1047 char * Equalizer::createValuesFromPreset( int i_preset )
1048 {
1049     char *psz_values;
1050     QString values;
1051
1052     /* Create the QString in Qt */
1053     for( int i = 0 ; i< BANDS ;i++ )
1054         values += QString( " %1" ).arg( eqz_preset_10b[i_preset]->f_amp[i] );
1055
1056     /* Convert it to char * */
1057     if( !asprintf( &psz_values, "%s", values.toAscii().constData() ) )
1058         return NULL;
1059
1060     return psz_values;
1061 }
1062
1063 void Equalizer::setCorePreset( int i_preset )
1064 {
1065     char *psz_values = createValuesFromPreset( i_preset );
1066     if( !psz_values ) return ;
1067
1068     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
1069                                                VLC_OBJECT_AOUT, FIND_ANYWHERE );
1070     if( p_aout )
1071     {
1072         delCallbacks( p_aout );
1073         var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
1074
1075         var_SetString( p_aout, "equalizer-bands", psz_values );
1076         var_SetFloat( p_aout, "equalizer-preamp",
1077                       eqz_preset_10b[i_preset]->f_preamp );
1078         addCallbacks( p_aout );
1079         vlc_object_release( p_aout );
1080     }
1081     config_PutPsz( p_intf, "equalizer-bands", psz_values );
1082     config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
1083     config_PutFloat( p_intf, "equalizer-preamp",
1084                     eqz_preset_10b[i_preset]->f_preamp );
1085 }
1086
1087 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1088                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1089 {
1090     char *psz_preset = newval.psz_string;
1091     Equalizer *eq = ( Equalizer * )p_data;
1092     int i_preset = eq->presetsComboBox->findData( QVariant( psz_preset ) );
1093     eq->presetsComboBox->setCurrentIndex( i_preset );
1094     return VLC_SUCCESS;
1095 }
1096
1097 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1098 {
1099     //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1100     //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1101     var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1102 }
1103
1104 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1105 {
1106     //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1107     //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1108     var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1109 }
1110
1111 /**********************************************************************
1112  * Audio filters
1113  **********************************************************************/
1114
1115 /**********************************************************************
1116  * Spatializer
1117  **********************************************************************/
1118 static const char *psz_control_names[] =
1119 {
1120     "Roomsize", "Width" , "Wet", "Dry", "Damp"
1121 };
1122
1123 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1124     QWidget( _parent ) , p_intf( _p_intf )
1125 {
1126     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1127     smallFont.setPointSize( smallFont.pointSize() - 3 );
1128
1129     QGridLayout *layout = new QGridLayout( this );
1130     layout->setMargin( 0 );
1131
1132     enableCheck = new QCheckBox( qtr( "Enable spatializer" ) );
1133     layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1134
1135     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1136     {
1137         spatCtrl[i] = new QSlider( Qt::Vertical );
1138         if( i < 2 )
1139         {
1140             spatCtrl[i]->setMaximum( 10 );
1141             spatCtrl[i]->setValue( 2 );
1142         }
1143         else
1144         {
1145             spatCtrl[i]->setMaximum( 10 );
1146             spatCtrl[i]->setValue( 0 );
1147             spatCtrl[i]->setMinimum( -10 );
1148         }
1149         oldControlVars[i] = spatCtrl[i]->value();
1150         CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1151         ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1152         ctrl_texts[i]->setFont( smallFont );
1153         ctrl_readout[i] = new QLabel( "" );
1154         ctrl_readout[i]->setFont( smallFont );
1155         layout->addWidget( spatCtrl[i], 1, i );
1156         layout->addWidget( ctrl_readout[i], 2, i );
1157         layout->addWidget( ctrl_texts[i], 3, i );
1158     }
1159
1160     BUTTONACT( enableCheck, enable() );
1161
1162     /* Write down initial values */
1163     aout_instance_t *p_aout = ( aout_instance_t * )
1164         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1165     char *psz_af;
1166
1167     if( p_aout )
1168     {
1169         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1170         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1171         {
1172             controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1173         }
1174         vlc_object_release( p_aout );
1175     }
1176     else
1177     {
1178         psz_af = config_GetPsz( p_intf, "audio-filter" );
1179         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1180         {
1181             controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1182         }
1183     }
1184     if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1185         enableCheck->setChecked( true );
1186     free( psz_af );
1187     enable( enableCheck->isChecked() );
1188     setValues( controlVars );
1189 }
1190
1191 Spatializer::~Spatializer()
1192 {
1193 }
1194
1195 void Spatializer::enable()
1196 {
1197     bool en = enableCheck->isChecked();
1198     aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1199             en ? true : false );
1200     enable( en );
1201 }
1202
1203 void Spatializer::enable( bool en )
1204 {
1205     for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1206     {
1207         spatCtrl[i]->setEnabled( en );
1208         ctrl_texts[i]->setEnabled( en );
1209         ctrl_readout[i]->setEnabled( en );
1210     }
1211 }
1212 void Spatializer::setInitValues()
1213 {
1214     setValues( controlVars );
1215 }
1216
1217 void Spatializer::setValues( float *controlVars )
1218 {
1219     aout_instance_t *p_aout= ( aout_instance_t * )
1220         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1221
1222     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1223     {
1224         float f = (float)(  spatCtrl[i]->value() );
1225         ctrl_readout[i]->setText( QString::number( f, 'f',  1 ) );
1226     }
1227     if( p_aout )
1228     {
1229         for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1230         {
1231             if( oldControlVars[i] != spatCtrl[i]->value() )
1232             {
1233                 var_SetFloat( p_aout, psz_control_names[i],
1234                         ( float )spatCtrl[i]->value() );
1235                 config_PutFloat( p_intf, psz_control_names[i],
1236                         ( float ) spatCtrl[i]->value() );
1237                 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1238             }
1239         }
1240         vlc_object_release( p_aout );
1241     }
1242
1243 }
1244 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1245 {
1246     //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1247     //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1248 }
1249
1250 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1251 {
1252     //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1253     //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1254 }
1255
1256 #include <QToolButton>
1257 #include <QGridLayout>
1258
1259 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1260                             QWidget( _parent ) , p_intf( _p_intf )
1261 {
1262     QGroupBox *AVBox, *subsBox;
1263
1264     QToolButton *moinsAV, *plusAV;
1265     QToolButton *moinssubs, *plussubs;
1266     QToolButton *moinssubSpeed, *plussubSpeed;
1267
1268     QToolButton *updateButton;
1269
1270     QGridLayout *mainLayout = new QGridLayout( this );
1271
1272     /* AV sync */
1273     AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1274     QGridLayout *AVLayout = new QGridLayout( AVBox );
1275
1276     moinsAV = new QToolButton;
1277     moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1278     moinsAV->setAutoRaise( true );
1279     moinsAV->setText( "-" );
1280     AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1281
1282     plusAV = new QToolButton;
1283     plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1284     plusAV->setAutoRaise( true );
1285     plusAV->setText( "+" );
1286     AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1287
1288     QLabel *AVLabel = new QLabel;
1289     AVLabel->setText( qtr( "Advance of audio over video:" ) );
1290     AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1291
1292     AVSpin = new QDoubleSpinBox;
1293     AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1294     AVSpin->setDecimals( 3 );
1295     AVSpin->setMinimum( -100.0 );
1296     AVSpin->setMaximum( 100.0 );
1297     AVSpin->setSingleStep( 0.1 );
1298     AVSpin->setToolTip( qtr( "A positive value means that\n"
1299                              "the audio is ahead of the video" ) );
1300     AVSpin->setSuffix( "s" );
1301     AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1302     mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1303
1304
1305     /* Subs */
1306     subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1307     QGridLayout *subsLayout = new QGridLayout( subsBox );
1308
1309     moinssubs = new QToolButton;
1310     moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1311     moinssubs->setAutoRaise( true );
1312     moinssubs->setText( "-" );
1313     subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1314
1315     plussubs = new QToolButton;
1316     plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1317     plussubs->setAutoRaise( true );
1318     plussubs->setText( "+" );
1319     subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1320
1321     QLabel *subsLabel = new QLabel;
1322     subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1323     subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1324
1325     subsSpin = new QDoubleSpinBox;
1326     subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1327     subsSpin->setDecimals( 3 );
1328     subsSpin->setMinimum( -100.0 );
1329     subsSpin->setMaximum( 100.0 );
1330     subsSpin->setSingleStep( 0.1 );
1331     subsSpin->setToolTip( qtr( "A positive value means that\n"
1332                              "the subtitles are ahead of the video" ) );
1333     subsSpin->setSuffix( "s" );
1334     subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1335
1336
1337     moinssubSpeed = new QToolButton;
1338     moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1339     moinssubSpeed->setAutoRaise( true );
1340     moinssubSpeed->setText( "-" );
1341     subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1342
1343     plussubSpeed = new QToolButton;
1344     plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1345     plussubSpeed->setAutoRaise( true );
1346     plussubSpeed->setText( "+" );
1347     subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1348
1349     QLabel *subSpeedLabel = new QLabel;
1350     subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1351     subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1352
1353     subSpeedSpin = new QDoubleSpinBox;
1354     subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1355     subSpeedSpin->setDecimals( 3 );
1356     subSpeedSpin->setMinimum( 1 );
1357     subSpeedSpin->setMaximum( 100 );
1358     subSpeedSpin->setSingleStep( 0.2 );
1359     subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1360
1361     mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1362
1363     updateButton = new QToolButton;
1364     updateButton->setAutoRaise( true );
1365     mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1366
1367
1368     /* Various Connects */
1369     CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1370     CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1371     CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1372     CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1373     CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1374     CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1375     CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1376     CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1377     CONNECT( subSpeedSpin, valueChanged ( double ),
1378              this, adjustSubsSpeed( double ) );
1379     BUTTON_SET_ACT_I( updateButton, "", update,
1380             qtr( "Force update of this dialog's values" ), update() );
1381
1382     /* Set it */
1383     update();
1384 }
1385
1386 void SyncControls::clean()
1387 {
1388     AVSpin->setValue( 0.0 );
1389     subsSpin->setValue( 0.0 );
1390     subSpeedSpin->setValue( 1.0 );
1391 }
1392
1393 void SyncControls::update()
1394 {
1395     int64_t i_delay;
1396     if( THEMIM->getInput() )
1397     {
1398         i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1399         AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1400         i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1401         subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1402         subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1403     }
1404 }
1405
1406 void SyncControls::advanceAudio( double f_advance )
1407 {
1408     if( THEMIM->getInput() )
1409     {
1410         int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1411         i_delay = f_advance * 1000000;
1412         var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1413     }
1414 }
1415
1416 void SyncControls::advanceSubs( double f_advance )
1417 {
1418     if( THEMIM->getInput() )
1419     {
1420         int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1421         i_delay = f_advance * 1000000;
1422         var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1423         msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
1424     }
1425 }
1426
1427 void SyncControls::adjustSubsSpeed( double f_fps )
1428 {
1429     if( THEMIM->getInput() )
1430     {
1431         var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1432     }
1433 }
1434
1435 /**********************************************************************
1436  * Video filters / Adjust
1437  **********************************************************************/
1438
1439 /**********************************************************************
1440  * Extended playbak controls
1441  **********************************************************************/