47 |
class Group; |
class Group; |
48 |
class Instrument; |
class Instrument; |
49 |
class File; |
class File; |
50 |
|
class LookupTable; |
51 |
|
|
52 |
class Sample : public LinuxSampler::SampleFileBase<Region> { |
class Sample : public LinuxSampler::SampleFileBase<Region> { |
53 |
public: |
public: |
238 |
EG(); |
EG(); |
239 |
}; |
}; |
240 |
|
|
241 |
|
// Fixed size array with copy-on-write semantics |
242 |
|
template<class T> |
243 |
|
class Array |
244 |
|
{ |
245 |
|
private: |
246 |
|
struct Rep { |
247 |
|
int refcount; |
248 |
|
T a[128]; |
249 |
|
|
250 |
|
Rep() : refcount(1) { } |
251 |
|
static void release(Rep* rep) { |
252 |
|
if (!--rep->refcount) delete rep; |
253 |
|
} |
254 |
|
} *ptr; |
255 |
|
public: |
256 |
|
Array() : ptr(0) { } |
257 |
|
~Array() { Rep::release(ptr); } |
258 |
|
|
259 |
|
Array& operator=(const Array& array) { |
260 |
|
if (this != &array) { |
261 |
|
ptr = array.ptr; |
262 |
|
if (ptr) ptr->refcount++; |
263 |
|
} |
264 |
|
return *this; |
265 |
|
} |
266 |
|
|
267 |
|
const T& operator[](int i) const { return ptr->a[i]; } |
268 |
|
|
269 |
|
void set(int i, const T& v) { |
270 |
|
if (!ptr) { |
271 |
|
ptr = new Rep; |
272 |
|
} else if (ptr->refcount > 1 && ptr->a[i] != v) { |
273 |
|
Rep* newptr = new Rep(*ptr); |
274 |
|
newptr->refcount = 1; |
275 |
|
Rep::release(ptr); |
276 |
|
ptr = newptr; |
277 |
|
} |
278 |
|
ptr->a[i] = v; |
279 |
|
} |
280 |
|
}; |
281 |
|
|
282 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
283 |
// class Definition |
// class Definition |
284 |
|
|
296 |
int lochan; int hichan; |
int lochan; int hichan; |
297 |
int lokey; int hikey; |
int lokey; int hikey; |
298 |
int lovel; int hivel; |
int lovel; int hivel; |
299 |
std::vector<int> locc; std::vector<int> hicc; |
Array<int> locc; Array<int> hicc; |
300 |
int lobend; int hibend; |
int lobend; int hibend; |
301 |
int lobpm; int hibpm; |
float lobpm; float hibpm; |
302 |
int lochanaft; int hichanaft; |
int lochanaft; int hichanaft; |
303 |
int lopolyaft; int hipolyaft; |
int lopolyaft; int hipolyaft; |
304 |
int loprog; int hiprog; |
int loprog; int hiprog; |
308 |
int seq_length; |
int seq_length; |
309 |
int seq_position; |
int seq_position; |
310 |
|
|
311 |
std::vector<int> start_locc; std::vector<int> start_hicc; |
Array<int> start_locc; Array<int> start_hicc; |
312 |
std::vector<int> stop_locc; std::vector<int> stop_hicc; |
Array<int> stop_locc; Array<int> stop_hicc; |
313 |
|
|
314 |
int sw_lokey; int sw_hikey; |
int sw_lokey; int sw_hikey; |
315 |
int sw_last; |
int sw_last; |
321 |
trigger_t trigger; |
trigger_t trigger; |
322 |
|
|
323 |
uint group; |
uint group; |
324 |
optional<int> off_by; |
uint off_by; |
325 |
off_mode_t off_mode; |
off_mode_t off_mode; |
326 |
|
|
327 |
std::vector<int> on_locc; std::vector<int> on_hicc; |
Array<int> on_locc; Array<int> on_hicc; |
328 |
|
|
329 |
// sample player |
// sample player |
330 |
optional<int> count; |
optional<int> count; |
331 |
optional<float> delay; optional<float> delay_random; std::vector<optional<float> > delay_oncc; |
optional<float> delay; optional<float> delay_random; Array<optional<float> > delay_oncc; |
332 |
optional<int> delay_beats; optional<int> stop_beats; |
optional<int> delay_beats; optional<int> stop_beats; |
333 |
optional<int> delay_samples; std::vector<optional<int> > delay_samples_oncc; |
optional<int> delay_samples; Array<optional<int> > delay_samples_oncc; |
334 |
optional<int> end; |
optional<int> end; |
335 |
optional<float> loop_crossfade; |
optional<float> loop_crossfade; |
336 |
optional<int> offset; optional<int> offset_random; std::vector<optional<int> > offset_oncc; |
optional<int> offset; optional<int> offset_random; Array<optional<int> > offset_oncc; |
337 |
loop_mode_t loop_mode; |
loop_mode_t loop_mode; |
338 |
optional<int> loop_start; optional<int> loop_end; |
optional<int> loop_start; optional<int> loop_end; |
339 |
optional<int> sync_beats; |
optional<int> sync_beats; |
344 |
float pan; |
float pan; |
345 |
float width; |
float width; |
346 |
float position; |
float position; |
347 |
float amp_keytrack; int amp_keycenter; float amp_veltrack; std::vector<float> amp_velcurve_; float amp_random; |
float amp_keytrack; int amp_keycenter; float amp_veltrack; Array<float> amp_velcurve; float amp_random; |
348 |
float rt_decay; |
float rt_decay; |
349 |
std::vector<float> gain_oncc; |
Array<float> gain_oncc; |
350 |
int xfin_lokey; int xfin_hikey; |
int xfin_lokey; int xfin_hikey; |
351 |
int xfout_lokey; int xfout_hikey; |
int xfout_lokey; int xfout_hikey; |
352 |
curve_t xf_keycurve; |
curve_t xf_keycurve; |
353 |
int xfin_lovel; int xfin_hivel; |
int xfin_lovel; int xfin_hivel; |
354 |
int xfout_lovel; int xfout_hivel; |
int xfout_lovel; int xfout_hivel; |
355 |
curve_t xf_velcurve; |
curve_t xf_velcurve; |
356 |
std::vector<int> xfin_locc; std::vector<int> xfin_hicc; |
Array<int> xfin_locc; Array<int> xfin_hicc; |
357 |
std::vector<int> xfout_locc; std::vector<int> xfout_hicc; |
Array<int> xfout_locc; Array<int> xfout_hicc; |
358 |
curve_t xf_cccurve; |
curve_t xf_cccurve; |
359 |
|
|
360 |
// pitch |
// pitch |
366 |
// filter |
// filter |
367 |
filter_t fil_type; filter_t fil2_type; |
filter_t fil_type; filter_t fil2_type; |
368 |
optional<float> cutoff; optional<float> cutoff2; |
optional<float> cutoff; optional<float> cutoff2; |
369 |
std::vector<int> cutoff_oncc; std::vector<int> cutoff2_oncc; |
Array<int> cutoff_oncc; Array<int> cutoff2_oncc; |
370 |
std::vector<int> cutoff_smoothcc; std::vector<int> cutoff2_smoothcc; |
Array<int> cutoff_smoothcc; Array<int> cutoff2_smoothcc; |
371 |
std::vector<int> cutoff_stepcc; std::vector<int> cutoff2_stepcc; |
Array<int> cutoff_stepcc; Array<int> cutoff2_stepcc; |
372 |
std::vector<int> cutoff_curvecc; std::vector<int> cutoff2_curvecc; |
Array<int> cutoff_curvecc; Array<int> cutoff2_curvecc; |
373 |
int cutoff_chanaft; int cutoff2_chanaft; |
int cutoff_chanaft; int cutoff2_chanaft; |
374 |
int cutoff_polyaft; int cutoff2_polyaft; |
int cutoff_polyaft; int cutoff2_polyaft; |
375 |
float resonance; float resonance2; |
float resonance; float resonance2; |
376 |
std::vector<int> resonance_oncc; std::vector<int> resonance2_oncc; |
Array<int> resonance_oncc; Array<int> resonance2_oncc; |
377 |
std::vector<int> resonance_smoothcc; std::vector<int> resonance2_smoothcc; |
Array<int> resonance_smoothcc; Array<int> resonance2_smoothcc; |
378 |
std::vector<int> resonance_stepcc; std::vector<int> resonance2_stepcc; |
Array<int> resonance_stepcc; Array<int> resonance2_stepcc; |
379 |
std::vector<int> resonance_curvecc; std::vector<int> resonance2_curvecc; |
Array<int> resonance_curvecc; Array<int> resonance2_curvecc; |
380 |
int fil_keytrack; int fil2_keytrack; |
int fil_keytrack; int fil2_keytrack; |
381 |
int fil_keycenter; int fil2_keycenter; |
int fil_keycenter; int fil2_keycenter; |
382 |
int fil_veltrack; int fil2_veltrack; |
int fil_veltrack; int fil2_veltrack; |
384 |
|
|
385 |
// per voice equalizer |
// per voice equalizer |
386 |
float eq1_freq; float eq2_freq; float eq3_freq; |
float eq1_freq; float eq2_freq; float eq3_freq; |
387 |
std::vector<float> eq1_freq_oncc; std::vector<float> eq2_freq_oncc; std::vector<float> eq3_freq_oncc; |
Array<float> eq1_freq_oncc; Array<float> eq2_freq_oncc; Array<float> eq3_freq_oncc; |
388 |
float eq1_vel2freq; float eq2_vel2freq; float eq3_vel2freq; |
float eq1_vel2freq; float eq2_vel2freq; float eq3_vel2freq; |
389 |
float eq1_bw; float eq2_bw; float eq3_bw; |
float eq1_bw; float eq2_bw; float eq3_bw; |
390 |
std::vector<float> eq1_bw_oncc; std::vector<float> eq2_bw_oncc; std::vector<float> eq3_bw_oncc; |
Array<float> eq1_bw_oncc; Array<float> eq2_bw_oncc; Array<float> eq3_bw_oncc; |
391 |
float eq1_gain; float eq2_gain; float eq3_gain; |
float eq1_gain; float eq2_gain; float eq3_gain; |
392 |
std::vector<float> eq1_gain_oncc; std::vector<float> eq2_gain_oncc; std::vector<float> eq3_gain_oncc; |
Array<float> eq1_gain_oncc; Array<float> eq2_gain_oncc; Array<float> eq3_gain_oncc; |
393 |
float eq1_vel2gain; float eq2_vel2gain; float eq3_vel2gain; |
float eq1_vel2gain; float eq2_vel2gain; float eq3_vel2gain; |
394 |
|
|
395 |
//Deprecated (from version 1) |
//Deprecated (from version 1) |
396 |
float ampeg_delay, ampeg_start, ampeg_attack, ampeg_hold, ampeg_decay, ampeg_sustain, ampeg_release; |
float ampeg_delay, ampeg_start, ampeg_attack, ampeg_hold, ampeg_decay, ampeg_sustain, ampeg_release; |
397 |
float fileg_delay, fileg_start, fileg_attack, fileg_hold, fileg_decay, fileg_sustain, fileg_release; |
float fileg_delay, fileg_start, fileg_attack, fileg_hold, fileg_decay, fileg_sustain, fileg_release; |
398 |
float pitcheg_delay, pitcheg_start, pitcheg_attack, pitcheg_hold, pitcheg_decay, pitcheg_sustain, pitcheg_release; |
float pitcheg_delay, pitcheg_start, pitcheg_attack, pitcheg_hold, pitcheg_decay, pitcheg_sustain, pitcheg_release; |
399 |
|
float amplfo_delay, amplfo_fade, amplfo_freq, amplfo_depth; |
400 |
|
float fillfo_delay, fillfo_fade, fillfo_freq, fillfo_depth; |
401 |
|
float pitchlfo_delay, pitchlfo_fade, pitchlfo_freq; |
402 |
|
int pitchlfo_depth; |
403 |
|
|
404 |
// envelope generators |
// envelope generators |
405 |
LinuxSampler::ArrayList<EG> eg; |
LinuxSampler::ArrayList<EG> eg; |
406 |
}; |
}; |
407 |
|
|
408 |
|
class Query { |
409 |
|
public: |
410 |
|
uint8_t chan; // MIDI channel |
411 |
|
uint8_t key; // MIDI note |
412 |
|
uint8_t vel; // MIDI velocity |
413 |
|
int bend; // MIDI pitch bend |
414 |
|
uint8_t bpm; // host BPM |
415 |
|
uint8_t chanaft; // MIDI channel pressure |
416 |
|
uint8_t polyaft; // MIDI polyphonic aftertouch |
417 |
|
uint8_t prog; // MIDI program change |
418 |
|
float rand; // generated random number |
419 |
|
trigger_t trig; // how it was triggered |
420 |
|
uint8_t* cc; // all 128 CC values |
421 |
|
float timer; // time since previous region in the group was triggered |
422 |
|
bool* sw; // state of region key switches, 128 possible values |
423 |
|
uint8_t last_sw_key; // last key pressed in the key switch range |
424 |
|
uint8_t prev_sw_key; // previous note value |
425 |
|
|
426 |
|
void search(const Instrument* pInstrument); |
427 |
|
void search(const Instrument* pInstrument, int triggercc); |
428 |
|
Region* next(); |
429 |
|
private: |
430 |
|
LinuxSampler::ArrayList<Region*>* pRegionList; |
431 |
|
int regionIndex; |
432 |
|
}; |
433 |
|
|
434 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
435 |
// class Region |
// class Region |
436 |
|
|
455 |
uint GetLoopEnd(); |
uint GetLoopEnd(); |
456 |
uint GetLoopCount(); |
uint GetLoopCount(); |
457 |
|
|
458 |
/// Return true if region is triggered by key |
/// Return true if region is triggered by key. Region is |
459 |
bool OnKey(uint8_t chan, uint8_t key, uint8_t vel, |
/// assumed to come from a search in the lookup table. |
460 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
bool OnKey(const Query& q); |
|
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
|
|
float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key); |
|
|
|
|
|
/// Return true if region is triggered by control change |
|
|
bool 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, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key); |
|
461 |
|
|
462 |
/// Return an articulation for the current state |
/// Return an articulation for the current state |
463 |
Articulation* GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc); |
Articulation* GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc); |
464 |
|
|
465 |
// unique region id |
// unique region id |
466 |
int id; |
int id; |
467 |
|
|
468 |
private: |
private: |
469 |
Instrument* pInstrument; |
Instrument* pInstrument; |
470 |
|
int seq_counter; |
471 |
}; |
}; |
472 |
|
|
473 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
483 |
std::string GetName() { return name; } |
std::string GetName() { return name; } |
484 |
SampleManager* GetSampleManager() { return pSampleManager; } |
SampleManager* GetSampleManager() { return pSampleManager; } |
485 |
|
|
|
/** |
|
|
* @returns All regions that are triggered by key |
|
|
*/ |
|
|
std::vector<Region*> GetRegionsOnKey ( |
|
|
uint8_t chan, uint8_t key, uint8_t vel, |
|
|
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
|
|
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
|
|
float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key |
|
|
); |
|
|
|
|
486 |
bool DestroyRegion(Region* pRegion); |
bool DestroyRegion(Region* pRegion); |
487 |
bool HasKeyBinding(uint8_t key); |
bool HasKeyBinding(uint8_t key); |
488 |
bool HasKeySwitchBinding(uint8_t key); |
bool HasKeySwitchBinding(uint8_t key); |
490 |
/// List of Regions belonging to this Instrument |
/// List of Regions belonging to this Instrument |
491 |
std::vector<Region*> regions; |
std::vector<Region*> regions; |
492 |
|
|
493 |
friend class sfz::File; |
friend class File; |
494 |
|
friend class Query; |
495 |
|
|
496 |
private: |
private: |
497 |
std::string name; |
std::string name; |
498 |
std::vector<bool> KeyBindings; |
std::vector<bool> KeyBindings; |
499 |
std::vector<bool> KeySwitchBindings; |
std::vector<bool> KeySwitchBindings; |
500 |
SampleManager* pSampleManager; |
SampleManager* pSampleManager; |
501 |
|
LookupTable* pLookupTable; |
502 |
|
LookupTable* pLookupTableCC[128]; |
503 |
}; |
}; |
504 |
|
|
505 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
541 |
private: |
private: |
542 |
void push_header(std::string token); |
void push_header(std::string token); |
543 |
void push_opcode(std::string token); |
void push_opcode(std::string token); |
544 |
int parseInt(std::string value); |
int parseKey(const std::string& value); |
|
float parseFloat(std::string value); |
|
545 |
EG& eg(int x); |
EG& eg(int x); |
546 |
EGNode& egnode(int x, int y); |
EGNode& egnode(int x, int y); |
547 |
|
|