The Battle for Wesnoth  1.17.4+dev
lua_audio.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2022
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "lua_audio.hpp"
16 
17 #include "log.hpp"
18 #include "lua/lauxlib.h"
19 #include "scripting/lua_common.hpp"
20 #include "scripting/push_check.hpp"
21 #include "sound.hpp"
22 #include "sound_music_track.hpp"
23 #include "preferences/general.hpp"
24 #include "resources.hpp"
25 #include "soundsource.hpp"
26 #include <set>
27 
28 static lg::log_domain log_audio("audio");
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)
32 
33 static const char* Track = "music track";
34 static const char* Source = "sound source";
35 
37  std::shared_ptr<sound::music_track> track;
38 public:
39  explicit lua_music_track(int i) : track(sound::get_track(i)) {}
40  explicit lua_music_track(std::shared_ptr<sound::music_track> new_track) : track(new_track) {}
41  bool valid() const {
42  return track && track->valid();
43  }
45  return *track;
46  }
47  const sound::music_track& operator*() const {
48  return *track;
49  }
50  std::shared_ptr<sound::music_track> operator->() {
51  return track;
52  }
53  std::shared_ptr<const sound::music_track> operator->() const {
54  return track;
55  }
56 };
57 
58 static lua_music_track* push_track(lua_State* L, int i) {
59  lua_music_track* trk = new(L) lua_music_track(i);
60  luaL_setmetatable(L, Track);
61  return trk;
62 }
63 
64 static lua_music_track* push_track(lua_State* L, std::shared_ptr<sound::music_track> new_track) {
65  lua_music_track* trk = new(L) lua_music_track(new_track);
66  luaL_setmetatable(L, Track);
67  return trk;
68 }
69 
70 static lua_music_track* get_track(lua_State* L, int i) {
71  return static_cast<lua_music_track*>(luaL_checkudata(L, i, Track));
72 }
73 
76 public:
77  explicit lua_sound_source(const soundsource::sourcespec& spec) : spec(spec) {}
80  return spec;
81  }
83  return spec;
84  }
86  return &spec;
87  }
89  return &spec;
90  }
91 };
92 
93 static lua_sound_source& push_source(lua_State* L, const soundsource::sourcespec& spec) {
94  lua_sound_source* src = new(L) lua_sound_source(spec);
95  luaL_setmetatable(L, Source);
96  return *src;
97 }
98 
99 static lua_sound_source& get_source(lua_State* L, int i) {
100  return *static_cast<lua_sound_source*>(luaL_checkudata(L, i, Source));
101 }
102 
103 /**
104  * Destroys a lua_music_track object before it is collected (__gc metamethod).
105  */
106 static int impl_track_collect(lua_State* L)
107 {
108  lua_music_track* u = get_track(L, 1);
109  u->lua_music_track::~lua_music_track();
110  return 0;
111 }
112 
113 static int impl_music_get(lua_State* L) {
114  if(lua_isnumber(L, 2)) {
115  push_track(L, lua_tointeger(L, 2) - 1);
116  return 1;
117  }
118  const char* m = luaL_checkstring(L, 2);
119 
120  if(strcmp(m, "current") == 0) {
122  return 1;
123  }
124 
125  if(strcmp(m, "previous") == 0) {
127  return 1;
128  }
129 
130  if(strcmp(m, "current_i") == 0) {
131  auto current_index = sound::get_current_track_index();
132  if(current_index) {
133  lua_pushinteger(L, *current_index + 1);
134  } else {
135  lua_pushnil(L);
136  }
137  return 1;
138  }
139  if(strcmp(m, "all") == 0) {
140  config playlist;
142  const auto& range = playlist.child_range("music");
143  std::vector<config> tracks(range.begin(), range.end());
144  lua_push(L, tracks);
145  return 1;
146  }
147  // This calculation reverses the one used in [volume] to get back the relative volume level.
148  // (Which is the same calculation that's duplicated in impl_music_set.)
150  return luaW_getmetafield(L, 1, m);
151 }
152 
153 static int impl_music_set(lua_State* L) {
154  if(lua_isnumber(L, 2)) {
155  unsigned int i = lua_tointeger(L, 2) - 1;
156  config cfg;
157  if(lua_isnil(L, 3)) {
158  if(i < sound::get_num_tracks()) {
160  }
161  } else if(luaW_toconfig(L, 3, cfg)) {
162  // Don't clear the playlist
163  cfg["append"] = true;
164  // Don't allow play_once=yes
165  if(cfg["play_once"]) {
166  return luaL_argerror(L, 3, "For play_once, use wesnoth.music_list.play instead");
167  }
168  if(i >= sound::get_num_tracks()) {
170  } else {
171  // Remove the track at that index and add the new one in its place
172  // It's a little inefficient though...
174  sound::play_music_config(cfg, false, i);
175  }
176  } else {
177  lua_music_track& track = *get_track(L, 3);
178  if(i < sound::get_num_tracks()) {
179  sound::set_track(i, track.operator->());
180  } else {
181  track->write(cfg, true);
183  }
184  }
185  return 0;
186  }
187  const char* m = luaL_checkstring(L, 2);
189  modify_int_attrib_check_range("current_i", sound::play_track(value - 1), 1, static_cast<int>(sound::get_num_tracks()));
190  return 0;
191 }
192 
193 static int impl_music_len(lua_State* L) {
194  lua_pushinteger(L, sound::get_num_tracks());
195  return 1;
196 }
197 
198 static int intf_music_play(lua_State* L) {
199  sound::play_music_once(luaL_checkstring(L, 1));
200  return 0;
201 }
202 
203 static int intf_music_next(lua_State*) {
204  std::size_t n = sound::get_num_tracks();
205  if(n > 0) {
207  }
208  return 0;
209 }
210 
211 static int intf_music_add(lua_State* L) {
212  int index = -1;
213  if(lua_isinteger(L, 1)) {
214  index = lua_tointeger(L, 1);
215  lua_remove(L, 1);
216  }
217  config cfg = config {
218  "name", luaL_checkstring(L, 1),
219  "append", true,
220  };
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)) {
224  if(found_imm) {
225  return luaL_argerror(L, i, "only one boolean argument may be passed");
226  } else {
227  cfg["immediate"] = luaW_toboolean(L, i);
228  }
229  } else if(lua_isnumber(L, i)) {
230  if(found_ms_after) {
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;
235  } else {
236  cfg["ms_before"] = lua_tointeger(L, i);
237  found_ms_before = true;
238  }
239  } else {
240  return luaL_argerror(L, i, "unrecognized argument");
241  }
242  }
243  sound::play_music_config(cfg, false, index);
244  return 0;
245 }
246 
247 static int intf_music_clear(lua_State*) {
249  return 0;
250 }
251 
252 static int intf_music_remove(lua_State* L) {
253  // Use a non-standard comparator to ensure iteration in descending order
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));
257  }
258  for(int i : to_remove) {
260  }
261  return 0;
262 }
263 
264 static int intf_music_commit(lua_State*) {
266  return 0;
267 }
268 
269 static int impl_track_get(lua_State* L) {
271  if(track == nullptr) {
272  return luaL_error(L, "Error: Attempted to access an invalid music track.\n");
273  }
274  const char* m = luaL_checkstring(L, 2);
275  return_bool_attrib("valid", track->valid());
276  if(!track->valid()) {
277  return luaL_error(L, "Tried to access member of track that is no longer valid.");
278  }
279  return_bool_attrib("append", (*track)->append());
280  return_bool_attrib("shuffle", (*track)->shuffle());
281  return_bool_attrib("immediate", (*track)->immediate());
282  return_bool_attrib("once", (*track)->play_once());
283  return_int_attrib("ms_before", (*track)->ms_before());
284  return_int_attrib("ms_after", (*track)->ms_after());
285  return_string_attrib("name", (*track)->id());
286  return_string_attrib("title", (*track)->title());
287 
288  return_cfg_attrib("__cfg",
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());
297 
298  return luaW_getmetafield(L, 1, m);
299 }
300 
301 static int impl_track_set(lua_State* L) {
303  if(track == nullptr || !track->valid()) {
304  return luaL_error(L, "Error: Attempted to access an invalid music track.\n");
305  }
306  const char* m = luaL_checkstring(L, 2);
307  modify_bool_attrib("shuffle", (*track)->set_shuffle(value));
308  modify_bool_attrib("once", (*track)->set_play_once(value));
309  modify_int_attrib("ms_before", (*track)->set_ms_before(value));
310  modify_int_attrib("ms_after", (*track)->set_ms_after(value));
311  modify_string_attrib("title", (*track)->set_title(value));
312  return 0;
313 }
314 
315 static int impl_track_eq(lua_State* L) {
316  lua_music_track* a = get_track(L, 1);
317  lua_music_track* b = get_track(L, 2);
318  if(!a || !b) {
319  // This implies that one argument is not a music track, though I suspect this is dead code...?
320  // Does Lua ever call this if the arguments are not of the same type?
321  lua_pushboolean(L, false);
322  return 1;
323  }
324  if(!a->valid() && !b->valid()) {
325  lua_pushboolean(L, true);
326  return 1;
327  }
328  if(a->valid() && b->valid()) {
329  lua_music_track& lhs = *a;
330  lua_music_track& rhs = *b;
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());
332  return 1;
333  }
334  lua_pushboolean(L, false);
335  return 1;
336 }
337 
338 /**
339  * Get an existing sound source
340  * Key: The sound source ID
341  */
342 static int impl_sndsrc_get(lua_State* L) {
344  return 0;
345  }
346  std::string id = luaL_checkstring(L, 2);
348  return 0;
349  }
351  return 1;
352 }
353 
354 /**
355  * Adds or removes a sound source by its ID
356  * Key: sound source ID
357  * Value: Table containing keyword arguments, existing sound source userdata, or nil to delete
358  */
359 static int impl_sndsrc_set(lua_State* L) {
361  return 0;
362  }
363  std::string id = luaL_checkstring(L, 2);
364  config cfg;
365  if(lua_isnil(L, 3)) {
367  } else if(luaW_toconfig(L, 3, cfg)) {
368  cfg["id"] = id;
369  soundsource::sourcespec spec(cfg);
372  } else {
373  auto& src = get_source(L, 3);
376  }
377  return 0;
378 }
379 static int impl_source_collect(lua_State* L)
380 {
381  lua_sound_source& u = get_source(L, 1);
382  u.lua_sound_source::~lua_sound_source();
383  return 0;
384 }
385 
386 static int impl_source_get(lua_State* L) {
387  lua_sound_source& src = get_source(L, 1);
388  const char* m = luaL_checkstring(L, 2);
389  return_string_attrib("id", src->id());
391  return_int_attrib("delay", src->minimum_delay());
392  return_int_attrib("chance", src->chance());
393  return_int_attrib("loop", src->loops());
394  return_int_attrib("range", src->full_range());
395  return_int_attrib("fade_range", src->fade_range());
396  return_bool_attrib("check_fogged", src->check_fogged());
397  return_bool_attrib("check_shrouded", src->check_shrouded());
398  return_cfg_attrib("__cfg", src->write(cfg));
399 
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) {
404  luaW_pushlocation(L, loc);
405  lua_rawseti(L, -1, lua_rawlen(L, -2) + 1);
406  }
407  }
408 
409  return luaW_getmetafield(L, 1, m);
410 }
411 
412 static int impl_source_set(lua_State* L) {
413  lua_sound_source& src = get_source(L, 1);
414  const char* m = luaL_checkstring(L, 2);
415  modify_int_attrib("delay", src->set_minimum_delay(value));
416  modify_int_attrib("chance", src->set_chance(value));
417  modify_int_attrib("loop", src->set_loops(value));
418  modify_int_attrib("range", src->set_full_range(value));
419  modify_int_attrib("fade_range", src->set_fade_range(value));
420  modify_bool_attrib("check_fogged", src->set_check_fogged(value));
421  modify_bool_attrib("check_shrouded", src->set_check_shrouded(value));
422 
423  if(strcmp(m, "sounds") == 0) {
424  std::string files;
425  if(lua_istable(L, 3)) {
426  files = utils::join(lua_check<std::vector<std::string>>(L, 3));
427  } else {
428  files = luaL_checkstring(L, 3);
429  }
430  src->set_files(files);
431  }
432 
433  if(strcmp(m, "locations") == 0) {
434  std::vector<map_location> locs;
435  locs.resize(1);
436  if(luaW_tolocation(L, 3, locs[0])) {
437 
438  } else {
439  locs.clear();
440  for(lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
441  locs.push_back(luaW_checklocation(L, -1));
442  }
443  }
444  src->set_locations(locs);
445  }
446 
447  // Now apply the change
450  return 0;
451 }
452 
453 static int impl_source_eq(lua_State* L) {
454  lua_sound_source& a = get_source(L, 1);
455  lua_sound_source& b = get_source(L, 2);
456  if(a->id() != b->id()) {
457  lua_pushboolean(L, false);
458  return 1;
459  }
460  lua_pushboolean(L,
461  a->files() == b->files() &&
462  a->minimum_delay() == b->minimum_delay() &&
463  a->chance() == b->chance() &&
464  a->loops() == b->loops() &&
465  a->full_range() == b->full_range() &&
466  a->fade_range() == b->fade_range() &&
467  a->check_fogged() == b->check_fogged() &&
468  a->check_shrouded() == b->check_shrouded() &&
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())
470  );
471  return 1;
472 }
473 
474 /**
475  * Gets the current sound volume
476  * - Return: Current volume
477  */
478 static int impl_audio_get(lua_State* L)
479 {
480  std::string m = luaL_checkstring(L, 2);
481  if(m != "volume") return 0;
482  int vol = preferences::sound_volume();
483  lua_pushnumber(L, sound::get_sound_volume() * 100.0 / vol);
484  return 1;
485 }
486 
487 /**
488  * Sets the current sound volume
489  * - Arg: New volume to set
490  */
491 static int impl_audio_set(lua_State* L)
492 {
493  std::string m = luaL_checkstring(L, 2);
494  if(m != "volume") {
495  lua_rawset(L, 1);
496  return 0;
497  }
498  int vol = preferences::sound_volume();
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");
502  }
503  vol = static_cast<int>(rel*vol / 100.0f);
505  return 0;
506 }
507 
508 namespace lua_audio {
509  std::string register_table(lua_State* L) {
510  // Metatable to enable the volume attribute
511  luaW_getglobal(L, "wesnoth", "audio");
512  lua_createtable(L, 0, 2);
513  static luaL_Reg vol_callbacks[] {
514  { "__index", impl_audio_get },
515  { "__newindex", impl_audio_set },
516  { nullptr, nullptr },
517  };
518  luaL_setfuncs(L, vol_callbacks, 0);
519  lua_setmetatable(L, -2);
520 
521  // The music playlist metatable
522  lua_newuserdatauv(L, 0, 0);
523  lua_createtable(L, 0, 10);
524  static luaL_Reg pl_callbacks[] {
525  { "__index", impl_music_get },
526  { "__newindex", impl_music_set },
527  { "__len", impl_music_len },
528  { "play", intf_music_play },
529  { "add", intf_music_add },
530  { "clear", intf_music_clear },
531  { "remove", intf_music_remove },
532  { "next", intf_music_next },
533  { "force_refresh", intf_music_commit },
534  { nullptr, nullptr },
535  };
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");
541 
542  // The sound source map metatable
543  lua_newuserdatauv(L, 0, 0);
544  lua_createtable(L, 0, 3);
545  static luaL_Reg slm_callbacks[] {
546  { "__index", impl_sndsrc_get },
547  { "__newindex", impl_sndsrc_set },
548  { nullptr, nullptr },
549  };
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");
555  lua_pop(L, 1);
556 
557  // The music track metatable
558  luaL_newmetatable(L, Track);
559  static luaL_Reg track_callbacks[] {
560  {"__gc", impl_track_collect},
561  { "__index", impl_track_get },
562  { "__newindex", impl_track_set },
563  { "__eq", impl_track_eq },
564  { nullptr, nullptr },
565  };
566  luaL_setfuncs(L, track_callbacks, 0);
567  lua_pushstring(L, Track);
568  lua_setfield(L, -2, "__metatable");
569  lua_pop(L, 1);
570 
571  // The sound source metatable
572  luaL_newmetatable(L, Source);
573  static luaL_Reg source_callbacks[] {
574  {"__gc", impl_source_collect},
575  { "__index", impl_source_get },
576  { "__newindex", impl_source_set },
577  { "__eq", impl_source_eq },
578  { nullptr, nullptr },
579  };
580  luaL_setfuncs(L, source_callbacks, 0);
581  lua_pushstring(L, Source);
582  lua_setfield(L, -2, "__metatable");
583 
584  return "Adding music playlist table...\n";
585  }
586 }
void empty_playlist()
Definition: sound.cpp:612
std::decay_t< T > lua_check(lua_State *L, int n)
Definition: push_check.hpp:346
#define modify_bool_attrib(name, accessor)
Definition: lua_common.hpp:404
void write(config &cfg) const
Serializes information into cfg as a new (appended) child of key "sound_source".
unsigned int get_num_tracks()
Definition: sound.cpp:221
static int impl_source_eq(lua_State *L)
Definition: lua_audio.cpp:453
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...
Definition: lua_audio.cpp:359
sound::music_track & operator*()
Definition: lua_audio.cpp:44
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::shared_ptr< music_track > get_current_track()
Definition: sound.cpp:208
static int impl_audio_get(lua_State *L)
Gets the current sound volume.
Definition: lua_audio.cpp:478
static int intf_music_commit(lua_State *)
Definition: lua_audio.cpp:264
static lua_music_track * get_track(lua_State *L, int i)
Definition: lua_audio.cpp:70
#define a
static lg::log_domain log_audio("audio")
child_itors child_range(config_key_type key)
Definition: config.cpp:344
static lua_sound_source & push_source(lua_State *L, const soundsource::sourcespec &spec)
Definition: lua_audio.cpp:93
void remove_track(unsigned int i)
Definition: sound.cpp:246
std::shared_ptr< sound::music_track > track
Definition: lua_audio.cpp:37
#define return_string_attrib(name, accessor)
Definition: lua_common.hpp:256
static int impl_sndsrc_get(lua_State *L)
Get an existing sound source Key: The sound source ID.
Definition: lua_audio.cpp:342
static int impl_source_collect(lua_State *L)
Definition: lua_audio.cpp:379
std::shared_ptr< music_track > get_previous_music_track()
Definition: sound.cpp:212
void set_fade_range(int value)
static int impl_track_collect(lua_State *L)
Destroys a lua_music_track object before it is collected (__gc metamethod).
Definition: lua_audio.cpp:106
void remove(const std::string &id)
Definition: soundsource.cpp:66
Audio output for sound and music.
Definition: sound.cpp:41
void play_music_once(const std::string &file)
Definition: sound.cpp:603
#define return_vector_string_attrib(name, accessor)
Definition: lua_common.hpp:319
void lua_push(lua_State *L, const T &val)
Definition: push_check.hpp:360
void set_minimum_delay(int value)
void write_music_play_list(config &snapshot)
Definition: sound.cpp:852
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
Definition: lua_common.cpp:774
soundsource::sourcespec * operator->()
Definition: lua_audio.cpp:85
#define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max)
Definition: lua_common.hpp:392
const std::vector< map_location > & get_locations() const
static int intf_music_play(lua_State *L)
Definition: lua_audio.cpp:198
const std::string & id() const
static int impl_music_set(lua_State *L)
Definition: lua_audio.cpp:153
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
Definition: general.hpp:83
#define b
bool valid() const
Definition: lua_audio.cpp:41
static int impl_music_len(lua_State *L)
Definition: lua_audio.cpp:193
static const char * Track
Definition: lua_audio.cpp:33
static int intf_music_add(lua_State *L)
Definition: lua_audio.cpp:211
static int intf_music_next(lua_State *)
Definition: lua_audio.cpp:203
#define modify_string_attrib(name, accessor)
Definition: lua_common.hpp:347
#define return_int_attrib(name, accessor)
Definition: lua_common.hpp:267
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...
Definition: lua_common.cpp:952
bool luaW_toboolean(lua_State *L, int n)
Definition: lua_common.cpp:971
static lua_music_track * push_track(lua_State *L, int i)
Definition: lua_audio.cpp:58
void set_full_range(int value)
bool check_shrouded() const
std::shared_ptr< sound::music_track > operator->()
Definition: lua_audio.cpp:50
static int impl_track_eq(lua_State *L)
Definition: lua_audio.cpp:315
#define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max)
Definition: lua_common.hpp:369
static int impl_source_set(lua_State *L)
Definition: lua_audio.cpp:412
static int impl_audio_set(lua_State *L)
Sets the current sound volume.
Definition: lua_audio.cpp:491
const std::string & files() const
void set_loops(int value)
static const char * Source
Definition: lua_audio.cpp:34
int get_sound_volume()
Definition: sound.cpp:1079
void set_sound_volume(int vol)
Definition: sound.cpp:1088
void set_music_volume(int vol)
Definition: sound.cpp:1068
void set_check_shrouded(bool value)
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
Definition: lua_common.cpp:823
#define return_cfg_attrib(name, accessor)
Definition: lua_common.hpp:297
Sound source info class.
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
std::size_t i
Definition: function.cpp:967
soundsource::manager * soundsources
Definition: resources.cpp:28
void add(const sourcespec &source)
Definition: soundsource.cpp:51
lua_music_track(std::shared_ptr< sound::music_track > new_track)
Definition: lua_audio.cpp:40
Internal representation of music tracks.
static int intf_music_remove(lua_State *L)
Definition: lua_audio.cpp:252
std::string register_table(lua_State *L)
Definition: lua_audio.cpp:509
static int impl_track_get(lua_State *L)
Definition: lua_audio.cpp:269
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.
Definition: unicode.cpp:72
int get_music_volume()
Definition: sound.cpp:1059
void set_files(const std::string &f)
static int impl_music_get(lua_State *L)
Definition: lua_audio.cpp:113
void set_chance(int value)
const soundsource::sourcespec * operator->() const
Definition: lua_audio.cpp:88
#define return_bool_attrib(name, accessor)
Definition: lua_common.hpp:287
int sound_volume()
Definition: general.cpp:617
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...
Definition: lua_common.cpp:515
#define f
std::vector< std::string > split(const config_attribute_value &val)
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:705
static int impl_source_get(lua_State *L)
Definition: lua_audio.cpp:386
std::optional< unsigned int > get_current_track_index()
Definition: sound.cpp:201
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.
Definition: lua_common.cpp:714
#define return_float_attrib(name, accessor)
Definition: lua_common.hpp:277
const soundsource::sourcespec & operator*() const
Definition: lua_audio.cpp:82
Standard logging facilities (interface).
lua_sound_source(const soundsource::sourcespec &spec)
Definition: lua_audio.cpp:77
std::shared_ptr< const sound::music_track > operator->() const
Definition: lua_audio.cpp:53
soundsource::sourcespec spec
Definition: lua_audio.cpp:75
void commit_music_changes()
Definition: sound.cpp:823
void set_track(unsigned int i, const std::shared_ptr< music_track > &to)
Definition: sound.cpp:239
static int intf_music_clear(lua_State *)
Definition: lua_audio.cpp:247
const sound::music_track & operator*() const
Definition: lua_audio.cpp:47
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
void play_track(unsigned int i)
Definition: sound.cpp:629
void set_check_fogged(bool value)
static int impl_track_set(lua_State *L)
Definition: lua_audio.cpp:301
static map_location::DIRECTION n
soundsource::sourcespec & operator*()
Definition: lua_audio.cpp:79
lua_music_track(int i)
Definition: lua_audio.cpp:39
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
Definition: lua_common.cpp:725
int music_volume()
Definition: general.cpp:602
#define modify_int_attrib(name, accessor)
Definition: lua_common.hpp:358
static lua_sound_source & get_source(lua_State *L, int i)
Definition: lua_audio.cpp:99
void set_locations(const std::vector< map_location > &locs)