volume.c 3.66 KB
Newer Older
1
/*****************************************************************************
2
 * volume.c
3
 *****************************************************************************
4
 * Copyright (C) 2007-2008 the VideoLAN team
5 6 7
 * $Id$
 *
 * Authors: Antoine Cellerier <dionoea at videolan tod org>
8
 *          Pierre d'Herbemont <pdherbemont # videolan.org>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * 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.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#ifndef  _GNU_SOURCE
#   define  _GNU_SOURCE
#endif

32 33 34 35
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

36
#include <vlc_common.h>
37 38 39 40
#include <vlc_plugin.h>
#include <vlc_meta.h>
#include <vlc_charset.h>
#include <vlc_aout.h>
41 42 43 44 45

#include <lua.h>        /* Low level lua C API */
#include <lauxlib.h>    /* Higher level C API */
#include <lualib.h>     /* Lua libs */

46 47
#include "../vlc.h"
#include "../libs.h"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
48
#include "playlist.h"
49 50

/*****************************************************************************
51
 * Volume related
52
 *****************************************************************************/
53
static int vlclua_volume_set( lua_State *L )
54
{
55
    playlist_t *p_this = vlclua_get_playlist_internal( L );
56 57
    int i_volume = luaL_checkint( L, 1 );
    /* Do we need to check that i_volume is in the AOUT_VOLUME_MIN->MAX range?*/
58 59 60
    int i_ret = aout_VolumeSet( p_this, i_volume );
    vlclua_release_playlist_internal( p_this );
    return vlclua_push_ret( L, i_ret );
61
}
62

63 64
static int vlclua_volume_get( lua_State *L )
{
65
    playlist_t *p_this = vlclua_get_playlist_internal( L );
66 67 68 69 70
    audio_volume_t i_volume;
    if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
        lua_pushnumber( L, i_volume );
    else
        lua_pushnil( L );
71
    vlclua_release_playlist_internal( p_this );
72 73 74
    return 1;
}

75
static int vlclua_volume_up( lua_State *L )
76
{
77
    audio_volume_t i_volume;
78 79
    playlist_t *p_this = vlclua_get_playlist_internal( L );
    aout_VolumeUp( p_this, luaL_optint( L, 1, 1 ), &i_volume );
80
    lua_pushnumber( L, i_volume );
81
    vlclua_release_playlist_internal( p_this );
82
    return 1;
83 84
}

85
static int vlclua_volume_down( lua_State *L )
86
{
87
    audio_volume_t i_volume;
88 89
    playlist_t *p_this = vlclua_get_playlist_internal( L );
    aout_VolumeDown( p_this, luaL_optint( L, 1, 1 ), &i_volume );
90
    lua_pushnumber( L, i_volume );
91
    vlclua_release_playlist_internal( p_this );
92
    return 1;
93 94
}

95 96 97 98 99 100 101 102 103 104 105 106
/*****************************************************************************
 *
 *****************************************************************************/
static const luaL_Reg vlclua_volume_reg[] = {
    { "get", vlclua_volume_get },
    { "set", vlclua_volume_set },
    { "up", vlclua_volume_up },
    { "down", vlclua_volume_down },
    { NULL, NULL }
};

void luaopen_volume( lua_State *L )
107
{
108 109 110
    lua_newtable( L );
    luaL_register( L, NULL, vlclua_volume_reg );
    lua_setfield( L, -2, "volume" );
111
}