/[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 3939 by schoenebeck, Thu Jun 17 12:04:54 2021 UTC revision 3946 by schoenebeck, Fri Jun 18 15:51:32 2021 UTC
# 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 6405  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 6421  namespace { Line 6429  namespace {
6429                  }                  }
6430              }              }
6431          }          }
         SamplesIterator = tmp; // restore iterator  
6432      }      }
6433    
6434      void File::LoadSamples() {      void File::LoadSamples() {
# Line 6539  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 6546  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 6573  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 6604  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 7308  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 7414  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.3939  
changed lines
  Added in v.3946

  ViewVC Help
Powered by ViewVC