/[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 3723 by schoenebeck, Wed Jan 22 15:48:32 2020 UTC revision 3929 by schoenebeck, Tue Jun 15 12:22:26 2021 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2020 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2021 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 209  namespace DLS { Line 209  namespace DLS {
209          if (lart) {          if (lart) {
210              uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2              uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2
211                                                                           : CHUNK_ID_ARTL;                                                                           : CHUNK_ID_ARTL;
212              RIFF::Chunk* art = lart->GetFirstSubChunk();              size_t i = 0;
213              while (art) {              for (RIFF::Chunk* art = lart->GetSubChunkAt(i); art;
214                     art = lart->GetSubChunkAt(++i))
215                {
216                  if (art->GetChunkID() == artCkType) {                  if (art->GetChunkID() == artCkType) {
217                      if (!pArticulations) pArticulations = new ArticulationList;                      if (!pArticulations) pArticulations = new ArticulationList;
218                      pArticulations->push_back(new Articulation(art));                      pArticulations->push_back(new Articulation(art));
219                  }                  }
                 art = lart->GetNextSubChunk();  
220              }              }
221          }          }
222      }      }
# Line 1163  namespace DLS { Line 1164  namespace DLS {
1164          if (pSample) return pSample;          if (pSample) return pSample;
1165          File* file = (File*) GetParent()->GetParent();          File* file = (File*) GetParent()->GetParent();
1166          uint64_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];          uint64_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1167          Sample* sample = file->GetFirstSample();          size_t i = 0;
1168          while (sample) {          for (Sample* sample = file->GetSample(i); sample;
1169                         sample = file->GetSample(++i))
1170            {
1171              if (sample->ullWavePoolOffset == soughtoffset) return (pSample = sample);              if (sample->ullWavePoolOffset == soughtoffset) return (pSample = sample);
             sample = file->GetNextSample();  
1172          }          }
1173          return NULL;          return NULL;
1174      }      }
# Line 1357  namespace DLS { Line 1359  namespace DLS {
1359          pRegions = NULL;          pRegions = NULL;
1360      }      }
1361    
1362        /**
1363         * Returns Region at supplied @a pos position within the region list of
1364         * this instrument. If supplied @a pos is out of bounds then @c NULL is
1365         * returned.
1366         *
1367         * @param pos - position of sought Region in region list
1368         * @returns pointer address to requested region or @c NULL if @a pos is
1369         *          out of bounds
1370         */
1371        Region* Instrument::GetRegionAt(size_t pos) {
1372            if (!pRegions) LoadRegions();
1373            if (!pRegions) return NULL;
1374            if (pos >= pRegions->size()) return NULL;
1375            return (*pRegions)[pos];
1376        }
1377    
1378        /**
1379         * Returns the first Region of the instrument. You have to call this
1380         * method once before you use GetNextRegion().
1381         *
1382         * @returns  pointer address to first region or NULL if there is none
1383         * @see      GetNextRegion()
1384         * @deprecated  This method is not reentrant-safe, use GetRegionAt()
1385         *              instead.
1386         */
1387      Region* Instrument::GetFirstRegion() {      Region* Instrument::GetFirstRegion() {
1388          if (!pRegions) LoadRegions();          if (!pRegions) LoadRegions();
1389          if (!pRegions) return NULL;          if (!pRegions) return NULL;
# Line 1364  namespace DLS { Line 1391  namespace DLS {
1391          return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;          return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1392      }      }
1393    
1394        /**
1395         * Returns the next Region of the instrument. You have to call
1396         * GetFirstRegion() once before you can use this method. By calling this
1397         * method multiple times it iterates through the available Regions.
1398         *
1399         * @returns  pointer address to the next region or NULL if end reached
1400         * @see      GetFirstRegion()
1401         * @deprecated  This method is not reentrant-safe, use GetRegionAt()
1402         *              instead.
1403         */
1404      Region* Instrument::GetNextRegion() {      Region* Instrument::GetNextRegion() {
1405          if (!pRegions) return NULL;          if (!pRegions) return NULL;
1406          RegionsIterator++;          RegionsIterator++;
# Line 1375  namespace DLS { Line 1412  namespace DLS {
1412          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
1413          if (lrgn) {          if (lrgn) {
1414              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
1415              RIFF::List* rgn = lrgn->GetFirstSubList();              size_t i = 0;
1416              while (rgn) {              for (RIFF::List* rgn = lrgn->GetSubListAt(i); rgn;
1417                     rgn = lrgn->GetSubListAt(++i))
1418                {
1419                  if (rgn->GetListType() == regionCkType) {                  if (rgn->GetListType() == regionCkType) {
1420                      pRegions->push_back(new Region(this, rgn));                      pRegions->push_back(new Region(this, rgn));
1421                  }                  }
                 rgn = lrgn->GetNextSubList();  
1422              }              }
1423          }          }
1424      }      }
# Line 1399  namespace DLS { Line 1437  namespace DLS {
1437      void Instrument::MoveRegion(Region* pSrc, Region* pDst) {      void Instrument::MoveRegion(Region* pSrc, Region* pDst) {
1438          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
1439          lrgn->MoveSubChunk(pSrc->pCkRegion, (RIFF::Chunk*) (pDst ? pDst->pCkRegion : 0));          lrgn->MoveSubChunk(pSrc->pCkRegion, (RIFF::Chunk*) (pDst ? pDst->pCkRegion : 0));
1440            for (size_t i = 0; i < pRegions->size(); ++i) {
1441          pRegions->remove(pSrc);              if ((*pRegions)[i] == pSrc) {
1442          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);                  pRegions->erase(pRegions->begin() + i);
1443          pRegions->insert(iter, pSrc);                  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);
1444                    pRegions->insert(iter, pSrc);
1445                }
1446            }
1447      }      }
1448    
1449      void Instrument::DeleteRegion(Region* pRegion) {      void Instrument::DeleteRegion(Region* pRegion) {
# Line 1524  namespace DLS { Line 1565  namespace DLS {
1565      void Instrument::CopyAssign(const Instrument* orig) {      void Instrument::CopyAssign(const Instrument* orig) {
1566          CopyAssignCore(orig);          CopyAssignCore(orig);
1567          // delete all regions first          // delete all regions first
1568          while (Regions) DeleteRegion(GetFirstRegion());          while (Regions) DeleteRegion(GetRegionAt(0));
1569          // now recreate and copy regions          // now recreate and copy regions
1570          {          {
1571              RegionList::const_iterator it = orig->pRegions->begin();              RegionList::const_iterator it = orig->pRegions->begin();
# Line 1660  namespace DLS { Line 1701  namespace DLS {
1701              delete pRIFF;              delete pRIFF;
1702      }      }
1703    
1704        /**
1705         * Returns Sample object of @a index.
1706         *
1707         * @param index - position of sample in sample list (0..n)
1708         * @returns sample object or NULL if index is out of bounds
1709         */
1710        Sample* File::GetSample(size_t index) {
1711            if (!pSamples) LoadSamples();
1712            if (!pSamples) return NULL;
1713            if (index >= pSamples->size()) return NULL;
1714            return (*pSamples)[index];
1715        }
1716    
1717        /**
1718         * Returns a pointer to the first <i>Sample</i> object of the file,
1719         * <i>NULL</i> otherwise.
1720         *
1721         * @deprecated  This method is not reentrant-safe, use GetSample()
1722         *              instead.
1723         */
1724      Sample* File::GetFirstSample() {      Sample* File::GetFirstSample() {
1725          if (!pSamples) LoadSamples();          if (!pSamples) LoadSamples();
1726          if (!pSamples) return NULL;          if (!pSamples) return NULL;
# Line 1667  namespace DLS { Line 1728  namespace DLS {
1728          return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;          return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1729      }      }
1730    
1731        /**
1732         * Returns a pointer to the next <i>Sample</i> object of the file,
1733         * <i>NULL</i> otherwise.
1734         *
1735         * @deprecated  This method is not reentrant-safe, use GetSample()
1736         *              instead.
1737         */
1738      Sample* File::GetNextSample() {      Sample* File::GetNextSample() {
1739          if (!pSamples) return NULL;          if (!pSamples) return NULL;
1740          SamplesIterator++;          SamplesIterator++;
# Line 1679  namespace DLS { Line 1747  namespace DLS {
1747          if (wvpl) {          if (wvpl) {
1748              file_offset_t wvplFileOffset = wvpl->GetFilePos() -              file_offset_t wvplFileOffset = wvpl->GetFilePos() -
1749                                             wvpl->GetPos(); // should be zero, but just to be sure                                             wvpl->GetPos(); // should be zero, but just to be sure
1750              RIFF::List* wave = wvpl->GetFirstSubList();              size_t i = 0;
1751              while (wave) {              for (RIFF::List* wave = wvpl->GetSubListAt(i); wave;
1752                     wave = wvpl->GetSubListAt(++i))
1753                {
1754                  if (wave->GetListType() == LIST_TYPE_WAVE) {                  if (wave->GetListType() == LIST_TYPE_WAVE) {
1755                      file_offset_t waveFileOffset = wave->GetFilePos() -                      file_offset_t waveFileOffset = wave->GetFilePos() -
1756                                                     wave->GetPos(); // should be zero, but just to be sure                                                     wave->GetPos(); // should be zero, but just to be sure
1757                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1758                  }                  }
                 wave = wvpl->GetNextSubList();  
1759              }              }
1760          }          }
1761          else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)          else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)
# Line 1694  namespace DLS { Line 1763  namespace DLS {
1763              if (dwpl) {              if (dwpl) {
1764                  file_offset_t dwplFileOffset = dwpl->GetFilePos() -                  file_offset_t dwplFileOffset = dwpl->GetFilePos() -
1765                                                 dwpl->GetPos(); // should be zero, but just to be sure                                                 dwpl->GetPos(); // should be zero, but just to be sure
1766                  RIFF::List* wave = dwpl->GetFirstSubList();                  size_t i = 0;
1767                  while (wave) {                  for (RIFF::List* wave = dwpl->GetSubListAt(i); wave;
1768                         wave = dwpl->GetSubListAt(++i))
1769                    {
1770                      if (wave->GetListType() == LIST_TYPE_WAVE) {                      if (wave->GetListType() == LIST_TYPE_WAVE) {
1771                          file_offset_t waveFileOffset = wave->GetFilePos() -                          file_offset_t waveFileOffset = wave->GetFilePos() -
1772                                                         wave->GetPos(); // should be zero, but just to be sure                                                         wave->GetPos(); // should be zero, but just to be sure
1773                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1774                      }                      }
                     wave = dwpl->GetNextSubList();  
1775                  }                  }
1776              }              }
1777          }          }
# Line 1758  namespace DLS { Line 1828  namespace DLS {
1828          if (!pInstruments) pInstruments = new InstrumentList;          if (!pInstruments) pInstruments = new InstrumentList;
1829          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1830          if (lstInstruments) {          if (lstInstruments) {
1831              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();              size_t i = 0;
1832              while (lstInstr) {              for (RIFF::List* lstInstr = lstInstruments->GetSubListAt(i);
1833                     lstInstr; lstInstr = lstInstruments->GetSubListAt(++i))
1834                {
1835                  if (lstInstr->GetListType() == LIST_TYPE_INS) {                  if (lstInstr->GetListType() == LIST_TYPE_INS) {
1836                      pInstruments->push_back(new Instrument(this, lstInstr));                      pInstruments->push_back(new Instrument(this, lstInstr));
1837                  }                  }
                 lstInstr = lstInstruments->GetNextSubList();  
1838              }              }
1839          }          }
1840      }      }

Legend:
Removed from v.3723  
changed lines
  Added in v.3929

  ViewVC Help
Powered by ViewVC