28 #define DBG_AUDIO LOG_STREAM(debug, log_audio)
29 #define LOG_AUDIO LOG_STREAM(info, log_audio)
30 #define ERR_AUDIO LOG_STREAM(err, log_audio)
32 static const char*
Track =
"music track";
33 static const char*
Source =
"sound source";
36 std::shared_ptr<sound::music_track>
track;
52 std::shared_ptr<const sound::music_track>
operator->()
const {
59 luaL_setmetatable(L,
Track);
65 luaL_setmetatable(L,
Track);
94 luaL_setmetatable(L,
Source);
108 u->lua_music_track::~lua_music_track();
113 if(lua_isnumber(L, 2)) {
117 const char* m = luaL_checkstring(L, 2);
119 if(strcmp(m,
"current") == 0) {
124 if(strcmp(m,
"previous") == 0) {
129 if(strcmp(m,
"current_i") == 0) {
132 lua_pushinteger(L, *current_index + 1);
138 if(strcmp(m,
"all") == 0) {
142 std::vector<config> tracks(range.begin(), range.end());
153 if(lua_isnumber(L, 2)) {
154 unsigned int i = lua_tointeger(L, 2) - 1;
156 if(lua_isnil(L, 3)) {
162 cfg[
"append"] =
true;
164 if(cfg[
"play_once"].to_bool()) {
165 return luaL_argerror(L, 3,
"For play_once, use wesnoth.music_list.play instead");
180 track->write(cfg,
true);
186 const char* m = luaL_checkstring(L, 2);
212 if(lua_isinteger(L, 1)) {
213 index = lua_tointeger(L, 1);
217 "name", luaL_checkstring(L, 1),
220 bool found_ms_before =
false, found_ms_after =
false, found_imm =
false;
221 for(
int i = 2;
i <= lua_gettop(L);
i++) {
222 if(lua_isboolean(L,
i)) {
224 return luaL_argerror(L,
i,
"only one boolean argument may be passed");
228 }
else if(lua_isnumber(L,
i)) {
230 return luaL_argerror(L,
i,
"only two integer arguments may be passed");
231 }
else if(found_ms_before) {
232 cfg[
"ms_after"] = lua_tointeger(L,
i);
233 found_ms_after =
true;
235 cfg[
"ms_before"] = lua_tointeger(L,
i);
236 found_ms_before =
true;
239 return luaL_argerror(L,
i,
"unrecognized argument");
253 std::set<int, std::greater<int>> to_remove;
254 for(
int i = 1;
i <= lua_gettop(L);
i++) {
255 to_remove.insert(luaL_checkinteger(L,
i));
257 for(
int i : to_remove) {
270 if(track ==
nullptr) {
271 return luaL_error(L,
"Error: Attempted to access an invalid music track.\n");
273 const char* m = luaL_checkstring(L, 2);
275 if(!track->
valid()) {
276 return luaL_error(L,
"Tried to access member of track that is no longer valid.");
288 cfg[
"append"]=(*track)->append();
289 cfg[
"shuffle"]=(*track)->shuffle();
290 cfg[
"immediate"]=(*track)->immediate();
291 cfg[
"once"]=(*track)->play_once();
292 cfg[
"ms_before"]=(*track)->ms_before();
293 cfg[
"ms_after"]=(*track)->ms_after();
294 cfg[
"name"]=(*track)->id();
295 cfg[
"title"]=(*track)->title());
302 if(track ==
nullptr || !track->
valid()) {
303 return luaL_error(L,
"Error: Attempted to access an invalid music track.\n");
305 const char* m = luaL_checkstring(L, 2);
308 modify_int_attrib(
"ms_before", (*track)->set_ms_before(std::chrono::milliseconds{value}));
309 modify_int_attrib(
"ms_after", (*track)->set_ms_after(std::chrono::milliseconds{value}));
320 lua_pushboolean(L,
false);
323 if(!a->
valid() && !
b->valid()) {
324 lua_pushboolean(L,
true);
327 if(a->
valid() &&
b->valid()) {
330 lua_pushboolean(L, lhs->id() == rhs->id() && lhs->shuffle() == rhs->shuffle() && lhs->play_once() == rhs->play_once() && lhs->ms_before() == rhs->ms_before() && lhs->ms_after() == rhs->ms_after());
333 lua_pushboolean(L,
false);
345 std::string
id = luaL_checkstring(L, 2);
362 std::string
id = luaL_checkstring(L, 2);
364 if(lua_isnil(L, 3)) {
381 u.lua_sound_source::~lua_sound_source();
387 const char* m = luaL_checkstring(L, 2);
399 if(strcmp(m,
"locations") == 0) {
400 const auto& locs =
src->get_locations();
401 lua_createtable(L, locs.size(), 0);
402 for(
const auto& loc : locs) {
404 lua_rawseti(L, -1, lua_rawlen(L, -2) + 1);
413 const char* m = luaL_checkstring(L, 2);
422 if(strcmp(m,
"sounds") == 0) {
424 if(lua_istable(L, 3)) {
427 files = luaL_checkstring(L, 3);
429 src->set_files(files);
432 if(strcmp(m,
"locations") == 0) {
433 std::vector<map_location> locs;
439 for(lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
443 src->set_locations(locs);
455 if(a->
id() !=
b->id()) {
456 lua_pushboolean(L,
false);
460 a->
files() ==
b->files() &&
463 a->
loops() ==
b->loops() &&
468 std::set<map_location>(a->
get_locations().begin(), a->
get_locations().end()) == std::set<map_location>(
b->get_locations().begin(),
b->get_locations().end())
479 std::string m = luaL_checkstring(L, 2);
480 if(m !=
"volume")
return 0;
492 std::string m = luaL_checkstring(L, 2);
498 float rel = lua_tonumber(L, 3);
499 if(rel < 0.0f || rel > 100.0f) {
500 return luaL_argerror(L, 1,
"volume must be in range 0..100");
502 vol =
static_cast<int>(rel*vol / 100.0f);
511 lua_createtable(L, 0, 2);
512 static luaL_Reg vol_callbacks[] {
515 {
nullptr,
nullptr },
517 luaL_setfuncs(L, vol_callbacks, 0);
518 lua_setmetatable(L, -2);
521 lua_newuserdatauv(L, 0, 0);
522 lua_createtable(L, 0, 10);
523 static luaL_Reg pl_callbacks[] {
533 {
nullptr,
nullptr },
535 luaL_setfuncs(L, pl_callbacks, 0);
536 lua_pushstring(L,
"music playlist");
537 lua_setfield(L, -2,
"__metatable");
538 lua_setmetatable(L, -2);
539 lua_setfield(L, -2,
"music_list");
542 lua_newuserdatauv(L, 0, 0);
543 lua_createtable(L, 0, 3);
544 static luaL_Reg slm_callbacks[] {
547 {
nullptr,
nullptr },
549 luaL_setfuncs(L, slm_callbacks, 0);
550 lua_pushstring(L,
"sound source map");
551 lua_setfield(L, -2,
"__metatable");
552 lua_setmetatable(L, -2);
553 lua_setfield(L, -2,
"sources");
557 luaL_newmetatable(L,
Track);
558 static luaL_Reg track_callbacks[] {
563 {
nullptr,
nullptr },
565 luaL_setfuncs(L, track_callbacks, 0);
566 lua_pushstring(L,
Track);
567 lua_setfield(L, -2,
"__metatable");
571 luaL_newmetatable(L,
Source);
572 static luaL_Reg source_callbacks[] {
577 {
nullptr,
nullptr },
579 luaL_setfuncs(L, source_callbacks, 0);
580 lua_pushstring(L,
Source);
581 lua_setfield(L, -2,
"__metatable");
583 return "Adding music playlist table...\n";
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
lua_music_track(std::shared_ptr< sound::music_track > new_track)
const sound::music_track & operator*() const
std::shared_ptr< sound::music_track > operator->()
std::shared_ptr< const sound::music_track > operator->() const
sound::music_track & operator*()
std::shared_ptr< sound::music_track > track
soundsource::sourcespec & operator*()
lua_sound_source(lua_sound_source &)=delete
soundsource::sourcespec spec
lua_sound_source(const soundsource::sourcespec &spec)
const soundsource::sourcespec & operator*() const
const soundsource::sourcespec * operator->() const
soundsource::sourcespec * operator->()
Internal representation of music tracks.
void add(const sourcespec &source)
void remove(const std::string &id)
bool check_fogged() const
const std::vector< map_location > & get_locations() const
const std::string & files() const
bool check_shrouded() const
auto minimum_delay() const
const std::string & id() const
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
std::decay_t< T > lua_check(lua_State *L, int n)
static int intf_music_add(lua_State *L)
static lua_sound_source & push_source(lua_State *L, const soundsource::sourcespec &spec)
static int impl_audio_set(lua_State *L)
Sets the current sound volume.
static int impl_source_collect(lua_State *L)
static const char * Track
static int impl_music_len(lua_State *L)
static int impl_track_set(lua_State *L)
static int intf_music_commit(lua_State *)
static lua_music_track * get_track(lua_State *L, int i)
static int impl_music_get(lua_State *L)
static int intf_music_remove(lua_State *L)
static lua_music_track * push_track(lua_State *L, int i)
static int impl_audio_get(lua_State *L)
Gets the current sound volume.
static lg::log_domain log_audio("audio")
static int impl_track_get(lua_State *L)
static lua_sound_source & get_source(lua_State *L, int i)
static int impl_source_eq(lua_State *L)
static int impl_source_set(lua_State *L)
static int intf_music_next(lua_State *)
static int intf_music_play(lua_State *L)
static int impl_track_eq(lua_State *L)
static int impl_source_get(lua_State *L)
static int impl_sndsrc_set(lua_State *L)
Adds or removes a sound source by its ID Key: sound source ID Value: Table containing keyword argumen...
static const char * Source
static int impl_sndsrc_get(lua_State *L)
Get an existing sound source Key: The sound source ID.
static int impl_track_collect(lua_State *L)
Destroys a lua_music_track object before it is collected (__gc metamethod).
static int impl_music_set(lua_State *L)
static int intf_music_clear(lua_State *)
void luaW_pushlocation(lua_State *L, const map_location &ml)
Converts a map location object to a Lua table pushed at the top of the stack.
bool luaW_toboolean(lua_State *L, int n)
bool luaW_getmetafield(lua_State *L, int idx, const char *key)
Like luaL_getmetafield, but returns false if key is an empty string or begins with two underscores.
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
bool luaW_getglobal(lua_State *L, const std::vector< std::string > &path)
Pushes the value found by following the variadic names (char *), if the value is not nil.
#define return_float_attrib(name, accessor)
#define return_vector_string_attrib(name, accessor)
#define return_string_attrib(name, accessor)
#define return_int_attrib(name, accessor)
#define modify_bool_attrib(name, accessor)
#define return_bool_attrib(name, accessor)
#define modify_int_attrib(name, accessor)
#define return_cfg_attrib(name, accessor)
#define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max)
#define modify_string_attrib(name, accessor)
#define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max)
static int music_volume()
std::string register_table(lua_State *L)
soundsource::manager * soundsources
Audio output for sound and music.
void write_music_play_list(config &snapshot)
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
void remove_track(unsigned int i)
unsigned int get_num_tracks()
void play_music_once(const std::string &file)
utils::optional< unsigned int > get_current_track_index()
void set_track(unsigned int i, const std::shared_ptr< music_track > &to)
void commit_music_changes()
void play_track(unsigned int i)
std::shared_ptr< music_track > get_previous_music_track()
void set_music_volume(int vol)
std::shared_ptr< music_track > get_current_track()
void set_sound_volume(int vol)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
void lua_push(lua_State *L, const T &val)
rect src
Non-transparent portion of the surface to compose.
static map_location::direction n