51 |
return val; |
return val; |
52 |
} |
} |
53 |
|
|
54 |
Sample* SampleManager::FindSample(std::string samplePath, int offset) { |
Sample* SampleManager::FindSample(std::string samplePath, uint offset, int end) { |
55 |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
56 |
for (; it != sampleMap.end(); it++) { |
for (; it != sampleMap.end(); it++) { |
57 |
if (it->first->GetFile() == samplePath) { |
if (it->first->GetFile() == samplePath) { |
59 |
* same sample with different offset as different samples |
* same sample with different offset as different samples |
60 |
* // TODO: Ignore offset when the whole sample is cached in RAM? |
* // TODO: Ignore offset when the whole sample is cached in RAM? |
61 |
*/ |
*/ |
62 |
int maxOffset = it->first->MaxOffset; |
if (it->first->Offset == offset && it->first->End == end) return it->first; |
|
if(it->first->Offset == offset || (it->first->Offset < maxOffset && offset < maxOffset)) { |
|
|
return it->first; |
|
|
} |
|
63 |
} |
} |
64 |
} |
} |
65 |
|
|
110 |
Sample* Region::GetSample(bool create) |
Sample* Region::GetSample(bool create) |
111 |
{ |
{ |
112 |
if(pSample == NULL && create) { |
if(pSample == NULL && create) { |
113 |
int i = offset ? *offset : 0; |
uint i = offset ? *offset : 0; |
114 |
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i); |
int e = end ? *end : -2; |
115 |
|
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, e); |
116 |
if (sf != NULL) pSample = sf; // Reuse already created sample |
if (sf != NULL) pSample = sf; // Reuse already created sample |
117 |
else pSample = new Sample(sample, false, i); |
else pSample = new Sample(sample, false, i, e); |
118 |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
119 |
} |
} |
120 |
return pSample; |
return pSample; |