29 #define DBG_AUDIO LOG_STREAM(debug, log_audio)
30 #define LOG_AUDIO LOG_STREAM(info, log_audio)
31 #define ERR_AUDIO LOG_STREAM(err, log_audio)
33 static const char*
Track =
"music track";
34 static const char*
Source =
"sound source";
37 std::shared_ptr<sound::music_track>
track;
53 std::shared_ptr<const sound::music_track>
operator->()
const {
60 luaL_setmetatable(L,
Track);
66 luaL_setmetatable(L,
Track);
95 luaL_setmetatable(L,
Source);
109 u->lua_music_track::~lua_music_track();
114 if(lua_isnumber(L, 2)) {
118 const char* m = luaL_checkstring(L, 2);
120 if(strcmp(m,
"current") == 0) {
125 if(strcmp(m,
"previous") == 0) {
130 if(strcmp(m,
"current_i") == 0) {
133 lua_pushinteger(L, *current_index + 1);
139 if(strcmp(m,
"all") == 0) {
143 std::vector<config> tracks(range.begin(), range.end());
154 if(lua_isnumber(L, 2)) {
155 unsigned int i = lua_tointeger(L, 2) - 1;
157 if(lua_isnil(L, 3)) {
163 cfg[
"append"] =
true;
165 if(cfg[
"play_once"].to_bool()) {
166 return luaL_argerror(L, 3,
"For play_once, use wesnoth.music_list.play instead");
181 track->write(cfg,
true);
187 const char* m = luaL_checkstring(L, 2);
213 if(lua_isinteger(L, 1)) {
214 index = lua_tointeger(L, 1);
218 "name", luaL_checkstring(L, 1),
221 bool found_ms_before =
false, found_ms_after =
false, found_imm =
false;
222 for(
int i = 2;
i <= lua_gettop(L);
i++) {
223 if(lua_isboolean(L,
i)) {
225 return luaL_argerror(L,
i,
"only one boolean argument may be passed");
229 }
else if(lua_isnumber(L,
i)) {
231 return luaL_argerror(L,
i,
"only two integer arguments may be passed");
232 }
else if(found_ms_before) {
233 cfg[
"ms_after"] = lua_tointeger(L,
i);
234 found_ms_after =
true;
236 cfg[
"ms_before"] = lua_tointeger(L,
i);
237 found_ms_before =
true;
240 return luaL_argerror(L,
i,
"unrecognized argument");
254 std::set<int, std::greater<int>> to_remove;
255 for(
int i = 1;
i <= lua_gettop(L);
i++) {
256 to_remove.insert(luaL_checkinteger(L,
i));
258 for(
int i : to_remove) {
271 if(track ==
nullptr) {
272 return luaL_error(L,
"Error: Attempted to access an invalid music track.\n");
274 const char* m = luaL_checkstring(L, 2);
276 if(!track->
valid()) {
277 return luaL_error(L,
"Tried to access member of track that is no longer valid.");
289 cfg[
"append"]=(*track)->append();
290 cfg[
"shuffle"]=(*track)->shuffle();
291 cfg[
"immediate"]=(*track)->immediate();
292 cfg[
"once"]=(*track)->play_once();
293 cfg[
"ms_before"]=(*track)->ms_before();
294 cfg[
"ms_after"]=(*track)->ms_after();
295 cfg[
"name"]=(*track)->id();
296 cfg[
"title"]=(*track)->title());
303 if(track ==
nullptr || !track->
valid()) {
304 return luaL_error(L,
"Error: Attempted to access an invalid music track.\n");
306 const char* m = luaL_checkstring(L, 2);
309 modify_int_attrib(
"ms_before", (*track)->set_ms_before(std::chrono::milliseconds{value}));
310 modify_int_attrib(
"ms_after", (*track)->set_ms_after(std::chrono::milliseconds{value}));
321 lua_pushboolean(L,
false);
324 if(!a->
valid() && !
b->valid()) {
325 lua_pushboolean(L,
true);
328 if(a->
valid() &&
b->valid()) {
331 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());
334 lua_pushboolean(L,
false);
346 std::string
id = luaL_checkstring(L, 2);
363 std::string
id = luaL_checkstring(L, 2);
365 if(lua_isnil(L, 3)) {
382 u.lua_sound_source::~lua_sound_source();
388 const char* m = luaL_checkstring(L, 2);
400 if(strcmp(m,
"locations") == 0) {
401 const auto& locs =
src->get_locations();
402 lua_createtable(L, locs.size(), 0);
403 for(
const auto&
loc : locs) {
405 lua_rawseti(L, -1, lua_rawlen(L, -2) + 1);
414 const char* m = luaL_checkstring(L, 2);
423 if(strcmp(m,
"sounds") == 0) {
425 if(lua_istable(L, 3)) {
428 files = luaL_checkstring(L, 3);
430 src->set_files(files);
433 if(strcmp(m,
"locations") == 0) {
434 std::vector<map_location> locs;
440 for(lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
444 src->set_locations(locs);
456 if(a->
id() !=
b->id()) {
457 lua_pushboolean(L,
false);
461 a->
files() ==
b->files() &&
464 a->
loops() ==
b->loops() &&
469 std::set<map_location>(a->
get_locations().begin(), a->
get_locations().end()) == std::set<map_location>(
b->get_locations().begin(),
b->get_locations().end())
480 std::string m = luaL_checkstring(L, 2);
481 if(m !=
"volume")
return 0;
493 std::string m = luaL_checkstring(L, 2);
499 float rel = lua_tonumber(L, 3);
500 if(rel < 0.0f || rel > 100.0f) {
501 return luaL_argerror(L, 1,
"volume must be in range 0..100");
503 vol =
static_cast<int>(rel*vol / 100.0f);
512 lua_createtable(L, 0, 2);
513 static luaL_Reg vol_callbacks[] {
516 {
nullptr,
nullptr },
518 luaL_setfuncs(L, vol_callbacks, 0);
519 lua_setmetatable(L, -2);
522 lua_newuserdatauv(L, 0, 0);
523 lua_createtable(L, 0, 10);
524 static luaL_Reg pl_callbacks[] {
534 {
nullptr,
nullptr },
536 luaL_setfuncs(L, pl_callbacks, 0);
537 lua_pushstring(L,
"music playlist");
538 lua_setfield(L, -2,
"__metatable");
539 lua_setmetatable(L, -2);
540 lua_setfield(L, -2,
"music_list");
543 lua_newuserdatauv(L, 0, 0);
544 lua_createtable(L, 0, 3);
545 static luaL_Reg slm_callbacks[] {
548 {
nullptr,
nullptr },
550 luaL_setfuncs(L, slm_callbacks, 0);
551 lua_pushstring(L,
"sound source map");
552 lua_setfield(L, -2,
"__metatable");
553 lua_setmetatable(L, -2);
554 lua_setfield(L, -2,
"sources");
558 luaL_newmetatable(L,
Track);
559 static luaL_Reg track_callbacks[] {
564 {
nullptr,
nullptr },
566 luaL_setfuncs(L, track_callbacks, 0);
567 lua_pushstring(L,
Track);
568 lua_setfield(L, -2,
"__metatable");
572 luaL_newmetatable(L,
Source);
573 static luaL_Reg source_callbacks[] {
578 {
nullptr,
nullptr },
580 luaL_setfuncs(L, source_callbacks, 0);
581 lua_pushstring(L,
Source);
582 lua_setfield(L, -2,
"__metatable");
584 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(std::string_view 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