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"
35 #include <vlc_intf_strings.h>
38 /**********************************************************************
40 **********************************************************************/
42 static const QString band_frequencies[] =
44 " 60Hz ", " 170 Hz " , " 310 Hz ", " 600 Hz ", " 1 kHz ",
45 " 3 kHz " , " 6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
48 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
49 QWidget( _parent ) , p_intf( _p_intf )
51 QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
52 smallFont.setPointSize( smallFont.pointSize() - 3 );
56 ui.preampLabel->setFont( smallFont );
57 ui.preampSlider->setMaximum( 400 );
58 for( int i = 0 ; i < NB_PRESETS ; i ++ )
60 ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
63 CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
65 BUTTONACT( ui.enableCheck, enable() );
66 BUTTONACT( ui.eq2PassCheck, set2Pass() );
68 CONNECT( ui.preampSlider, valueChanged(int), this, setPreamp() );
70 QGridLayout *grid = new QGridLayout( ui.frame );
72 for( int i = 0 ; i < BANDS ; i++ )
74 bands[i] = new QSlider( Qt::Vertical );
75 bands[i]->setMaximum( 400 );
76 bands[i]->setValue( 200 );
77 CONNECT( bands[i], valueChanged(int), this, setBand() );
78 band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
79 band_texts[i]->setFont( smallFont );
80 grid->addWidget( bands[i], 0, i );
81 grid->addWidget( band_texts[i], 1, i );
84 /* Write down initial values */
85 aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
86 VLC_OBJECT_AOUT, FIND_ANYWHERE);
92 psz_af = var_GetString( p_aout, "audio-filter" );
93 if( var_GetBool( p_aout, "equalizer-2pass" ) )
94 ui.eq2PassCheck->setChecked( true );
95 psz_bands = var_GetString( p_aout, "equalizer-bands" );
96 f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
97 vlc_object_release( p_aout );
101 psz_af = config_GetPsz( p_intf, "audio-filter" );
102 if( config_GetInt( p_intf, "equalizer-2pass" ) )
103 ui.eq2PassCheck->setChecked( true );
104 psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
105 f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
107 if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
108 ui.enableCheck->setChecked( true );
109 enable( ui.enableCheck->isChecked() );
111 setValues( psz_bands, f_preamp );
114 Equalizer::~Equalizer()
118 void Equalizer::enable()
120 bool en = ui.enableCheck->isChecked();
121 aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
122 en ? VLC_TRUE : VLC_FALSE );
126 void Equalizer::enable( bool en )
128 ui.eq2PassCheck->setEnabled( en );
129 ui.preampLabel->setEnabled( en );
130 ui.preampSlider->setEnabled( en );
131 for( int i = 0 ; i< BANDS; i++ )
133 bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
137 void Equalizer::set2Pass()
139 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
140 VLC_OBJECT_AOUT, FIND_ANYWHERE);
141 vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
144 config_PutInt( p_intf, "equalizer-2pass", b_2p );
147 var_SetBool( p_aout, "equalizer-2pass", b_2p );
148 config_PutInt( p_intf, "equalizer-2pass", b_2p );
149 for( int i = 0; i < p_aout->i_nb_inputs; i++ )
151 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
153 vlc_object_release( p_aout );
157 void Equalizer::setPreamp()
159 float f= (float)( ui.preampSlider->value() ) /10 - 20;
161 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
162 VLC_OBJECT_AOUT, FIND_ANYWHERE);
164 sprintf( psz_val, "%.1f", f );
165 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
168 delCallbacks( p_aout );
169 var_SetFloat( p_aout, "equalizer-preamp", f );
170 addCallbacks( p_aout );
171 vlc_object_release( p_aout );
173 config_PutFloat( p_intf, "equalizer-preamp", f );
176 void Equalizer::setBand()
178 char psz_values[102]; memset( psz_values, 0, 102 );
180 /**\todo smoothing */
182 for( int i = 0 ; i< BANDS ; i++ )
185 float f_val = (float)( bands[i]->value() ) / 10 - 20 ;
186 sprintf( psz_values, "%s %f", psz_values, f_val );
187 sprintf( psz_val, "% 5.1f", f_val );
188 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
190 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
191 VLC_OBJECT_AOUT, FIND_ANYWHERE);
194 delCallbacks( p_aout );
195 var_SetString( p_aout, "equalizer-bands", psz_values );
196 addCallbacks( p_aout );
197 vlc_object_release( p_aout );
200 void Equalizer::setValues( char *psz_bands, float f_preamp )
205 for( int i = 0; i < 10; i++ )
208 float f = strtof( p, &p );
209 int i_val= (int)( ( f + 20 ) * 10 );
210 bands[i]->setValue( i_val );
211 sprintf( psz_val, "% 5.1f", f );
212 band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
214 if( p == NULL ) break;
220 int i_val = (int)( ( f_preamp + 20 ) * 10 );
221 sprintf( psz_val, "%.1f", f_preamp );
222 ui.preampSlider->setValue( i_val );
223 ui.preampLabel->setText( qtr("Preamp\n") + psz_val + qtr("dB") );
226 void Equalizer::setPreset( int preset )
228 aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
229 VLC_OBJECT_AOUT, FIND_ANYWHERE);
231 char psz_values[102]; memset( psz_values, 0, 102 );
232 for( int i = 0 ; i< 10 ;i++ )
233 sprintf( psz_values, "%s %.1f", psz_values,
234 eqz_preset_10b[preset]->f_amp[i] );
238 delCallbacks( p_aout );
239 var_SetString( p_aout, "equalizer-bands", psz_values );
240 var_SetFloat( p_aout, "equalizer-preamp",
241 eqz_preset_10b[preset]->f_preamp );
242 addCallbacks( p_aout );
243 vlc_object_release( p_aout );
245 config_PutPsz( p_intf, "equalizer-bands", psz_values );
246 config_PutFloat( p_intf, "equalizer-preamp",
247 eqz_preset_10b[preset]->f_preamp );
249 setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
252 void Equalizer::delCallbacks( aout_instance_t *p_aout )
254 // var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
255 // var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
258 void Equalizer::addCallbacks( aout_instance_t *p_aout )
260 // var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
261 // var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
265 /**********************************************************************
266 * Video filters / Adjust
267 **********************************************************************/
269 /**********************************************************************
271 **********************************************************************/
273 /**********************************************************************
274 * Extended playbak controls
275 **********************************************************************/