/[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 834 by persson, Mon Feb 6 17:58:21 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 266  namespace DLS { Line 269  namespace DLS {
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              // TODO: no check for ZSTR terminated strings yet
272              s = (char*) ck->LoadChunkData();              s.assign((char*) ck->LoadChunkData(), ck->GetSize());
273              ck->ReleaseChunkData();              ck->ReleaseChunkData();
274          }          }
275      }      }
# Line 895  namespace DLS { Line 898  namespace DLS {
898      }      }
899    
900      void Instrument::LoadRegions() {      void Instrument::LoadRegions() {
901            if (!pRegions) pRegions = new RegionList;
902          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
903          if (!lrgn) throw DLS::Exception("DLS::Instrument doesn't seem to have any Region (mandatory chunks in <ins > chunk not found)");          if (lrgn) {
904          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
905          RIFF::List* rgn = lrgn->GetFirstSubList();              RIFF::List* rgn = lrgn->GetFirstSubList();
906          while (rgn) {              while (rgn) {
907              if (rgn->GetListType() == regionCkType) {                  if (rgn->GetListType() == regionCkType) {
908                  if (!pRegions) pRegions = new RegionList;                      pRegions->push_back(new Region(this, rgn));
909                  pRegions->push_back(new Region(this, rgn));                  }
910                    rgn = lrgn->GetNextSubList();
911              }              }
             rgn = lrgn->GetNextSubList();  
912          }          }
913      }      }
914    
915      Region* Instrument::AddRegion() {      Region* Instrument::AddRegion() {
916          if (!pRegions) pRegions = new RegionList;          if (!pRegions) LoadRegions();
917          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
918          if (!lrgn)  lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);          if (!lrgn)  lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);
919          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
920          Region* pNewRegion = new Region(this, rgn);          Region* pNewRegion = new Region(this, rgn);
921          pRegions->push_back(pNewRegion);          pRegions->push_back(pNewRegion);
922            Regions = pRegions->size();
923          return pNewRegion;          return pNewRegion;
924      }      }
925    
# Line 923  namespace DLS { Line 928  namespace DLS {
928          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
929          if (iter == pRegions->end()) return;          if (iter == pRegions->end()) return;
930          pRegions->erase(iter);          pRegions->erase(iter);
931            Regions = pRegions->size();
932          delete pRegion;          delete pRegion;
933      }      }
934    
# Line 1082  namespace DLS { Line 1088  namespace DLS {
1088          if (pWavePoolTable) delete[] pWavePoolTable;          if (pWavePoolTable) delete[] pWavePoolTable;
1089          if (pWavePoolTableHi) delete[] pWavePoolTableHi;          if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1090          if (pVersion) delete pVersion;          if (pVersion) delete pVersion;
1091            for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1092                delete *i;
1093      }      }
1094    
1095      Sample* File::GetFirstSample() {      Sample* File::GetFirstSample() {
# Line 1098  namespace DLS { Line 1106  namespace DLS {
1106      }      }
1107    
1108      void File::LoadSamples() {      void File::LoadSamples() {
1109            if (!pSamples) pSamples = new SampleList;
1110          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1111          if (wvpl) {          if (wvpl) {
1112              unsigned long wvplFileOffset = wvpl->GetFilePos();              unsigned long wvplFileOffset = wvpl->GetFilePos();
1113              RIFF::List* wave = wvpl->GetFirstSubList();              RIFF::List* wave = wvpl->GetFirstSubList();
1114              while (wave) {              while (wave) {
1115                  if (wave->GetListType() == LIST_TYPE_WAVE) {                  if (wave->GetListType() == LIST_TYPE_WAVE) {
                     if (!pSamples) pSamples = new SampleList;  
1116                      unsigned long waveFileOffset = wave->GetFilePos();                      unsigned long waveFileOffset = wave->GetFilePos();
1117                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1118                  }                  }
# Line 1118  namespace DLS { Line 1126  namespace DLS {
1126                  RIFF::List* wave = dwpl->GetFirstSubList();                  RIFF::List* wave = dwpl->GetFirstSubList();
1127                  while (wave) {                  while (wave) {
1128                      if (wave->GetListType() == LIST_TYPE_WAVE) {                      if (wave->GetListType() == LIST_TYPE_WAVE) {
                         if (!pSamples) pSamples = new SampleList;  
1129                          unsigned long waveFileOffset = wave->GetFilePos();                          unsigned long waveFileOffset = wave->GetFilePos();
1130                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1131                      }                      }
# Line 1136  namespace DLS { Line 1143  namespace DLS {
1143       * @returns pointer to new Sample object       * @returns pointer to new Sample object
1144       */       */
1145      Sample* File::AddSample() {      Sample* File::AddSample() {
1146           if (!pSamples) LoadSamples();
1147         __ensureMandatoryChunksExist();         __ensureMandatoryChunksExist();
1148         RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);         RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1149         // 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;  
1150         RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);         RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
1151         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*/);
1152         pSamples->push_back(pSample);         pSamples->push_back(pSample);
# Line 1175  namespace DLS { Line 1182  namespace DLS {
1182      }      }
1183    
1184      void File::LoadInstruments() {      void File::LoadInstruments() {
1185            if (!pInstruments) pInstruments = new InstrumentList;
1186          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1187          if (lstInstruments) {          if (lstInstruments) {
1188              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1189              while (lstInstr) {              while (lstInstr) {
1190                  if (lstInstr->GetListType() == LIST_TYPE_INS) {                  if (lstInstr->GetListType() == LIST_TYPE_INS) {
                     if (!pInstruments) pInstruments = new InstrumentList;  
1191                      pInstruments->push_back(new Instrument(this, lstInstr));                      pInstruments->push_back(new Instrument(this, lstInstr));
1192                  }                  }
1193                  lstInstr = lstInstruments->GetNextSubList();                  lstInstr = lstInstruments->GetNextSubList();
# Line 1196  namespace DLS { Line 1203  namespace DLS {
1203       * @returns pointer to new Instrument object       * @returns pointer to new Instrument object
1204       */       */
1205      Instrument* File::AddInstrument() {      Instrument* File::AddInstrument() {
1206           if (!pInstruments) LoadInstruments();
1207         __ensureMandatoryChunksExist();         __ensureMandatoryChunksExist();
        if (!pInstruments) pInstruments = new InstrumentList;  
1208         RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);         RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1209         RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);         RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
1210         Instrument* pInstrument = new Instrument(this, lstInstr);         Instrument* pInstrument = new Instrument(this, lstInstr);
# Line 1205  namespace DLS { Line 1212  namespace DLS {
1212         return pInstrument;         return pInstrument;
1213      }      }
1214    
1215      /** @brief Delete a instrument.      /** @brief Delete an instrument.
1216       *       *
1217       * This will delete the given Instrument object from the DLS file. You       * This will delete the given Instrument object from the DLS file. You
1218       * 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.834

  ViewVC Help
Powered by ViewVC