]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Do not try to access other's filters
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
1 /*****************************************************************************
2  * extended_panels.cpp : Extended controls panels
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea .t videolan d@t org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <QLabel>
26 #include <QVariant>
27 #include <QString>
28 #include <QFont>
29 #include <QGridLayout>
30 #include <QSignalMapper>
31
32 #include "components/extended_panels.hpp"
33 #include "dialogs/preferences.hpp"
34 #include "dialogs_provider.hpp"
35 #include "qt4.hpp"
36
37 #include "../../audio_filter/equalizer_presets.h"
38 #include <vlc_aout.h>
39 #include <vlc_intf_strings.h>
40 #include <vlc_vout.h>
41 #include <vlc_osd.h>
42
43 #include <iostream>
44
45 #if 0
46 class ConfClickHandler : public QObject
47 {
48 public:
49     ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject (_e) {
50         e = _e; p_intf = _p_intf;
51     }
52     virtual ~ConfClickHandler() {}
53     bool eventFilter( QObject *obj, QEvent *evt )
54     {
55         if( evt->type() == QEvent::MouseButtonPress )
56         {
57             e->gotoConf( obj );
58             return true;
59         }
60         return false;
61     }
62 private:
63     ExtVideo* e;
64     intf_thread_t *p_intf;
65 };
66 #endif
67
68 QString ModuleFromWidgetName( QObject *obj )
69 {
70     return obj->objectName().replace("Enable","");
71 }
72
73 QString OptionFromWidgetName( QObject *obj )
74 {
75     /* Gruik ? ... nah */
76     QString option = obj->objectName().replace( "Slider", "" )
77                                       .replace( "Combo" , "" )
78                                       .replace( "Dial"  , "" )
79                                       .replace( "Check" , "" )
80                                       .replace( "Spin"  , "" )
81                                       .replace( "Text"  , "" );
82     for( char a = 'A'; a <= 'Z'; a++ )
83     {
84         option = option.replace( QString( a ),
85                                  QString( '-' ) + QString( a + 'a' - 'A' ) );
86     }
87     return option;
88 }
89
90 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QWidget *_parent ) :
91                            QWidget( _parent ) , p_intf( _p_intf )
92 {
93     ui.setupUi( this );
94
95 #define SETUP_VFILTER( widget ) \
96     { \
97         vlc_object_t *p_obj = (vlc_object_t *) \
98             vlc_object_find_name( p_intf->p_libvlc, \
99                                   #widget, \
100                                   FIND_CHILD ); \
101         QCheckBox *checkbox = qobject_cast<QCheckBox*>(ui.widget##Enable); \
102         QGroupBox *groupbox = qobject_cast<QGroupBox*>(ui.widget##Enable); \
103         if( p_obj ) \
104         { \
105             vlc_object_release( p_obj ); \
106             if( checkbox ) checkbox->setCheckState( Qt::Checked ); \
107             else groupbox->setChecked( true ); \
108         } \
109         else \
110         { \
111             if( checkbox ) checkbox->setCheckState( Qt::Unchecked ); \
112             else groupbox->setChecked( false ); \
113         } \
114     } \
115     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
116 #define SETUP_VFILTER_OPTION( widget, signal ) \
117     initComboBoxItems( ui.widget ); \
118     setWidgetValue( ui.widget ); \
119     CONNECT( ui.widget, signal, this, updateFilterOptions() );
120
121     SETUP_VFILTER( adjust )
122     SETUP_VFILTER_OPTION( hueSlider, valueChanged(int) )
123     SETUP_VFILTER_OPTION( contrastSlider, valueChanged(int) )
124     SETUP_VFILTER_OPTION( brightnessSlider, valueChanged(int) )
125     SETUP_VFILTER_OPTION( saturationSlider, valueChanged(int) )
126     SETUP_VFILTER_OPTION( gammaSlider, valueChanged(int) )
127     SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged(int) )
128
129     SETUP_VFILTER( extract )
130     SETUP_VFILTER_OPTION( extractComponentText, textChanged(QString) )
131
132     SETUP_VFILTER( colorthres )
133     SETUP_VFILTER_OPTION( colorthresColorText, textChanged(QString) )
134     SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged(int) )
135     SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged(int) )
136
137     SETUP_VFILTER( invert )
138
139     SETUP_VFILTER( gradient )
140     SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged(QString) )
141     SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged(int) )
142     SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged(int) )
143
144     SETUP_VFILTER( motionblur )
145     SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged(int) )
146
147     SETUP_VFILTER( motiondetect )
148
149     SETUP_VFILTER( noise )
150
151     SETUP_VFILTER( psychedelic )
152
153     SETUP_VFILTER( sharpen )
154     SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged(int) )
155
156     SETUP_VFILTER( ripple )
157
158     SETUP_VFILTER( wave )
159
160     SETUP_VFILTER( transform )
161     SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged(QString) )
162
163     SETUP_VFILTER( rotate )
164     SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged(int) )
165     ui.rotateAngleDial->setWrapping( true );
166     ui.rotateAngleDial->setNotchesVisible( true );
167
168     SETUP_VFILTER( puzzle )
169     SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged(int) )
170     SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged(int) )
171     SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged(int) )
172
173     SETUP_VFILTER( magnify )
174
175     SETUP_VFILTER( clone )
176     SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged(int) )
177
178     SETUP_VFILTER( wall )
179     SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged(int) )
180     SETUP_VFILTER_OPTION( wallColsSpin, valueChanged(int) )
181
182     SETUP_VFILTER( erase )
183     SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
184     SETUP_VFILTER_OPTION( eraseYSpin, valueChanged(int) )
185     SETUP_VFILTER_OPTION( eraseXSpin, valueChanged(int) )
186
187     SETUP_VFILTER( marq )
188     SETUP_VFILTER_OPTION( marqMarqueeText, textChanged(QString) )
189     SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged(QString) )
190
191     SETUP_VFILTER( logo )
192     SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
193     SETUP_VFILTER_OPTION( logoYSpin, valueChanged(int) )
194     SETUP_VFILTER_OPTION( logoXSpin, valueChanged(int) )
195     SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged(int) )
196
197 #undef SETUP_VFILTER
198 #undef SETUP_VFILTER_OPTION
199 }
200
201 ExtVideo::~ExtVideo()
202 {
203 }
204
205 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
206 {
207     vout_thread_t *p_vout;
208     char *psz_parser, *psz_string;
209
210     char *psz_filter_type;
211     vlc_object_t *p_obj = (vlc_object_t *)
212         vlc_object_find_name( p_intf->p_libvlc, psz_name, FIND_CHILD );
213     if( !p_obj )
214     {
215         msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
216         return;
217     }
218
219     if( module_IsCapable( (module_t*)p_obj, "video filter2" ) )
220     {
221         psz_filter_type = "video-filter";
222     }
223     else if( module_IsCapable( (module_t*)p_obj, "video filter" ) )
224     {
225         psz_filter_type = "vout-filter";
226     }
227     else if( module_IsCapable( (module_t*)p_obj, "sub filter" ) )
228     {
229         psz_filter_type = "sub-filter";
230     }
231     else
232     {
233         vlc_object_release( p_obj );
234         msg_Err( p_intf, "Unknown video filter type." );
235         return;
236     }
237     vlc_object_release( p_obj );
238
239     psz_string = config_GetPsz( p_intf, psz_filter_type );
240
241     if( !psz_string ) psz_string = strdup("");
242
243     psz_parser = strstr( psz_string, psz_name );
244
245     if( b_add )
246     {
247         if( !psz_parser )
248         {
249             psz_parser = psz_string;
250             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
251                             psz_string, psz_name );
252             free( psz_parser );
253         }
254         else
255         {
256             return;
257         }
258     }
259     else
260     {
261         if( psz_parser )
262         {
263             if( *(psz_parser + strlen(psz_name)) == ':' )
264             {
265                 memmove( psz_parser, psz_parser + strlen(psz_name) + 1,
266                          strlen(psz_parser + strlen(psz_name) + 1 ) + 1 );
267             }
268             else
269             {
270                 *psz_parser = '\0';
271             }
272
273             /* Remove trailing : : */
274             if( strlen( psz_string ) > 0 &&
275                 *( psz_string + strlen( psz_string ) -1 ) == ':' )
276             {
277                 *( psz_string + strlen( psz_string ) -1 ) = '\0';
278             }
279         }
280         else
281         {
282             free( psz_string );
283             return;
284         }
285     }
286     /* Vout is not kept, so put that in the config */
287     config_PutPsz( p_intf, psz_filter_type, psz_string );
288     if( !strcmp( psz_filter_type, "video-filter" ) )
289         ui.videoFilterText->setText( psz_string );
290     else if( !strcmp( psz_filter_type, "vout-filter" ) )
291         ui.voutFilterText->setText( psz_string );
292     else if( !strcmp( psz_filter_type, "sub-filter" ) )
293         ui.subpictureFilterText->setText( psz_string );
294
295     /* Try to set on the fly */
296     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
297                                               FIND_ANYWHERE );
298     if( p_vout )
299     {
300         if( !strcmp( psz_filter_type, "sub-filter" ) )
301             var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
302         else
303             var_SetString( p_vout, psz_filter_type, psz_string );
304         vlc_object_release( p_vout );
305     }
306
307     free( psz_string );
308 }
309
310 void ExtVideo::updateFilters()
311 {
312     QString module = ModuleFromWidgetName( sender() );
313     //std::cout << "Module name: " << module.toStdString() << std::endl;
314
315     QCheckBox *checkbox = qobject_cast<QCheckBox*>(sender());
316     QGroupBox *groupbox = qobject_cast<QGroupBox*>(sender());
317
318     ChangeVFiltersString( qtu(module),
319                           checkbox ? checkbox->isChecked()
320                                    : groupbox->isChecked() );
321 }
322
323 void ExtVideo::initComboBoxItems( QObject *widget )
324 {
325     QComboBox *combobox = qobject_cast<QComboBox*>(widget);
326     if( !combobox ) return;
327     QString option = OptionFromWidgetName( widget );
328     module_config_t *p_item = config_FindConfig( VLC_OBJECT(p_intf),
329                                                  option.toStdString().c_str() );
330     if( p_item )
331     {
332         int i_type = p_item->i_type & CONFIG_ITEM;
333         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
334         {
335             if( i_type == CONFIG_ITEM_INTEGER
336              || i_type == CONFIG_ITEM_BOOL )
337                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->pi_list[i_index] );
338             else if( i_type == CONFIG_ITEM_STRING )
339                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->ppsz_list[i_index] );
340         }
341     }
342     else
343     {
344         msg_Err( p_intf, "Couldn't find option \"%s\".",
345                  option.toStdString().c_str() );
346     }
347 }
348
349 void ExtVideo::setWidgetValue( QObject *widget )
350 {
351     QString module = ModuleFromWidgetName( widget->parent() );
352     //std::cout << "Module name: " << module.toStdString() << std::endl;
353     QString option = OptionFromWidgetName( widget );
354     //std::cout << "Option name: " << option.toStdString() << std::endl;
355
356     vlc_object_t *p_obj = (vlc_object_t *)
357         vlc_object_find_name( p_intf->p_libvlc,
358                               module.toStdString().c_str(),
359                               FIND_CHILD );
360     int i_type;
361     vlc_value_t val;
362
363     if( !p_obj )
364     {
365         msg_Dbg( p_intf,
366                  "Module instance %s not found, looking in config values.",
367                  module.toStdString().c_str() );
368         i_type = config_GetType( p_intf, option.toStdString().c_str() ) & 0xf0;
369         switch( i_type )
370         {
371             case VLC_VAR_INTEGER:
372             case VLC_VAR_BOOL:
373                 val.i_int = config_GetInt( p_intf, option.toStdString().c_str() );
374                 break;
375             case VLC_VAR_FLOAT:
376                 val.f_float = config_GetFloat( p_intf, option.toStdString().c_str() );
377                 break;
378             case VLC_VAR_STRING:
379                 val.psz_string = config_GetPsz( p_intf, option.toStdString().c_str() );
380                 break;
381         }
382     }
383     else
384     {
385         i_type = var_Type( p_obj, option.toStdString().c_str() ) & 0xf0;
386         var_Get( p_obj, option.toStdString().c_str(), &val );
387         vlc_object_release( p_obj );
388     }
389
390     /* Try to cast to all the widgets we're likely to encounter. Only
391      * one of the casts is expected to work. */
392     QSlider        *slider        = qobject_cast<QSlider*>       (widget);
393     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (widget);
394     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (widget);
395     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(widget);
396     QDial          *dial          = qobject_cast<QDial*>         (widget);
397     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (widget);
398     QComboBox      *combobox      = qobject_cast<QComboBox*>     (widget);
399
400     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
401     {
402         int i_int = 0;
403         if( slider )        slider->setValue( val.i_int );
404         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
405                                                               : Qt::Unchecked );
406         else if( spinbox )  spinbox->setValue( val.i_int );
407         else if( dial )     dial->setValue( (540-val.i_int)%360 );
408         else if( lineedit )
409         {
410             char str[30];
411             sprintf( str, "%06X", val.i_int );
412             lineedit->setText( str );
413         }
414         else if( combobox ) combobox->setCurrentIndex(
415                             combobox->findData( val.i_int ) );
416         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
417     }
418     else if( i_type == VLC_VAR_FLOAT )
419     {
420         double f_float = 0;
421         if( slider ) slider->setValue( (int)(val.f_float*(double)slider->tickInterval())); /* hack alert! */
422         else if( doublespinbox ) doublespinbox->setValue(val.f_float);
423         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
424     }
425     else if( i_type == VLC_VAR_STRING )
426     {
427         const char *psz_string = NULL;
428         if( lineedit ) lineedit->setText( qfu(val.psz_string) );
429         else if( combobox ) combobox->setCurrentIndex(
430                             combobox->findData( qfu( val.psz_string ) ) );
431         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
432         free( val.psz_string );
433     }
434     else
435         msg_Err( p_intf,
436                  "Module %s's %s variable is of an unsupported type (%d)",
437                  module.toStdString().c_str(),
438                  option.toStdString().c_str(),
439                  i_type );
440 }
441
442 void ExtVideo::updateFilterOptions()
443 {
444     QString module = ModuleFromWidgetName( sender()->parent() );
445     //std::cout << "Module name: " << module.toStdString() << std::endl;
446     QString option = OptionFromWidgetName( sender() );
447     //std::cout << "Option name: " << option.toStdString() << std::endl;
448
449     vlc_object_t *p_obj = (vlc_object_t *)
450         vlc_object_find_name( p_intf->p_libvlc,
451                               module.toStdString().c_str(),
452                               FIND_CHILD );
453     if( !p_obj )
454     {
455         msg_Err( p_intf, "Module %s not found.", module.toStdString().c_str() );
456         return;
457     }
458
459     int i_type = var_Type( p_obj, option.toStdString().c_str() );
460     bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
461     if( !b_is_command )
462     {
463         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.",
464                  module.toStdString().c_str(),
465                  option.toStdString().c_str() );
466         /* FIXME: restart automatically somewhere near the end of this function */
467     }
468
469     /* Try to cast to all the widgets we're likely to encounter. Only
470      * one of the casts is expected to work. */
471     QSlider        *slider        = qobject_cast<QSlider*>       (sender());
472     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (sender());
473     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (sender());
474     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(sender());
475     QDial          *dial          = qobject_cast<QDial*>         (sender());
476     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (sender());
477     QComboBox      *combobox      = qobject_cast<QComboBox*>     (sender());
478
479     i_type &= 0xf0;
480     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
481     {
482         int i_int = 0;
483         if( slider )        i_int = slider->value();
484         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
485         else if( spinbox )  i_int = spinbox->value();
486         else if( dial )     i_int = (540-dial->value())%360;
487         else if( lineedit ) i_int = lineedit->text().toInt(NULL,16);
488         else if( combobox ) i_int = combobox->itemData(combobox->currentIndex()).toInt();
489         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
490         config_PutInt( p_intf, option.toStdString().c_str(), i_int );
491         if( b_is_command )
492         {
493             if( i_type == VLC_VAR_INTEGER )
494                 var_SetInteger( p_obj, option.toStdString().c_str(), i_int );
495             else
496                 var_SetBool( p_obj, option.toStdString().c_str(), i_int );
497         }
498     }
499     else if( i_type == VLC_VAR_FLOAT )
500     {
501         double f_float = 0;
502         if( slider )             f_float = (double)slider->value()
503                                          / (double)slider->tickInterval(); /* hack alert! */
504         else if( doublespinbox ) f_float = doublespinbox->value();
505         else if( lineedit ) f_float = lineedit->text().toDouble();
506         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
507         config_PutFloat( p_intf, option.toStdString().c_str(), f_float );
508         if( b_is_command )
509             var_SetFloat( p_obj, option.toStdString().c_str(), f_float );
510     }
511     else if( i_type == VLC_VAR_STRING )
512     {
513         char *psz_string = NULL;
514         if( lineedit ) psz_string = qtu(lineedit->text());
515         else if( combobox ) psz_string = qtu(combobox->itemData(
516                                          combobox->currentIndex()).toString());
517         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
518         psz_string = strdup( psz_string );
519         config_PutPsz( p_intf, option.toStdString().c_str(), psz_string );
520         if( b_is_command )
521             var_SetString( p_obj, option.toStdString().c_str(), psz_string );
522         free( psz_string );
523     }
524     else
525         msg_Err( p_intf,
526                  "Module %s's %s variable is of an unsupported type (%d)",
527                  module.toStdString().c_str(),
528                  option.toStdString().c_str(),
529                  i_type );
530
531     vlc_object_release( p_obj );
532 }
533
534 #if 0
535 void ExtVideo::gotoConf( QObject* src )
536 {
537 #define SHOWCONF(module) \
538     if( src->objectName().contains(module) ) \
539     { \
540         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
541         return; \
542     }
543     SHOWCONF( "clone" );
544     SHOWCONF( "magnify" );
545     SHOWCONF( "wave" );
546     SHOWCONF( "ripple" );
547     SHOWCONF( "invert" );
548     SHOWCONF( "puzzle" );
549     SHOWCONF( "wall" );
550     SHOWCONF( "gradient" );
551     SHOWCONF( "colorthres" )
552 }
553 #endif
554
555 /**********************************************************************
556  * Equalizer
557  **********************************************************************/
558
559 static const QString band_frequencies[] =
560 {
561     "   60Hz  ", " 170 Hz " , " 310 Hz ", " 600 Hz ", "  1 kHz  ",
562     "  3 kHz  " , "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
563 };
564
565 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
566                             QWidget( _parent ) , p_intf( _p_intf )
567 {
568     QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
569     smallFont.setPointSize( smallFont.pointSize() - 3 );
570
571     ui.setupUi( this );
572
573     ui.preampLabel->setFont( smallFont );
574     ui.preampSlider->setMaximum( 400 );
575     for( int i = 0 ; i < NB_PRESETS ; i ++ )
576     {
577         ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
578                                   QVariant( i ) );
579     }
580     CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
581
582     BUTTONACT( ui.enableCheck, enable() );
583     BUTTONACT( ui.eq2PassCheck, set2Pass() );
584
585     CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
586
587     QGridLayout *grid = new QGridLayout( ui.frame );
588     grid->setMargin( 0 );
589     for( int i = 0 ; i < BANDS ; i++ )
590     {
591         bands[i] = new QSlider( Qt::Vertical );
592         bands[i]->setMaximum( 400 );
593         bands[i]->setValue( 200 );
594         CONNECT( bands[i], valueChanged(int), this, setBand() );
595         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
596         band_texts[i]->setFont( smallFont );
597         grid->addWidget( bands[i], 0, i );
598         grid->addWidget( band_texts[i], 1, i );
599     }
600
601     /* Write down initial values */
602     aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
603                                     VLC_OBJECT_AOUT, FIND_ANYWHERE);
604     char *psz_af = NULL;
605     char *psz_bands;
606     float f_preamp;
607     if( p_aout )
608     {
609         psz_af = var_GetString( p_aout, "audio-filter" );
610         if( var_GetBool( p_aout, "equalizer-2pass" ) )
611             ui.eq2PassCheck->setChecked( true );
612         psz_bands = var_GetString( p_aout, "equalizer-bands" );
613         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
614         vlc_object_release( p_aout );
615     }
616     else
617     {
618         psz_af = config_GetPsz( p_intf, "audio-filter" );
619         if( config_GetInt( p_intf, "equalizer-2pass" ) )
620             ui.eq2PassCheck->setChecked( true );
621         psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
622         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
623     }
624     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
625         ui.enableCheck->setChecked( true );
626     enable( ui.enableCheck->isChecked() );
627
628     setValues( psz_bands, f_preamp );
629 }
630
631 Equalizer::~Equalizer()
632 {
633 }
634
635 void Equalizer::enable()
636 {
637     bool en = ui.enableCheck->isChecked();
638     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
639                        en ? VLC_TRUE : VLC_FALSE );
640     enable( en );
641 }
642
643 void Equalizer::enable( bool en )
644 {
645     ui.eq2PassCheck->setEnabled( en );
646     ui.preampLabel->setEnabled( en );
647     ui.preampSlider->setEnabled( en  );
648     for( int i = 0 ; i< BANDS; i++ )
649     {
650         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
651     }
652 }
653
654 void Equalizer::set2Pass()
655 {
656     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
657                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
658     vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
659
660     if( p_aout == NULL )
661         config_PutInt( p_intf, "equalizer-2pass", b_2p );
662     else
663     {
664         var_SetBool( p_aout, "equalizer-2pass", b_2p );
665         config_PutInt( p_intf, "equalizer-2pass", b_2p );
666         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
667         {
668             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
669         }
670         vlc_object_release( p_aout );
671     }
672 }
673
674 void Equalizer::setPreamp()
675 {
676     float f= (float)(  ui.preampSlider->value() ) /10 - 20;
677     char psz_val[5];
678     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
679                                        VLC_OBJECT_AOUT, FIND_ANYWHERE);
680
681     sprintf( psz_val, "%.1f", f );
682     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
683     if( p_aout )
684     {
685         delCallbacks( p_aout );
686         var_SetFloat( p_aout, "equalizer-preamp", f );
687         addCallbacks( p_aout );
688         vlc_object_release( p_aout );
689     }
690     config_PutFloat( p_intf, "equalizer-preamp", f );
691 }
692
693 void Equalizer::setBand()
694 {
695     char psz_values[102]; memset( psz_values, 0, 102 );
696
697     /**\todo smoothing */
698
699     for( int i = 0 ; i< BANDS ; i++ )
700     {
701         char psz_val[5];
702         float f_val = (float)(  bands[i]->value() ) / 10 - 20 ;
703         sprintf( psz_values, "%s %f", psz_values, f_val );
704         sprintf( psz_val, "% 5.1f", f_val );
705         band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
706     }
707     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
708                                           VLC_OBJECT_AOUT, FIND_ANYWHERE);
709     if( p_aout )
710     {
711         delCallbacks( p_aout );
712         var_SetString( p_aout, "equalizer-bands", psz_values );
713         addCallbacks( p_aout );
714         vlc_object_release( p_aout );
715     }
716 }
717 void Equalizer::setValues( char *psz_bands, float f_preamp )
718 {
719     char *p = psz_bands;
720     if ( p )
721     {
722         for( int i = 0; i < 10; i++ )
723         {
724             char psz_val[5];
725             float f = strtof( p, &p );
726             int  i_val= (int)( ( f + 20 ) * 10 );
727             bands[i]->setValue(  i_val );
728             sprintf( psz_val, "% 5.1f", f );
729             band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
730                                     "dB" );
731             if( p == NULL || *p == '\0' ) break;
732             p++;
733             if( *p == '\0' )  break;
734         }
735     }
736     char psz_val[5];
737     int i_val = (int)( ( f_preamp + 20 ) * 10 );
738     sprintf( psz_val, "%.1f", f_preamp );
739     ui.preampSlider->setValue( i_val );
740     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
741 }
742
743 void Equalizer::setPreset( int preset )
744 {
745     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
746                                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);
747
748     char psz_values[102]; memset( psz_values, 0, 102 );
749     for( int i = 0 ; i< 10 ;i++ )
750         sprintf( psz_values, "%s %.1f", psz_values,
751                                         eqz_preset_10b[preset]->f_amp[i] );
752
753     if( p_aout )
754     {
755         delCallbacks( p_aout );
756         var_SetString( p_aout, "equalizer-bands", psz_values );
757         var_SetFloat( p_aout, "equalizer-preamp",
758                       eqz_preset_10b[preset]->f_preamp );
759         addCallbacks( p_aout );
760         vlc_object_release( p_aout );
761     }
762     config_PutPsz( p_intf, "equalizer-bands", psz_values );
763     config_PutFloat( p_intf, "equalizer-preamp",
764                     eqz_preset_10b[preset]->f_preamp );
765
766     setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
767 }
768
769 void Equalizer::delCallbacks( aout_instance_t *p_aout )
770 {
771 //    var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
772 //    var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
773 }
774
775 void Equalizer::addCallbacks( aout_instance_t *p_aout )
776 {
777 //    var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
778 //    var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
779 }
780
781
782 /**********************************************************************
783  * Video filters / Adjust
784  **********************************************************************/
785
786 /**********************************************************************
787  * Audio filters
788  **********************************************************************/
789
790 /**********************************************************************
791  * Extended playbak controls
792  **********************************************************************/