Decklink: Fix swapped format arguments
[vlc.git] / modules / lua / libs / volume.c
bloba060b883e74fd929b58c1b8acf1549f55934586a
1 /*****************************************************************************
2 * volume.c
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea at videolan tod org>
8 * Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * Preamble
27 *****************************************************************************/
28 #ifndef _GNU_SOURCE
29 # define _GNU_SOURCE
30 #endif
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
36 #include <math.h>
37 #include <vlc_common.h>
38 #include <vlc_plugin.h>
39 #include <vlc_meta.h>
40 #include <vlc_playlist.h>
41 #include <vlc_aout.h>
43 #include "../vlc.h"
44 #include "../libs.h"
46 /*****************************************************************************
47 * Volume related
48 *****************************************************************************/
49 static int vlclua_volume_set( lua_State *L )
51 playlist_t *p_this = vlclua_get_playlist_internal( L );
52 int i_volume = luaL_checkint( L, 1 );
53 if( i_volume < 0 )
54 i_volume = 0;
55 int i_ret = playlist_VolumeSet( p_this, i_volume/(float)AOUT_VOLUME_DEFAULT );
56 return vlclua_push_ret( L, i_ret );
59 static int vlclua_volume_get( lua_State *L )
61 playlist_t *p_this = vlclua_get_playlist_internal( L );
62 long i_volume = lroundf(playlist_VolumeGet( p_this ) * AOUT_VOLUME_DEFAULT);
63 lua_pushnumber( L, i_volume );
64 return 1;
67 static int vlclua_volume_up( lua_State *L )
69 playlist_t *p_this = vlclua_get_playlist_internal( L );
70 float volume;
72 playlist_VolumeUp( p_this, (int)luaL_optinteger( L, 1, 1 ), &volume );
73 lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
74 return 1;
77 static int vlclua_volume_down( lua_State *L )
79 playlist_t *p_this = vlclua_get_playlist_internal( L );
80 float volume;
82 playlist_VolumeDown( p_this, (int)luaL_optinteger( L, 1, 1 ), &volume );
83 lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
84 return 1;
87 /*****************************************************************************
89 *****************************************************************************/
90 static const luaL_Reg vlclua_volume_reg[] = {
91 { "get", vlclua_volume_get },
92 { "set", vlclua_volume_set },
93 { "up", vlclua_volume_up },
94 { "down", vlclua_volume_down },
95 { NULL, NULL }
98 void luaopen_volume( lua_State *L )
100 lua_newtable( L );
101 luaL_register( L, NULL, vlclua_volume_reg );
102 lua_setfield( L, -2, "volume" );