]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Add calls to config_Put* to make sure that the configuration values survive a filter...
[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
42 #include <iostream>
43
44 #if 0
45 class ConfClickHandler : public QObject
46 {
47 public:
48     ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject (_e) {
49         e = _e; p_intf = _p_intf;
50     }
51     virtual ~ConfClickHandler() {}
52     bool eventFilter( QObject *obj, QEvent *evt )
53     {
54         if( evt->type() == QEvent::MouseButtonPress )
55         {
56             e->gotoConf( obj );
57             return true;
58         }
59         return false;
60     }
61 private:
62     ExtVideo* e;
63     intf_thread_t *p_intf;
64 };
65 #endif
66
67 QString ModuleFromWidgetName( QObject *obj )
68 {
69     return obj->objectName().replace("Enable","");
70 }
71
72 QString OptionFromWidgetName( QObject *obj )
73 {
74     /* Gruik ? ... nah */
75     QString option = obj->objectName().replace( "Slider", "" )
76                                       .replace( "Combo" , "" )
77                                       .replace( "Dial"  , "" )
78                                       .replace( "Check" , "" )
79                                       .replace( "Spin"  , "" )
80                                       .replace( "Text"  , "" );
81     for( char a = 'A'; a <= 'Z'; a++ )
82     {
83         option = option.replace( QString( a ),
84                                  QString( '-' ) + QString( a + 'a' - 'A' ) );
85     }
86     return option;
87 }
88
89 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QWidget *_parent ) :
90                            QWidget( _parent ) , p_intf( _p_intf )
91 {
92     ui.setupUi( this );
93
94 #define SETUP_VFILTER( widget ) \
95     { \
96         vlc_object_t *p_obj = (vlc_object_t *) \
97             vlc_object_find_name( p_intf->p_libvlc, \
98                                   #widget, \
99                                   FIND_CHILD ); \
100         QCheckBox *checkbox = qobject_cast<QCheckBox*>(ui.widget##Enable); \
101         QGroupBox *groupbox = qobject_cast<QGroupBox*>(ui.widget##Enable); \
102         if( p_obj ) \
103         { \
104             vlc_object_release( p_obj ); \
105             if( checkbox ) checkbox->setCheckState( Qt::Checked ); \
106             else groupbox->setChecked( true ); \
107         } \
108         else \
109         { \
110             if( checkbox ) checkbox->setCheckState( Qt::Unchecked ); \
111             else groupbox->setChecked( false ); \
112         } \
113     } \
114     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
115 #define SETUP_VFILTER_OPTION( widget, signal ) \
116     setWidgetValue( ui.widget ); \
117     CONNECT( ui.widget, signal, this, updateFilterOptions() );
118
119     SETUP_VFILTER( adjust )
120     SETUP_VFILTER_OPTION( hueSlider, valueChanged(int) )
121     SETUP_VFILTER_OPTION( contrastSlider, valueChanged(int) )
122     SETUP_VFILTER_OPTION( brightnessSlider, valueChanged(int) )
123     SETUP_VFILTER_OPTION( saturationSlider, valueChanged(int) )
124     SETUP_VFILTER_OPTION( gammaSlider, valueChanged(int) )
125     SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged(int) )
126
127     SETUP_VFILTER( extract )
128     SETUP_VFILTER_OPTION( extractRedSlider, valueChanged(int) )
129     SETUP_VFILTER_OPTION( extractGreenSlider, valueChanged(int) )
130     SETUP_VFILTER_OPTION( extractBlueSlider, valueChanged(int) )
131
132     SETUP_VFILTER( colorthres )
133     SETUP_VFILTER_OPTION( colorthresRedSlider, valueChanged(int) )
134     SETUP_VFILTER_OPTION( colorthresGreenSlider, valueChanged(int) )
135     SETUP_VFILTER_OPTION( colorthresBlueSlider, valueChanged(int) )
136     SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged(int) )
137     SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged(int) )
138
139     SETUP_VFILTER( invert )
140
141     SETUP_VFILTER( gradient )
142     SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged(QString) )
143     SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged(int) )
144     SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged(int) )
145
146     SETUP_VFILTER( blur )
147     SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged(int) )
148
149     SETUP_VFILTER( motiondetect )
150
151     SETUP_VFILTER( noise )
152
153     SETUP_VFILTER( psychedelic )
154
155     SETUP_VFILTER( sharpen )
156     SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged(int) )
157
158     SETUP_VFILTER( ripple )
159
160     SETUP_VFILTER( wave )
161
162     SETUP_VFILTER( transform )
163     SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged(QString) )
164
165     SETUP_VFILTER( rotate )
166     SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged(int) )
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_global, psz_name, FIND_CHILD );
213     if( !p_obj )
214     {
215         msg_Err( p_intf, "Unable to find filter module." );
216         return;
217     }
218
219     if( !strcmp( ((module_t*)p_obj)->psz_capability, "video filter2" ) )
220     {
221         psz_filter_type = "video-filter";
222     }
223     else if( !strcmp( ((module_t*)p_obj)->psz_capability, "video filter" ) )
224     {
225         psz_filter_type = "vout-filter";
226     }
227     else if( !strcmp( ((module_t*)p_obj)->psz_capability, "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         var_SetString( p_vout, psz_filter_type, psz_string );
301         vlc_object_release( p_vout );
302     }
303
304     free( psz_string );
305 }
306
307 void ExtVideo::updateFilters()
308 {
309     QString module = ModuleFromWidgetName( sender() );
310     std::cout << "Module name: " << module.toStdString() << std::endl;
311
312     QCheckBox *checkbox = qobject_cast<QCheckBox*>(sender());
313     QGroupBox *groupbox = qobject_cast<QGroupBox*>(sender());
314
315     ChangeVFiltersString( qtu(module),
316                           checkbox ? checkbox->isChecked()
317                                    : groupbox->isChecked() );
318 }
319
320 void ExtVideo::setWidgetValue( QObject *widget )
321 {
322     QString module = ModuleFromWidgetName( widget->parent() );
323     //std::cout << "Module name: " << module.toStdString() << std::endl;
324     QString option = OptionFromWidgetName( widget );
325     //std::cout << "Option name: " << option.toStdString() << std::endl;
326
327     vlc_object_t *p_obj = (vlc_object_t *)
328         vlc_object_find_name( p_intf->p_libvlc,
329                               module.toStdString().c_str(),
330                               FIND_CHILD );
331     int i_type;
332     vlc_value_t val;
333
334     if( !p_obj )
335     {
336         msg_Dbg( p_intf,
337                  "Module instance %s not found, looking in config values.",
338                  module.toStdString().c_str() );
339         i_type = config_GetType( p_intf, option.toStdString().c_str() ) & 0xf0;
340         switch( i_type )
341         {
342             case VLC_VAR_INTEGER:
343             case VLC_VAR_BOOL:
344                 val.i_int = config_GetInt( p_intf, option.toStdString().c_str() );
345                 break;
346             case VLC_VAR_FLOAT:
347                 val.f_float = config_GetFloat( p_intf, option.toStdString().c_str() );
348                 break;
349             case VLC_VAR_STRING:
350                 val.psz_string = config_GetPsz( p_intf, option.toStdString().c_str() );
351                 break;
352         }
353     }
354     else
355     {
356         i_type = var_Type( p_obj, option.toStdString().c_str() ) & 0xf0;
357         var_Get( p_obj, option.toStdString().c_str(), &val );
358         vlc_object_release( p_obj );
359     }
360
361     /* Try to cast to all the widgets we're likely to encounter. Only
362      * one of the casts is expected to work. */
363     QSlider        *slider        = qobject_cast<QSlider*>       (widget);
364     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (widget);
365     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (widget);
366     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(widget);
367     QDial          *dial          = qobject_cast<QDial*>         (widget);
368     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (widget);
369     QComboBox      *combobox      = qobject_cast<QComboBox*>     (widget);
370
371     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
372     {
373         int i_int = 0;
374         if( slider )        slider->setValue( val.i_int );
375         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
376                                                               : Qt::Unchecked );
377         else if( spinbox )  spinbox->setValue( val.i_int );
378         else if( dial )     dial->setValue( val.i_int );
379         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
380     }
381     else if( i_type == VLC_VAR_FLOAT )
382     {
383         double f_float = 0;
384         if( slider ) slider->setValue( (int)(val.f_float*(double)slider->tickInterval())); /* hack alert! */
385         else if( doublespinbox ) doublespinbox->setValue(val.f_float);
386         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
387     }
388     else if( i_type == VLC_VAR_STRING )
389     {
390         const char *psz_string = NULL;
391         if( lineedit ) lineedit->setText( val.psz_string );
392         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
393         free( val.psz_string );
394     }
395     else
396         msg_Err( p_intf,
397                  "Module %s's %s variable is of an unsupported type (%d)",
398                  module.toStdString().c_str(),
399                  option.toStdString().c_str(),
400                  i_type );
401 }
402
403 void ExtVideo::updateFilterOptions()
404 {
405     QString module = ModuleFromWidgetName( sender()->parent() );
406     std::cout << "Module name: " << module.toStdString() << std::endl;
407     QString option = OptionFromWidgetName( sender() );
408     std::cout << "Option name: " << option.toStdString() << std::endl;
409
410     vlc_object_t *p_obj = (vlc_object_t *)
411         vlc_object_find_name( p_intf->p_libvlc,
412                               module.toStdString().c_str(),
413                               FIND_CHILD );
414     if( !p_obj )
415     {
416         msg_Err( p_intf, "Module %s not found.", module.toStdString().c_str() );
417         return;
418     }
419
420     int i_type = var_Type( p_obj, option.toStdString().c_str() );
421     if( !( i_type & VLC_VAR_ISCOMMAND ) )
422     {
423         vlc_object_release( p_obj );
424         msg_Err( p_intf, "Module %s's %s variable isn't a command.",
425                  module.toStdString().c_str(),
426                  option.toStdString().c_str() );
427         return;
428     }
429
430     /* Try to cast to all the widgets we're likely to encounter. Only
431      * one of the casts is expected to work. */
432     QSlider        *slider        = qobject_cast<QSlider*>       (sender());
433     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (sender());
434     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (sender());
435     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(sender());
436     QDial          *dial          = qobject_cast<QDial*>         (sender());
437     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (sender());
438     QComboBox      *combobox      = qobject_cast<QComboBox*>     (sender());
439
440     i_type &= 0xf0;
441     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
442     {
443         int i_int = 0;
444         if( slider )        i_int = slider->value();
445         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
446         else if( spinbox )  i_int = spinbox->value();
447         else if( dial )     i_int = dial->value();
448         else if( lineedit ) i_int = lineedit->text().toInt();
449         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
450         config_PutInt( p_intf, option.toStdString().c_str(), i_int );
451         if( i_type == VLC_VAR_INTEGER )
452             var_SetInteger( p_obj, option.toStdString().c_str(), i_int );
453         else
454             var_SetBool( p_obj, option.toStdString().c_str(), i_int );
455     }
456     else if( i_type == VLC_VAR_FLOAT )
457     {
458         double f_float = 0;
459         if( slider )             f_float = (double)slider->value()
460                                          / (double)slider->tickInterval(); /* hack alert! */
461         else if( doublespinbox ) f_float = doublespinbox->value();
462         else if( lineedit ) f_float = lineedit->text().toDouble();
463         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
464         config_PutFloat( p_intf, option.toStdString().c_str(), f_float );
465         var_SetFloat( p_obj, option.toStdString().c_str(), f_float );
466     }
467     else if( i_type == VLC_VAR_STRING )
468     {
469         const char *psz_string = NULL;
470         if( lineedit ) psz_string = lineedit->text().toStdString().c_str();
471         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
472         config_PutPsz( p_intf, option.toStdString().c_str(), psz_string );
473         var_SetString( p_obj, option.toStdString().c_str(), psz_string );
474     }
475     else
476         msg_Err( p_intf,
477                  "Module %s's %s variable is of an unsupported type (%d)",
478                  module.toStdString().c_str(),
479                  option.toStdString().c_str(),
480                  i_type );
481
482     vlc_object_release( p_obj );
483 }
484
485 #if 0
486 void ExtVideo::gotoConf( QObject* src )
487 {
488 #define SHOWCONF(module) \
489     if( src->objectName().contains(module) ) \
490     { \
491         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
492         return; \
493     }
494     SHOWCONF( "clone" );
495     SHOWCONF( "magnify" );
496     SHOWCONF( "wave" );
497     SHOWCONF( "ripple" );
498     SHOWCONF( "invert" );
499     SHOWCONF( "puzzle" );
500     SHOWCONF( "wall" );
501     SHOWCONF( "gradient" );
502     SHOWCONF( "colorthres" )
503 }
504 #endif
505
506 /**********************************************************************
507  * Equalizer
508  **********************************************************************/
509
510 static const QString band_frequencies[] =
511 {
512     "   60Hz  ", " 170 Hz " , " 310 Hz ", " 600 Hz ", "  1 kHz  ",
513     "  3 kHz  " , "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
514 };
515
516 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
517                             QWidget( _parent ) , p_intf( _p_intf )
518 {
519     QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
520     smallFont.setPointSize( smallFont.pointSize() - 3 );
521
522     ui.setupUi( this );
523
524     ui.preampLabel->setFont( smallFont );
525     ui.preampSlider->setMaximum( 400 );
526     for( int i = 0 ; i < NB_PRESETS ; i ++ )
527     {
528         ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
529                                   QVariant( i ) );
530     }
531     CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
532
533     BUTTONACT( ui.enableCheck, enable() );
534     BUTTONACT( ui.eq2PassCheck, set2Pass() );
535
536     CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
537
538     QGridLayout *grid = new QGridLayout( ui.frame );
539     grid->setMargin( 0 );
540     for( int i = 0 ; i < BANDS ; i++ )
541     {
542         bands[i] = new QSlider( Qt::Vertical );
543         bands[i]->setMaximum( 400 );
544         bands[i]->setValue( 200 );
545         CONNECT( bands[i], valueChanged(int), this, setBand() );
546         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
547         band_texts[i]->setFont( smallFont );
548         grid->addWidget( bands[i], 0, i );
549         grid->addWidget( band_texts[i], 1, i );
550     }
551
552     /* Write down initial values */
553     aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
554                                     VLC_OBJECT_AOUT, FIND_ANYWHERE);
555     char *psz_af = NULL;
556     char *psz_bands;
557     float f_preamp;
558     if( p_aout )
559     {
560         psz_af = var_GetString( p_aout, "audio-filter" );
561         if( var_GetBool( p_aout, "equalizer-2pass" ) )
562             ui.eq2PassCheck->setChecked( true );
563         psz_bands = var_GetString( p_aout, "equalizer-bands" );
564         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
565         vlc_object_release( p_aout );
566     }
567     else
568     {
569         psz_af = config_GetPsz( p_intf, "audio-filter" );
570         if( config_GetInt( p_intf, "equalizer-2pass" ) )
571             ui.eq2PassCheck->setChecked( true );
572         psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
573         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
574     }
575     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
576         ui.enableCheck->setChecked( true );
577     enable( ui.enableCheck->isChecked() );
578
579     setValues( psz_bands, f_preamp );
580 }
581
582 Equalizer::~Equalizer()
583 {
584 }
585
586 void Equalizer::enable()
587 {
588     bool en = ui.enableCheck->isChecked();
589     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
590                        en ? VLC_TRUE : VLC_FALSE );
591     enable( en );
592 }
593
594 void Equalizer::enable( bool en )
595 {
596     ui.eq2PassCheck->setEnabled( en );
597     ui.preampLabel->setEnabled( en );
598     ui.preampSlider->setEnabled( en  );
599     for( int i = 0 ; i< BANDS; i++ )
600     {
601         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
602     }
603 }
604
605 void Equalizer::set2Pass()
606 {
607     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
608                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
609     vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
610
611     if( p_aout == NULL )
612         config_PutInt( p_intf, "equalizer-2pass", b_2p );
613     else
614     {
615         var_SetBool( p_aout, "equalizer-2pass", b_2p );
616         config_PutInt( p_intf, "equalizer-2pass", b_2p );
617         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
618         {
619             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
620         }
621         vlc_object_release( p_aout );
622     }
623 }
624
625 void Equalizer::setPreamp()
626 {
627     float f= (float)(  ui.preampSlider->value() ) /10 - 20;
628     char psz_val[5];
629     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
630                                        VLC_OBJECT_AOUT, FIND_ANYWHERE);
631
632     sprintf( psz_val, "%.1f", f );
633     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
634     if( p_aout )
635     {
636         delCallbacks( p_aout );
637         var_SetFloat( p_aout, "equalizer-preamp", f );
638         addCallbacks( p_aout );
639         vlc_object_release( p_aout );
640     }
641     config_PutFloat( p_intf, "equalizer-preamp", f );
642 }
643
644 void Equalizer::setBand()
645 {
646     char psz_values[102]; memset( psz_values, 0, 102 );
647
648     /**\todo smoothing */
649
650     for( int i = 0 ; i< BANDS ; i++ )
651     {
652         char psz_val[5];
653         float f_val = (float)(  bands[i]->value() ) / 10 - 20 ;
654         sprintf( psz_values, "%s %f", psz_values, f_val );
655         sprintf( psz_val, "% 5.1f", f_val );
656         band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
657     }
658     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
659                                           VLC_OBJECT_AOUT, FIND_ANYWHERE);
660     if( p_aout )
661     {
662         delCallbacks( p_aout );
663         var_SetString( p_aout, "equalizer-bands", psz_values );
664         addCallbacks( p_aout );
665         vlc_object_release( p_aout );
666     }
667 }
668 void Equalizer::setValues( char *psz_bands, float f_preamp )
669 {
670     char *p = psz_bands;
671     if ( p )
672     {
673         for( int i = 0; i < 10; i++ )
674         {
675             char psz_val[5];
676             float f = strtof( p, &p );
677             int  i_val= (int)( ( f + 20 ) * 10 );
678             bands[i]->setValue(  i_val );
679             sprintf( psz_val, "% 5.1f", f );
680             band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
681                                     "dB" );
682             if( p == NULL || *p == '\0' ) break;
683             p++;
684             if( *p == '\0' )  break;
685         }
686     }
687     char psz_val[5];
688     int i_val = (int)( ( f_preamp + 20 ) * 10 );
689     sprintf( psz_val, "%.1f", f_preamp );
690     ui.preampSlider->setValue( i_val );
691     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
692 }
693
694 void Equalizer::setPreset( int preset )
695 {
696     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
697                                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);
698
699     char psz_values[102]; memset( psz_values, 0, 102 );
700     for( int i = 0 ; i< 10 ;i++ )
701         sprintf( psz_values, "%s %.1f", psz_values,
702                                         eqz_preset_10b[preset]->f_amp[i] );
703
704     if( p_aout )
705     {
706         delCallbacks( p_aout );
707         var_SetString( p_aout, "equalizer-bands", psz_values );
708         var_SetFloat( p_aout, "equalizer-preamp",
709                       eqz_preset_10b[preset]->f_preamp );
710         addCallbacks( p_aout );
711         vlc_object_release( p_aout );
712     }
713     config_PutPsz( p_intf, "equalizer-bands", psz_values );
714     config_PutFloat( p_intf, "equalizer-preamp",
715                     eqz_preset_10b[preset]->f_preamp );
716
717     setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
718 }
719
720 void Equalizer::delCallbacks( aout_instance_t *p_aout )
721 {
722 //    var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
723 //    var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
724 }
725
726 void Equalizer::addCallbacks( aout_instance_t *p_aout )
727 {
728 //    var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
729 //    var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
730 }
731
732
733 /**********************************************************************
734  * Video filters / Adjust
735  **********************************************************************/
736
737 /**********************************************************************
738  * Audio filters
739  **********************************************************************/
740
741 /**********************************************************************
742  * Extended playbak controls
743  **********************************************************************/