[vlc-commits] Qt4: complete default volume lookup function

Rémi Denis-Courmont git at videolan.org
Sat Feb 22 12:27:25 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb 22 13:02:54 2014 +0200| [783d2842d9f12a9537eb723f416074fc260dbabc] | committer: Rémi Denis-Courmont

Qt4: complete default volume lookup function

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=783d2842d9f12a9537eb723f416074fc260dbabc
---

 modules/gui/qt4/components/simple_preferences.cpp |  103 ++++++++++++++-------
 1 file changed, 69 insertions(+), 34 deletions(-)

diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index aaa8c48..ee0f1c3 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -184,6 +184,58 @@ static const char *const ppsz_language_text[] =
     "Walon",
 };
 
+static int getDefaultAudioVolume(vlc_object_t *obj, const char *aout)
+{
+    if (!strcmp(aout, "") || !strcmp(aout, "any"))
+        return -1;
+    else
+    /* Note: For hysterical raisins, this is sorted by decreasing priority
+     * order (then alphabetical order). */
+    if (!strcmp(aout, "pulse"))
+        return -1;
+    else
+#ifdef __linux__
+    if (!strcmp(aout, "alsa") && module_exists("alsa"))
+        return cbrtf(config_GetFloat(obj, "alsa-gain")) * 100.f + .5f;
+    else
+#endif
+#ifdef _WIN32
+    if (!strcmp(aout, "mmdevice"))
+        return -1;
+    else
+#endif
+    if (!strcmp(aout, "sndio"))
+        return -1;
+    else
+#ifdef __APPLE__
+    if (!strcmp("auhal") && module_exists("auhal"))
+        return (config_GetFloat(obj, "auhal-volume") * 100.f + .5f)
+                 / AOUT_VOLUME_DEFAULT;
+    else
+#endif
+#ifdef _WIN32
+    if (!strcmp(aout, "directsound") && module_exists("directsound"))
+        return config_GetFloat(obj, "directx-volume") * 100.f + .5f;
+    else
+#endif
+    if (!strcmp(aout, "jack"))
+        return cbrtf(config_GetFloat(obj, "jack-gain")) * 100.f + 0.5f;
+    else
+#ifdef __OS2__
+    if (!strcmp(aout, "kai"))
+        return cbrtf(config_GetFloat(obj, "kai-gain")) * 100.f + .5f;
+    else
+#endif
+    if (!strcmp(aout, "oss"))
+        return -1;
+    else
+#ifdef _WIN32
+    if (!strcmp(aout, "waveout"))
+        return config_GetFloat(obj, "waveout-volume") * 100.f + .5f;
+    else
+#endif
+        return -1;
+}
 
 /*********************************************************************
  * The List of categories
@@ -472,39 +524,6 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             ui.volumeValue->setMaximum( i_max_volume );
             ui.defaultVolume->setMaximum( i_max_volume );
 
-            bool b_enabled = config_GetInt( p_intf, "volume-save" );
-            ui.resetVolumeCheckbox->setChecked( !b_enabled );
-
-            p_config = config_FindConfig( VLC_OBJECT(p_intf), "aout" );
-            char *psz_aout = p_config->value.psz;
-
-            int i_volume = 100; //FIXME not foolproof
-
-#define get_vol_aout( name ) \
-            module_exists( name ) && ( !psz_aout || !strcmp( psz_aout, name ) || !strcmp( psz_aout, "any" ) )
-
-#if defined( _WIN32 )
-            if( get_vol_aout( "directsound" ) )
-                i_volume = config_GetFloat( p_intf, "directx-volume") * 100 + 0.5;
-            else if( get_vol_aout( "waveout" ) )
-                i_volume = config_GetFloat( p_intf, "waveout-volume") * 100 + 0.5;
-#elif defined( Q_OS_MAC )
-            if( get_vol_aout( "auhal" ) )
-                i_volume = ( config_GetFloat( p_intf, "auhal-volume") * 100 + 0.5 )
-                    / AOUT_VOLUME_DEFAULT;
-#elif defined( __OS2__ )
-            if( get_vol_aout( "kai" ) )
-                i_volume = cbrtf( config_GetFloat( p_intf, "kai-gain" ) ) * 100 + 0.5;
-#else
-            if( get_vol_aout( "alsa" ) )
-                i_volume = cbrtf( config_GetFloat( p_intf, "alsa-gain" ) ) * 100 + 0.5;
-            else if( get_vol_aout( "jack" ) )
-                i_volume = cbrtf( config_GetFloat( p_intf, "jack-gain" ) ) * 100 + 0.5;
-#endif
-#undef get_vol_aout
-
-            ui.defaultVolume->setValue( i_volume );
-
             CONNECT( ui.defaultVolume, valueChanged( int ),
                      this, updateAudioVolume( int ) );
 
@@ -583,7 +602,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
             free( psz );
 
-            b_enabled = ( qs_filter.contains( "normvol" ) );
+            bool b_enabled = ( qs_filter.contains( "normvol" ) );
             ui.volNormBox->setChecked( b_enabled );
             ui.volNormSpin->setEnabled( b_enabled );
 
@@ -972,6 +991,22 @@ void SPrefsPanel::updateAudioOptions( int number)
     optionWidgets["fileW"]->setVisible( ( value == "afile" ) );
     optionWidgets["spdifChB"]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
                                            value == "directsound" || value == "waveout" ) );
+
+    int volume = getDefaultAudioVolume(VLC_OBJECT(p_intf), qtu(value));
+    bool save = true;
+
+    if (volume >= 0)
+        save = config_GetInt(VLC_OBJECT(p_intf), "volume-save");
+
+    QCheckBox *resetVolumeCheckBox =
+        qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"]);
+    resetVolumeCheckBox->setChecked(!save);
+    resetVolumeCheckBox->setEnabled(volume >= 0);
+
+    QSlider *defaultVolume =
+        qobject_cast<QSlider *>(optionWidgets["defaultVolume"]);
+    defaultVolume->setValue((volume >= 0) ? volume : 100);
+    defaultVolume->setEnabled(volume >= 0);
 }
 
 



More information about the vlc-commits mailing list