[vlc-commits] LUA: EQ Preset setter

Akash Mehrotra git at videolan.org
Tue Aug 30 19:41:45 CEST 2011


vlc | branch: master | Akash Mehrotra <mehrotra.akash at gmail.com> | Tue Aug 30 19:39:41 2011 +0200| [d0ea236c473a560dc796be053262bfa15722ccb7] | committer: Jean-Baptiste Kempf

LUA: EQ Preset setter

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

 modules/lua/libs/equalizer.c            |   46 +++++++++++++++++++++++++++++-
 share/lua/http/requests/README.txt      |    3 ++
 share/lua/intf/modules/httprequests.lua |    2 +
 3 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/modules/lua/libs/equalizer.c b/modules/lua/libs/equalizer.c
index 9d7d87f..f365a8e 100644
--- a/modules/lua/libs/equalizer.c
+++ b/modules/lua/libs/equalizer.c
@@ -176,7 +176,7 @@ static int vlclua_equalizer_get( lua_State *L )
         free(str);
         asprintf( &str , "band_%d", i++ );
         lua_setfield( L , -2 , str );
-        free(str);
+        free( str );
     }
     free( psz_bands_origin );
     if (loc != (locale_t)0)
@@ -239,6 +239,47 @@ static int vlclua_equalizer_set( lua_State *L )
     return 1;
 }
 
+/*****************************************************************************
+* Set the preset specified by preset id
+*****************************************************************************/
+static int vlclua_equalizer_setpreset( lua_State *L )
+{
+    int presetid = luaL_checknumber( L, 1 );
+    if( presetid >= NB_PRESETS || presetid < 0 )
+        return 0;
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
+    {
+        audio_output_t *p_aout = input_GetAout( p_input );
+        vlc_object_release( p_input );
+        if ( !p_aout )
+        {
+            return 0;
+        }
+        char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
+        if ( !psz_af || strstr ( psz_af, "equalizer" ) == NULL )
+        {
+            vlc_object_release( p_aout );
+            return 0;
+        }
+        char *newstr;
+        if( asprintf( &newstr , "%6.1f" , eqz_preset_10b[presetid].f_amp[0] ) == -1 )
+            return 0;
+        for ( int i = 1 ; i < 10 ; i++ )
+        {
+            if ( asprintf( &newstr, "%s%6.1f",newstr ,eqz_preset_10b[presetid].f_amp[i]) == -1 )
+                return 0;
+        }
+        var_SetString( p_aout, "equalizer-bands",newstr );
+        var_SetFloat( p_aout, "equalizer-preamp", eqz_preset_10b[presetid].f_preamp );
+        var_SetString( p_aout , "equalizer-preset" , preset_list[presetid] );
+        vlc_object_release( p_aout );
+        free( newstr );
+        return 1;
+    }
+    return 0;
+}
+ 
 /****************************************************************************
 * Enable/disable Equalizer
 *****************************************************************************/
@@ -271,7 +312,8 @@ static const luaL_Reg vlclua_equalizer_reg[] = {
     { "equalizerget", vlclua_equalizer_get },
     { "equalizerset", vlclua_equalizer_set },
     { "enable", vlclua_equalizer_enable },
-    {"presets",vlclua_equalizer_get_presets },
+    { "presets",vlclua_equalizer_get_presets },
+    { "setpreset", vlclua_equalizer_setpreset },
     { NULL, NULL }
 };
 
diff --git a/share/lua/http/requests/README.txt b/share/lua/http/requests/README.txt
index 9b37946..109d44a 100644
--- a/share/lua/http/requests/README.txt
+++ b/share/lua/http/requests/README.txt
@@ -125,6 +125,9 @@ status.xml or status.json
  0 --  disables the equalizer
  1 --  enables the equalizer
 
+>command=setpreset&val=<presetid>
+ set the equalizer preset as per the id specified
+
 <Displays the equalizer band gains.
 Band 0: 60 Hz, 1: 170 Hz, 2: 310 Hz, 3: 600 Hz, 4: 1 kHz,
 5: 3 kHz, 6: 6 kHz, 7: 12 kHz , 8: 14 kHz , 9: 16 kHz
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 3ccc946..fcd7a90 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -172,6 +172,8 @@ processcommands = function ()
 	  vlc.equalizer.equalizerset(band,val)
 	elseif command == "enableeq" then
 	  if val == '0' then vlc.equalizer.enable(false) else vlc.equalizer.enable(true) end
+	elseif command == "setpreset" then 
+	  vlc.equalizer.setpreset(val)
 	end
 
 	local input = nil



More information about the vlc-commits mailing list