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

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


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

Qt4: complete default volume lookup function

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

 modules/gui/qt4/components/simple_preferences.cpp |   94 ++++++++++++++-------
 1 file changed, 65 insertions(+), 29 deletions(-)

diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index aaa8c48..f3afbb5 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,38 +524,22 @@ 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
+            int i_volume = getDefaultAudioVolume(VLC_OBJECT(p_intf), psz_aout);
+            if( i_volume >= 0 )
+            {
+                bool b_enabled = config_GetInt( p_intf, "volume-save" );
 
-            ui.defaultVolume->setValue( i_volume );
+                ui.resetVolumeCheckbox->setChecked( !b_enabled );
+                ui.defaultVolume->setValue( i_volume );
+            }
+            else
+            {
+                ui.resetVolumeCheckbox->setChecked( false );
+                ui.defaultVolume->setValue( 100 );
+            }
 
             CONNECT( ui.defaultVolume, valueChanged( int ),
                      this, updateAudioVolume( int ) );
@@ -583,7 +619,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 );
 



More information about the vlc-commits mailing list