From: <pst...@us...> - 2008-03-30 14:35:34
|
Revision: 368 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=368&view=rev Author: pstieber Date: 2008-03-30 07:35:30 -0700 (Sun, 30 Mar 2008) Log Message: ----------- 1. Renamed the following classes to match the new coding style: tReadBase -> JZReadBase tWriteBase -> JZWriteBase tStdChunk -> JZStandardChunk tStdRead -> JZStandardRead tStdWrite -> JZStandardWrite 2. Added constructors for JZReadBase and JZWriteBase so data members could be initialized. 3. Separated JZReadBase and JZWriteBase inline member function definitions from the declarations. 4. Prefixed JZReadBase and JZWriteBase data members with m to match the new coding style, and made them protected. 5. Added JZReadBase::GetTicksPerQuarter so the mTicksPerQuarter data member could be made protected instead of public. 6. Moved the JZStandardChunk declaration from the header to the source file because no other code uses it. 7. Changed the file name argument of JZStandardWrite::Open from char* to const char* to match the virtual base class version. Prior to this change the base class version was incorrectly called when used in a polymorphic manner. 8. Changed some local variable names to match the new coding style. 9. Made some cosmetic indentation changes. Modified Paths: -------------- trunk/jazz/src/Events.cpp trunk/jazz/src/Events.h trunk/jazz/src/Project.cpp trunk/jazz/src/Song.cpp trunk/jazz/src/Song.h trunk/jazz/src/StandardFile.cpp trunk/jazz/src/StandardFile.h trunk/jazz/src/Track.cpp trunk/jazz/src/Track.h Modified: trunk/jazz/src/Events.cpp =================================================================== --- trunk/jazz/src/Events.cpp 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Events.cpp 2008-03-30 14:35:30 UTC (rev 368) @@ -41,16 +41,31 @@ //***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int tReadBase::Open(const char* pFileName) +JZReadBase::JZReadBase() + : mTicksPerQuarter(0), + mTrackCount(0), + mpFd(NULL) { +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZReadBase::~JZReadBase() +{ +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZReadBase::Open(const char* pFileName) +{ if (pFileName == NULL) { - fd = stdin; + mpFd = stdin; } else { - fd = fopen(pFileName, "rb"); - if (fd == NULL) + mpFd = fopen(pFileName, "rb"); + if (mpFd == NULL) { ostringstream Oss; Oss << "Error opening file " << pFileName; @@ -63,11 +78,11 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void tReadBase::Close() +void JZReadBase::Close() { - if (fd != stdin) + if (mpFd != stdin) { - fclose(fd); + fclose(mpFd); } } @@ -75,11 +90,27 @@ //***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int tWriteBase::Open(const char* pFileName, int nTracks, int TicksPerQuarter) +JZWriteBase::JZWriteBase() + : mpFd(NULL) { +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZWriteBase::~JZWriteBase() +{ +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZWriteBase::Open( + const char* pFileName, + int TrackCount, + int TicksPerQuarter) +{ if (pFileName == NULL) { - fd = stdout; + mpFd = stdout; } else { @@ -98,8 +129,8 @@ delete syscmd; } #endif - fd = fopen(pFileName, "wb"); - if (fd == NULL) + mpFd = fopen(pFileName, "wb"); + if (mpFd == NULL) { ostringstream Oss; Oss << "Error opening file " << pFileName; @@ -107,16 +138,16 @@ return 0; } } - return nTracks; + return TrackCount; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void tWriteBase::Close() +void JZWriteBase::Close() { - if (fd != stdout) + if (mpFd != stdout) { - fclose(fd); + fclose(mpFd); } } Modified: trunk/jazz/src/Events.h =================================================================== --- trunk/jazz/src/Events.h 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Events.h 2008-03-30 14:35:30 UTC (rev 368) @@ -33,113 +33,183 @@ // - Ascii-File // - Midi-Port //***************************************************************************** - -class tReadBase +class JZReadBase { public: - virtual ~tReadBase() - { - } + JZReadBase(); - // Ths value is known after a call to Open. - int TicksPerQuarter; + virtual ~JZReadBase(); - int nTracks; - virtual int Open(const char* pFileName); virtual void Close(); + int GetTicksPerQuarter() const; + virtual JZEvent* Read() = 0; virtual int NextTrack() = 0; protected: - FILE* fd; + // Ths value is known after a call to Open. + int mTicksPerQuarter; + + int mTrackCount; + + FILE* mpFd; }; +//***************************************************************************** +// Description: +// These are the read base class inline member functions. +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZReadBase::GetTicksPerQuarter() const +{ + return mTicksPerQuarter; +} -class tWriteBase +//***************************************************************************** +//***************************************************************************** +class JZWriteBase { public: - virtual ~tWriteBase() - { - } + JZWriteBase(); - virtual int Open(const char* pFileName, int nTracks, int TicksPerQuarter); + virtual ~JZWriteBase(); + virtual int Open( + const char* pFileName, + int TrackCount, + int TicksPerQuarter); + virtual void Close(); - virtual int Write(JZEvent* pEvent) - { - return Write(pEvent, 0, 0); - } + virtual int Write(JZEvent* pEvent); - virtual int Write(JZEvent* pEvent, unsigned char Character) - { - return Write(pEvent, &Character, 1); - } + virtual int Write(JZEvent* pEvent, unsigned char Character); virtual int Write( JZEvent* pEvent, unsigned char Character1, - unsigned char Character2) - { - unsigned char Array[2]; - Array[0] = Character1; - Array[1] = Character2; - return Write(pEvent, Array, 2); - } + unsigned char Character2); virtual int Write( JZEvent* pEvent, unsigned char Character1, unsigned char Character2, - unsigned char Character3) - { - unsigned char Array[3]; - Array[0] = Character1; - Array[1] = Character2; - Array[2] = Character3; - return Write(pEvent, Array, 3); - } + unsigned char Character3); virtual int Write( JZEvent* pEvent, unsigned char Character1, unsigned char Character2, unsigned char Character3, - unsigned char Character4) - { - unsigned char Array[4]; - Array[0] = Character1; - Array[1] = Character2; - Array[2] = Character3; - Array[3] = Character4; - return Write(pEvent, Array, 4); - } + unsigned char Character4); - virtual int Write(JZEvent* pEvent, unsigned char* pString, int Length) = 0; + virtual int Write( + JZEvent* pEvent, + unsigned char* pString, + int Length) = 0; - virtual void NextTrack() - { - } + virtual void NextTrack(); protected: - FILE* fd; + FILE* mpFd; }; +//***************************************************************************** +// Description: +// These are the write base class inline member functions. +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZWriteBase::Write(JZEvent* pEvent) +{ + return Write(pEvent, 0, 0); +} -// -------------------------------------------------------------------------- -// tGetMidiBytes -// -------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZWriteBase::Write(JZEvent* pEvent, unsigned char Character) +{ + return Write(pEvent, &Character, 1); +} -class tGetMidiBytes : public tWriteBase +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZWriteBase::Write( + JZEvent* pEvent, + unsigned char Character1, + unsigned char Character2) { + unsigned char Array[2]; + + Array[0] = Character1; + Array[1] = Character2; + + return Write(pEvent, Array, 2); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZWriteBase::Write( + JZEvent* pEvent, + unsigned char Character1, + unsigned char Character2, + unsigned char Character3) +{ + unsigned char Array[3]; + + Array[0] = Character1; + Array[1] = Character2; + Array[2] = Character3; + + return Write(pEvent, Array, 3); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZWriteBase::Write( + JZEvent* pEvent, + unsigned char Character1, + unsigned char Character2, + unsigned char Character3, + unsigned char Character4) +{ + unsigned char Array[4]; + + Array[0] = Character1; + Array[1] = Character2; + Array[2] = Character3; + Array[3] = Character4; + + return Write(pEvent, Array, 4); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZWriteBase::NextTrack() +{ +} + +//***************************************************************************** +// tGetMidiBytes +//***************************************************************************** +class tGetMidiBytes : public JZWriteBase +{ public: int Open(const char* pFileName, int nTracks, int TicksPerQuarter) @@ -348,7 +418,7 @@ virtual tEndOfTrack* IsEndOfTrack() { edb(); return 0; } virtual tChnPressure* IsChnPressure() { edb(); return 0; } - virtual int Write(tWriteBase& io) + virtual int Write(JZWriteBase& io) { edb(); return io.Write(this); @@ -470,7 +540,7 @@ OffVeloc = 0; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Key, Veloc); } @@ -500,7 +570,7 @@ OffVeloc = veloc; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Key, OffVeloc); } @@ -528,7 +598,7 @@ Value = val; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { int v = Value + 8192; edb(); return io.Write(this, (unsigned char)(v & 0x7F), (unsigned char)(v >> 7)); @@ -559,7 +629,7 @@ Value = val; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Control, Value); } @@ -584,7 +654,7 @@ Program = prg; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Program); } @@ -621,7 +691,7 @@ delete [] Data; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Data, Length); } @@ -931,7 +1001,7 @@ this->eventlength=eventlength; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { Data = new unsigned char [Length + 1]; @@ -997,7 +1067,7 @@ virtual int GetPitch() { edb(); return GetBPM() / 2; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, (char)(uSec >> 16), (char)(uSec >> 8), (char)uSec); } @@ -1042,7 +1112,7 @@ Quarter = Character4; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Numerator, Denomiator, Clocks, Quarter); } @@ -1068,7 +1138,7 @@ { } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this); } @@ -1092,7 +1162,7 @@ Minor = Character2; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Sharps, Minor); } @@ -1114,7 +1184,7 @@ Key = key; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Key, Value); } @@ -1139,7 +1209,7 @@ Value = val; } - virtual int Write(tWriteBase &io) + virtual int Write(JZWriteBase &io) { edb(); return io.Write(this, Value); } Modified: trunk/jazz/src/Project.cpp =================================================================== --- trunk/jazz/src/Project.cpp 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Project.cpp 2008-03-30 14:35:30 UTC (rev 368) @@ -310,8 +310,8 @@ if (fd) { fclose(fd); - tStdRead io; - Read(io, gpStartUpSong.c_str()); + JZStandardRead Io; + Read(Io, gpStartUpSong.c_str()); // if (gpStartUpSong == string("jazz.mid")) // { // lasts = gpStartUpSong; @@ -505,7 +505,7 @@ //----------------------------------------------------------------------------- void JZProject::OpenSong(const wxString& SongFileName) { - tStdRead Io; + JZStandardRead Io; Clear(); Read(Io, SongFileName); mpConfig->Put(C_StartUpSong, SongFileName.c_str()); @@ -522,7 +522,7 @@ //----------------------------------------------------------------------------- void JZProject::Save(const wxString& SongFileName) { - tStdWrite Io; + JZStandardWrite Io; Write(Io, SongFileName); mpConfig->Put(C_StartUpSong, SongFileName.c_str()); } Modified: trunk/jazz/src/Song.cpp =================================================================== --- trunk/jazz/src/Song.cpp 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Song.cpp 2008-03-30 14:35:30 UTC (rev 368) @@ -61,7 +61,7 @@ return mTracks[0].GetDefaultSpeed(); } -void JZSong::Read(tReadBase& Io, const char* pFileName) +void JZSong::Read(JZReadBase& Io, const char* pFileName) { int i; wxBeginBusyCursor(); @@ -75,7 +75,7 @@ mTracks[i].Read(Io); } Io.Close(); - TicksPerQuarter = Io.TicksPerQuarter; + TicksPerQuarter = Io.GetTicksPerQuarter(); if (TicksPerQuarter < 48) { @@ -97,7 +97,7 @@ } -void JZSong::Write(tWriteBase& Io, const char* pFileName) +void JZSong::Write(JZWriteBase& Io, const char* pFileName) { // Make sure track 0 has a synth reset if (!mTracks[0].Reset) Modified: trunk/jazz/src/Song.h =================================================================== --- trunk/jazz/src/Song.h 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Song.h 2008-03-30 14:35:30 UTC (rev 368) @@ -83,8 +83,8 @@ virtual ~JZSong(); void Clear(); - void Read(tReadBase& Io, const char* pFileName = 0); - void Write(tWriteBase& Io, const char* pFileName = 0); + void Read(JZReadBase& Io, const char* pFileName = 0); + void Write(JZWriteBase& Io, const char* pFileName = 0); JZTrack *GetTrack(int Nr); int GetLastClock(); Modified: trunk/jazz/src/StandardFile.cpp =================================================================== --- trunk/jazz/src/StandardFile.cpp 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/StandardFile.cpp 2008-03-30 14:35:30 UTC (rev 368) @@ -35,22 +35,24 @@ using namespace std; -// ---------------------------------------------------------------------- -// StdFile-Util -// ---------------------------------------------------------------------- - #ifdef sparc +//***************************************************************************** +//***************************************************************************** static void SwapW(void *p) { } +//***************************************************************************** +//***************************************************************************** static void SwapL(void *p) { } #else +//***************************************************************************** +//***************************************************************************** static void SwapW(void* p) { char *cp = (char *)p; @@ -59,7 +61,8 @@ cp[1] = tmp; } - +//***************************************************************************** +//***************************************************************************** static void SwapL(void* p) { short tmp, *sp = (short *)p; @@ -72,11 +75,50 @@ #endif -// -------------------------------------------------------------- +//***************************************************************************** +//***************************************************************************** +class JZStandardChunk +{ + public: + + JZStandardChunk(); + + ~JZStandardChunk(); + + int IsEof(); // Only after Load, Save never has Eof. + + void Load(FILE* fd); + + void Save(FILE* fd); // Depends on EndOfTrack + + void Put(JZEvent* pEvent, unsigned char* pData, int Length); + + // A return value of NULL indicates we are at the end of the track. + JZEvent* Get(); + + void Rewind(); + + private: + + long Size; // Size of base + long nRead; // Number of bytes read from the file + unsigned char* mpBase; // Buffer for data. + unsigned char* cp; // Aktueller Schreib/Lese pointer + long Clock; // Absolute Clock + int EofSeen; // endoftrack meta-event read + int RunningStatus; + + void Resize(int SizeNeeded); + void PutVar(unsigned long val); + unsigned long GetVar(); +}; + +//***************************************************************************** // StdChunk -// -------------------------------------------------------------- - -tStdChunk::tStdChunk() +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZStandardChunk::JZStandardChunk() : mpBase(0) { Size = 128; @@ -85,12 +127,16 @@ Rewind(); } -tStdChunk::~tStdChunk() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZStandardChunk::~JZStandardChunk() { delete [] mpBase; } -void tStdChunk::Rewind() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardChunk::Rewind() { RunningStatus = 0; cp = mpBase; @@ -98,14 +144,17 @@ Clock = 0; } - -inline void tStdChunk::Resize(int Needed) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZStandardChunk::Resize(int Needed) { long Used = cp - mpBase; long i, n = Size; if (Size - Used < Needed) { - do { + do + { Size *= 2; //mpBase = (unsigned char *)realloc(mpBase, Size); } while (Size - Used < Needed); @@ -120,14 +169,17 @@ } } - -inline int tStdChunk::IsEof() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZStandardChunk::IsEof() { return EofSeen || ((cp - mpBase) >= nRead); } - -void tStdChunk::PutVar(unsigned long val) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardChunk::PutVar(unsigned long val) { unsigned long buf; buf = val & 0x7f; @@ -148,8 +200,9 @@ } } - -unsigned long tStdChunk::GetVar() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +unsigned long JZStandardChunk::GetVar() { unsigned long val; char c; @@ -163,38 +216,40 @@ return val; } - - -void tStdChunk::Put(JZEvent *e, unsigned char* Data, int Length) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardChunk::Put(JZEvent* pEvent, unsigned char* Data, int Length) { unsigned char Stat; long dif; Resize(Length + 20); - dif = e->GetClock() - Clock; + dif = pEvent->GetClock() - Clock; PutVar(dif); Clock += dif; #if 0 -printfxxo("%02X %02X ", e->Clock, dif); -if (e->Stat != 0x90) -{ - int i; - printf("%02X ", e->Stat); - for (i = 0; i < Length; i++) - printf("%02X ", Data[i]); - putchar('\n'); -} + printfxxo("%02X %02X ", pEvent->Clock, dif); + if (pEvent->Stat != 0x90) + { + int i; + printf("%02X ", pEvent->Stat); + for (i = 0; i < Length; i++) + { + printf("%02X ", Data[i]); + } + putchar('\n'); + } #endif - switch (e->Stat) + switch (pEvent->Stat) { // KeyOff -> KeyOn mit Vel=0. Gives better Runningstatus! case StatKeyOff: // SN-- only if KeyOff veloc is zero - if (!e->IsKeyOff()->OffVeloc) + if (!pEvent->IsKeyOff()->OffVeloc) { - Stat = StatKeyOn | e->IsChannelEvent()->Channel; + Stat = StatKeyOn | pEvent->IsChannelEvent()->Channel; if (Stat != RunningStatus) { RunningStatus = Stat; @@ -205,7 +260,7 @@ } else { - Stat = StatKeyOff | e->IsChannelEvent()->Channel; + Stat = StatKeyOff | pEvent->IsChannelEvent()->Channel; if (Stat != RunningStatus) { RunningStatus = Stat; @@ -226,7 +281,7 @@ // SN++ case StatChnPressure: - Stat = e->Stat | e->IsChannelEvent()->Channel; + Stat = pEvent->Stat | pEvent->IsChannelEvent()->Channel; if (Stat != RunningStatus) { RunningStatus = Stat; @@ -268,14 +323,14 @@ if (1) { int i; - printf("%02X ", e->Stat); + printf("%02X ", pEvent->Stat); for (i = 0; i < Length; i++) printf("%02X ", Data[i]); putchar('\n'); } #endif - Stat = e->Stat; + Stat = pEvent->Stat; RunningStatus = 0; *cp++ = 0xff; *cp++ = Stat; @@ -288,15 +343,14 @@ } } - - - -JZEvent* tStdChunk::Get() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZEvent* JZStandardChunk::Get() { int len; unsigned char Stat; unsigned char Channel; - JZEvent *e = 0; + JZEvent* pEvent = 0; while (!IsEof()) { @@ -307,10 +361,10 @@ case StatSysEx: // Sysex ++ cp; len = GetVar(); - e = new tSysEx(Clock, cp, len); + pEvent = new tSysEx(Clock, cp, len); cp += len; //RunningStatus = 0; - return e; + return pEvent; case 0xff: // Meta-Event ++cp; @@ -327,75 +381,75 @@ { case StatText: // Text-Event len = GetVar(); - e = new tText(Clock, cp, len); + pEvent = new tText(Clock, cp, len); cp += len; - return e; + return pEvent; case StatTrackName: // Track-Name len = GetVar(); - e = new tTrackName(Clock, cp, len); + pEvent = new tTrackName(Clock, cp, len); cp += len; - return e; + return pEvent; case StatPlayTrack: // JAVE playtrack event len = GetVar(); fprintf(stderr, "reading playtrack event\n"); - e = new tPlayTrack(Clock, cp, len); + pEvent = new tPlayTrack(Clock, cp, len); cp += len; - return e; + return pEvent; case StatJazzMeta: // Jazz Meta Event len = GetVar(); if (memcmp(cp, "JAZ2", 4) == 0) - e = new tJazzMeta(Clock, cp, len); + pEvent = new tJazzMeta(Clock, cp, len); else - e = new tMetaEvent(Clock, Stat, cp, len); + pEvent = new tMetaEvent(Clock, Stat, cp, len); cp += len; - return e; + return pEvent; case StatCopyright: // Copyright notice len = GetVar(); - e = new tCopyright(Clock, cp, len); + pEvent = new tCopyright(Clock, cp, len); cp += len; - return e; + return pEvent; case StatMarker: len = GetVar(); - e = new tMarker(Clock, cp, len); + pEvent = new tMarker(Clock, cp, len); cp += len; - return e; + return pEvent; case StatEndOfTrack: EofSeen = 1; cp += GetVar(); - e = new tEndOfTrack(Clock); //JAVE return an explicit event rather than 0 - return e; + pEvent = new tEndOfTrack(Clock); //JAVE return an explicit event rather than 0 + return pEvent; //return 0; // EOF case StatSetTempo: len = GetVar(); - e = new tSetTempo(Clock, cp[0], cp[1], cp[2]); + pEvent = new tSetTempo(Clock, cp[0], cp[1], cp[2]); cp += len; - return e; + return pEvent; case StatTimeSignat: len = GetVar(); - e = new tTimeSignat(Clock, cp[0], cp[1], cp[2], cp[3]); + pEvent = new tTimeSignat(Clock, cp[0], cp[1], cp[2], cp[3]); cp += len; - return e; + return pEvent; case StatMtcOffset: // MtcOffset len = GetVar(); - e = new tMtcOffset(Clock, cp, len); + pEvent = new tMtcOffset(Clock, cp, len); cp += len; RunningStatus = 0; - return e; + return pEvent; default: // Text und andere ignorieren len = GetVar(); - e = new tMetaEvent(Clock, Stat, cp, len); + pEvent = new tMetaEvent(Clock, Stat, cp, len); cp += len; - return e; + return pEvent; } break; @@ -409,43 +463,43 @@ switch(Stat) { case StatKeyOff: // SN++ added off veloc - e = new tKeyOff(Clock, Channel, cp[0],cp[1]); + pEvent = new tKeyOff(Clock, Channel, cp[0],cp[1]); cp += 2; - return e; + return pEvent; case StatKeyOn: if (cp[1]) - e = new tKeyOn(Clock, Channel, cp[0], cp[1]); + pEvent = new tKeyOn(Clock, Channel, cp[0], cp[1]); else - e = new tKeyOff(Clock, Channel, cp[0]); + pEvent = new tKeyOff(Clock, Channel, cp[0]); cp += 2; - return e; + return pEvent; case StatKeyPressure: // SN++ Aftertouch - e = new tKeyPressure(Clock, Channel, cp[0], cp[1]); + pEvent = new tKeyPressure(Clock, Channel, cp[0], cp[1]); cp += 2; - return e; + return pEvent; case StatControl: - e = new tControl(Clock, Channel, cp[0], cp[1]); + pEvent = new tControl(Clock, Channel, cp[0], cp[1]); cp += 2; - return e; + return pEvent; case StatPitch: - e = new tPitch(Clock, Channel, cp[0], cp[1]); + pEvent = new tPitch(Clock, Channel, cp[0], cp[1]); cp += 2; - return e; + return pEvent; case StatProgram: - e = new tProgram(Clock, Channel, cp[0]); + pEvent = new tProgram(Clock, Channel, cp[0]); cp += 1; - return e; + return pEvent; case StatChnPressure: - e = new tChnPressure(Clock, Channel, cp[0]); + pEvent = new tChnPressure(Clock, Channel, cp[0]); cp += 1; - return e; + return pEvent; default: { @@ -460,25 +514,24 @@ return 0; // eof } - -// ------------------------------------------------------------------- - - -void tStdChunk::Load(FILE *fd) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardChunk::Load(FILE* pFd) { char Type[4]; int Size; - fread(Type, 4, 1, fd); - fread(&Size, 4, 1, fd); + fread(Type, 4, 1, pFd); + fread(&Size, 4, 1, pFd); SwapL(&Size); Resize(Size); - fread(mpBase, Size, 1, fd); + fread(mpBase, Size, 1, pFd); nRead = Size; } - -void tStdChunk::Save(FILE *fd) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardChunk::Save(FILE* pFd) { int Size, hSize; @@ -487,54 +540,63 @@ *cp++ = 0xff; *cp++ = 0x2f; *cp++ = 0x00; - fwrite("MTrk", 4, 1, fd); + fwrite("MTrk", 4, 1, pFd); Size = hSize = cp - mpBase; SwapL(&hSize); - fwrite(&hSize, 4, 1, fd); - fwrite(mpBase, Size, 1, fd); + fwrite(&hSize, 4, 1, pFd); + fwrite(mpBase, Size, 1, pFd); } -// ---------------------------------------------------------------------- - -struct tFileHeader +//***************************************************************************** +//***************************************************************************** +struct JZFileHeader { short Format; - short nTracks; + short mTrackCount; short Unit; void Swap(); }; -void tFileHeader::Swap() +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFileHeader::Swap() { SwapW(&Format); - SwapW(&nTracks); + SwapW(&mTrackCount); SwapW(&Unit); } -// ---------------------------- ReadStd ----------------------------- - - -tStdRead::tStdRead() - : tReadBase(), +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZStandardRead::JZStandardRead() + : JZReadBase(), mpTracks(0), - TrackNr(0) + mTrackIndex(0) { } -tStdRead::~tStdRead() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZStandardRead::~JZStandardRead() { delete [] mpTracks; } -int tStdRead::Open(const char* pFileName) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZStandardRead::Open(const char* pFileName) { - tFileHeader h; + JZFileHeader FileHeader; int hSize; int i; char Type[4]; - if (!tReadBase::Open(pFileName)) + if (!JZReadBase::Open(pFileName)) { ostringstream Oss; Oss << "Can't open " << pFileName; @@ -542,7 +604,7 @@ return 0; } - fread(Type, 4, 1, fd); + fread(Type, 4, 1, mpFd); if (strncmp("MThd", Type, 4) != 0) { @@ -550,105 +612,126 @@ return 0; } - fread(&hSize, 4, 1, fd); + fread(&hSize, 4, 1, mpFd); SwapL(&hSize); - assert (hSize == sizeof(h)); + assert (hSize == sizeof(FileHeader)); - fread(&h, 6, 1, fd); - h.Swap(); - nTracks = h.nTracks; - TicksPerQuarter = h.Unit; + fread(&FileHeader, 6, 1, mpFd); + FileHeader.Swap(); + mTrackCount = FileHeader.mTrackCount; + mTicksPerQuarter = FileHeader.Unit; - mpTracks = new tStdChunk [nTracks]; - for (i = 0; i < nTracks; i++) + mpTracks = new JZStandardChunk [mTrackCount]; + for (i = 0; i < mTrackCount; i++) { - mpTracks[i].Load(fd); + mpTracks[i].Load(mpFd); } - TrackNr = -1; + mTrackIndex = -1; - return nTracks; + return mTrackCount; } -void tStdRead::Close() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardRead::Close() { - tReadBase::Close(); + JZReadBase::Close(); } -JZEvent *tStdRead::Read() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZEvent* JZStandardRead::Read() { - assert(TrackNr >= 0 && TrackNr < nTracks); - return mpTracks[TrackNr].Get(); + assert(mTrackIndex >= 0 && mTrackIndex < mTrackCount); + return mpTracks[mTrackIndex].Get(); } -int tStdRead::NextTrack() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZStandardRead::NextTrack() { - ++TrackNr; - return TrackNr < nTracks; + ++mTrackIndex; + return mTrackIndex < mTrackCount; } - -// ------------------------------ tWriteStd --------------------------------- - -tStdWrite::tStdWrite() - : tWriteBase(), +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZStandardWrite::JZStandardWrite() + : JZWriteBase(), mpTracks(0), - TrackNr(0), - nTracks(0), - TicksPerQuarter(0) + mTrackIndex(0), + mTrackCount(0), + mTicksPerQuarter(0) { } -tStdWrite::~tStdWrite() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZStandardWrite::~JZStandardWrite() { delete [] mpTracks; } -int tStdWrite::Open(char* pFileName, int ntracks, int timebase) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZStandardWrite::Open( + const char* pFileName, + int TrackCount, + int TicksPerQuarter) { - if (!tWriteBase::Open(pFileName, ntracks, timebase)) + if (!JZWriteBase::Open(pFileName, TrackCount, TicksPerQuarter)) { return 0; } - nTracks = ntracks; - TicksPerQuarter = timebase; - mpTracks = new tStdChunk [ntracks]; - TrackNr = -1; - return nTracks; + + mTrackCount = TrackCount; + mTicksPerQuarter = TicksPerQuarter; + mpTracks = new JZStandardChunk [TrackCount]; + mTrackIndex = -1; + return mTrackCount; } -void tStdWrite::Close() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardWrite::Close() { long Size; - tFileHeader h; + JZFileHeader FileHeader; int i; - fwrite("MThd", 4, 1, fd); + fwrite("MThd", 4, 1, mpFd); Size = 6; SwapL(&Size); - fwrite(&Size, 4, 1, fd); - h.Unit = TicksPerQuarter; - h.Format = 1; - h.nTracks = nTracks; - h.Swap(); - fwrite(&h, 6, 1, fd); + fwrite(&Size, 4, 1, mpFd); + FileHeader.Unit = mTicksPerQuarter; + FileHeader.Format = 1; + FileHeader.mTrackCount = mTrackCount; + FileHeader.Swap(); + fwrite(&FileHeader, 6, 1, mpFd); - for (i = 0; i < nTracks; i++) + for (i = 0; i < mTrackCount; i++) { - mpTracks[i].Save(fd); + mpTracks[i].Save(mpFd); } - tWriteBase::Close(); + JZWriteBase::Close(); } -void tStdWrite::NextTrack() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZStandardWrite::NextTrack() { - ++TrackNr; + ++mTrackIndex; } -int tStdWrite::Write(JZEvent *e, unsigned char* data, int len) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZStandardWrite::Write(JZEvent* pEvent, unsigned char* pString, int Length) { - assert(TrackNr >= 0 && TrackNr < nTracks); - mpTracks[TrackNr].Put(e, data, len); + assert(mTrackIndex >= 0 && mTrackIndex < mTrackCount); + mpTracks[mTrackIndex].Put(pEvent, pString, Length); return 0; } Modified: trunk/jazz/src/StandardFile.h =================================================================== --- trunk/jazz/src/StandardFile.h 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/StandardFile.h 2008-03-30 14:35:30 UTC (rev 368) @@ -28,84 +28,63 @@ #include <stdio.h> class JZEvent; -class tStdChunk +class JZStandardChunk; + +//***************************************************************************** +//***************************************************************************** +class JZStandardRead : public JZReadBase { public: - tStdChunk(); + JZStandardRead(); - ~tStdChunk(); + virtual ~JZStandardRead(); - int IsEof(); // Only after Load, Save never has Eof. + virtual int Open(const char* pFileName); - void Load(FILE* fd); + virtual void Close(); - void Save(FILE* fd); // Depends on EndOfTrack + virtual JZEvent* Read(); - void Put(JZEvent* pEvent, unsigned char* pData, int Length); + virtual int NextTrack(); - // A return value of NULL indicates we are at the end of the track. - JZEvent* Get(); - - void Rewind(); - private: - long Size; // Size of base - long nRead; // Number of bytes read from the file - unsigned char* mpBase; // Buffer for data. - unsigned char* cp; // Aktueller Schreib/Lese pointer - long Clock; // Absolute Clock - int EofSeen; // endoftrack meta-event read - int RunningStatus; + JZStandardChunk* mpTracks; - void Resize(int SizeNeeded); - void PutVar(unsigned long val); - unsigned long GetVar(); + int mTrackIndex; }; - -class tStdRead : public tReadBase +//***************************************************************************** +//***************************************************************************** +class JZStandardWrite : public JZWriteBase { public: - tStdRead(); + JZStandardWrite(); - virtual ~tStdRead(); + virtual ~JZStandardWrite(); - virtual int Open(const char* pFileName); + virtual int Open( + const char* pFileName, + int TrackCount, + int TicksPerQuarter); + virtual void Close(); - virtual JZEvent* Read(); - virtual int NextTrack(); + virtual int Write(JZEvent* Event, unsigned char* pString, int Length); + virtual void NextTrack(); + private: - tStdChunk* mpTracks; - int TrackNr; -}; + JZStandardChunk* mpTracks; + int mTrackIndex; + int mTrackCount; -class tStdWrite : public tWriteBase -{ - public: - - tStdWrite(); - - virtual ~tStdWrite(); - - virtual int Open(char* pFileName, int nTracks, int TicksPerQuarter); - virtual void Close(); - virtual int Write(JZEvent* Event, unsigned char *s, int len); - virtual void NextTrack(); - - private: - - tStdChunk* mpTracks; - int TrackNr; - int nTracks; - int TicksPerQuarter; + int mTicksPerQuarter; }; #endif // !defined(JZ_STANDARDFILE_H) Modified: trunk/jazz/src/Track.cpp =================================================================== --- trunk/jazz/src/Track.cpp 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Track.cpp 2008-03-30 14:35:30 UTC (rev 368) @@ -35,9 +35,9 @@ #include <cstdlib> #include <assert.h> -int tParam::Write(tWriteBase& io) +int tParam::Write(JZWriteBase& Io) { - return(Msb.Write(io) + Lsb.Write(io) + DataMsb.Write(io)); + return Msb.Write(Io) + Lsb.Write(Io) + DataMsb.Write(Io); } void tParam::SetCha(unsigned char cha) @@ -1271,69 +1271,69 @@ #endif -void tEventArray::Write(tWriteBase &io) +void tEventArray::Write(JZWriteBase& Io) { JZEvent *e; int WrittenBefore; Length2Keyoff(); - io.NextTrack(); + Io.NextTrack(); // Write copyright notice first (according to spec): if (Copyright) { - Copyright->Write(io); + Copyright->Write(Io); } // Write MTC offset before any transmittable events (spec) if (MtcOffset) { - MtcOffset->Write(io); + MtcOffset->Write(Io); } // Synth reset if (Reset) { - Reset->Write(io); + Reset->Write(Io); } // Rpn / Nrpn: // All these must be written in order (three tControl's in a row) if (VibRate) { - VibRate->Write(io); + VibRate->Write(Io); } if (VibDepth) { - VibDepth->Write(io); + VibDepth->Write(Io); } if (VibDelay) { - VibDelay->Write(io); + VibDelay->Write(Io); } if (Cutoff) { - Cutoff->Write(io); + Cutoff->Write(Io); } if (Resonance) { - Resonance->Write(io); + Resonance->Write(Io); } if (EnvAttack) { - EnvAttack->Write(io); + EnvAttack->Write(Io); } if (EnvDecay) { - EnvDecay->Write(io); + EnvDecay->Write(Io); } if (EnvRelease) { - EnvRelease->Write(io); + EnvRelease->Write(Io); } if (BendPitchSens) { - BendPitchSens->Write(io); + BendPitchSens->Write(Io); } tDrumInstrumentParameter *dpar = DrumParams.FirstElem(); @@ -1344,7 +1344,7 @@ { if (dpar->Get(index)) { - dpar->Get(index)->Write(io); + dpar->Get(index)->Write(Io); } } dpar = DrumParams.NextElem(dpar); @@ -1353,17 +1353,17 @@ // mpBank: Must be sure bank is written before program: if (mpBank) { - mpBank->Write(io); + mpBank->Write(Io); } if (mpBank2) { - mpBank2->Write(io); + mpBank2->Write(Io); } if (mPatch) { - mPatch->Write(io); + mPatch->Write(Io); } // write jazz track info @@ -1372,7 +1372,7 @@ jazz->SetTrackState(State); jazz->SetTrackDevice(Device); jazz->SetIntroLength(gpSong->GetIntroLength()); - jazz->Write(io); + jazz->Write(Io); for (int i = 0; i < nEvents; i++) { @@ -1416,15 +1416,13 @@ } if (!WrittenBefore) { - e->Write(io); + e->Write(Io); } } Keyoff2Length(); } - - -void tEventArray::Read(tReadBase &io) +void tEventArray::Read(JZReadBase& Io) { JZEvent *e; Channel = 0; @@ -1436,8 +1434,8 @@ bool NeedToDelete; - io.NextTrack(); - while ((e = io.Read()) != 0) + Io.NextTrack(); + while ((e = Io.Read()) != 0) { NeedToDelete = false; SpecialEvent = 0; Modified: trunk/jazz/src/Track.h =================================================================== --- trunk/jazz/src/Track.h 2008-03-30 13:41:19 UTC (rev 367) +++ trunk/jazz/src/Track.h 2008-03-30 14:35:30 UTC (rev 368) @@ -68,7 +68,7 @@ { } - virtual int Write(tWriteBase &io); + virtual int Write(JZWriteBase& Io); virtual void SetCha( unsigned char cha ); virtual int GetVal() { @@ -375,8 +375,8 @@ tEventArray(); virtual ~tEventArray(); - void Read(tReadBase &io); - void Write(tWriteBase &io); + void Read(JZReadBase& Io); + void Write(JZWriteBase& Io); int GetLastClock(); int IsEmpty(); @@ -386,9 +386,16 @@ public: - int GetAudioMode() const { return audio_mode; } - void SetAudioMode(int x) { audio_mode = x; } + int GetAudioMode() const + { + return audio_mode; + } + void SetAudioMode(int x) + { + audio_mode = x; + } + protected: int audio_mode; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |