1 /*****************************************************************************
2 * extended_panels.cpp : Extended controls panels
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id: preferences.cpp 16643 2006-09-13 12:45:46Z zorglub $
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <QGridLayout>
30 #include "components/extended_panels.hpp"
33 #include "../../audio_filter/equalizer_presets.h"
34 #include <audio_output.h>
35 #include <aout_internal.h>
36 #include <vlc_intf_strings.h>
39 /**********************************************************************
41 **********************************************************************/
43 static const QString band_frequencies[] =
45 " 60Hz ", " 170 Hz " , " 310 Hz ", " 600 Hz ", " 1 kHz ",
46 " 3 kHz " , " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
49 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
50 QWidget( _parent ) , p_intf( _p_intf )
52 QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
53 smallFont.setPointSize( smallFont.pointSize() - 3 );
57 ui.preampLabel->setFont( smallFont );
58 ui.preampSlider->setMaximum( 400 );
59 for( int i = 0 ; i < NB_PRESETS ; i ++ )
61 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
64 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
66 BUTTONACT( ui.enableCheck, enable() );
67 BUTTONACT( ui.eq2PassCheck, set2Pass() );
69 CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
71 QGridLayout *grid = new QGridLayout( ui.frame );
73 for( int i = 0 ; i < BANDS ; i++ )
75 bands[i] = new QSlider( Qt::Vertical );
76 bands[i]->setMaximum( 400 );
77 bands[i]->setValue( 200 );
78 CONNECT( bands[i], valueChanged(int), this, setBand() );
79 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
80 band_texts[i]->setFont( smallFont );
81 grid->addWidget( bands[i], 0, i );
82 grid->addWidget( band_texts[i], 1, i );
85 /* Write down initial values */
86 aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
87 VLC_OBJECT_AOUT, FIND_ANYWHERE);
93 psz_af = var_GetString( p_aout, "audio-filter" );
94 if( var_GetBool( p_aout, "equalizer-2pass" ) )
95 ui.eq2PassCheck->setChecked( true );
96 psz_bands = var_GetString( p_aout, "equalizer-bands" );
97 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
98 vlc_object_release( p_aout );
102 psz_af = config_GetPsz( p_intf, "audio-filter" );
103 if( config_GetInt( p_intf, "equalizer-2pass" ) )
104 ui.eq2PassCheck->setChecked( true );
105 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
106 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
108 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
109 ui.enableCheck->setChecked( true );
110 enable( ui.enableCheck->isChecked() );
112 setValues( psz_bands, f_preamp );
115 Equalizer::~Equalizer()
119 void Equalizer::enable()
121 bool en = ui.enableCheck->isChecked();
122 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
123 en ? VLC_TRUE : VLC_FALSE );
127 void Equalizer::enable( bool en )
129 ui.eq2PassCheck->setEnabled( en );
130 ui.preampLabel->setEnabled( en );
131 ui.preampSlider->setEnabled( en );
132 for( int i = 0 ; i< BANDS; i++ )
134 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
138 void Equalizer::set2Pass()
140 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
141 VLC_OBJECT_AOUT, FIND_ANYWHERE);
142 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
145 config_PutInt( p_intf, "equalizer-2pass", b_2p );
148 var_SetBool( p_aout, "equalizer-2pass", b_2p );
149 config_PutInt( p_intf, "equalizer-2pass", b_2p );
150 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
152 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
154 vlc_object_release( p_aout );
158 void Equalizer::setPreamp()
160 float f= (float)( ui.preampSlider->value() ) /10 - 20;
162 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
163 VLC_OBJECT_AOUT, FIND_ANYWHERE);
165 sprintf( psz_val, "%.1f", f );
166 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
169 delCallbacks( p_aout );
170 var_SetFloat( p_aout, "equalizer-preamp", f );
171 addCallbacks( p_aout );
172 vlc_object_release( p_aout );
174 config_PutFloat( p_intf, "equalizer-preamp", f );
177 void Equalizer::setBand()
179 char psz_values[102]; memset( psz_values, 0, 102 );
181 /**\todo smoothing */
183 for( int i = 0 ; i< BANDS ; i++ )
186 float f_val = (float)( bands[i]->value() ) / 10 - 20 ;
187 sprintf( psz_values, "%s %f", psz_values, f_val );
188 sprintf( psz_val, "% 5.1f", f_val );
189 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
191 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
192 VLC_OBJECT_AOUT, FIND_ANYWHERE);
195 delCallbacks( p_aout );
196 var_SetString( p_aout, "equalizer-bands", psz_values );
197 addCallbacks( p_aout );
198 vlc_object_release( p_aout );
201 void Equalizer::setValues( char *psz_bands, float f_preamp )
206 for( int i = 0; i < 10; i++ )
209 float f = strtof( p, &p );
210 int i_val= (int)( ( f + 20 ) * 10 );
211 bands[i]->setValue( i_val );
212 sprintf( psz_val, "% 5.1f", f );
213 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
215 if( p == NULL ) break;
221 int i_val = (int)( ( f_preamp + 20 ) * 10 );
222 sprintf( psz_val, "%.1f", f_preamp );
223 ui.preampSlider->setValue( i_val );
224 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
227 void Equalizer::setPreset( int preset )
229 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
230 VLC_OBJECT_AOUT, FIND_ANYWHERE);
232 char psz_values[102]; memset( psz_values, 0, 102 );
233 for( int i = 0 ; i< 10 ;i++ )
234 sprintf( psz_values, "%s %.1f", psz_values,
235 eqz_preset_10b[preset]->f_amp[i] );
239 delCallbacks( p_aout );
240 var_SetString( p_aout, "equalizer-bands", psz_values );
241 var_SetFloat( p_aout, "equalizer-preamp",
242 eqz_preset_10b[preset]->f_preamp );
243 addCallbacks( p_aout );
244 vlc_object_release( p_aout );
246 config_PutPsz( p_intf, "equalizer-bands", psz_values );
247 config_PutFloat( p_intf, "equalizer-preamp",
248 eqz_preset_10b[preset]->f_preamp );
250 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
253 void Equalizer::delCallbacks( aout_instance_t *p_aout )
255 // var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
256 // var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
259 void Equalizer::addCallbacks( aout_instance_t *p_aout )
261 // var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
262 // var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
266 /**********************************************************************
267 * Video filters / Adjust
268 **********************************************************************/
270 /**********************************************************************
272 **********************************************************************/
274 /**********************************************************************
275 * Extended playbak controls
276 **********************************************************************/