//
//  AudioEngine.hpp
//  Meteor
//
//  Created by Cesar Parent on 09/09/2015.
//  Copyright © 2015 Cesar Parent. All rights reserved.
//

#ifndef AudioEngine_hpp
#define AudioEngine_hpp

#include "../defines.h"
#include <unordered_map>
#include <string>

NS_BEGIN

/*!
 * @class           AudioEngine
 * @ingroup         Management
 * @brief           A static class that controls Audio Playback in a Meteor game.
 * @details         AudioEngine provides a staic API to play audio effects (playSound()) and play,
 *                  pause and stop music.
 *
 *                  Music and effect are cached the first time they are loaded. The cache can be
 *                  flushed using flushCache(). This is usually done when changing scenes to avoid
 *                  storing unused content in memory.
 */
class AudioEngine {
    
public:
    
    /**
     * @name        Playing Sound Effects
     * @{
     */
    
    /*!
     * @brief       Plays a sound loaded from a `wav` file.
     * @note        The first time a sound file is played, it will be loaded in the cache for later
     *              reuse. The cache can be flushed using flushCache().
     * @param       filename    The name of a sound file.
     */
    static void
    playSound(const std::string& filename);
    
    /**
     * @}
     * @name        Playing And Controlling Background Music
     * @{
     */
    
    /*!
     * @brief       Plays background music loaded from a `wav` file.
     * @note        The first time a music file is played, it will be loaded in the cache for later
     *              reuse. The cache can be flushed using flushCache().
     * @param       filename    The name of a music file.
     * @param       loops       The amount of times the music should loop. Set to `-1` to loop
     *                          forever.
     */
    static void
    playMusic(const std::string& filename, int loops = 0);
    
    /*!
     * @brief       Pauses the background music if it is playing.
     */
    static void
    pauseMusic();
    
    /*!
     * @brief       Resumes the background music if it is paused.
     */
    static void
    unpauseMusic();
    
    /*!
     * @brief       Stops the background music.
     * @param       fadeout     Time over which the music fades out.
     */
    static void
    stopMusic(float fadeout = 0);
    
    /**
     * @}
     * @name        Managing the sound cache.
     * @{
     */
    
    /*!
     * @brief       Flushes the sound effect and music caches.
     * @warning     Flushing the cache will stop playback of any currently loaded music and sound
     *              effects.
     */
    static void
    flushCache();
    
    /**
     * @}
     */
    
};

NS_END


#endif /* AudioEngine_hpp */
