1 #pragma once
2 
3 namespace Ogre  {  class FileStreamDataStream;  }
4 class SoundBase;  class SoundBaseMgr;
5 
6 const int MAX_SOUNDS_PER_SCRIPT = 8;  // per 1 template
7 
8 
9 ///  sound template  from .cfg to create
10 //---------------------------------------------------------------------------------------
11 class SoundTemplate
12 {
13 	friend class SoundMgr;
14 	friend class Sound;
15 
16 public:
17 	SoundTemplate(Ogre::String name, Ogre::String filename);
18 
19 private:
20 	bool setParameter(Ogre::StringVector vec);
21 
22 	Ogre::String name, file_name;
23 
24 	bool  has_start, has_stop;
25 	bool  unpitchable;
26 
27 	Ogre::String sound_names[MAX_SOUNDS_PER_SCRIPT];
28 	float        sound_pitches[MAX_SOUNDS_PER_SCRIPT];
29 	Ogre::String start_name, stop_name;
30 
31 	int   free_sound;
32 };
33 
34 
35 ///  Sound instance
36 //---------------------------------------------------------------------------------------
37 class Sound
38 {
39 	friend class SoundMgr;
40 
41 public:
42 	Sound(int car, SoundTemplate* tpl, SoundBaseMgr* mgr);
43 	~Sound();
44 
45 	void setGain(float value);
46 	void setPitch(float value);
47 	void setPosition(Ogre::Vector3 pos, Ogre::Vector3 velocity);
48 
49 	bool isAudible();
50 	void start(), stop(), kill();
51 	bool is2D;  // hud sounds, no distance attenuation
52 	void set2D(bool b), setEngine(bool b);
53 
54 	void seek(float pos);
55 	void runOnce();
56 	void setEnabled(bool e);
57 
58 private:
59 	SoundTemplate* templ;
60 	SoundBaseMgr* sound_mgr;
61 
62 	SoundBase* start_sound, *stop_sound;
63 	SoundBase* sounds[MAX_SOUNDS_PER_SCRIPT];
64 
65 	float pitch_gain[MAX_SOUNDS_PER_SCRIPT];
66 	float lastgain;
67 
68 	int car;  //  number of the car this is for
69 	bool engine;
70 };
71 
72 
73 ///  Sounds manager
74 //---------------------------------------------------------------------------------------
75 class SoundMgr
76 {
77 public:
78 	SoundMgr();
79 	~SoundMgr();
80 	bool Init(std::string snd_device, bool reverb);
81 
82 	void parseScript(Ogre::FileStreamDataStream* stream);  // sounds.cfg
83 
84 	Sound* createInstance(Ogre::String templatename, int car);  // new Sound
85 
86 	void setPaused(bool mute);
87 	void setMasterVolume(float vol);
88 
89 	void setCamera(Ogre::Vector3 position, Ogre::Vector3 direction, Ogre::Vector3 up, Ogre::Vector3 velocity);
isDisabled()90 	bool isDisabled() {  return disabled;  }
91 
92 	SoundBaseMgr* sound_mgr;
93 
94 private:
95 	SoundTemplate* createTemplate(Ogre::String name, Ogre::String filename);
96 	void skipToNextCloseBrace(Ogre::FileStreamDataStream* chunk);
97 	void skipToNextOpenBrace(Ogre::FileStreamDataStream* chunk);
98 
99 	bool disabled;
100 
101 	std::map <Ogre::String, SoundTemplate*> templates;
102 	std::vector<SoundTemplate*> v_templ;  // to delete
103 };
104