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; |
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()) |
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 |
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( |
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 |
} |
} |
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; |
6947 |
return bRequiresSave; |
return bRequiresSave; |
6948 |
} |
} |
6949 |
|
|
6950 |
|
/** |
6951 |
|
* Returns a pointer to the first <i>Group</i> object of the file, |
6952 |
|
* <i>NULL</i> otherwise. |
6953 |
|
* |
6954 |
|
* @deprecated This method is not reentrant-safe, use GetGroup() instead. |
6955 |
|
*/ |
6956 |
Group* File::GetFirstGroup() { |
Group* File::GetFirstGroup() { |
6957 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
6958 |
// there must always be at least one group |
// there must always be at least one group |
6960 |
return *GroupsIterator; |
return *GroupsIterator; |
6961 |
} |
} |
6962 |
|
|
6963 |
|
/** |
6964 |
|
* Returns a pointer to the next <i>Group</i> object of the file, |
6965 |
|
* <i>NULL</i> otherwise. |
6966 |
|
* |
6967 |
|
* @deprecated This method is not reentrant-safe, use GetGroup() instead. |
6968 |
|
*/ |
6969 |
Group* File::GetNextGroup() { |
Group* File::GetNextGroup() { |
6970 |
if (!pGroups) return NULL; |
if (!pGroups) return NULL; |
6971 |
++GroupsIterator; |
++GroupsIterator; |
6978 |
* @param index - number of the sought group (0..n) |
* @param index - number of the sought group (0..n) |
6979 |
* @returns sought group or NULL if there's no such group |
* @returns sought group or NULL if there's no such group |
6980 |
*/ |
*/ |
6981 |
Group* File::GetGroup(uint index) { |
Group* File::GetGroup(size_t index) { |
6982 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
6983 |
GroupsIterator = pGroups->begin(); |
if (index >= pGroups->size()) return NULL; |
6984 |
for (uint i = 0; GroupsIterator != pGroups->end(); i++) { |
return (*pGroups)[index]; |
|
if (i == index) return *GroupsIterator; |
|
|
++GroupsIterator; |
|
|
} |
|
|
return NULL; |
|
6985 |
} |
} |
6986 |
|
|
6987 |
/** |
/** |
6996 |
*/ |
*/ |
6997 |
Group* File::GetGroup(String name) { |
Group* File::GetGroup(String name) { |
6998 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
6999 |
GroupsIterator = pGroups->begin(); |
size_t i = 0; |
7000 |
for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i) |
for (Group* pGroup = GetGroup(i); pGroup; pGroup = GetGroup(++i)) |
7001 |
if ((*GroupsIterator)->Name == name) return *GroupsIterator; |
if (pGroup->Name == name) return pGroup; |
7002 |
return NULL; |
return NULL; |
7003 |
} |
} |
7004 |
|
|
7022 |
*/ |
*/ |
7023 |
void File::DeleteGroup(Group* pGroup) { |
void File::DeleteGroup(Group* pGroup) { |
7024 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
7025 |
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
std::vector<Group*>::iterator iter = |
7026 |
|
find(pGroups->begin(), pGroups->end(), pGroup); |
7027 |
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"); |
7028 |
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!"); |
7029 |
// delete all members of this group |
// delete all members of this group |
7030 |
for (Sample* pSample = pGroup->GetFirstSample(); pSample; pSample = pGroup->GetNextSample()) { |
Sample* pSample; |
7031 |
|
while ((pSample = pGroup->GetSample(0))) { |
7032 |
DeleteSample(pSample); |
DeleteSample(pSample); |
7033 |
} |
} |
7034 |
// now delete this group object |
// now delete this group object |
7049 |
*/ |
*/ |
7050 |
void File::DeleteGroupOnly(Group* pGroup) { |
void File::DeleteGroupOnly(Group* pGroup) { |
7051 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
7052 |
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
std::vector<Group*>::iterator iter = |
7053 |
|
find(pGroups->begin(), pGroups->end(), pGroup); |
7054 |
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"); |
7055 |
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!"); |
7056 |
// move all members of this group to another group |
// move all members of this group to another group |
7061 |
} |
} |
7062 |
|
|
7063 |
void File::LoadGroups() { |
void File::LoadGroups() { |
7064 |
if (!pGroups) pGroups = new std::list<Group*>; |
if (!pGroups) pGroups = new std::vector<Group*>; |
7065 |
// try to read defined groups from file |
// try to read defined groups from file |
7066 |
RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
7067 |
if (lst3gri) { |
if (lst3gri) { |
7260 |
} |
} |
7261 |
} |
} |
7262 |
|
|
7263 |
std::list<Group*>::iterator iter = pGroups->begin(); |
std::vector<Group*>::iterator iter = pGroups->begin(); |
7264 |
std::list<Group*>::iterator end = pGroups->end(); |
std::vector<Group*>::iterator end = pGroups->end(); |
7265 |
for (; iter != end; ++iter) { |
for (; iter != end; ++iter) { |
7266 |
(*iter)->UpdateChunks(pProgress); |
(*iter)->UpdateChunks(pProgress); |
7267 |
} |
} |