/[svn]/libgig/trunk/src/gig.h
ViewVC logotype

Diff of /libgig/trunk/src/gig.h

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

revision 1335 by schoenebeck, Sun Sep 9 21:22:58 2007 UTC revision 2699 by schoenebeck, Mon Jan 12 17:12:05 2015 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2007 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2015 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 25  Line 25 
25  #define __GIG_H__  #define __GIG_H__
26    
27  #include "DLS.h"  #include "DLS.h"
28    #include <vector>
29    
30  #if WORDS_BIGENDIAN  #if WORDS_BIGENDIAN
31  # define LIST_TYPE_3PRG 0x33707267  # define LIST_TYPE_3PRG 0x33707267
32  # define LIST_TYPE_3EWL 0x3365776C  # define LIST_TYPE_3EWL 0x3365776C
33  # define LIST_TYPE_3GRI 0x33677269  # define LIST_TYPE_3GRI 0x33677269
34  # define LIST_TYPE_3GNL 0x33676E6C  # define LIST_TYPE_3GNL 0x33676E6C
35  # define CHUNK_ID_SMPL  0x736D706C  # define LIST_TYPE_3LS  0x334c5320 // own gig format extension
36    # define LIST_TYPE_RTIS 0x52544953 // own gig format extension
37  # define CHUNK_ID_3GIX  0x33676978  # define CHUNK_ID_3GIX  0x33676978
38  # define CHUNK_ID_3EWA  0x33657761  # define CHUNK_ID_3EWA  0x33657761
39  # define CHUNK_ID_3LNK  0x336C6E6B  # define CHUNK_ID_3LNK  0x336C6E6B
# Line 40  Line 42 
42  # define CHUNK_ID_3GNM  0x33676E6D  # define CHUNK_ID_3GNM  0x33676E6D
43  # define CHUNK_ID_EINF  0x65696E66  # define CHUNK_ID_EINF  0x65696E66
44  # define CHUNK_ID_3CRC  0x33637263  # define CHUNK_ID_3CRC  0x33637263
45    # define CHUNK_ID_SCRI  0x53637269 // own gig format extension
46    # define CHUNK_ID_LSNM  0x4c534e4d // own gig format extension
47    # define CHUNK_ID_SCSL  0x5343534c // own gig format extension
48  #else  // little endian  #else  // little endian
49  # define LIST_TYPE_3PRG 0x67727033  # define LIST_TYPE_3PRG 0x67727033
50  # define LIST_TYPE_3EWL 0x6C776533  # define LIST_TYPE_3EWL 0x6C776533
51  # define LIST_TYPE_3GRI 0x69726733  # define LIST_TYPE_3GRI 0x69726733
52  # define LIST_TYPE_3GNL 0x6C6E6733  # define LIST_TYPE_3GNL 0x6C6E6733
53  # define CHUNK_ID_SMPL  0x6C706D73  # define LIST_TYPE_3LS  0x20534c33 // own gig format extension
54    # define LIST_TYPE_RTIS 0x53495452 // own gig format extension
55  # define CHUNK_ID_3GIX  0x78696733  # define CHUNK_ID_3GIX  0x78696733
56  # define CHUNK_ID_3EWA  0x61776533  # define CHUNK_ID_3EWA  0x61776533
57  # define CHUNK_ID_3LNK  0x6B6E6C33  # define CHUNK_ID_3LNK  0x6B6E6C33
# Line 54  Line 60 
60  # define CHUNK_ID_3GNM  0x6D6E6733  # define CHUNK_ID_3GNM  0x6D6E6733
61  # define CHUNK_ID_EINF  0x666E6965  # define CHUNK_ID_EINF  0x666E6965
62  # define CHUNK_ID_3CRC  0x63726333  # define CHUNK_ID_3CRC  0x63726333
63    # define CHUNK_ID_SCRI  0x69726353 // own gig format extension
64    # define CHUNK_ID_LSNM  0x4d4e534c // own gig format extension
65    # define CHUNK_ID_SCSL  0x4c534353 // own gig format extension
66  #endif // WORDS_BIGENDIAN  #endif // WORDS_BIGENDIAN
67    
68  /** Gigasampler specific classes and definitions */  /** Gigasampler/GigaStudio specific classes and definitions */
69  namespace gig {  namespace gig {
70    
71      typedef std::string String;      typedef std::string String;
72        typedef RIFF::progress_t progress_t;
73    
74      /** Lower and upper limit of a range. */      /** Lower and upper limit of a range. */
75      struct range_t {      struct range_t {
# Line 302  namespace gig { Line 312  namespace gig {
312          unsigned long loop_cycles_left;  ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle.          unsigned long loop_cycles_left;  ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle.
313      };      };
314    
     /**  
      * @brief Used for indicating the progress of a certain task.  
      *  
      * The function pointer argument has to be supplied with a valid  
      * function of the given signature which will then be called on  
      * progress changes. An equivalent progress_t structure will be passed  
      * back as argument to the callback function on each progress change.  
      * The factor field of the supplied progress_t structure will then  
      * reflect the current progress as value between 0.0 and 1.0. You might  
      * want to use the custom field for data needed in your callback  
      * function.  
      */  
     struct progress_t {  
         void (*callback)(progress_t*); ///< Callback function pointer which has to be assigned to a function for progress notification.  
         float factor;                  ///< Reflects current progress as value between 0.0 and 1.0.  
         void* custom;                  ///< This pointer can be used for arbitrary data.  
         float __range_min;             ///< Only for internal usage, do not modify!  
         float __range_max;             ///< Only for internal usage, do not modify!  
         progress_t();  
     };  
   
     /** @brief CRC-32 checksum implementation  
      *  
      * This class is used to calculate checksums of the sample data in  
      * a gig file. The checksums are stored in the 3crc chunk of the  
      * gig file and automatically updated when a sample is written  
      * with Sample::Write().  
      */  
     class CRC {  
     private:  
         uint32_t value;  
         static const uint32_t* table;  
         static uint32_t* initTable();  
     public:  
         CRC() {  
             reset();  
         }  
         void reset() {  
             value = 0xffffffff;  
         }  
         void update(unsigned char* buf, int len) {  
             for (int i = 0 ; i < len ; i++) {  
                 value = table[(value ^ buf[i]) & 0xff] ^ (value >> 8);  
             }  
         }  
         uint32_t getValue() {  
             return value ^ 0xffffffff;  
         }  
     };  
   
315      // just symbol prototyping      // just symbol prototyping
316      class File;      class File;
317      class Instrument;      class Instrument;
318      class Sample;      class Sample;
319      class Region;      class Region;
320      class Group;      class Group;
321        class Script;
322        class ScriptGroup;
323    
324      /** @brief Encapsulates articulation information of a dimension region.      /** @brief Encapsulates articulation informations of a dimension region.
325         *
326         * This is the most important data object of the Gigasampler / GigaStudio
327         * format. A DimensionRegion provides the link to the sample to be played
328         * and all required articulation informations to be interpreted for playing
329         * back the sample and processing it appropriately by the sampler software.
330         * Every Region of a Gigasampler Instrument has at least one dimension
331         * region (exactly then when the Region has no dimension defined). Many
332         * Regions though provide more than one DimensionRegion, which reflect
333         * different playing "cases". For example a different sample might be played
334         * if a certain pedal is pressed down, or if the note was triggered with
335         * different velocity.
336         *
337         * One instance of a DimensionRegion reflects exactly one particular case
338         * while playing an instrument (for instance "note between C3 and E3 was
339         * triggered AND note on velocity was between 20 and 42 AND modulation wheel
340         * controller is between 80 and 127). The DimensionRegion defines what to do
341         * under that one particular case, that is which sample to play back and how
342         * to play that sample back exactly and how to process it. So a
343         * DimensionRegion object is always linked to exactly one sample. It may
344         * however also link to no sample at all, for defining a "silence" case
345         * where nothing shall be played (for example when note on velocity was
346         * below 6).
347       *       *
348       *  Every Gigasampler Instrument has at least one dimension region       * Note that a DimensionRegion object only defines "what to do", but it does
349       *  (exactly then when it has no dimension defined).       * not define "when to do it". To actually resolve which DimensionRegion to
350         * pick under which situation, you need to refer to the DimensionRegions'
351         * parent Region object. The Region object contains the necessary
352         * "Dimension" definitions, which in turn define which DimensionRegion is
353         * associated with which playing case exactly.
354       *       *
355       *  Gigasampler provides three Envelope Generators and Low Frequency       * The Gigasampler/GigaStudio format defines 3 Envelope Generators and 3
356       *  Oscillators:       * Low Frequency Oscillators:
357       *       *
358       *  - EG1 and LFO1, both controlling sample amplitude       *  - EG1 and LFO1, both controlling sample amplitude
359       *  - EG2 and LFO2, both controlling filter cutoff frequency       *  - EG2 and LFO2, both controlling filter cutoff frequency
360       *  - EG3 and LFO3, both controlling sample pitch       *  - EG3 and LFO3, both controlling sample pitch
361         *
362         * Since the gig format was designed as extension to the DLS file format,
363         * this class is derived from the DLS::Sampler class. So also refer to
364         * DLS::Sampler for additional informations, class attributes and methods.
365       */       */
366      class DimensionRegion : protected DLS::Sampler {      class DimensionRegion : protected DLS::Sampler {
367          public:          public:
368              uint8_t            VelocityUpperLimit;            ///< Defines the upper velocity value limit of a velocity split (only if an user defined limit was set, thus a value not equal to 128/NumberOfSplits, else this value is 0). Only for gig2, otherwise the DimensionUpperLimts are used instead.              uint8_t            VelocityUpperLimit;            ///< Defines the upper velocity value limit of a velocity split (only if an user defined limit was set, thus a value not equal to 128/NumberOfSplits, else this value is 0). Only for gig2, for gig3 and above the DimensionUpperLimits are used instead.
369              Sample*            pSample;                       ///< Points to the Sample which is assigned to the dimension region.              Sample*            pSample;                       ///< Points to the Sample which is assigned to the dimension region.
370              // Sample Amplitude EG/LFO              // Sample Amplitude EG/LFO
371              uint16_t           EG1PreAttack;                  ///< Preattack value of the sample amplitude EG (0 - 1000 permille).              uint16_t           EG1PreAttack;                  ///< Preattack value of the sample amplitude EG (0 - 1000 permille).
# Line 425  namespace gig { Line 417  namespace gig {
417              // Filter              // Filter
418              bool               VCFEnabled;                    ///< If filter should be used.              bool               VCFEnabled;                    ///< If filter should be used.
419              vcf_type_t         VCFType;                       ///< Defines the general filter characteristic (lowpass, highpass, bandpass, etc.).              vcf_type_t         VCFType;                       ///< Defines the general filter characteristic (lowpass, highpass, bandpass, etc.).
420              vcf_cutoff_ctrl_t  VCFCutoffController;           ///< Specifies which external controller has influence on the filter cutoff frequency.              vcf_cutoff_ctrl_t  VCFCutoffController;           ///< Specifies which external controller has influence on the filter cutoff frequency. @deprecated Don't alter directly, use SetVCFCutoffController() instead!
421              bool               VCFCutoffControllerInvert;     ///< Inverts values coming from the defined cutoff controller              bool               VCFCutoffControllerInvert;     ///< Inverts values coming from the defined cutoff controller
422              uint8_t            VCFCutoff;                     ///< Max. cutoff frequency.              uint8_t            VCFCutoff;                     ///< Max. cutoff frequency.
423              curve_type_t       VCFVelocityCurve;              ///< Defines a transformation curve for the incoming velocity values, affecting the VCF.              curve_type_t       VCFVelocityCurve;              ///< Defines a transformation curve for the incoming velocity values, affecting the VCF. @deprecated Don't alter directly, use SetVCFVelocityCurve() instead!
424              uint8_t            VCFVelocityScale;              ///< (0-127) Amount velocity controls VCF cutoff frequency (only if no other VCF cutoff controller is defined, otherwise this is the minimum cutoff).              uint8_t            VCFVelocityScale;              ///< (0-127) Amount velocity controls VCF cutoff frequency (only if no other VCF cutoff controller is defined, otherwise this is the minimum cutoff). @deprecated Don't alter directly, use SetVCFVelocityScale() instead!
425              uint8_t            VCFVelocityDynamicRange;       ///< 0x04 = lowest, 0x00 = highest              uint8_t            VCFVelocityDynamicRange;       ///< 0x04 = lowest, 0x00 = highest . @deprecated Don't alter directly, use SetVCFVelocityDynamicRange() instead!
426              uint8_t            VCFResonance;                  ///< Firm internal filter resonance weight.              uint8_t            VCFResonance;                  ///< Firm internal filter resonance weight.
427              bool               VCFResonanceDynamic;           ///< If <i>true</i>: Increases the resonance Q according to changes of controllers that actually control the VCF cutoff frequency (EG2, ext. VCF MIDI controller).              bool               VCFResonanceDynamic;           ///< If <i>true</i>: Increases the resonance Q according to changes of controllers that actually control the VCF cutoff frequency (EG2, ext. VCF MIDI controller).
428              vcf_res_ctrl_t     VCFResonanceController;        ///< Specifies which external controller has influence on the filter resonance Q.              vcf_res_ctrl_t     VCFResonanceController;        ///< Specifies which external controller has influence on the filter resonance Q.
429              bool               VCFKeyboardTracking;           ///< If <i>true</i>: VCF cutoff frequence will be dependend to the note key position relative to the defined breakpoint value.              bool               VCFKeyboardTracking;           ///< If <i>true</i>: VCF cutoff frequence will be dependend to the note key position relative to the defined breakpoint value.
430              uint8_t            VCFKeyboardTrackingBreakpoint; ///< See VCFKeyboardTracking (0 - 127).              uint8_t            VCFKeyboardTrackingBreakpoint; ///< See VCFKeyboardTracking (0 - 127).
431              // Key Velocity Transformations              // Key Velocity Transformations
432              curve_type_t       VelocityResponseCurve;         ///< Defines a transformation curve to the incoming velocity values affecting amplitude (usually you don't have to interpret this parameter, use GetVelocityAttenuation() instead).              curve_type_t       VelocityResponseCurve;         ///< Defines a transformation curve to the incoming velocity values affecting amplitude (usually you don't have to interpret this parameter, use GetVelocityAttenuation() instead). @deprecated Don't alter directly, use SetVelocityResponseCurve() instead!
433              uint8_t            VelocityResponseDepth;         ///< Dynamic range of velocity affecting amplitude (0 - 4) (usually you don't have to interpret this parameter, use GetVelocityAttenuation() instead).              uint8_t            VelocityResponseDepth;         ///< Dynamic range of velocity affecting amplitude (0 - 4) (usually you don't have to interpret this parameter, use GetVelocityAttenuation() instead). @deprecated Don't alter directly, use SetVelocityResponseDepth() instead!
434              uint8_t            VelocityResponseCurveScaling;  ///< 0 - 127 (usually you don't have to interpret this parameter, use GetVelocityAttenuation() instead)              uint8_t            VelocityResponseCurveScaling;  ///< 0 - 127 (usually you don't have to interpret this parameter, use GetVelocityAttenuation() instead). @deprecated Don't alter directly, use SetVelocityResponseCurveScaling() instead!
435              curve_type_t       ReleaseVelocityResponseCurve;  ///< Defines a transformation curve to the incoming release veloctiy values affecting envelope times.              curve_type_t       ReleaseVelocityResponseCurve;  ///< Defines a transformation curve to the incoming release veloctiy values affecting envelope times. @deprecated Don't alter directly, use SetReleaseVelocityResponseCurve() instead!
436              uint8_t            ReleaseVelocityResponseDepth;  ///< Dynamic range of release velocity affecting envelope time (0 - 4).              uint8_t            ReleaseVelocityResponseDepth;  ///< Dynamic range of release velocity affecting envelope time (0 - 4). @deprecated Don't alter directly, use SetReleaseVelocityResponseDepth() instead!
437              uint8_t            ReleaseTriggerDecay;           ///< 0 - 8              uint8_t            ReleaseTriggerDecay;           ///< 0 - 8
438              // Mix / Layer              // Mix / Layer
439              crossfade_t        Crossfade;              crossfade_t        Crossfade;
# Line 457  namespace gig { Line 449  namespace gig {
449              bool               MSDecode;                      ///< Gigastudio flag: defines if Mid Side Recordings should be decoded.              bool               MSDecode;                      ///< Gigastudio flag: defines if Mid Side Recordings should be decoded.
450              uint16_t           SampleStartOffset;             ///< Number of samples the sample start should be moved (0 - 2000).              uint16_t           SampleStartOffset;             ///< Number of samples the sample start should be moved (0 - 2000).
451              double             SampleAttenuation;             ///< Sample volume (calculated from DLS::Sampler::Gain)              double             SampleAttenuation;             ///< Sample volume (calculated from DLS::Sampler::Gain)
452              uint8_t            DimensionUpperLimits[8];       ///< gig3: defines the upper limit of the dimension values for this dimension region              uint8_t            DimensionUpperLimits[8];       ///< gig3: defines the upper limit of the dimension values for this dimension region. In case you wondered why this is defined on DimensionRegion level and not on Region level: the zone sizes (upper limits) of the velocity dimension can indeed differ in the individual dimension regions, depending on which zones of the other dimension types are currently selected. So this is exceptional for the velocity dimension only. All other dimension types have the same dimension zone sizes for every single DimensionRegion (of the sample Region).
453    
454              // derived attributes from DLS::Sampler              // derived attributes from DLS::Sampler
455              DLS::Sampler::UnityNote;              using DLS::Sampler::UnityNote;
456              DLS::Sampler::FineTune;              using DLS::Sampler::FineTune;
457              DLS::Sampler::Gain;              using DLS::Sampler::Gain;
458              DLS::Sampler::SampleLoops;              using DLS::Sampler::SampleLoops;
459              DLS::Sampler::pSampleLoops;              using DLS::Sampler::pSampleLoops;
460    
461              // own methods              // own methods
462              double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);              double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);
463              double GetVelocityRelease(uint8_t MIDIKeyVelocity);              double GetVelocityRelease(uint8_t MIDIKeyVelocity);
464              double GetVelocityCutoff(uint8_t MIDIKeyVelocity);              double GetVelocityCutoff(uint8_t MIDIKeyVelocity);
465                void SetVelocityResponseCurve(curve_type_t curve);
466                void SetVelocityResponseDepth(uint8_t depth);
467                void SetVelocityResponseCurveScaling(uint8_t scaling);
468                void SetReleaseVelocityResponseCurve(curve_type_t curve);
469                void SetReleaseVelocityResponseDepth(uint8_t depth);
470                void SetVCFCutoffController(vcf_cutoff_ctrl_t controller);
471                void SetVCFVelocityCurve(curve_type_t curve);
472                void SetVCFVelocityDynamicRange(uint8_t range);
473                void SetVCFVelocityScale(uint8_t scaling);
474              Region* GetParent() const;              Region* GetParent() const;
475              // derived methods              // derived methods
476              DLS::Sampler::AddSampleLoop;              using DLS::Sampler::AddSampleLoop;
477              DLS::Sampler::DeleteSampleLoop;              using DLS::Sampler::DeleteSampleLoop;
478              // overridden methods              // overridden methods
479              virtual void UpdateChunks();              virtual void SetGain(int32_t gain);
480                virtual void UpdateChunks(progress_t* pProgress);
481                virtual void CopyAssign(const DimensionRegion* orig);
482          protected:          protected:
483              uint8_t* VelocityTable; ///< For velocity dimensions with custom defined zone ranges only: used for fast converting from velocity MIDI value to dimension bit number.              uint8_t* VelocityTable; ///< For velocity dimensions with custom defined zone ranges only: used for fast converting from velocity MIDI value to dimension bit number.
484              DimensionRegion(Region* pParent, RIFF::List* _3ewl);              DimensionRegion(Region* pParent, RIFF::List* _3ewl);
485              DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);              DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);
486             ~DimensionRegion();             ~DimensionRegion();
487                void CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples);
488              friend class Region;              friend class Region;
489          private:          private:
490              typedef enum { ///< Used to decode attenuation, EG1 and EG2 controller              typedef enum { ///< Used to decode attenuation, EG1 and EG2 controller
491                    // official leverage controllers as they were defined in the original Gigasampler/GigaStudio format:
492                  _lev_ctrl_none              = 0x00,                  _lev_ctrl_none              = 0x00,
493                  _lev_ctrl_modwheel          = 0x03, ///< Modulation Wheel (MIDI Controller 1)                  _lev_ctrl_modwheel          = 0x03, ///< Modulation Wheel (MIDI Controller 1)
494                  _lev_ctrl_breath            = 0x05, ///< Breath Controller (Coarse, MIDI Controller 2)                  _lev_ctrl_breath            = 0x05, ///< Breath Controller (Coarse, MIDI Controller 2)
# Line 509  namespace gig { Line 514  namespace gig {
514                  _lev_ctrl_effect4depth      = 0x2b, ///< Effect 4 Depth (MIDI Controller 94)                  _lev_ctrl_effect4depth      = 0x2b, ///< Effect 4 Depth (MIDI Controller 94)
515                  _lev_ctrl_effect5depth      = 0x2d, ///< Effect 5 Depth (MIDI Controller 95)                  _lev_ctrl_effect5depth      = 0x2d, ///< Effect 5 Depth (MIDI Controller 95)
516                  _lev_ctrl_channelaftertouch = 0x2f, ///< Channel Key Pressure                  _lev_ctrl_channelaftertouch = 0x2f, ///< Channel Key Pressure
517                  _lev_ctrl_velocity          = 0xff  ///< Key Velocity                  _lev_ctrl_velocity          = 0xff, ///< Key Velocity
518    
519                    // format extension (these controllers are so far only supported by LinuxSampler & gigedit) they will *NOT* work with Gigasampler/GigaStudio !
520                    // (the assigned values here are their official MIDI CC number plus the highest bit set):
521                    _lev_ctrl_CC3_EXT           = 0x83, ///< MIDI Controller 3 [gig format extension]
522    
523                    _lev_ctrl_CC6_EXT           = 0x86, ///< Data Entry MSB (MIDI Controller 6) [gig format extension]
524                    _lev_ctrl_CC7_EXT           = 0x87, ///< Channel Volume (MIDI Controller 7) [gig format extension]
525                    _lev_ctrl_CC8_EXT           = 0x88, ///< Balance (MIDI Controller 8) [gig format extension]
526                    _lev_ctrl_CC9_EXT           = 0x89, ///< MIDI Controller 9 [gig format extension]
527                    _lev_ctrl_CC10_EXT          = 0x8a, ///< Pan (MIDI Controller 10) [gig format extension]
528                    _lev_ctrl_CC11_EXT          = 0x8b, ///< Expression Controller (MIDI Controller 11) [gig format extension]
529    
530                    _lev_ctrl_CC14_EXT          = 0x8e, ///< MIDI Controller 14 [gig format extension]
531                    _lev_ctrl_CC15_EXT          = 0x8f, ///< MIDI Controller 15 [gig format extension]
532    
533                    _lev_ctrl_CC20_EXT          = 0x94, ///< MIDI Controller 20 [gig format extension]
534                    _lev_ctrl_CC21_EXT          = 0x95, ///< MIDI Controller 21 [gig format extension]
535                    _lev_ctrl_CC22_EXT          = 0x96, ///< MIDI Controller 22 [gig format extension]
536                    _lev_ctrl_CC23_EXT          = 0x97, ///< MIDI Controller 23 [gig format extension]
537                    _lev_ctrl_CC24_EXT          = 0x98, ///< MIDI Controller 24 [gig format extension]
538                    _lev_ctrl_CC25_EXT          = 0x99, ///< MIDI Controller 25 [gig format extension]
539                    _lev_ctrl_CC26_EXT          = 0x9a, ///< MIDI Controller 26 [gig format extension]
540                    _lev_ctrl_CC27_EXT          = 0x9b, ///< MIDI Controller 27 [gig format extension]
541                    _lev_ctrl_CC28_EXT          = 0x9c, ///< MIDI Controller 28 [gig format extension]
542                    _lev_ctrl_CC29_EXT          = 0x9d, ///< MIDI Controller 29 [gig format extension]
543                    _lev_ctrl_CC30_EXT          = 0x9e, ///< MIDI Controller 30 [gig format extension]
544                    _lev_ctrl_CC31_EXT          = 0x9f, ///< MIDI Controller 31 [gig format extension]
545    
546                    _lev_ctrl_CC68_EXT          = 0xc4, ///< Legato Footswitch (MIDI Controller 68) [gig format extension]
547                    _lev_ctrl_CC69_EXT          = 0xc5, ///< Hold 2 (MIDI Controller 69) [gig format extension]
548                    _lev_ctrl_CC70_EXT          = 0xc6, ///< Sound Ctrl. 1 - Sound Variation (MIDI Controller 70) [gig format extension]
549                    _lev_ctrl_CC71_EXT          = 0xc7, ///< Sound Ctrl. 2 - Timbre (MIDI Controller 71) [gig format extension]
550                    _lev_ctrl_CC72_EXT          = 0xc8, ///< Sound Ctrl. 3 - Release Time (MIDI Controller 72) [gig format extension]
551                    _lev_ctrl_CC73_EXT          = 0xc9, ///< Sound Ctrl. 4 - Attack Time (MIDI Controller 73) [gig format extension]
552                    _lev_ctrl_CC74_EXT          = 0xca, ///< Sound Ctrl. 5 - Brightness (MIDI Controller 74) [gig format extension]
553                    _lev_ctrl_CC75_EXT          = 0xcb, ///< Sound Ctrl. 6 - Decay Time (MIDI Controller 75) [gig format extension]
554                    _lev_ctrl_CC76_EXT          = 0xcc, ///< Sound Ctrl. 7 - Vibrato Rate (MIDI Controller 76) [gig format extension]
555                    _lev_ctrl_CC77_EXT          = 0xcd, ///< Sound Ctrl. 8 - Vibrato Depth (MIDI Controller 77) [gig format extension]
556                    _lev_ctrl_CC78_EXT          = 0xce, ///< Sound Ctrl. 9 - Vibrato Delay (MIDI Controller 78) [gig format extension]
557                    _lev_ctrl_CC79_EXT          = 0xcf, ///< Sound Ctrl. 10 (MIDI Controller 79) [gig format extension]
558    
559                    _lev_ctrl_CC84_EXT          = 0xd4, ///< Portamento Control (MIDI Controller 84) [gig format extension]
560                    _lev_ctrl_CC85_EXT          = 0xd5, ///< MIDI Controller 85 [gig format extension]
561                    _lev_ctrl_CC86_EXT          = 0xd6, ///< MIDI Controller 86 [gig format extension]
562                    _lev_ctrl_CC87_EXT          = 0xd7, ///< MIDI Controller 87 [gig format extension]
563    
564                    _lev_ctrl_CC89_EXT          = 0xd9, ///< MIDI Controller 89 [gig format extension]
565                    _lev_ctrl_CC90_EXT          = 0xda, ///< MIDI Controller 90 [gig format extension]
566    
567                    _lev_ctrl_CC96_EXT          = 0xe0, ///< Data Increment (MIDI Controller 96) [gig format extension]
568                    _lev_ctrl_CC97_EXT          = 0xe1, ///< Data Decrement (MIDI Controller 97) [gig format extension]
569    
570                    _lev_ctrl_CC102_EXT         = 0xe6, ///< MIDI Controller 102 [gig format extension]
571                    _lev_ctrl_CC103_EXT         = 0xe7, ///< MIDI Controller 103 [gig format extension]
572                    _lev_ctrl_CC104_EXT         = 0xe8, ///< MIDI Controller 104 [gig format extension]
573                    _lev_ctrl_CC105_EXT         = 0xe9, ///< MIDI Controller 105 [gig format extension]
574                    _lev_ctrl_CC106_EXT         = 0xea, ///< MIDI Controller 106 [gig format extension]
575                    _lev_ctrl_CC107_EXT         = 0xeb, ///< MIDI Controller 107 [gig format extension]
576                    _lev_ctrl_CC108_EXT         = 0xec, ///< MIDI Controller 108 [gig format extension]
577                    _lev_ctrl_CC109_EXT         = 0xed, ///< MIDI Controller 109 [gig format extension]
578                    _lev_ctrl_CC110_EXT         = 0xee, ///< MIDI Controller 110 [gig format extension]
579                    _lev_ctrl_CC111_EXT         = 0xef, ///< MIDI Controller 111 [gig format extension]
580                    _lev_ctrl_CC112_EXT         = 0xf0, ///< MIDI Controller 112 [gig format extension]
581                    _lev_ctrl_CC113_EXT         = 0xf1, ///< MIDI Controller 113 [gig format extension]
582                    _lev_ctrl_CC114_EXT         = 0xf2, ///< MIDI Controller 114 [gig format extension]
583                    _lev_ctrl_CC115_EXT         = 0xf3, ///< MIDI Controller 115 [gig format extension]
584                    _lev_ctrl_CC116_EXT         = 0xf4, ///< MIDI Controller 116 [gig format extension]
585                    _lev_ctrl_CC117_EXT         = 0xf5, ///< MIDI Controller 117 [gig format extension]
586                    _lev_ctrl_CC118_EXT         = 0xf6, ///< MIDI Controller 118 [gig format extension]
587                    _lev_ctrl_CC119_EXT         = 0xf7  ///< MIDI Controller 119 [gig format extension]
588              } _lev_ctrl_t;              } _lev_ctrl_t;
589              typedef std::map<uint32_t, double*> VelocityTableMap;              typedef std::map<uint32_t, double*> VelocityTableMap;
590    
# Line 522  namespace gig { Line 597  namespace gig {
597    
598              leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController);              leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController);
599              _lev_ctrl_t     EncodeLeverageController(leverage_ctrl_t DecodedController);              _lev_ctrl_t     EncodeLeverageController(leverage_ctrl_t DecodedController);
600                double* GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth);
601                double* GetCutoffVelocityTable(curve_type_t vcfVelocityCurve, uint8_t vcfVelocityDynamicRange, uint8_t vcfVelocityScale, vcf_cutoff_ctrl_t vcfCutoffController);
602              double* GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);              double* GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);
603              double* CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);              double* CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);
604      };      };
605    
606      /** @brief Encapsulates sample waves used for playback.      /** @brief Encapsulates sample waves of Gigasampler/GigaStudio files used for playback.
607         *
608         * This class provides access to the actual audio sample data of a
609         * Gigasampler/GigaStudio file. Along to the actual sample data, it also
610         * provides access to the sample's meta informations like bit depth,
611         * sample rate, encoding type, but also loop informations. The latter may be
612         * used by instruments for resembling sounds with arbitary note lengths.
613       *       *
614       * In case you created a new sample with File::AddSample(), you should       * In case you created a new sample with File::AddSample(), you should
615       * first update all attributes with the desired meta informations       * first update all attributes with the desired meta informations
# Line 540  namespace gig { Line 623  namespace gig {
623       * retrieved from the respective DimensionRegon instead from the Sample       * retrieved from the respective DimensionRegon instead from the Sample
624       * itself. This was made for allowing different loop definitions for the       * itself. This was made for allowing different loop definitions for the
625       * same sample under different conditions.       * same sample under different conditions.
626         *
627         * Since the gig format was designed as extension to the DLS file format,
628         * this class is derived from the DLS::Sample class. So also refer to
629         * DLS::Sample for additional informations, class attributes and methods.
630       */       */
631      class Sample : public DLS::Sample {      class Sample : public DLS::Sample {
632          public:          public:
# Line 575  namespace gig { Line 662  namespace gig {
662              void          ReleaseSampleData();              void          ReleaseSampleData();
663              void          Resize(int iNewSize);              void          Resize(int iNewSize);
664              unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);              unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
665              unsigned long GetPos();              unsigned long GetPos() const;
666              unsigned long Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer = NULL);              unsigned long Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer = NULL);
667              unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL);              unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL);
668              unsigned long Write(void* pBuffer, unsigned long SampleCount);              unsigned long Write(void* pBuffer, unsigned long SampleCount);
669              Group*        GetGroup() const;              Group*        GetGroup() const;
670              virtual void  UpdateChunks();              virtual void  UpdateChunks(progress_t* pProgress);
671                void CopyAssignMeta(const Sample* orig);
672                void CopyAssignWave(const Sample* orig);
673          protected:          protected:
674              static unsigned int  Instances;               ///< Number of instances of class Sample.              static unsigned int  Instances;               ///< Number of instances of class Sample.
675              static buffer_t      InternalDecompressionBuffer; ///< Buffer used for decompression as well as for truncation of 24 Bit -> 16 Bit samples.              static buffer_t      InternalDecompressionBuffer; ///< Buffer used for decompression as well as for truncation of 24 Bit -> 16 Bit samples.
# Line 595  namespace gig { Line 684  namespace gig {
684              unsigned long        FileNo;                  ///< File number (> 0 when sample is stored in an extension file, 0 when it's in the gig)              unsigned long        FileNo;                  ///< File number (> 0 when sample is stored in an extension file, 0 when it's in the gig)
685              RIFF::Chunk*         pCk3gix;              RIFF::Chunk*         pCk3gix;
686              RIFF::Chunk*         pCkSmpl;              RIFF::Chunk*         pCkSmpl;
687              CRC                  crc;                     ///< CRC-32 checksum of the raw sample data              uint32_t             crc;                     ///< CRC-32 checksum of the raw sample data
688    
689              Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo = 0);              Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo = 0);
690             ~Sample();             ~Sample();
# Line 629  namespace gig { Line 718  namespace gig {
718      };      };
719    
720      // TODO: <3dnl> list not used yet - not important though (just contains optional descriptions for the dimensions)      // TODO: <3dnl> list not used yet - not important though (just contains optional descriptions for the dimensions)
721      /** Defines <i>Region</i> information of an <i>Instrument</i>. */      /** @brief Defines Region information of a Gigasampler/GigaStudio instrument.
722         *
723         * A Region reflects a consecutive area (key range) on the keyboard. The
724         * individual regions in the gig format may not overlap with other regions
725         * (of the same instrument that is). Further, in the gig format a Region is
726         * merely a container for DimensionRegions (a.k.a. "Cases"). The Region
727         * itself does not provide the sample mapping or articulation informations
728         * used, even though the data structures of regions indeed provide such
729         * informations. The latter is however just of historical nature, because
730         * the gig file format was derived from the DLS file format.
731         *
732         * Each Region consists of at least one or more DimensionRegions. The actual
733         * amount of DimensionRegions depends on which kind of "dimensions" are
734         * defined for this region, and on the split / zone amount for each of those
735         * dimensions.
736         *
737         * Since the gig format was designed as extension to the DLS file format,
738         * this class is derived from the DLS::Region class. So also refer to
739         * DLS::Region for additional informations, class attributes and methods.
740         */
741      class Region : public DLS::Region {      class Region : public DLS::Region {
742          public:          public:
743              unsigned int            Dimensions;               ///< Number of defined dimensions, do not alter!              unsigned int            Dimensions;               ///< Number of defined dimensions, do not alter!
# Line 641  namespace gig { Line 749  namespace gig {
749              // own methods              // own methods
750              DimensionRegion* GetDimensionRegionByValue(const uint DimValues[8]);              DimensionRegion* GetDimensionRegionByValue(const uint DimValues[8]);
751              DimensionRegion* GetDimensionRegionByBit(const uint8_t DimBits[8]);              DimensionRegion* GetDimensionRegionByBit(const uint8_t DimBits[8]);
752                int              GetDimensionRegionIndexByValue(const uint DimValues[8]);
753              Sample*          GetSample();              Sample*          GetSample();
754              void             AddDimension(dimension_def_t* pDimDef);              void             AddDimension(dimension_def_t* pDimDef);
755              void             DeleteDimension(dimension_def_t* pDimDef);              void             DeleteDimension(dimension_def_t* pDimDef);
756                dimension_def_t* GetDimensionDefinition(dimension_t type);
757                void             DeleteDimensionZone(dimension_t type, int zone);
758                void             SplitDimensionZone(dimension_t type, int zone);
759                void             SetDimensionType(dimension_t oldType, dimension_t newType);
760              // overridden methods              // overridden methods
761              virtual void     SetKeyRange(uint16_t Low, uint16_t High);              virtual void     SetKeyRange(uint16_t Low, uint16_t High);
762              virtual void     UpdateChunks();              virtual void     UpdateChunks(progress_t* pProgress);
763                virtual void     CopyAssign(const Region* orig);
764          protected:          protected:
765              Region(Instrument* pInstrument, RIFF::List* rgnList);              Region(Instrument* pInstrument, RIFF::List* rgnList);
766              void LoadDimensionRegions(RIFF::List* rgn);              void LoadDimensionRegions(RIFF::List* rgn);
767              void UpdateVelocityTable();              void UpdateVelocityTable();
768              Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress = NULL);              Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress = NULL);
769                void CopyAssign(const Region* orig, const std::map<Sample*,Sample*>* mSamples);
770                DimensionRegion* GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase);
771             ~Region();             ~Region();
772              friend class Instrument;              friend class Instrument;
773      };      };
774    
775      /** Provides all neccessary information for the synthesis of an <i>Instrument</i>. */      /** @brief Abstract base class for all MIDI rules.
776         *
777         * Note: Instead of using MIDI rules, we recommend you using real-time
778         * instrument scripts instead. Read about the reasons below.
779         *
780         * MIDI Rules (also called "iMIDI rules" or "intelligent MIDI rules") were
781         * introduced with GigaStudio 4 as an attempt to increase the power of
782         * potential user controls over sounds. At that point other samplers already
783         * supported certain powerful user control features, which were not possible
784         * with GigaStudio yet. For example triggering new notes by MIDI CC
785         * controller.
786         *
787         * Such extended features however were usually implemented by other samplers
788         * by requiring the sound designer to write an instrument script which the
789         * designer would then bundle with the respective instrument file. Such
790         * scripts are essentially text files, using a very specific programming
791         * language for the purpose of controlling the sampler in real-time. Since
792         * however musicians are not typically keen to writing such cumbersome
793         * script files, the GigaStudio designers decided to implement such extended
794         * features completely without instrument scripts. Instead they created a
795         * set of rules, which could be defined and altered conveniently by mouse
796         * clicks in GSt's instrument editor application. The downside of this
797         * overall approach however, was that those MIDI rules were very limited in
798         * practice. As sound designer you easily came across the possiblities such
799         * MIDI rules were able to offer.
800         *
801         * Due to such severe use case constraints, support for MIDI rules is quite
802         * limited in libgig. At the moment only the "Control Trigger", "Alternator"
803         * and the "Legato" MIDI rules are supported by libgig. Consequently the
804         * graphical instrument editor application gigedit just supports the
805         * "Control Trigger" and "Legato" MIDI rules, and LinuxSampler even does not
806         * support any MIDI rule type at all and LinuxSampler probably will not
807         * support MIDI rules in future either.
808         *
809         * Instead of using MIDI rules, we introduced real-time instrument scripts
810         * as extension to the original GigaStudio file format. This script based
811         * solution is much more powerful than MIDI rules and is already supported
812         * by libgig, gigedit and LinuxSampler.
813         *
814         * @deprecated Just provided for backward compatiblity, use Script for new
815         *             instruments instead.
816         */
817        class MidiRule {
818            public:
819                virtual ~MidiRule() { }
820            protected:
821                virtual void UpdateChunks(uint8_t* pData) const = 0;
822                friend class Instrument;
823        };
824    
825        /** @brief MIDI rule for triggering notes by control change events.
826         *
827         * A "Control Trigger MIDI rule" allows to trigger new notes by sending MIDI
828         * control change events to the sampler.
829         *
830         * Note: "Control Trigger" MIDI rules are only supported by gigedit, but not
831         * by LinuxSampler. We recommend you using real-time instrument scripts
832         * instead. Read more about the details and reasons for this in the
833         * description of the MidiRule base class.
834         *
835         * @deprecated Just provided for backward compatiblity, use Script for new
836         *             instruments instead. See description of MidiRule for details.
837         */
838        class MidiRuleCtrlTrigger : public MidiRule {
839            public:
840                uint8_t ControllerNumber;   ///< MIDI controller number.
841                uint8_t Triggers;           ///< Number of triggers.
842                struct trigger_t {
843                    uint8_t TriggerPoint;   ///< The CC value to pass for the note to be triggered.
844                    bool    Descending;     ///< If the change in CC value should be downwards.
845                    uint8_t VelSensitivity; ///< How sensitive the velocity should be to the speed of the controller change.
846                    uint8_t Key;            ///< Key to trigger.
847                    bool    NoteOff;        ///< If a note off should be triggered instead of a note on.
848                    uint8_t Velocity;       ///< Velocity of the note to trigger. 255 means that velocity should depend on the speed of the controller change.
849                    bool    OverridePedal;  ///< If a note off should be triggered even if the sustain pedal is down.
850                } pTriggers[32];
851    
852            protected:
853                MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg);
854                MidiRuleCtrlTrigger();
855                void UpdateChunks(uint8_t* pData) const;
856                friend class Instrument;
857        };
858    
859        /** @brief MIDI rule for instruments with legato samples.
860         *
861         * A "Legato MIDI rule" allows playing instruments resembling the legato
862         * playing technique. In the past such legato articulations were tried to be
863         * simulated by pitching the samples of the instrument. However since
864         * usually a high amount of pitch is needed for legatos, this always sounded
865         * very artificial and unrealistic. The "Legato MIDI rule" thus uses another
866         * approach. Instead of pitching the samples, it allows the sound designer
867         * to bundle separate, additional samples for the individual legato
868         * situations and the legato rules defined which samples to be played in
869         * which situation.
870         *
871         * Note: "Legato MIDI rules" are only supported by gigedit, but not
872         * by LinuxSampler. We recommend you using real-time instrument scripts
873         * instead. Read more about the details and reasons for this in the
874         * description of the MidiRule base class.
875         *
876         * @deprecated Just provided for backward compatiblity, use Script for new
877         *             instruments instead. See description of MidiRule for details.
878         */
879        class MidiRuleLegato : public MidiRule {
880            public:
881                uint8_t LegatoSamples;     ///< Number of legato samples per key in each direction (always 12)
882                bool BypassUseController;  ///< If a controller should be used to bypass the sustain note
883                uint8_t BypassKey;         ///< Key to be used to bypass the sustain note
884                uint8_t BypassController;  ///< Controller to be used to bypass the sustain note
885                uint16_t ThresholdTime;    ///< Maximum time (ms) between two notes that should be played legato
886                uint16_t ReleaseTime;      ///< Release time
887                range_t KeyRange;          ///< Key range for legato notes
888                uint8_t ReleaseTriggerKey; ///< Key triggering release samples
889                uint8_t AltSustain1Key;    ///< Key triggering alternate sustain samples
890                uint8_t AltSustain2Key;    ///< Key triggering a second set of alternate sustain samples
891    
892            protected:
893                MidiRuleLegato(RIFF::Chunk* _3ewg);
894                MidiRuleLegato();
895                void UpdateChunks(uint8_t* pData) const;
896                friend class Instrument;
897        };
898    
899        /** @brief MIDI rule to automatically cycle through specified sequences of different articulations.
900         *
901         * The instrument must be using the smartmidi dimension.
902         *
903         * Note: "Alternator" MIDI rules are neither supported by gigedit nor by
904         * LinuxSampler. We recommend you using real-time instrument scripts
905         * instead. Read more about the details and reasons for this in the
906         * description of the MidiRule base class.
907         *
908         * @deprecated Just provided for backward compatiblity, use Script for new
909         *             instruments instead. See description of MidiRule for details.
910         */
911        class MidiRuleAlternator : public MidiRule {
912            public:
913                uint8_t Articulations;     ///< Number of articulations in the instrument
914                String pArticulations[32]; ///< Names of the articulations
915    
916                range_t PlayRange;         ///< Key range of the playable keys in the instrument
917    
918                uint8_t Patterns;          ///< Number of alternator patterns
919                struct pattern_t {
920                    String Name;           ///< Name of the pattern
921                    int Size;              ///< Number of steps in the pattern
922                    const uint8_t& operator[](int i) const { /// Articulation to play
923                        return data[i];
924                    }
925                    uint8_t& operator[](int i) {
926                        return data[i];
927                    }
928                private:
929                    uint8_t data[32];
930                } pPatterns[32];           ///< A pattern is a sequence of articulation numbers
931    
932                typedef enum {
933                    selector_none,
934                    selector_key_switch,
935                    selector_controller
936                } selector_t;
937                selector_t Selector;       ///< Method by which pattern is chosen
938                range_t KeySwitchRange;    ///< Key range for key switch selector
939                uint8_t Controller;        ///< CC number for controller selector
940    
941                bool Polyphonic;           ///< If alternator should step forward only when all notes are off
942                bool Chained;              ///< If all patterns should be chained together
943    
944            protected:
945                MidiRuleAlternator(RIFF::Chunk* _3ewg);
946                MidiRuleAlternator();
947                void UpdateChunks(uint8_t* pData) const;
948                friend class Instrument;
949        };
950    
951        /** @brief A MIDI rule not yet implemented by libgig.
952         *
953         * This class is currently used as a place holder by libgig for MIDI rule
954         * types which are not supported by libgig yet.
955         *
956         * Note: Support for missing MIDI rule types are probably never added to
957         * libgig. We recommend you using real-time instrument scripts instead.
958         * Read more about the details and reasons for this in the description of
959         * the MidiRule base class.
960         *
961         * @deprecated Just provided for backward compatiblity, use Script for new
962         *             instruments instead. See description of MidiRule for details.
963         */
964        class MidiRuleUnknown : public MidiRule {
965            protected:
966                MidiRuleUnknown() { }
967                void UpdateChunks(uint8_t* pData) const { }
968                friend class Instrument;
969        };
970    
971        /** @brief Real-time instrument script (gig format extension).
972         *
973         * Real-time instrument scripts are user supplied small programs which can
974         * be used by instrument designers to create custom behaviors and features
975         * not available in the stock sampler engine. Features which might be very
976         * exotic or specific for the respective instrument.
977         *
978         * This is an extension of the GigaStudio format, thus a feature which was
979         * not available in the GigaStudio 4 software. It is currently only
980         * supported by LinuxSampler and gigedit. Scripts will not load with the
981         * original GigaStudio software.
982         */
983        class Script {
984            public:
985                enum Encoding_t {
986                    ENCODING_ASCII = 0 ///< Standard 8 bit US ASCII character encoding (default).
987                };
988                enum Compression_t {
989                    COMPRESSION_NONE = 0 ///< Is not compressed at all (default).
990                };
991                enum Language_t {
992                    LANGUAGE_NKSP = 0 ///< NKSP stands for "Is Not KSP" (default).
993                };
994    
995                String         Name;        ///< Arbitrary name of the script, which may be displayed i.e. in an instrument editor.
996                Compression_t  Compression; ///< Whether the script was/should be compressed, and if so, which compression algorithm shall be used.
997                Encoding_t     Encoding;    ///< Format the script's source code text is encoded with.
998                Language_t     Language;    ///< Programming language and dialect the script is written in.
999                bool           Bypass;      ///< Global bypass: if enabled, this script shall not be executed by the sampler for any instrument.
1000    
1001                String GetScriptAsText();
1002                void   SetScriptAsText(const String& text);
1003                void   SetGroup(ScriptGroup* pGroup);
1004                ScriptGroup* GetGroup() const;
1005            protected:
1006                Script(ScriptGroup* group, RIFF::Chunk* ckScri);
1007                virtual ~Script();
1008                void UpdateChunks(progress_t* pProgress);
1009                void RemoveAllScriptReferences();
1010                friend class ScriptGroup;
1011                friend class Instrument;
1012            private:
1013                ScriptGroup*          pGroup;
1014                RIFF::Chunk*          pChunk; ///< 'Scri' chunk
1015                std::vector<uint8_t>  data;
1016                uint32_t              crc; ///< CRC-32 checksum of the raw script data
1017        };
1018    
1019        /** @brief Group of instrument scripts (gig format extension).
1020         *
1021         * This class is simply used to sort a bunch of real-time instrument scripts
1022         * into individual groups. This allows instrument designers and script
1023         * developers to keep scripts in a certain order while working with a larger
1024         * amount of scripts in an instrument editor.
1025         *
1026         * This is an extension of the GigaStudio format, thus a feature which was
1027         * not available in the GigaStudio 4 software. It is currently only
1028         * supported by LinuxSampler and gigedit.
1029         */
1030        class ScriptGroup {
1031            public:
1032                String   Name; ///< Name of this script group. For example to be displayed in an instrument editor.
1033    
1034                Script*  GetScript(uint index);
1035                Script*  AddScript();
1036                void     DeleteScript(Script* pScript);
1037            protected:
1038                ScriptGroup(File* file, RIFF::List* lstRTIS);
1039                virtual ~ScriptGroup();
1040                void LoadScripts();
1041                void UpdateChunks(progress_t* pProgress);
1042                friend class Script;
1043                friend class File;
1044            private:
1045                File*                pFile;
1046                RIFF::List*          pList; ///< 'RTIS' list chunk
1047                std::list<Script*>*  pScripts;
1048        };
1049    
1050        /** @brief Provides access to a Gigasampler/GigaStudio instrument.
1051         *
1052         * This class provides access to Gigasampler/GigaStudio instruments
1053         * contained in .gig files. A gig instrument is merely a set of keyboard
1054         * ranges (called Region), plus some additional global informations about
1055         * the instrument. The major part of the actual instrument definition used
1056         * for the synthesis of the instrument is contained in the respective Region
1057         * object (or actually in the respective DimensionRegion object being, see
1058         * description of Region for details).
1059         *
1060         * Since the gig format was designed as extension to the DLS file format,
1061         * this class is derived from the DLS::Instrument class. So also refer to
1062         * DLS::Instrument for additional informations, class attributes and
1063         * methods.
1064         */
1065      class Instrument : protected DLS::Instrument {      class Instrument : protected DLS::Instrument {
1066          public:          public:
1067              // derived attributes from DLS::Resource              // derived attributes from DLS::Resource
1068              DLS::Resource::pInfo;              using DLS::Resource::pInfo;
1069              DLS::Resource::pDLSID;              using DLS::Resource::pDLSID;
1070              // derived attributes from DLS::Instrument              // derived attributes from DLS::Instrument
1071              DLS::Instrument::IsDrum;              using DLS::Instrument::IsDrum;
1072              DLS::Instrument::MIDIBank;              using DLS::Instrument::MIDIBank;
1073              DLS::Instrument::MIDIBankCoarse;              using DLS::Instrument::MIDIBankCoarse;
1074              DLS::Instrument::MIDIBankFine;              using DLS::Instrument::MIDIBankFine;
1075              DLS::Instrument::MIDIProgram;              using DLS::Instrument::MIDIProgram;
1076              DLS::Instrument::Regions;              using DLS::Instrument::Regions;
1077              // own attributes              // own attributes
1078              int32_t   Attenuation;       ///< in dB              int32_t   Attenuation;       ///< in dB
1079              uint16_t  EffectSend;              uint16_t  EffectSend;
# Line 679  namespace gig { Line 1084  namespace gig {
1084    
1085    
1086              // derived methods from DLS::Resource              // derived methods from DLS::Resource
1087              DLS::Resource::GetParent;              using DLS::Resource::GetParent;
1088              // overridden methods              // overridden methods
1089              Region*   GetFirstRegion();              Region*   GetFirstRegion();
1090              Region*   GetNextRegion();              Region*   GetNextRegion();
1091              Region*   AddRegion();              Region*   AddRegion();
1092              void      DeleteRegion(Region* pRegion);              void      DeleteRegion(Region* pRegion);
1093              virtual void UpdateChunks();              virtual void UpdateChunks(progress_t* pProgress);
1094                virtual void CopyAssign(const Instrument* orig);
1095              // own methods              // own methods
1096              Region*   GetRegion(unsigned int Key);              Region*   GetRegion(unsigned int Key);
1097                MidiRule* GetMidiRule(int i);
1098                MidiRuleCtrlTrigger* AddMidiRuleCtrlTrigger();
1099                MidiRuleLegato*      AddMidiRuleLegato();
1100                MidiRuleAlternator*  AddMidiRuleAlternator();
1101                void      DeleteMidiRule(int i);
1102                // real-time instrument script methods
1103                Script*   GetScriptOfSlot(uint index);
1104                void      AddScriptSlot(Script* pScript, bool bypass = false);
1105                void      SwapScriptSlots(uint index1, uint index2);
1106                void      RemoveScriptSlot(uint index);
1107                void      RemoveScript(Script* pScript);
1108                uint      ScriptSlotCount() const;
1109                bool      IsScriptSlotBypassed(uint index);
1110                void      SetScriptSlotBypassed(uint index, bool bBypass);
1111          protected:          protected:
1112              Region*   RegionKeyTable[128]; ///< fast lookup for the corresponding Region of a MIDI key              Region*   RegionKeyTable[128]; ///< fast lookup for the corresponding Region of a MIDI key
1113    
1114              Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress = NULL);              Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress = NULL);
1115             ~Instrument();             ~Instrument();
1116                void CopyAssign(const Instrument* orig, const std::map<Sample*,Sample*>* mSamples);
1117              void UpdateRegionKeyTable();              void UpdateRegionKeyTable();
1118                void LoadScripts();
1119                void UpdateScriptFileOffsets();
1120              friend class File;              friend class File;
1121              friend class Region; // so Region can call UpdateRegionKeyTable()              friend class Region; // so Region can call UpdateRegionKeyTable()
1122            private:
1123                struct _ScriptPooolEntry {
1124                    uint32_t fileOffset;
1125                    bool     bypass;
1126                };
1127                struct _ScriptPooolRef {
1128                    Script*  script;
1129                    bool     bypass;
1130                };
1131                MidiRule** pMidiRules;
1132                std::vector<_ScriptPooolEntry> scriptPoolFileOffsets;
1133                std::vector<_ScriptPooolRef>* pScriptRefs;
1134      };      };
1135    
1136      /** @brief Group of Gigasampler objects      /** @brief Group of Gigasampler samples
1137       *       *
1138       * Groups help to organize a huge collection of Gigasampler objects.       * Groups help to organize a huge collection of Gigasampler samples.
1139       * Groups are not concerned at all for the synthesis, but they help       * Groups are not concerned at all for the synthesis, but they help
1140       * sound library developers when working on complex instruments with an       * sound library developers when working on complex instruments with an
1141       * instrument editor (as long as that instrument editor supports it ;-).       * instrument editor (as long as that instrument editor supports it ;-).
1142       *       *
      * At the moment, it seems as only samples can be grouped together in  
      * the Gigasampler format yet. If this is false in the meantime, please  
      * tell us !  
      *  
1143       * A sample is always assigned to exactly one Group. This also means       * A sample is always assigned to exactly one Group. This also means
1144       * there is always at least one Group in a .gig file, no matter if you       * there is always at least one Group in a .gig file, no matter if you
1145       * created one yet or not.       * created one yet or not.
# Line 723  namespace gig { Line 1154  namespace gig {
1154          protected:          protected:
1155              Group(File* file, RIFF::Chunk* ck3gnm);              Group(File* file, RIFF::Chunk* ck3gnm);
1156              virtual ~Group();              virtual ~Group();
1157              virtual void UpdateChunks();              virtual void UpdateChunks(progress_t* pProgress);
1158              void MoveAll();              void MoveAll();
1159              friend class File;              friend class File;
1160          private:          private:
1161              File*        pFile;              File*        pFile;
1162              RIFF::Chunk* pNameChunk;              RIFF::Chunk* pNameChunk; ///< '3gnm' chunk
1163      };      };
1164    
1165      /** Parses Gigasampler files and provides abstract access to the data. */      /** @brief Provides convenient access to Gigasampler/GigaStudio .gig files.
1166         *
1167         * This is the entry class for accesing a Gigasampler/GigaStudio (.gig) file
1168         * with libgig. It allows you to open existing .gig files, modifying them
1169         * and saving them persistently either under the same file name or under a
1170         * different location.
1171         *
1172         * A .gig file is merely a monolithic file. That means samples and the
1173         * defintion of the virtual instruments are contained in the same file. A
1174         * .gig file contains an arbitrary amount of samples, and an arbitrary
1175         * amount of instruments which are referencing those samples. It is also
1176         * possible to store samples in .gig files not being referenced by any
1177         * instrument. This is not an error from the file format's point of view and
1178         * it is actually often used in practice during the design phase of new gig
1179         * instruments.
1180         *
1181         * So on toplevel of the gig file format you have:
1182         *
1183         * - A set of samples (see Sample).
1184         * - A set of virtual instruments (see Instrument).
1185         *
1186         * And as extension to the original GigaStudio format, we added:
1187         *
1188         * - Real-time instrument scripts (see Script).
1189         *
1190         * Note that the latter however is only supported by libgig, gigedit and
1191         * LinuxSampler. Scripts are not supported by the original GigaStudio
1192         * software.
1193         *
1194         * All released Gigasampler/GigaStudio file format versions are supported
1195         * (so from first Gigasampler version up to including GigaStudio 4).
1196         *
1197         * Since the gig format was designed as extension to the DLS file format,
1198         * this class is derived from the DLS::File class. So also refer to
1199         * DLS::File for additional informations, class attributes and methods.
1200         */
1201      class File : protected DLS::File {      class File : protected DLS::File {
1202          public:          public:
1203              static const DLS::version_t VERSION_2;              static const DLS::version_t VERSION_2;
1204              static const DLS::version_t VERSION_3;              static const DLS::version_t VERSION_3;
1205    
1206              // derived attributes from DLS::Resource              // derived attributes from DLS::Resource
1207              DLS::Resource::pInfo;              using DLS::Resource::pInfo;
1208              DLS::Resource::pDLSID;              using DLS::Resource::pDLSID;
1209              // derived attributes from DLS::File              // derived attributes from DLS::File
1210              DLS::File::pVersion;              using DLS::File::pVersion;
1211              DLS::File::Instruments;              using DLS::File::Instruments;
1212    
1213              // derived methods from DLS::Resource              // derived methods from DLS::Resource
1214              DLS::Resource::GetParent;              using DLS::Resource::GetParent;
1215              // derived methods from DLS::File              // derived methods from DLS::File
1216              DLS::File::Save;              using DLS::File::Save;
1217                using DLS::File::GetFileName;
1218                using DLS::File::SetFileName;
1219              // overridden  methods              // overridden  methods
1220              File();              File();
1221              File(RIFF::File* pRIFF);              File(RIFF::File* pRIFF);
1222              Sample*     GetFirstSample(progress_t* pProgress = NULL); ///< Returns a pointer to the first <i>Sample</i> object of the file, <i>NULL</i> otherwise.              Sample*     GetFirstSample(progress_t* pProgress = NULL); ///< Returns a pointer to the first <i>Sample</i> object of the file, <i>NULL</i> otherwise.
1223              Sample*     GetNextSample();      ///< Returns a pointer to the next <i>Sample</i> object of the file, <i>NULL</i> otherwise.              Sample*     GetNextSample();      ///< Returns a pointer to the next <i>Sample</i> object of the file, <i>NULL</i> otherwise.
1224                Sample*     GetSample(uint index);
1225              Sample*     AddSample();              Sample*     AddSample();
1226              void        DeleteSample(Sample* pSample);              void        DeleteSample(Sample* pSample);
1227              Instrument* GetFirstInstrument(); ///< Returns a pointer to the first <i>Instrument</i> object of the file, <i>NULL</i> otherwise.              Instrument* GetFirstInstrument(); ///< Returns a pointer to the first <i>Instrument</i> object of the file, <i>NULL</i> otherwise.
1228              Instrument* GetNextInstrument();  ///< Returns a pointer to the next <i>Instrument</i> object of the file, <i>NULL</i> otherwise.              Instrument* GetNextInstrument();  ///< Returns a pointer to the next <i>Instrument</i> object of the file, <i>NULL</i> otherwise.
1229              Instrument* GetInstrument(uint index, progress_t* pProgress = NULL);              Instrument* GetInstrument(uint index, progress_t* pProgress = NULL);
1230              Instrument* AddInstrument();              Instrument* AddInstrument();
1231                Instrument* AddDuplicateInstrument(const Instrument* orig);
1232              void        DeleteInstrument(Instrument* pInstrument);              void        DeleteInstrument(Instrument* pInstrument);
1233              Group*      GetFirstGroup(); ///< Returns a pointer to the first <i>Group</i> object of the file, <i>NULL</i> otherwise.              Group*      GetFirstGroup(); ///< Returns a pointer to the first <i>Group</i> object of the file, <i>NULL</i> otherwise.
1234              Group*      GetNextGroup();  ///< Returns a pointer to the next <i>Group</i> object of the file, <i>NULL</i> otherwise.              Group*      GetNextGroup();  ///< Returns a pointer to the next <i>Group</i> object of the file, <i>NULL</i> otherwise.
1235              Group*      GetGroup(uint index);              Group*      GetGroup(uint index);
1236                Group*      GetGroup(String name);
1237              Group*      AddGroup();              Group*      AddGroup();
1238              void        DeleteGroup(Group* pGroup);              void        DeleteGroup(Group* pGroup);
1239              void        DeleteGroupOnly(Group* pGroup);              void        DeleteGroupOnly(Group* pGroup);
1240                void        SetAutoLoad(bool b);
1241                bool        GetAutoLoad();
1242                void        AddContentOf(File* pFile);
1243                ScriptGroup* GetScriptGroup(uint index);
1244                ScriptGroup* GetScriptGroup(const String& name);
1245                ScriptGroup* AddScriptGroup();
1246                void        DeleteScriptGroup(ScriptGroup* pGroup);
1247              virtual    ~File();              virtual    ~File();
1248              virtual void UpdateChunks();              virtual void UpdateChunks(progress_t* pProgress);
1249          protected:          protected:
1250              // overridden protected methods from DLS::File              // overridden protected methods from DLS::File
1251              virtual void LoadSamples();              virtual void LoadSamples();
1252              virtual void LoadInstruments();              virtual void LoadInstruments();
1253              virtual void LoadGroups();              virtual void LoadGroups();
1254                virtual void UpdateFileOffsets();
1255              // own protected methods              // own protected methods
1256              virtual void LoadSamples(progress_t* pProgress);              virtual void LoadSamples(progress_t* pProgress);
1257              virtual void LoadInstruments(progress_t* pProgress);              virtual void LoadInstruments(progress_t* pProgress);
1258                virtual void LoadScriptGroups();
1259              void SetSampleChecksum(Sample* pSample, uint32_t crc);              void SetSampleChecksum(Sample* pSample, uint32_t crc);
1260              friend class Region;              friend class Region;
1261              friend class Sample;              friend class Sample;
1262              friend class Group; // so Group can access protected member pRIFF              friend class Group; // so Group can access protected member pRIFF
1263                friend class ScriptGroup; // so ScriptGroup can access protected member pRIFF
1264          private:          private:
             static const DLS::Info::FixedStringLength FixedStringLengths[];  
1265              std::list<Group*>*          pGroups;              std::list<Group*>*          pGroups;
1266              std::list<Group*>::iterator GroupsIterator;              std::list<Group*>::iterator GroupsIterator;
1267                bool                        bAutoLoad;
1268                std::list<ScriptGroup*>*    pScriptGroups;
1269      };      };
1270    
1271      /**      /**

Legend:
Removed from v.1335  
changed lines
  Added in v.2699

  ViewVC Help
Powered by ViewVC