00001 #ifndef _SONG_H_
00002 #define _SONG_H_
00003
00004 #include "ISound.h"
00005
00006 #define MAX_TRACKS 3
00007 #define MAX_BARS 20
00008 #define BAR_LENGTH 4.0f //4 is a good number as it creates 4:4 timing, to do other non 1:1 timing is more complicated
00009 #define NUM_SCALES 7
00010 #define SCALE_LENGTH 7
00011 #define VOLUME_AMPLITUDE 10000
00012
00013 typedef unsigned int UInt;
00014 typedef unsigned char Uint8;
00015 typedef short int Sint16;
00016
00017 class SongSection
00018 {
00019 public:
00020 SongSection();
00021 ~SongSection();
00022
00023 bool Initialise(const UInt &bpm, const UInt &length);
00024 Sint16* GetBuffer(const UInt &position, const int &len);
00025 void Output();
00026
00027 UInt GetSectionLength() { return m_timePerSection; }
00028
00029 enum eBarNoteLength
00030 {
00031 eOneNote = 0,
00032 eTwoNotes,
00033 eFourNotes,
00034 eEightNotes,
00035 eNumNotesTypes
00036 };
00037
00038 struct SBar
00039 {
00040 SBar() : pFrequencies(0), numFreqs(0), timePerFreq(0) {}
00041 ~SBar() { if(pFrequencies) delete[] pFrequencies; }
00042
00043 float* pFrequencies;
00044 UInt numFreqs, timePerFreq;
00045 };
00046
00047 struct STrack
00048 {
00049 STrack() : pBars(0), numBars(0), pUniqueBars(0), numUniqueBars(0) {}
00050 ~STrack() { if(pBars) delete[] pBars; if(pUniqueBars) delete[] pUniqueBars; }
00051 SBar** pBars;
00052 SBar* pUniqueBars;
00053 UInt numBars, numUniqueBars, timePerBar;
00054 };
00055
00056 protected:
00057 STrack* m_pTracks;
00058 static float* m_pTrackDegreesOnWave;
00059 UInt m_numTracks, m_timePerSection;
00060 };
00061
00062 class Song : public ISound
00063 {
00064 public:
00065 Song();
00066 ~Song();
00067
00068 void Initialise(const bool &bPreCreate, const UInt &bpm, const UInt &numUniqueSections, const UInt &lengthInSections, const UInt &timePerSection);
00069 void Output();
00070 virtual Sint16* GetBuffer(const UInt &position, const int &len, bool isLooping = false);
00071
00072 protected:
00073 Sint16* GetDynamicBuffer(const UInt &pos, const int &len);
00074 char* m_name;
00075
00076 bool m_bIsPreCreated;
00077 UInt m_lastBufferRequested;
00078 Sint16** m_pSongData;
00079 UInt m_numSampleSets;
00080
00081 SongSection** m_pSongSections;
00082 SongSection* m_pUniqueSections;
00083 UInt m_numSections, m_length, m_timePerSection, m_bpm, m_lastPointPlayed;
00084 };
00085
00086 #endif