]> git.lizzy.rs Git - dragonfireclient.git/blob - src/sound.h
Translated using Weblate (German)
[dragonfireclient.git] / src / sound.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef SOUND_HEADER
21 #define SOUND_HEADER
22
23 #include <set>
24 #include <string>
25 #include "irrlichttypes_bloated.h"
26
27 class OnDemandSoundFetcher
28 {
29 public:
30         virtual void fetchSounds(const std::string &name,
31                         std::set<std::string> &dst_paths,
32                         std::set<std::string> &dst_datas) = 0;
33 };
34
35 struct SimpleSoundSpec
36 {
37         SimpleSoundSpec(const std::string &name = "", float gain = 1.0, float fade = 0.0)
38             : name(name), gain(gain), fade(fade)
39         {
40         }
41
42         bool exists() const { return name != ""; }
43
44         std::string name;
45         float gain;
46         float fade;
47 };
48
49 class ISoundManager
50 {
51 public:
52         virtual ~ISoundManager() {}
53         // Multiple sounds can be loaded per name; when played, the sound
54         // should be chosen randomly from alternatives
55         // Return value determines success/failure
56         virtual bool loadSoundFile(
57                         const std::string &name, const std::string &filepath) = 0;
58         virtual bool loadSoundData(
59                         const std::string &name, const std::string &filedata) = 0;
60
61         virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
62         virtual void setListenerGain(float gain) = 0;
63
64         // playSound functions return -1 on failure, otherwise a handle to the
65         // sound. If name=="", call should be ignored without error.
66         virtual int playSound(const std::string &name, bool loop, float volume,
67                         float fade = 0) = 0;
68         virtual int playSoundAt(
69                         const std::string &name, bool loop, float volume, v3f pos) = 0;
70         virtual void stopSound(int sound) = 0;
71         virtual bool soundExists(int sound) = 0;
72         virtual void updateSoundPosition(int sound, v3f pos) = 0;
73         virtual bool updateSoundGain(int id, float gain) = 0;
74         virtual float getSoundGain(int id) = 0;
75         virtual void step(float dtime) = 0;
76         virtual void fadeSound(int sound, float step, float gain) = 0;
77
78         int playSound(const SimpleSoundSpec &spec, bool loop)
79         {
80                 return playSound(spec.name, loop, spec.gain, spec.fade);
81         }
82         int playSoundAt(const SimpleSoundSpec &spec, bool loop, v3f pos)
83         {
84                 return playSoundAt(spec.name, loop, spec.gain, pos);
85         }
86 };
87
88 class DummySoundManager : public ISoundManager
89 {
90 public:
91         virtual bool loadSoundFile(const std::string &name, const std::string &filepath)
92         {
93                 return true;
94         }
95         virtual bool loadSoundData(const std::string &name, const std::string &filedata)
96         {
97                 return true;
98         }
99         void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
100         void setListenerGain(float gain) {}
101         int playSound(const std::string &name, bool loop, float volume, float fade)
102         {
103                 return 0;
104         }
105         int playSoundAt(const std::string &name, bool loop, float volume, v3f pos)
106         {
107                 return 0;
108         }
109         void stopSound(int sound) {}
110         bool soundExists(int sound) { return false; }
111         void updateSoundPosition(int sound, v3f pos) {}
112         bool updateSoundGain(int id, float gain) { return false; }
113         float getSoundGain(int id) { return 0; }
114         void step(float dtime) {}
115         void fadeSound(int sound, float step, float gain) {}
116 };
117
118 // Global DummySoundManager singleton
119 extern DummySoundManager dummySoundManager;
120
121 #endif