/[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 2114 by persson, Tue Aug 10 12:05:19 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            class LookupTable;
51    
52      class Sample : public LinuxSampler::SampleFileBase<Region> {      class Sample : public LinuxSampler::SampleFileBase<Region> {
53          public:          public:
54              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 216  namespace sfz
216          virtual ~Articulation();          virtual ~Articulation();
217      };      };
218    
219        class EGNode
220        {
221        public:
222            float time;
223            float level;
224            float shape;
225            float curve;
226            EGNode();
227        };
228    
229        class EG
230        {
231        public:
232            LinuxSampler::ArrayList<EGNode> node;
233            int sustain;
234            int loop;
235            int loop_count;
236            float amplitude;
237            float cutoff;
238            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 231  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 243  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 255  namespace sfz Line 320  namespace sfz
320    
321          trigger_t trigger;          trigger_t trigger;
322    
323          optional<int> 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 279  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 301  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 319  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)
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
405            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      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
# Line 357  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, uint8_t seq, 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,
463                     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,                     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
464                     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,                     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
465                     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);
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;
472    
473      private:      private:
474          Instrument* pInstrument;          Instrument* pInstrument;
475            int seq_counter;
476      };      };
477    
478      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
# Line 392  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, uint8_t seq, 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 409  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      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
# Line 457  namespace sfz Line 545  namespace sfz
545      private:      private:
546          void  push_header(std::string token);          void  push_header(std::string token);
547          void  push_opcode(std::string token);          void  push_opcode(std::string token);
548          int   parseInt(std::string value);          int parseKey(const std::string& value);
549          float parseFloat(std::string value);          EG& eg(int x);
550            EGNode& egnode(int x, int y);
551    
552          std::string currentDir;          std::string currentDir;
553          /// 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.2114

  ViewVC Help
Powered by ViewVC