/[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 839 by persson, Fri Feb 10 19:23:59 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 1082  namespace DLS { Line 1092  namespace DLS {
1092          if (pWavePoolTable) delete[] pWavePoolTable;          if (pWavePoolTable) delete[] pWavePoolTable;
1093          if (pWavePoolTableHi) delete[] pWavePoolTableHi;          if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1094          if (pVersion) delete pVersion;          if (pVersion) delete pVersion;
1095            for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1096                delete *i;
1097      }      }
1098    
1099      Sample* File::GetFirstSample() {      Sample* File::GetFirstSample() {
# Line 1098  namespace DLS { Line 1110  namespace DLS {
1110      }      }
1111    
1112      void File::LoadSamples() {      void File::LoadSamples() {
1113            if (!pSamples) pSamples = new SampleList;
1114          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1115          if (wvpl) {          if (wvpl) {
1116              unsigned long wvplFileOffset = wvpl->GetFilePos();              unsigned long wvplFileOffset = wvpl->GetFilePos();
1117              RIFF::List* wave = wvpl->GetFirstSubList();              RIFF::List* wave = wvpl->GetFirstSubList();
1118              while (wave) {              while (wave) {
1119                  if (wave->GetListType() == LIST_TYPE_WAVE) {                  if (wave->GetListType() == LIST_TYPE_WAVE) {
                     if (!pSamples) pSamples = new SampleList;  
1120                      unsigned long waveFileOffset = wave->GetFilePos();                      unsigned long waveFileOffset = wave->GetFilePos();
1121                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1122                  }                  }
# Line 1118  namespace DLS { Line 1130  namespace DLS {
1130                  RIFF::List* wave = dwpl->GetFirstSubList();                  RIFF::List* wave = dwpl->GetFirstSubList();
1131                  while (wave) {                  while (wave) {
1132                      if (wave->GetListType() == LIST_TYPE_WAVE) {                      if (wave->GetListType() == LIST_TYPE_WAVE) {
                         if (!pSamples) pSamples = new SampleList;  
1133                          unsigned long waveFileOffset = wave->GetFilePos();                          unsigned long waveFileOffset = wave->GetFilePos();
1134                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1135                      }                      }
# Line 1136  namespace DLS { Line 1147  namespace DLS {
1147       * @returns pointer to new Sample object       * @returns pointer to new Sample object
1148       */       */
1149      Sample* File::AddSample() {      Sample* File::AddSample() {
1150           if (!pSamples) LoadSamples();
1151         __ensureMandatoryChunksExist();         __ensureMandatoryChunksExist();
1152         RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);         RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1153         // 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;  
1154         RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);         RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
1155         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*/);
1156         pSamples->push_back(pSample);         pSamples->push_back(pSample);
# Line 1175  namespace DLS { Line 1186  namespace DLS {
1186      }      }
1187    
1188      void File::LoadInstruments() {      void File::LoadInstruments() {
1189            if (!pInstruments) pInstruments = new InstrumentList;
1190          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1191          if (lstInstruments) {          if (lstInstruments) {
1192              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1193              while (lstInstr) {              while (lstInstr) {
1194                  if (lstInstr->GetListType() == LIST_TYPE_INS) {                  if (lstInstr->GetListType() == LIST_TYPE_INS) {
                     if (!pInstruments) pInstruments = new InstrumentList;  
1195                      pInstruments->push_back(new Instrument(this, lstInstr));                      pInstruments->push_back(new Instrument(this, lstInstr));
1196                  }                  }
1197                  lstInstr = lstInstruments->GetNextSubList();                  lstInstr = lstInstruments->GetNextSubList();
# Line 1196  namespace DLS { Line 1207  namespace DLS {
1207       * @returns pointer to new Instrument object       * @returns pointer to new Instrument object
1208       */       */
1209      Instrument* File::AddInstrument() {      Instrument* File::AddInstrument() {
1210           if (!pInstruments) LoadInstruments();
1211         __ensureMandatoryChunksExist();         __ensureMandatoryChunksExist();
        if (!pInstruments) pInstruments = new InstrumentList;  
1212         RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);         RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1213         RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);         RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
1214         Instrument* pInstrument = new Instrument(this, lstInstr);         Instrument* pInstrument = new Instrument(this, lstInstr);
# Line 1205  namespace DLS { Line 1216  namespace DLS {
1216         return pInstrument;         return pInstrument;
1217      }      }
1218    
1219      /** @brief Delete a instrument.      /** @brief Delete an instrument.
1220       *       *
1221       * This will delete the given Instrument object from the DLS file. You       * This will delete the given Instrument object from the DLS file. You
1222       * 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.839

  ViewVC Help
Powered by ViewVC