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;
49 std::shared_ptr<const sound::music_track>
operator->()
const {
57 luaL_setmetatable(L,
Track);
90 luaL_setmetatable(L,
Source);
104 u->lua_music_track::~lua_music_track();
109 if(lua_isnumber(L, 2)) {
113 const char* m = luaL_checkstring(L, 2);
115 if(strcmp(m,
"current") == 0) {
120 if(strcmp(m,
"previous") == 0) {
125 if(strcmp(m,
"current_i") == 0) {
128 lua_pushinteger(L, *current_index + 1);
134 if(strcmp(m,
"all") == 0) {
138 std::vector<config> tracks(range.begin(), range.end());
149 if(lua_isnumber(L, 2)) {
150 unsigned int i = lua_tointeger(L, 2) - 1;
152 if(lua_isnil(L, 3)) {
158 cfg[
"append"] =
true;
160 if(
cfg[
"play_once"].to_bool()) {
161 return luaL_argerror(L, 3,
"For play_once, use wesnoth.music_list.play instead");
176 track->write(
cfg,
true);
182 const char* m = luaL_checkstring(L, 2);
208 if(lua_isinteger(L, 1)) {
209 index = lua_tointeger(L, 1);
213 "name", luaL_checkstring(L, 1),
216 bool found_ms_before =
false, found_ms_after =
false, found_imm =
false;
217 for(
int i = 2;
i <= lua_gettop(L);
i++) {
218 if(lua_isboolean(L,
i)) {
220 return luaL_argerror(L,
i,
"only one boolean argument may be passed");
224 }
else if(lua_isnumber(L,
i)) {
226 return luaL_argerror(L,
i,
"only two integer arguments may be passed");
227 }
else if(found_ms_before) {
228 cfg[
"ms_after"] = lua_tointeger(L,
i);
229 found_ms_after =
true;
231 cfg[
"ms_before"] = lua_tointeger(L,
i);
232 found_ms_before =
true;
235 return luaL_argerror(L,
i,
"unrecognized argument");
249 std::set<int, std::greater<int>> to_remove;
250 for(
int i = 1;
i <= lua_gettop(L);
i++) {
251 to_remove.insert(luaL_checkinteger(L,
i));
253 for(
int i : to_remove) {
266 if(track ==
nullptr) {
267 return luaL_error(L,
"Error: Attempted to access an invalid music track.\n");
269 const char* m = luaL_checkstring(L, 2);
281 cfg[
"shuffle"]=(*track)->shuffle();
282 cfg[
"immediate"]=(*track)->immediate();
283 cfg[
"once"]=(*track)->play_once();
284 cfg[
"ms_before"]=(*track)->ms_before();
285 cfg[
"ms_after"]=(*track)->ms_after();
286 cfg[
"name"]=(*track)->id();
287 cfg[
"title"]=(*track)->title());
294 if(track ==
nullptr) {
295 return luaL_error(L,
"Error: Attempted to access an invalid music track.\n");
297 const char* m = luaL_checkstring(L, 2);
300 modify_int_attrib(
"ms_before", (*track)->set_ms_before(std::chrono::milliseconds{value}));
301 modify_int_attrib(
"ms_after", (*track)->set_ms_after(std::chrono::milliseconds{value}));
312 lua_pushboolean(L,
false);
317 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());
329 std::string
id = luaL_checkstring(L, 2);
346 std::string
id = luaL_checkstring(L, 2);
348 if(lua_isnil(L, 3)) {
365 u.lua_sound_source::~lua_sound_source();
371 const char* m = luaL_checkstring(L, 2);
383 if(strcmp(m,
"locations") == 0) {
384 const auto& locs =
src->get_locations();
385 lua_createtable(L, locs.size(), 0);
386 for(
const auto&
loc : locs) {
388 lua_rawseti(L, -1, lua_rawlen(L, -2) + 1);
397 const char* m = luaL_checkstring(L, 2);
406 if(strcmp(m,
"sounds") == 0) {
408 if(lua_istable(L, 3)) {
411 files = luaL_checkstring(L, 3);
413 src->set_files(files);
416 if(strcmp(m,
"locations") == 0) {
417 std::vector<map_location> locs;
423 for(lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
427 src->set_locations(locs);
439 if(a->
id() !=
b->id()) {
440 lua_pushboolean(L,
false);
444 a->
files() ==
b->files() &&
447 a->
loops() ==
b->loops() &&
452 std::set<map_location>(a->
get_locations().begin(), a->
get_locations().end()) == std::set<map_location>(
b->get_locations().begin(),
b->get_locations().end())
463 std::string m = luaL_checkstring(L, 2);
464 if(m !=
"volume")
return 0;
476 std::string m = luaL_checkstring(L, 2);
482 float rel = lua_tonumber(L, 3);
483 if(rel < 0.0f || rel > 100.0f) {
484 return luaL_argerror(L, 1,
"volume must be in range 0..100");
486 vol =
static_cast<int>(rel*vol / 100.0f);
495 lua_createtable(L, 0, 2);
496 static luaL_Reg vol_callbacks[] {
499 {
nullptr,
nullptr },
501 luaL_setfuncs(L, vol_callbacks, 0);
502 lua_setmetatable(L, -2);
505 lua_newuserdatauv(L, 0, 0);
506 lua_createtable(L, 0, 10);
507 static luaL_Reg pl_callbacks[] {
517 {
nullptr,
nullptr },
519 luaL_setfuncs(L, pl_callbacks, 0);
520 lua_pushstring(L,
"music playlist");
521 lua_setfield(L, -2,
"__metatable");
522 lua_setmetatable(L, -2);
523 lua_setfield(L, -2,
"music_list");
526 lua_newuserdatauv(L, 0, 0);
527 lua_createtable(L, 0, 3);
528 static luaL_Reg slm_callbacks[] {
531 {
nullptr,
nullptr },
533 luaL_setfuncs(L, slm_callbacks, 0);
534 lua_pushstring(L,
"sound source map");
535 lua_setfield(L, -2,
"__metatable");
536 lua_setmetatable(L, -2);
537 lua_setfield(L, -2,
"sources");
541 luaL_newmetatable(L,
Track);
542 static luaL_Reg track_callbacks[] {
547 {
nullptr,
nullptr },
549 luaL_setfuncs(L, track_callbacks, 0);
550 lua_pushstring(L,
Track);
551 lua_setfield(L, -2,
"__metatable");
555 luaL_newmetatable(L,
Source);
556 static luaL_Reg source_callbacks[] {
561 {
nullptr,
nullptr },
563 luaL_setfuncs(L, source_callbacks, 0);
564 lua_pushstring(L,
Source);
565 lua_setfield(L, -2,
"__metatable");
567 return "Adding music playlist table...\n";
A config object defines a single node in a WML file, with access to child nodes.
void append(const config &cfg)
Append data from another config object to this one.
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 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 lua_music_track * push_track(lua_State *L, std::shared_ptr< sound::music_track > &&new_track)
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
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_track(unsigned int i)
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