--- linuxsampler/trunk/src/engines/sfz/sfz.cpp 2011/08/08 13:40:04 2232 +++ linuxsampler/trunk/src/engines/sfz/sfz.cpp 2011/08/19 15:51:18 2248 @@ -31,7 +31,6 @@ #include "../../common/File.h" #include "../../common/Path.h" -#include "../../common/global_private.h" #include "LookupTable.h" namespace sfz @@ -51,7 +50,7 @@ return val; } - Sample* SampleManager::FindSample(std::string samplePath, int offset) { + Sample* SampleManager::FindSample(std::string samplePath, uint offset, int end) { std::map >::iterator it = sampleMap.begin(); for (; it != sampleMap.end(); it++) { if (it->first->GetFile() == samplePath) { @@ -59,10 +58,7 @@ * same sample with different offset as different samples * // TODO: Ignore offset when the whole sample is cached in RAM? */ - int maxOffset = it->first->MaxOffset; - if(it->first->Offset == offset || (it->first->Offset < maxOffset && offset < maxOffset)) { - return it->first; - } + if (it->first->Offset == offset && it->first->End == end) return it->first; } } @@ -113,10 +109,11 @@ Sample* Region::GetSample(bool create) { if(pSample == NULL && create) { - int i = offset ? *offset : 0; - Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i); + uint i = offset ? *offset : 0; + int e = end ? *end : -2; + Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, e); if (sf != NULL) pSample = sf; // Reuse already created sample - else pSample = new Sample(sample, false, i); + else pSample = new Sample(sample, false, i, e); GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); } return pSample; @@ -326,6 +323,9 @@ volume_curvecc.clear(); volume_smoothcc.clear(); pan = 0; + pan_oncc.clear(); + pan_curvecc.clear(); + pan_smoothcc.clear(); width = 100; position = 0; amp_keytrack = 0; @@ -413,8 +413,8 @@ gain_oncc.set(i, 0); xfin_locc.set(i, 0); xfin_hicc.set(i, 0); - xfout_locc.set(i, 127); - xfout_hicc.set(i, 127); + xfout_locc.set(i, 0); + xfout_hicc.set(i, 0); // filter cutoff_oncc.set(i, 0); @@ -513,18 +513,26 @@ amplfo_fade = 0; amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ amplfo_depth = 0; + amplfo_delay_oncc.clear(); + amplfo_fade_oncc.clear(); + amplfo_depthcc.clear(); amplfo_freqcc.clear(); fillfo_delay = 0; fillfo_fade = 0; fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ fillfo_depth = 0; + fillfo_delay_oncc.clear(); + fillfo_fade_oncc.clear(); + fillfo_depthcc.clear(); fillfo_freqcc.clear(); pitchlfo_delay = 0; pitchlfo_fade = 0; pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ pitchlfo_depth = 0; + pitchlfo_delay_oncc.clear(); + pitchlfo_fade_oncc.clear(); pitchlfo_freqcc.clear(); } @@ -609,6 +617,9 @@ region->volume_curvecc = volume_curvecc; region->volume_smoothcc = volume_smoothcc; region->pan = pan; + region->pan_oncc = pan_oncc; + region->pan_curvecc = pan_curvecc; + region->pan_smoothcc = pan_smoothcc; region->width = width; region->position = position; region->amp_keytrack = amp_keytrack; @@ -773,6 +784,9 @@ region->amplfo_freq = amplfo_freq; region->amplfo_depth = amplfo_depth; + region->amplfo_delay_oncc = amplfo_delay_oncc; + region->amplfo_fade_oncc = amplfo_fade_oncc; + region->amplfo_depthcc = amplfo_depthcc; region->amplfo_freqcc = amplfo_freqcc; region->fillfo_delay = fillfo_delay; @@ -780,6 +794,9 @@ region->fillfo_freq = fillfo_freq; region->fillfo_depth = fillfo_depth; + region->fillfo_delay_oncc = fillfo_delay_oncc; + region->fillfo_fade_oncc = fillfo_fade_oncc; + region->fillfo_depthcc = fillfo_depthcc; region->fillfo_freqcc = fillfo_freqcc; region->pitchlfo_delay = pitchlfo_delay; @@ -787,6 +804,8 @@ region->pitchlfo_freq = pitchlfo_freq; region->pitchlfo_depth = pitchlfo_depth; + region->pitchlfo_delay_oncc = pitchlfo_delay_oncc; + region->pitchlfo_fade_oncc = pitchlfo_fade_oncc; region->pitchlfo_depthcc = pitchlfo_depthcc; region->pitchlfo_freqcc = pitchlfo_freqcc; @@ -816,9 +835,11 @@ currentDir = LinuxSampler::Path::stripLastName(file); std::string token; std::string line; + currentLine = 0; while (std::getline(fs, line)) { + currentLine++; // COMMENT std::string::size_type slash_index = line.find("//"); if (slash_index != std::string::npos) @@ -965,14 +986,45 @@ _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); } - for (int k = 0; k < _instrument->regions.size(); k++) { - Region* r = _instrument->regions[k]; + for (int i = 0; i < _instrument->regions.size(); i++) { + Region* r = _instrument->regions[i]; copyCurves(r->volume_curvecc, r->volume_oncc); - copySmoothValues(r->volume_smoothcc, r->volume_oncc); - r->volume_curvecc.clear(); + + copySmoothValues(r->volume_smoothcc, r->volume_oncc); r->volume_smoothcc.clear(); + + copyCurves(r->pan_curvecc, r->pan_oncc); + r->pan_curvecc.clear(); + + copySmoothValues(r->pan_smoothcc, r->pan_oncc); + r->pan_smoothcc.clear(); + + for (int j = 0; j < r->eg.size(); j++) { + copyCurves(r->eg[j].pan_curvecc, r->eg[j].pan_oncc); + r->eg[j].pan_curvecc.clear(); + } + + for (int j = 0; j < r->lfos.size(); j++) { + copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc); + r->lfos[j].volume_smoothcc.clear(); + + copySmoothValues(r->lfos[j].freq_smoothcc, r->lfos[j].freq_oncc); + r->lfos[j].freq_smoothcc.clear(); + + copySmoothValues(r->lfos[j].pitch_smoothcc, r->lfos[j].pitch_oncc); + r->lfos[j].pitch_smoothcc.clear(); + + copySmoothValues(r->lfos[j].pan_smoothcc, r->lfos[j].pan_oncc); + r->lfos[j].pan_smoothcc.clear(); + + copySmoothValues(r->lfos[j].cutoff_smoothcc, r->lfos[j].cutoff_oncc); + r->lfos[j].cutoff_smoothcc.clear(); + + copySmoothValues(r->lfos[j].resonance_smoothcc, r->lfos[j].resonance_oncc); + r->lfos[j].resonance_smoothcc.clear(); + } } } @@ -1007,6 +1059,28 @@ } } } + + int File::ToInt(const std::string& s) throw(LinuxSampler::Exception) { + int i; + std::istringstream iss(s); + if(!(iss >> i)) { + std::ostringstream oss; + oss << "Line " << currentLine << ": Expected an integer"; + throw LinuxSampler::Exception(oss.str()); + } + return i; + } + + float File::ToFloat(const std::string& s) throw(LinuxSampler::Exception) { + float i; + std::istringstream iss(s); + if(!(iss >> i)) { + std::ostringstream oss; + oss << "Line " << currentLine << ": Expected a floating-point number"; + throw LinuxSampler::Exception(oss.str()); + } + return i; + } void File::push_header(std::string token) @@ -1325,7 +1399,19 @@ else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); + else if (sscanf(s, "_amplitude_oncc%d", &y)) eg(x).amplitude_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); + else if (strcmp(s, "_volume") == 0) eg(x).volume = check(key, -144.0f, 6.0f, ToFloat(value)); + else if (sscanf(s, "_volume_oncc%d", &y)) eg(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) ); else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); + else if (sscanf(s, "_cutoff_oncc%d", &y)) eg(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); + else if (strcmp(s, "_pitch") == 0) eg(x).pitch = check(key, -9600, 9600, ToInt(value)); + else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); + else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value)); + else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) ); + else if (strcmp(s, "_pan") == 0) eg(x).pan = check(key, -100.0f, 100.0f, ToFloat(value)); + else if (strcmp(s, "_pan_curve") == 0) eg(x).pan_curve = check(key, 0, 30000, ToInt(value)); + else if (sscanf(s, "_pan_oncc%d", &y)) eg(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if (sscanf(s, "_pan_curvecc%d", &y)) eg(x).pan_curvecc.add( CC(y, 0.0f, check(key, 0, 30000, ToInt(value))) ); else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; } @@ -1392,18 +1478,29 @@ const char* s = key.c_str() + y; if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value)); else if (sscanf(s, "_freq_oncc%d", &y)) lfo(x).freq_oncc.add( CC(y, check(key, 0.0f, 20.0f, ToFloat(value))) ); + else if (sscanf(s, "_freq_smoothcc%d", &y)) lfo(x).freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value); else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value)); + else if (sscanf(s, "_delay_oncc%d", &y)) lfo(x).delay_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value)); else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value)); else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) ); else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value)); + else if (sscanf(s, "_volume_oncc%d", &y)) lfo(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) ); + else if (sscanf(s, "_volume_smoothcc%d", &y)) lfo(x).volume_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value)); else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); + else if (sscanf(s, "_pitch_smoothcc%d", &y)) lfo(x).pitch_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value)); + else if (sscanf(s, "_cutoff_oncc%d", &y)) lfo(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); + else if (sscanf(s, "_cutoff_smoothcc%d", &y)) lfo(x).cutoff_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value)); + else if (sscanf(s, "_resonance_oncc%d", &y)) lfo(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) ); + else if (sscanf(s, "_resonance_smoothcc%d", &y)) lfo(x).resonance_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value)); + else if (sscanf(s, "_pan_oncc%d", &y)) lfo(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if (sscanf(s, "_pan_smoothcc%d", &y)) lfo(x).pan_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; } @@ -1475,13 +1572,24 @@ else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.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))) ); + else if ("pitchlfo_delay_on" == key_cc) pCurDef->pitchlfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); + else if ("pitchlfo_fade_on" == key_cc) pCurDef->pitchlfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value)); else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); + else if ("fillfo_delay_on" == key_cc) pCurDef->fillfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); + else if ("fillfo_fade_on" == key_cc) pCurDef->fillfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); + else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) ); else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); + else if ("amplfo_delay_on" == key_cc) pCurDef->amplfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); + else if ("amplfo_fade_on" == key_cc) pCurDef->amplfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) ); + else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) ); else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); - 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))) ); else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(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))) ); + else if ("pan_on" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) ); + else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) ); else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; } @@ -1540,17 +1648,30 @@ } EG::EG() : - sustain(0), loop(0), loop_count(0), - amplitude(0), cutoff(0) { - } + sustain(0), loop(0), loop_count(0), amplitude(0), pan(0), pan_curve(-1), + cutoff(0), pitch(0), resonance(0), volume(-200) /* less than -144 dB is considered unset */ + { } void EG::Copy(const EG& eg) { sustain = eg.sustain; loop = eg.loop; loop_count = eg.loop_count; amplitude = eg.amplitude; + volume = eg.volume; cutoff = eg.cutoff; + pitch = eg.pitch; + resonance = eg.resonance; + pan = eg.pan; + pan_curve = eg.pan_curve; node = eg.node; + + amplitude_oncc = eg.amplitude_oncc; + volume_oncc = eg.volume_oncc; + cutoff_oncc = eg.cutoff_oncc; + pitch_oncc = eg.pitch_oncc; + resonance_oncc = eg.resonance_oncc; + pan_oncc = eg.pan_oncc; + pan_curvecc = eg.pan_curvecc; } LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ @@ -1569,10 +1690,22 @@ cutoff = lfo.cutoff; resonance = lfo.resonance; pan = lfo.pan; - freq_oncc = lfo.freq_oncc; - fade_oncc = lfo.fade_oncc; - phase_oncc = lfo.phase_oncc; - pitch_oncc = lfo.pitch_oncc; + + delay_oncc = lfo.delay_oncc; + freq_oncc = lfo.freq_oncc; + freq_smoothcc = lfo.freq_smoothcc; + fade_oncc = lfo.fade_oncc; + phase_oncc = lfo.phase_oncc; + pitch_oncc = lfo.pitch_oncc; + pitch_smoothcc = lfo.pitch_smoothcc; + volume_oncc = lfo.volume_oncc; + volume_smoothcc = lfo.volume_smoothcc; + pan_oncc = lfo.pan_oncc; + pan_smoothcc = lfo.pan_smoothcc; + cutoff_oncc = lfo.cutoff_oncc; + cutoff_smoothcc = lfo.cutoff_smoothcc; + resonance_oncc = lfo.resonance_oncc; + resonance_smoothcc = lfo.resonance_smoothcc; } EG& File::eg(int x) {