]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Qt4 - Extended Panels: add callback on audio-presets to fix the issue when the audio...
[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 #include <string.h>
45
46 #if 0
47 class ConfClickHandler : public QObject
48 {
49 public:
50     ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject (_e) {
51         e = _e; p_intf = _p_intf;
52     }
53     virtual ~ConfClickHandler() {}
54     bool eventFilter( QObject *obj, QEvent *evt )
55     {
56         if( evt->type() == QEvent::MouseButtonPress )
57         {
58             e->gotoConf( obj );
59             return true;
60         }
61         return false;
62     }
63 private:
64     ExtVideo* e;
65     intf_thread_t *p_intf;
66 };
67 #endif
68
69 QString ModuleFromWidgetName( QObject *obj )
70 {
71     return obj->objectName().replace("Enable","");
72 }
73
74 QString OptionFromWidgetName( QObject *obj )
75 {
76     /* Gruik ? ... nah */
77     QString option = obj->objectName().replace( "Slider", "" )
78                                       .replace( "Combo" , "" )
79                                       .replace( "Dial"  , "" )
80                                       .replace( "Check" , "" )
81                                       .replace( "Spin"  , "" )
82                                       .replace( "Text"  , "" );
83     for( char a = 'A'; a <= 'Z'; a++ )
84     {
85         option = option.replace( QString( a ),
86                                  QString( '-' ) + QString( a + 'a' - 'A' ) );
87     }
88     return option;
89 }
90
91 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QWidget *_parent ) :
92                            QWidget( _parent ) , p_intf( _p_intf )
93 {
94     ui.setupUi( this );
95
96 #define SETUP_VFILTER( widget ) \
97     { \
98         vlc_object_t *p_obj = (vlc_object_t *) \
99             vlc_object_find_name( p_intf->p_libvlc, \
100                                   #widget, \
101                                   FIND_CHILD ); \
102         QCheckBox *checkbox = qobject_cast<QCheckBox*>(ui.widget##Enable); \
103         QGroupBox *groupbox = qobject_cast<QGroupBox*>(ui.widget##Enable); \
104         if( p_obj ) \
105         { \
106             vlc_object_release( p_obj ); \
107             if( checkbox ) checkbox->setCheckState( Qt::Checked ); \
108             else groupbox->setChecked( true ); \
109         } \
110         else \
111         { \
112             if( checkbox ) checkbox->setCheckState( Qt::Unchecked ); \
113             else groupbox->setChecked( false ); \
114         } \
115     } \
116     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
117 #define SETUP_VFILTER_OPTION( widget, signal ) \
118     initComboBoxItems( ui.widget ); \
119     setWidgetValue( ui.widget ); \
120     CONNECT( ui.widget, signal, this, updateFilterOptions() );
121
122     SETUP_VFILTER( adjust )
123     SETUP_VFILTER_OPTION( hueSlider, valueChanged(int) )
124     SETUP_VFILTER_OPTION( contrastSlider, valueChanged(int) )
125     SETUP_VFILTER_OPTION( brightnessSlider, valueChanged(int) )
126     SETUP_VFILTER_OPTION( saturationSlider, valueChanged(int) )
127     SETUP_VFILTER_OPTION( gammaSlider, valueChanged(int) )
128     SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged(int) )
129
130     SETUP_VFILTER( extract )
131     SETUP_VFILTER_OPTION( extractComponentText, textChanged(QString) )
132
133     SETUP_VFILTER( colorthres )
134     SETUP_VFILTER_OPTION( colorthresColorText, textChanged(QString) )
135     SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged(int) )
136     SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged(int) )
137
138     SETUP_VFILTER( invert )
139
140     SETUP_VFILTER( gradient )
141     SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged(QString) )
142     SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged(int) )
143     SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged(int) )
144
145     SETUP_VFILTER( motionblur )
146     SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged(int) )
147
148     SETUP_VFILTER( motiondetect )
149
150     SETUP_VFILTER( noise )
151
152     SETUP_VFILTER( psychedelic )
153
154     SETUP_VFILTER( sharpen )
155     SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged(int) )
156
157     SETUP_VFILTER( ripple )
158
159     SETUP_VFILTER( wave )
160
161     SETUP_VFILTER( transform )
162     SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged(QString) )
163
164     SETUP_VFILTER( rotate )
165     SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged(int) )
166     ui.rotateAngleDial->setWrapping( true );
167     ui.rotateAngleDial->setNotchesVisible( true );
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     const 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     module_t *p_obj = module_FindName( p_intf, psz_name );
215     if( !p_obj )
216     {
217         msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
218         return;
219     }
220
221     if( module_IsCapable( p_obj, "video filter2" ) )
222     {
223         psz_filter_type = "video-filter";
224     }
225     else if( module_IsCapable( p_obj, "video filter" ) )
226     {
227         psz_filter_type = "vout-filter";
228     }
229     else if( module_IsCapable( p_obj, "sub filter" ) )
230     {
231         psz_filter_type = "sub-filter";
232     }
233     else
234     {
235         vlc_object_release( p_obj );
236         msg_Err( p_intf, "Unknown video filter type." );
237         return;
238     }
239     vlc_object_release( p_obj );
240
241     psz_string = config_GetPsz( p_intf, psz_filter_type );
242
243     if( !psz_string ) psz_string = strdup("");
244
245     psz_parser = strstr( psz_string, psz_name );
246
247     if( b_add )
248     {
249         if( !psz_parser )
250         {
251             psz_parser = psz_string;
252             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
253                             psz_string, psz_name );
254             free( psz_parser );
255         }
256         else
257         {
258             return;
259         }
260     }
261     else
262     {
263         if( psz_parser )
264         {
265             if( *(psz_parser + strlen(psz_name)) == ':' )
266             {
267                 memmove( psz_parser, psz_parser + strlen(psz_name) + 1,
268                          strlen(psz_parser + strlen(psz_name) + 1 ) + 1 );
269             }
270             else
271             {
272                 *psz_parser = '\0';
273             }
274
275             /* Remove trailing : : */
276             if( strlen( psz_string ) > 0 &&
277                 *( psz_string + strlen( psz_string ) -1 ) == ':' )
278             {
279                 *( psz_string + strlen( psz_string ) -1 ) = '\0';
280             }
281         }
282         else
283         {
284             free( psz_string );
285             return;
286         }
287     }
288     /* Vout is not kept, so put that in the config */
289     config_PutPsz( p_intf, psz_filter_type, psz_string );
290     if( !strcmp( psz_filter_type, "video-filter" ) )
291         ui.videoFilterText->setText( psz_string );
292     else if( !strcmp( psz_filter_type, "vout-filter" ) )
293         ui.voutFilterText->setText( psz_string );
294     else if( !strcmp( psz_filter_type, "sub-filter" ) )
295         ui.subpictureFilterText->setText( psz_string );
296
297     /* Try to set on the fly */
298     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
299                                               FIND_ANYWHERE );
300     if( p_vout )
301     {
302         if( !strcmp( psz_filter_type, "sub-filter" ) )
303             var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
304         else
305             var_SetString( p_vout, psz_filter_type, psz_string );
306         vlc_object_release( p_vout );
307     }
308
309     free( psz_string );
310 }
311
312 void ExtVideo::updateFilters()
313 {
314     QString module = ModuleFromWidgetName( sender() );
315     //std::cout << "Module name: " << module.toStdString() << std::endl;
316
317     QCheckBox *checkbox = qobject_cast<QCheckBox*>(sender());
318     QGroupBox *groupbox = qobject_cast<QGroupBox*>(sender());
319
320     ChangeVFiltersString( qtu(module),
321                           checkbox ? checkbox->isChecked()
322                                    : groupbox->isChecked() );
323 }
324
325 void ExtVideo::initComboBoxItems( QObject *widget )
326 {
327     QComboBox *combobox = qobject_cast<QComboBox*>(widget);
328     if( !combobox ) return;
329     QString option = OptionFromWidgetName( widget );
330     module_config_t *p_item = config_FindConfig( VLC_OBJECT(p_intf),
331                                                  option.toStdString().c_str() );
332     if( p_item )
333     {
334         int i_type = p_item->i_type & CONFIG_ITEM;
335         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
336         {
337             if( i_type == CONFIG_ITEM_INTEGER
338              || i_type == CONFIG_ITEM_BOOL )
339                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->pi_list[i_index] );
340             else if( i_type == CONFIG_ITEM_STRING )
341                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ), p_item->ppsz_list[i_index] );
342         }
343     }
344     else
345     {
346         msg_Err( p_intf, "Couldn't find option \"%s\".",
347                  option.toStdString().c_str() );
348     }
349 }
350
351 void ExtVideo::setWidgetValue( QObject *widget )
352 {
353     QString module = ModuleFromWidgetName( widget->parent() );
354     //std::cout << "Module name: " << module.toStdString() << std::endl;
355     QString option = OptionFromWidgetName( widget );
356     //std::cout << "Option name: " << option.toStdString() << std::endl;
357
358     vlc_object_t *p_obj = (vlc_object_t *)
359         vlc_object_find_name( p_intf->p_libvlc,
360                               module.toStdString().c_str(),
361                               FIND_CHILD );
362     int i_type;
363     vlc_value_t val;
364
365     if( !p_obj )
366     {
367 #if 0
368         msg_Dbg( p_intf,
369                  "Module instance %s not found, looking in config values.",
370                  module.toStdString().c_str() );
371 #endif
372         i_type = config_GetType( p_intf, option.toStdString().c_str() ) & 0xf0;
373         switch( i_type )
374         {
375             case VLC_VAR_INTEGER:
376             case VLC_VAR_BOOL:
377                 val.i_int = config_GetInt( p_intf, option.toStdString().c_str() );
378                 break;
379             case VLC_VAR_FLOAT:
380                 val.f_float = config_GetFloat( p_intf, option.toStdString().c_str() );
381                 break;
382             case VLC_VAR_STRING:
383                 val.psz_string = config_GetPsz( p_intf, option.toStdString().c_str() );
384                 break;
385         }
386     }
387     else
388     {
389         i_type = var_Type( p_obj, option.toStdString().c_str() ) & 0xf0;
390         var_Get( p_obj, option.toStdString().c_str(), &val );
391         vlc_object_release( p_obj );
392     }
393
394     /* Try to cast to all the widgets we're likely to encounter. Only
395      * one of the casts is expected to work. */
396     QSlider        *slider        = qobject_cast<QSlider*>       (widget);
397     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (widget);
398     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (widget);
399     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(widget);
400     QDial          *dial          = qobject_cast<QDial*>         (widget);
401     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (widget);
402     QComboBox      *combobox      = qobject_cast<QComboBox*>     (widget);
403
404     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
405     {
406         int i_int = 0;
407         if( slider )        slider->setValue( val.i_int );
408         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
409                                                               : Qt::Unchecked );
410         else if( spinbox )  spinbox->setValue( val.i_int );
411         else if( dial )     dial->setValue( (540-val.i_int)%360 );
412         else if( lineedit )
413         {
414             char str[30];
415             sprintf( str, "%06X", val.i_int );
416             lineedit->setText( str );
417         }
418         else if( combobox ) combobox->setCurrentIndex(
419                             combobox->findData( val.i_int ) );
420         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
421     }
422     else if( i_type == VLC_VAR_FLOAT )
423     {
424         double f_float = 0;
425         if( slider ) slider->setValue( (int)(val.f_float*(double)slider->tickInterval())); /* hack alert! */
426         else if( doublespinbox ) doublespinbox->setValue(val.f_float);
427         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
428     }
429     else if( i_type == VLC_VAR_STRING )
430     {
431         if( lineedit ) lineedit->setText( qfu(val.psz_string) );
432         else if( combobox ) combobox->setCurrentIndex(
433                             combobox->findData( qfu( val.psz_string ) ) );
434         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
435         free( val.psz_string );
436     }
437     else
438         msg_Err( p_intf,
439                  "Module %s's %s variable is of an unsupported type (%d)",
440                  module.toStdString().c_str(),
441                  option.toStdString().c_str(),
442                  i_type );
443 }
444
445 void ExtVideo::updateFilterOptions()
446 {
447     QString module = ModuleFromWidgetName( sender()->parent() );
448     //std::cout << "Module name: " << module.toStdString() << std::endl;
449     QString option = OptionFromWidgetName( sender() );
450     //std::cout << "Option name: " << option.toStdString() << std::endl;
451
452     vlc_object_t *p_obj = (vlc_object_t *)
453         vlc_object_find_name( p_intf->p_libvlc,
454                               module.toStdString().c_str(),
455                               FIND_CHILD );
456     if( !p_obj )
457     {
458         msg_Err( p_intf, "Module %s not found.", module.toStdString().c_str() );
459         return;
460     }
461
462     int i_type = var_Type( p_obj, option.toStdString().c_str() );
463     bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
464     if( !b_is_command )
465     {
466         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.",
467                  module.toStdString().c_str(),
468                  option.toStdString().c_str() );
469         /* FIXME: restart automatically somewhere near the end of this function */
470     }
471
472     /* Try to cast to all the widgets we're likely to encounter. Only
473      * one of the casts is expected to work. */
474     QSlider        *slider        = qobject_cast<QSlider*>       (sender());
475     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     (sender());
476     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      (sender());
477     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>(sender());
478     QDial          *dial          = qobject_cast<QDial*>         (sender());
479     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     (sender());
480     QComboBox      *combobox      = qobject_cast<QComboBox*>     (sender());
481
482     i_type &= 0xf0;
483     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
484     {
485         int i_int = 0;
486         if( slider )        i_int = slider->value();
487         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
488         else if( spinbox )  i_int = spinbox->value();
489         else if( dial )     i_int = (540-dial->value())%360;
490         else if( lineedit ) i_int = lineedit->text().toInt(NULL,16);
491         else if( combobox ) i_int = combobox->itemData(combobox->currentIndex()).toInt();
492         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
493         config_PutInt( p_intf, option.toStdString().c_str(), i_int );
494         if( b_is_command )
495         {
496             if( i_type == VLC_VAR_INTEGER )
497                 var_SetInteger( p_obj, option.toStdString().c_str(), i_int );
498             else
499                 var_SetBool( p_obj, option.toStdString().c_str(), i_int );
500         }
501     }
502     else if( i_type == VLC_VAR_FLOAT )
503     {
504         double f_float = 0;
505         if( slider )             f_float = (double)slider->value()
506                                          / (double)slider->tickInterval(); /* hack alert! */
507         else if( doublespinbox ) f_float = doublespinbox->value();
508         else if( lineedit ) f_float = lineedit->text().toDouble();
509         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
510         config_PutFloat( p_intf, option.toStdString().c_str(), f_float );
511         if( b_is_command )
512             var_SetFloat( p_obj, option.toStdString().c_str(), f_float );
513     }
514     else if( i_type == VLC_VAR_STRING )
515     {
516         char *psz_string = NULL;
517         if( lineedit ) psz_string = strdup(qtu(lineedit->text()));
518         else if( combobox ) psz_string = strdup(qtu(combobox->itemData(
519                                          combobox->currentIndex()).toString()));
520         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
521         config_PutPsz( p_intf, option.toStdString().c_str(), psz_string );
522         if( b_is_command )
523             var_SetString( p_obj, option.toStdString().c_str(), psz_string );
524         free( psz_string );
525     }
526     else
527         msg_Err( p_intf,
528                  "Module %s's %s variable is of an unsupported type (%d)",
529                  module.toStdString().c_str(),
530                  option.toStdString().c_str(),
531                  i_type );
532
533     vlc_object_release( p_obj );
534 }
535
536 #if 0
537 void ExtVideo::gotoConf( QObject* src )
538 {
539 #define SHOWCONF(module) \
540     if( src->objectName().contains(module) ) \
541     { \
542         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
543         return; \
544     }
545     SHOWCONF( "clone" );
546     SHOWCONF( "magnify" );
547     SHOWCONF( "wave" );
548     SHOWCONF( "ripple" );
549     SHOWCONF( "invert" );
550     SHOWCONF( "puzzle" );
551     SHOWCONF( "wall" );
552     SHOWCONF( "gradient" );
553     SHOWCONF( "colorthres" )
554 }
555 #endif
556
557 /**********************************************************************
558  * Equalizer
559  **********************************************************************/
560
561 static const QString band_frequencies[] =
562 {
563     "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
564     "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
565 };
566
567 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
568                             QWidget( _parent ) , p_intf( _p_intf )
569 {
570     QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
571     smallFont.setPointSize( smallFont.pointSize() - 3 );
572
573     ui.setupUi( this );
574     presetsComboBox = ui.presetsCombo;
575
576     ui.preampLabel->setFont( smallFont );
577     ui.preampSlider->setMaximum( 400 );
578     for( int i = 0 ; i < NB_PRESETS ; i ++ )
579     {
580         ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
581                                   QVariant( i ) );
582     }
583     CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
584
585     BUTTONACT( ui.enableCheck, enable() );
586     BUTTONACT( ui.eq2PassCheck, set2Pass() );
587
588     CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
589
590     QGridLayout *grid = new QGridLayout( ui.frame );
591     grid->setMargin( 0 );
592     for( int i = 0 ; i < BANDS ; i++ )
593     {
594         bands[i] = new QSlider( Qt::Vertical );
595         bands[i]->setMaximum( 400 );
596         bands[i]->setValue( 200 );
597         CONNECT( bands[i], valueChanged(int), this, setBand() );
598         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
599         band_texts[i]->setFont( smallFont );
600         grid->addWidget( bands[i], 0, i );
601         grid->addWidget( band_texts[i], 1, i );
602     }
603
604     /* Write down initial values */
605     aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
606                                     VLC_OBJECT_AOUT, FIND_ANYWHERE);
607     char *psz_af = NULL;
608     char *psz_bands;
609     float f_preamp;
610     if( p_aout )
611     {
612         psz_af = var_GetString( p_aout, "audio-filter" );
613         if( var_GetBool( p_aout, "equalizer-2pass" ) )
614             ui.eq2PassCheck->setChecked( true );
615         psz_bands = var_GetString( p_aout, "equalizer-bands" );
616         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
617         vlc_object_release( p_aout );
618     }
619     else
620     {
621         psz_af = config_GetPsz( p_intf, "audio-filter" );
622         if( config_GetInt( p_intf, "equalizer-2pass" ) )
623             ui.eq2PassCheck->setChecked( true );
624         psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
625         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
626     }
627     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
628         ui.enableCheck->setChecked( true );
629     enable( ui.enableCheck->isChecked() );
630
631     setValues( psz_bands, f_preamp );
632 }
633
634 Equalizer::~Equalizer()
635 {
636 }
637
638 void Equalizer::enable()
639 {
640     bool en = ui.enableCheck->isChecked();
641     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
642                        en ? VLC_TRUE : VLC_FALSE );
643 //    aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
644 //                       en ? VLC_TRUE : VLC_FALSE );
645 //     aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
646 //                       en ? VLC_TRUE : VLC_FALSE );
647      enable( en );
648 }
649
650 void Equalizer::enable( bool en )
651 {
652     ui.eq2PassCheck->setEnabled( en );
653     ui.preampLabel->setEnabled( en );
654     ui.preampSlider->setEnabled( en  );
655     for( int i = 0 ; i< BANDS; i++ )
656     {
657         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
658     }
659 }
660
661 void Equalizer::set2Pass()
662 {
663     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
664                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
665     vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
666
667     if( p_aout == NULL )
668         config_PutInt( p_intf, "equalizer-2pass", b_2p );
669     else
670     {
671         var_SetBool( p_aout, "equalizer-2pass", b_2p );
672         config_PutInt( p_intf, "equalizer-2pass", b_2p );
673         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
674         {
675             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
676         }
677         vlc_object_release( p_aout );
678     }
679 }
680
681 void Equalizer::setPreamp()
682 {
683     float f= (float)(  ui.preampSlider->value() ) /10 - 20;
684     char psz_val[5];
685     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
686                                        VLC_OBJECT_AOUT, FIND_ANYWHERE);
687
688     sprintf( psz_val, "%.1f", f );
689     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
690     if( p_aout )
691     {
692         delCallbacks( p_aout );
693         var_SetFloat( p_aout, "equalizer-preamp", f );
694         addCallbacks( p_aout );
695         vlc_object_release( p_aout );
696     }
697     config_PutFloat( p_intf, "equalizer-preamp", f );
698 }
699
700 void Equalizer::setBand()
701 {
702     char psz_values[102]; memset( psz_values, 0, 102 );
703
704     /**\todo smoothing */
705
706     for( int i = 0 ; i< BANDS ; i++ )
707     {
708         char psz_val[5];
709         float f_val = (float)(  bands[i]->value() ) / 10 - 20 ;
710         sprintf( psz_values, "%s %f", psz_values, f_val );
711         sprintf( psz_val, "% 5.1f", f_val );
712         band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
713     }
714     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
715                                           VLC_OBJECT_AOUT, FIND_ANYWHERE);
716     if( p_aout )
717     {
718         delCallbacks( p_aout );
719         var_SetString( p_aout, "equalizer-bands", psz_values );
720         addCallbacks( p_aout );
721         vlc_object_release( p_aout );
722     }
723 }
724 void Equalizer::setValues( char *psz_bands, float f_preamp )
725 {
726     char *p = psz_bands;
727     if ( p )
728     {
729         for( int i = 0; i < 10; i++ )
730         {
731             char psz_val[5];
732             float f = strtof( p, &p );
733             int  i_val= (int)( ( f + 20 ) * 10 );
734             bands[i]->setValue(  i_val );
735             sprintf( psz_val, "% 5.1f", f );
736             band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
737                                     "dB" );
738             if( p == NULL || *p == '\0' ) break;
739             p++;
740             if( *p == '\0' )  break;
741         }
742     }
743     char psz_val[5];
744     int i_val = (int)( ( f_preamp + 20 ) * 10 );
745     sprintf( psz_val, "%.1f", f_preamp );
746     ui.preampSlider->setValue( i_val );
747     ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
748 }
749
750 void Equalizer::setPreset( int preset )
751 {
752     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
753                                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);
754
755     char psz_values[102]; memset( psz_values, 0, 102 );
756     for( int i = 0 ; i< 10 ;i++ )
757         sprintf( psz_values, "%s %.1f", psz_values,
758                                         eqz_preset_10b[preset]->f_amp[i] );
759
760     if( p_aout )
761     {
762         delCallbacks( p_aout );
763         var_SetString( p_aout, "equalizer-bands", psz_values );
764         var_SetFloat( p_aout, "equalizer-preamp",
765                       eqz_preset_10b[preset]->f_preamp );
766         addCallbacks( p_aout );
767         vlc_object_release( p_aout );
768     }
769     config_PutPsz( p_intf, "equalizer-bands", psz_values );
770     config_PutFloat( p_intf, "equalizer-preamp",
771                     eqz_preset_10b[preset]->f_preamp );
772
773     setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
774 }
775
776 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
777                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
778 {
779     char *psz_preset = newval.psz_string;
780     Equalizer *eq = (Equalizer *)p_data;
781     eq->presetsComboBox->setCurrentIndex( eq->presetsComboBox->findText( qfu( psz_preset) ) );
782     return VLC_SUCCESS;
783 }
784
785 void Equalizer::delCallbacks( aout_instance_t *p_aout )
786 {
787     //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
788     //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
789     var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
790 }
791
792 void Equalizer::addCallbacks( aout_instance_t *p_aout )
793 {
794     //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
795     //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
796     var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
797 }
798
799 /**********************************************************************
800  * Spatializer
801  **********************************************************************/
802 static const char *psz_control_names[] =
803 {
804     "Roomsize", "Width" , "Wet", "Dry", "Damp"
805 };
806 static const QString control_names[] =
807 {
808     "Roomsize", "Width" , "Wet", "Dry", "Damp"
809 };
810
811 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
812     QWidget( _parent ) , p_intf( _p_intf )
813 {
814     QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
815     smallFont.setPointSize( smallFont.pointSize() - 3 );
816
817     ui.setupUi( this );
818
819     QGridLayout *grid = new QGridLayout( ui.frame );
820     grid->setMargin( 0 );
821
822     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
823     {
824         spatCtrl[i] = new QSlider( Qt::Vertical );
825         if( i < 2)
826         {
827             spatCtrl[i]->setMaximum( 10 );
828             spatCtrl[i]->setValue( 2 );
829         }
830         else
831         {
832             spatCtrl[i]->setMaximum( 10 );
833             spatCtrl[i]->setValue( 0 );
834             spatCtrl[i]->setMinimum( -10 );
835         }
836         oldControlVars[i] = spatCtrl[i]->value();
837         CONNECT( spatCtrl[i], valueChanged(int), this, setInitValues() );
838         ctrl_texts[i] = new QLabel( control_names[i] + "\n" );
839         ctrl_texts[i]->setFont( smallFont );
840         ctrl_readout[i] = new QLabel( "" );
841         ctrl_readout[i]->setFont( smallFont );
842         grid->addWidget( spatCtrl[i], 0, i );
843         grid->addWidget( ctrl_readout[i],1,i);
844         grid->addWidget( ctrl_texts[i], 2, i );
845     }
846
847     BUTTONACT( ui.enableCheck, enable() );
848
849     /* Write down initial values */
850     aout_instance_t *p_aout = (aout_instance_t *)
851         vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
852     char *psz_af = NULL;
853
854     if( p_aout )
855     {
856         psz_af = var_GetString( p_aout, "audio-filter" );
857         for( int i = 0; i < NUM_SP_CTRL ; i++)
858         {
859             controlVars[i] = var_GetFloat( p_aout,  psz_control_names[i] );
860         }
861         vlc_object_release( p_aout );
862     }
863     else
864     {
865         psz_af = config_GetPsz( p_aout, "audio-filter" );
866         for( int i = 0; i < NUM_SP_CTRL ; i++)
867         {
868             controlVars[i] = config_GetFloat( p_intf,  psz_control_names[i] );
869         }
870     }
871     if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
872         ui.enableCheck->setChecked( true );
873     enable( ui.enableCheck->isChecked() );
874     setValues( controlVars );
875
876 }
877
878 Spatializer::~Spatializer()
879 {
880 }
881
882 void Spatializer::enable()
883 {
884     bool en = ui.enableCheck->isChecked();
885     aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
886             en ? VLC_TRUE : VLC_FALSE );
887     enable( en );
888 }
889
890 void Spatializer::enable( bool en )
891 {
892     for( int i = 0 ; i< NUM_SP_CTRL; i++ )
893     {
894         spatCtrl[i]->setEnabled( en );
895         ctrl_texts[i]->setEnabled( en );
896         ctrl_readout[i]->setEnabled( en );
897     }
898 }
899 void Spatializer::setInitValues()
900 {
901     setValues(controlVars);
902 }
903
904 void Spatializer::setValues(float *controlVars)
905 {
906     char psz_val[5];
907     char var_name[5];
908     aout_instance_t *p_aout= (aout_instance_t *)
909         vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
910
911     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
912     {
913         float f= (float)(  spatCtrl[i]->value() );
914         sprintf( psz_val, "%.1f", f );
915         ctrl_readout[i]->setText( psz_val );
916     }
917     if( p_aout )
918     {
919         for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
920         {
921             if( oldControlVars[i] != spatCtrl[i]->value() )
922             {
923                 var_SetFloat( p_aout, psz_control_names[i],
924                         (float)spatCtrl[i]->value() );
925                 config_PutFloat( p_intf, psz_control_names[i],
926                         (float) spatCtrl[i]->value());
927                 oldControlVars[i] = (float) spatCtrl[i]->value();
928             }
929         }
930         vlc_object_release( p_aout );
931     }
932     //    printf("set callback values %s %s %d\n", __FILE__,__func__,__LINE__);
933
934 }
935 void Spatializer::delCallbacks( aout_instance_t *p_aout )
936 {
937     //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
938     //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
939 }
940
941 void Spatializer::addCallbacks( aout_instance_t *p_aout )
942 {
943     //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
944     //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
945 }
946
947 /**********************************************************************
948  * Video filters / Adjust
949  **********************************************************************/
950
951 /**********************************************************************
952  * Audio filters
953  **********************************************************************/
954
955 /**********************************************************************
956  * Extended playbak controls
957  **********************************************************************/