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

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

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

revision 2681 by schoenebeck, Mon Jul 7 15:20:22 2014 UTC revision 2682 by schoenebeck, Mon Dec 29 16:25:51 2014 UTC
# Line 53  Line 53 
53    
54  namespace gig {  namespace gig {
55    
 // *************** progress_t ***************  
 // *  
   
     progress_t::progress_t() {  
         callback    = NULL;  
         custom      = NULL;  
         __range_min = 0.0f;  
         __range_max = 1.0f;  
     }  
   
     // private helper function to convert progress of a subprocess into the global progress  
     static void __notify_progress(progress_t* pProgress, float subprogress) {  
         if (pProgress && pProgress->callback) {  
             const float totalrange    = pProgress->__range_max - pProgress->__range_min;  
             const float totalprogress = pProgress->__range_min + subprogress * totalrange;  
             pProgress->factor         = totalprogress;  
             pProgress->callback(pProgress); // now actually notify about the progress  
         }  
     }  
   
     // private helper function to divide a progress into subprogresses  
     static void __divide_progress(progress_t* pParentProgress, progress_t* pSubProgress, float totalTasks, float currentTask) {  
         if (pParentProgress && pParentProgress->callback) {  
             const float totalrange    = pParentProgress->__range_max - pParentProgress->__range_min;  
             pSubProgress->callback    = pParentProgress->callback;  
             pSubProgress->custom      = pParentProgress->custom;  
             pSubProgress->__range_min = pParentProgress->__range_min + totalrange * currentTask / totalTasks;  
             pSubProgress->__range_max = pSubProgress->__range_min + totalrange / totalTasks;  
         }  
     }  
   
   
56  // *************** Internal functions for sample decompression ***************  // *************** Internal functions for sample decompression ***************
57  // *  // *
58    
# Line 528  namespace { Line 496  namespace {
496       * Usually there is absolutely no need to call this method explicitly.       * Usually there is absolutely no need to call this method explicitly.
497       * It will be called automatically when File::Save() was called.       * It will be called automatically when File::Save() was called.
498       *       *
499         * @param pProgress - callback function for progress notification
500       * @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data       * @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data
501       *                        was provided yet       *                        was provided yet
502       * @throws gig::Exception if there is any invalid sample setting       * @throws gig::Exception if there is any invalid sample setting
503       */       */
504      void Sample::UpdateChunks() {      void Sample::UpdateChunks(progress_t* pProgress) {
505          // first update base class's chunks          // first update base class's chunks
506          DLS::Sample::UpdateChunks();          DLS::Sample::UpdateChunks(pProgress);
507    
508          // make sure 'smpl' chunk exists          // make sure 'smpl' chunk exists
509          pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL);          pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL);
# Line 1752  namespace { Line 1721  namespace {
1721       *       *
1722       * Usually there is absolutely no need to call this method explicitly.       * Usually there is absolutely no need to call this method explicitly.
1723       * It will be called automatically when File::Save() was called.       * It will be called automatically when File::Save() was called.
1724         *
1725         * @param pProgress - callback function for progress notification
1726       */       */
1727      void DimensionRegion::UpdateChunks() {      void DimensionRegion::UpdateChunks(progress_t* pProgress) {
1728          // first update base class's chunk          // first update base class's chunk
1729          DLS::Sampler::UpdateChunks();          DLS::Sampler::UpdateChunks(pProgress);
1730    
1731          RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);          RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);
1732          uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();          uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
# Line 3026  namespace { Line 2997  namespace {
2997       * Usually there is absolutely no need to call this method explicitly.       * Usually there is absolutely no need to call this method explicitly.
2998       * It will be called automatically when File::Save() was called.       * It will be called automatically when File::Save() was called.
2999       *       *
3000         * @param pProgress - callback function for progress notification
3001       * @throws gig::Exception if samples cannot be dereferenced       * @throws gig::Exception if samples cannot be dereferenced
3002       */       */
3003      void Region::UpdateChunks() {      void Region::UpdateChunks(progress_t* pProgress) {
3004          // in the gig format we don't care about the Region's sample reference          // in the gig format we don't care about the Region's sample reference
3005          // but we still have to provide some existing one to not corrupt the          // but we still have to provide some existing one to not corrupt the
3006          // file, so to avoid the latter we simply always assign the sample of          // file, so to avoid the latter we simply always assign the sample of
# Line 3036  namespace { Line 3008  namespace {
3008          pSample = pDimensionRegions[0]->pSample;          pSample = pDimensionRegions[0]->pSample;
3009    
3010          // first update base class's chunks          // first update base class's chunks
3011          DLS::Region::UpdateChunks();          DLS::Region::UpdateChunks(pProgress);
3012    
3013          // update dimension region's chunks          // update dimension region's chunks
3014          for (int i = 0; i < DimensionRegions; i++) {          for (int i = 0; i < DimensionRegions; i++) {
3015              pDimensionRegions[i]->UpdateChunks();              pDimensionRegions[i]->UpdateChunks(pProgress);
3016          }          }
3017    
3018          File* pFile = (File*) GetParent()->GetParent();          File* pFile = (File*) GetParent()->GetParent();
# Line 4161  namespace { Line 4133  namespace {
4133          memcpy(&data[0], &text[0], text.size());          memcpy(&data[0], &text[0], text.size());
4134      }      }
4135    
4136      void Script::UpdateChunks() {      /**
4137         * Apply this script to the respective RIFF chunks. You have to call
4138         * File::Save() to make changes persistent.
4139         *
4140         * Usually there is absolutely no need to call this method explicitly.
4141         * It will be called automatically when File::Save() was called.
4142         *
4143         * @param pProgress - callback function for progress notification
4144         */
4145        void Script::UpdateChunks(progress_t* pProgress) {
4146          // recalculate CRC32 check sum          // recalculate CRC32 check sum
4147          __resetCRC(crc);          __resetCRC(crc);
4148          __calculateCRC(&data[0], data.size(), crc);          __calculateCRC(&data[0], data.size(), crc);
# Line 4251  namespace { Line 4232  namespace {
4232          }          }
4233      }      }
4234    
4235      void ScriptGroup::UpdateChunks() {      /**
4236         * Apply this script group to the respective RIFF chunks. You have to call
4237         * File::Save() to make changes persistent.
4238         *
4239         * Usually there is absolutely no need to call this method explicitly.
4240         * It will be called automatically when File::Save() was called.
4241         *
4242         * @param pProgress - callback function for progress notification
4243         */
4244        void ScriptGroup::UpdateChunks(progress_t* pProgress) {
4245          if (pScripts) {          if (pScripts) {
4246              if (!pList)              if (!pList)
4247                  pList = pFile->pRIFF->GetSubList(LIST_TYPE_3LS)->AddSubList(LIST_TYPE_RTIS);                  pList = pFile->pRIFF->GetSubList(LIST_TYPE_3LS)->AddSubList(LIST_TYPE_RTIS);
# Line 4262  namespace { Line 4252  namespace {
4252              for (std::list<Script*>::iterator it = pScripts->begin();              for (std::list<Script*>::iterator it = pScripts->begin();
4253                   it != pScripts->end(); ++it)                   it != pScripts->end(); ++it)
4254              {              {
4255                  (*it)->UpdateChunks();                  (*it)->UpdateChunks(pProgress);
4256              }              }
4257          }          }
4258      }      }
# Line 4472  namespace { Line 4462  namespace {
4462       * Usually there is absolutely no need to call this method explicitly.       * Usually there is absolutely no need to call this method explicitly.
4463       * It will be called automatically when File::Save() was called.       * It will be called automatically when File::Save() was called.
4464       *       *
4465         * @param pProgress - callback function for progress notification
4466       * @throws gig::Exception if samples cannot be dereferenced       * @throws gig::Exception if samples cannot be dereferenced
4467       */       */
4468      void Instrument::UpdateChunks() {      void Instrument::UpdateChunks(progress_t* pProgress) {
4469          // first update base classes' chunks          // first update base classes' chunks
4470          DLS::Instrument::UpdateChunks();          DLS::Instrument::UpdateChunks(pProgress);
4471    
4472          // update Regions' chunks          // update Regions' chunks
4473          {          {
4474              RegionList::iterator iter = pRegions->begin();              RegionList::iterator iter = pRegions->begin();
4475              RegionList::iterator end  = pRegions->end();              RegionList::iterator end  = pRegions->end();
4476              for (; iter != end; ++iter)              for (; iter != end; ++iter)
4477                  (*iter)->UpdateChunks();                  (*iter)->UpdateChunks(pProgress);
4478          }          }
4479    
4480          // make sure 'lart' RIFF list chunk exists          // make sure 'lart' RIFF list chunk exists
# Line 5004  namespace { Line 4995  namespace {
4995       *       *
4996       * Usually there is absolutely no need to call this method explicitly.       * Usually there is absolutely no need to call this method explicitly.
4997       * It will be called automatically when File::Save() was called.       * It will be called automatically when File::Save() was called.
4998         *
4999         * @param pProgress - callback function for progress notification
5000       */       */
5001      void Group::UpdateChunks() {      void Group::UpdateChunks(progress_t* pProgress) {
5002          // make sure <3gri> and <3gnl> list chunks exist          // make sure <3gri> and <3gnl> list chunks exist
5003          RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI);          RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI);
5004          if (!_3gri) {          if (!_3gri) {
# Line 5781  namespace { Line 5774  namespace {
5774       * Usually there is absolutely no need to call this method explicitly.       * Usually there is absolutely no need to call this method explicitly.
5775       * It will be called automatically when File::Save() was called.       * It will be called automatically when File::Save() was called.
5776       *       *
5777         * @param pProgress - callback function for progress notification
5778       * @throws Exception - on errors       * @throws Exception - on errors
5779       */       */
5780      void File::UpdateChunks() {      void File::UpdateChunks(progress_t* pProgress) {
5781          bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL;          bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL;
5782    
5783          b64BitWavePoolOffsets = pVersion && pVersion->major == 3;          b64BitWavePoolOffsets = pVersion && pVersion->major == 3;
# Line 5806  namespace { Line 5800  namespace {
5800                  for (std::list<ScriptGroup*>::iterator it = pScriptGroups->begin();                  for (std::list<ScriptGroup*>::iterator it = pScriptGroups->begin();
5801                       it != pScriptGroups->end(); ++it)                       it != pScriptGroups->end(); ++it)
5802                  {                  {
5803                      (*it)->UpdateChunks();                      (*it)->UpdateChunks(pProgress);
5804                  }                  }
5805              }              }
5806          }          }
5807    
5808          // first update base class's chunks          // first update base class's chunks
5809          DLS::File::UpdateChunks();          DLS::File::UpdateChunks(pProgress);
5810    
5811          if (newFile) {          if (newFile) {
5812              // INFO was added by Resource::UpdateChunks - make sure it              // INFO was added by Resource::UpdateChunks - make sure it
# Line 5849  namespace { Line 5843  namespace {
5843              std::list<Group*>::iterator iter = pGroups->begin();              std::list<Group*>::iterator iter = pGroups->begin();
5844              std::list<Group*>::iterator end  = pGroups->end();              std::list<Group*>::iterator end  = pGroups->end();
5845              for (; iter != end; ++iter) {              for (; iter != end; ++iter) {
5846                  (*iter)->UpdateChunks();                  (*iter)->UpdateChunks(pProgress);
5847              }              }
5848          }          }
5849    

Legend:
Removed from v.2681  
changed lines
  Added in v.2682

  ViewVC Help
Powered by ViewVC