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; |
1347 |
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
1348 |
else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); |
else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); |
1349 |
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
1350 |
|
else if (sscanf(s, "_amplitude_oncc%d", &y)) eg(x).amplitude_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1351 |
|
else if (strcmp(s, "_volume") == 0) eg(x).volume = check(key, -144.0f, 6.0f, ToFloat(value)); |
1352 |
|
else if (sscanf(s, "_volume_oncc%d", &y)) eg(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) ); |
1353 |
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
1354 |
|
else if (sscanf(s, "_cutoff_oncc%d", &y)) eg(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); |
1355 |
|
else if (strcmp(s, "_pitch") == 0) eg(x).pitch = check(key, -9600, 9600, ToInt(value)); |
1356 |
|
else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); |
1357 |
|
else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value)); |
1358 |
|
else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) ); |
1359 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1360 |
} |
} |
1361 |
|
|
1583 |
} |
} |
1584 |
|
|
1585 |
EG::EG() : |
EG::EG() : |
1586 |
sustain(0), loop(0), loop_count(0), |
sustain(0), loop(0), loop_count(0), amplitude(0), |
1587 |
amplitude(0), cutoff(0) { |
cutoff(0), pitch(0), resonance(0), volume(-200) /* less than -144 dB is considered unset */ |
1588 |
} |
{ } |
1589 |
|
|
1590 |
void EG::Copy(const EG& eg) { |
void EG::Copy(const EG& eg) { |
1591 |
sustain = eg.sustain; |
sustain = eg.sustain; |
1592 |
loop = eg.loop; |
loop = eg.loop; |
1593 |
loop_count = eg.loop_count; |
loop_count = eg.loop_count; |
1594 |
amplitude = eg.amplitude; |
amplitude = eg.amplitude; |
1595 |
|
volume = eg.volume; |
1596 |
cutoff = eg.cutoff; |
cutoff = eg.cutoff; |
1597 |
|
pitch = eg.pitch; |
1598 |
|
resonance = eg.resonance; |
1599 |
node = eg.node; |
node = eg.node; |
1600 |
|
|
1601 |
|
amplitude_oncc = eg.amplitude_oncc; |
1602 |
|
volume_oncc = eg.volume_oncc; |
1603 |
|
cutoff_oncc = eg.cutoff_oncc; |
1604 |
|
pitch_oncc = eg.pitch_oncc; |
1605 |
|
resonance_oncc = eg.resonance_oncc; |
1606 |
} |
} |
1607 |
|
|
1608 |
LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ |
LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ |