/[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 3941 by schoenebeck, Fri Jun 18 14:06:20 2021 UTC revision 3949 by schoenebeck, Sat Jun 19 08:35:48 2021 UTC
# Line 4801  namespace { Line 4801  namespace {
4801    
4802      ScriptGroup::~ScriptGroup() {      ScriptGroup::~ScriptGroup() {
4803          if (pScripts) {          if (pScripts) {
4804              std::list<Script*>::iterator iter = pScripts->begin();              std::vector<Script*>::iterator iter = pScripts->begin();
4805              std::list<Script*>::iterator end  = pScripts->end();              std::vector<Script*>::iterator end  = pScripts->end();
4806              while (iter != end) {              while (iter != end) {
4807                  delete *iter;                  delete *iter;
4808                  ++iter;                  ++iter;
# Line 4840  namespace { Line 4840  namespace {
4840              // now store the name of this group as <LSNM> chunk as subchunk of the <RTIS> list chunk              // now store the name of this group as <LSNM> chunk as subchunk of the <RTIS> list chunk
4841              ::SaveString(CHUNK_ID_LSNM, NULL, pList, Name, String("Unnamed Group"), true, 64);              ::SaveString(CHUNK_ID_LSNM, NULL, pList, Name, String("Unnamed Group"), true, 64);
4842    
4843              for (std::list<Script*>::iterator it = pScripts->begin();              for (std::vector<Script*>::iterator it = pScripts->begin();
4844                   it != pScripts->end(); ++it)                   it != pScripts->end(); ++it)
4845              {              {
4846                  (*it)->UpdateChunks(pProgress);                  (*it)->UpdateChunks(pProgress);
# Line 4857  namespace { Line 4857  namespace {
4857       */       */
4858      Script* ScriptGroup::GetScript(uint index) {      Script* ScriptGroup::GetScript(uint index) {
4859          if (!pScripts) LoadScripts();          if (!pScripts) LoadScripts();
4860          std::list<Script*>::iterator it = pScripts->begin();          if (index >= pScripts->size()) return NULL;
4861          for (uint i = 0; it != pScripts->end(); ++i, ++it)          return (*pScripts)[index];
             if (i == index) return *it;  
         return NULL;  
4862      }      }
4863    
4864      /** @brief Add new instrument script.      /** @brief Add new instrument script.
# Line 4893  namespace { Line 4891  namespace {
4891       */       */
4892      void ScriptGroup::DeleteScript(Script* pScript) {      void ScriptGroup::DeleteScript(Script* pScript) {
4893          if (!pScripts) LoadScripts();          if (!pScripts) LoadScripts();
4894          std::list<Script*>::iterator iter =          std::vector<Script*>::iterator iter =
4895              find(pScripts->begin(), pScripts->end(), pScript);              find(pScripts->begin(), pScripts->end(), pScript);
4896          if (iter == pScripts->end())          if (iter == pScripts->end())
4897              throw gig::Exception("Could not delete script, could not find given script");              throw gig::Exception("Could not delete script, could not find given script");
# Line 4906  namespace { Line 4904  namespace {
4904    
4905      void ScriptGroup::LoadScripts() {      void ScriptGroup::LoadScripts() {
4906          if (pScripts) return;          if (pScripts) return;
4907          pScripts = new std::list<Script*>;          pScripts = new std::vector<Script*>;
4908          if (!pList) return;          if (!pList) return;
4909    
4910          size_t i = 0;          size_t i = 0;
# Line 5503  namespace { Line 5501  namespace {
5501          File* pFile = (File*) GetParent();          File* pFile = (File*) GetParent();
5502          for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) {          for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) {
5503              uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset;              uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset;
5504              for (uint i = 0; pFile->GetScriptGroup(i); ++i) {              for (size_t i = 0; pFile->GetScriptGroup(i); ++i) {
5505                  ScriptGroup* group = pFile->GetScriptGroup(i);                  ScriptGroup* group = pFile->GetScriptGroup(i);
5506                  for (uint s = 0; group->GetScript(s); ++s) {                  for (uint s = 0; group->GetScript(s); ++s) {
5507                      Script* script = group->GetScript(s);                      Script* script = group->GetScript(s);
# Line 6412  namespace { Line 6410  namespace {
6410          pSample->DeleteChunks();          pSample->DeleteChunks();
6411          delete pSample;          delete pSample;
6412    
         SampleList::iterator tmp = SamplesIterator;  
6413          // remove all references to the sample          // remove all references to the sample
6414          for (Instrument* instrument = GetFirstInstrument() ; instrument ;          size_t iIns = 0;
6415               instrument = GetNextInstrument()) {          for (Instrument* instrument = GetInstrument(iIns); instrument;
6416                             instrument = GetInstrument(++iIns))
6417            {
6418              size_t iRgn = 0;              size_t iRgn = 0;
6419              for (Region* region = instrument->GetRegionAt(iRgn); region;              for (Region* region = instrument->GetRegionAt(iRgn); region;
6420                   region = instrument->GetRegionAt(++iRgn))                   region = instrument->GetRegionAt(++iRgn))
# Line 6428  namespace { Line 6427  namespace {
6427                  }                  }
6428              }              }
6429          }          }
         SamplesIterator = tmp; // restore iterator  
6430      }      }
6431    
6432      void File::LoadSamples() {      void File::LoadSamples() {
# Line 6546  namespace { Line 6544  namespace {
6544              __notify_progress(pProgress, 1.0); // notify done              __notify_progress(pProgress, 1.0); // notify done
6545      }      }
6546    
6547        /**
6548         * Returns a pointer to the first <i>Instrument</i> object of the file,
6549         * <i>NULL</i> otherwise.
6550         *
6551         * @deprecated  This method is not reentrant-safe, use GetInstrument()
6552         *              instead.
6553         */
6554      Instrument* File::GetFirstInstrument() {      Instrument* File::GetFirstInstrument() {
6555          if (!pInstruments) LoadInstruments();          if (!pInstruments) LoadInstruments();
6556          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
# Line 6553  namespace { Line 6558  namespace {
6558          return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL );          return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL );
6559      }      }
6560    
6561        /**
6562         * Returns a pointer to the next <i>Instrument</i> object of the file,
6563         * <i>NULL</i> otherwise.
6564         *
6565         * @deprecated  This method is not reentrant-safe, use GetInstrument()
6566         *              instead.
6567         */
6568      Instrument* File::GetNextInstrument() {      Instrument* File::GetNextInstrument() {
6569          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
6570          InstrumentsIterator++;          InstrumentsIterator++;
# Line 6580  namespace { Line 6592  namespace {
6592       * @param pProgress - optional: callback function for progress notification       * @param pProgress - optional: callback function for progress notification
6593       * @returns  sought instrument or NULL if there's no such instrument       * @returns  sought instrument or NULL if there's no such instrument
6594       */       */
6595      Instrument* File::GetInstrument(uint index, progress_t* pProgress) {      Instrument* File::GetInstrument(size_t index, progress_t* pProgress) {
6596          if (!pInstruments) {          if (!pInstruments) {
6597              // TODO: hack - we simply load ALL samples here, it would have been done in the Region constructor anyway (ATM)              // TODO: hack - we simply load ALL samples here, it would have been done in the Region constructor anyway (ATM)
6598    
# Line 6611  namespace { Line 6623  namespace {
6623              }              }
6624          }          }
6625          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
6626          InstrumentsIterator = pInstruments->begin();          if (index >= pInstruments->size()) return NULL;
6627          for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) {          return static_cast<gig::Instrument*>( (*pInstruments)[index] );
             if (i == index) return static_cast<gig::Instrument*>( *InstrumentsIterator );  
             InstrumentsIterator++;  
         }  
         return NULL;  
6628      }      }
6629    
6630      /** @brief Add a new instrument definition.      /** @brief Add a new instrument definition.
# Line 6703  namespace { Line 6711  namespace {
6711          }          }
6712    
6713          // clone script groups and their scripts          // clone script groups and their scripts
6714          for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) {          for (size_t iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) {
6715              ScriptGroup* sg = pFile->GetScriptGroup(iGroup);              ScriptGroup* sg = pFile->GetScriptGroup(iGroup);
6716              ScriptGroup* dg = AddScriptGroup();              ScriptGroup* dg = AddScriptGroup();
6717              dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name;              dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name;
# Line 7095  namespace { Line 7103  namespace {
7103       * @param index - number of the sought group (0..n)       * @param index - number of the sought group (0..n)
7104       * @returns sought script group or NULL if there's no such group       * @returns sought script group or NULL if there's no such group
7105       */       */
7106      ScriptGroup* File::GetScriptGroup(uint index) {      ScriptGroup* File::GetScriptGroup(size_t index) {
7107          if (!pScriptGroups) LoadScriptGroups();          if (!pScriptGroups) LoadScriptGroups();
7108          std::list<ScriptGroup*>::iterator it = pScriptGroups->begin();          std::list<ScriptGroup*>::iterator it = pScriptGroups->begin();
7109          for (uint i = 0; it != pScriptGroups->end(); ++i, ++it)          for (uint i = 0; it != pScriptGroups->end(); ++i, ++it)
# Line 7315  namespace { Line 7323  namespace {
7323    
7324              memset(&pData[48], 0, sublen - 48);              memset(&pData[48], 0, sublen - 48);
7325    
7326              for (Instrument* instrument = GetFirstInstrument() ; instrument ;              size_t iIns = 0;
7327                   instrument = GetNextInstrument()) {              for (Instrument* instrument = GetInstrument(iIns); instrument;
7328                                 instrument = GetInstrument(++iIns))
7329                {
7330                  int nbusedsamples = 0;                  int nbusedsamples = 0;
7331                  int nbusedchannels = 0;                  int nbusedchannels = 0;
7332                  int nbdimregions = 0;                  int nbdimregions = 0;
# Line 7421  namespace { Line 7431  namespace {
7431      void File::UpdateFileOffsets() {      void File::UpdateFileOffsets() {
7432          DLS::File::UpdateFileOffsets();          DLS::File::UpdateFileOffsets();
7433    
7434          for (Instrument* instrument = GetFirstInstrument(); instrument;          size_t i = 0;
7435               instrument = GetNextInstrument())          for (Instrument* instrument = GetInstrument(i); instrument;
7436                             instrument = GetInstrument(++i))
7437          {          {
7438              instrument->UpdateScriptFileOffsets();              instrument->UpdateScriptFileOffsets();
7439          }          }

Legend:
Removed from v.3941  
changed lines
  Added in v.3949

  ViewVC Help
Powered by ViewVC