]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/extrapanel.cpp
modules/gui/wxwindows/extrapanel.cpp: minor string fix
[vlc] / modules / gui / wxwindows / extrapanel.cpp
1 /*****************************************************************************
2  * extrapanel.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004, 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/aout.h>
29 #include <aout_internal.h>
30 #include <vlc/vout.h>
31 #include <vlc/intf.h>
32
33 #include <math.h>
34
35 #include "wxwindows.h"
36
37 /*****************************************************************************
38  * Local class declarations.
39  *****************************************************************************/
40
41 /* FIXME */
42 #define SMOOTH_TIP N_( "If this setting is not zero, the bands will move " \
43                 "together when you move one. The higher the value is, the " \
44                 "more correlated their movement will be." )
45
46 static int IntfBandsCallback( vlc_object_t *, char const *,
47                               vlc_value_t, vlc_value_t, void * );
48 static int IntfPreampCallback( vlc_object_t *, char const *,
49                                vlc_value_t, vlc_value_t, void * );
50 static void ChangeFiltersString( intf_thread_t *, aout_instance_t *,
51                                  char *, vlc_bool_t );
52 static void ChangeVFiltersString( intf_thread_t *, char *, vlc_bool_t );
53
54
55 /* IDs for the controls and the menu commands */
56 enum
57 {
58     Notebook_Event,
59
60     Adjust_Event,
61     RestoreDefaults_Event,
62
63     Hue_Event,
64     Contrast_Event,
65     Brightness_Event,
66     Saturation_Event,
67     Gamma_Event,
68     Ratio_Event,
69
70     FiltersInfo_Event,
71
72     Filter0_Event, Filter1_Event, Filter2_Event, Filter3_Event, Filter4_Event,
73     Filter5_Event, Filter6_Event, Filter7_Event, Filter8_Event, Filter9_Event,
74
75     EqEnable_Event,
76     Eq2Pass_Event,
77     EqRestore_Event,
78
79     Smooth_Event,
80
81     Preamp_Event,
82
83     Band0_Event,Band1_Event,Band2_Event,Band3_Event,Band4_Event,
84     Band5_Event,Band6_Event,Band7_Event,Band8_Event,Band9_Event,
85
86     NormVol_Event, NVSlider_Event, HeadPhone_Event
87 };
88
89 BEGIN_EVENT_TABLE( ExtraPanel, wxPanel )
90     EVT_IDLE( ExtraPanel::OnIdle )
91
92     /* Equalizer */
93     EVT_CHECKBOX( EqEnable_Event, ExtraPanel::OnEnableEqualizer )
94     EVT_CHECKBOX( Eq2Pass_Event, ExtraPanel::OnEq2Pass )
95     EVT_BUTTON( EqRestore_Event, ExtraPanel::OnEqRestore )
96
97     EVT_COMMAND_SCROLL( Preamp_Event, ExtraPanel::OnPreamp )
98     EVT_COMMAND_SCROLL( Smooth_Event, ExtraPanel::OnEqSmooth )
99
100     EVT_COMMAND_SCROLL(Band0_Event, ExtraPanel::OnChangeEqualizer)
101     EVT_COMMAND_SCROLL(Band1_Event, ExtraPanel::OnChangeEqualizer)
102     EVT_COMMAND_SCROLL(Band2_Event, ExtraPanel::OnChangeEqualizer)
103     EVT_COMMAND_SCROLL(Band3_Event, ExtraPanel::OnChangeEqualizer)
104     EVT_COMMAND_SCROLL(Band4_Event, ExtraPanel::OnChangeEqualizer)
105     EVT_COMMAND_SCROLL(Band5_Event, ExtraPanel::OnChangeEqualizer)
106     EVT_COMMAND_SCROLL(Band6_Event, ExtraPanel::OnChangeEqualizer)
107     EVT_COMMAND_SCROLL(Band7_Event, ExtraPanel::OnChangeEqualizer)
108     EVT_COMMAND_SCROLL(Band8_Event, ExtraPanel::OnChangeEqualizer)
109     EVT_COMMAND_SCROLL(Band9_Event, ExtraPanel::OnChangeEqualizer)
110
111     /* Video */
112     EVT_CHECKBOX( Adjust_Event, ExtraPanel::OnEnableAdjust )
113     EVT_BUTTON( RestoreDefaults_Event, ExtraPanel::OnRestoreDefaults )
114
115     EVT_COMMAND_SCROLL(Hue_Event, ExtraPanel::OnAdjustUpdate)
116     EVT_COMMAND_SCROLL(Contrast_Event, ExtraPanel::OnAdjustUpdate)
117     EVT_COMMAND_SCROLL(Brightness_Event, ExtraPanel::OnAdjustUpdate)
118     EVT_COMMAND_SCROLL(Saturation_Event, ExtraPanel::OnAdjustUpdate)
119     EVT_COMMAND_SCROLL(Gamma_Event, ExtraPanel::OnAdjustUpdate)
120
121     EVT_BUTTON( FiltersInfo_Event, ExtraPanel::OnFiltersInfo )
122
123     EVT_CHECKBOX( Filter0_Event, ExtraPanel::OnSelectFilter )
124     EVT_CHECKBOX( Filter1_Event, ExtraPanel::OnSelectFilter )
125     EVT_CHECKBOX( Filter2_Event, ExtraPanel::OnSelectFilter )
126     EVT_CHECKBOX( Filter3_Event, ExtraPanel::OnSelectFilter )
127     EVT_CHECKBOX( Filter4_Event, ExtraPanel::OnSelectFilter )
128     EVT_CHECKBOX( Filter5_Event, ExtraPanel::OnSelectFilter )
129     EVT_CHECKBOX( Filter6_Event, ExtraPanel::OnSelectFilter )
130     EVT_CHECKBOX( Filter7_Event, ExtraPanel::OnSelectFilter )
131     EVT_CHECKBOX( Filter8_Event, ExtraPanel::OnSelectFilter )
132     EVT_CHECKBOX( Filter9_Event, ExtraPanel::OnSelectFilter )
133
134     /* Audio */
135     EVT_CHECKBOX( NormVol_Event, ExtraPanel::OnNormvol )
136     EVT_CHECKBOX( HeadPhone_Event, ExtraPanel::OnHeadphone )
137
138     EVT_COMMAND_SCROLL( NVSlider_Event, ExtraPanel::OnNormvolSlider )
139
140 END_EVENT_TABLE()
141
142 struct filter {
143     char *psz_filter;
144     char *psz_name;
145     char *psz_help;
146 };
147
148 static const struct filter vfilters[] =
149 {
150     { "clone", "Image clone", "Creates several clones of the image" },
151     { "distort", "Distortion", "Adds distorsion effects" },
152     { "invert", "Image inversion" , "Inverts the image colors" },
153     { "crop", "Image cropping", "Crops the image" },
154     { "motionblur", "Blurring", "Creates a motion blurring on the image" },
155     { "transform", "Transformation", "Rotates or flips the image" },
156     { NULL, NULL, NULL } /* Do not remove this line */
157 };
158
159 /*****************************************************************************
160  * Constructor.
161  *****************************************************************************/
162 ExtraPanel::ExtraPanel( intf_thread_t *_p_intf, wxWindow *_p_parent ):
163         wxPanel( _p_parent , -1, wxDefaultPosition, wxDefaultSize )
164 {
165
166     p_intf = _p_intf;
167     p_parent = _p_parent;
168     SetAutoLayout( TRUE );
169
170     wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
171
172     notebook = new wxNotebook( this, Notebook_Event );
173
174     wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
175
176     notebook->AddPage( VideoPanel( notebook ), wxU(_("Video")) );
177     notebook->AddPage( EqzPanel( notebook ), wxU(_("Equalizer")) );
178     notebook->AddPage( AudioPanel( notebook ), wxU(_("Audio")) );
179
180     extra_sizer->Add( notebook_sizer, 1, wxEXPAND, 0 );
181
182     SetSizerAndFit( extra_sizer );
183     extra_sizer->Layout();
184 }
185
186 ExtraPanel::~ExtraPanel()
187 {
188 }
189
190 /* Video Panel constructor */
191 wxPanel *ExtraPanel::VideoPanel( wxWindow *parent )
192 {
193     char *psz_filters;
194
195     wxPanel *panel = new wxPanel( parent, -1 );
196     wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
197
198     /* Create static box to surround the adjust controls */
199     wxStaticBox *adjust_box =
200            new wxStaticBox( panel, -1, wxU(_("Adjust Image")) );
201     wxStaticBoxSizer *adjust_sizer =
202         new wxStaticBoxSizer( adjust_box, wxVERTICAL );
203     adjust_sizer->SetMinSize( -1, 50 );
204
205     /* Create flex grid */
206     wxFlexGridSizer *adjust_gridsizer =
207         new wxFlexGridSizer( 6, 2, 0, 0);
208     adjust_gridsizer->AddGrowableCol(1);
209
210     /* Create the adjust button */
211     wxCheckBox * adjust_check = new wxCheckBox( panel, Adjust_Event,
212                                                  wxU(_("Enable")));
213
214     /* Create the restore to defaults button */
215     restoredefaults_button =
216         new wxButton( panel, RestoreDefaults_Event,
217         wxU(_("Restore Defaults")), wxDefaultPosition);
218
219     wxStaticText *hue_text = new wxStaticText( panel, -1,
220                                        wxU(_("Hue")) );
221     hue_slider = new wxSlider ( panel, Hue_Event, 0, 0,
222                                 360, wxDefaultPosition, wxDefaultSize );
223
224     wxStaticText *contrast_text = new wxStaticText( panel, -1,
225                                        wxU(_("Contrast")) );
226     contrast_slider = new wxSlider ( panel, Contrast_Event, 0, 0,
227                                 200, wxDefaultPosition, wxDefaultSize);
228
229     wxStaticText *brightness_text = new wxStaticText( panel, -1,
230                                        wxU(_("Brightness")) );
231     brightness_slider = new wxSlider ( panel, Brightness_Event, 0, 0,
232                            200, wxDefaultPosition, wxDefaultSize) ;
233
234     wxStaticText *saturation_text = new wxStaticText( panel, -1,
235                                           wxU(_("Saturation")) );
236     saturation_slider = new wxSlider ( panel, Saturation_Event, 0, 0,
237                            300, wxDefaultPosition, wxDefaultSize );
238
239     wxStaticText *gamma_text = new wxStaticText( panel, -1,
240                                           wxU(_("Gamma")) );
241     gamma_slider = new wxSlider ( panel, Gamma_Event, 0, 0,
242                            100, wxDefaultPosition, wxDefaultSize );
243
244     adjust_gridsizer->Add( adjust_check, 1, wxEXPAND|wxALL, 2 );
245     adjust_gridsizer->Add( restoredefaults_button, 1, wxEXPAND|wxALL, 2 );
246     adjust_gridsizer->Add( hue_text, 1, wxEXPAND|wxALL, 2 );
247     adjust_gridsizer->Add( hue_slider, 1, wxEXPAND|wxALL, 2 );
248     adjust_gridsizer->Add( contrast_text, 1, wxEXPAND|wxALL, 2 );
249     adjust_gridsizer->Add( contrast_slider, 1, wxEXPAND|wxALL, 2 );
250     adjust_gridsizer->Add( brightness_text, 1, wxEXPAND|wxALL, 2 );
251     adjust_gridsizer->Add( brightness_slider, 1, wxEXPAND|wxALL, 2 );
252     adjust_gridsizer->Add( saturation_text, 1, wxEXPAND|wxALL, 2 );
253     adjust_gridsizer->Add( saturation_slider, 1, wxEXPAND|wxALL, 2 );
254     adjust_gridsizer->Add( gamma_text, 1, wxEXPAND|wxALL, 2 );
255     adjust_gridsizer->Add( gamma_slider, 1, wxEXPAND|wxALL, 2 );
256
257     adjust_sizer->Add( adjust_gridsizer, 1, wxEXPAND|wxALL, 2);
258
259     panel_sizer->Add( adjust_sizer , 1, wxTOP, 2 );
260
261 #if 0
262     /* Create sizer to surround the other controls */
263     wxBoxSizer *other_sizer = new wxBoxSizer( wxVERTICAL );
264
265     wxStaticBox *video_box =
266             new wxStaticBox( panel, -1, wxU(_("Video Options")) );
267     /* Create the sizer for the frame */
268     wxStaticBoxSizer *video_sizer =
269        new wxStaticBoxSizer( video_box, wxVERTICAL );
270     video_sizer->SetMinSize( -1, 50 );
271
272     static const wxString ratio_array[] =
273     {
274         wxT("4:3"),
275         wxT("16:9"),
276     };
277
278     wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
279     wxStaticText *ratio_text = new wxStaticText( panel, -1,
280                                           wxU(_("Aspect Ratio")) );
281
282     ratio_combo = new wxComboBox( panel, Ratio_Event, wxT(""),
283                                   wxDefaultPosition, wxSize( 80 , -1),
284                                   WXSIZEOF(ratio_array), ratio_array,
285                                   0 );
286
287     ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
288     ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
289     ratio_sizer->Layout();
290
291     video_sizer->Add( ratio_sizer  , 0 , wxALL , 2 );
292     video_sizer->Layout();
293 #endif
294
295     wxStaticBox *filter_box =
296                   new wxStaticBox( panel, -1, wxU(_("Video Filters")) );
297     wxStaticBoxSizer *filter_sizer =
298                    new wxStaticBoxSizer( filter_box, wxHORIZONTAL );
299
300     wxBoxSizer *t_col_sizer = new wxBoxSizer( wxVERTICAL );
301
302
303     for( int i = 0 ; vfilters[i].psz_filter != NULL ; i++ )
304     {
305         wxCheckBox *box = new wxCheckBox( panel, Filter0_Event + i,
306                                           wxU( _( vfilters[i].psz_name ) ) );
307         t_col_sizer->Add( box, 0, wxALL, 4 );
308         box->SetToolTip( wxU( _( vfilters[i].psz_help ) ) );
309     }
310
311     filter_sizer->Add( t_col_sizer );
312     filter_sizer->Add( new wxButton( panel, FiltersInfo_Event,
313                             wxU(_("More info" ) ) ), 0, wxALL, 4 );
314 #if 0
315     other_sizer->Add( video_sizer, 0, wxALL | wxEXPAND , 0);
316     other_sizer->Add( filter_sizer, 0, wxALL | wxEXPAND , 0);
317     other_sizer->Layout();
318     panel_sizer->Add(other_sizer , 1 );
319 #endif
320
321     panel_sizer->Add( filter_sizer, 1, wxTOP|wxLEFT, 2 );
322
323     panel->SetSizerAndFit( panel_sizer );
324
325     /* Layout the whole panel */
326     panel_sizer->Layout();
327
328     panel_sizer->SetSizeHints( panel );
329
330     /* Write down initial values */
331     psz_filters = config_GetPsz( p_intf, "filter" );
332     if( psz_filters && strstr( psz_filters, "adjust" ) )
333     {
334         adjust_check->SetValue( 1 );
335         restoredefaults_button->Enable();
336         saturation_slider->Enable();
337         contrast_slider->Enable();
338         brightness_slider->Enable();
339         hue_slider->Enable();
340         gamma_slider->Enable();
341     }
342     else
343     {
344         adjust_check->SetValue( 0 );
345         restoredefaults_button->Disable();
346         saturation_slider->Disable();
347         contrast_slider->Disable();
348         brightness_slider->Disable();
349         hue_slider->Disable();
350         gamma_slider->Disable();
351     }
352     if( psz_filters ) free( psz_filters );
353
354     int i_value = config_GetInt( p_intf, "hue" );
355     if( i_value > 0 && i_value < 360 )
356         hue_slider->SetValue( i_value );
357     float f_value;
358     f_value = config_GetFloat( p_intf, "saturation" );
359     if( f_value > 0 && f_value < 5 )
360         saturation_slider->SetValue( (int)(100 * f_value) );
361     f_value = config_GetFloat( p_intf, "contrast" );
362     if( f_value > 0 && f_value < 4 )
363         contrast_slider->SetValue( (int)(100 * f_value) );
364     f_value = config_GetFloat( p_intf, "brightness" );
365     if( f_value > 0 && f_value < 2 )
366         brightness_slider->SetValue( (int)(100 * f_value) );
367     f_value = config_GetFloat( p_intf, "gamma" );
368     if( f_value > 0 && f_value < 10 )
369         gamma_slider->SetValue( (int)(10 * f_value) );
370
371     return panel;
372 }
373
374 /* Audio panel constructor */
375 wxPanel *ExtraPanel::AudioPanel( wxWindow *parent )
376 {
377     char *psz_filters;
378
379     wxPanel *panel = new wxPanel( parent, -1 );
380     wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
381
382     /* Create static box to surround the adjust controls */
383     wxStaticBox *filter_box =
384            new wxStaticBox( panel, -1, wxU(_("Audio filters")) );
385     wxStaticBoxSizer *filter_sizer =
386         new wxStaticBoxSizer( filter_box, wxVERTICAL );
387     filter_sizer->SetMinSize( -1, 50 );
388
389     wxCheckBox * headphone_check = new wxCheckBox( panel, HeadPhone_Event,
390                                     wxU(_("Headphone virtualization")));
391     headphone_check->SetToolTip( wxU(_("This filter gives the feeling of a "
392              "5.1 speaker set when using a headphone." ) ) );
393
394     wxCheckBox * normvol_check = new wxCheckBox( panel, NormVol_Event,
395                                     wxU(_("Volume normalization")));
396     normvol_check->SetToolTip( wxU(_("This filter prevents the audio output "
397                          "power from going over a defined value." ) ) );
398
399     wxStaticText *normvol_label = new wxStaticText( panel, -1,
400                                    wxU( _("Maximum level") ) );
401
402     wxSlider *normvol_slider = new wxSlider ( panel, NVSlider_Event, 20, 5,
403                            100, wxDefaultPosition, wxSize( 100, -1 ) );
404
405     filter_sizer->Add( headphone_check, 0, wxALL, 4 );
406     filter_sizer->Add( normvol_check, 0, wxALL, 4 );
407     filter_sizer->Add( normvol_label, 0, wxALL, 4 );
408     filter_sizer->Add( normvol_slider, 0, wxALL, 4 );
409
410     panel_sizer->Add( filter_sizer, 1, wxTOP, 2 );
411     panel->SetSizerAndFit( panel_sizer );
412     panel_sizer->Layout();
413     panel_sizer->SetSizeHints( panel );
414
415     /* Write down initial values */
416     psz_filters = config_GetPsz( p_intf, "audio-filter" );
417     if( psz_filters )
418     {
419         headphone_check->SetValue( strstr( psz_filters, "headphone" ) );
420         normvol_check->SetValue( strstr( psz_filters, "normvol" ) );
421         free( psz_filters );
422     }
423     else
424     {
425         headphone_check->SetValue( 0 );
426         normvol_check->SetValue( 0 );
427     }
428
429     return panel;
430 }
431
432
433 static const wxString band_frequencies[] =
434 {
435     wxT(" 60 Hz"),
436     wxT("170 Hz"),
437     wxT("310 Hz"),
438     wxT("600 Hz"),
439     wxT(" 1 kHz"),
440     wxT(" 3 kHz"),
441     wxT(" 6 kHz"),
442     wxT("12 kHz"),
443     wxT("14 kHz"),
444     wxT("16 kHz")
445 };
446
447 /* Equalizer Panel constructor */
448 wxPanel *ExtraPanel::EqzPanel( wxWindow *parent )
449 {
450     wxPanel *panel = new wxPanel( parent, -1 );
451     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
452
453     /* Create static box to surround the adjust controls */
454     wxBoxSizer *top_sizer =
455         new wxBoxSizer( wxHORIZONTAL );
456
457     /* Create the enable button */
458     eq_chkbox =  new wxCheckBox( panel, EqEnable_Event,
459                             wxU(_("Enable") ) );
460     eq_chkbox->SetToolTip( wxU(_("Enable the equalizer. You can either "
461     "manually change the bands or use a preset (Audio Menu->Equalizer)." ) ) );
462     top_sizer->Add( eq_chkbox, 0, wxALL, 2 );
463
464     eq_2p_chkbox =  new wxCheckBox( panel, Eq2Pass_Event,
465                             wxU(_("2 Pass") ) );
466
467     eq_2p_chkbox->SetToolTip( wxU(_("If you enable this settting, the "
468      "equalizer filter will be applied twice. The effect will be sharper.") ) );
469
470     top_sizer->Add( eq_2p_chkbox, 0, wxALL, 2 );
471
472     top_sizer->Add( 0, 0, 1, wxALL, 2 );
473
474     top_sizer->Add( new wxButton( panel, EqRestore_Event,
475                                   wxU( _("Restore Defaults") ) ),
476                     0, wxALL, 2 );
477     top_sizer->Add( 0, 0, 1, wxALL, 2 );
478
479     wxStaticText *smooth_text = new wxStaticText( panel, -1, wxU( "Smooth :" ));
480     smooth_text->SetToolTip( wxU( SMOOTH_TIP ) );
481     top_sizer->Add( smooth_text, 0, wxALL, 2 );
482
483     smooth_slider =new wxSlider( panel, Smooth_Event, 0, 0, 10 ,
484                     wxDefaultPosition, wxSize( 100, -1 ) );
485     smooth_slider->SetToolTip( wxU( SMOOTH_TIP ) );
486     top_sizer->Add( smooth_slider, 0, wxALL, 2 );
487
488     /* Create flex grid */
489     wxFlexGridSizer *eq_gridsizer =
490         new wxFlexGridSizer( 2, 12, 0, 0);
491     eq_gridsizer->AddGrowableRow( 0 );
492     eq_gridsizer->AddGrowableCol( 1 );
493
494     preamp_slider = new wxSlider( panel, Preamp_Event, 200, 0, 400,
495                     wxDefaultPosition, wxSize( -1 , 90 ) , wxSL_VERTICAL );
496     eq_gridsizer->Add( preamp_slider, 1, wxEXPAND|wxALL, 2 );
497
498     eq_gridsizer->Add( 0, 0, 1, wxALL, 2 );
499
500     for( int i = 0 ; i < 10 ; i++ )
501     {
502         band_sliders[i] = new wxSlider( panel, Band0_Event + i, 200, 0, 400,
503                     wxDefaultPosition, wxSize( -1 , 90 ) , wxSL_VERTICAL );
504
505         i_values[i] = 200;
506         eq_gridsizer->Add( band_sliders[i], 1, wxEXPAND|wxALL, 2 );
507     }
508
509     preamp_text = new wxStaticText( panel, -1, wxT( "Preamp\n0.0dB" ) );
510     wxFont font= preamp_text->GetFont();
511     font.SetPointSize(7);
512     preamp_text->SetFont( font );
513     eq_gridsizer->Add( preamp_text, wxALL, 2 );
514
515     eq_gridsizer->Add( 0, 0, 1 );
516
517     for( int i = 0 ; i < 10 ; i++ )
518     {
519         band_texts[i] = new wxStaticText( panel, -1,
520                                 band_frequencies[i] + wxU("\n0.0dB" ) ) ;
521         eq_gridsizer->Add( band_texts[i], 1, wxEXPAND|wxALL, 2 );
522         wxFont font= band_texts[i]->GetFont();
523         font.SetPointSize(7);
524         band_texts[i]->SetFont( font );
525     }
526
527     panel_sizer->Add( top_sizer , 0 , wxTOP | wxEXPAND, 5 );
528     panel_sizer->Add( eq_gridsizer , 0 , wxEXPAND, 0 );
529
530     panel->SetSizer( panel_sizer );
531
532     panel_sizer->Layout();
533
534     panel_sizer->SetSizeHints( panel );
535
536     CheckAout();
537     return panel;
538 }
539
540 /*******************************************************
541  * Event handlers
542  *******************************************************/
543
544 /* Keep aout up to date and update the bands if needed */
545 void ExtraPanel::OnIdle( wxIdleEvent &event )
546 {
547     CheckAout();
548     if( b_update == VLC_TRUE )
549     {
550         if( b_my_update == VLC_TRUE )
551         {
552             b_update = b_my_update = VLC_FALSE;
553             return;
554         }
555         char *p = psz_bands;
556         for( int i = 0; i < 10; i++ )
557         {
558                 float f;
559                 char psz_val[5];
560                 int i_val;
561                 /* Read dB -20/20*/
562                 f = strtof( p, &p );
563                 i_val= (int)( ( f + 20 ) * 10 );
564                 band_sliders[i]->SetValue( 400 - i_val );
565                 i_values[i] = 400 - i_val;
566                 sprintf( psz_val, "%.1f", f );
567                 band_texts[i]->SetLabel( band_frequencies[i] + wxT("\n") +
568                                                 wxU( psz_val ) + wxT("dB") );
569                 if( p == NULL )
570                 {
571                     break;
572                 }
573                 p++;
574                 if( *p == 0 )
575                     break;
576         }
577         char psz_val[5];
578         int i_val = (int)( ( f_preamp + 20 ) * 10 );
579         sprintf( psz_val, "%.1f", f_preamp );
580         preamp_slider->SetValue( 400 - i_val );
581         const wxString preamp = wxT("Preamp\n");
582         preamp_text->SetLabel( preamp + wxU( psz_val ) + wxT( "dB" ) );
583         eq_chkbox->SetValue( TRUE );
584         b_update = VLC_FALSE;
585     }
586 }
587
588 /*************************
589  *  Equalizer Panel events
590  *************************/
591 void ExtraPanel::OnEnableEqualizer( wxCommandEvent &event )
592 {
593     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
594                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
595     ChangeFiltersString( p_intf,p_aout, "equalizer",
596                          event.IsChecked() ? VLC_TRUE : VLC_FALSE );
597     if( p_aout != NULL )
598         vlc_object_release( p_aout );
599 }
600
601 void ExtraPanel::OnEqRestore( wxCommandEvent &event )
602 {
603     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
604                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
605     if( p_aout == NULL )
606     {
607         vlc_value_t val;
608         vlc_bool_t b_previous = eq_chkbox->IsChecked();
609         val.f_float = 12.0;
610         IntfPreampCallback( NULL, NULL, val,val, this );
611         config_PutFloat( p_intf, "equalizer-preamp", 12.0 );
612         val.psz_string = strdup( "0 0 0 0 0 0 0 0 0 0" );
613         IntfBandsCallback( NULL, NULL, val,val, this );
614         config_PutPsz( p_intf, "equalizer-bands",
615                                 "0 0 0 0 0 0 0 0 0 0");
616         config_PutPsz( p_intf, "equalizer-preset","flat" );
617         eq_chkbox->SetValue( b_previous );
618     }
619     else
620     {
621         var_SetFloat( p_aout, "equalizer-preamp", 0.0 );
622         var_SetString( p_aout, "equalizer-bands",
623                                 "0 0 0 0 0 0 0 0 0 0");
624         var_SetString( p_aout , "equalizer-preset" , "flat" );
625         vlc_object_release( p_aout );
626     }
627 }
628
629 void ExtraPanel::OnEq2Pass( wxCommandEvent &event )
630 {
631     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
632                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
633
634     vlc_bool_t b_2p = event.IsChecked() ? VLC_TRUE : VLC_FALSE;
635
636     if( p_aout == NULL )
637     {
638         config_PutInt( p_intf, "equalizer-2pass", b_2p );
639     }
640     else
641     {
642         var_SetBool( p_aout, "equalizer-2pass", b_2p );
643         if( eq_chkbox->IsChecked() )
644         {
645             for( int i = 0; i < p_aout->i_nb_inputs; i++ )
646             {
647                 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
648             }
649         }
650         vlc_object_release( p_aout );
651     }
652 }
653
654 void ExtraPanel::OnEqSmooth( wxScrollEvent &event )
655 {
656     /* Max smoothing : 70% */
657     i_smooth = event.GetPosition() * 7;
658 }
659
660 void ExtraPanel::OnPreamp( wxScrollEvent &event )
661 {
662     float f= (float)( 400 - event.GetPosition() ) / 10 - 20 ;
663     char psz_val[5];
664
665     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
666                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
667
668     sprintf( psz_val, "%.1f", f );
669     const wxString preamp = wxT("Preamp\n");
670     preamp_text->SetLabel( preamp + wxU( psz_val ) + wxT( "dB" ) );
671
672     if( p_aout == NULL )
673     {
674         config_PutFloat( p_intf, "equalizer-preamp", f );
675     }
676     else
677     {
678         var_SetFloat( p_aout, "equalizer-preamp", f );
679         b_my_update = VLC_TRUE;
680         vlc_object_release( p_aout );
681     }
682 }
683
684 void ExtraPanel::OnChangeEqualizer( wxScrollEvent &event )
685 {
686     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
687                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
688     char psz_values[102];
689     memset( psz_values, 0, 102 );
690
691     /* Smoothing */
692     int i_diff = event.GetPosition() - i_values[  event.GetId() - Band0_Event ];
693     i_values[ event.GetId() - Band0_Event] = event.GetPosition();
694
695     for( int i = event.GetId() + 1 ; i <= Band9_Event ; i++ )
696     {
697         int i_new = band_sliders[ i-Band0_Event ]->GetValue() +
698            (int)( i_diff * pow( (float)i_smooth / 100 , i- event.GetId() ) ) ;
699         if( i_new < 0 ) i_new = 0;
700         if( i_new > 400 ) i_new = 400;
701         band_sliders[ i-Band0_Event ]->SetValue( i_new );
702     }
703     for( int i = Band0_Event ; i < event.GetId() ; i++ )
704     {
705         int i_new =   band_sliders[ i-Band0_Event ]->GetValue() +
706            (int)( i_diff * pow( (float)i_smooth / 100 , event.GetId() - i  ) );
707         if( i_new < 0 ) i_new = 0;
708         if( i_new > 400 ) i_new = 400;
709         band_sliders[ i-Band0_Event ]->SetValue( i_new );
710     }
711
712     /* Write the new bands values */
713     for( int i = 0 ; i < 10 ; i++ )
714     {
715         char psz_val[5];
716         float f_val = (float)( 400 - band_sliders[i]->GetValue() ) / 10- 20 ;
717         sprintf( psz_values, "%s %f", psz_values, f_val );
718         sprintf( psz_val, "%.1f", f_val );
719         band_texts[i]->SetLabel( band_frequencies[i] + wxT("\n") +
720                         wxU( psz_val ) + wxT("dB" ) );
721     }
722     if( p_aout == NULL )
723     {
724         config_PutPsz( p_intf, "equalizer-bands", psz_values );
725     }
726     else
727     {
728         var_SetString( p_aout, "equalizer-bands", psz_values );
729         b_my_update = VLC_TRUE;
730         vlc_object_release( p_aout );
731     }
732 }
733
734 /***********************
735  * Audio Panel events
736  ***********************/
737 void ExtraPanel::OnHeadphone( wxCommandEvent &event )
738 {
739     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
740                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
741     ChangeFiltersString( p_intf , p_aout, "headphone",
742                          event.IsChecked() ? VLC_TRUE : VLC_FALSE );
743     if( p_aout != NULL )
744         vlc_object_release( p_aout );
745 }
746
747 void ExtraPanel::OnNormvol( wxCommandEvent &event )
748 {
749     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
750                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
751     ChangeFiltersString( p_intf , p_aout, "normvol",
752                          event.IsChecked() ? VLC_TRUE : VLC_FALSE );
753     if( p_aout != NULL )
754         vlc_object_release( p_aout );
755 }
756
757 void ExtraPanel::OnNormvolSlider( wxScrollEvent &event )
758 {
759     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
760                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
761     if( p_aout != NULL )
762     {
763         var_SetFloat( p_aout, "norm-max-level", (float)event.GetPosition()/10 );
764         vlc_object_release( p_aout );
765     }
766     else
767     {
768         config_PutFloat( p_intf, "norm-max-level",
769                         (float)event.GetPosition()/10 );
770     }
771 }
772 /***********************
773  *  Video Panel events
774  ***********************/
775 void ExtraPanel::OnEnableAdjust(wxCommandEvent& event)
776 {
777     ChangeVFiltersString( p_intf,  "adjust",
778                           event.IsChecked() ? VLC_TRUE : VLC_FALSE );
779
780     if( event.IsChecked() )
781     {
782         restoredefaults_button->Enable();
783         brightness_slider->Enable();
784         saturation_slider->Enable();
785         contrast_slider->Enable();
786         hue_slider->Enable();
787         gamma_slider->Enable();
788     }
789     else
790     {
791         restoredefaults_button->Disable();
792         brightness_slider->Disable();
793         saturation_slider->Disable();
794         contrast_slider->Disable();
795         hue_slider->Disable();
796         gamma_slider->Disable();
797     }
798 }
799
800 void ExtraPanel::OnRestoreDefaults( wxCommandEvent &event)
801 {
802     hue_slider->SetValue(0);
803     saturation_slider->SetValue(100);
804     brightness_slider->SetValue(100);
805     contrast_slider->SetValue(100),
806     gamma_slider->SetValue(10);
807
808     wxScrollEvent *hscroll_event = new wxScrollEvent(0, Hue_Event, 0);
809     OnAdjustUpdate(*hscroll_event);
810
811     wxScrollEvent *sscroll_event = new wxScrollEvent(0, Saturation_Event, 100);
812     OnAdjustUpdate(*sscroll_event);
813
814     wxScrollEvent *bscroll_event = new wxScrollEvent(0, Brightness_Event, 100);
815     OnAdjustUpdate(*bscroll_event);
816
817     wxScrollEvent *cscroll_event = new wxScrollEvent(0, Contrast_Event, 100);
818     OnAdjustUpdate(*cscroll_event);
819
820     wxScrollEvent *gscroll_event = new wxScrollEvent(0, Gamma_Event, 10);
821     OnAdjustUpdate(*gscroll_event);
822
823 }
824
825 void ExtraPanel::OnAdjustUpdate( wxScrollEvent &event)
826 {
827     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
828                                  VLC_OBJECT_VOUT, FIND_ANYWHERE);
829     if( p_vout == NULL )
830     {
831         switch( event.GetId() )
832         {
833             case Hue_Event:
834                 config_PutInt( p_intf , "hue" , event.GetPosition() );
835                 break;
836
837             case Saturation_Event:
838                 config_PutFloat( p_intf , "saturation" ,
839                                 (float)event.GetPosition()/100 );
840                 break;
841
842             case Brightness_Event:
843                 config_PutFloat( p_intf , "brightness" ,
844                                 (float)event.GetPosition()/100 );
845                 break;
846
847             case Contrast_Event:
848                 config_PutFloat( p_intf , "contrast" ,
849                                 (float)event.GetPosition()/100 );
850                 break;
851
852             case Gamma_Event:
853                 config_PutFloat( p_intf , "gamma" ,
854                                 (float)event.GetPosition()/10 );
855                 break;
856         }
857     }
858     else
859     {
860         vlc_value_t val;
861         switch( event.GetId() )
862         {
863             case Hue_Event:
864                 val.i_int = event.GetPosition();
865                 var_Set( p_vout, "hue", val );
866                 break;
867
868             case Saturation_Event:
869                 val.f_float = (float)event.GetPosition() / 100;
870                 var_Set( p_vout, "saturation", val );
871                 break;
872
873             case Brightness_Event:
874                 val.f_float = (float)event.GetPosition() / 100;
875                 var_Set( p_vout, "brightness", val );
876                 break;
877
878             case Contrast_Event:
879                 val.f_float = (float)event.GetPosition() / 100;
880                 var_Set( p_vout, "contrast", val );
881                 break;
882
883             case Gamma_Event:
884                 val.f_float = (float)event.GetPosition() / 10;
885                 var_Set( p_vout, "gamma", val );
886                 break;
887         }
888         vlc_object_release(p_vout);
889     }
890 }
891
892 /* FIXME */
893 void ExtraPanel::OnRatio( wxCommandEvent& event )
894 {
895    config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
896 }
897
898
899 void ExtraPanel::OnSelectFilter(wxCommandEvent& event)
900 {
901     int i_filter = event.GetId() - Filter0_Event ;
902     if( vfilters[i_filter].psz_filter  )
903     {
904         ChangeVFiltersString( p_intf, vfilters[i_filter].psz_filter ,
905                               event.IsChecked() ? VLC_TRUE : VLC_FALSE );
906     }
907 }
908
909 void ExtraPanel::OnFiltersInfo(wxCommandEvent& event)
910 {
911     wxMessageBox( wxU( _("Select the video effects filters to apply. "
912                   "You must restart the stream for these settings to "
913                   "take effect.\n"
914                   "To configure the filters, go to the Preferences, "
915                   "and go to Modules/Video Filters. "
916                   "You can then configure each filter.\n"
917                   "If you want fine control over the filters ( to choose "
918                   "the order in which they are applied ), you need to enter "
919                   "manually a filters string (Preferences / General / Video)."
920                   ) ),
921                     wxU( _("More information" ) ), wxOK | wxICON_INFORMATION,
922                     this->p_parent );
923 }
924 /**********************************
925  * Other functions
926  **********************************/
927 void ExtraPanel::CheckAout()
928 {
929     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
930                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
931     if( p_aout != NULL )
932     {
933         if( p_aout != p_intf->p_sys->p_aout )
934         {
935             /* We want to know if someone changes the bands */
936             if( var_AddCallback( p_aout, "equalizer-bands",
937                                     IntfBandsCallback, this ) )
938             {
939                 /* The variable does not exist yet, wait */
940                 vlc_object_release( p_aout );
941                 return;
942             }
943             if( var_AddCallback( p_aout, "equalizer-preamp",
944                                     IntfPreampCallback, this )  )
945             {
946                 vlc_object_release( p_aout );
947                 return;
948             }
949             /* Ok, we have our variables, make a first update round */
950             p_intf->p_sys->p_aout = p_aout;
951
952             f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
953             psz_bands = var_GetString( p_aout, "equalizer-bands" );
954             b_update = VLC_TRUE;
955         }
956         vlc_object_release( p_aout );
957     }
958 }
959
960
961 static void ChangeVFiltersString( intf_thread_t *p_intf,
962                                  char *psz_name, vlc_bool_t b_add )
963 {
964     vout_thread_t *p_vout;
965     char *psz_parser, *psz_string;
966
967     psz_string = config_GetPsz( p_intf, "filter" );
968
969     if( !psz_string ) psz_string = strdup("");
970
971     psz_parser = strstr( psz_string, psz_name );
972
973     if( b_add )
974     {
975         if( !psz_parser )
976         {
977             psz_parser = psz_string;
978             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
979                             psz_string, psz_name );
980             free( psz_parser );
981         }
982         else
983         {
984             return;
985         }
986     }
987     else
988     {
989         if( psz_parser )
990         {
991             memmove( psz_parser, psz_parser + strlen(psz_name) +
992                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
993                             strlen(psz_parser + strlen(psz_name)) + 1 );
994
995             /* Remove trailing : : */
996             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
997             {
998                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
999             }
1000          }
1001          else
1002          {
1003              free( psz_string );
1004              return;
1005          }
1006     }
1007     /* Vout is not kept, so put that in the config */
1008     config_PutPsz( p_intf, "filter", psz_string );
1009
1010     /* Try to set on the fly */
1011     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1012                                               FIND_ANYWHERE );
1013     if( p_vout )
1014     {
1015         var_SetString( p_vout, "filter", psz_string );
1016         vlc_object_release( p_vout );
1017     }
1018
1019     free( psz_string );
1020 }
1021
1022
1023 static void ChangeFiltersString( intf_thread_t *p_intf,
1024                                  aout_instance_t * p_aout,
1025                                  char *psz_name, vlc_bool_t b_add )
1026 {
1027     char *psz_parser, *psz_string;
1028
1029     if( p_aout )
1030     {
1031         psz_string = var_GetString( p_aout, "audio-filter" );
1032     }
1033     else
1034     {
1035         psz_string = config_GetPsz( p_intf, "audio-filter" );
1036     }
1037
1038     if( !psz_string ) psz_string = strdup("");
1039
1040     psz_parser = strstr( psz_string, psz_name );
1041
1042     if( b_add )
1043     {
1044         if( !psz_parser )
1045         {
1046             psz_parser = psz_string;
1047             asprintf( &psz_string, (*psz_string) ? "%s,%s" : "%s%s",
1048                             psz_string, psz_name );
1049             free( psz_parser );
1050         }
1051         else
1052         {
1053             return;
1054         }
1055     }
1056     else
1057     {
1058         if( psz_parser )
1059         {
1060             memmove( psz_parser, psz_parser + strlen(psz_name) +
1061                             (*(psz_parser + strlen(psz_name)) == ',' ? 1 : 0 ),
1062                             strlen(psz_parser + strlen(psz_name)) + 1 );
1063
1064             if( *(psz_string+strlen(psz_string ) -1 ) == ',' )
1065             {
1066                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
1067             }
1068          }
1069          else
1070          {
1071              free( psz_string );
1072              return;
1073          }
1074     }
1075
1076     if( p_aout == NULL )
1077     {
1078         config_PutPsz( p_intf, "audio-filter", psz_string );
1079     }
1080     else
1081     {
1082         var_SetString( p_aout, "audio-filter", psz_string );
1083         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
1084         {
1085             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
1086         }
1087     }
1088     free( psz_string );
1089 }
1090
1091
1092 static int IntfBandsCallback( vlc_object_t *p_this, char const *psz_cmd,
1093                           vlc_value_t oldval, vlc_value_t newval, void *param )
1094 {
1095     ExtraPanel *p_panel = (ExtraPanel *)param;
1096
1097     p_panel->psz_bands = strdup( newval.psz_string );
1098     p_panel->b_update = VLC_TRUE;
1099
1100     return VLC_SUCCESS;
1101 }
1102
1103 static int IntfPreampCallback( vlc_object_t *p_this, char const *psz_cmd,
1104                           vlc_value_t oldval, vlc_value_t newval, void *param )
1105 {
1106     ExtraPanel *p_panel = (ExtraPanel *)param;
1107
1108     p_panel->f_preamp = newval.f_float;
1109     p_panel->b_update = VLC_TRUE;
1110
1111     return VLC_SUCCESS;
1112 }
1113
1114 #if 0
1115 /**********************************************************************
1116  * A small window to contain the extrapanel in its undocked state
1117  **********************************************************************/
1118 BEGIN_EVENT_TABLE(ExtraWindow, wxFrame)
1119 END_EVENT_TABLE()
1120
1121
1122 ExtraWindow::ExtraWindow( intf_thread_t *_p_intf, wxWindow *p_parent,
1123                           wxPanel *_extra_panel ):
1124        wxFrame( p_parent, -1, wxU(_("Extended controls")), wxDefaultPosition,
1125                  wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1126 {
1127         fprintf(stderr,"Creating extrawindow\n");
1128     p_intf = _p_intf;
1129     SetIcon( *p_intf->p_sys->p_icon );
1130
1131     wxBoxSizer *window_sizer = new wxBoxSizer( wxVERTICAL );
1132     SetSizer( window_sizer );
1133 //    panel = new ExtraPanel(  p_intf, this );//_extra_panel;
1134
1135     panel = _extra_panel;
1136     window_sizer->Add( panel );
1137
1138     window_sizer->Layout();
1139     window_sizer->Fit( this );
1140
1141     Show();
1142 }
1143
1144 ExtraWindow::~ExtraWindow()
1145 {
1146     delete panel;
1147 }
1148 #endif