Commit 80d51438 authored by Akash Mehrotra's avatar Akash Mehrotra Committed by Jean-Baptiste Kempf

LUA: Enable/Disable EQ, fix EQ input validation, and presets getter

move equalizer.xml to httprequests.lua
Use a table to return equalizer band values
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 8568f791
......@@ -34,6 +34,7 @@
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_aout_intf.h>
#include <vlc_input.h>
#include <vlc_charset.h>
......@@ -42,6 +43,9 @@
#include "input.h"
#include "../libs.h"
#include "../vlc.h"
#include "playlist.h"
#include "../../audio_filter/equalizer_presets.h"
#if !defined WIN32
# include <locale.h>
......@@ -128,14 +132,14 @@ Band 8: 14 kHz
Band 9: 16 kHz
*****************************************************************************/
/*****************************************************************************
* Get the equalizer level for the specified band
* Return EQ level for all bands as a Table
*****************************************************************************/
static int vlclua_equalizer_get( lua_State *L )
{
int bands = 9;
input_thread_t *p_input = vlclua_get_input_internal( L );
if( !p_input )
return 0;
audio_output_t *p_aout = input_GetAout( p_input );
vlc_object_release( p_input );
if( !p_aout )
......@@ -151,15 +155,28 @@ static int vlclua_equalizer_get( lua_State *L )
}
free( psz_af );
int bandid = luaL_checknumber( L, 1 );
char *psz_bands_origin, *psz_bands;
psz_bands_origin = psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
if( !psz_bands )
{
vlc_object_release( p_aout );
return 0;
}
locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
locale_t oldloc = uselocale (loc);
while( bandid >= 0 )
int i = 0;
char *str;
lua_newtable( L );
while( bands >= 0 )
{
level = strtof( psz_bands, &psz_bands);
bandid--;
bands--;
asprintf( &str , "%f" , level );
lua_pushstring( L, str );
free(str);
asprintf( &str , "band_%d", i++ );
lua_setfield( L , -2 , str );
free(str);
}
free( psz_bands_origin );
if (loc != (locale_t)0)
......@@ -167,15 +184,8 @@ static int vlclua_equalizer_get( lua_State *L )
uselocale (oldloc);
freelocale (loc);
}
vlc_object_release( p_aout );
if( bandid == -1 )
{
lua_pushnumber( L, level );
return 1;
}
else
return 0;
}
......@@ -184,6 +194,9 @@ static int vlclua_equalizer_get( lua_State *L )
*****************************************************************************/
static int vlclua_equalizer_set( lua_State *L )
{
int bandid = luaL_checknumber( L, 1 );
if ( bandid < 0 || bandid > 9)
return 0;
input_thread_t *p_input = vlclua_get_input_internal( L );
if( !p_input )
return 0;
......@@ -203,7 +216,6 @@ static int vlclua_equalizer_set( lua_State *L )
}
free( psz_af );
int bandid = luaL_checknumber( L, 1 );
float level = luaL_checknumber( L, 2 );
char *bands = var_GetString( p_aout, "equalizer-bands" );
char newstr[7];
......@@ -227,12 +239,39 @@ static int vlclua_equalizer_set( lua_State *L )
return 1;
}
/****************************************************************************
* Enable/disable Equalizer
*****************************************************************************/
static int vlclua_equalizer_enable ( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
bool state = luaL_checkboolean ( L , 1 );
aout_EnableFilter( p_playlist, "equalizer", state );
return 0;
}
/*****************************************************************************
* Get preset names
*****************************************************************************/
static int vlclua_equalizer_get_presets( lua_State *L )
{
lua_newtable( L );
char *str;
for( int i = 0 ; i < NB_PRESETS ; i++ )
{
lua_pushstring( L, preset_list_text[i] );
asprintf( &str , "id_%d",i );
lua_setfield( L , -2 , str );
free(str);
}
return 1;
}
static const luaL_Reg vlclua_equalizer_reg[] = {
{ "preampget", vlclua_preamp_get },
{ "preampset", vlclua_preamp_set },
{ "equalizerget", vlclua_equalizer_get },
{ "equalizerset", vlclua_equalizer_set },
{ "enable", vlclua_equalizer_enable },
{"presets",vlclua_equalizer_get_presets },
{ NULL, NULL }
};
......
......@@ -333,7 +333,6 @@ DIST_http_lua = \
lua/http/requests/playlist.xml \
lua/http/requests/README.txt \
lua/http/requests/playlist_jstree.xml \
lua/http/requests/equalizer.xml \
lua/http/requests/browse.xml \
lua/http/requests/vlm_cmd.xml \
lua/http/requests/status.xml \
......
......@@ -112,6 +112,23 @@ status.xml or status.json
+1H:2M -> seek 1 hour and 2 minutes forward
-10% -> seek 10% back
>command=preamp&val=<val in dB>
sets the preamp value, must be >=-20 and <=20
>command=equalizer&band=<band>&val=<gain in dB, must be >=-20 and <=20)
set the gain for a specific band
>command=enableeq&val=<0 or 1>
0 -- disables the equalizer
1 -- enables the equalizer
<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
<Display the list of presets available for the equalizer
=======
playlist.xml:
=============
< get the full playlist tree
......@@ -131,13 +148,3 @@ vlm_cmd.xml:
?command=<cmd>
> get the error message from <cmd>
equalizer.xml:
=============
>command=preamp&val=<val in dB>
sets the preamp value, must be >=-20 and <=20
>command=equalizer&band=<band>&val=<gain in dB, must be >=-20 and <=20)
<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
<?xml version="1.0" encoding="utf-8" standalone="yes" ?<?vlcprint'>'?>
<?vlc --[[
vim:syntax=lua
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
< equalizer.xml: VLC media player web interface
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
< Copyright (C) 2011 the VideoLAN team
< $Id$
<
< Authors: Akash Mehrotra < mehrotra <dot> akash <at> gmail <dot> com >
<
< This program is free software; you can redistribute it and/or modify
< it under the terms of the GNU General Public License as published by
< the Free Software Foundation; either version 2 of the License, or
< (at your option) any later version.
<
< This program is distributed in the hope that it will be useful,
< but WITHOUT ANY WARRANTY; without even the implied warranty of
< MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
< GNU General Public License for more details.
<
< You should have received a copy of the GNU General Public License
< along with this program; if not, write to the Free Software
< Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
]]?>
<?vlc
local command = _GET['command']
local val = _GET['val']
local band = _GET['band']
function round(what, precision)
if what then return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision) else return "" end
end
if command == "preamp" then vlc.equalizer.preampset(val)
elseif command == "equalizer" then vlc.equalizer.equalizerset(band,val)
end
freq = { 60 , 170 , 310 , 600 , 1000 , 3000 , 6000 , 12000 , 14000 , 16000 }
?>
<root>
<preamp><?vlc print(round(vlc.equalizer.preampget(),2)) ?></preamp>
<equalizer>
<?vlc for i = 0,9
do print("<band id='"..i.."' freqency = '"..freq[i+1].."'>"..round(vlc.equalizer.equalizerget(i),1).."</band>") end ?>
</equalizer>
</root>
......@@ -59,6 +59,9 @@ function strsplit(text, delimiter)
return list
end
function round(what, precision)
if what then return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision) else return "" end
end
--main function to process commands sent with the request
......@@ -69,6 +72,7 @@ processcommands = function ()
local id = tonumber(_GET['id'] or -1)
local val = _GET['val']
local options = _GET['option']
local band = _GET['band']
if type(options) ~= "table" then -- Deal with the 0 or 1 option case
options = { options }
end
......@@ -158,6 +162,12 @@ processcommands = function ()
if vlc.object.vout() then
vlc.var.set(vlc.object.vout(),"aspect-ratio",val)
end
elseif command == "preamp" then
vlc.equalizer.preampset(val)
elseif command == "equalizer" then
vlc.equalizer.equalizerset(band,val)
elseif command == "enableeq" then
if val == '0' then vlc.equalizer.enable(false) else vlc.equalizer.enable(true) end
end
local input = nil
......@@ -391,6 +401,13 @@ local aout = vlc.object.aout()
s.random=vlc.var.get(playlist,"random")
s.loop=vlc.var.get(playlist,"loop")
s["repeat"]=vlc.var.get(playlist,"repeat")
s.equalizer={}
s.equalizer.preamp=round(vlc.equalizer.preampget(),2)
s.equalizer.bands=vlc.equalizer.equalizerget()
if s.equalizer.bands ~= null then
for k,i in pairs(s.equalizer.bands) do s.equalizer.bands[k]=round(i,2) end
s.equalizer.presets=vlc.equalizer.presets()
end
if (includecategories and item) then
s.information={}
......@@ -421,3 +438,4 @@ local aout = vlc.object.aout()
return s
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment