Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSSample.h

Go to the documentation of this file.
00001 #ifndef CSSample_h
00002 #define CSSample_h
00003 
00004 #include <string>
00005 #include <vector>
00006 #include <map>
00007 #include "SDLMain.h"
00008 #include "CSLoadable.h"
00009 #include "CSLog.h"
00010 
00011 #ifdef WIN32
00012 #pragma warning(disable : 4786 )
00013 #endif
00014 
00015 class CSSample;
00016 class CSSampleLoader;
00017 
00018 typedef std::vector<CSSample *> CSSamples;
00019 typedef std::map<int, CSSample *> CSSampleMap;
00020 
00021 class CSSampleData
00022 {
00023     public:
00024         char *id;
00025         char *filename;     // of bitmap file
00026 
00027         CSSampleData()
00028         {
00029             id = 0;
00030             filename = 0;
00031         }
00032 
00033         ~CSSampleData()
00034         {
00035             if (id != 0) 
00036             {
00037                 free(id);
00038                 id = 0;
00039             }
00040             if (filename != 0) 
00041             {
00042                 free(filename);
00043                 filename = 0;
00044             }
00045         }
00046 };
00047 
00048 class CSSample
00049 {
00050     friend CSSampleLoader;
00051     private:
00052         static CSSampleMap *mAllPlayingSamples;
00053         static bool mLock;
00054         static int mIsInit;
00055         Mix_Chunk *mSample;
00056         int mChannel;
00057 
00058         // constructor using name
00059         CSSample(const std::string &filename);
00060         void initialize(const CSSampleData &data);
00061         static void loadSampleData(const std::string &filename, CSSampleData &data);
00062 
00063     public:
00064         // copy constructor
00065         CSSample(const CSSample &Sample);
00066 
00067         // destructor
00068         virtual ~CSSample();    
00069 
00070         static const char *CLASS;
00071         virtual std::string getType() {return (std::string) CLASS;}
00072 
00073         void play();    
00074         void stop();    
00075         void pause();   
00076         void resume();  
00077 
00078         static void pauseAll();
00079         static void resumeAll();
00080         static void channel_finished(int channel);
00081         static void addCallback(int channel, CSSample *sample);
00082         static void removeCallback(int channel);
00083         static void init();
00084         static void deinit();
00085         static bool isPlaying();
00086 };
00087 
00088 // factory - class
00089 // that is used to create CSSample
00090 class CSSampleLoader : public Loadable<CSSample>
00091 {
00092     protected:
00093         virtual CSSample *create(const std::string &filename)
00094         {
00095             return new CSSample(filename);
00096         }
00097 
00098     public:
00099         static CSSampleLoader INSTANCE;
00100 };
00101 
00102 
00103 #endif // CSSample_h

Generated on Wed Jul 14 00:43:42 2004 for CSLib by doxygen 1.3.6