12#include "physfsrwops.h"
27#define MUSIC_SUFFIX ".ogg"
30static double music_vol = 0.;
31static double music_vol_lin = 0.;
44static int music_lua_update = LUA_NOREF;
45static int music_lua_choose = LUA_NOREF;
46static int music_lua_play = LUA_NOREF;
47static int music_lua_stop = LUA_NOREF;
48static int music_lua_pause = LUA_NOREF;
49static int music_lua_resume = LUA_NOREF;
50static int music_lua_info = LUA_NOREF;
51static int music_lua_volume = LUA_NOREF;
73 NTracingZone( _ctx, 1 );
76 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_update );
77 lua_pushnumber(
naevL, dt );
79 WARN( _(
"Error while running music function '%s': %s" ),
"update",
80 lua_tostring(
naevL, -1 ) );
84 NTracingZoneEnd( _ctx );
99 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_choose );
100 if ( situation != NULL )
101 lua_pushstring(
naevL, situation );
103 lua_pushnil(
naevL );
105 WARN( _(
"Error while running music function '%s': %s" ),
"choose",
106 lua_tostring(
naevL, -1 ) );
132 if ( ( conf.music > 1. ) || ( conf.music < 0. ) )
133 WARN( _(
"Music has invalid value, clamping to [0:1]." ) );
166 files = PHYSFS_enumerateFiles( MUSIC_PATH );
171 for (
size_t i = 0; files[i] != NULL; i++ ) {
172 int flen = strlen( files[i] );
173 if ( ( flen > suflen ) &&
174 strncmp( &files[i][flen - suflen],
MUSIC_SUFFIX, suflen ) == 0 ) {
181 DEBUG( n_(
"Loaded %d Song",
"Loaded %d Songs", nmusic ), nmusic );
184 PHYSFS_freeList( files );
202 music_vol = 1. / pow( 2., ( 1. - vol ) * 8. );
207 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_volume );
208 lua_pushnumber(
naevL, music_vol );
210 WARN( _(
"Error while running music function '%s': %s" ),
"volume",
211 lua_tostring(
naevL, -1 ) );
225 return music_vol_lin;
247 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_play );
248 if ( filename != NULL )
249 lua_pushstring(
naevL, filename );
251 lua_pushnil(
naevL );
253 WARN( _(
"Error while running music function '%s': %s" ),
"play",
254 lua_tostring(
naevL, -1 ) );
273 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_stop );
274 lua_pushboolean(
naevL, disable );
276 WARN( _(
"Error while running music function '%s': %s" ),
"stop",
277 lua_tostring(
naevL, -1 ) );
293 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_pause );
294 lua_pushboolean(
naevL, disable );
296 WARN( _(
"Error while running music function '%s': %s" ),
"pause",
297 lua_tostring(
naevL, -1 ) );
313 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_resume );
315 WARN( _(
"Error while running music function '%s': %s" ),
"resume",
316 lua_tostring(
naevL, -1 ) );
335 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, music_lua_info );
337 WARN( _(
"Error while running music function '%s': %s" ),
"info",
338 lua_tostring(
naevL, -1 ) );
343 minfo.playing = lua_toboolean(
naevL, -3 );
344 minfo.name = strdup( luaL_optstring(
naevL, -2,
"" ) );
345 minfo.pos = luaL_optnumber(
naevL, -1, -1 );
372 music_env = nlua_newEnv( MUSIC_LUA_PATH );
378 if ( nlua_dobufenv(
music_env, buf, bufsize, MUSIC_LUA_PATH ) != 0 ) {
379 WARN( _(
"Error loading music file: %s\n"
381 "Most likely Lua file has improper syntax, please check" ),
382 MUSIC_LUA_PATH, lua_tostring(
naevL, -1 ) );
410 music_lua_choose = LUA_NOREF;
411 music_lua_update = LUA_NOREF;
412 music_lua_play = LUA_NOREF;
413 music_lua_stop = LUA_NOREF;
414 music_lua_pause = LUA_NOREF;
415 music_lua_resume = LUA_NOREF;
416 music_lua_info = LUA_NOREF;
417 music_lua_volume = LUA_NOREF;
MusicInfo_t * music_info(void)
Gets information about the current music state.
static int music_runchoose
static int music_find(void)
Internal music loading routines.
int music_play(const char *filename)
Plays the loaded music.
int music_pause(int disable)
Pauses the music.
double music_getVolumeLog(void)
Gets the current music volume (logarithmic).
double music_getVolume(void)
Gets the current music volume (linear).
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
int music_volume(double vol)
Sets the music volume from a linear value.
int music_stop(int disable)
Stops the loaded music.
static void music_luaQuit(void)
Quits the music Lua control system.
void music_rechoose(void)
Attempts to rechoose the music.
static int music_luaInit(void)
Initialize the music Lua control system.
void music_exit(void)
Exits the music subsystem.
static nlua_env music_env
void music_update(double dt)
Updates the music.
int music_init(void)
Initializes the music subsystem.
static int music_runLua(const char *situation)
Runs the Lua music choose function.
int music_resume(void)
Resumes the music.
Header file with generic functions and naev-specifics.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
int nlua_refenvtype(nlua_env env, const char *name, int type)
Gets the reference of a global in a lua environment if it matches a type.
int nlua_loadTk(nlua_env env)
Loads the Toolkit Lua library.