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