/[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 2100 by persson, Sat May 15 09:02:31 2010 UTC revision 2101 by persson, Sun May 30 11:40:31 2010 UTC
# Line 107  namespace sfz Line 107  namespace sfz
107          }          }
108      }      }
109    
110      bool      bool Region::OnKey(const Query& q) {
111      Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel,          bool is_triggered(
112                int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,              q.chan    >= lochan     &&  q.chan    <= hichan     &&
113                uint8_t prog, float rand, trigger_t trig, uint8_t* cc,              q.key     >= lokey      &&  q.key     <= hikey      &&
114                float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)              q.vel     >= lovel      &&  q.vel     <= hivel      &&
115      {              q.bend    >= lobend     &&  q.bend    <= hibend     &&
116          // chan        (MIDI channel)              q.bpm     >= lobpm      &&  q.bpm     <  hibpm      &&
117          // key         (MIDI note)              q.chanaft >= lochanaft  &&  q.chanaft <= hichanaft  &&
118          // vel         (MIDI velocity)              q.polyaft >= lopolyaft  &&  q.polyaft <= hipolyaft  &&
119                q.prog    >= loprog     &&  q.prog    <= hiprog     &&
120          // bend        (MIDI pitch bend)              q.rand    >= lorand     &&  q.rand    <  hirand     &&
121          // bpm         (host BPM)              q.timer   >= lotimer    &&  q.timer   <= hitimer    &&
         // chanaft     (MIDI channel pressure)  
         // polyaft     (MIDI polyphonic aftertouch)  
         // prog        (MIDI program change)  
         // rand        (generated random number)  
         // trigger     (how it was triggered)  
         // cc          (all 128 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     &&  
             key     >= lokey      &&  key     <= hikey      &&  
             vel     >= lovel      &&  vel     <= hivel      &&  
             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    &&  
122    
123              ( sw_last == -1 ||              ( sw_last == -1 ||
124                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : false) ) &&                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (q.last_sw_key == sw_last) : false) ) &&
125    
126              ( sw_down == -1 ||              ( sw_down == -1 ||
127                ((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (sw[sw_down]) : false) )  &&                ((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (q.sw[sw_down]) : false) )  &&
128    
129              ( sw_up   == -1 ||              ( sw_up   == -1 ||
130                ((sw_up   >= sw_lokey && (sw_hikey == -1 || sw_up   <= sw_hikey)) ? (!sw[sw_up]) : true) )  &&                ((sw_up   >= sw_lokey && (sw_hikey == -1 || sw_up   <= sw_hikey)) ? (!q.sw[sw_up]) : true) )  &&
131    
132              ( sw_previous == -1 ||              ( sw_previous == -1 ||
133                prev_sw_key == sw_previous )  &&                q.prev_sw_key == sw_previous )  &&
134    
135              ((trigger & trig) != 0)              ((trigger & q.trig) != 0)
136          );          );
137    
138          if (!is_triggered)          if (!is_triggered)
139              return false;              return false;
140    
141          for (int i = 0; i < 128; ++i)          for (int i = 0; i < 128; ++i) {
142          {              if (locc[i] != -1 && hicc[i] != -1 && !(q.cc[i] >= locc[i] && q.cc[i] <= hicc[i]))
             if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i]))  
143                  return false;                  return false;
144          }          }
145    
# Line 278  namespace sfz Line 254  namespace sfz
254          regions.clear();          regions.clear();
255      }      }
256    
257      std::vector<Region*> Instrument::GetRegionsOnKey (      Query::Query(const Instrument& instrument) {
258          uint8_t chan, uint8_t key, uint8_t vel,          i = instrument.regions.begin();
259          int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,          regions_end = instrument.regions.end();
260          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  
     ) {  
         std::vector<Region*> v;  
         for (int i = 0; i < regions.size(); i++) {  
             if (regions[i]->OnKey (  
                 chan, key, vel, bend, bpm, chanaft, polyaft, prog,  
                 rand, trig, cc, timer, sw, last_sw_key, prev_sw_key)  
                     ) { v.push_back(regions[i]); }  
         }  
261    
262          return v;      Region* Query::next() {
263            while (i != regions_end) {
264                if ((*i++)->OnKey(*this)) return *i;
265            }
266            return 0;
267      }      }
268    
269      bool Instrument::DestroyRegion(Region* pRegion) {      bool Instrument::DestroyRegion(Region* pRegion) {

Legend:
Removed from v.2100  
changed lines
  Added in v.2101

  ViewVC Help
Powered by ViewVC