Planeshift

songstream.h

Go to the documentation of this file.
00001 /*
00002  * songstream.h, Author: Andrea Rizzi <[email protected]>
00003  *
00004  * Copyright (C) 2001-2011 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef SONGSTREAM_H
00021 #define SONGSTREAM_H
00022 
00023 
00024 //====================================================================================
00025 // Crystal Space Includes
00026 //====================================================================================
00027 #include <cssysdef.h>
00028 #include <csutil/ref.h>
00029 #include <csutil/randomgen.h>
00030 #include <csplugincommon/sndsys/sndstream.h>
00031 
00032 //------------------------------------------------------------------------------------
00033 // Forward Declarations
00034 //------------------------------------------------------------------------------------
00035 class Instrument;
00036 class SndSysSongData;
00037 struct SongData;
00038 struct csSndSysSoundFormat;
00039 
00040 using namespace CS::SndSys;
00041 
00042 class SndSysSongStream: public SndSysBasicStream
00043 {
00044 public:
00045     SndSysSongStream(csRef<SndSysSongData> soundData, SongData* songData, csSndSysSoundFormat* renderFormat, int mode3D);
00046     virtual ~SndSysSongStream();
00047 
00048     // From iSndSysStream
00049     //--------------------
00050     virtual void AdvancePosition(size_t frameDelta);
00051     virtual const char* GetDescription();
00052     virtual size_t GetFrameCount();
00053 
00054     // SndSysBasicStream overriding
00055     //------------------------------
00056     virtual bool AlwaysStream() const { return true; }
00057     virtual bool ResetPosition();
00058     virtual bool SetPosition(size_t newPosition) { return false; } // not supported
00059     virtual bool SetLoopBoundaries(size_t startPosition, size_t endPosition) { return false; } // not supported
00060 
00061 private:
00062     bool isFinished;                    
00063     size_t currentMeasure;              
00064     size_t currentNote;                 
00065 
00066     size_t lastRepeatStart;             
00067     size_t lastRepeatEnd;               
00068     int repeatCounter;                  
00069     csArray<uint> repeatsDone;          
00070     char* copyNoteBuffer;               
00071     size_t lastNoteSize;                
00072 
00073     SongData* songData;                 
00074     float timePerDivision;              
00075     csRef<SndSysSongData> soundData;    
00076 
00077     int conversionFactor;               
00078     bool conversionNeeded;              
00079 
00086     bool CheckPlaybackReadComplete();
00087 
00097     bool GetNextChord(char* &noteBuffer, size_t &noteBufferSize);
00098 
00108     void AdjustAlteration(char pitch, int &alter);
00109 
00118     void CopyNoteIntoBuffer(char* noteBuffer, size_t noteBufferSize);
00119 };
00120 
00121 #endif /* SONGSTREAM_H */