The Battle for Wesnoth  1.19.0-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 <string>
19 #include <memory>
20 
21 class config;
22 
23 namespace sound {
24 
25 /**
26  * Internal representation of music tracks.
27  */
29 {
30 public:
31  music_track();
32  music_track(const config& node);
33  explicit music_track(const std::string& v_name);
34  void write(config& parent_node, bool append) const;
35 
36  bool valid() const { return file_path_.empty() != true; }
37 
38  bool append() const { return append_; }
39  bool immediate() const { return immediate_; }
40  bool shuffle() const { return shuffle_; }
41  bool play_once() const { return once_; }
42  int ms_before() const { return ms_before_; }
43  int ms_after() const { return ms_after_; }
44 
45  const std::string& file_path() const { return file_path_; }
46  const std::string& id() const { return id_; }
47  const std::string& title() const { return title_; }
48 
49  void set_play_once(bool v) { once_ = v; }
50  void set_shuffle(bool v) { shuffle_ = v; }
51  void set_ms_before(int v) { ms_before_ = v; }
52  void set_ms_after(int v) { ms_after_ = v; }
53  void set_title(const std::string& v) { title_ = v; }
54 
55 private:
56  void resolve();
57 
58  std::string id_;
59  std::string file_path_;
60  std::string title_;
61 
63 
64  bool once_;
65  bool append_;
66  bool immediate_;
67  bool shuffle_;
68 };
69 
70 std::shared_ptr<music_track> get_track(unsigned int i);
71 void set_track(unsigned int i, const std::shared_ptr<music_track>& to);
72 
73 } /* end namespace sound */
74 
75 inline bool operator==(const sound::music_track& a, const sound::music_track& b) {
76  return a.file_path() == b.file_path();
77 }
78 inline bool operator!=(const sound::music_track& a, const sound::music_track& b) {
79  return a.file_path() != b.file_path();
80 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Internal representation of music tracks.
const std::string & title() const
void set_play_once(bool v)
void set_title(const std::string &v)
const std::string & file_path() const
void write(config &parent_node, bool append) const
const std::string & id() const
std::size_t i
Definition: function.cpp:968
Audio output for sound and music.
Definition: sound.cpp:40
void set_track(unsigned int i, const std::shared_ptr< music_track > &to)
Definition: sound.cpp:237
std::shared_ptr< music_track > get_track(unsigned int i)
Definition: sound.cpp:224
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 a
#define b