/[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 2072 by persson, Sat Mar 20 11:37:52 2010 UTC revision 2175 by persson, Mon Apr 25 08:12:36 2011 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *
6   *   Copyright (C) 2009 - 2010 Anders Dahnielson and Grigor Iliev          *   *   Copyright (C) 2009 - 2011 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 47  namespace sfz Line 47  namespace sfz
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:
# Line 57  namespace sfz Line 58  namespace sfz
58      // Enumerations      // Enumerations
59      enum sw_vel_t    { VEL_CURRENT, VEL_PREVIOUS };      enum sw_vel_t    { VEL_CURRENT, VEL_PREVIOUS };
60      enum off_mode_t  { OFF_FAST, OFF_NORMAL };      enum off_mode_t  { OFF_FAST, OFF_NORMAL };
61      enum loop_mode_t { NO_LOOP, ONE_SHOT, LOOP_CONTINUOUS, LOOP_SUSTAIN };      enum loop_mode_t { NO_LOOP, ONE_SHOT, LOOP_CONTINUOUS, LOOP_SUSTAIN, LOOP_UNSET };
62      enum curve_t     { GAIN, POWER };      enum curve_t     { GAIN, POWER };
63      enum filter_t    { LPF_1P, HPF_1P, BPF_1P, BRF_1P, APF_1P,      enum filter_t    { LPF_1P, HPF_1P, BPF_1P, BRF_1P, APF_1P,
64                         LPF_2P, HPF_2P, BPF_2P, BRF_2P, PKF_2P,                         LPF_2P, HPF_2P, BPF_2P, BRF_2P, PKF_2P,
# Line 237  namespace sfz Line 238  namespace sfz
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    
# Line 254  namespace sfz Line 296  namespace sfz
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;
# Line 266  namespace sfz Line 308  namespace sfz
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;
# Line 279  namespace sfz Line 321  namespace sfz
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;
# Line 302  namespace sfz Line 344  namespace sfz
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
# Line 324  namespace sfz Line 366  namespace sfz
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;          int cutoff_cc; // TODO: this is just a temporary fix to avoid
371          std::vector<int> cutoff_stepcc; std::vector<int> cutoff2_stepcc;                         // looping through the cutoff_oncc array
372          std::vector<int> cutoff_curvecc; std::vector<int> cutoff2_curvecc;          Array<int> cutoff_smoothcc; Array<int> cutoff2_smoothcc;
373            Array<int> cutoff_stepcc; Array<int> cutoff2_stepcc;
374            Array<int> cutoff_curvecc; Array<int> cutoff2_curvecc;
375          int cutoff_chanaft; int cutoff2_chanaft;          int cutoff_chanaft; int cutoff2_chanaft;
376          int cutoff_polyaft; int cutoff2_polyaft;          int cutoff_polyaft; int cutoff2_polyaft;
377          float resonance; float resonance2;          float resonance; float resonance2;
378          std::vector<int> resonance_oncc; std::vector<int> resonance2_oncc;          Array<int> resonance_oncc; Array<int> resonance2_oncc;
379          std::vector<int> resonance_smoothcc; std::vector<int> resonance2_smoothcc;          Array<int> resonance_smoothcc; Array<int> resonance2_smoothcc;
380          std::vector<int> resonance_stepcc; std::vector<int> resonance2_stepcc;          Array<int> resonance_stepcc; Array<int> resonance2_stepcc;
381          std::vector<int> resonance_curvecc; std::vector<int> resonance2_curvecc;          Array<int> resonance_curvecc; Array<int> resonance2_curvecc;
382          int fil_keytrack; int fil2_keytrack;          int fil_keytrack; int fil2_keytrack;
383          int fil_keycenter; int fil2_keycenter;          int fil_keycenter; int fil2_keycenter;
384          int fil_veltrack; int fil2_veltrack;          int fil_veltrack; int fil2_veltrack;
# Line 342  namespace sfz Line 386  namespace sfz
386    
387          // per voice equalizer          // per voice equalizer
388          float eq1_freq; float eq2_freq; float eq3_freq;          float eq1_freq; float eq2_freq; float eq3_freq;
389          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;
390          float eq1_vel2freq; float eq2_vel2freq; float eq3_vel2freq;          float eq1_vel2freq; float eq2_vel2freq; float eq3_vel2freq;
391          float eq1_bw; float eq2_bw; float eq3_bw;          float eq1_bw; float eq2_bw; float eq3_bw;
392          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;
393          float eq1_gain; float eq2_gain; float eq3_gain;          float eq1_gain; float eq2_gain; float eq3_gain;
394          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;
395          float eq1_vel2gain; float eq2_vel2gain; float eq3_vel2gain;          float eq1_vel2gain; float eq2_vel2gain; float eq3_vel2gain;
396    
397          //Deprecated (from version 1)          //Deprecated (from version 1)
# Line 363  namespace sfz Line 407  namespace sfz
407          LinuxSampler::ArrayList<EG> eg;          LinuxSampler::ArrayList<EG> eg;
408      };      };
409    
410        class Query {
411        public:
412            uint8_t chan;        // MIDI channel
413            uint8_t key;         // MIDI note
414            uint8_t vel;         // MIDI velocity
415            int bend;            // MIDI pitch bend
416            uint8_t bpm;         // host BPM
417            uint8_t chanaft;     // MIDI channel pressure
418            uint8_t polyaft;     // MIDI polyphonic aftertouch
419            uint8_t prog;        // MIDI program change
420            float rand;          // generated random number
421            trigger_t trig;      // how it was triggered
422            uint8_t* cc;         // all 128 CC values
423            float timer;         // time since previous region in the group was triggered
424            bool* sw;            // state of region key switches, 128 possible values
425            uint8_t last_sw_key; // last key pressed in the key switch range
426            uint8_t prev_sw_key; // previous note value
427    
428            void search(const Instrument* pInstrument);
429            void search(const Instrument* pInstrument, int triggercc);
430            Region* next();
431        private:
432            LinuxSampler::ArrayList<Region*>* pRegionList;
433            int regionIndex;
434        };
435    
436      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
437      // class Region      // class Region
438    
# Line 387  namespace sfz Line 457  namespace sfz
457          uint GetLoopEnd();          uint GetLoopEnd();
458          uint GetLoopCount();          uint GetLoopCount();
459    
460          /// Return true if region is triggered by key          /// Return true if region is triggered by key. Region is
461          bool OnKey(uint8_t chan, uint8_t key, uint8_t vel,          /// assumed to come from a search in the lookup table.
462                 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, 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, 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;
# Line 423  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, 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 440  namespace sfz Line 492  namespace sfz
492          /// List of Regions belonging to this Instrument          /// List of Regions belonging to this Instrument
493          std::vector<Region*> regions;          std::vector<Region*> regions;
494    
495          friend class sfz::File;          friend class File;
496            friend class Query;
497    
498      private:      private:
499          std::string name;          std::string name;
500          std::vector<bool> KeyBindings;          std::vector<bool> KeyBindings;
501          std::vector<bool> KeySwitchBindings;          std::vector<bool> KeySwitchBindings;
502          SampleManager* pSampleManager;          SampleManager* pSampleManager;
503            LookupTable* pLookupTable;
504            LookupTable* pLookupTableCC[128];
505      };      };
506    
507      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////

Legend:
Removed from v.2072  
changed lines
  Added in v.2175

  ViewVC Help
Powered by ViewVC