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