The Battle for Wesnoth  1.15.7+dev
sound.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
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 #pragma once
16 
17 #include "events.hpp"
18 #include "sound_music_track.hpp"
19 
20 #include <boost/optional.hpp>
21 #include <string>
22 
23 class config;
24 
25 namespace sound {
26 
34 };
35 
37 std::vector<std::string> enumerate_drivers();
38 
40 {
42  int frequency;
43  uint16_t format;
44  int channels;
46 
47  static driver_status query();
48 };
49 
50 bool init_sound();
51 void close_sound();
52 void reset_sound();
53 
54 void stop_music();
55 void stop_sound();
56 void stop_UI_sound();
57 void stop_bell();
58 
59 // Read config entry, alter track list accordingly.
60 void play_music_config(const config &music_node, bool allow_interrupt_current_track = false, int i = -1);
61 // Act on any track list changes from above.
63 
64 // Play this particular music file over and over and over.
65 void play_music_repeatedly(const std::string& id);
66 // Play this particular music file once, then silence.
67 void play_music_once(const std::string& id);
68 // Empty the playlist
69 void empty_playlist();
70 // Start playing current music.
71 void play_music();
72 
73 // Change parameters of a playing sound, given its id
74 void reposition_sound(int id, unsigned int distance);
75 #define DISTANCE_SILENT 255
76 
77 // Check if there's a sound associated with given id playing
78 bool is_sound_playing(int id);
79 
80 // Stop sound associated with a given id
81 void stop_sound(int id);
82 
83 // Play sound, or random one of comma-separated sounds.
84 void play_sound(const std::string& files, channel_group group = SOUND_FX, unsigned int repeats = 0);
85 
86 // Play sound, or random one of comma-separated sounds. Use specified
87 // distance and associate it with specified id (of a sound source).
88 void play_sound_positioned(const std::string &files, int id, int repeats, unsigned int distance);
89 
90 // Play sound, or random one of comma-separated sounds in bell channel
91 void play_bell(const std::string& files);
92 
93 // Play sound, or random one of comma-separated sounds in timer channel
94 void play_timer(const std::string& files, int loop_ticks, int fadein_ticks);
95 
96 // Play user-interface sound, or random one of comma-separated sounds.
97 void play_UI_sound(const std::string& files);
98 
99 // A class to periodically check for new music that needs to be played
102 };
103 
104 // A class to mute music when the game is in background
106 public:
107  music_muter();
108  void handle_event(const SDL_Event&) override {}
109  void handle_window_event(const SDL_Event& event) override;
110 };
111 
112 // Save music playlist for snapshot
113 void write_music_play_list(config& snapshot);
114 
115 int get_music_volume();
116 int get_sound_volume();
117 void set_music_volume(int vol);
118 void set_sound_volume(int vol);
119 void set_bell_volume(int vol);
120 void set_UI_volume(int vol);
121 
122 boost::optional<unsigned int> get_current_track_index();
123 std::shared_ptr<sound::music_track> get_current_track();
124 std::shared_ptr<sound::music_track> get_previous_music_track();
125 void set_previous_track(std::shared_ptr<music_track>);
126 unsigned int get_num_tracks();
127 void remove_track(unsigned int i);
128 void play_track(unsigned int i);
129 
130 void flush_cache();
131 
132 }
void empty_playlist()
Definition: sound.cpp:611
void close_sound()
Definition: sound.cpp:494
unsigned int get_num_tracks()
Definition: sound.cpp:220
bool is_sound_playing(int id)
Definition: sound.cpp:877
void play_sound_positioned(const std::string &files, int id, int repeats, unsigned int distance)
Definition: sound.cpp:1027
void stop_music()
Definition: sound.cpp:556
channel_group
Definition: sound.hpp:27
std::string current_driver()
Definition: sound.cpp:411
std::shared_ptr< music_track > get_current_track()
Definition: sound.cpp:207
logger & info()
Definition: log.cpp:91
void set_UI_volume(int vol)
Definition: sound.cpp:1119
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:564
Audio output for sound and music.
Definition: sound.cpp:40
void play_music_once(const std::string &file)
Definition: sound.cpp:602
void write_music_play_list(config &snapshot)
Definition: sound.cpp:851
void reposition_sound(int id, unsigned int distance)
Definition: sound.cpp:861
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
Definition: sound.cpp:1020
uint16_t format
Definition: sound.hpp:43
bool init_sound()
Definition: sound.cpp:442
void reset_sound()
Definition: sound.cpp:525
void set_bell_volume(int vol)
Definition: sound.cpp:1107
void process(int mousex, int mousey)
Definition: tooltips.cpp:193
void stop_UI_sound()
Definition: sound.cpp:591
void set_previous_track(std::shared_ptr< music_track > track)
Definition: sound.cpp:215
void play_music()
Definition: sound.cpp:616
boost::optional< unsigned int > get_current_track_index()
Definition: sound.cpp:200
int get_sound_volume()
Definition: sound.cpp:1078
void set_sound_volume(int vol)
Definition: sound.cpp:1087
void set_music_volume(int vol)
Definition: sound.cpp:1067
void flush_cache()
Definition: sound.cpp:194
std::size_t i
Definition: function.cpp:933
void stop_bell()
Definition: sound.cpp:579
int get_music_volume()
Definition: sound.cpp:1058
void play_bell(const std::string &files)
Definition: sound.cpp:1035
void play_timer(const std::string &files, int loop_ticks, int fadein_ticks)
Definition: sound.cpp:1043
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:704
void play_music_repeatedly(const std::string &id)
Definition: sound.cpp:682
void play_UI_sound(const std::string &files)
Definition: sound.cpp:1051
void commit_music_changes()
Definition: sound.cpp:822
static driver_status query()
Definition: sound.cpp:430
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
std::vector< std::string > enumerate_drivers()
Definition: sound.cpp:417
void play_track(unsigned int i)
Definition: sound.cpp:628
void handle_event(const SDL_Event &) override
Definition: sound.hpp:108