]> git.sesse.net Git - vlc/blob - modules/misc/lua/libs/volume.c
lua: remove "bla ? true : false"
[vlc] / modules / misc / lua / libs / volume.c
1 /*****************************************************************************
2  * volume.c
3  *****************************************************************************
4  * Copyright (C) 2007-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *          Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifndef  _GNU_SOURCE
29 #   define  _GNU_SOURCE
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_meta.h>
39 #include <vlc_aout.h>
40
41 #include <lua.h>        /* Low level lua C API */
42 #include <lauxlib.h>    /* Higher level C API */
43 #include <lualib.h>     /* Lua libs */
44
45 #include "../vlc.h"
46 #include "../libs.h"
47 #include "playlist.h"
48
49 /*****************************************************************************
50  * Volume related
51  *****************************************************************************/
52 static int vlclua_volume_set( lua_State *L )
53 {
54     playlist_t *p_this = vlclua_get_playlist_internal( L );
55     int i_volume = __MAX(__MIN(luaL_checkint( L, 1 ), AOUT_VOLUME_MAX),
56                          AOUT_VOLUME_MIN);
57     int i_ret = aout_VolumeSet( p_this, i_volume );
58     return vlclua_push_ret( L, i_ret );
59 }
60
61 static int vlclua_volume_get( lua_State *L )
62 {
63     playlist_t *p_this = vlclua_get_playlist_internal( L );
64     audio_volume_t i_volume;
65     if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
66         lua_pushnumber( L, i_volume );
67     else
68         lua_pushnil( L );
69     return 1;
70 }
71
72 static int vlclua_volume_up( lua_State *L )
73 {
74     audio_volume_t i_volume;
75     playlist_t *p_this = vlclua_get_playlist_internal( L );
76     aout_VolumeUp( p_this, luaL_optint( L, 1, 1 ), &i_volume );
77     lua_pushnumber( L, i_volume );
78     return 1;
79 }
80
81 static int vlclua_volume_down( lua_State *L )
82 {
83     audio_volume_t i_volume;
84     playlist_t *p_this = vlclua_get_playlist_internal( L );
85     aout_VolumeDown( p_this, luaL_optint( L, 1, 1 ), &i_volume );
86     lua_pushnumber( L, i_volume );
87     return 1;
88 }
89
90 /*****************************************************************************
91  *
92  *****************************************************************************/
93 static const luaL_Reg vlclua_volume_reg[] = {
94     { "get", vlclua_volume_get },
95     { "set", vlclua_volume_set },
96     { "up", vlclua_volume_up },
97     { "down", vlclua_volume_down },
98     { NULL, NULL }
99 };
100
101 void luaopen_volume( lua_State *L )
102 {
103     lua_newtable( L );
104     luaL_register( L, NULL, vlclua_volume_reg );
105     lua_setfield( L, -2, "volume" );
106 }