--- linuxsampler/trunk/src/engines/sfz/sfz.cpp 2011/07/28 18:24:12 2222 +++ linuxsampler/trunk/src/engines/sfz/sfz.cpp 2011/08/10 19:40:39 2235 @@ -51,7 +51,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 +59,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 +110,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; @@ -198,6 +196,13 @@ this->name = name; this->pSampleManager = pSampleManager ? pSampleManager : this; pLookupTable = 0; + + // The first 6 curves are defined internally (actually 7 with the one at index 0) + Curve c; + for (int i = 0; i < 128; i++) c.v[i] = i / 127.0f; + curves.add(c); curves.add(c); curves.add(c); curves.add(c); + curves.add(c); curves.add(c); curves.add(c); + /////// } Instrument::~Instrument() @@ -315,6 +320,9 @@ // amplifier volume = 0; + volume_oncc.clear(); + volume_curvecc.clear(); + volume_smoothcc.clear(); pan = 0; width = 100; position = 0; @@ -435,10 +443,13 @@ eq1_gain_oncc.set(i, 0); eq2_gain_oncc.set(i, 0); eq3_gain_oncc.set(i, 0); + + pitchlfo_depthcc.set(i, 0); } cutoff_cc = 0; eg.clear(); + lfos.clear(); // deprecated ampeg_delay = 0; @@ -455,6 +466,14 @@ ampeg_vel2decay = 0; ampeg_vel2sustain = 0; ampeg_vel2release = 0; + + ampeg_delaycc.clear(); + ampeg_startcc.clear(); + ampeg_attackcc.clear(); + ampeg_holdcc.clear(); + ampeg_decaycc.clear(); + ampeg_sustaincc.clear(); + ampeg_releasecc.clear(); fileg_delay = 0; fileg_start = 0; //in percentage @@ -490,18 +509,23 @@ amplfo_delay = 0; amplfo_fade = 0; - amplfo_freq = 0; + amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ amplfo_depth = 0; + amplfo_depthcc.clear(); + amplfo_freqcc.clear(); fillfo_delay = 0; fillfo_fade = 0; - fillfo_freq = 0; + fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ fillfo_depth = 0; + fillfo_depthcc.clear(); + fillfo_freqcc.clear(); pitchlfo_delay = 0; pitchlfo_fade = 0; - pitchlfo_freq = 0; + pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ pitchlfo_depth = 0; + pitchlfo_freqcc.clear(); } Region* @@ -581,6 +605,9 @@ // amplifier region->volume = volume; + region->volume_oncc = volume_oncc; + region->volume_curvecc = volume_curvecc; + region->volume_smoothcc = volume_smoothcc; region->pan = pan; region->width = width; region->position = position; @@ -700,6 +727,14 @@ region->ampeg_vel2decay = ampeg_vel2decay; region->ampeg_vel2sustain = ampeg_vel2sustain; region->ampeg_vel2release = ampeg_vel2release; + + region->ampeg_delaycc = ampeg_delaycc; + region->ampeg_startcc = ampeg_startcc; + region->ampeg_attackcc = ampeg_attackcc; + region->ampeg_holdcc = ampeg_holdcc; + region->ampeg_decaycc = ampeg_decaycc; + region->ampeg_sustaincc = ampeg_sustaincc; + region->ampeg_releasecc = ampeg_releasecc; region->fileg_delay = fileg_delay; region->fileg_start = fileg_start; @@ -737,16 +772,28 @@ region->amplfo_fade = amplfo_fade; region->amplfo_freq = amplfo_freq; region->amplfo_depth = amplfo_depth; + + region->amplfo_depthcc = amplfo_depthcc; + region->amplfo_freqcc = amplfo_freqcc; region->fillfo_delay = fillfo_delay; region->fillfo_fade = fillfo_fade; region->fillfo_freq = fillfo_freq; region->fillfo_depth = fillfo_depth; + + region->fillfo_depthcc = fillfo_depthcc; + region->fillfo_freqcc = fillfo_freqcc; region->pitchlfo_delay = pitchlfo_delay; region->pitchlfo_fade = pitchlfo_fade; region->pitchlfo_freq = pitchlfo_freq; region->pitchlfo_depth = pitchlfo_depth; + + region->pitchlfo_depthcc = pitchlfo_depthcc; + region->pitchlfo_freqcc = pitchlfo_freqcc; + + region->eg = eg; + region->lfos = lfos; return region; } @@ -919,6 +966,36 @@ for (int i = 0 ; i < 128 ; i++) { _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); } + + for (int i = 0; i < _instrument->regions.size(); i++) { + Region* r = _instrument->regions[i]; + + copyCurves(r->volume_curvecc, r->volume_oncc); + r->volume_curvecc.clear(); + + copySmoothValues(r->volume_smoothcc, r->volume_oncc); + r->volume_smoothcc.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(); + } + } } File::~File() @@ -932,6 +1009,26 @@ { return _instrument; } + + void File::copyCurves(LinuxSampler::ArrayList& curves, LinuxSampler::ArrayList& dest) { + for (int i = 0; i < curves.size(); i++) { + for (int j = 0; j < dest.size(); j++) { + if (curves[i].Controller == dest[j].Controller) { + dest[j].Curve = curves[i].Curve; + } + } + } + } + + void File::copySmoothValues(LinuxSampler::ArrayList& smooths, LinuxSampler::ArrayList& dest) { + for (int i = 0; i < smooths.size(); i++) { + for (int j = 0; j < dest.size(); j++) { + if (smooths[i].Controller == dest[j].Controller) { + dest[j].Smooth = smooths[i].Smooth; + } + } + } + } void File::push_header(std::string token) @@ -957,6 +1054,12 @@ octave_offset = 0; note_offset = 0; } + else if (token == "") + { + _current_section = CURVE; + _instrument->curves.add(Curve()); + _current_curve = &_instrument->curves[_instrument->curves.size() - 1]; + } else { _current_section = UNKNOWN; @@ -973,7 +1076,20 @@ std::string::size_type delimiter_index = token.find('='); std::string key = token.substr(0, delimiter_index); std::string value = token.substr(delimiter_index + 1); - int x, y; + int x, y, z; + + if (_current_section == CURVE) { + if (sscanf(key.c_str(), "v%d", &x)) { + if (x < 0 || x > 127) { + std::cerr << "Invalid curve index: " << x << std::endl; + } + _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value)); + } else { + std::cerr << "The opcode '" << key << "' in section is unsupported by libsfz!" << std::endl; + } + + return; + } // sample definition if ("sample" == key) @@ -1104,7 +1220,7 @@ else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value); else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); - else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value); + else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value); else if ("xfin_lokey" == key) pCurDef->xfin_lokey = parseKey(value); else if ("xfin_hikey" == key) pCurDef->xfin_hikey = parseKey(value); else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value); @@ -1138,7 +1254,7 @@ else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value); else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value); - else if ("bend_step" == key) pCurDef->bend_step = ToInt(value); + else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value); // filter else if ("fil_type" == key || "filtype" == key) @@ -1212,80 +1328,34 @@ else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) { pCurDef->amp_velcurve.set(x, ToFloat(value)); } - - // CCs - else if (key.find("cc") != std::string::npos) - { - std::string::size_type delimiter_index = key.find("cc"); - std::string key_cc = key.substr(0, delimiter_index); - int num_cc = ToInt(key.substr(delimiter_index + 2)); - - // input controls - if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value)); - else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value)); - else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value)); - else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value)); - else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value)); - else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value)); - else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value)); - else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value)); - - // sample player - else if ("delay_on" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value)); - else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value)); - else if ("offset_on" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value)); - - // amplifier - else if ("gain_on" == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value)); - else if ("xfin_lo" == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value)); - else if ("xfin_hi" == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value)); - else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value)); - else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value)); - - // filter - else if ("cutoff_on" == key_cc || "cutoff_" == key_cc) { - pCurDef->cutoff_oncc.set(num_cc, ToInt(value)); - pCurDef->cutoff_cc = num_cc; - } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); - else if ("cutoff_smooth" == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value)); - else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value)); - else if ("cutoff_step" == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value)); - else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.set(num_cc, ToInt(value)); - else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.set(num_cc, ToInt(value)); - else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.set(num_cc, ToInt(value)); - else if ("resonance_on" == key_cc) pCurDef->resonance_oncc.set(num_cc, ToInt(value)); - else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc.set(num_cc, ToInt(value)); - else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.set(num_cc, ToInt(value)); - else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.set(num_cc, ToInt(value)); - else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.set(num_cc, ToInt(value)); - else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.set(num_cc, ToInt(value)); - else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.set(num_cc, ToInt(value)); - else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.set(num_cc, ToInt(value)); - - // per voice equalizer - else if ("eq1_freq_on" == key_cc || "eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value)); - else if ("eq2_freq_on" == key_cc || "eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value)); - else if ("eq3_freq_on" == key_cc || "eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value)); - else if ("eq1_bw_on" == key_cc || "eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value)); - else if ("eq2_bw_on" == key_cc || "eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value)); - else if ("eq3_bw_on" == key_cc || "eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value)); - else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value)); - else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value)); - else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value)); - else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; - } + // v2 envelope generators else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) { const char* s = key.c_str() + y; - if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value); - else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value); + if (sscanf(s, "_time%d%n", &y, &z)) { + const char* s2 = s + z; + if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value)); + else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) ); + } else if (sscanf(s, "_level%d%n", &y, &z)) { + const char* s2 = s + z; + if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value)); + else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) ); + } else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value); else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value); else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value); 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 std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; } @@ -1351,13 +1421,110 @@ else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) { 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; + } + + // CCs + else if (key.find("cc") != std::string::npos) + { + std::string::size_type delimiter_index = key.find("cc"); + std::string key_cc = key.substr(0, delimiter_index); + int num_cc = ToInt(key.substr(delimiter_index + 2)); + + // input controls + if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value)); + else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value)); + else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value)); + else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value)); + else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value)); + else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value)); + else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value)); + else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value)); + + // sample player + else if ("delay_on" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value)); + else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value)); + else if ("offset_on" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value)); + + // amplifier + else if ("gain_on" == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value)); + else if ("xfin_lo" == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value)); + else if ("xfin_hi" == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value)); + else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value)); + else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value)); + + // filter + else if ("cutoff_on" == key_cc || "cutoff_" == key_cc) { + pCurDef->cutoff_oncc.set(num_cc, ToInt(value)); + pCurDef->cutoff_cc = num_cc; + } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); + else if ("cutoff_smooth" == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value)); + else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value)); + else if ("cutoff_step" == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value)); + else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.set(num_cc, ToInt(value)); + else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.set(num_cc, ToInt(value)); + else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.set(num_cc, ToInt(value)); + else if ("resonance_on" == key_cc) pCurDef->resonance_oncc.set(num_cc, ToInt(value)); + else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc.set(num_cc, ToInt(value)); + else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.set(num_cc, ToInt(value)); + else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.set(num_cc, ToInt(value)); + else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.set(num_cc, ToInt(value)); + else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.set(num_cc, ToInt(value)); + else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.set(num_cc, ToInt(value)); + else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.set(num_cc, ToInt(value)); + + // per voice equalizer + else if ("eq1_freq_on" == key_cc || "eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value)); + else if ("eq2_freq_on" == key_cc || "eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value)); + else if ("eq3_freq_on" == key_cc || "eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value)); + else if ("eq1_bw_on" == key_cc || "eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value)); + else if ("eq2_bw_on" == key_cc || "eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value)); + else if ("eq3_bw_on" == key_cc || "eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value)); + else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value)); + else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value)); + else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value)); + + else if ("ampeg_delay" == key_cc) pCurDef->ampeg_delaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if ("ampeg_start" == key_cc) pCurDef->ampeg_startcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if ("ampeg_attack" == key_cc) pCurDef->ampeg_attackcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if ("ampeg_hold" == key_cc) pCurDef->ampeg_holdcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); + else if ("ampeg_decay" == key_cc) pCurDef->ampeg_decaycc.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))) ); + else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.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_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_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_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 std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; } @@ -1404,10 +1571,72 @@ EGNode::EGNode() : time(0), level(0), shape(0), curve(0) { } + + void EGNode::Copy(const EGNode& egNode) { + time = egNode.time; + level = egNode.level; + shape = egNode.shape; + curve = egNode.curve; + + time_oncc = egNode.time_oncc; + level_oncc = egNode.level_oncc; + } EG::EG() : - sustain(0), loop(0), loop_count(0), - amplitude(0), cutoff(0) { + sustain(0), loop(0), loop_count(0), amplitude(0), + 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; + 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; + } + + LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ + fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) { + + } + + void LFO::Copy(const LFO& lfo) { + delay = lfo.delay; + freq = lfo.freq; + fade = lfo.fade; + phase = lfo.phase; + wave = lfo.wave; + volume = lfo.volume; + pitch = lfo.pitch; + cutoff = lfo.cutoff; + resonance = lfo.resonance; + pan = lfo.pan; + + 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) { @@ -1424,11 +1653,6 @@ } return e.node[y]; } - - LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ - wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) { - - } LFO& File::lfo(int x) { while (pCurDef->lfos.size() <= x) {