]> git.sesse.net Git - vlc/blobdiff - 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
index 23876c472609ace11464fcbc51d2f487e6576989..fa5071b07308f786d1b87cd31d78f3afa3e88f52 100644 (file)
@@ -41,6 +41,7 @@
 #include <vlc_osd.h>
 
 #include <iostream>
+#include <string.h>
 
 #if 0
 class ConfClickHandler : public QObject
@@ -206,31 +207,26 @@ void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
 {
     vout_thread_t *p_vout;
     char *psz_parser, *psz_string;
-
-    char *psz_filter_type;
-    msg_Err( p_intf, "FIXME %s %s %d.", __FILE__, __func__, __LINE__ );
-    return;
-#if 0
+    const char *psz_filter_type;
 
     /* Please leave p_libvlc_global. This is where cached modules are
      * stored. We're not trying to find a module instance. */
-    vlc_object_t *p_obj = (vlc_object_t *)
-        vlc_object_find_name( vlc_global_object(), psz_name, FIND_CHILD );
+    module_t *p_obj = module_FindName( p_intf, psz_name );
     if( !p_obj )
     {
         msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
         return;
     }
 
-    if( module_IsCapable( (module_t*)p_obj, "video filter2" ) )
+    if( module_IsCapable( p_obj, "video filter2" ) )
     {
         psz_filter_type = "video-filter";
     }
-    else if( module_IsCapable( (module_t*)p_obj, "video filter" ) )
+    else if( module_IsCapable( p_obj, "video filter" ) )
     {
         psz_filter_type = "vout-filter";
     }
-    else if( module_IsCapable( (module_t*)p_obj, "sub filter" ) )
+    else if( module_IsCapable( p_obj, "sub filter" ) )
     {
         psz_filter_type = "sub-filter";
     }
@@ -311,7 +307,6 @@ void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
     }
 
     free( psz_string );
-#endif
 }
 
 void ExtVideo::updateFilters()
@@ -369,9 +364,11 @@ void ExtVideo::setWidgetValue( QObject *widget )
 
     if( !p_obj )
     {
+#if 0
         msg_Dbg( p_intf,
                  "Module instance %s not found, looking in config values.",
                  module.toStdString().c_str() );
+#endif
         i_type = config_GetType( p_intf, option.toStdString().c_str() ) & 0xf0;
         switch( i_type )
         {
@@ -563,8 +560,8 @@ void ExtVideo::gotoConf( QObject* src )
 
 static const QString band_frequencies[] =
 {
-    "   60Hz  ", " 170 Hz " , " 310 Hz ", " 600 Hz ", "  1 kHz  ",
-    "  3 kHz  " , "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
+    "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
+    "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
 };
 
 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
@@ -574,6 +571,7 @@ Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
     smallFont.setPointSize( smallFont.pointSize() - 3 );
 
     ui.setupUi( this );
+    presetsComboBox = ui.presetsCombo;
 
     ui.preampLabel->setFont( smallFont );
     ui.preampSlider->setMaximum( 400 );
@@ -642,7 +640,11 @@ void Equalizer::enable()
     bool en = ui.enableCheck->isChecked();
     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
                        en ? VLC_TRUE : VLC_FALSE );
-    enable( en );
+//    aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
+//                       en ? VLC_TRUE : VLC_FALSE );
+//     aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
+//                       en ? VLC_TRUE : VLC_FALSE );
+     enable( en );
 }
 
 void Equalizer::enable( bool en )
@@ -771,18 +773,176 @@ void Equalizer::setPreset( int preset )
     setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
 }
 
+static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
+                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    char *psz_preset = newval.psz_string;
+    Equalizer *eq = (Equalizer *)p_data;
+    eq->presetsComboBox->setCurrentIndex( eq->presetsComboBox->findText( qfu( psz_preset) ) );
+    return VLC_SUCCESS;
+}
+
 void Equalizer::delCallbacks( aout_instance_t *p_aout )
 {
-//    var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
-//    var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
+    //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
+    //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
+    var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
 }
 
 void Equalizer::addCallbacks( aout_instance_t *p_aout )
 {
-//    var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
-//    var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
+    //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
+    //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
+    var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
 }
 
