/*
  Copyright (C) 2010-2011  Charles Pence <charles@charlespence.net>
  Copyright (C) 1996-1997  Id Software, Inc.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOUND_SAMPLE_H__
#define SOUND_SAMPLE_H__

namespace sound
{

class Sample
{
    //
    // Sample management (load and retrieve via index)
    //
    
public:
    typedef boost::shared_ptr<Sample> Pointer;

private:
    typedef std::vector<Pointer> SampleList;
    static SampleList samples_;
    static boost::mutex sample_lock_;

public:
    // Load a sample, returning the sample index
    static unsigned Load(const std::string &samplename);
    
    // Return the sample for this index
    static Pointer Get(unsigned index);
        
    
    //
    // Sample data
    //
    
public:
    inline Mix_Chunk *chunk() const { return chunk_; }
    inline bool looping() const { return loop_position_ != -1; }
    inline int loop_position() const { return loop_position_; }
    
private:
    std::string name_;
    
    Mix_Chunk *chunk_;    
    int loop_position_;
    
    
    //
    // Utility: looping file support
    //
    
private:
    static bool loops_loaded_;
    static boost::unordered_map<std::string, int> loops_;
    
    static void LoadLoopFile();
};

}

#endif /* SOUND_SAMPLE_H__ */
