]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Revert [21140] which broke the extend panels in Qt4 + add a comment so this doesn...
[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( grain )
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     ui.rotateAngleDial->setWrapping( true );
168     ui.rotateAngleDial->setNotchesVisible( true );
169
170     SETUP_VFILTER( puzzle )
171     SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged(int) )
172     SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged(int) )
173     SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged(int) )
174
175     SETUP_VFILTER( magnify )
176
177     SETUP_VFILTER( clone )
178     SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged(int) )
179
180     SETUP_VFILTER( wall )
181     SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged(int) )
182     SETUP_VFILTER_OPTION( wallColsSpin, valueChanged(int) )
183
184     SETUP_VFILTER( erase )
185     SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
186     SETUP_VFILTER_OPTION( eraseYSpin, valueChanged(int) )
187     SETUP_VFILTER_OPTION( eraseXSpin, valueChanged(int) )
188
189     SETUP_VFILTER( marq )
190     SETUP_VFILTER_OPTION( marqMarqueeText, textChanged(QString) )
191     SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged(QString) )
192
193     SETUP_VFILTER( logo )
194     SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
195     SETUP_VFILTER_OPTION( logoYSpin, valueChanged(int) )
196     SETUP_VFILTER_OPTION( logoXSpin, valueChanged(int) )
197     SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged(int) )
198
199 #undef SETUP_VFILTER
200 #undef SETUP_VFILTER_OPTION
201 }
202
203 ExtVideo::~ExtVideo()
204 {
205 }
206
207 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
208 {
209     vout_thread_t *p_vout;
210     char *psz_parser, *psz_string;
211
212     char *psz_filter_type;
213
214     /* Please leave p_libvlc_global. This is where cached modules are
215      * stored. We're not trying to find a module instance. */
216     vlc_object_t *p_obj = (vlc_object_t *)
217         vlc_object_find_name( p_intf->p_libvlc_global, psz_name, FIND_CHILD );
218     if( !p_obj )
219     {
220         msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
221         return;
222     }
223
224     if( module_IsCapable( (module_t*)p_obj, "video filter2" ) )
225     {
226         psz_filter_type = "video-filter";
227     }
228     else if( module_IsCapable( (module_t*)p_obj, "video filter" ) )
229     {
230         psz_filter_type = "vout-filter";
231     }
232     else if( module_IsCapable( (module_t*)p_obj, "sub filter" ) )
233     {
234         psz_filter_type = "sub-filter";
235     }
236     else
237     {
238         vlc_object_release( p_obj );
239         msg_Err( p_intf, "Unknown video filter type." );
240         return;
241     }
242     vlc_object_release( p_obj );
243
244     psz_string = config_GetPsz( p_intf, psz_filter_type );
245
246     if( !psz_string ) psz_string = strdup("");
247
248     psz_parser = strstr( psz_string, psz_name );
249
250     if( b_add )
251     {
252         if( !psz_parser )
253         {
254             psz_parser = psz_string;
255             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
256                             psz_string, psz_name );
257             free( psz_parser );
258         }
259         else
260         {
261             return;
262         }
263     }
264     else
265     {
266         if( psz_parser )
267         {
268             if( *(psz_parser + strlen(psz_name)) == ':' )
269             {
270                 memmove( psz_parser, psz_parser + strlen(psz_name) + 1,
271                          strlen(psz_parser + strlen(psz_name) + 1 ) + 1 );
272             }
273             else
274             {
275                 *psz_parser = '\0';
276             }
277
278             /* Remove trailing : : */
279             if( strlen( psz_string ) > 0 &&
280                 *( psz_string + strlen( psz_string ) -1 ) == ':' )
281             {
282                 *( psz_string + strlen( psz_string ) -1 ) = '\0';
283             }
284         }
285         else
286         {
287             free( psz_string );
288             return;
289         }
290     }
291     /* Vout is not kept, so put that in the config */
292     config_PutPsz( p_intf, psz_filter_type, psz_string );
293     if( !strcmp( psz_filter_type, "video-filter" ) )
294         ui.videoFilterText->setText( psz_string );
295     else if( !strcmp( psz_filter_type, "vout-filter" ) )
296         ui.voutFilterText->setText( psz_string );
297     else if( !strcmp( psz_filter_type, "sub-filter" ) )
298         ui.subpictureFilterText->setText( psz_string );
299
300     /* Try to set on the fly */
301     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
302                                               FIND_ANYWHERE );
303     if( p_vout )
304     {
305         printf("Filter string: %s\n", psz_string);
306         if( !strcmp( psz_filter_type, "sub-filter" ) )
307             var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
308         else
309             var_SetString( p_vout, psz_filter_type, psz_string );
310         vlc_object_release( p_vout );
311     }
312
313     printf("%s %s %d\n", __FILE__,__func__,__LINE__);
314
315     free( psz_string );
316     printf("%s %s %d\n", __FILE__,__func__,__LINE__);
317 }
318
319 void ExtVideo::updateFilters()
320 {
321     QString module = ModuleFromWidgetName( sender() );
322     //std::cout << "Module name: " << module.toStdString() << std::endl;
323
324     QCheckBox *checkbox = qobject_cast<QCheckBox*>(sender());
325     QGroupBox *groupbox = qobject_cast<QGroupBox*>(sender());
326
327     ChangeVFiltersString( qtu(module),
328                           checkbox ? checkbox->isChecked()
329                                    : groupbox->isChecked() );
330 }
331
332 void ExtVideo::initComboBoxItems( QObject *widget )
333 {
334     QComboBox *combobox = qobject_cast<QComboBox*>(widget);
335     if( !combobox ) return;
336     QString option = OptionFromWidgetName( widget );
337     module_config_t *p_item = config_FindConfig( VLC_OBJECT(p_intf),
338                                                  option.toStdString().c_str() );
339     if( p_item )
340     {
341         int i_type = p_item->i_type & CONFIG_ITEM;
342         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
343         {
344             if( i_type == CONFIG_ITEM_INTEGER
345              || i_type == CONFIG_ITEM_BOOL )
346                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->pi_list[i_index] );
347             else if( i_type == CONFIG_ITEM_STRING )
348                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->ppsz_list[i_index] );
349         }
350     }
351     else
352     {
353         msg_Err( p_intf, "Couldn't find option \"%s\".",
354                  option.toStdString().c_str() );
355     }
356 }
357
358 void ExtVideo::setWidgetValue( QObject *widget )
359 {
360     QString module = ModuleFromWidgetName( widget->parent() );
361     //std::cout << "Module name: " << module.toStdString() << std::endl;
362     QString option = OptionFromWidgetName( widget );
363     //std::cout << "Option name: " << option.toStdString() << std::endl;
364
365     vlc_object_t *p_obj = (vlc_object_t *)
366         vlc_object_find_name( p_intf->p_libvlc,
367                               module.toStdString().c_str(),
368                               FIND_CHILD );
369     int i_type;
370     vlc_value_t val;
371
372     if( !p_obj )
373     {
374         msg_Dbg( p_intf,
375                  "Module instance %s not found, looking in config values.",
376                  module.toStdString().c_str() );
377         i_type = config_GetType( p_intf, option.toStdString().c_str() ) & 0xf0;
378         switch( i_type )
379         {
380             case VLC_VAR_INTEGER:
381             case VLC_VAR_BOOL:
382                 val.i_int = config_GetInt( p_intf, option.toStdString().c_str() );
383                 break;
384             case VLC_VAR_FLOAT:
385                 val.f_float = config_GetFloat( p_intf, option.toStdString().c_str() );
386                 break;
387             case VLC_VAR_STRING:
388                 val.psz_string = config_GetPsz( p_intf, option.toStdString().c_str() );
389                 break;
390         }
391     }
392     else
393     {
394         i_type = var_Type( p_obj, option.toStdString().c_str() ) & 0xf0;
395         var_Get( p_obj, option.toStdString().c_str(), &val );
396         vlc_object_release( p_obj );
397     }
398
399     /* Try to cast to all the widgets we're likely to encounter. Only
400      * one of the casts is expected to work. */
401     QSlider        *slider        = qobject_cast<QSlider*>       (widget);
402     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (widget);
403     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (widget);
404     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(widget);
405     QDial          *dial          = qobject_cast<QDial*>         (widget);
406     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (widget);
407     QComboBox      *combobox      = qobject_cast<QComboBox*>     (widget);
408
409     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
410     {
411         int i_int = 0;
412         if( slider )        slider->setValue( val.i_int );
413         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
414                                                               : Qt::Unchecked );
415         else if( spinbox )  spinbox->setValue( val.i_int );
416         else if( dial )     dial->setValue( (540-val.i_int)%360 );
417         else if( lineedit )
418         {
419             char str[30];
420             sprintf( str, "%06X", val.i_int );
421             lineedit->setText( str );
422         }
423         else if( combobox ) combobox->setCurrentIndex(
424                             combobox->findData( val.i_int ) );
425         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
426     }
427     else if( i_type == VLC_VAR_FLOAT )
428     {
429         double f_float = 0;
430         if( slider ) slider->setValue( (int)(val.f_float*(double)slider->tickInterval())); /* hack alert! */
431         else if( doublespinbox ) doublespinbox->setValue(val.f_float);
432         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
433     }
434     else if( i_type == VLC_VAR_STRING )
435     {
436         if( lineedit ) lineedit->setText( qfu(val.psz_string) );
437         else if( combobox ) combobox->setCurrentIndex(
438                             combobox->findData( qfu( val.psz_string ) ) );
439         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
440         free( val.psz_string );
441     }
442     else
443         msg_Err( p_intf,
444                  "Module %s's %s variable is of an unsupported type (%d)",
445                  module.toStdString().c_str(),
446                  option.toStdString().c_str(),
447                  i_type );
448 }
449
450 void ExtVideo::updateFilterOptions()
451 {
452     QString module = ModuleFromWidgetName( sender()->parent() );
453     //std::cout << "Module name: " << module.toStdString() << std::endl;
454     QString option = OptionFromWidgetName( sender() );
455     //std::cout << "Option name: " << option.toStdString() << std::endl;
456
457     vlc_object_t *p_obj = (vlc_object_t *)
458         vlc_object_find_name( p_intf->p_libvlc,
459                               module.toStdString().c_str(),
460                               FIND_CHILD );
461     if( !p_obj )
462     {
463         msg_Err( p_intf, "Module %s not found.", module.toStdString().c_str() );
464         return;
465     }
466
467     int i_type = var_Type( p_obj, option.toStdString().c_str() );
468     bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
469     if( !b_is_command )
470     {
471         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.",
472                  module.toStdString().c_str(),
473                  option.toStdString().c_str() );
474         /* FIXME: restart automatically somewhere near the end of this function */
475     }
476
477     /* Try to cast to all the widgets we're likely to encounter. Only
478      * one of the casts is expected to work. */
479     QSlider        *slider        = qobject_cast<QSlider*>       (sender());
480     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (sender());
481     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (sender());
482     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(sender());
483     QDial          *dial          = qobject_cast<QDial*>         (sender());
484     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (sender());
485     QComboBox      *combobox      = qobject_cast<QComboBox*>     (sender());
486
487     i_type &= 0xf0;
488     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
489     {
490         int i_int = 0;
491         if( slider )        i_int = slider->value();
492         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
493         else if( spinbox )  i_int = spinbox->value();
494         else if( dial )     i_int = (540-dial->value())%360;
495         else if( lineedit ) i_int = lineedit->text().toInt(NULL,16);
496         else if( combobox ) i_int = combobox->itemData(combobox->currentIndex()).toInt();
497         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
498         config_PutInt( p_intf, option.toStdString().c_str(), i_int );
499         if( b_is_command )
500         {
501             if( i_type == VLC_VAR_INTEGER )
502                 var_SetInteger( p_obj, option.toStdString().c_str(), i_int );
503             else
504                 var_SetBool( p_obj, option.toStdString().c_str(), i_int );
505         }
506     }
507     else if( i_type == VLC_VAR_FLOAT )
508     {
509         double f_float = 0;
510         if( slider )             f_float = (double)slider->value()
511                                          / (double)slider->tickInterval(); /* hack alert! */
512         else if( doublespinbox ) f_float = doublespinbox->value();
513         else if( lineedit ) f_float = lineedit->text().toDouble();
514         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
515         config_PutFloat( p_intf, option.toStdString().c_str(), f_float );
516         if( b_is_command )
517             var_SetFloat( p_obj, option.toStdString().c_str(), f_float );
518     }
519     else if( i_type == VLC_VAR_STRING )
520     {
521         char *psz_string = NULL;
522         if( lineedit ) psz_string = strdup(qtu(lineedit->text()));
523         else if( combobox ) psz_string = strdup(qtu(combobox->itemData(
524                                          combobox->currentIndex()).toString()));
525         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
526         config_PutPsz( p_intf, option.toStdString().c_str(), psz_string );
527         if( b_is_command )
528             var_SetString( p_obj, option.toStdString().c_str(), psz_string );
529         free( psz_string );
530     }
531     else
532         msg_Err( p_intf,
533                  "Module %s's %s variable is of an unsupported type (%d)",
534                  module.toStdString().c_str(),
535                  option.toStdString().c_str(),
536                  i_type );
537
538     vlc_object_release( p_obj );
539 }
540
541 #if 0
542 void ExtVideo::gotoConf( QObject* src )
543 {
544 #define SHOWCONF(module) \
545     if( src->objectName().contains(module) ) \
546     { \
547         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
548         return; \
549     }
550     SHOWCONF( "clone" );
551     SHOWCONF( "magnify" );
552     SHOWCONF( "wave" );
553     SHOWCONF( "ripple" );
554     SHOWCONF( "invert" );
555     SHOWCONF( "puzzle" );
556     SHOWCONF( "wall" );
557     SHOWCONF( "gradient" );
558     SHOWCONF( "colorthres" )
559 }
560 #endif
561
562 /**********************************************************************
563  * Equalizer
564  **********************************************************************/
565
566 static const QString band_frequencies[] =
567 {
568     "   60Hz  ", " 170 Hz " , " 310 Hz ", " 600 Hz ", "  1 kHz  ",
569     "  3 kHz  " , "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
570 };
571
572 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
573                             QWidget( _parent ) , p_intf( _p_intf )
574 {
575     QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
576     smallFont.setPointSize( smallFont.pointSize() - 3 );
577
578     ui.setupUi( this );
579
580     ui.preampLabel->setFont( smallFont );
581     ui.preampSlider->setMaximum( 400 );
582     for( int i = 0 ; i < NB_PRESETS ; i ++ )
583     {
584         ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
585                                   QVariant( i ) );
586     }
587     CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
588
589     BUTTONACT( ui.enableCheck, enable() );
590     BUTTONACT( ui.eq2PassCheck, set2Pass() );
591
592     CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
593
594     QGridLayout *grid = new QGridLayout( ui.frame );
595     grid->setMargin( 0 );
596     for( int i = 0 ; i < BANDS ; i++ )
597     {
598         bands[i] = new QSlider( Qt::Vertical );
599         bands[i]->setMaximum( 400 );
600         bands[i]->setValue( 200 );
601         CONNECT( bands[i], valueChanged(int), this, setBand() );
602         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
603         band_texts[i]->setFont( smallFont );
604         grid->addWidget( bands[i], 0, i );
605         grid->addWidget( band_texts[i], 1, i );
606     }
607
608     /* Write down initial values */
609     aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
610                                     VLC_OBJECT_AOUT, FIND_ANYWHERE);
611     char *psz_af = NULL;
612     char *psz_bands;
613     float f_preamp;
614     if( p_aout )
615     {
616         psz_af = var_GetString( p_aout, "audio-filter" );
617         if( var_GetBool( p_aout, "equalizer-2pass" ) )
618             ui.eq2PassCheck->setChecked( true );
619         psz_bands = var_GetString( p_aout, "equalizer-bands" );
620         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
621         vlc_object_release( p_aout );
622     }
623     else
624     {
625         psz_af = config_GetPsz( p_intf, "audio-filter" );
626         if( config_GetInt( p_intf, "equalizer-2pass" ) )
627             ui.eq2PassCheck->setChecked( true );
628         psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
629         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
630     }
631     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
632         ui.enableCheck->setChecked( true );
633     enable( ui.enableCheck->isChecked() );
634
635     setValues( psz_bands, f_preamp );
636 }
637
638 Equalizer::~Equalizer()
639 {
640 }
641
642 void Equalizer::enable()
643 {
644     bool en = ui.enableCheck->isChecked();
645     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
646                        en ? VLC_TRUE : VLC_FALSE );
647     enable( en );
648 }
649
650 void Equalizer::enable( bool en )
651 {
652     ui.eq2PassCheck->setEnabled( en );
653     ui.preampLabel->setEnabled( en );
654     ui.preampSlider->setEnabled( en  );
655     for( int i = 0 ; i< BANDS; i++ )
656     {
657         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
658     }
659 }
660
661 void Equalizer::set2Pass()
662 {
663     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
664                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
665     vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
666
667     if( p_aout == NULL )
668         config_PutInt( p_intf, "equalizer-2pass", b_2p );
669     else
670     {
671         var_SetBool( p_aout, "equalizer-2pass", b_2p );
672         config_PutInt( p_intf, "equalizer-2pass", b_2p );
673         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
674         {
675             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
676         }
677         vlc_object_release( p_aout );
678     }
679 }
680
681 void Equalizer::setPreamp()
682 {
683     float f= (float)(  ui.preampSlider->value() ) /10 - 20;
684     char psz_val[5];
685     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
686                                        VLC_OBJECT_AOUT, FIND_ANYWHERE);
687
688     sprintf( psz_val, "%.1f", f );
689     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
690     if( p_aout )
691     {
692         delCallbacks( p_aout );
693         var_SetFloat( p_aout, "equalizer-preamp", f );
694         addCallbacks( p_aout );
695         vlc_object_release( p_aout );
696     }
697     config_PutFloat( p_intf, "equalizer-preamp", f );
698 }
699
700 void Equalizer::setBand()
701 {
702     char psz_values[102]; memset( psz_values, 0, 102 );
703
704     /**\todo smoothing */
705
706     for( int i = 0 ; i< BANDS ; i++ )
707     {
708         char psz_val[5];
709         float f_val = (float)(  bands[i]->value() ) / 10 - 20 ;
710         sprintf( psz_values, "%s %f", psz_values, f_val );
711         sprintf( psz_val, "% 5.1f", f_val );
712         band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
713     }
714     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
715                                           VLC_OBJECT_AOUT, FIND_ANYWHERE);
716     if( p_aout )
717     {
718         delCallbacks( p_aout );
719         var_SetString( p_aout, "equalizer-bands", psz_values );
720         addCallbacks( p_aout );
721         vlc_object_release( p_aout );
722     }
723 }
724 void Equalizer::setValues( char *psz_bands, float f_preamp )
725 {
726     char *p = psz_bands;
727     if ( p )
728     {
729         for( int i = 0; i < 10; i++ )
730         {
731             char psz_val[5];
732             float f = strtof( p, &p );
733             int  i_val= (int)( ( f + 20 ) * 10 );
734             bands[i]->setValue(  i_val );
735             sprintf( psz_val, "% 5.1f", f );
736             band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
737                                     "dB" );
738             if( p == NULL || *p == '\0' ) break;
739             p++;
740             if( *p == '\0' )  break;
741         }
742     }
743     char psz_val[5];
744     int i_val = (int)( ( f_preamp + 20 ) * 10 );
745     sprintf( psz_val, "%.1f", f_preamp );
746     ui.preampSlider->setValue( i_val );
747     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
748 }
749
750 void Equalizer::setPreset( int preset )
751 {
752     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
753                                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);
754
755     char psz_values[102]; memset( psz_values, 0, 102 );
756     for( int i = 0 ; i< 10 ;i++ )
757         sprintf( psz_values, "%s %.1f", psz_values,
758                                         eqz_preset_10b[preset]->f_amp[i] );
759
760     if( p_aout )
761     {
762         delCallbacks( p_aout );
763         var_SetString( p_aout, "equalizer-bands", psz_values );
764         var_SetFloat( p_aout, "equalizer-preamp",
765                       eqz_preset_10b[preset]->f_preamp );
766         addCallbacks( p_aout );
767         vlc_object_release( p_aout );
768     }
769     config_PutPsz( p_intf, "equalizer-bands", psz_values );
770     config_PutFloat( p_intf, "equalizer-preamp",
771                     eqz_preset_10b[preset]->f_preamp );
772
773     setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
774 }
775
776 void Equalizer::delCallbacks( aout_instance_t *p_aout )
777 {
778 //    var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
779 //    var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
780 }
781
782 void Equalizer::addCallbacks( aout_instance_t *p_aout )
783 {
784 //    var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
785 //    var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
786 }
787
788
789 /**********************************************************************
790  * Video filters / Adjust
791  **********************************************************************/
792
793 /**********************************************************************
794  * Audio filters
795  **********************************************************************/
796
797 /**********************************************************************
798  * Extended playbak controls
799  **********************************************************************/