31 |
|
|
32 |
#include "../../common/File.h" |
#include "../../common/File.h" |
33 |
#include "../../common/Path.h" |
#include "../../common/Path.h" |
|
#include "../../common/global_private.h" |
|
34 |
#include "LookupTable.h" |
#include "LookupTable.h" |
35 |
|
|
36 |
namespace sfz |
namespace sfz |
50 |
return val; |
return val; |
51 |
} |
} |
52 |
|
|
53 |
Sample* SampleManager::FindSample(std::string samplePath, int offset) { |
Sample* SampleManager::FindSample(std::string samplePath, uint offset, int end) { |
54 |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
55 |
for (; it != sampleMap.end(); it++) { |
for (; it != sampleMap.end(); it++) { |
56 |
if (it->first->GetFile() == samplePath) { |
if (it->first->GetFile() == samplePath) { |
58 |
* same sample with different offset as different samples |
* same sample with different offset as different samples |
59 |
* // TODO: Ignore offset when the whole sample is cached in RAM? |
* // TODO: Ignore offset when the whole sample is cached in RAM? |
60 |
*/ |
*/ |
61 |
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; |
|
|
} |
|
62 |
} |
} |
63 |
} |
} |
64 |
|
|
109 |
Sample* Region::GetSample(bool create) |
Sample* Region::GetSample(bool create) |
110 |
{ |
{ |
111 |
if(pSample == NULL && create) { |
if(pSample == NULL && create) { |
112 |
int i = offset ? *offset : 0; |
uint i = offset ? *offset : 0; |
113 |
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i); |
int e = end ? *end : -2; |
114 |
|
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, e); |
115 |
if (sf != NULL) pSample = sf; // Reuse already created sample |
if (sf != NULL) pSample = sf; // Reuse already created sample |
116 |
else pSample = new Sample(sample, false, i); |
else pSample = new Sample(sample, false, i, e); |
117 |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
118 |
} |
} |
119 |
return pSample; |
return pSample; |
323 |
volume_curvecc.clear(); |
volume_curvecc.clear(); |
324 |
volume_smoothcc.clear(); |
volume_smoothcc.clear(); |
325 |
pan = 0; |
pan = 0; |
326 |
|
pan_oncc.clear(); |
327 |
|
pan_curvecc.clear(); |
328 |
|
pan_smoothcc.clear(); |
329 |
width = 100; |
width = 100; |
330 |
position = 0; |
position = 0; |
331 |
amp_keytrack = 0; |
amp_keytrack = 0; |
413 |
gain_oncc.set(i, 0); |
gain_oncc.set(i, 0); |
414 |
xfin_locc.set(i, 0); |
xfin_locc.set(i, 0); |
415 |
xfin_hicc.set(i, 0); |
xfin_hicc.set(i, 0); |
416 |
xfout_locc.set(i, 127); |
xfout_locc.set(i, 0); |
417 |
xfout_hicc.set(i, 127); |
xfout_hicc.set(i, 0); |
418 |
|
|
419 |
// filter |
// filter |
420 |
cutoff_oncc.set(i, 0); |
cutoff_oncc.set(i, 0); |
513 |
amplfo_fade = 0; |
amplfo_fade = 0; |
514 |
amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
515 |
amplfo_depth = 0; |
amplfo_depth = 0; |
516 |
|
amplfo_delay_oncc.clear(); |
517 |
|
amplfo_fade_oncc.clear(); |
518 |
amplfo_depthcc.clear(); |
amplfo_depthcc.clear(); |
519 |
amplfo_freqcc.clear(); |
amplfo_freqcc.clear(); |
520 |
|
|
522 |
fillfo_fade = 0; |
fillfo_fade = 0; |
523 |
fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
524 |
fillfo_depth = 0; |
fillfo_depth = 0; |
525 |
|
fillfo_delay_oncc.clear(); |
526 |
|
fillfo_fade_oncc.clear(); |
527 |
fillfo_depthcc.clear(); |
fillfo_depthcc.clear(); |
528 |
fillfo_freqcc.clear(); |
fillfo_freqcc.clear(); |
529 |
|
|
531 |
pitchlfo_fade = 0; |
pitchlfo_fade = 0; |
532 |
pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
533 |
pitchlfo_depth = 0; |
pitchlfo_depth = 0; |
534 |
|
pitchlfo_delay_oncc.clear(); |
535 |
|
pitchlfo_fade_oncc.clear(); |
536 |
pitchlfo_freqcc.clear(); |
pitchlfo_freqcc.clear(); |
537 |
} |
} |
538 |
|
|
617 |
region->volume_curvecc = volume_curvecc; |
region->volume_curvecc = volume_curvecc; |
618 |
region->volume_smoothcc = volume_smoothcc; |
region->volume_smoothcc = volume_smoothcc; |
619 |
region->pan = pan; |
region->pan = pan; |
620 |
|
region->pan_oncc = pan_oncc; |
621 |
|
region->pan_curvecc = pan_curvecc; |
622 |
|
region->pan_smoothcc = pan_smoothcc; |
623 |
region->width = width; |
region->width = width; |
624 |
region->position = position; |
region->position = position; |
625 |
region->amp_keytrack = amp_keytrack; |
region->amp_keytrack = amp_keytrack; |
784 |
region->amplfo_freq = amplfo_freq; |
region->amplfo_freq = amplfo_freq; |
785 |
region->amplfo_depth = amplfo_depth; |
region->amplfo_depth = amplfo_depth; |
786 |
|
|
787 |
|
region->amplfo_delay_oncc = amplfo_delay_oncc; |
788 |
|
region->amplfo_fade_oncc = amplfo_fade_oncc; |
789 |
region->amplfo_depthcc = amplfo_depthcc; |
region->amplfo_depthcc = amplfo_depthcc; |
790 |
region->amplfo_freqcc = amplfo_freqcc; |
region->amplfo_freqcc = amplfo_freqcc; |
791 |
|
|
794 |
region->fillfo_freq = fillfo_freq; |
region->fillfo_freq = fillfo_freq; |
795 |
region->fillfo_depth = fillfo_depth; |
region->fillfo_depth = fillfo_depth; |
796 |
|
|
797 |
|
region->fillfo_delay_oncc = fillfo_delay_oncc; |
798 |
|
region->fillfo_fade_oncc = fillfo_fade_oncc; |
799 |
region->fillfo_depthcc = fillfo_depthcc; |
region->fillfo_depthcc = fillfo_depthcc; |
800 |
region->fillfo_freqcc = fillfo_freqcc; |
region->fillfo_freqcc = fillfo_freqcc; |
801 |
|
|
804 |
region->pitchlfo_freq = pitchlfo_freq; |
region->pitchlfo_freq = pitchlfo_freq; |
805 |
region->pitchlfo_depth = pitchlfo_depth; |
region->pitchlfo_depth = pitchlfo_depth; |
806 |
|
|
807 |
|
region->pitchlfo_delay_oncc = pitchlfo_delay_oncc; |
808 |
|
region->pitchlfo_fade_oncc = pitchlfo_fade_oncc; |
809 |
region->pitchlfo_depthcc = pitchlfo_depthcc; |
region->pitchlfo_depthcc = pitchlfo_depthcc; |
810 |
region->pitchlfo_freqcc = pitchlfo_freqcc; |
region->pitchlfo_freqcc = pitchlfo_freqcc; |
811 |
|
|
835 |
currentDir = LinuxSampler::Path::stripLastName(file); |
currentDir = LinuxSampler::Path::stripLastName(file); |
836 |
std::string token; |
std::string token; |
837 |
std::string line; |
std::string line; |
838 |
|
currentLine = 0; |
839 |
|
|
840 |
while (std::getline(fs, line)) |
while (std::getline(fs, line)) |
841 |
{ |
{ |
842 |
|
currentLine++; |
843 |
// COMMENT |
// COMMENT |
844 |
std::string::size_type slash_index = line.find("//"); |
std::string::size_type slash_index = line.find("//"); |
845 |
if (slash_index != std::string::npos) |
if (slash_index != std::string::npos) |
995 |
copySmoothValues(r->volume_smoothcc, r->volume_oncc); |
copySmoothValues(r->volume_smoothcc, r->volume_oncc); |
996 |
r->volume_smoothcc.clear(); |
r->volume_smoothcc.clear(); |
997 |
|
|
998 |
|
copyCurves(r->pan_curvecc, r->pan_oncc); |
999 |
|
r->pan_curvecc.clear(); |
1000 |
|
|
1001 |
|
copySmoothValues(r->pan_smoothcc, r->pan_oncc); |
1002 |
|
r->pan_smoothcc.clear(); |
1003 |
|
|
1004 |
|
for (int j = 0; j < r->eg.size(); j++) { |
1005 |
|
copyCurves(r->eg[j].pan_curvecc, r->eg[j].pan_oncc); |
1006 |
|
r->eg[j].pan_curvecc.clear(); |
1007 |
|
} |
1008 |
|
|
1009 |
for (int j = 0; j < r->lfos.size(); j++) { |
for (int j = 0; j < r->lfos.size(); j++) { |
1010 |
copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc); |
copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc); |
1011 |
r->lfos[j].volume_smoothcc.clear(); |
r->lfos[j].volume_smoothcc.clear(); |
1059 |
} |
} |
1060 |
} |
} |
1061 |
} |
} |
1062 |
|
|
1063 |
|
int File::ToInt(const std::string& s) throw(LinuxSampler::Exception) { |
1064 |
|
int i; |
1065 |
|
std::istringstream iss(s); |
1066 |
|
if(!(iss >> i)) { |
1067 |
|
std::ostringstream oss; |
1068 |
|
oss << "Line " << currentLine << ": Expected an integer"; |
1069 |
|
throw LinuxSampler::Exception(oss.str()); |
1070 |
|
} |
1071 |
|
return i; |
1072 |
|
} |
1073 |
|
|
1074 |
|
float File::ToFloat(const std::string& s) throw(LinuxSampler::Exception) { |
1075 |
|
float i; |
1076 |
|
std::istringstream iss(s); |
1077 |
|
if(!(iss >> i)) { |
1078 |
|
std::ostringstream oss; |
1079 |
|
oss << "Line " << currentLine << ": Expected a floating-point number"; |
1080 |
|
throw LinuxSampler::Exception(oss.str()); |
1081 |
|
} |
1082 |
|
return i; |
1083 |
|
} |
1084 |
|
|
1085 |
void |
void |
1086 |
File::push_header(std::string token) |
File::push_header(std::string token) |
1399 |
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
1400 |
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); |
1401 |
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
1402 |
|
else if (sscanf(s, "_amplitude_oncc%d", &y)) eg(x).amplitude_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1403 |
|
else if (strcmp(s, "_volume") == 0) eg(x).volume = check(key, -144.0f, 6.0f, ToFloat(value)); |
1404 |
|
else if (sscanf(s, "_volume_oncc%d", &y)) eg(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) ); |
1405 |
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
1406 |
|
else if (sscanf(s, "_cutoff_oncc%d", &y)) eg(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); |
1407 |
|
else if (strcmp(s, "_pitch") == 0) eg(x).pitch = check(key, -9600, 9600, ToInt(value)); |
1408 |
|
else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); |
1409 |
|
else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value)); |
1410 |
|
else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) ); |
1411 |
|
else if (strcmp(s, "_pan") == 0) eg(x).pan = check(key, -100.0f, 100.0f, ToFloat(value)); |
1412 |
|
else if (strcmp(s, "_pan_curve") == 0) eg(x).pan_curve = check(key, 0, 30000, ToInt(value)); |
1413 |
|
else if (sscanf(s, "_pan_oncc%d", &y)) eg(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1414 |
|
else if (sscanf(s, "_pan_curvecc%d", &y)) eg(x).pan_curvecc.add( CC(y, 0.0f, check(key, 0, 30000, ToInt(value))) ); |
1415 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1416 |
} |
} |
1417 |
|
|
1572 |
else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1573 |
else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1574 |
|
|
1575 |
|
else if ("pitchlfo_delay_on" == key_cc) pCurDef->pitchlfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1576 |
|
else if ("pitchlfo_fade_on" == key_cc) pCurDef->pitchlfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1577 |
else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value)); |
else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value)); |
1578 |
else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1579 |
|
else if ("fillfo_delay_on" == key_cc) pCurDef->fillfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1580 |
|
else if ("fillfo_fade_on" == key_cc) pCurDef->fillfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1581 |
else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) ); |
else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) ); |
1582 |
else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1583 |
|
else if ("amplfo_delay_on" == key_cc) pCurDef->amplfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1584 |
|
else if ("amplfo_fade_on" == key_cc) pCurDef->amplfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1585 |
else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) ); |
else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) ); |
1586 |
else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1587 |
else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -144.0f, 100.0f, ToFloat(value))) ); |
1588 |
else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) ); |
else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) ); |
1589 |
else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) ); |
else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) ); |
1590 |
|
else if ("pan_on" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1591 |
|
else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) ); |
1592 |
|
else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) ); |
1593 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1594 |
} |
} |
1595 |
|
|
1648 |
} |
} |
1649 |
|
|
1650 |
EG::EG() : |
EG::EG() : |
1651 |
sustain(0), loop(0), loop_count(0), |
sustain(0), loop(0), loop_count(0), amplitude(0), pan(0), pan_curve(-1), |
1652 |
amplitude(0), cutoff(0) { |
cutoff(0), pitch(0), resonance(0), volume(-200) /* less than -144 dB is considered unset */ |
1653 |
} |
{ } |
1654 |
|
|
1655 |
void EG::Copy(const EG& eg) { |
void EG::Copy(const EG& eg) { |
1656 |
sustain = eg.sustain; |
sustain = eg.sustain; |
1657 |
loop = eg.loop; |
loop = eg.loop; |
1658 |
loop_count = eg.loop_count; |
loop_count = eg.loop_count; |
1659 |
amplitude = eg.amplitude; |
amplitude = eg.amplitude; |
1660 |
|
volume = eg.volume; |
1661 |
cutoff = eg.cutoff; |
cutoff = eg.cutoff; |
1662 |
|
pitch = eg.pitch; |
1663 |
|
resonance = eg.resonance; |
1664 |
|
pan = eg.pan; |
1665 |
|
pan_curve = eg.pan_curve; |
1666 |
node = eg.node; |
node = eg.node; |
1667 |
|
|
1668 |
|
amplitude_oncc = eg.amplitude_oncc; |
1669 |
|
volume_oncc = eg.volume_oncc; |
1670 |
|
cutoff_oncc = eg.cutoff_oncc; |
1671 |
|
pitch_oncc = eg.pitch_oncc; |
1672 |
|
resonance_oncc = eg.resonance_oncc; |
1673 |
|
pan_oncc = eg.pan_oncc; |
1674 |
|
pan_curvecc = eg.pan_curvecc; |
1675 |
} |
} |
1676 |
|
|
1677 |
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 */ |