+/**********************************************************************
+ * Spatializer
+ **********************************************************************/
+static const char *psz_control_names[] =
+{
+    "Roomsize", "Width" , "Wet", "Dry", "Damp"
+};
+static const QString control_names[] =
+{
+    "Roomsize", "Width" , "Wet", "Dry", "Damp"
+};
+
+Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
+    QWidget( _parent ) , p_intf( _p_intf )
+{
+    QFont smallFont = QApplication::font( static_cast<QWidget*>(0) );
+    smallFont.setPointSize( smallFont.pointSize() - 3 );
+
+    ui.setupUi( this );
+
+    QGridLayout *grid = new QGridLayout( ui.frame );
+    grid->setMargin( 0 );
+
+    for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
+    {
+        spatCtrl[i] = new QSlider( Qt::Vertical );
+        if( i < 2)
+        {
+            spatCtrl[i]->setMaximum( 10 );
+            spatCtrl[i]->setValue( 2 );
+        }
+        else
+        {
+            spatCtrl[i]->setMaximum( 10 );
+            spatCtrl[i]->setValue( 0 );
+            spatCtrl[i]->setMinimum( -10 );
+        }
+        oldControlVars[i] = spatCtrl[i]->value();
+        CONNECT( spatCtrl[i], valueChanged(int), this, setInitValues() );
+        ctrl_texts[i] = new QLabel( control_names[i] + "\n" );
+        ctrl_texts[i]->setFont( smallFont );
+        ctrl_readout[i] = new QLabel( "" );
+        ctrl_readout[i]->setFont( smallFont );
+        grid->addWidget( spatCtrl[i], 0, i );
+        grid->addWidget( ctrl_readout[i],1,i);
+        grid->addWidget( ctrl_texts[i], 2, i );
+    }
+
+    BUTTONACT( ui.enableCheck, enable() );
+
+    /* Write down initial values */
+    aout_instance_t *p_aout = (aout_instance_t *)
+        vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
+    char *psz_af = NULL;
+
+    if( p_aout )
+    {
+        psz_af = var_GetString( p_aout, "audio-filter" );
+        for( int i = 0; i < NUM_SP_CTRL ; i++)
+        {
+            controlVars[i] = var_GetFloat( p_aout,  psz_control_names[i] );
+        }
+        vlc_object_release( p_aout );
+    }
+    else
+    {
+        psz_af = config_GetPsz( p_aout, "audio-filter" );
+        for( int i = 0; i < NUM_SP_CTRL ; i++)
+        {
+            controlVars[i] = config_GetFloat( p_intf,  psz_control_names[i] );
+        }
+    }
+    if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
+        ui.enableCheck->setChecked( true );
+    enable( ui.enableCheck->isChecked() );
+    setValues( controlVars );
+
+}
+
+Spatializer::~Spatializer()
+{
+}
+
+void Spatializer::enable()
+{
+    bool en = ui.enableCheck->isChecked();
+    aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
+            en ? VLC_TRUE : VLC_FALSE );
+    enable( en );
+}
+
+void Spatializer::enable( bool en )
+{
+    for( int i = 0 ; i< NUM_SP_CTRL; i++ )
+    {
+        spatCtrl[i]->setEnabled( en );
+        ctrl_texts[i]->setEnabled( en );
+        ctrl_readout[i]->setEnabled( en );
+    }
+}
+void Spatializer::setInitValues()
+{
+    setValues(controlVars);
+}
+
+void Spatializer::setValues(float *controlVars)
+{
+    char psz_val[5];
+    char var_name[5];
+    aout_instance_t *p_aout= (aout_instance_t *)
+        vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
+
+    for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
+    {
+        float f= (float)(  spatCtrl[i]->value() );
+        sprintf( psz_val, "%.1f", f );
+        ctrl_readout[i]->setText( psz_val );
+    }
+    if( p_aout )
+    {
+        for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
+        {
+            if( oldControlVars[i] != spatCtrl[i]->value() )
+            {
+                var_SetFloat( p_aout, psz_control_names[i],
+                        (float)spatCtrl[i]->value() );
+                config_PutFloat( p_intf, psz_control_names[i],
+                        (float) spatCtrl[i]->value());
+                oldControlVars[i] = (float) spatCtrl[i]->value();
+            }
+        }
+        vlc_object_release( p_aout );
+    }
+    //    printf("set callback values %s %s %d\n", __FILE__,__func__,__LINE__);
+
+}
+void Spatializer::delCallbacks( aout_instance_t *p_aout )
+{
+    //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
+    //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
+}
+
+void Spatializer::addCallbacks( aout_instance_t *p_aout )
+{
+    //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
+    //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
+}
 
 /**********************************************************************
  * Video filters / Adjust