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

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

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

revision 2021 by iliev, Fri Oct 30 16:36:20 2009 UTC revision 2101 by persson, Sun May 30 11:40:31 2010 UTC
# Line 2  Line 2 
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  *
# Line 32  Line 32 
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;
# Line 46  namespace sfz Line 47  namespace sfz
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) { }
# Line 214  namespace sfz Line 215  namespace sfz
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    
# Line 231  namespace sfz Line 295  namespace sfz
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;
# Line 243  namespace sfz Line 307  namespace sfz
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;
# Line 255  namespace sfz Line 319  namespace sfz
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;
# Line 279  namespace sfz Line 343  namespace sfz
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
# Line 301  namespace sfz Line 365  namespace sfz
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;
# Line 319  namespace sfz Line 383  namespace sfz
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        class Query {
408        public:
409            Query(const Instrument& instrument);
410            Region* next();
411            uint8_t chan;        // MIDI channel
412            uint8_t key;         // MIDI note      TODO: or controller
413            uint8_t vel;         // MIDI velocity
414            int bend;            // MIDI pitch bend
415            uint8_t bpm;         // host BPM
416            uint8_t chanaft;     // MIDI channel pressure
417            uint8_t polyaft;     // MIDI polyphonic aftertouch
418            uint8_t prog;        // MIDI program change
419            float rand;          // generated random number
420            trigger_t trig;      // how it was triggered
421            uint8_t* cc;         // all 128 CC values
422            float timer;         // time since previous region in the group was triggered
423            bool* sw;            // state of region key switches, 128 possible values
424            uint8_t last_sw_key; // last key pressed in the key switch range
425            uint8_t prev_sw_key; // previous note value
426        private:
427            std::vector<Region*>::const_iterator i;
428            std::vector<Region*>::const_iterator regions_end;
429      };      };
430    
431      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
# Line 358  namespace sfz Line 453  namespace sfz
453          uint GetLoopCount();          uint GetLoopCount();
454    
455          /// Return true if region is triggered by key          /// Return true if region is triggered by key
456          bool OnKey(uint8_t chan, uint8_t key, uint8_t vel,          bool OnKey(const Query& q);
                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);  
457    
458          /// Return true if region is triggered by control change          /// Return true if region is triggered by control change
459          bool OnControl(uint8_t chan, uint8_t cont, uint8_t val,          bool OnControl(uint8_t chan, uint8_t cont, uint8_t val,
460                     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,                     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
461                     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,                     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
462                     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);
463    
464          /// Return an articulation for the current state          /// Return an articulation for the current state
465           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);
466    
467          // unique region id          // unique region id
468          int id;          int id;
469    
470      private:      private:
471          Instrument* pInstrument;          Instrument* pInstrument;
472            int seq_counter;
473      };      };
474    
475      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
# Line 392  namespace sfz Line 485  namespace sfz
485          std::string GetName() { return name; }          std::string GetName() { return name; }
486          SampleManager* GetSampleManager() { return pSampleManager; }          SampleManager* GetSampleManager() { return pSampleManager; }
487    
         /**  
          * @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  
         );  
   
488          bool DestroyRegion(Region* pRegion);          bool DestroyRegion(Region* pRegion);
489          bool HasKeyBinding(uint8_t key);          bool HasKeyBinding(uint8_t key);
490          bool HasKeySwitchBinding(uint8_t key);          bool HasKeySwitchBinding(uint8_t key);
# Line 457  namespace sfz Line 540  namespace sfz
540      private:      private:
541          void  push_header(std::string token);          void  push_header(std::string token);
542          void  push_opcode(std::string token);          void  push_opcode(std::string token);
543          int   parseInt(std::string value);          int parseKey(const std::string& value);
544          float parseFloat(std::string value);          EG& eg(int x);
545            EGNode& egnode(int x, int y);
546    
547          std::string currentDir;          std::string currentDir;
548          /// Pointer to the Instrument belonging to this file          /// Pointer to the Instrument belonging to this file

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

  ViewVC Help
Powered by ViewVC