/[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 3929 by schoenebeck, Tue Jun 15 12:22:26 2021 UTC revision 3946 by schoenebeck, Fri Jun 18 15:51:32 2021 UTC
# Line 609  namespace { Line 609  namespace {
609          uint16_t iSampleGroup = 0; // 0 refers to default sample group          uint16_t iSampleGroup = 0; // 0 refers to default sample group
610          File* pFile = static_cast<File*>(pParent);          File* pFile = static_cast<File*>(pParent);
611          if (pFile->pGroups) {          if (pFile->pGroups) {
612              std::list<Group*>::iterator iter = pFile->pGroups->begin();              std::vector<Group*>::iterator iter = pFile->pGroups->begin();
613              std::list<Group*>::iterator end  = pFile->pGroups->end();              std::vector<Group*>::iterator end  = pFile->pGroups->end();
614              for (int i = 0; iter != end; i++, iter++) {              for (int i = 0; iter != end; i++, iter++) {
615                  if (*iter == pGroup) {                  if (*iter == pGroup) {
616                      iSampleGroup = i;                      iSampleGroup = i;
# Line 5394  namespace { Line 5394  namespace {
5394       * @param dst - destination instrument at which this instrument will be       * @param dst - destination instrument at which this instrument will be
5395       *              moved to, or pass NULL for moving to end of list       *              moved to, or pass NULL for moving to end of list
5396       * @throw gig::Exception if this instrument and target instrument are not       * @throw gig::Exception if this instrument and target instrument are not
5397       *                       part of the same file       *                       part of the same file, as well as on unexpected
5398         *                       internal error
5399       */       */
5400      void Instrument::MoveTo(Instrument* dst) {      void Instrument::MoveTo(Instrument* dst) {
5401          if (dst && GetParent() != dst->GetParent())          if (dst && GetParent() != dst->GetParent())
# Line 5411  namespace { Line 5412  namespace {
5412    
5413              File::InstrumentList::iterator itFrom =              File::InstrumentList::iterator itFrom =
5414                  std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(this));                  std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(this));
5415                if (itFrom == list.end())
5416                    throw Exception(
5417                        "gig::Instrument::MoveTo(): unexpected missing membership "
5418                        "of this instrument."
5419                    );
5420                list.erase(itFrom);
5421    
5422              File::InstrumentList::iterator itTo =              File::InstrumentList::iterator itTo =
5423                  std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(dst));                  std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(dst));
5424    
5425              list.splice(itTo, list, itFrom);              list.insert(itTo, this);
5426          }          }
5427    
5428          // move the instrument's actual list RIFF chunk appropriately          // move the instrument's actual list RIFF chunk appropriately
# Line 6122  namespace { Line 6129  namespace {
6129      }      }
6130    
6131      /**      /**
6132         * Returns Sample object at @a index of this sample group.
6133         *
6134         * @param index - position of sample in this sample group's sample list
6135         *                (0..n)
6136         * @returns sample object or NULL if index is out of bounds
6137         */
6138        Sample* Group::GetSample(size_t index) {
6139            if (pFile->pSamples && index >= pFile->pSamples->size()) return NULL;
6140            size_t indexInFile = 0;
6141            size_t indexInGroup = 0;
6142            for (Sample* pSample = pFile->GetSample(indexInFile); pSample;
6143                         pSample = pFile->GetSample(++indexInFile))
6144            {
6145                if (pSample->GetGroup() != this) continue;
6146                if (indexInGroup++ == index) return pSample;
6147            }
6148            return NULL;
6149        }
6150    
6151        /**
6152       * Returns the first Sample of this Group. You have to call this method       * Returns the first Sample of this Group. You have to call this method
6153       * once before you use GetNextSample().       * once before you use GetNextSample().
6154       *       *
# Line 6131  namespace { Line 6158  namespace {
6158       * @returns  pointer address to first Sample or NULL if there is none       * @returns  pointer address to first Sample or NULL if there is none
6159       *           applied to this Group       *           applied to this Group
6160       * @see      GetNextSample()       * @see      GetNextSample()
6161         * @deprecated  This method is not reentrant-safe, use GetSample()
6162         *              instead.
6163       */       */
6164      Sample* Group::GetFirstSample() {      Sample* Group::GetFirstSample() {
6165          size_t& i = this->SamplesIterator;          size_t& i = this->SamplesIterator;
# Line 6153  namespace { Line 6182  namespace {
6182       * @returns  pointer address to the next Sample of this Group or NULL if       * @returns  pointer address to the next Sample of this Group or NULL if
6183       *           end reached       *           end reached
6184       * @see      GetFirstSample()       * @see      GetFirstSample()
6185         * @deprecated  This method is not reentrant-safe, use GetSample()
6186         *              instead.
6187       */       */
6188      Sample* Group::GetNextSample() {      Sample* Group::GetNextSample() {
6189          size_t& i = this->SamplesIterator;          size_t& i = this->SamplesIterator;
# Line 6180  namespace { Line 6211  namespace {
6211       */       */
6212      void Group::MoveAll() {      void Group::MoveAll() {
6213          // get "that" other group first          // get "that" other group first
6214            size_t i = 0;
6215          Group* pOtherGroup = NULL;          Group* pOtherGroup = NULL;
6216          for (pOtherGroup = pFile->GetFirstGroup(); pOtherGroup; pOtherGroup = pFile->GetNextGroup()) {          for (pOtherGroup = pFile->GetGroup(i); pOtherGroup;
6217                 pOtherGroup = pFile->GetGroup(++i))
6218            {
6219              if (pOtherGroup != this) break;              if (pOtherGroup != this) break;
6220          }          }
6221          if (!pOtherGroup) throw Exception(          if (!pOtherGroup) throw Exception(
# Line 6189  namespace { Line 6223  namespace {
6223              "other Group. This is a bug, report it!"              "other Group. This is a bug, report it!"
6224          );          );
6225          // now move all samples of this group to the other group          // now move all samples of this group to the other group
6226          for (Sample* pSample = GetFirstSample(); pSample; pSample = GetNextSample()) {          Sample* pSample;
6227            while ((pSample = GetSample(0))) {
6228              pOtherGroup->AddSample(pSample);              pOtherGroup->AddSample(pSample);
6229          }          }
6230      }      }
# Line 6261  namespace { Line 6296  namespace {
6296    
6297      File::~File() {      File::~File() {
6298          if (pGroups) {          if (pGroups) {
6299              std::list<Group*>::iterator iter = pGroups->begin();              std::vector<Group*>::iterator iter = pGroups->begin();
6300              std::list<Group*>::iterator end  = pGroups->end();              std::vector<Group*>::iterator end  = pGroups->end();
6301              while (iter != end) {              while (iter != end) {
6302                  delete *iter;                  delete *iter;
6303                  ++iter;                  ++iter;
# Line 6377  namespace { Line 6412  namespace {
6412          pSample->DeleteChunks();          pSample->DeleteChunks();
6413          delete pSample;          delete pSample;
6414    
         SampleList::iterator tmp = SamplesIterator;  
6415          // remove all references to the sample          // remove all references to the sample
6416          for (Instrument* instrument = GetFirstInstrument() ; instrument ;          size_t iIns = 0;
6417               instrument = GetNextInstrument()) {          for (Instrument* instrument = GetInstrument(iIns); instrument;
6418                             instrument = GetInstrument(++iIns))
6419            {
6420              size_t iRgn = 0;              size_t iRgn = 0;
6421              for (Region* region = instrument->GetRegionAt(iRgn); region;              for (Region* region = instrument->GetRegionAt(iRgn); region;
6422                   region = instrument->GetRegionAt(++iRgn))                   region = instrument->GetRegionAt(++iRgn))
# Line 6393  namespace { Line 6429  namespace {
6429                  }                  }
6430              }              }
6431          }          }
         SamplesIterator = tmp; // restore iterator  
6432      }      }
6433    
6434      void File::LoadSamples() {      void File::LoadSamples() {
# Line 6511  namespace { Line 6546  namespace {
6546              __notify_progress(pProgress, 1.0); // notify done              __notify_progress(pProgress, 1.0); // notify done
6547      }      }
6548    
6549        /**
6550         * Returns a pointer to the first <i>Instrument</i> object of the file,
6551         * <i>NULL</i> otherwise.
6552         *
6553         * @deprecated  This method is not reentrant-safe, use GetInstrument()
6554         *              instead.
6555         */
6556      Instrument* File::GetFirstInstrument() {      Instrument* File::GetFirstInstrument() {
6557          if (!pInstruments) LoadInstruments();          if (!pInstruments) LoadInstruments();
6558          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
# Line 6518  namespace { Line 6560  namespace {
6560          return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL );          return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL );
6561      }      }
6562    
6563        /**
6564         * Returns a pointer to the next <i>Instrument</i> object of the file,
6565         * <i>NULL</i> otherwise.
6566         *
6567         * @deprecated  This method is not reentrant-safe, use GetInstrument()
6568         *              instead.
6569         */
6570      Instrument* File::GetNextInstrument() {      Instrument* File::GetNextInstrument() {
6571          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
6572          InstrumentsIterator++;          InstrumentsIterator++;
# Line 6545  namespace { Line 6594  namespace {
6594       * @param pProgress - optional: callback function for progress notification       * @param pProgress - optional: callback function for progress notification
6595       * @returns  sought instrument or NULL if there's no such instrument       * @returns  sought instrument or NULL if there's no such instrument
6596       */       */
6597      Instrument* File::GetInstrument(uint index, progress_t* pProgress) {      Instrument* File::GetInstrument(size_t index, progress_t* pProgress) {
6598          if (!pInstruments) {          if (!pInstruments) {
6599              // 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)
6600    
# Line 6576  namespace { Line 6625  namespace {
6625              }              }
6626          }          }
6627          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
6628          InstrumentsIterator = pInstruments->begin();          if (index >= pInstruments->size()) return NULL;
6629          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;  
6630      }      }
6631    
6632      /** @brief Add a new instrument definition.      /** @brief Add a new instrument definition.
# Line 6912  namespace { Line 6957  namespace {
6957          return bRequiresSave;          return bRequiresSave;
6958      }      }
6959    
6960        /**
6961         * Returns a pointer to the first <i>Group</i> object of the file,
6962         * <i>NULL</i> otherwise.
6963         *
6964         * @deprecated  This method is not reentrant-safe, use GetGroup() instead.
6965         */
6966      Group* File::GetFirstGroup() {      Group* File::GetFirstGroup() {
6967          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
6968          // there must always be at least one group          // there must always be at least one group
# Line 6919  namespace { Line 6970  namespace {
6970          return *GroupsIterator;          return *GroupsIterator;
6971      }      }
6972    
6973        /**
6974         * Returns a pointer to the next <i>Group</i> object of the file,
6975         * <i>NULL</i> otherwise.
6976         *
6977         * @deprecated  This method is not reentrant-safe, use GetGroup() instead.
6978         */
6979      Group* File::GetNextGroup() {      Group* File::GetNextGroup() {
6980          if (!pGroups) return NULL;          if (!pGroups) return NULL;
6981          ++GroupsIterator;          ++GroupsIterator;
# Line 6931  namespace { Line 6988  namespace {
6988       * @param index - number of the sought group (0..n)       * @param index - number of the sought group (0..n)
6989       * @returns sought group or NULL if there's no such group       * @returns sought group or NULL if there's no such group
6990       */       */
6991      Group* File::GetGroup(uint index) {      Group* File::GetGroup(size_t index) {
6992          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
6993          GroupsIterator = pGroups->begin();          if (index >= pGroups->size()) return NULL;
6994          for (uint i = 0; GroupsIterator != pGroups->end(); i++) {          return (*pGroups)[index];
             if (i == index) return *GroupsIterator;  
             ++GroupsIterator;  
         }  
         return NULL;  
6995      }      }
6996    
6997      /**      /**
# Line 6953  namespace { Line 7006  namespace {
7006       */       */
7007      Group* File::GetGroup(String name) {      Group* File::GetGroup(String name) {
7008          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
7009          GroupsIterator = pGroups->begin();          size_t i = 0;
7010          for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i)          for (Group* pGroup = GetGroup(i); pGroup; pGroup = GetGroup(++i))
7011              if ((*GroupsIterator)->Name == name) return *GroupsIterator;              if (pGroup->Name == name) return pGroup;
7012          return NULL;          return NULL;
7013      }      }
7014    
# Line 6979  namespace { Line 7032  namespace {
7032       */       */
7033      void File::DeleteGroup(Group* pGroup) {      void File::DeleteGroup(Group* pGroup) {
7034          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
7035          std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);          std::vector<Group*>::iterator iter =
7036                find(pGroups->begin(), pGroups->end(), pGroup);
7037          if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");          if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");
7038          if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");          if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");
7039          // delete all members of this group          // delete all members of this group
7040          for (Sample* pSample = pGroup->GetFirstSample(); pSample; pSample = pGroup->GetNextSample()) {          Sample* pSample;
7041            while ((pSample = pGroup->GetSample(0))) {
7042              DeleteSample(pSample);              DeleteSample(pSample);
7043          }          }
7044          // now delete this group object          // now delete this group object
# Line 7004  namespace { Line 7059  namespace {
7059       */       */
7060      void File::DeleteGroupOnly(Group* pGroup) {      void File::DeleteGroupOnly(Group* pGroup) {
7061          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
7062          std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);          std::vector<Group*>::iterator iter =
7063                find(pGroups->begin(), pGroups->end(), pGroup);
7064          if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");          if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");
7065          if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");          if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");
7066          // move all members of this group to another group          // move all members of this group to another group
# Line 7015  namespace { Line 7071  namespace {
7071      }      }
7072    
7073      void File::LoadGroups() {      void File::LoadGroups() {
7074          if (!pGroups) pGroups = new std::list<Group*>;          if (!pGroups) pGroups = new std::vector<Group*>;
7075          // try to read defined groups from file          // try to read defined groups from file
7076          RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI);          RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI);
7077          if (lst3gri) {          if (lst3gri) {
# Line 7214  namespace { Line 7270  namespace {
7270                  }                  }
7271              }              }
7272    
7273              std::list<Group*>::iterator iter = pGroups->begin();              std::vector<Group*>::iterator iter = pGroups->begin();
7274              std::list<Group*>::iterator end  = pGroups->end();              std::vector<Group*>::iterator end  = pGroups->end();
7275              for (; iter != end; ++iter) {              for (; iter != end; ++iter) {
7276                  (*iter)->UpdateChunks(pProgress);                  (*iter)->UpdateChunks(pProgress);
7277              }              }
# Line 7269  namespace { Line 7325  namespace {
7325    
7326              memset(&pData[48], 0, sublen - 48);              memset(&pData[48], 0, sublen - 48);
7327    
7328              for (Instrument* instrument = GetFirstInstrument() ; instrument ;              size_t iIns = 0;
7329                   instrument = GetNextInstrument()) {              for (Instrument* instrument = GetInstrument(iIns); instrument;
7330                                 instrument = GetInstrument(++iIns))
7331                {
7332                  int nbusedsamples = 0;                  int nbusedsamples = 0;
7333                  int nbusedchannels = 0;                  int nbusedchannels = 0;
7334                  int nbdimregions = 0;                  int nbdimregions = 0;
# Line 7375  namespace { Line 7433  namespace {
7433      void File::UpdateFileOffsets() {      void File::UpdateFileOffsets() {
7434          DLS::File::UpdateFileOffsets();          DLS::File::UpdateFileOffsets();
7435    
7436          for (Instrument* instrument = GetFirstInstrument(); instrument;          size_t i = 0;
7437               instrument = GetNextInstrument())          for (Instrument* instrument = GetInstrument(i); instrument;
7438                             instrument = GetInstrument(++i))
7439          {          {
7440              instrument->UpdateScriptFileOffsets();              instrument->UpdateScriptFileOffsets();
7441          }          }

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

  ViewVC Help
Powered by ViewVC