/[svn]/linuxsampler/trunk/src/engines/sfz/sfz.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sfz/sfz.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2114 by persson, Tue Aug 10 12:05:19 2010 UTC revision 2176 by persson, Sun May 1 15:19:38 2011 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *
6   *   Copyright (C) 2009 - 2010 Anders Dahnielson and Grigor Iliev          *   *   Copyright (C) 2009 - 2011 Anders Dahnielson and Grigor Iliev          *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 142  namespace sfz Line 142  namespace sfz
142          return is_triggered;          return is_triggered;
143      }      }
144    
     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;  
     }  
   
145      Articulation*      Articulation*
146      Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)      Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)
147      {      {
# Line 212  namespace sfz Line 149  namespace sfz
149      }      }
150    
151      bool Region::HasLoop() {      bool Region::HasLoop() {
152          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() :
153                (loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN);
154          return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();          return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();
155      }      }
156    
157      uint Region::GetLoopStart() {      uint Region::GetLoopStart() {
158          return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined          return (!loop_start) ? pSample->GetLoopStart() : *loop_start;
159      }      }
160    
161      uint Region::GetLoopEnd() {      uint Region::GetLoopEnd() {
162          return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined          return (!loop_end) ? pSample->GetLoopEnd() : *loop_end;
163      }      }
164    
165      uint Region::GetLoopCount() {      uint Region::GetLoopCount() {
# Line 244  namespace sfz Line 182  namespace sfz
182              delete regions[i];              delete regions[i];
183          }          }
184          delete pLookupTable;          delete pLookupTable;
185            for (int i = 0 ; i < 128 ; i++) {
186                delete pLookupTableCC[i];
187            }
188      }      }
189    
190      void Query::search(const Instrument* pInstrument) {      void Query::search(const Instrument* pInstrument) {
# Line 251  namespace sfz Line 192  namespace sfz
192          regionIndex = 0;          regionIndex = 0;
193      }      }
194    
195        void Query::search(const Instrument* pInstrument, int triggercc) {
196            pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this);
197            regionIndex = 0;
198        }
199    
200      Region* Query::next() {      Region* Query::next() {
201          for ( ; regionIndex < pRegionList->size() ; regionIndex++) {          for ( ; regionIndex < pRegionList->size() ; regionIndex++) {
202              if ((*pRegionList)[regionIndex]->OnKey(*this)) {              if ((*pRegionList)[regionIndex]->OnKey(*this)) {
# Line 339  namespace sfz Line 285  namespace sfz
285          end.unset();          end.unset();
286          loop_crossfade.unset();          loop_crossfade.unset();
287          offset.unset(); offset_random.unset();          offset.unset(); offset_random.unset();
288          loop_mode = NO_LOOP;          loop_mode = LOOP_UNSET;
289          loop_start.unset(); loop_end.unset();          loop_start.unset(); loop_end.unset();
290          sync_beats.unset(); sync_offset.unset();          sync_beats.unset(); sync_offset.unset();
291    
# Line 466  namespace sfz Line 412  namespace sfz
412              eq2_gain_oncc.set(i, 0);              eq2_gain_oncc.set(i, 0);
413              eq3_gain_oncc.set(i, 0);              eq3_gain_oncc.set(i, 0);
414          }          }
415            cutoff_cc = 0;
416    
417          eg.clear();          eg.clear();
418    
# Line 478  namespace sfz Line 425  namespace sfz
425          ampeg_sustain  = 100; // in percentage          ampeg_sustain  = 100; // in percentage
426          ampeg_release  = 0;          ampeg_release  = 0;
427    
428            ampeg_vel2delay   = 0;
429            ampeg_vel2attack  = 0;
430            ampeg_vel2hold    = 0;
431            ampeg_vel2decay   = 0;
432            ampeg_vel2sustain = 0;
433            ampeg_vel2release = 0;
434    
435          fileg_delay    = 0;          fileg_delay    = 0;
436          fileg_start    = 0; //in percentage          fileg_start    = 0; //in percentage
437          fileg_attack   = 0;          fileg_attack   = 0;
# Line 628  namespace sfz Line 582  namespace sfz
582          region->fil_type = fil_type;          region->fil_type = fil_type;
583          region->cutoff = cutoff;          region->cutoff = cutoff;
584          region->cutoff_oncc = cutoff_oncc;          region->cutoff_oncc = cutoff_oncc;
585            region->cutoff_cc = cutoff_cc;
586          region->cutoff_smoothcc = cutoff_smoothcc;          region->cutoff_smoothcc = cutoff_smoothcc;
587          region->cutoff_stepcc = cutoff_stepcc;          region->cutoff_stepcc = cutoff_stepcc;
588          region->cutoff_curvecc = cutoff_curvecc;          region->cutoff_curvecc = cutoff_curvecc;
# Line 699  namespace sfz Line 654  namespace sfz
654          region->ampeg_sustain  = ampeg_sustain;          region->ampeg_sustain  = ampeg_sustain;
655          region->ampeg_release  = ampeg_release;          region->ampeg_release  = ampeg_release;
656    
657            region->ampeg_vel2delay   = ampeg_vel2delay;
658            region->ampeg_vel2attack  = ampeg_vel2attack;
659            region->ampeg_vel2hold    = ampeg_vel2hold;
660            region->ampeg_vel2decay   = ampeg_vel2decay;
661            region->ampeg_vel2sustain = ampeg_vel2sustain;
662            region->ampeg_vel2release = ampeg_vel2release;
663    
664          region->fileg_delay    = fileg_delay;          region->fileg_delay    = fileg_delay;
665          region->fileg_start    = fileg_start;          region->fileg_start    = fileg_start;
666          region->fileg_attack   = fileg_attack;          region->fileg_attack   = fileg_attack;
# Line 832  namespace sfz Line 794  namespace sfz
794              ::sfz::Region* pRegion = _instrument->regions[i];              ::sfz::Region* pRegion = _instrument->regions[i];
795              int low = pRegion->lokey;              int low = pRegion->lokey;
796              int high = pRegion->hikey;              int high = pRegion->hikey;
797              if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {              if (low != -1) { // lokey -1 means region doesn't play on note-on
798                  std::cerr << "Invalid key range: " << low << " - " << high << std::endl;                  // hikey -1 is the same as no limit, except that it
799              } else {                  // also enables on_locc/on_hicc
800                  for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true;                  if (high == -1) high = 127;
801                    if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {
802                        std::cerr << "Invalid key range: " << low << " - " << high << std::endl;
803                    } else {
804                        for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true;
805                    }
806              }              }
807    
808              // get keyswitches              // get keyswitches
# Line 890  namespace sfz Line 857  namespace sfz
857          }          }
858    
859          _instrument->pLookupTable = new LookupTable(_instrument);          _instrument->pLookupTable = new LookupTable(_instrument);
860    
861            // create separate lookup tables for controller triggered
862            // regions, one for each CC
863            for (int i = 0 ; i < 128 ; i++) {
864                _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);
865            }
866      }      }
867    
868      File::~File()      File::~File()
# Line 1213  namespace sfz Line 1186  namespace sfz
1186              else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));              else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));
1187    
1188              // filter              // filter
1189              else if ("cutoff_on"  == key_cc || "cutoff_" == key_cc) pCurDef->cutoff_oncc.set(num_cc, ToInt(value));              else if ("cutoff_on"  == key_cc || "cutoff_" == key_cc) {
1190              else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value));                  pCurDef->cutoff_oncc.set(num_cc, ToInt(value));
1191                    pCurDef->cutoff_cc = num_cc;
1192                } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value));
1193              else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value));              else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value));
1194              else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value));              else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value));
1195              else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value));              else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value));
# Line 1264  namespace sfz Line 1239  namespace sfz
1239          else if ("ampeg_hold"   == key) pCurDef->ampeg_hold = ToFloat(value);          else if ("ampeg_hold"   == key) pCurDef->ampeg_hold = ToFloat(value);
1240          else if ("ampeg_decay"   == key) pCurDef->ampeg_decay = ToFloat(value);          else if ("ampeg_decay"   == key) pCurDef->ampeg_decay = ToFloat(value);
1241          else if ("ampeg_sustain"   == key) pCurDef->ampeg_sustain = ToFloat(value);          else if ("ampeg_sustain"   == key) pCurDef->ampeg_sustain = ToFloat(value);
1242          else if ("ampeg_release"   == key) pCurDef->ampeg_release = ToFloat(value);          else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value);
1243            else if ("ampeg_vel2delay" == key) pCurDef->ampeg_vel2delay = ToFloat(value);
1244            else if ("ampeg_vel2attack" == key) pCurDef->ampeg_vel2attack = ToFloat(value);
1245            else if ("ampeg_vel2hold" == key) pCurDef->ampeg_vel2hold = ToFloat(value);
1246            else if ("ampeg_vel2decay" == key) pCurDef->ampeg_vel2decay = ToFloat(value);
1247            else if ("ampeg_vel2sustain" == key) pCurDef->ampeg_vel2sustain = ToFloat(value);
1248            else if ("ampeg_vel2release" == key) pCurDef->ampeg_vel2release = ToFloat(value);
1249          else if ("fileg_delay"   == key) pCurDef->fileg_delay = ToFloat(value);          else if ("fileg_delay"   == key) pCurDef->fileg_delay = ToFloat(value);
1250          else if ("fileg_start"   == key) pCurDef->fileg_start = ToFloat(value);          else if ("fileg_start"   == key) pCurDef->fileg_start = ToFloat(value);
1251          else if ("fileg_attack"   == key) pCurDef->fileg_attack = ToFloat(value);          else if ("fileg_attack"   == key) pCurDef->fileg_attack = ToFloat(value);
# Line 1313  namespace sfz Line 1294  namespace sfz
1294              case 'g': i = 7; break;              case 'g': i = 7; break;
1295              case 'a': i = 9; break;              case 'a': i = 9; break;
1296              case 'b': i = 11; break;              case 'b': i = 11; break;
1297                case '-': if (s == "-1") return -1;
1298              default:              default:
1299                  std::cerr << "Not a note: " << s << std::endl;                  std::cerr << "Not a note: " << s << std::endl;
1300                  return 0;                  return 0;

Legend:
Removed from v.2114  
changed lines
  Added in v.2176

  ViewVC Help
Powered by ViewVC