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