/[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 2058 by persson, Sun Feb 14 11:40:49 2010 UTC revision 2082 by persson, Sun Apr 11 10:20:24 2010 UTC
# Line 67  namespace sfz Line 67  namespace sfz
67      Definition::Definition() :      Definition::Definition() :
68          locc(128), hicc(128), start_locc(128), start_hicc(128), stop_locc(128),          locc(128), hicc(128), start_locc(128), start_hicc(128), stop_locc(128),
69          stop_hicc(128), on_locc(128), on_hicc(128), delay_oncc(128), delay_samples_oncc(128),          stop_hicc(128), on_locc(128), on_hicc(128), delay_oncc(128), delay_samples_oncc(128),
70          offset_oncc(128), amp_velcurve_(128), gain_oncc(128), xfin_locc(128), xfin_hicc(128),          offset_oncc(128), amp_velcurve(128), gain_oncc(128), xfin_locc(128), xfin_hicc(128),
71          xfout_locc(128), xfout_hicc(128), cutoff_oncc(128), cutoff2_oncc(128), cutoff_smoothcc(128),          xfout_locc(128), xfout_hicc(128), cutoff_oncc(128), cutoff2_oncc(128), cutoff_smoothcc(128),
72          cutoff2_smoothcc(128), cutoff_stepcc(128), cutoff2_stepcc(128), cutoff_curvecc(128),          cutoff2_smoothcc(128), cutoff_stepcc(128), cutoff2_stepcc(128), cutoff_curvecc(128),
73          cutoff2_curvecc(128), resonance_oncc(128), resonance2_oncc(128), resonance_smoothcc(128),          cutoff2_curvecc(128), resonance_oncc(128), resonance2_oncc(128), resonance_smoothcc(128),
# Line 89  namespace sfz Line 89  namespace sfz
89      Region::Region()      Region::Region()
90      {      {
91          pSample = NULL;          pSample = NULL;
92            seq_counter = 1;
93      }      }
94    
95      Region::~Region()      Region::~Region()
# Line 121  namespace sfz Line 122  namespace sfz
122      Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel,      Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel,
123                int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,                int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
124                uint8_t prog, float rand, trigger_t trig, uint8_t* cc,                uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
125                float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)                float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)
126      {      {
127          // chan        (MIDI channel)          // chan        (MIDI channel)
128          // key         (MIDI note)          // key         (MIDI note)
# Line 137  namespace sfz Line 138  namespace sfz
138          // cc          (all 128 CC values)          // cc          (all 128 CC values)
139    
140          // timer       (time since previous region in the group was triggered)          // timer       (time since previous region in the group was triggered)
         // seq         (the state of the region sequence counter)  
141          // sw          (the state of region key switches, 128 possible values)          // sw          (the state of region key switches, 128 possible values)
142          // last_sw_key (the last key pressed in the key switch range)          // last_sw_key (the last key pressed in the key switch range)
143          // prev_sw_key (the previous note value)          // prev_sw_key (the previous note value)
# Line 147  namespace sfz Line 147  namespace sfz
147              key     >= lokey      &&  key     <= hikey      &&              key     >= lokey      &&  key     <= hikey      &&
148              vel     >= lovel      &&  vel     <= hivel      &&              vel     >= lovel      &&  vel     <= hivel      &&
149              bend    >= lobend     &&  bend    <= hibend     &&              bend    >= lobend     &&  bend    <= hibend     &&
150              bpm     >= lobpm      &&  bpm     <= hibpm      &&              bpm     >= lobpm      &&  bpm     <  hibpm      &&
151              chanaft >= lochanaft  &&  chanaft <= hichanaft  &&              chanaft >= lochanaft  &&  chanaft <= hichanaft  &&
152              polyaft >= lopolyaft  &&  polyaft <= hipolyaft  &&              polyaft >= lopolyaft  &&  polyaft <= hipolyaft  &&
153              prog    >= loprog     &&  prog    <= hiprog     &&              prog    >= loprog     &&  prog    <= hiprog     &&
154              rand    >= lorand     &&  rand    <= hirand     &&              rand    >= lorand     &&  rand    <  hirand     &&
155              timer   >= lotimer    &&  timer   <= hitimer    &&              timer   >= lotimer    &&  timer   <= hitimer    &&
             seq == seq_position   &&  
156    
157              ( (sw_lokey == -1 || sw_hikey == -1 || sw_last  == -1) ||              ( (sw_lokey == -1 || sw_hikey == -1 || sw_last  == -1) ||
158                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&
# Line 177  namespace sfz Line 176  namespace sfz
176                  return false;                  return false;
177          }          }
178    
179          return true;          // seq_position has to be checked last, so we know that we
180            // increment the right counter
181            is_triggered = (seq_counter == seq_position);
182            seq_counter = (seq_counter % seq_length) + 1;
183    
184            return is_triggered;
185      }      }
186    
187      bool      bool
188      Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val,      Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val,
189          int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,          int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
190          uint8_t prog, float rand, trigger_t trig, uint8_t* cc,          uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
191          float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)          float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)
192      {      {
193          // chan      (MIDI channel)          // chan      (MIDI channel)
194          // cont      (MIDI controller)          // cont      (MIDI controller)
# Line 200  namespace sfz Line 204  namespace sfz
204          // cc        (all CC values)          // cc        (all CC values)
205    
206          // timer       (time since previous region in the group was triggered)          // timer       (time since previous region in the group was triggered)
         // seq         (the state of the region sequence counter)  
207          // sw          (the state of region key switches, 128 possible values)          // sw          (the state of region key switches, 128 possible values)
208          // last_sw_key (the last key pressed in the key switch range)          // last_sw_key (the last key pressed in the key switch range)
209          // prev_sw_key (the previous note value)          // prev_sw_key (the previous note value)
# Line 210  namespace sfz Line 213  namespace sfz
213              ((val   >= on_locc[cont]    &&  val     <= on_hicc[cont])     ||              ((val   >= on_locc[cont]    &&  val     <= on_hicc[cont])     ||
214               (val   >= start_locc[cont] &&  val     <= start_hicc[cont])) &&               (val   >= start_locc[cont] &&  val     <= start_hicc[cont])) &&
215              bend    >= lobend           &&  bend    <= hibend             &&              bend    >= lobend           &&  bend    <= hibend             &&
216              bpm     >= lobpm            &&  bpm     <= hibpm              &&              bpm     >= lobpm            &&  bpm     <  hibpm              &&
217              chanaft >= lochanaft        &&  chanaft <= hichanaft          &&              chanaft >= lochanaft        &&  chanaft <= hichanaft          &&
218              polyaft >= lopolyaft        &&  polyaft <= hipolyaft          &&              polyaft >= lopolyaft        &&  polyaft <= hipolyaft          &&
219              prog    >= loprog           &&  prog    <= hiprog             &&              prog    >= loprog           &&  prog    <= hiprog             &&
220              rand    >= lorand           &&  rand    <= hirand             &&              rand    >= lorand           &&  rand    <  hirand             &&
221              timer   >= lotimer          &&  timer   <= hitimer            &&              timer   >= lotimer          &&  timer   <= hitimer            &&
             seq == seq_position   &&  
222    
223              ( (sw_lokey == -1 || sw_hikey == -1 || sw_last  == -1) ||              ( (sw_lokey == -1 || sw_hikey == -1 || sw_last  == -1) ||
224                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&
# Line 287  namespace sfz Line 289  namespace sfz
289          uint8_t chan, uint8_t key, uint8_t vel,          uint8_t chan, uint8_t key, uint8_t vel,
290          int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,          int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
291          uint8_t prog, float rand, trigger_t trig, uint8_t* cc,          uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
292          float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key          float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key
293      ) {      ) {
294          std::vector<Region*> v;          std::vector<Region*> v;
295          for (int i = 0; i < regions.size(); i++) {          for (int i = 0; i < regions.size(); i++) {
296              if (regions[i]->OnKey (              if (regions[i]->OnKey (
297                  chan, key, vel, bend, bpm, chanaft, polyaft, prog,                  chan, key, vel, bend, bpm, chanaft, polyaft, prog,
298                  rand, trig, cc, timer, seq, sw, last_sw_key, prev_sw_key)                  rand, trig, cc, timer, sw, last_sw_key, prev_sw_key)
299                      ) { v.push_back(regions[i]); }                      ) { v.push_back(regions[i]); }
300          }          }
301    
# Line 469  namespace sfz Line 471  namespace sfz
471              offset_oncc[i].unset();              offset_oncc[i].unset();
472    
473              // amplifier              // amplifier
474              amp_velcurve_[i] = 0; //fixme: 20 log (127^2 / i^2)              amp_velcurve[i] = -1;
475              gain_oncc[i] = 0;              gain_oncc[i] = 0;
476              xfin_locc[i] = 0;              xfin_locc[i] = 0;
477              xfin_hicc[i] = 0;              xfin_hicc[i] = 0;
# Line 533  namespace sfz Line 535  namespace sfz
535          pitcheg_decay    = 0;          pitcheg_decay    = 0;
536          pitcheg_sustain  = 100; // in percentage          pitcheg_sustain  = 100; // in percentage
537          pitcheg_release  = 0;          pitcheg_release  = 0;
538    
539            amplfo_delay     = 0;
540            amplfo_fade      = 0;
541            amplfo_freq      = 0;
542            amplfo_depth     = 0;
543    
544            fillfo_delay     = 0;
545            fillfo_fade      = 0;
546            fillfo_freq      = 0;
547            fillfo_depth     = 0;
548    
549            pitchlfo_delay   = 0;
550            pitchlfo_fade    = 0;
551            pitchlfo_freq    = 0;
552            pitchlfo_depth   = 0;
553      }      }
554    
555      Region*      Region*
# Line 618  namespace sfz Line 635  namespace sfz
635          region->amp_keytrack = amp_keytrack;          region->amp_keytrack = amp_keytrack;
636          region->amp_keycenter = amp_keycenter;          region->amp_keycenter = amp_keycenter;
637          region->amp_veltrack = amp_veltrack;          region->amp_veltrack = amp_veltrack;
638          region->amp_velcurve_ = amp_velcurve_;          region->amp_velcurve = amp_velcurve;
639          region->amp_random = amp_random;          region->amp_random = amp_random;
640          region->rt_decay = rt_decay;          region->rt_decay = rt_decay;
641          region->gain_oncc = gain_oncc;          region->gain_oncc = gain_oncc;
# Line 740  namespace sfz Line 757  namespace sfz
757          region->pitcheg_sustain  = pitcheg_sustain;          region->pitcheg_sustain  = pitcheg_sustain;
758          region->pitcheg_release  = pitcheg_release;          region->pitcheg_release  = pitcheg_release;
759    
760            region->amplfo_delay     = amplfo_delay;
761            region->amplfo_fade      = amplfo_fade;
762            region->amplfo_freq      = amplfo_freq;
763            region->amplfo_depth     = amplfo_depth;
764    
765            region->fillfo_delay     = fillfo_delay;
766            region->fillfo_fade      = fillfo_fade;
767            region->fillfo_freq      = fillfo_freq;
768            region->fillfo_depth     = fillfo_depth;
769    
770            region->pitchlfo_delay   = pitchlfo_delay;
771            region->pitchlfo_fade    = pitchlfo_fade;
772            region->pitchlfo_freq    = pitchlfo_freq;
773            region->pitchlfo_depth   = pitchlfo_depth;
774    
775          return region;          return region;
776      }      }
777    
# Line 857  namespace sfz Line 889  namespace sfz
889              } else {              } else {
890                  std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl;                  std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl;
891              }              }
892    
893                // create velocity response curve
894                int prev = 0;
895                float prevvalue = 0;
896                for (int v = 0 ; v < 128 ; v++) {
897                    if (pRegion->amp_velcurve[v] >= 0) {
898                        float step = (pRegion->amp_velcurve[v] - prevvalue) / (v - prev);
899                        for ( ; prev < v ; prev++) {
900                            pRegion->amp_velcurve[prev] = prevvalue;
901                            prevvalue += step;
902                        }
903                    }
904                }
905                if (prev) {
906                    float step = (1 - prevvalue) / (127 - prev);
907                    for ( ; prev < 128 ; prev++) {
908                        pRegion->amp_velcurve[prev] = prevvalue;
909                        prevvalue += step;
910                    }
911                } else {
912                    // default curve
913                    for (int v = 0 ; v < 128 ; v++) {
914                        pRegion->amp_velcurve[v] = v * v / (127.0 * 127.0);
915                    }
916                }
917                // apply amp_veltrack
918                float offset = -pRegion->amp_veltrack;
919                if (offset <= 0) offset += 100;
920                for (int v = 0 ; v < 128 ; v++) {
921                    pRegion->amp_velcurve[v] =
922                        (offset + pRegion->amp_veltrack * pRegion->amp_velcurve[v]) / 100;
923                }
924          }          }
925      }      }
926    
# Line 1147  namespace sfz Line 1211  namespace sfz
1211          else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);          else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);
1212          else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);          else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);
1213    
1214          //fixme: parse amp_velcurve_N          else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {
1215                pCurDef->amp_velcurve[x] = ToFloat(value);
1216            }
1217    
1218          // CCs          // CCs
1219          else if (key.find("cc") != std::string::npos)          else if (key.find("cc") != std::string::npos)
# Line 1245  namespace sfz Line 1311  namespace sfz
1311          else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);          else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);
1312          else if ("pitcheg_sustain"   == key) pCurDef->pitcheg_sustain = ToFloat(value);          else if ("pitcheg_sustain"   == key) pCurDef->pitcheg_sustain = ToFloat(value);
1313          else if ("pitcheg_release"   == key) pCurDef->pitcheg_release = ToFloat(value);          else if ("pitcheg_release"   == key) pCurDef->pitcheg_release = ToFloat(value);
1314    
1315            // v1 LFO
1316            else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value);
1317            else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value);
1318            else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value);
1319            else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value);
1320            else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value);
1321            else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value);
1322            else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value);
1323            else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value);
1324            else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value);
1325            else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value);
1326            else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value);
1327            else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value);
1328    
1329          else {          else {
1330              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1331          }          }

Legend:
Removed from v.2058  
changed lines
  Added in v.2082

  ViewVC Help
Powered by ViewVC