--- libgig/trunk/src/gig.cpp 2021/06/14 12:07:47 3924 +++ libgig/trunk/src/gig.cpp 2021/06/19 11:01:40 3961 @@ -609,8 +609,8 @@ uint16_t iSampleGroup = 0; // 0 refers to default sample group File* pFile = static_cast(pParent); if (pFile->pGroups) { - std::list::iterator iter = pFile->pGroups->begin(); - std::list::iterator end = pFile->pGroups->end(); + std::vector::iterator iter = pFile->pGroups->begin(); + std::vector::iterator end = pFile->pGroups->end(); for (int i = 0; iter != end; i++, iter++) { if (*iter == pGroup) { iSampleGroup = i; @@ -4325,21 +4325,23 @@ uint64_t soughtoffset = uint64_t(file->pWavePoolTable[WavePoolTableIndex]) | uint64_t(file->pWavePoolTableHi[WavePoolTableIndex]) << 32; - Sample* sample = file->GetFirstSample(pProgress); - while (sample) { + size_t i = 0; + for (Sample* sample = file->GetSample(i, pProgress); sample; + sample = file->GetSample(++i)) + { if (sample->ullWavePoolOffset == soughtoffset) - return static_cast(sample); - sample = file->GetNextSample(); + return sample; } } else { // use extension files and 32 bit wave pool offsets file_offset_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; file_offset_t soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; - Sample* sample = file->GetFirstSample(pProgress); - while (sample) { + size_t i = 0; + for (Sample* sample = file->GetSample(i, pProgress); sample; + sample = file->GetSample(++i)) + { if (sample->ullWavePoolOffset == soughtoffset && - sample->FileNo == soughtfileno) return static_cast(sample); - sample = file->GetNextSample(); + sample->FileNo == soughtfileno) return sample; } } return NULL; @@ -4799,8 +4801,8 @@ ScriptGroup::~ScriptGroup() { if (pScripts) { - std::list::iterator iter = pScripts->begin(); - std::list::iterator end = pScripts->end(); + std::vector::iterator iter = pScripts->begin(); + std::vector::iterator end = pScripts->end(); while (iter != end) { delete *iter; ++iter; @@ -4838,7 +4840,7 @@ // now store the name of this group as chunk as subchunk of the list chunk ::SaveString(CHUNK_ID_LSNM, NULL, pList, Name, String("Unnamed Group"), true, 64); - for (std::list::iterator it = pScripts->begin(); + for (std::vector::iterator it = pScripts->begin(); it != pScripts->end(); ++it) { (*it)->UpdateChunks(pProgress); @@ -4853,12 +4855,10 @@ * @param index - number of the sought script (0..n) * @returns sought script or NULL if there's no such script */ - Script* ScriptGroup::GetScript(uint index) { + Script* ScriptGroup::GetScript(size_t index) { if (!pScripts) LoadScripts(); - std::list::iterator it = pScripts->begin(); - for (uint i = 0; it != pScripts->end(); ++i, ++it) - if (i == index) return *it; - return NULL; + if (index >= pScripts->size()) return NULL; + return (*pScripts)[index]; } /** @brief Add new instrument script. @@ -4891,7 +4891,7 @@ */ void ScriptGroup::DeleteScript(Script* pScript) { if (!pScripts) LoadScripts(); - std::list::iterator iter = + std::vector::iterator iter = find(pScripts->begin(), pScripts->end(), pScript); if (iter == pScripts->end()) throw gig::Exception("Could not delete script, could not find given script"); @@ -4904,7 +4904,7 @@ void ScriptGroup::LoadScripts() { if (pScripts) return; - pScripts = new std::list; + pScripts = new std::vector; if (!pList) return; size_t i = 0; @@ -5301,11 +5301,28 @@ } /** + * Returns Region at supplied @a pos position within the region list of + * this instrument. If supplied @a pos is out of bounds then @c NULL is + * returned. + * + * @param pos - position of sought Region in region list + * @returns pointer address to requested region or @c NULL if @a pos is + * out of bounds + */ + Region* Instrument::GetRegionAt(size_t pos) { + if (!pRegions) return NULL; + if (pos >= pRegions->size()) return NULL; + return static_cast( (*pRegions)[pos] ); + } + + /** * Returns the first Region of the instrument. You have to call this * method once before you use GetNextRegion(). * * @returns pointer address to first region or NULL if there is none * @see GetNextRegion() + * @deprecated This method is not reentrant-safe, use GetRegionAt() + * instead. */ Region* Instrument::GetFirstRegion() { if (!pRegions) return NULL; @@ -5320,6 +5337,8 @@ * * @returns pointer address to the next region or NULL if end reached * @see GetFirstRegion() + * @deprecated This method is not reentrant-safe, use GetRegionAt() + * instead. */ Region* Instrument::GetNextRegion() { if (!pRegions) return NULL; @@ -5373,7 +5392,8 @@ * @param dst - destination instrument at which this instrument will be * moved to, or pass NULL for moving to end of list * @throw gig::Exception if this instrument and target instrument are not - * part of the same file + * part of the same file, as well as on unexpected + * internal error */ void Instrument::MoveTo(Instrument* dst) { if (dst && GetParent() != dst->GetParent()) @@ -5390,11 +5410,17 @@ File::InstrumentList::iterator itFrom = std::find(list.begin(), list.end(), static_cast(this)); + if (itFrom == list.end()) + throw Exception( + "gig::Instrument::MoveTo(): unexpected missing membership " + "of this instrument." + ); + list.erase(itFrom); File::InstrumentList::iterator itTo = std::find(list.begin(), list.end(), static_cast(dst)); - list.splice(itTo, list, itFrom); + list.insert(itTo, this); } // move the instrument's actual list RIFF chunk appropriately @@ -5475,7 +5501,7 @@ File* pFile = (File*) GetParent(); for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) { uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset; - for (uint i = 0; pFile->GetScriptGroup(i); ++i) { + for (size_t i = 0; pFile->GetScriptGroup(i); ++i) { ScriptGroup* group = pFile->GetScriptGroup(i); for (uint s = 0; group->GetScript(s); ++s) { Script* script = group->GetScript(s); @@ -5513,7 +5539,7 @@ * @param index - instrument script slot index * @returns script or NULL if index is out of bounds */ - Script* Instrument::GetScriptOfSlot(uint index) { + Script* Instrument::GetScriptOfSlot(size_t index) { LoadScripts(); if (index >= pScriptRefs->size()) return NULL; return pScriptRefs->at(index).script; @@ -5574,7 +5600,7 @@ * @param index1 - index of the first script slot to swap * @param index2 - index of the second script slot to swap */ - void Instrument::SwapScriptSlots(uint index1, uint index2) { + void Instrument::SwapScriptSlots(size_t index1, size_t index2) { LoadScripts(); if (index1 >= pScriptRefs->size() || index2 >= pScriptRefs->size()) return; @@ -5589,7 +5615,7 @@ * * @param index - index of script slot to remove */ - void Instrument::RemoveScriptSlot(uint index) { + void Instrument::RemoveScriptSlot(size_t index) { LoadScripts(); if (index >= pScriptRefs->size()) return; pScriptRefs->erase( pScriptRefs->begin() + index ); @@ -5630,8 +5656,8 @@ * GigaStudio 4 software. It will currently only work with LinuxSampler and * gigedit. */ - uint Instrument::ScriptSlotCount() const { - return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size()); + size_t Instrument::ScriptSlotCount() const { + return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size(); } /** @brief Whether script execution shall be skipped. @@ -5650,7 +5676,7 @@ * @param index - index of the script slot on this instrument * @see Script::Bypass */ - bool Instrument::IsScriptSlotBypassed(uint index) { + bool Instrument::IsScriptSlotBypassed(size_t index) { if (index >= ScriptSlotCount()) return false; return pScriptRefs ? pScriptRefs->at(index).bypass : scriptPoolFileOffsets.at(index).bypass; @@ -5670,7 +5696,7 @@ * @param bBypass - if true, the script slot will be skipped by the sampler * @see Script::Bypass */ - void Instrument::SetScriptSlotBypassed(uint index, bool bBypass) { + void Instrument::SetScriptSlotBypassed(size_t index, bool bBypass) { if (index >= ScriptSlotCount()) return; if (pScriptRefs) pScriptRefs->at(index).bypass = bBypass; @@ -5690,8 +5716,8 @@ * the @c Script identified by passed @p uuid. */ bool Instrument::ReferencesScriptWithUuid(const _UUID& uuid) { - const uint nSlots = ScriptSlotCount(); - for (uint iSlot = 0; iSlot < nSlots; ++iSlot) + const size_t nSlots = ScriptSlotCount(); + for (size_t iSlot = 0; iSlot < nSlots; ++iSlot) if (_UUIDFromCArray(&GetScriptOfSlot(iSlot)->Uuid[0]) == uuid) return true; return false; @@ -5716,7 +5742,7 @@ * @param slot - script slot index of the variable to be retrieved * @param variable - name of the 'patch' variable in that script */ - bool Instrument::IsScriptPatchVariableSet(int slot, String variable) { + bool Instrument::IsScriptPatchVariableSet(size_t slot, String variable) { if (variable.empty()) return false; Script* script = GetScriptOfSlot(slot); if (!script) return false; @@ -5750,7 +5776,7 @@ * * @param slot - script slot index of the variable to be retrieved */ - std::map Instrument::GetScriptPatchVariables(int slot) { + std::map Instrument::GetScriptPatchVariables(size_t slot) { Script* script = GetScriptOfSlot(slot); if (!script) return std::map(); const _UUID uuid = _UUIDFromCArray(&script->Uuid[0]); @@ -5782,7 +5808,7 @@ * @param slot - script slot index of the variable to be retrieved * @param variable - name of the 'patch' variable in that script */ - String Instrument::GetScriptPatchVariable(int slot, String variable) { + String Instrument::GetScriptPatchVariable(size_t slot, String variable) { std::map vars = GetScriptPatchVariables(slot); return (vars.count(variable)) ? vars.find(variable)->second : ""; } @@ -5809,7 +5835,7 @@ * @throws gig::Exception if given script @p slot index is invalid or given * @p variable name is empty */ - void Instrument::SetScriptPatchVariable(int slot, String variable, String value) { + void Instrument::SetScriptPatchVariable(size_t slot, String variable, String value) { if (variable.empty()) throw Exception("Variable name must not be empty"); Script* script = GetScriptOfSlot(slot); @@ -5986,7 +6012,7 @@ pMidiRules[0] = NULL; // delete all old regions - while (Regions) DeleteRegion(GetFirstRegion()); + while (Regions) DeleteRegion(GetRegionAt(0)); // create new regions and copy them from original { RegionList::const_iterator it = orig->pRegions->begin(); @@ -6042,6 +6068,7 @@ Group::Group(File* file, RIFF::Chunk* ck3gnm) { pFile = file; pNameChunk = ck3gnm; + SamplesIterator = 0; ::LoadString(pNameChunk, Name); } @@ -6100,6 +6127,26 @@ } /** + * Returns Sample object at @a index of this sample group. + * + * @param index - position of sample in this sample group's sample list + * (0..n) + * @returns sample object or NULL if index is out of bounds + */ + Sample* Group::GetSample(size_t index) { + if (pFile->pSamples && index >= pFile->pSamples->size()) return NULL; + size_t indexInFile = 0; + size_t indexInGroup = 0; + for (Sample* pSample = pFile->GetSample(indexInFile); pSample; + pSample = pFile->GetSample(++indexInFile)) + { + if (pSample->GetGroup() != this) continue; + if (indexInGroup++ == index) return pSample; + } + return NULL; + } + + /** * Returns the first Sample of this Group. You have to call this method * once before you use GetNextSample(). * @@ -6109,11 +6156,17 @@ * @returns pointer address to first Sample or NULL if there is none * applied to this Group * @see GetNextSample() + * @deprecated This method is not reentrant-safe, use GetSample() + * instead. */ Sample* Group::GetFirstSample() { - // FIXME: lazy und unsafe implementation, should be an autonomous iterator - for (Sample* pSample = pFile->GetFirstSample(); pSample; pSample = pFile->GetNextSample()) { - if (pSample->GetGroup() == this) return pSample; + size_t& i = this->SamplesIterator; + i = 0; + for (Sample* pSample = pFile->GetSample(i); pSample; + pSample = pFile->GetSample(++i)) + { + if (pSample->GetGroup() == this) + return pSample; } return NULL; } @@ -6127,11 +6180,16 @@ * @returns pointer address to the next Sample of this Group or NULL if * end reached * @see GetFirstSample() + * @deprecated This method is not reentrant-safe, use GetSample() + * instead. */ Sample* Group::GetNextSample() { - // FIXME: lazy und unsafe implementation, should be an autonomous iterator - for (Sample* pSample = pFile->GetNextSample(); pSample; pSample = pFile->GetNextSample()) { - if (pSample->GetGroup() == this) return pSample; + size_t& i = this->SamplesIterator; + for (Sample* pSample = pFile->GetSample(++i); pSample; + pSample = pFile->GetSample(++i)) + { + if (pSample->GetGroup() == this) + return pSample; } return NULL; } @@ -6151,8 +6209,11 @@ */ void Group::MoveAll() { // get "that" other group first + size_t i = 0; Group* pOtherGroup = NULL; - for (pOtherGroup = pFile->GetFirstGroup(); pOtherGroup; pOtherGroup = pFile->GetNextGroup()) { + for (pOtherGroup = pFile->GetGroup(i); pOtherGroup; + pOtherGroup = pFile->GetGroup(++i)) + { if (pOtherGroup != this) break; } if (!pOtherGroup) throw Exception( @@ -6160,7 +6221,8 @@ "other Group. This is a bug, report it!" ); // now move all samples of this group to the other group - for (Sample* pSample = GetFirstSample(); pSample; pSample = GetNextSample()) { + Sample* pSample; + while ((pSample = GetSample(0))) { pOtherGroup->AddSample(pSample); } } @@ -6232,8 +6294,8 @@ File::~File() { if (pGroups) { - std::list::iterator iter = pGroups->begin(); - std::list::iterator end = pGroups->end(); + std::vector::iterator iter = pGroups->begin(); + std::vector::iterator end = pGroups->end(); while (iter != end) { delete *iter; ++iter; @@ -6241,8 +6303,8 @@ delete pGroups; } if (pScriptGroups) { - std::list::iterator iter = pScriptGroups->begin(); - std::list::iterator end = pScriptGroups->end(); + std::vector::iterator iter = pScriptGroups->begin(); + std::vector::iterator end = pScriptGroups->end(); while (iter != end) { delete *iter; ++iter; @@ -6251,6 +6313,14 @@ } } + /** + * Returns a pointer to the first Sample object of the file, + * NULL otherwise. + * + * @param pProgress - optional: callback function for progress notification + * @deprecated This method is not reentrant-safe, use GetSample() + * instead. + */ Sample* File::GetFirstSample(progress_t* pProgress) { if (!pSamples) LoadSamples(pProgress); if (!pSamples) return NULL; @@ -6258,6 +6328,13 @@ return static_cast( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); } + /** + * Returns a pointer to the next Sample object of the file, + * NULL otherwise. + * + * @deprecated This method is not reentrant-safe, use GetSample() + * instead. + */ Sample* File::GetNextSample() { if (!pSamples) return NULL; SamplesIterator++; @@ -6267,18 +6344,15 @@ /** * Returns Sample object of @a index. * + * @param index - position of sample in sample list (0..n) + * @param pProgress - optional: callback function for progress notification * @returns sample object or NULL if index is out of bounds */ - Sample* File::GetSample(uint index) { - if (!pSamples) LoadSamples(); + Sample* File::GetSample(size_t index, progress_t* pProgress) { + if (!pSamples) LoadSamples(pProgress); if (!pSamples) return NULL; - DLS::File::SampleList::iterator it = pSamples->begin(); - for (int i = 0; i < index; ++i) { - ++it; - if (it == pSamples->end()) return NULL; - } - if (it == pSamples->end()) return NULL; - return static_cast( *it ); + if (index >= pSamples->size()) return NULL; + return static_cast( (*pSamples)[index] ); } /** @@ -6336,13 +6410,15 @@ pSample->DeleteChunks(); delete pSample; - SampleList::iterator tmp = SamplesIterator; // remove all references to the sample - for (Instrument* instrument = GetFirstInstrument() ; instrument ; - instrument = GetNextInstrument()) { - for (Region* region = instrument->GetFirstRegion() ; region ; - region = instrument->GetNextRegion()) { - + size_t iIns = 0; + for (Instrument* instrument = GetInstrument(iIns); instrument; + instrument = GetInstrument(++iIns)) + { + size_t iRgn = 0; + for (Region* region = instrument->GetRegionAt(iRgn); region; + region = instrument->GetRegionAt(++iRgn)) + { if (region->GetSample() == pSample) region->SetSample(NULL); for (int i = 0 ; i < region->DimensionRegions ; i++) { @@ -6351,7 +6427,6 @@ } } } - SamplesIterator = tmp; // restore iterator } void File::LoadSamples() { @@ -6365,8 +6440,6 @@ if (!pSamples) pSamples = new SampleList; - RIFF::File* file = pRIFF; - // just for progress calculation int iSampleIndex = 0; int iTotalSamples = WavePoolCount; @@ -6471,6 +6544,13 @@ __notify_progress(pProgress, 1.0); // notify done } + /** + * Returns a pointer to the first Instrument object of the file, + * NULL otherwise. + * + * @deprecated This method is not reentrant-safe, use GetInstrument() + * instead. + */ Instrument* File::GetFirstInstrument() { if (!pInstruments) LoadInstruments(); if (!pInstruments) return NULL; @@ -6478,6 +6558,13 @@ return static_cast( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); } + /** + * Returns a pointer to the next Instrument object of the file, + * NULL otherwise. + * + * @deprecated This method is not reentrant-safe, use GetInstrument() + * instead. + */ Instrument* File::GetNextInstrument() { if (!pInstruments) return NULL; InstrumentsIterator++; @@ -6505,7 +6592,7 @@ * @param pProgress - optional: callback function for progress notification * @returns sought instrument or NULL if there's no such instrument */ - Instrument* File::GetInstrument(uint index, progress_t* pProgress) { + Instrument* File::GetInstrument(size_t index, progress_t* pProgress) { if (!pInstruments) { // TODO: hack - we simply load ALL samples here, it would have been done in the Region constructor anyway (ATM) @@ -6515,7 +6602,7 @@ __divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask __notify_progress(&subprogress, 0.0f); if (GetAutoLoad()) - GetFirstSample(&subprogress); // now force all samples to be loaded + GetSample(0, &subprogress); // now force all samples to be loaded __notify_progress(&subprogress, 1.0f); // instrument loading subtask @@ -6529,19 +6616,15 @@ } else { // sample loading subtask if (GetAutoLoad()) - GetFirstSample(); // now force all samples to be loaded + GetSample(0); // now force all samples to be loaded // instrument loading subtask LoadInstruments(); } } if (!pInstruments) return NULL; - InstrumentsIterator = pInstruments->begin(); - for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { - if (i == index) return static_cast( *InstrumentsIterator ); - InstrumentsIterator++; - } - return NULL; + if (index >= pInstruments->size()) return NULL; + return static_cast( (*pInstruments)[index] ); } /** @brief Add a new instrument definition. @@ -6628,7 +6711,7 @@ } // clone script groups and their scripts - for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) { + for (size_t iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) { ScriptGroup* sg = pFile->GetScriptGroup(iGroup); ScriptGroup* dg = AddScriptGroup(); dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name; @@ -6769,7 +6852,7 @@ } int File::GetWaveTableIndexOf(gig::Sample* pSample) { - if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned + if (!pSamples) GetSample(0); // make sure sample chunks were scanned File::SampleList::iterator iter = pSamples->begin(); File::SampleList::iterator end = pSamples->end(); for (int index = 0; iter != end; ++iter, ++index) @@ -6789,7 +6872,7 @@ if (!_3crc) return false; if (_3crc->GetNewSize() <= 0) return false; if (_3crc->GetNewSize() % 8) return false; - if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned + if (!pSamples) GetSample(0); // make sure sample chunks were scanned if (_3crc->GetNewSize() != pSamples->size() * 8) return false; const file_offset_t n = _3crc->GetNewSize() / 8; @@ -6823,7 +6906,7 @@ */ bool File::RebuildSampleChecksumTable() { // make sure sample chunks were scanned - if (!pSamples) GetFirstSample(); + if (!pSamples) GetSample(0); bool bRequiresSave = false; @@ -6872,6 +6955,12 @@ return bRequiresSave; } + /** + * Returns a pointer to the first Group object of the file, + * NULL otherwise. + * + * @deprecated This method is not reentrant-safe, use GetGroup() instead. + */ Group* File::GetFirstGroup() { if (!pGroups) LoadGroups(); // there must always be at least one group @@ -6879,6 +6968,12 @@ return *GroupsIterator; } + /** + * Returns a pointer to the next Group object of the file, + * NULL otherwise. + * + * @deprecated This method is not reentrant-safe, use GetGroup() instead. + */ Group* File::GetNextGroup() { if (!pGroups) return NULL; ++GroupsIterator; @@ -6891,14 +6986,10 @@ * @param index - number of the sought group (0..n) * @returns sought group or NULL if there's no such group */ - Group* File::GetGroup(uint index) { + Group* File::GetGroup(size_t index) { if (!pGroups) LoadGroups(); - GroupsIterator = pGroups->begin(); - for (uint i = 0; GroupsIterator != pGroups->end(); i++) { - if (i == index) return *GroupsIterator; - ++GroupsIterator; - } - return NULL; + if (index >= pGroups->size()) return NULL; + return (*pGroups)[index]; } /** @@ -6913,9 +7004,9 @@ */ Group* File::GetGroup(String name) { if (!pGroups) LoadGroups(); - GroupsIterator = pGroups->begin(); - for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i) - if ((*GroupsIterator)->Name == name) return *GroupsIterator; + size_t i = 0; + for (Group* pGroup = GetGroup(i); pGroup; pGroup = GetGroup(++i)) + if (pGroup->Name == name) return pGroup; return NULL; } @@ -6939,11 +7030,13 @@ */ void File::DeleteGroup(Group* pGroup) { if (!pGroups) LoadGroups(); - std::list::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); + std::vector::iterator iter = + find(pGroups->begin(), pGroups->end(), pGroup); if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); // delete all members of this group - for (Sample* pSample = pGroup->GetFirstSample(); pSample; pSample = pGroup->GetNextSample()) { + Sample* pSample; + while ((pSample = pGroup->GetSample(0))) { DeleteSample(pSample); } // now delete this group object @@ -6964,7 +7057,8 @@ */ void File::DeleteGroupOnly(Group* pGroup) { if (!pGroups) LoadGroups(); - std::list::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); + std::vector::iterator iter = + find(pGroups->begin(), pGroups->end(), pGroup); if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); // move all members of this group to another group @@ -6975,7 +7069,7 @@ } void File::LoadGroups() { - if (!pGroups) pGroups = new std::list; + if (!pGroups) pGroups = new std::vector; // try to read defined groups from file RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); if (lst3gri) { @@ -7009,12 +7103,10 @@ * @param index - number of the sought group (0..n) * @returns sought script group or NULL if there's no such group */ - ScriptGroup* File::GetScriptGroup(uint index) { + ScriptGroup* File::GetScriptGroup(size_t index) { if (!pScriptGroups) LoadScriptGroups(); - std::list::iterator it = pScriptGroups->begin(); - for (uint i = 0; it != pScriptGroups->end(); ++i, ++it) - if (i == index) return *it; - return NULL; + if (index >= pScriptGroups->size()) return NULL; + return (*pScriptGroups)[index]; } /** @brief Get instrument script group (by name). @@ -7027,9 +7119,10 @@ */ ScriptGroup* File::GetScriptGroup(const String& name) { if (!pScriptGroups) LoadScriptGroups(); - std::list::iterator it = pScriptGroups->begin(); - for (uint i = 0; it != pScriptGroups->end(); ++i, ++it) - if ((*it)->Name == name) return *it; + for (size_t i = 0; i < pScriptGroups->size(); ++i) { + ScriptGroup* pGroup = (*pScriptGroups)[i]; + if (pGroup->Name == name) return pGroup; + } return NULL; } @@ -7062,7 +7155,7 @@ */ void File::DeleteScriptGroup(ScriptGroup* pScriptGroup) { if (!pScriptGroups) LoadScriptGroups(); - std::list::iterator iter = + std::vector::iterator iter = find(pScriptGroups->begin(), pScriptGroups->end(), pScriptGroup); if (iter == pScriptGroups->end()) throw gig::Exception("Could not delete script group, could not find given script group"); @@ -7077,7 +7170,7 @@ void File::LoadScriptGroups() { if (pScriptGroups) return; - pScriptGroups = new std::list; + pScriptGroups = new std::vector; RIFF::List* lstLS = pRIFF->GetSubList(LIST_TYPE_3LS); if (lstLS) { size_t i = 0; @@ -7122,7 +7215,7 @@ // of the respective instrument script chunk as reference. if (pScriptGroups) { // Update instrument script (group) chunks. - for (std::list::iterator it = pScriptGroups->begin(); + for (std::vector::iterator it = pScriptGroups->begin(); it != pScriptGroups->end(); ++it) { (*it)->UpdateChunks(pProgress); @@ -7174,8 +7267,8 @@ } } - std::list::iterator iter = pGroups->begin(); - std::list::iterator end = pGroups->end(); + std::vector::iterator iter = pGroups->begin(); + std::vector::iterator end = pGroups->end(); for (; iter != end; ++iter) { (*iter)->UpdateChunks(pProgress); } @@ -7213,9 +7306,11 @@ uint8_t* pData = (uint8_t*) einf->LoadChunkData(); std::map sampleMap; - int sampleIdx = 0; - for (Sample* pSample = GetFirstSample(); pSample; pSample = GetNextSample()) { - sampleMap[pSample] = sampleIdx++; + size_t sampleIdx = 0; + for (Sample* pSample = GetSample(0); pSample; + pSample = GetSample(++sampleIdx)) + { + sampleMap[pSample] = sampleIdx; } int totnbusedsamples = 0; @@ -7227,8 +7322,10 @@ memset(&pData[48], 0, sublen - 48); - for (Instrument* instrument = GetFirstInstrument() ; instrument ; - instrument = GetNextInstrument()) { + size_t iIns = 0; + for (Instrument* instrument = GetInstrument(iIns); instrument; + instrument = GetInstrument(++iIns)) + { int nbusedsamples = 0; int nbusedchannels = 0; int nbdimregions = 0; @@ -7236,8 +7333,10 @@ memset(&pData[(instrumentIdx + 1) * sublen + 48], 0, sublen - 48); - for (Region* region = instrument->GetFirstRegion() ; region ; - region = instrument->GetNextRegion()) { + size_t iRgn = 0; + for (Region* region = instrument->GetRegionAt(iRgn); region; + region = instrument->GetRegionAt(++iRgn)) + { for (int i = 0 ; i < region->DimensionRegions ; i++) { gig::DimensionRegion *d = region->pDimensionRegions[i]; if (d->pSample) { @@ -7331,8 +7430,9 @@ void File::UpdateFileOffsets() { DLS::File::UpdateFileOffsets(); - for (Instrument* instrument = GetFirstInstrument(); instrument; - instrument = GetNextInstrument()) + size_t i = 0; + for (Instrument* instrument = GetInstrument(i); instrument; + instrument = GetInstrument(++i)) { instrument->UpdateScriptFileOffsets(); }