--- linuxsampler/trunk/src/engines/sfz/sfz.cpp 2010/07/04 12:50:51 2106 +++ linuxsampler/trunk/src/engines/sfz/sfz.cpp 2011/04/25 08:12:36 2175 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2008 Anders Dahnielson * - * Copyright (C) 2009 - 2010 Anders Dahnielson and Grigor Iliev * + * Copyright (C) 2009 - 2011 Anders Dahnielson and Grigor Iliev * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -142,69 +142,6 @@ return is_triggered; } - bool - Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val, - int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, - uint8_t prog, float rand, trigger_t trig, uint8_t* cc, - float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) - { - // chan (MIDI channel) - // cont (MIDI controller) - // val (MIDI controller value) - - // bend (MIDI pitch bend) - // bpm (host BPM) - // chanaft (MIDI channel pressure) - // polyaft (MIDI polyphonic aftertouch) - // prog (MIDI program change) - // rand (generated random number) - // trigger (how it was triggered) - // cc (all CC values) - - // timer (time since previous region in the group was triggered) - // sw (the state of region key switches, 128 possible values) - // last_sw_key (the last key pressed in the key switch range) - // prev_sw_key (the previous note value) - - bool is_triggered = ( - chan >= lochan && chan <= hichan && - ((val >= on_locc[cont] && val <= on_hicc[cont]) || - (val >= start_locc[cont] && val <= start_hicc[cont])) && - bend >= lobend && bend <= hibend && - bpm >= lobpm && bpm < hibpm && - chanaft >= lochanaft && chanaft <= hichanaft && - polyaft >= lopolyaft && polyaft <= hipolyaft && - prog >= loprog && prog <= hiprog && - rand >= lorand && rand < hirand && - timer >= lotimer && timer <= hitimer && - - ( sw_last == -1 || - ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : false) ) && - - ( sw_down == -1 || - ((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (sw[sw_down]) : false) ) && - - ( sw_up == -1 || - ((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!sw[sw_up]) : true) ) && - - ( sw_previous == -1 || - prev_sw_key == sw_previous ) && - - ((trigger & trig) != 0) - ); - - if (!is_triggered) - return false; - - for (int i = 0; i < 128; ++i) - { - if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i])) - return false; - } - - return true; - } - Articulation* Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc) { @@ -212,16 +149,17 @@ } bool Region::HasLoop() { - bool b = loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN; // TODO: ONE_SHOT mode + bool b = loop_mode == ::sfz::LOOP_UNSET ? pSample->GetLoops() : + (loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN); return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); } uint Region::GetLoopStart() { - return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined + return (!loop_start) ? pSample->GetLoopStart() : *loop_start; } uint Region::GetLoopEnd() { - return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined + return (!loop_end) ? pSample->GetLoopEnd() : *loop_end; } uint Region::GetLoopCount() { @@ -244,6 +182,9 @@ delete regions[i]; } delete pLookupTable; + for (int i = 0 ; i < 128 ; i++) { + delete pLookupTableCC[i]; + } } void Query::search(const Instrument* pInstrument) { @@ -251,6 +192,11 @@ regionIndex = 0; } + void Query::search(const Instrument* pInstrument, int triggercc) { + pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this); + regionIndex = 0; + } + Region* Query::next() { for ( ; regionIndex < pRegionList->size() ; regionIndex++) { if ((*pRegionList)[regionIndex]->OnKey(*this)) { @@ -328,7 +274,7 @@ trigger = TRIGGER_ATTACK; group = 0; - off_by.unset(); + off_by = 0; off_mode = OFF_FAST; // sample player @@ -339,7 +285,7 @@ end.unset(); loop_crossfade.unset(); offset.unset(); offset_random.unset(); - loop_mode = NO_LOOP; + loop_mode = LOOP_UNSET; loop_start.unset(); loop_end.unset(); sync_beats.unset(); sync_offset.unset(); @@ -466,6 +412,7 @@ eq2_gain_oncc.set(i, 0); eq3_gain_oncc.set(i, 0); } + cutoff_cc = 0; eg.clear(); @@ -628,6 +575,7 @@ region->fil_type = fil_type; region->cutoff = cutoff; region->cutoff_oncc = cutoff_oncc; + region->cutoff_cc = cutoff_cc; region->cutoff_smoothcc = cutoff_smoothcc; region->cutoff_stepcc = cutoff_stepcc; region->cutoff_curvecc = cutoff_curvecc; @@ -832,10 +780,15 @@ ::sfz::Region* pRegion = _instrument->regions[i]; int low = pRegion->lokey; int high = pRegion->hikey; - if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { - std::cerr << "Invalid key range: " << low << " - " << high << std::endl; - } else { - for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; + if (low != -1) { // lokey -1 means region doesn't play on note-on + // hikey -1 is the same as no limit, except that it + // also enables on_locc/on_hicc + if (high == -1) high = 127; + if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { + std::cerr << "Invalid key range: " << low << " - " << high << std::endl; + } else { + for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; + } } // get keyswitches @@ -890,6 +843,12 @@ } _instrument->pLookupTable = new LookupTable(_instrument); + + // create separate lookup tables for controller triggered + // regions, one for each CC + for (int i = 0 ; i < 128 ; i++) { + _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); + } } File::~File() @@ -1037,8 +996,8 @@ else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); else if ("off_mode" == key || "offmode" == key) { - if (value == "fast") _current_group->off_mode = OFF_FAST; - else if (value == "normal") _current_group->off_mode = OFF_NORMAL; + if (value == "fast") pCurDef->off_mode = OFF_FAST; + else if (value == "normal") pCurDef->off_mode = OFF_NORMAL; } // sample player @@ -1213,8 +1172,10 @@ 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)); - else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); + 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)); @@ -1313,6 +1274,7 @@ case 'g': i = 7; break; case 'a': i = 9; break; case 'b': i = 11; break; + case '-': if (s == "-1") return -1; default: std::cerr << "Not a note: " << s << std::endl; return 0;