2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2008-2009 Anders Dahnielson <anders@dahnielson.com> * |
* Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com> * |
6 |
* Copyright (C) 2009 Grigor Iliev * |
* Copyright (C) 2009 - 2010 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 * |
32 |
|
|
33 |
#include "../common/SampleFile.h" |
#include "../common/SampleFile.h" |
34 |
#include "../common/SampleManager.h" |
#include "../common/SampleManager.h" |
35 |
|
#include "../../common/ArrayList.h" |
36 |
|
|
37 |
#define TRIGGER_ATTACK ((unsigned char) (1 << 0)) // 0x01 |
#define TRIGGER_ATTACK ((unsigned char) (1 << 0)) // 0x01 |
38 |
#define TRIGGER_RELEASE ((unsigned char) (1 << 1)) // 0x02 |
#define TRIGGER_RELEASE ((unsigned char) (1 << 1)) // 0x02 |
39 |
#define TRIGGER_FIRST ((unsigned char) (1 << 2)) // 0x04 |
#define TRIGGER_FIRST ((unsigned char) (1 << 2)) // 0x04 |
40 |
#define TRIGGER_LEGATO ((unsigned char) (1 << 3)) // 0x08 |
#define TRIGGER_LEGATO ((unsigned char) (1 << 3)) // 0x08 |
41 |
|
|
42 |
namespace sfz |
namespace sfz |
43 |
{ |
{ |
44 |
// Forward declarations |
// Forward declarations |
45 |
class Articulation; |
class Articulation; |
47 |
class Group; |
class Group; |
48 |
class Instrument; |
class Instrument; |
49 |
class File; |
class File; |
50 |
|
|
51 |
class Sample : public LinuxSampler::SampleFileBase<Region> { |
class Sample : public LinuxSampler::SampleFileBase<Region> { |
52 |
public: |
public: |
53 |
Sample(String File, bool DontClose = false) : LinuxSampler::SampleFileBase<Region>(File, DontClose) { } |
Sample(String File, bool DontClose = false) : LinuxSampler::SampleFileBase<Region>(File, DontClose) { } |
215 |
virtual ~Articulation(); |
virtual ~Articulation(); |
216 |
}; |
}; |
217 |
|
|
218 |
|
class EGNode |
219 |
|
{ |
220 |
|
public: |
221 |
|
float time; |
222 |
|
float level; |
223 |
|
float shape; |
224 |
|
float curve; |
225 |
|
EGNode(); |
226 |
|
}; |
227 |
|
|
228 |
|
class EG |
229 |
|
{ |
230 |
|
public: |
231 |
|
LinuxSampler::ArrayList<EGNode> node; |
232 |
|
int sustain; |
233 |
|
int loop; |
234 |
|
int loop_count; |
235 |
|
float amplitude; |
236 |
|
float cutoff; |
237 |
|
EG(); |
238 |
|
}; |
239 |
|
|
240 |
|
// Fixed size array with copy-on-write semantics |
241 |
|
template<class T> |
242 |
|
class Array |
243 |
|
{ |
244 |
|
private: |
245 |
|
struct Rep { |
246 |
|
int refcount; |
247 |
|
T a[128]; |
248 |
|
|
249 |
|
Rep() : refcount(1) { } |
250 |
|
static void release(Rep* rep) { |
251 |
|
if (!--rep->refcount) delete rep; |
252 |
|
} |
253 |
|
} *ptr; |
254 |
|
public: |
255 |
|
Array() : ptr(0) { } |
256 |
|
~Array() { Rep::release(ptr); } |
257 |
|
|
258 |
|
Array& operator=(const Array& array) { |
259 |
|
if (this != &array) { |
260 |
|
ptr = array.ptr; |
261 |
|
if (ptr) ptr->refcount++; |
262 |
|
} |
263 |
|
return *this; |
264 |
|
} |
265 |
|
|
266 |
|
const T& operator[](int i) const { return ptr->a[i]; } |
267 |
|
|
268 |
|
void set(int i, const T& v) { |
269 |
|
if (!ptr) { |
270 |
|
ptr = new Rep; |
271 |
|
} else if (ptr->refcount > 1 && ptr->a[i] != v) { |
272 |
|
Rep* newptr = new Rep(*ptr); |
273 |
|
newptr->refcount = 1; |
274 |
|
Rep::release(ptr); |
275 |
|
ptr = newptr; |
276 |
|
} |
277 |
|
ptr->a[i] = v; |
278 |
|
} |
279 |
|
}; |
280 |
|
|
281 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
282 |
// class Definition |
// class Definition |
283 |
|
|
295 |
int lochan; int hichan; |
int lochan; int hichan; |
296 |
int lokey; int hikey; |
int lokey; int hikey; |
297 |
int lovel; int hivel; |
int lovel; int hivel; |
298 |
std::vector<int> locc; std::vector<int> hicc; |
Array<int> locc; Array<int> hicc; |
299 |
int lobend; int hibend; |
int lobend; int hibend; |
300 |
int lobpm; int hibpm; |
int lobpm; int hibpm; |
301 |
int lochanaft; int hichanaft; |
int lochanaft; int hichanaft; |
307 |
int seq_length; |
int seq_length; |
308 |
int seq_position; |
int seq_position; |
309 |
|
|
310 |
std::vector<int> start_locc; std::vector<int> start_hicc; |
Array<int> start_locc; Array<int> start_hicc; |
311 |
std::vector<int> stop_locc; std::vector<int> stop_hicc; |
Array<int> stop_locc; Array<int> stop_hicc; |
312 |
|
|
313 |
int sw_lokey; int sw_hikey; |
int sw_lokey; int sw_hikey; |
314 |
int sw_last; |
int sw_last; |
319 |
|
|
320 |
trigger_t trigger; |
trigger_t trigger; |
321 |
|
|
322 |
optional<int> group; |
uint group; |
323 |
optional<int> off_by; |
optional<int> off_by; |
324 |
off_mode_t off_mode; |
off_mode_t off_mode; |
325 |
|
|
326 |
std::vector<int> on_locc; std::vector<int> on_hicc; |
Array<int> on_locc; Array<int> on_hicc; |
327 |
|
|
328 |
// sample player |
// sample player |
329 |
optional<int> count; |
optional<int> count; |
330 |
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; |
331 |
optional<int> delay_beats; optional<int> stop_beats; |
optional<int> delay_beats; optional<int> stop_beats; |
332 |
optional<int> delay_samples; std::vector<optional<int> > delay_samples_oncc; |
optional<int> delay_samples; Array<optional<int> > delay_samples_oncc; |
333 |
optional<int> end; |
optional<int> end; |
334 |
optional<float> loop_crossfade; |
optional<float> loop_crossfade; |
335 |
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; |
336 |
loop_mode_t loop_mode; |
loop_mode_t loop_mode; |
337 |
optional<int> loop_start; optional<int> loop_end; |
optional<int> loop_start; optional<int> loop_end; |
338 |
optional<int> sync_beats; |
optional<int> sync_beats; |
343 |
float pan; |
float pan; |
344 |
float width; |
float width; |
345 |
float position; |
float position; |
346 |
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; |
347 |
float rt_decay; |
float rt_decay; |
348 |
std::vector<float> gain_oncc; |
Array<float> gain_oncc; |
349 |
int xfin_lokey; int xfin_hikey; |
int xfin_lokey; int xfin_hikey; |
350 |
int xfout_lokey; int xfout_hikey; |
int xfout_lokey; int xfout_hikey; |
351 |
curve_t xf_keycurve; |
curve_t xf_keycurve; |
352 |
int xfin_lovel; int xfin_hivel; |
int xfin_lovel; int xfin_hivel; |
353 |
int xfout_lovel; int xfout_hivel; |
int xfout_lovel; int xfout_hivel; |
354 |
curve_t xf_velcurve; |
curve_t xf_velcurve; |
355 |
std::vector<int> xfin_locc; std::vector<int> xfin_hicc; |
Array<int> xfin_locc; Array<int> xfin_hicc; |
356 |
std::vector<int> xfout_locc; std::vector<int> xfout_hicc; |
Array<int> xfout_locc; Array<int> xfout_hicc; |
357 |
curve_t xf_cccurve; |
curve_t xf_cccurve; |
358 |
|
|
359 |
// pitch |
// pitch |
365 |
// filter |
// filter |
366 |
filter_t fil_type; filter_t fil2_type; |
filter_t fil_type; filter_t fil2_type; |
367 |
optional<float> cutoff; optional<float> cutoff2; |
optional<float> cutoff; optional<float> cutoff2; |
368 |
std::vector<int> cutoff_oncc; std::vector<int> cutoff2_oncc; |
Array<int> cutoff_oncc; Array<int> cutoff2_oncc; |
369 |
std::vector<int> cutoff_smoothcc; std::vector<int> cutoff2_smoothcc; |
Array<int> cutoff_smoothcc; Array<int> cutoff2_smoothcc; |
370 |
std::vector<int> cutoff_stepcc; std::vector<int> cutoff2_stepcc; |
Array<int> cutoff_stepcc; Array<int> cutoff2_stepcc; |
371 |
std::vector<int> cutoff_curvecc; std::vector<int> cutoff2_curvecc; |
Array<int> cutoff_curvecc; Array<int> cutoff2_curvecc; |
372 |
int cutoff_chanaft; int cutoff2_chanaft; |
int cutoff_chanaft; int cutoff2_chanaft; |
373 |
int cutoff_polyaft; int cutoff2_polyaft; |
int cutoff_polyaft; int cutoff2_polyaft; |
374 |
float resonance; float resonance2; |
float resonance; float resonance2; |
375 |
std::vector<int> resonance_oncc; std::vector<int> resonance2_oncc; |
Array<int> resonance_oncc; Array<int> resonance2_oncc; |
376 |
std::vector<int> resonance_smoothcc; std::vector<int> resonance2_smoothcc; |
Array<int> resonance_smoothcc; Array<int> resonance2_smoothcc; |
377 |
std::vector<int> resonance_stepcc; std::vector<int> resonance2_stepcc; |
Array<int> resonance_stepcc; Array<int> resonance2_stepcc; |
378 |
std::vector<int> resonance_curvecc; std::vector<int> resonance2_curvecc; |
Array<int> resonance_curvecc; Array<int> resonance2_curvecc; |
379 |
int fil_keytrack; int fil2_keytrack; |
int fil_keytrack; int fil2_keytrack; |
380 |
int fil_keycenter; int fil2_keycenter; |
int fil_keycenter; int fil2_keycenter; |
381 |
int fil_veltrack; int fil2_veltrack; |
int fil_veltrack; int fil2_veltrack; |
383 |
|
|
384 |
// per voice equalizer |
// per voice equalizer |
385 |
float eq1_freq; float eq2_freq; float eq3_freq; |
float eq1_freq; float eq2_freq; float eq3_freq; |
386 |
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; |
387 |
float eq1_vel2freq; float eq2_vel2freq; float eq3_vel2freq; |
float eq1_vel2freq; float eq2_vel2freq; float eq3_vel2freq; |
388 |
float eq1_bw; float eq2_bw; float eq3_bw; |
float eq1_bw; float eq2_bw; float eq3_bw; |
389 |
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; |
390 |
float eq1_gain; float eq2_gain; float eq3_gain; |
float eq1_gain; float eq2_gain; float eq3_gain; |
391 |
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; |
392 |
float eq1_vel2gain; float eq2_vel2gain; float eq3_vel2gain; |
float eq1_vel2gain; float eq2_vel2gain; float eq3_vel2gain; |
393 |
|
|
394 |
//Deprecated (from version 1) |
//Deprecated (from version 1) |
395 |
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; |
396 |
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; |
397 |
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; |
398 |
|
float amplfo_delay, amplfo_fade, amplfo_freq, amplfo_depth; |
399 |
|
float fillfo_delay, fillfo_fade, fillfo_freq, fillfo_depth; |
400 |
|
float pitchlfo_delay, pitchlfo_fade, pitchlfo_freq; |
401 |
|
int pitchlfo_depth; |
402 |
|
|
403 |
|
// envelope generators |
404 |
|
LinuxSampler::ArrayList<EG> eg; |
405 |
}; |
}; |
406 |
|
|
407 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
432 |
bool OnKey(uint8_t chan, uint8_t key, uint8_t vel, |
bool OnKey(uint8_t chan, uint8_t key, uint8_t vel, |
433 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
434 |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
435 |
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); |
436 |
|
|
437 |
/// Return true if region is triggered by control change |
/// Return true if region is triggered by control change |
438 |
bool OnControl(uint8_t chan, uint8_t cont, uint8_t val, |
bool OnControl(uint8_t chan, uint8_t cont, uint8_t val, |
439 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
440 |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
441 |
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); |
442 |
|
|
443 |
/// Return an articulation for the current state |
/// Return an articulation for the current state |
444 |
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); |
448 |
|
|
449 |
private: |
private: |
450 |
Instrument* pInstrument; |
Instrument* pInstrument; |
451 |
|
int seq_counter; |
452 |
}; |
}; |
453 |
|
|
454 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
471 |
uint8_t chan, uint8_t key, uint8_t vel, |
uint8_t chan, uint8_t key, uint8_t vel, |
472 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
473 |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
474 |
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 |
475 |
); |
); |
476 |
|
|
477 |
bool DestroyRegion(Region* pRegion); |
bool DestroyRegion(Region* pRegion); |
529 |
private: |
private: |
530 |
void push_header(std::string token); |
void push_header(std::string token); |
531 |
void push_opcode(std::string token); |
void push_opcode(std::string token); |
532 |
int parseInt(std::string value); |
int parseKey(const std::string& value); |
533 |
float parseFloat(std::string value); |
EG& eg(int x); |
534 |
|
EGNode& egnode(int x, int y); |
535 |
|
|
536 |
std::string currentDir; |
std::string currentDir; |
537 |
/// Pointer to the Instrument belonging to this file |
/// Pointer to the Instrument belonging to this file |