summary refs log tree commit diff stats
path: root/src/mixer.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-27 12:05:45 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-27 12:05:45 -0500
commit1656242563d14fa564bab8d4bc40054ab8998553 (patch)
tree872589408ac7aef54b1959dc53b946fbed9dfcaa /src/mixer.h
parente644f5c0d769989bd3b0665312c6949d76f5e388 (diff)
downloadtanetane-1656242563d14fa564bab8d4bc40054ab8998553.tar.gz
tanetane-1656242563d14fa564bab8d4bc40054ab8998553.tar.bz2
tanetane-1656242563d14fa564bab8d4bc40054ab8998553.zip
Added background music (defined on a per-map basis)
Diffstat (limited to 'src/mixer.h')
-rw-r--r--src/mixer.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mixer.h b/src/mixer.h index 7f6ef72..b049118 100644 --- a/src/mixer.h +++ b/src/mixer.h
@@ -52,6 +52,16 @@ public:
52 52
53using chunk_ptr = std::unique_ptr<Mix_Chunk, chunk_deleter>; 53using chunk_ptr = std::unique_ptr<Mix_Chunk, chunk_deleter>;
54 54
55class music_deleter {
56public:
57
58 void operator()(Mix_Music* music) {
59 Mix_FreeMusic(music);
60 }
61};
62
63using music_ptr = std::unique_ptr<Mix_Music, music_deleter>;
64
55// MUST create the Renderer first! 65// MUST create the Renderer first!
56class Mixer { 66class Mixer {
57public: 67public:
@@ -62,12 +72,38 @@ public:
62 72
63 void stopChannel(int channel); 73 void stopChannel(int channel);
64 74
75 // name is the name of the file, not containing the extension
76 // ms is the time in milliseconds to fade in
77 void playMusic(std::string_view name, int ms = 0);
78
79 bool isPlayingMusic() const { return !playingTrack_.empty(); }
80
81 const std::string& getPlayingTrack() const { return playingTrack_; }
82
83 void fadeoutMusic(int ms);
84
85 void muteMusic();
86
87 void unmuteMusic();
88
89 bool isMusicMuted() const { return musicMuted_; }
90
91 void pauseMusic();
92
93 void unpauseMusic();
94
65private: 95private:
66 96
67 Mix_Chunk* getChunkByFilename(std::string filename); 97 Mix_Chunk* getChunkByFilename(std::string filename);
68 98
99 Mix_Music* getMusicByName(std::string_view name);
100
69 mix_wrapper mix_; 101 mix_wrapper mix_;
70 std::map<std::string, chunk_ptr> sounds_; 102 std::map<std::string, chunk_ptr> sounds_;
103 std::map<std::string, music_ptr> music_;
104 std::string playingTrack_;
105 int musicVolume_ = MIX_MAX_VOLUME;
106 bool musicMuted_ = false;
71}; 107};
72 108
73#endif /* end of include guard: MIXER_H_6DF82000 */ 109#endif /* end of include guard: MIXER_H_6DF82000 */