The Battle for Wesnoth  1.17.0-dev
sound.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
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 "events.hpp"
19 #include "sound_music_track.hpp"
20 #include <optional>
21 
22 #include <string>
23 
24 class config;
25 
26 namespace sound {
27 
35 };
36 
37 std::string current_driver();
38 std::vector<std::string> enumerate_drivers();
39 
41 {
43  int frequency;
44  uint16_t format;
45  int channels;
47 
48  static driver_status query();
49 };
50 
51 bool init_sound();
52 void close_sound();
53 void reset_sound();
54 
55 void stop_music();
56 void stop_sound();
57 void stop_UI_sound();
58 void stop_bell();
59 
60 // Read config entry, alter track list accordingly.
61 void play_music_config(const config &music_node, bool allow_interrupt_current_track = false, int i = -1);
62 // Act on any track list changes from above.
64 
65 // Play this particular music file over and over and over.
66 void play_music_repeatedly(const std::string& id);
67 // Play this particular music file once, then silence.
68 void play_music_once(const std::string& id);
69 // Empty the playlist
70 void empty_playlist();
71 // Start playing current music.
72 void play_music();
73 
74 // Change parameters of a playing sound, given its id
75 void reposition_sound(int id, unsigned int distance);
76 #define DISTANCE_SILENT 255
77 
78 // Check if there's a sound associated with given id playing
79 bool is_sound_playing(int id);
80 
81 // Stop sound associated with a given id
82 void stop_sound(int id);
83 
84 // Play sound, or random one of comma-separated sounds.
85 void play_sound(const std::string& files, channel_group group = SOUND_FX, unsigned int repeats = 0);
86 
87 // Play sound, or random one of comma-separated sounds. Use specified
88 // distance and associate it with specified id (of a sound source).
89 void play_sound_positioned(const std::string &files, int id, int repeats, unsigned int distance);
90 
91 // Play sound, or random one of comma-separated sounds in bell channel
92 void play_bell(const std::string& files);
93 
94 // Play sound, or random one of comma-separated sounds in timer channel
95 void play_timer(const std::string& files, int loop_ticks, int fadein_ticks);
96 
97 // Play user-interface sound, or random one of comma-separated sounds.
98 void play_UI_sound(const std::string& files);
99 
100 // A class to periodically check for new music that needs to be played
103 };
104 
105 // A class to mute music when the game is in background
107 public:
108  music_muter();
109  void handle_event(const SDL_Event&) override {}
110  void handle_window_event(const SDL_Event& event) override;
111 };
112 
113 // Save music playlist for snapshot
114 void write_music_play_list(config& snapshot);
115 
116 int get_music_volume();
117 int get_sound_volume();
118 void set_music_volume(int vol);
119 void set_sound_volume(int vol);
120 void set_bell_volume(int vol);
121 void set_UI_volume(int vol);
122 
123 std::optional<unsigned int> get_current_track_index();
124 std::shared_ptr<sound::music_track> get_current_track();
125 std::shared_ptr<sound::music_track> get_previous_music_track();
126 void set_previous_track(std::shared_ptr<music_track>);
127 unsigned int get_num_tracks();
128 void remove_track(unsigned int i);
129 void play_track(unsigned int i);
130 
131 void flush_cache();
132 
133 }
void empty_playlist()
Definition: sound.cpp:612
void close_sound()
Definition: sound.cpp:495
unsigned int get_num_tracks()
Definition: sound.cpp:221
bool is_sound_playing(int id)
Definition: sound.cpp:878
void play_sound_positioned(const std::string &files, int id, int repeats, unsigned int distance)
Definition: sound.cpp:1028
void stop_music()
Definition: sound.cpp:557
channel_group
Definition: sound.hpp:28
std::string current_driver()
Definition: sound.cpp:412
std::shared_ptr< music_track > get_current_track()
Definition: sound.cpp:208
logger & info()
Definition: log.cpp:89
void set_UI_volume(int vol)
Definition: sound.cpp:1120
void remove_track(unsigned int i)
Definition: sound.cpp:246
std::shared_ptr< music_track > get_previous_music_track()
Definition: sound.cpp:212
void stop_sound()
Definition: sound.cpp:565
Audio output for sound and music.
Definition: sound.cpp:41
void play_music_once(const std::string &file)
Definition: sound.cpp:603
void write_music_play_list(config &snapshot)
Definition: sound.cpp:852
void reposition_sound(int id, unsigned int distance)
Definition: sound.cpp:862
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
Definition: sound.cpp:1021
uint16_t format
Definition: sound.hpp:44
bool init_sound()
Definition: sound.cpp:443
void reset_sound()
Definition: sound.cpp:526
void set_bell_volume(int vol)
Definition: sound.cpp:1108
void process(int mousex, int mousey)
Definition: tooltips.cpp:194
void stop_UI_sound()
Definition: sound.cpp:592
void set_previous_track(std::shared_ptr< music_track > track)
Definition: sound.cpp:216
void play_music()
Definition: sound.cpp:617
int get_sound_volume()
Definition: sound.cpp:1079
void set_sound_volume(int vol)
Definition: sound.cpp:1088
void set_music_volume(int vol)
Definition: sound.cpp:1068
void flush_cache()
Definition: sound.cpp:195
std::size_t i
Definition: function.cpp:967
void stop_bell()
Definition: sound.cpp:580
int get_music_volume()
Definition: sound.cpp:1059
void play_bell(const std::string &files)
Definition: sound.cpp:1036
void play_timer(const std::string &files, int loop_ticks, int fadein_ticks)
Definition: sound.cpp:1044
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:705
std::optional< unsigned int > get_current_track_index()
Definition: sound.cpp:201
void play_music_repeatedly(const std::string &id)
Definition: sound.cpp:683
void play_UI_sound(const std::string &files)
Definition: sound.cpp:1052
void commit_music_changes()
Definition: sound.cpp:823
static driver_status query()
Definition: sound.cpp:431
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
std::vector< std::string > enumerate_drivers()
Definition: sound.cpp:418
void play_track(unsigned int i)
Definition: sound.cpp:629
void handle_event(const SDL_Event &) override
Definition: sound.hpp:109