mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
CLuaInstance: Add multiple script functions for mute icon & volume
- Functions: enableMuteIcon, isMuted, AudioMute, setVolume, getVolume - This allows to save volume/mute status at plugin start and restore it on exit. - Set Lua api version to 1.35
This commit is contained in:
@@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <system/debug.h>
|
#include <system/debug.h>
|
||||||
|
#include <gui/widget/menue.h>
|
||||||
|
#include <driver/volume.h>
|
||||||
|
#include <gui/audiomute.h>
|
||||||
#include <gui/infoclock.h>
|
#include <gui/infoclock.h>
|
||||||
#include <cs_api.h>
|
#include <cs_api.h>
|
||||||
#include <neutrino.h>
|
#include <neutrino.h>
|
||||||
@@ -33,6 +36,8 @@
|
|||||||
#include "luainstance.h"
|
#include "luainstance.h"
|
||||||
#include "lua_misc.h"
|
#include "lua_misc.h"
|
||||||
|
|
||||||
|
extern CVolume* g_volume;
|
||||||
|
|
||||||
CLuaInstMisc* CLuaInstMisc::getInstance()
|
CLuaInstMisc* CLuaInstMisc::getInstance()
|
||||||
{
|
{
|
||||||
static CLuaInstMisc* LuaInstMisc = NULL;
|
static CLuaInstMisc* LuaInstMisc = NULL;
|
||||||
@@ -54,6 +59,11 @@ void CLuaInstMisc::LuaMiscRegister(lua_State *L)
|
|||||||
{ "strFind", CLuaInstMisc::strFind },
|
{ "strFind", CLuaInstMisc::strFind },
|
||||||
{ "strSub", CLuaInstMisc::strSub },
|
{ "strSub", CLuaInstMisc::strSub },
|
||||||
{ "enableInfoClock", CLuaInstMisc::enableInfoClock },
|
{ "enableInfoClock", CLuaInstMisc::enableInfoClock },
|
||||||
|
{ "enableMuteIcon", CLuaInstMisc::enableMuteIcon },
|
||||||
|
{ "setVolume", CLuaInstMisc::setVolume },
|
||||||
|
{ "getVolume", CLuaInstMisc::getVolume },
|
||||||
|
{ "AudioMute", CLuaInstMisc::AudioMute },
|
||||||
|
{ "isMuted", CLuaInstMisc::isMuted },
|
||||||
{ "runScript", CLuaInstMisc::runScriptExt },
|
{ "runScript", CLuaInstMisc::runScriptExt },
|
||||||
{ "GetRevision", CLuaInstMisc::GetRevision },
|
{ "GetRevision", CLuaInstMisc::GetRevision },
|
||||||
{ "checkVersion", CLuaInstMisc::checkVersion },
|
{ "checkVersion", CLuaInstMisc::checkVersion },
|
||||||
@@ -144,6 +154,56 @@ int CLuaInstMisc::enableInfoClock(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CLuaInstMisc::enableMuteIcon(lua_State *L)
|
||||||
|
{
|
||||||
|
bool enable = true;
|
||||||
|
int numargs = lua_gettop(L);
|
||||||
|
if (numargs > 1)
|
||||||
|
enable = _luaL_checkbool(L, 2);
|
||||||
|
CAudioMute::getInstance()->enableMuteIcon(enable);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CLuaInstMisc::setVolume(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_Integer vol = luaL_checkint(L, 2);
|
||||||
|
if (vol < 0) vol = 0;
|
||||||
|
if (vol > 100) vol = 100;
|
||||||
|
g_settings.current_volume = vol;
|
||||||
|
g_volume->setvol(vol);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CLuaInstMisc::getVolume(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, g_settings.current_volume);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CLuaInstMisc::AudioMute(lua_State *L)
|
||||||
|
{
|
||||||
|
int numargs = lua_gettop(L);
|
||||||
|
if (numargs < 2) {
|
||||||
|
printf("CLuaInstMisc::%s: not enough arguments (%d, expected 1 (or 2))\n", __func__, numargs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool newValue = false;
|
||||||
|
bool isEvent = false;
|
||||||
|
newValue = _luaL_checkbool(L, 2);
|
||||||
|
if (numargs > 2)
|
||||||
|
isEvent = _luaL_checkbool(L, 3);
|
||||||
|
|
||||||
|
CAudioMute::getInstance()->AudioMute(newValue, isEvent);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CLuaInstMisc::isMuted(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_pushboolean(L, CNeutrinoApp::getInstance()->isMuted());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int CLuaInstMisc::runScriptExt(lua_State *L)
|
int CLuaInstMisc::runScriptExt(lua_State *L)
|
||||||
{
|
{
|
||||||
int numargs = lua_gettop(L);
|
int numargs = lua_gettop(L);
|
||||||
|
@@ -54,6 +54,11 @@ class CLuaInstMisc
|
|||||||
static int strFind(lua_State *L);
|
static int strFind(lua_State *L);
|
||||||
static int strSub(lua_State *L);
|
static int strSub(lua_State *L);
|
||||||
static int enableInfoClock(lua_State *L);
|
static int enableInfoClock(lua_State *L);
|
||||||
|
static int enableMuteIcon(lua_State *L);
|
||||||
|
static int setVolume(lua_State *L);
|
||||||
|
static int getVolume(lua_State *L);
|
||||||
|
static int AudioMute(lua_State *L);
|
||||||
|
static int isMuted(lua_State *L);
|
||||||
static int runScriptExt(lua_State *L);
|
static int runScriptExt(lua_State *L);
|
||||||
static int GetRevision(lua_State *L);
|
static int GetRevision(lua_State *L);
|
||||||
static int checkVersion(lua_State *L);
|
static int checkVersion(lua_State *L);
|
||||||
|
@@ -31,7 +31,7 @@ extern "C" {
|
|||||||
#include "luainstance_helpers.h"
|
#include "luainstance_helpers.h"
|
||||||
|
|
||||||
#define LUA_API_VERSION_MAJOR 1
|
#define LUA_API_VERSION_MAJOR 1
|
||||||
#define LUA_API_VERSION_MINOR 34
|
#define LUA_API_VERSION_MINOR 35
|
||||||
|
|
||||||
void LuaInstRegisterFunctions(lua_State *L, bool fromThreads=false);
|
void LuaInstRegisterFunctions(lua_State *L, bool fromThreads=false);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user