[vlc-commits] Qt: get/set the default volume level for each audio output (fix #8503)

Ludovic Fauvet git at videolan.org
Wed Jul 10 16:48:45 CEST 2013


vlc/vlc-2.1 | branch: master | Ludovic Fauvet <etix at videolan.org> | Tue Jul  9 00:17:28 2013 +0200| [457a26b34b227cfb65987405b6c74b48b3774422] | committer: Jean-Baptiste Kempf

Qt: get/set the default volume level for each audio output (fix #8503)

Since 2.1 there is no way to set a global default volume. Instead it is now
required to set it independently for each audio output.

(cherry picked from commit 2a823309242446ed50190b082cf10a2499724a19)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/gui/qt4/components/simple_preferences.cpp |   93 +++++++++++++++++++--
 modules/gui/qt4/ui/sprefs_audio.ui                |   55 +++++-------
 2 files changed, 104 insertions(+), 44 deletions(-)

diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index 5c2dc60..9b08b18 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -45,6 +45,7 @@
 #include <QSettings>
 #include <QtAlgorithms>
 #include <QDir>
+#include <math.h>
 
 #define ICON_HEIGHT 64
 
@@ -326,16 +327,50 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
 #undef audioControl
 #undef audioCommon
 
+            int i_max_volume = config_GetInt( p_intf, "qt-max-volume" );
+
             /* Audio Options */
-            ui.volumeValue->setMaximum( 200 );
-            CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
-                                     defaultVolume );
+            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 ) && ( !strcmp( psz_aout, name ) || !strcmp( psz_aout, "any" ) )
+
+#if defined( _WIN32 )
+            if( get_vol_aout( "directx" ) )
+                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_WS_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 ) );
 
-            CONFIG_BOOL( "volume-save", keepVolumeRadio );
-            ui.defaultVolume_zone->setEnabled( ui.resetVolumeRadio->isChecked() );
-            CONNECT( ui.resetVolumeRadio, toggled( bool ),
+            ui.defaultVolume_zone->setEnabled( ui.resetVolumeCheckbox->isChecked() );
+            CONNECT( ui.resetVolumeCheckbox, toggled( bool ),
                      ui.defaultVolume_zone, setEnabled( bool ) );
 
             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
@@ -371,6 +406,8 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             optionWidgets["volLW"] = ui.volumeValue;
             optionWidgets["headphoneB"] = ui.headphoneEffect;
             optionWidgets["spdifChB"] = ui.spdifBox;
+            optionWidgets["defaultVolume"] = ui.defaultVolume;
+            optionWidgets["resetVolumeCheckbox"] = ui.resetVolumeCheckbox;
             updateAudioOptions( ui.outputModule->currentIndex() );
 
             /* LastFM */
@@ -407,7 +444,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
             free( psz );
 
-            bool b_enabled = ( qs_filter.contains( "normvol" ) );
+            b_enabled = ( qs_filter.contains( "normvol" ) );
             ui.volNormBox->setChecked( b_enabled );
             ui.volNormSpin->setEnabled( b_enabled );
 
@@ -782,7 +819,7 @@ SPrefsPanel::~SPrefsPanel()
 void SPrefsPanel::updateAudioVolume( int volume )
 {
     qobject_cast<QSpinBox *>(optionWidgets["volLW"])
-        ->setValue( volume * 100 / AOUT_VOLUME_DEFAULT );
+        ->setValue( volume );
 }
 
 
@@ -859,6 +896,46 @@ void SPrefsPanel::apply()
             qs_filter.removeAll( "headphone" );
 
         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
+
+        /* Default volume */
+        int i_volume =
+            qobject_cast<QSlider *>(optionWidgets["defaultVolume"])->value();
+        bool b_reset_volume =
+            qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"])->isChecked();
+        module_config_t *p_config = config_FindConfig( VLC_OBJECT(p_intf), "aout" );
+        char *psz_aout = p_config->value.psz;
+
+
+        float f_gain = powf( i_volume / 100.f, 3 );
+
+#define save_vol_aout( name ) \
+            module_exists( name ) && ( !strcmp( psz_aout, name ) || !strcmp( psz_aout, "any" ) )
+
+        //FIXME this is moot
+#if defined( _WIN32 )
+        VLC_UNUSED( f_gain );
+        if( save_vol_aout( "directx" ) )
+            config_PutFloat( p_intf, "directx-volume", i_volume / 100.f );
+        if( save_vol_aout( "waveout" ) )
+            config_PutFloat( p_intf, "waveout-volume", i_volume / 100.f );
+#elif defined( Q_WS_MAC )
+        VLC_UNUSED( f_gain );
+        if( save_vol_aout( "auhal" ) )
+            config_PutFloat( p_intf, "auhal-volume", i_volume / 100.f
+                    * AOUT_VOLUME_DEFAULT );
+#elif defined( __OS2__ )
+        if( save_vol_aout( "kai" ) )
+            config_PutFloat( p_intf, "kai-gain",  f_gain );
+#else
+        if( save_vol_aout( "alsa" ) )
+            config_PutFloat( p_intf, "alsa-gain", f_gain );
+        if( save_vol_aout( "jack" ) )
+            config_PutFloat( p_intf, "jack-gain", f_gain );
+#endif
+#undef save_vol_aout
+
+        config_PutInt( p_intf, "volume-save", !b_reset_volume );
+
         break;
     }
     case SPrefsSubtitles:
diff --git a/modules/gui/qt4/ui/sprefs_audio.ui b/modules/gui/qt4/ui/sprefs_audio.ui
index 1380aec..93b2ac7 100644
--- a/modules/gui/qt4/ui/sprefs_audio.ui
+++ b/modules/gui/qt4/ui/sprefs_audio.ui
@@ -8,7 +8,7 @@
     <x>0</x>
     <y>0</y>
     <width>707</width>
-    <height>536</height>
+    <height>509</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -46,39 +46,7 @@
          <property name="bottomMargin">
           <number>0</number>
          </property>
-         <item row="0" column="0" colspan="2">
-          <widget class="QRadioButton" name="keepVolumeRadio">
-           <property name="minimumSize">
-            <size>
-             <width>250</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Keep audio level between sessions</string>
-           </property>
-           <property name="checked">
-            <bool>true</bool>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="0" colspan="2">
-          <widget class="QRadioButton" name="resetVolumeRadio">
-           <property name="minimumSize">
-            <size>
-             <width>250</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Always reset audio start level to:</string>
-           </property>
-           <property name="checked">
-            <bool>false</bool>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="2">
+         <item row="0" column="2">
           <widget class="QWidget" name="defaultVolume_zone" native="true">
            <layout class="QHBoxLayout" name="horizontalLayout">
             <property name="spacing">
@@ -149,6 +117,22 @@
            </layout>
           </widget>
          </item>
+         <item row="0" column="0" colspan="2">
+          <widget class="QCheckBox" name="resetVolumeCheckbox">
+           <property name="minimumSize">
+            <size>
+             <width>250</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string>Always reset audio start level to:</string>
+           </property>
+           <property name="checked">
+            <bool>false</bool>
+           </property>
+          </widget>
+         </item>
         </layout>
        </widget>
       </item>
@@ -551,8 +535,7 @@
  </widget>
  <tabstops>
   <tabstop>enableAudio</tabstop>
-  <tabstop>keepVolumeRadio</tabstop>
-  <tabstop>resetVolumeRadio</tabstop>
+  <tabstop>resetVolumeCheckbox</tabstop>
   <tabstop>defaultVolume</tabstop>
   <tabstop>volumeValue</tabstop>
   <tabstop>outputModule</tabstop>



More information about the vlc-commits mailing list