/[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 2106 by persson, Sun Jul 4 12:50:51 2010 UTC
# 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 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 282  namespace sfz Line 324  namespace sfz
324          optional<int> off_by;          optional<int> 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;          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;
# Line 342  namespace sfz Line 384  namespace sfz
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)
# Line 363  namespace sfz Line 405  namespace sfz
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      TODO: or controller
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            Region* next();
428        private:
429            LinuxSampler::ArrayList<Region*>* pRegionList;
430            int regionIndex;
431        };
432    
433      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
434      // class Region      // class Region
435    
# Line 387  namespace sfz Line 454  namespace sfz
454          uint GetLoopEnd();          uint GetLoopEnd();
455          uint GetLoopCount();          uint GetLoopCount();
456    
457          /// Return true if region is triggered by key          /// Return true if region is triggered by key. Region is
458          bool OnKey(uint8_t chan, uint8_t key, uint8_t vel,          /// assumed to come from a search in the lookup table.
459                 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);  
460    
461          /// Return true if region is triggered by control change          /// Return true if region is triggered by control change
462          bool OnControl(uint8_t chan, uint8_t cont, uint8_t val,          bool OnControl(uint8_t chan, uint8_t cont, uint8_t val,
# Line 400  namespace sfz Line 465  namespace sfz
465                     float timer, 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);
466    
467          /// Return an articulation for the current state          /// Return an articulation for the current state
468           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);
469    
470          // unique region id          // unique region id
471          int id;          int id;
# Line 423  namespace sfz Line 488  namespace sfz
488          std::string GetName() { return name; }          std::string GetName() { return name; }
489          SampleManager* GetSampleManager() { return pSampleManager; }          SampleManager* GetSampleManager() { return pSampleManager; }
490    
         /**  
          * @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  
         );  
   
491          bool DestroyRegion(Region* pRegion);          bool DestroyRegion(Region* pRegion);
492          bool HasKeyBinding(uint8_t key);          bool HasKeyBinding(uint8_t key);
493          bool HasKeySwitchBinding(uint8_t key);          bool HasKeySwitchBinding(uint8_t key);
# Line 440  namespace sfz Line 495  namespace sfz
495          /// List of Regions belonging to this Instrument          /// List of Regions belonging to this Instrument
496          std::vector<Region*> regions;          std::vector<Region*> regions;
497    
498          friend class sfz::File;          friend class File;
499            friend class Query;
500    
501      private:      private:
502          std::string name;          std::string name;
503          std::vector<bool> KeyBindings;          std::vector<bool> KeyBindings;
504          std::vector<bool> KeySwitchBindings;          std::vector<bool> KeySwitchBindings;
505          SampleManager* pSampleManager;          SampleManager* pSampleManager;
506            LookupTable* pLookupTable;
507      };      };
508    
509      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////

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

  ViewVC Help
Powered by ViewVC