244 |
void InstrumentResourceManager::Sf2ResourceManager::Destroy(::sf2::File* pResource, void* pArg) { |
void InstrumentResourceManager::Sf2ResourceManager::Destroy(::sf2::File* pResource, void* pArg) { |
245 |
dmsg(1,("Freeing sf2 file from memory...")); |
dmsg(1,("Freeing sf2 file from memory...")); |
246 |
|
|
247 |
/* // Delete as much as possible of the sfz file. Some of the |
// Delete as much as possible of the sf2 file. Some of the |
248 |
// regions and samples may still be in use - these |
// regions and samples may still be in use - these |
249 |
// will be deleted later by the HandBackRegion function. |
// will be deleted later by the HandBackRegion function. |
250 |
bool deleteInstrument = true; |
bool deleteFile = true; |
|
::sf2::Instrument* pInstr = pResource->GetInstrument(); |
|
251 |
|
|
252 |
for (int i = pInstr->regions.size() - 1; i >= 0 ; i--) { |
for (int i = pResource->GetInstrumentCount() - 1; i >= 0; i--) { |
253 |
::sfz::Region* pRegion = pInstr->regions[i]; |
::sf2::Instrument* pInstr = pResource->GetInstrument(i); |
254 |
std::map< ::sfz::Region*, region_info_t>::iterator iter = parent->RegionInfo.find(pRegion); |
bool deleteInstrument = true; |
255 |
if (iter != parent->RegionInfo.end()) { |
|
256 |
region_info_t& regInfo = (*iter).second; |
for (int j = pInstr->GetRegionCount() - 1; j >= 0 ; j--) { |
257 |
regInfo.file = pResource; |
::sf2::Region* pRegion = pInstr->GetRegion(j); |
258 |
deleteInstrument = false; |
std::map< ::sf2::Region*, region_info_t>::iterator iter = parent->RegionInfo.find(pRegion); |
259 |
} else { |
if (iter != parent->RegionInfo.end()) { |
260 |
SampleFile* sf = pRegion->GetSample(false); |
region_info_t& regInfo = (*iter).second; |
261 |
if (sf != NULL) pInstr->GetSampleManager()->RemoveSampleConsumer(sf, pRegion); |
regInfo.file = pResource; |
262 |
if (sf == NULL || !pInstr->GetSampleManager()->HasSampleConsumers(sf)) pInstr->DestroyRegion(pRegion); |
deleteFile = deleteInstrument = false; |
263 |
|
} else { |
264 |
|
pInstr->DeleteRegion(pRegion); |
265 |
|
} |
266 |
} |
} |
267 |
|
|
268 |
|
if (deleteInstrument) pResource->DeleteInstrument(pInstr); |
269 |
} |
} |
270 |
|
|
271 |
if(deleteInstrument) delete pResource; |
if (deleteFile) { |
272 |
else dmsg(2,("keeping some samples that are in use..."));*/ |
delete pResource; |
273 |
|
delete (::RIFF::File*) pArg; |
274 |
|
} else { |
275 |
|
dmsg(2,("keeping some samples that are in use...")); |
276 |
|
for (int i = pResource->GetSampleCount() - 1; i >= 0; i--) { |
277 |
|
::sf2::Sample* sample = pResource->GetSample(i); |
278 |
|
if (parent->SampleRefCount.find(sample) == parent->SampleRefCount.end()) { |
279 |
|
pResource->DeleteSample(sample); |
280 |
|
} |
281 |
|
} |
282 |
|
} |
283 |
|
|
284 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
285 |
} |
} |