Debian Codegraph @

include/isound.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include "ideclmanager.h"
5 #include "igameresource.h"
6
7 #include <vector>
8 #include <functional>
9
10 // A list of sound files associated to a shader
11 typedef std::vector<std::string> SoundFileList;
12
13 constexpr float METERS_PER_UNIT = 0.0254f;
14 constexpr float UNITS_PER_METER = 1/METERS_PER_UNIT;
15
16 // The min and max radii of a sound shader
17 class SoundRadii {
18 float minRad, maxRad;
19 public:
20 //set sound radii either in metres or in inch on initialization might cause a conversion
21 SoundRadii (float min = 0, float max = 0, bool inMetres = false) {
22 if (inMetres) {
23 minRad = min * UNITS_PER_METER;
24 maxRad = max * UNITS_PER_METER;
25 }
26 else {
27 minRad = min;
28 maxRad = max;
29 }
30 }
31
32 // set the sound radii in metres or in inch, might cause a conversion
33 void setMin(float min, bool inMetres = false) {
34 if (inMetres) {
35 minRad = min * UNITS_PER_METER;
36 }
37 else {
38 minRad = min;
39 }
40 }
41
42 void setMax (float max, bool inMetres = false) {
43 if (inMetres) {
44 maxRad = max * UNITS_PER_METER;
45 }
46 else {
47 maxRad = max;
48 }
49 }
50
51 float getMin(bool inMetres = false) const {
52 return (inMetres) ? minRad * METERS_PER_UNIT : minRad;
53 }
54
55 float getMax(bool inMetres = false) const {
56 return (inMetres) ? maxRad * METERS_PER_UNIT : maxRad;
57 }
58 };
59
60 /// Representation of a single sound or sound shader.
61 class ISoundShader :
62 public decl::IDeclaration
63 {
64 public:
65 virtual ~ISoundShader() {}
66
67 using Ptr = std::shared_ptr<ISoundShader>;
68
69 /// Get the min and max radii of the shader
70 virtual SoundRadii getRadii() = 0;
71
72 /// Get the list of sound files associated to this shader
73 virtual SoundFileList getSoundFileList() = 0;
74
75 // angua: get the display folder for sorting the sounds in the sound chooser window
76 virtual const std::string& getDisplayFolder() = 0;
77 };
78
79 constexpr const char* const MODULE_SOUNDMANAGER("SoundManager");
80
81 /// Sound manager interface.
82 class ISoundManager :
83 public RegisterableModule
84 {
85 public:
86 /// Invoke a function for each sound shader
87 virtual void forEachShader(std::function<void(const ISoundShader::Ptr&)>) = 0;
88
89 /** greebo: Tries to lookup the SoundShader with the given name,
90 * returns a soundshader with an empty name, if the lookup failed.
91 */
92 virtual ISoundShader::Ptr getSoundShader(const std::string& shaderName) = 0;
93
94 /**
95 * greebo: Plays the given sound file (defined by its VFS path).
96 *
97 * @returns: TRUE, if the sound file was found at the given VFS path,
98 * FALSE otherwise
99 */
100 virtual bool playSound(const std::string& fileName) = 0;
101
102 /**
103 * greebo: Plays the given sound file (defined by its VFS path).
104 * Will loop the sound if the given flag is set to TRUE.
105 *
106 * @returns: TRUE, if the sound file was found at the given VFS path,
107 * FALSE otherwise
108 */
109 virtual bool playSound(const std::string& fileName, bool loopSound) = 0;
110
111 /** greebo: Stops the currently played sound.
112 */
113 virtual void stopSound() = 0;
114
115 // Returns the duration of the given sound file in seconds
116 // Will throw a std::out_of_range exception if the path cannot be resolved
117 virtual float getSoundFileDuration(const std::string& vfsPath) = 0;
118
119 // Reloads all sound shader definitions from the VFS
120 virtual void reloadSounds() = 0;
121 };
122
123 inline ISoundManager& GlobalSoundManager()
124 {
125 static module::InstanceReference<ISoundManager> _reference(MODULE_SOUNDMANAGER);
126 return _reference;
127 }