1 /* -------------------------------------------------------------------- 2 EXTREME TUXRACER 3 4 Copyright (C) 2010 Extreme Tux Racer Team 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 ---------------------------------------------------------------------*/ 16 17 #ifndef AUDIO_H 18 #define AUDIO_H 19 20 #include "bh.h" 21 #include <vector> 22 #include <unordered_map> 23 24 // -------------------------------------------------------------------- 25 // class CSound 26 // -------------------------------------------------------------------- 27 28 29 struct TSound; 30 31 class CSound { 32 private: 33 std::vector<TSound*> sounds; 34 std::unordered_map<std::string, std::size_t> SoundIndex; 35 public: 36 ~CSound(); 37 bool LoadChunk(const std::string& name, const std::string& filename); 38 void LoadSoundList(); 39 std::size_t GetSoundIdx(const std::string& name) const; 40 41 void SetVolume(std::size_t soundid, int volume); 42 void SetVolume(const std::string& name, int volume); 43 44 void Play(std::size_t soundid, bool loop); 45 void Play(const std::string& name, bool loop); 46 void Play(std::size_t soundid, bool loop, int volume); 47 void Play(const std::string& name, bool loop, int volume); 48 49 void Halt(std::size_t soundid); 50 void Halt(const std::string& name); 51 void HaltAll(); 52 53 void FreeSounds(); 54 }; 55 56 // -------------------------------------------------------------------- 57 // class CMusic 58 // -------------------------------------------------------------------- 59 60 enum ESituation { 61 MUS_RACING = 0, 62 MUS_WONRACE = 1, 63 MUS_LOSTRACE = 2, 64 SITUATION_COUNT 65 }; 66 67 namespace sf { 68 class Music; 69 }; 70 71 class CMusic { 72 private: 73 std::vector<sf::Music*> musics; 74 std::unordered_map<std::string, std::size_t> MusicIndex; 75 76 struct Situation { sf::Music* situation[SITUATION_COUNT]; }; 77 std::vector<Situation> themes; 78 std::unordered_map<std::string, std::size_t> ThemesIndex; 79 80 sf::Music* curr_music; // current music piece 81 int curr_volume; 82 83 bool Play(sf::Music* music, bool loop, int volume); 84 public: 85 CMusic(); 86 ~CMusic(); 87 88 bool LoadPiece(const std::string& name, const std::string& filename); 89 void LoadMusicList(); 90 std::size_t GetMusicIdx(const std::string& name) const; 91 std::size_t GetThemeIdx(const std::string& theme) const; 92 93 void SetVolume(int volume); 94 bool Play(std::size_t musid, bool loop); 95 bool Play(const std::string& name, bool loop); 96 bool Play(std::size_t musid, bool loop, int volume); 97 bool Play(const std::string& name, bool loop, int volume); 98 bool PlayTheme(std::size_t theme, ESituation situation); 99 void Halt(); 100 void FreeMusics(); 101 }; 102 103 // -------------------------------------------------------------------- 104 105 extern CMusic Music; 106 extern CSound Sound; 107 108 #endif 109