From 1656242563d14fa564bab8d4bc40054ab8998553 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 27 Feb 2021 12:05:45 -0500 Subject: Added background music (defined on a per-map basis) --- src/mixer.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/mixer.h') 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: using chunk_ptr = std::unique_ptr; +class music_deleter { +public: + + void operator()(Mix_Music* music) { + Mix_FreeMusic(music); + } +}; + +using music_ptr = std::unique_ptr; + // MUST create the Renderer first! class Mixer { public: @@ -62,12 +72,38 @@ public: void stopChannel(int channel); + // name is the name of the file, not containing the extension + // ms is the time in milliseconds to fade in + void playMusic(std::string_view name, int ms = 0); + + bool isPlayingMusic() const { return !playingTrack_.empty(); } + + const std::string& getPlayingTrack() const { return playingTrack_; } + + void fadeoutMusic(int ms); + + void muteMusic(); + + void unmuteMusic(); + + bool isMusicMuted() const { return musicMuted_; } + + void pauseMusic(); + + void unpauseMusic(); + private: Mix_Chunk* getChunkByFilename(std::string filename); + Mix_Music* getMusicByName(std::string_view name); + mix_wrapper mix_; std::map sounds_; + std::map music_; + std::string playingTrack_; + int musicVolume_ = MIX_MAX_VOLUME; + bool musicMuted_ = false; }; #endif /* end of include guard: MIXER_H_6DF82000 */ -- cgit 1.4.1