/[svn]/libgig/trunk/src/DLS.cpp
ViewVC logotype

Diff of /libgig/trunk/src/DLS.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 804 by schoenebeck, Sat Nov 12 19:16:01 2005 UTC revision 902 by persson, Sat Jul 22 14:22:01 2006 UTC
# Line 257  namespace DLS { Line 257  namespace DLS {
257          }          }
258      }      }
259    
260        Info::~Info() {
261        }
262    
263      /** @brief Load given INFO field.      /** @brief Load given INFO field.
264       *       *
265       * Load INFO field from INFO chunk with chunk ID \a ChunkID from INFO       * Load INFO field from INFO chunk with chunk ID \a ChunkID from INFO
# Line 265  namespace DLS { Line 268  namespace DLS {
268      void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {      void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
269          RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);          RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
270          if (ck) {          if (ck) {
271              // TODO: no check for ZSTR terminated strings yet              const char* str = (char*)ck->LoadChunkData();
272              s = (char*) ck->LoadChunkData();              int size = ck->GetSize();
273                int len;
274                for (len = 0 ; len < size ; len++)
275                    if (str[len] == '\0') break;
276                s.assign(str, len);
277              ck->ReleaseChunkData();              ck->ReleaseChunkData();
278          }          }
279      }      }
# Line 895  namespace DLS { Line 902  namespace DLS {
902      }      }
903    
904      void Instrument::LoadRegions() {      void Instrument::LoadRegions() {
905            if (!pRegions) pRegions = new RegionList;
906          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
907          if (!lrgn) throw DLS::Exception("DLS::Instrument doesn't seem to have any Region (mandatory chunks in <ins > chunk not found)");          if (lrgn) {
908          uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2              uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2
909          RIFF::List* rgn = lrgn->GetFirstSubList();              RIFF::List* rgn = lrgn->GetFirstSubList();
910          while (rgn) {              while (rgn) {
911              if (rgn->GetListType() == regionCkType) {                  if (rgn->GetListType() == regionCkType) {
912                  if (!pRegions) pRegions = new RegionList;                      pRegions->push_back(new Region(this, rgn));
913                  pRegions->push_back(new Region(this, rgn));                  }
914                    rgn = lrgn->GetNextSubList();
915              }              }
             rgn = lrgn->GetNextSubList();  
916          }          }
917      }      }
918    
919      Region* Instrument::AddRegion() {      Region* Instrument::AddRegion() {
920          if (!pRegions) pRegions = new RegionList;          if (!pRegions) LoadRegions();
921          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
922          if (!lrgn)  lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);          if (!lrgn)  lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);
923          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
924          Region* pNewRegion = new Region(this, rgn);          Region* pNewRegion = new Region(this, rgn);
925          pRegions->push_back(pNewRegion);          pRegions->push_back(pNewRegion);
926            Regions = pRegions->size();
927          return pNewRegion;          return pNewRegion;
928      }      }
929    
# Line 923  namespace DLS { Line 932  namespace DLS {
932          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
933          if (iter == pRegions->end()) return;          if (iter == pRegions->end()) return;
934          pRegions->erase(iter);          pRegions->erase(iter);
935            Regions = pRegions->size();
936          delete pRegion;          delete pRegion;
937      }      }
938    
# Line 1033  namespace DLS { Line 1043  namespace DLS {
1043          Instruments = colh->ReadUint32();          Instruments = colh->ReadUint32();
1044    
1045          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
1046          if (!ptbl) throw DLS::Exception("Mandatory <ptbl> chunk not found.");          if (!ptbl) { // pool table is missing - this is probably an ".art" file
1047          WavePoolHeaderSize = ptbl->ReadUint32();              WavePoolCount    = 0;
1048          WavePoolCount  = ptbl->ReadUint32();              pWavePoolTable   = NULL;
1049          pWavePoolTable = new uint32_t[WavePoolCount];              pWavePoolTableHi = NULL;
1050          pWavePoolTableHi = new uint32_t[WavePoolCount];              WavePoolHeaderSize = 8;
1051          ptbl->SetPos(WavePoolHeaderSize);              b64BitWavePoolOffsets = false;
1052            } else {
1053          // Check for 64 bit offsets (used in gig v3 files)              WavePoolHeaderSize = ptbl->ReadUint32();
1054          b64BitWavePoolOffsets = (ptbl->GetSize() - WavePoolHeaderSize == WavePoolCount * 8);              WavePoolCount  = ptbl->ReadUint32();
1055          if (b64BitWavePoolOffsets) {              pWavePoolTable = new uint32_t[WavePoolCount];
1056              for (int i = 0 ; i < WavePoolCount ; i++) {              pWavePoolTableHi = new uint32_t[WavePoolCount];
1057                  pWavePoolTableHi[i] = ptbl->ReadUint32();              ptbl->SetPos(WavePoolHeaderSize);
1058                  pWavePoolTable[i] = ptbl->ReadUint32();  
1059                  if (pWavePoolTable[i] & 0x80000000)              // Check for 64 bit offsets (used in gig v3 files)
1060                      throw DLS::Exception("Files larger than 2 GB not yet supported");              b64BitWavePoolOffsets = (ptbl->GetSize() - WavePoolHeaderSize == WavePoolCount * 8);
1061              }              if (b64BitWavePoolOffsets) {
1062          } else { // conventional 32 bit offsets                  for (int i = 0 ; i < WavePoolCount ; i++) {
1063              ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));                      pWavePoolTableHi[i] = ptbl->ReadUint32();
1064              for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;                      pWavePoolTable[i] = ptbl->ReadUint32();
1065                        if (pWavePoolTable[i] & 0x80000000)
1066                            throw DLS::Exception("Files larger than 2 GB not yet supported");
1067                    }
1068                } else { // conventional 32 bit offsets
1069                    ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
1070                    for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;
1071                }
1072          }          }
1073    
1074          pSamples     = NULL;          pSamples     = NULL;
# Line 1082  namespace DLS { Line 1099  namespace DLS {
1099          if (pWavePoolTable) delete[] pWavePoolTable;          if (pWavePoolTable) delete[] pWavePoolTable;
1100          if (pWavePoolTableHi) delete[] pWavePoolTableHi;          if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1101          if (pVersion) delete pVersion;          if (pVersion) delete pVersion;
1102            for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1103                delete *i;
1104      }      }
1105    
1106      Sample* File::GetFirstSample() {      Sample* File::GetFirstSample() {
# Line 1098  namespace DLS { Line 1117  namespace DLS {
1117      }      }
1118    
1119      void File::LoadSamples() {      void File::LoadSamples() {
1120            if (!pSamples) pSamples = new SampleList;
1121          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1122          if (wvpl) {          if (wvpl) {
1123              unsigned long wvplFileOffset = wvpl->GetFilePos();              unsigned long wvplFileOffset = wvpl->GetFilePos();
1124              RIFF::List* wave = wvpl->GetFirstSubList();              RIFF::List* wave = wvpl->GetFirstSubList();
1125              while (wave) {              while (wave) {
1126                  if (wave->GetListType() == LIST_TYPE_WAVE) {                  if (wave->GetListType() == LIST_TYPE_WAVE) {
                     if (!pSamples) pSamples = new SampleList;  
1127                      unsigned long waveFileOffset = wave->GetFilePos();                      unsigned long waveFileOffset = wave->GetFilePos();
1128                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1129                  }                  }
# Line 1118  namespace DLS { Line 1137  namespace DLS {
1137                  RIFF::List* wave = dwpl->GetFirstSubList();                  RIFF::List* wave = dwpl->GetFirstSubList();
1138                  while (wave) {                  while (wave) {
1139                      if (wave->GetListType() == LIST_TYPE_WAVE) {                      if (wave->GetListType() == LIST_TYPE_WAVE) {
                         if (!pSamples) pSamples = new SampleList;  
1140                          unsigned long waveFileOffset = wave->GetFilePos();                          unsigned long waveFileOffset = wave->GetFilePos();
1141                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1142                      }                      }
# Line 1136  namespace DLS { Line 1154  namespace DLS {
1154       * @returns pointer to new Sample object       * @returns pointer to new Sample object
1155       */       */
1156      Sample* File::AddSample() {      Sample* File::AddSample() {
1157           if (!pSamples) LoadSamples();
1158         __ensureMandatoryChunksExist();         __ensureMandatoryChunksExist();
1159         RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);         RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1160         // create new Sample object and its respective 'wave' list chunk         // create new Sample object and its respective 'wave' list chunk
        if (!pSamples) pSamples = new SampleList;  
1161         RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);         RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
1162         Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/);         Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/);
1163         pSamples->push_back(pSample);         pSamples->push_back(pSample);
# Line 1175  namespace DLS { Line 1193  namespace DLS {
1193      }      }
1194    
1195      void File::LoadInstruments() {      void File::LoadInstruments() {
1196            if (!pInstruments) pInstruments = new InstrumentList;
1197          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1198          if (lstInstruments) {          if (lstInstruments) {
1199              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1200              while (lstInstr) {              while (lstInstr) {
1201                  if (lstInstr->GetListType() == LIST_TYPE_INS) {                  if (lstInstr->GetListType() == LIST_TYPE_INS) {
                     if (!pInstruments) pInstruments = new InstrumentList;  
1202                      pInstruments->push_back(new Instrument(this, lstInstr));                      pInstruments->push_back(new Instrument(this, lstInstr));
1203                  }                  }
1204                  lstInstr = lstInstruments->GetNextSubList();                  lstInstr = lstInstruments->GetNextSubList();
# Line 1196  namespace DLS { Line 1214  namespace DLS {
1214       * @returns pointer to new Instrument object       * @returns pointer to new Instrument object
1215       */       */
1216      Instrument* File::AddInstrument() {      Instrument* File::AddInstrument() {
1217           if (!pInstruments) LoadInstruments();
1218         __ensureMandatoryChunksExist();         __ensureMandatoryChunksExist();
        if (!pInstruments) pInstruments = new InstrumentList;  
1219         RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);         RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1220         RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);         RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
1221         Instrument* pInstrument = new Instrument(this, lstInstr);         Instrument* pInstrument = new Instrument(this, lstInstr);
# Line 1205  namespace DLS { Line 1223  namespace DLS {
1223         return pInstrument;         return pInstrument;
1224      }      }
1225    
1226      /** @brief Delete a instrument.      /** @brief Delete an instrument.
1227       *       *
1228       * This will delete the given Instrument object from the DLS file. You       * This will delete the given Instrument object from the DLS file. You
1229       * have to call Save() to make this persistent to the file.       * have to call Save() to make this persistent to the file.

Legend:
Removed from v.804  
changed lines
  Added in v.902

  ViewVC Help
Powered by ViewVC