The Battle for Wesnoth  1.15.2+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <>
3  Part of the Battle for Wesnoth Project
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,
12  See the COPYING file for more details.
13 */
15 #pragma once
17 #include "events.hpp"
18 #include "sound_music_track.hpp"
20 #include <boost/optional.hpp>
21 #include <string>
23 class config;
25 namespace sound {
34 };
36 bool init_sound();
37 void close_sound();
38 void reset_sound();
40 void stop_music();
41 void stop_sound();
42 void stop_UI_sound();
43 void stop_bell();
45 // Read config entry, alter track list accordingly.
46 void play_music_config(const config &music_node, bool allow_interrupt_current_track = false, int i = -1);
47 // Act on any track list changes from above.
50 // Play this particular music file over and over and over.
51 void play_music_repeatedly(const std::string& id);
52 // Play this particular music file once, then silence.
53 void play_music_once(const std::string& id);
54 // Empty the playlist
55 void empty_playlist();
56 // Start playing current music.
57 void play_music();
59 // Change parameters of a playing sound, given its id
60 void reposition_sound(int id, unsigned int distance);
61 #define DISTANCE_SILENT 255
63 // Check if there's a sound associated with given id playing
64 bool is_sound_playing(int id);
66 // Stop sound associated with a given id
67 void stop_sound(int id);
69 // Play sound, or random one of comma-separated sounds.
70 void play_sound(const std::string& files, channel_group group = SOUND_FX, unsigned int repeats = 0);
72 // Play sound, or random one of comma-separated sounds. Use specified
73 // distance and associate it with specified id (of a sound source).
74 void play_sound_positioned(const std::string &files, int id, int repeats, unsigned int distance);
76 // Play sound, or random one of comma-separated sounds in bell channel
77 void play_bell(const std::string& files);
79 // Play sound, or random one of comma-separated sounds in timer channel
80 void play_timer(const std::string& files, int loop_ticks, int fadein_ticks);
82 // Play user-interface sound, or random one of comma-separated sounds.
83 void play_UI_sound(const std::string& files);
85 // A class to periodically check for new music that needs to be played
88 };
90 // A class to mute music when the game is in background
92 public:
93  music_muter();
94  void handle_event(const SDL_Event&) override {}
95  void handle_window_event(const SDL_Event& event) override;
96 };
98 // Save music playlist for snapshot
99 void write_music_play_list(config& snapshot);
101 int get_music_volume();
102 int get_sound_volume();
103 void set_music_volume(int vol);
104 void set_sound_volume(int vol);
105 void set_bell_volume(int vol);
106 void set_UI_volume(int vol);
108 boost::optional<unsigned int> get_current_track_index();
109 std::shared_ptr<sound::music_track> get_current_track();
110 std::shared_ptr<sound::music_track> get_previous_music_track();
111 void set_previous_track(std::shared_ptr<music_track>);
112 unsigned int get_num_tracks();
113 void remove_track(unsigned int i);
114 void play_track(unsigned int i);
116 void flush_cache();
118 }
void empty_playlist()
Definition: sound.cpp:580
void close_sound()
Definition: sound.cpp:463
unsigned int get_num_tracks()
Definition: sound.cpp:220
bool is_sound_playing(int id)
Definition: sound.cpp:846
void play_sound_positioned(const std::string &files, int id, int repeats, unsigned int distance)
Definition: sound.cpp:995
void stop_music()
Definition: sound.cpp:525
Definition: sound.hpp:27
std::shared_ptr< music_track > get_current_track()
Definition: sound.cpp:207
logger & info()
Definition: log.cpp:90
void set_UI_volume(int vol)
Definition: sound.cpp:1087
void remove_track(unsigned int i)
Definition: sound.cpp:245
std::shared_ptr< music_track > get_previous_music_track()
Definition: sound.cpp:211
void stop_sound()
Definition: sound.cpp:533
Audio output for sound and music.
Definition: sound.cpp:40
void play_music_once(const std::string &file)
Definition: sound.cpp:571
void write_music_play_list(config &snapshot)
Definition: sound.cpp:820
void reposition_sound(int id, unsigned int distance)
Definition: sound.cpp:830
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
Definition: sound.cpp:988
bool init_sound()
Definition: sound.cpp:411
void reset_sound()
Definition: sound.cpp:494
void set_bell_volume(int vol)
Definition: sound.cpp:1075
void stop_UI_sound()
Definition: sound.cpp:560
void set_previous_track(std::shared_ptr< music_track > track)
Definition: sound.cpp:215
void play_music()
Definition: sound.cpp:585
boost::optional< unsigned int > get_current_track_index()
Definition: sound.cpp:200
int get_sound_volume()
Definition: sound.cpp:1046
void set_sound_volume(int vol)
Definition: sound.cpp:1055
void set_music_volume(int vol)
Definition: sound.cpp:1035
void flush_cache()
Definition: sound.cpp:194
std::size_t i
Definition: function.cpp:933
void process(events::pump_info &info)
Definition: sound.cpp:736
void stop_bell()
Definition: sound.cpp:548
int get_music_volume()
Definition: sound.cpp:1026
void play_bell(const std::string &files)
Definition: sound.cpp:1003
void play_timer(const std::string &files, int loop_ticks, int fadein_ticks)
Definition: sound.cpp:1011
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:673
void play_music_repeatedly(const std::string &id)
Definition: sound.cpp:651
void play_UI_sound(const std::string &files)
Definition: sound.cpp:1019
void commit_music_changes()
Definition: sound.cpp:791
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
void play_track(unsigned int i)
Definition: sound.cpp:597
void handle_event(const SDL_Event &) override
Definition: sound.hpp:94