/[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 3933 by schoenebeck, Thu Jun 17 09:21:11 2021 UTC revision 3945 by schoenebeck, Fri Jun 18 15:46:44 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 6204  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 6213  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 6285  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 6403  namespace { Line 6414  namespace {
6414    
6415          SampleList::iterator tmp = SamplesIterator;          SampleList::iterator tmp = SamplesIterator;
6416          // remove all references to the sample          // remove all references to the sample
6417          for (Instrument* instrument = GetFirstInstrument() ; instrument ;          size_t iIns = 0;
6418               instrument = GetNextInstrument()) {          for (Instrument* instrument = GetInstrument(iIns); instrument;
6419                             instrument = GetInstrument(++iIns))
6420            {
6421              size_t iRgn = 0;              size_t iRgn = 0;
6422              for (Region* region = instrument->GetRegionAt(iRgn); region;              for (Region* region = instrument->GetRegionAt(iRgn); region;
6423                   region = instrument->GetRegionAt(++iRgn))                   region = instrument->GetRegionAt(++iRgn))
# Line 6535  namespace { Line 6548  namespace {
6548              __notify_progress(pProgress, 1.0); // notify done              __notify_progress(pProgress, 1.0); // notify done
6549      }      }
6550    
6551        /**
6552         * Returns a pointer to the first <i>Instrument</i> object of the file,
6553         * <i>NULL</i> otherwise.
6554         *
6555         * @deprecated  This method is not reentrant-safe, use GetInstrument()
6556         *              instead.
6557         */
6558      Instrument* File::GetFirstInstrument() {      Instrument* File::GetFirstInstrument() {
6559          if (!pInstruments) LoadInstruments();          if (!pInstruments) LoadInstruments();
6560          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
# Line 6542  namespace { Line 6562  namespace {
6562          return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL );          return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL );
6563      }      }
6564    
6565        /**
6566         * Returns a pointer to the next <i>Instrument</i> object of the file,
6567         * <i>NULL</i> otherwise.
6568         *
6569         * @deprecated  This method is not reentrant-safe, use GetInstrument()
6570         *              instead.
6571         */
6572      Instrument* File::GetNextInstrument() {      Instrument* File::GetNextInstrument() {
6573          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
6574          InstrumentsIterator++;          InstrumentsIterator++;
# Line 6569  namespace { Line 6596  namespace {
6596       * @param pProgress - optional: callback function for progress notification       * @param pProgress - optional: callback function for progress notification
6597       * @returns  sought instrument or NULL if there's no such instrument       * @returns  sought instrument or NULL if there's no such instrument
6598       */       */
6599      Instrument* File::GetInstrument(uint index, progress_t* pProgress) {      Instrument* File::GetInstrument(size_t index, progress_t* pProgress) {
6600          if (!pInstruments) {          if (!pInstruments) {
6601              // 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)
6602    
# Line 6600  namespace { Line 6627  namespace {
6627              }              }
6628          }          }
6629          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
6630          InstrumentsIterator = pInstruments->begin();          if (index >= pInstruments->size()) return NULL;
6631          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;  
6632      }      }
6633    
6634      /** @brief Add a new instrument definition.      /** @brief Add a new instrument definition.
# Line 6936  namespace { Line 6959  namespace {
6959          return bRequiresSave;          return bRequiresSave;
6960      }      }
6961    
6962        /**
6963         * Returns a pointer to the first <i>Group</i> object of the file,
6964         * <i>NULL</i> otherwise.
6965         *
6966         * @deprecated  This method is not reentrant-safe, use GetGroup() instead.
6967         */
6968      Group* File::GetFirstGroup() {      Group* File::GetFirstGroup() {
6969          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
6970          // there must always be at least one group          // there must always be at least one group
# Line 6943  namespace { Line 6972  namespace {
6972          return *GroupsIterator;          return *GroupsIterator;
6973      }      }
6974    
6975        /**
6976         * Returns a pointer to the next <i>Group</i> object of the file,
6977         * <i>NULL</i> otherwise.
6978         *
6979         * @deprecated  This method is not reentrant-safe, use GetGroup() instead.
6980         */
6981      Group* File::GetNextGroup() {      Group* File::GetNextGroup() {
6982          if (!pGroups) return NULL;          if (!pGroups) return NULL;
6983          ++GroupsIterator;          ++GroupsIterator;
# Line 6955  namespace { Line 6990  namespace {
6990       * @param index - number of the sought group (0..n)       * @param index - number of the sought group (0..n)
6991       * @returns sought group or NULL if there's no such group       * @returns sought group or NULL if there's no such group
6992       */       */
6993      Group* File::GetGroup(uint index) {      Group* File::GetGroup(size_t index) {
6994          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
6995          GroupsIterator = pGroups->begin();          if (index >= pGroups->size()) return NULL;
6996          for (uint i = 0; GroupsIterator != pGroups->end(); i++) {          return (*pGroups)[index];
             if (i == index) return *GroupsIterator;  
             ++GroupsIterator;  
         }  
         return NULL;  
6997      }      }
6998    
6999      /**      /**
# Line 6977  namespace { Line 7008  namespace {
7008       */       */
7009      Group* File::GetGroup(String name) {      Group* File::GetGroup(String name) {
7010          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
7011          GroupsIterator = pGroups->begin();          size_t i = 0;
7012          for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i)          for (Group* pGroup = GetGroup(i); pGroup; pGroup = GetGroup(++i))
7013              if ((*GroupsIterator)->Name == name) return *GroupsIterator;              if (pGroup->Name == name) return pGroup;
7014          return NULL;          return NULL;
7015      }      }
7016    
# Line 7003  namespace { Line 7034  namespace {
7034       */       */
7035      void File::DeleteGroup(Group* pGroup) {      void File::DeleteGroup(Group* pGroup) {
7036          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
7037          std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);          std::vector<Group*>::iterator iter =
7038                find(pGroups->begin(), pGroups->end(), pGroup);
7039          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");
7040          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!");
7041          // delete all members of this group          // delete all members of this group
7042          for (Sample* pSample = pGroup->GetFirstSample(); pSample; pSample = pGroup->GetNextSample()) {          Sample* pSample;
7043            while ((pSample = pGroup->GetSample(0))) {
7044              DeleteSample(pSample);              DeleteSample(pSample);
7045          }          }
7046          // now delete this group object          // now delete this group object
# Line 7028  namespace { Line 7061  namespace {
7061       */       */
7062      void File::DeleteGroupOnly(Group* pGroup) {      void File::DeleteGroupOnly(Group* pGroup) {
7063          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
7064          std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);          std::vector<Group*>::iterator iter =
7065                find(pGroups->begin(), pGroups->end(), pGroup);
7066          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");
7067          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!");
7068          // move all members of this group to another group          // move all members of this group to another group
# Line 7039  namespace { Line 7073  namespace {
7073      }      }
7074    
7075      void File::LoadGroups() {      void File::LoadGroups() {
7076          if (!pGroups) pGroups = new std::list<Group*>;          if (!pGroups) pGroups = new std::vector<Group*>;
7077          // try to read defined groups from file          // try to read defined groups from file
7078          RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI);          RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI);
7079          if (lst3gri) {          if (lst3gri) {
# Line 7238  namespace { Line 7272  namespace {
7272                  }                  }
7273              }              }
7274    
7275              std::list<Group*>::iterator iter = pGroups->begin();              std::vector<Group*>::iterator iter = pGroups->begin();
7276              std::list<Group*>::iterator end  = pGroups->end();              std::vector<Group*>::iterator end  = pGroups->end();
7277              for (; iter != end; ++iter) {              for (; iter != end; ++iter) {
7278                  (*iter)->UpdateChunks(pProgress);                  (*iter)->UpdateChunks(pProgress);
7279              }              }
# Line 7293  namespace { Line 7327  namespace {
7327    
7328              memset(&pData[48], 0, sublen - 48);              memset(&pData[48], 0, sublen - 48);
7329    
7330              for (Instrument* instrument = GetFirstInstrument() ; instrument ;              size_t iIns = 0;
7331                   instrument = GetNextInstrument()) {              for (Instrument* instrument = GetInstrument(iIns); instrument;
7332                                 instrument = GetInstrument(++iIns))
7333                {
7334                  int nbusedsamples = 0;                  int nbusedsamples = 0;
7335                  int nbusedchannels = 0;                  int nbusedchannels = 0;
7336                  int nbdimregions = 0;                  int nbdimregions = 0;
# Line 7399  namespace { Line 7435  namespace {
7435      void File::UpdateFileOffsets() {      void File::UpdateFileOffsets() {
7436          DLS::File::UpdateFileOffsets();          DLS::File::UpdateFileOffsets();
7437    
7438          for (Instrument* instrument = GetFirstInstrument(); instrument;          size_t i = 0;
7439               instrument = GetNextInstrument())          for (Instrument* instrument = GetInstrument(i); instrument;
7440                             instrument = GetInstrument(++i))
7441          {          {
7442              instrument->UpdateScriptFileOffsets();              instrument->UpdateScriptFileOffsets();
7443          }          }

Legend:
Removed from v.3933  
changed lines
  Added in v.3945

  ViewVC Help
Powered by ViewVC