The Battle for Wesnoth  1.19.5+dev
sound_music_track.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>, Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <chrono>
19 #include <string>
20 #include <memory>
21 
22 class config;
23 
24 namespace sound {
25 
26 /**
27  * Internal representation of music tracks.
28  */
30 {
31 public:
32  music_track();
33  music_track(const config& node);
34  explicit music_track(const std::string& v_name);
35  void write(config& parent_node, bool append) const;
36 
37  bool valid() const { return file_path_.empty() != true; }
38 
39  bool append() const { return append_; }
40  bool immediate() const { return immediate_; }
41  bool shuffle() const { return shuffle_; }
42  bool play_once() const { return once_; }
43  auto ms_before() const { return ms_before_; }
44  auto ms_after() const { return ms_after_; }
45 
46  const std::string& file_path() const { return file_path_; }
47  const std::string& id() const { return id_; }
48  const std::string& title() const { return title_; }
49 
50  void set_play_once(bool v) { once_ = v; }
51  void set_shuffle(bool v) { shuffle_ = v; }
52  void set_ms_before(const std::chrono::milliseconds& v) { ms_before_ = v; }
53  void set_ms_after(const std::chrono::milliseconds& v) { ms_after_ = v; }
54  void set_title(const std::string& v) { title_ = v; }
55 
56 private:
57  void resolve();
58 
59  std::string id_;
60  std::string file_path_;
61  std::string title_;
62 
63  std::chrono::milliseconds ms_before_, ms_after_;
64 
65  bool once_;
66  bool append_;
67  bool immediate_;
68  bool shuffle_;
69 };
70 
71 std::shared_ptr<music_track> get_track(unsigned int i);
72 void set_track(unsigned int i, const std::shared_ptr<music_track>& to);
73 
74 } /* end namespace sound */
75 
76 inline bool operator==(const sound::music_track& a, const sound::music_track& b) {
77  return a.file_path() == b.file_path();
78 }
79 inline bool operator!=(const sound::music_track& a, const sound::music_track& b) {
80  return a.file_path() != b.file_path();
81 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Internal representation of music tracks.
const std::string & title() const
void set_play_once(bool v)
std::chrono::milliseconds ms_before_
void set_ms_before(const std::chrono::milliseconds &v)
void set_title(const std::string &v)
const std::string & file_path() const
void write(config &parent_node, bool append) const
std::chrono::milliseconds ms_after_
const std::string & id() const
void set_ms_after(const std::chrono::milliseconds &v)
std::size_t i
Definition: function.cpp:1028
Audio output for sound and music.
Definition: sound.cpp:41
void set_track(unsigned int i, const std::shared_ptr< music_track > &to)
Definition: sound.cpp:239
std::shared_ptr< music_track > get_track(unsigned int i)
Definition: sound.cpp:226
bool operator==(const sound::music_track &a, const sound::music_track &b)
bool operator!=(const sound::music_track &a, const sound::music_track &b)
#define b