22 #include "vorbis/vorbisfile.h"
25 #define ERR_AUDIO LOG_STREAM(err, log_audio)
26 #define LOG_AUDIO LOG_STREAM(info, log_audio)
32 std::string title_from_file(
const std::string& track_path)
35 if(ov_fopen(track_path.c_str(), &vf) < 0) {
36 LOG_AUDIO <<
"Error opening file '" << track_path <<
"' for track identification";
40 vorbis_comment* comments = ov_comment(&vf, -1);
41 char** user_comments = comments->user_comments;
44 for(
int i = 0;
i < comments->comments;
i++) {
45 const std::string comment_string(user_comments[
i]);
48 if(comment_list[0] ==
"TITLE" || comment_list[0] ==
"title") {
49 title = comment_list[1];
58 utils::optional<std::string> resolve_track_path(
const std::string& track_file)
60 if(!track_file.empty()) {
64 LOG_AUDIO <<
"empty track filename specified for track identification";
65 return utils::nullopt;
72 if(
auto path = resolve_track_path(
cfg[
"name"])) {
73 return std::make_shared<music_track>(*
path,
cfg);
76 LOG_AUDIO <<
"could not find track '" <<
cfg[
"name"] <<
"'";
82 if(
auto path = resolve_track_path(file)) {
83 return std::make_shared<music_track>(*
path, file);
86 LOG_AUDIO <<
"could not find track '" << file <<
"'";
92 , file_path_(file_path)
93 , title_(node[
"title"])
94 , ms_before_(node[
"ms_before"].to_int())
95 , ms_after_(node[
"ms_after"].to_int())
96 , once_(node[
"play_once"].to_bool())
97 , append_(node[
"append"].to_bool())
98 , immediate_(node[
"immediate"].to_bool())
99 , shuffle_(node[
"shuffle"].to_bool(true))
108 , file_path_(file_path)
109 , title_(title_from_file(file_path_))
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(config_key_type key)
std::chrono::milliseconds ms_before_
void write(config &parent_node, bool append) const
static std::shared_ptr< music_track > create(const config &cfg)
music_track(const std::string &file_path, const config &node)
std::chrono::milliseconds ms_after_
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
Standard logging facilities (interface).
utils::optional< std::string > get_binary_file_location(const std::string &type, const std::string &filename)
Returns a complete path to the actual file of a given type, if it exists.
utils::optional< std::string > get_localized_path(const std::string &file, const std::string &suff)
Returns the localized version of the given filename, if it exists.
Audio output for sound and music.
std::vector< std::string_view > split_view(std::string_view s, const char sep, const int flags)
static lg::log_domain log_audio("audio")