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