libgig  4.1.0.svn8
gig.h
1 /***************************************************************************
2  * *
3  * libgig - C++ cross-platform Gigasampler format file access library *
4  * *
5  * Copyright (C) 2003-2018 by Christian Schoenebeck *
6  * <cuse@users.sourceforge.net> *
7  * *
8  * This library is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  ***************************************************************************/
23 
24 #ifndef __GIG_H__
25 #define __GIG_H__
26 
27 #include "DLS.h"
28 #include <vector>
29 
30 #ifndef __has_feature
31 # define __has_feature(x) 0
32 #endif
33 #ifndef HAVE_RTTI
34 # if __GXX_RTTI || __has_feature(cxx_rtti) || _CPPRTTI
35 # define HAVE_RTTI 1
36 # else
37 # define HAVE_RTTI 0
38 # endif
39 #endif
40 #if HAVE_RTTI
41 # include <typeinfo>
42 #else
43 # warning No RTTI available!
44 #endif
45 
46 #if WORDS_BIGENDIAN
47 # define LIST_TYPE_3PRG 0x33707267
48 # define LIST_TYPE_3EWL 0x3365776C
49 # define LIST_TYPE_3GRI 0x33677269
50 # define LIST_TYPE_3GNL 0x33676E6C
51 # define LIST_TYPE_3LS 0x334c5320 // own gig format extension
52 # define LIST_TYPE_RTIS 0x52544953 // own gig format extension
53 # define CHUNK_ID_3GIX 0x33676978
54 # define CHUNK_ID_3EWA 0x33657761
55 # define CHUNK_ID_3LNK 0x336C6E6B
56 # define CHUNK_ID_3EWG 0x33657767
57 # define CHUNK_ID_EWAV 0x65776176
58 # define CHUNK_ID_3GNM 0x33676E6D
59 # define CHUNK_ID_EINF 0x65696E66
60 # define CHUNK_ID_3CRC 0x33637263
61 # define CHUNK_ID_SCRI 0x53637269 // own gig format extension
62 # define CHUNK_ID_LSNM 0x4c534e4d // own gig format extension
63 # define CHUNK_ID_SCSL 0x5343534c // own gig format extension
64 # define CHUNK_ID_LSDE 0x4c534445 // own gig format extension
65 #else // little endian
66 # define LIST_TYPE_3PRG 0x67727033
67 # define LIST_TYPE_3EWL 0x6C776533
68 # define LIST_TYPE_3GRI 0x69726733
69 # define LIST_TYPE_3GNL 0x6C6E6733
70 # define LIST_TYPE_3LS 0x20534c33 // own gig format extension
71 # define LIST_TYPE_RTIS 0x53495452 // own gig format extension
72 # define CHUNK_ID_3GIX 0x78696733
73 # define CHUNK_ID_3EWA 0x61776533
74 # define CHUNK_ID_3LNK 0x6B6E6C33
75 # define CHUNK_ID_3EWG 0x67776533
76 # define CHUNK_ID_EWAV 0x76617765
77 # define CHUNK_ID_3GNM 0x6D6E6733
78 # define CHUNK_ID_EINF 0x666E6965
79 # define CHUNK_ID_3CRC 0x63726333
80 # define CHUNK_ID_SCRI 0x69726353 // own gig format extension
81 # define CHUNK_ID_LSNM 0x4d4e534c // own gig format extension
82 # define CHUNK_ID_SCSL 0x4c534353 // own gig format extension
83 # define CHUNK_ID_LSDE 0x4544534c // own gig format extension
84 #endif // WORDS_BIGENDIAN
85 
86 #ifndef GIG_DECLARE_ENUM
87 # define GIG_DECLARE_ENUM(type, ...) enum type { __VA_ARGS__ }
88 #endif
89 
90 // just symbol prototyping (since Serialization.h not included by default here)
91 namespace Serialization { class Archive; }
92 
94 namespace gig {
95 
96  typedef std::string String;
97  typedef RIFF::progress_t progress_t;
98  typedef RIFF::file_offset_t file_offset_t;
99 
101  struct range_t {
102  uint8_t low;
103  uint8_t high;
104  };
105 
107  struct buffer_t {
108  void* pStart;
109  file_offset_t Size;
110  file_offset_t NullExtensionSize;
111  buffer_t() {
112  pStart = NULL;
113  Size = 0;
114  NullExtensionSize = 0;
115  }
116  };
117 
122  GIG_DECLARE_ENUM(loop_type_t,
123  loop_type_normal = 0x00000000,
124  loop_type_bidirectional = 0x00000001,
125  loop_type_backward = 0x00000002
126  );
127 
132  GIG_DECLARE_ENUM(smpte_format_t,
133  smpte_format_no_offset = 0x00000000,
134  smpte_format_24_frames = 0x00000018,
135  smpte_format_25_frames = 0x00000019,
136  smpte_format_30_frames_dropping = 0x0000001D,
137  smpte_format_30_frames = 0x0000001E
138  );
139 
144  GIG_DECLARE_ENUM(curve_type_t,
145  curve_type_nonlinear = 0,
146  curve_type_linear = 1,
147  curve_type_special = 2,
148  curve_type_unknown = 0xffffffff
149  );
150 
155  GIG_DECLARE_ENUM(dim_bypass_ctrl_t,
156  dim_bypass_ctrl_none,
157  dim_bypass_ctrl_94,
158  dim_bypass_ctrl_95
159  );
160 
165  GIG_DECLARE_ENUM(lfo3_ctrl_t,
166  lfo3_ctrl_internal = 0x00,
167  lfo3_ctrl_modwheel = 0x01,
168  lfo3_ctrl_aftertouch = 0x02,
169  lfo3_ctrl_internal_modwheel = 0x03,
170  lfo3_ctrl_internal_aftertouch = 0x04
171  );
172 
177  GIG_DECLARE_ENUM(lfo2_ctrl_t,
178  lfo2_ctrl_internal = 0x00,
179  lfo2_ctrl_modwheel = 0x01,
180  lfo2_ctrl_foot = 0x02,
181  lfo2_ctrl_internal_modwheel = 0x03,
182  lfo2_ctrl_internal_foot = 0x04
183  );
184 
189  GIG_DECLARE_ENUM(lfo1_ctrl_t,
190  lfo1_ctrl_internal = 0x00,
191  lfo1_ctrl_modwheel = 0x01,
192  lfo1_ctrl_breath = 0x02,
193  lfo1_ctrl_internal_modwheel = 0x03,
194  lfo1_ctrl_internal_breath = 0x04
195  );
196 
201  GIG_DECLARE_ENUM(vcf_cutoff_ctrl_t,
202  vcf_cutoff_ctrl_none = 0x00,
203  vcf_cutoff_ctrl_none2 = 0x01,
204  vcf_cutoff_ctrl_modwheel = 0x81,
205  vcf_cutoff_ctrl_effect1 = 0x8c,
206  vcf_cutoff_ctrl_effect2 = 0x8d,
207  vcf_cutoff_ctrl_breath = 0x82,
208  vcf_cutoff_ctrl_foot = 0x84,
209  vcf_cutoff_ctrl_sustainpedal = 0xc0,
210  vcf_cutoff_ctrl_softpedal = 0xc3,
211  vcf_cutoff_ctrl_genpurpose7 = 0xd2,
212  vcf_cutoff_ctrl_genpurpose8 = 0xd3,
213  vcf_cutoff_ctrl_aftertouch = 0x80
214  );
215 
220  GIG_DECLARE_ENUM(vcf_res_ctrl_t,
221  vcf_res_ctrl_none = 0xffffffff,
222  vcf_res_ctrl_genpurpose3 = 0,
223  vcf_res_ctrl_genpurpose4 = 1,
224  vcf_res_ctrl_genpurpose5 = 2,
225  vcf_res_ctrl_genpurpose6 = 3
226  );
227 
236  struct leverage_ctrl_t {
241  GIG_DECLARE_ENUM(type_t,
242  type_none = 0x00,
243  type_channelaftertouch = 0x2f,
244  type_velocity = 0xff,
245  type_controlchange = 0xfe
246  );
247 
248  type_t type;
249  uint controller_number;
250 
251  void serialize(Serialization::Archive* archive);
252  };
253 
259  typedef leverage_ctrl_t attenuation_ctrl_t;
260 
266  typedef leverage_ctrl_t eg1_ctrl_t;
267 
273  typedef leverage_ctrl_t eg2_ctrl_t;
274 
284  GIG_DECLARE_ENUM(dimension_t,
285  dimension_none = 0x00,
286  dimension_samplechannel = 0x80,
287  dimension_layer = 0x81,
288  dimension_velocity = 0x82,
289  dimension_channelaftertouch = 0x83,
290  dimension_releasetrigger = 0x84,
291  dimension_keyboard = 0x85,
292  dimension_roundrobin = 0x86,
293  dimension_random = 0x87,
294  dimension_smartmidi = 0x88,
295  dimension_roundrobinkeyboard = 0x89,
296  dimension_modwheel = 0x01,
297  dimension_breath = 0x02,
298  dimension_foot = 0x04,
299  dimension_portamentotime = 0x05,
300  dimension_effect1 = 0x0c,
301  dimension_effect2 = 0x0d,
302  dimension_genpurpose1 = 0x10,
303  dimension_genpurpose2 = 0x11,
304  dimension_genpurpose3 = 0x12,
305  dimension_genpurpose4 = 0x13,
306  dimension_sustainpedal = 0x40,
307  dimension_portamento = 0x41,
308  dimension_sostenutopedal = 0x42,
309  dimension_softpedal = 0x43,
310  dimension_genpurpose5 = 0x30,
311  dimension_genpurpose6 = 0x31,
312  dimension_genpurpose7 = 0x32,
313  dimension_genpurpose8 = 0x33,
314  dimension_effect1depth = 0x5b,
315  dimension_effect2depth = 0x5c,
316  dimension_effect3depth = 0x5d,
317  dimension_effect4depth = 0x5e,
318  dimension_effect5depth = 0x5f
319  );
320 
327  GIG_DECLARE_ENUM(split_type_t,
328  split_type_normal,
329  split_type_bit
330  );
331 
333  struct dimension_def_t {
334  dimension_t dimension;
335  uint8_t bits;
336  uint8_t zones;
337  split_type_t split_type;
338  float zone_size;
339  };
340 
345  GIG_DECLARE_ENUM(vcf_type_t,
346  vcf_type_lowpass = 0x00,
347  vcf_type_lowpassturbo = 0xff,
348  vcf_type_bandpass = 0x01,
349  vcf_type_highpass = 0x02,
350  vcf_type_bandreject = 0x03
351  );
352 
360  struct crossfade_t {
361  #if WORDS_BIGENDIAN
362  uint8_t out_end;
363  uint8_t out_start;
364  uint8_t in_end;
365  uint8_t in_start;
366  #else // little endian
367  uint8_t in_start;
368  uint8_t in_end;
369  uint8_t out_start;
370  uint8_t out_end;
371  #endif // WORDS_BIGENDIAN
372 
373  void serialize(Serialization::Archive* archive);
374  };
375 
377  struct playback_state_t {
378  file_offset_t position;
379  bool reverse;
380  file_offset_t loop_cycles_left;
381  };
382 
406  struct eg_opt_t {
407  bool AttackCancel;
408  bool AttackHoldCancel;
409  bool Decay1Cancel;
410  bool Decay2Cancel;
411  bool ReleaseCancel;
412 
413  eg_opt_t();
414  void serialize(Serialization::Archive* archive);
415  };
416 
433  GIG_DECLARE_ENUM(sust_rel_trg_t,
434  sust_rel_trg_none = 0x00,
435  sust_rel_trg_maxvelocity = 0x01,
436  sust_rel_trg_keyvelocity = 0x02
437  );
438 
439  // just symbol prototyping
440  class File;
441  class Instrument;
442  class Sample;
443  class Region;
444  class Group;
445  class Script;
446  class ScriptGroup;
447 
490  class DimensionRegion : protected DLS::Sampler {
491  public:
492  uint8_t VelocityUpperLimit;
493  Sample* pSample;
494  // Sample Amplitude EG/LFO
495  uint16_t EG1PreAttack;
496  double EG1Attack;
497  double EG1Decay1;
498  double EG1Decay2;
499  bool EG1InfiniteSustain;
500  uint16_t EG1Sustain;
501  double EG1Release;
502  bool EG1Hold;
503  eg1_ctrl_t EG1Controller;
504  bool EG1ControllerInvert;
505  uint8_t EG1ControllerAttackInfluence;
506  uint8_t EG1ControllerDecayInfluence;
507  uint8_t EG1ControllerReleaseInfluence;
508  double LFO1Frequency;
509  uint16_t LFO1InternalDepth;
510  uint16_t LFO1ControlDepth;
511  lfo1_ctrl_t LFO1Controller;
512  bool LFO1FlipPhase;
513  bool LFO1Sync;
514  // Filter Cutoff Frequency EG/LFO
515  uint16_t EG2PreAttack;
516  double EG2Attack;
517  double EG2Decay1;
518  double EG2Decay2;
519  bool EG2InfiniteSustain;
520  uint16_t EG2Sustain;
521  double EG2Release;
522  eg2_ctrl_t EG2Controller;
523  bool EG2ControllerInvert;
524  uint8_t EG2ControllerAttackInfluence;
525  uint8_t EG2ControllerDecayInfluence;
526  uint8_t EG2ControllerReleaseInfluence;
527  double LFO2Frequency;
528  uint16_t LFO2InternalDepth;
529  uint16_t LFO2ControlDepth;
530  lfo2_ctrl_t LFO2Controller;
531  bool LFO2FlipPhase;
532  bool LFO2Sync;
533  // Sample Pitch EG/LFO
534  double EG3Attack;
535  int16_t EG3Depth;
536  double LFO3Frequency;
537  int16_t LFO3InternalDepth;
538  int16_t LFO3ControlDepth;
539  lfo3_ctrl_t LFO3Controller;
540  bool LFO3Sync;
541  // Filter
542  bool VCFEnabled;
543  vcf_type_t VCFType;
544  vcf_cutoff_ctrl_t VCFCutoffController;
545  bool VCFCutoffControllerInvert;
546  uint8_t VCFCutoff;
547  curve_type_t VCFVelocityCurve;
548  uint8_t VCFVelocityScale;
549  uint8_t VCFVelocityDynamicRange;
550  uint8_t VCFResonance;
551  bool VCFResonanceDynamic;
552  vcf_res_ctrl_t VCFResonanceController;
553  bool VCFKeyboardTracking;
554  uint8_t VCFKeyboardTrackingBreakpoint;
555  // Key Velocity Transformations
556  curve_type_t VelocityResponseCurve;
557  uint8_t VelocityResponseDepth;
558  uint8_t VelocityResponseCurveScaling;
559  curve_type_t ReleaseVelocityResponseCurve;
560  uint8_t ReleaseVelocityResponseDepth;
561  uint8_t ReleaseTriggerDecay;
562  // Mix / Layer
563  crossfade_t Crossfade;
564  bool PitchTrack;
565  dim_bypass_ctrl_t DimensionBypass;
566  int8_t Pan;
567  bool SelfMask;
568  attenuation_ctrl_t AttenuationController;
569  bool InvertAttenuationController;
570  uint8_t AttenuationControllerThreshold;
571  uint8_t ChannelOffset;
572  bool SustainDefeat;
573  bool MSDecode;
574  uint16_t SampleStartOffset;
575  double SampleAttenuation;
576  uint8_t DimensionUpperLimits[8];
577  eg_opt_t EG1Options;
578  eg_opt_t EG2Options;
579  sust_rel_trg_t SustainReleaseTrigger;
580  bool NoNoteOffReleaseTrigger;
581 
582  // derived attributes from DLS::Sampler
583  using DLS::Sampler::UnityNote;
584  using DLS::Sampler::FineTune;
585  using DLS::Sampler::Gain;
588 
589  // own methods
590  double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);
591  double GetVelocityRelease(uint8_t MIDIKeyVelocity);
592  double GetVelocityCutoff(uint8_t MIDIKeyVelocity);
593  void SetVelocityResponseCurve(curve_type_t curve);
594  void SetVelocityResponseDepth(uint8_t depth);
595  void SetVelocityResponseCurveScaling(uint8_t scaling);
596  void SetReleaseVelocityResponseCurve(curve_type_t curve);
597  void SetReleaseVelocityResponseDepth(uint8_t depth);
598  void SetVCFCutoffController(vcf_cutoff_ctrl_t controller);
599  void SetVCFVelocityCurve(curve_type_t curve);
600  void SetVCFVelocityDynamicRange(uint8_t range);
601  void SetVCFVelocityScale(uint8_t scaling);
602  Region* GetParent() const;
603  // derived methods
606  // overridden methods
607  virtual void SetGain(int32_t gain);
608  virtual void UpdateChunks(progress_t* pProgress);
609  virtual void CopyAssign(const DimensionRegion* orig);
610  protected:
611  uint8_t* VelocityTable;
612  DimensionRegion(Region* pParent, RIFF::List* _3ewl);
613  DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);
614  ~DimensionRegion();
615  void CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples);
616  void serialize(Serialization::Archive* archive);
617  friend class Region;
618  friend class Serialization::Archive;
619  private:
620  typedef enum {
621  // official leverage controllers as they were defined in the original Gigasampler/GigaStudio format:
622  _lev_ctrl_none = 0x00,
623  _lev_ctrl_modwheel = 0x03,
624  _lev_ctrl_breath = 0x05,
625  _lev_ctrl_foot = 0x07,
626  _lev_ctrl_effect1 = 0x0d,
627  _lev_ctrl_effect2 = 0x0f,
628  _lev_ctrl_genpurpose1 = 0x11,
629  _lev_ctrl_genpurpose2 = 0x13,
630  _lev_ctrl_genpurpose3 = 0x15,
631  _lev_ctrl_genpurpose4 = 0x17,
632  _lev_ctrl_portamentotime = 0x0b,
633  _lev_ctrl_sustainpedal = 0x01,
634  _lev_ctrl_portamento = 0x19,
635  _lev_ctrl_sostenutopedal = 0x1b,
636  _lev_ctrl_softpedal = 0x09,
637  _lev_ctrl_genpurpose5 = 0x1d,
638  _lev_ctrl_genpurpose6 = 0x1f,
639  _lev_ctrl_genpurpose7 = 0x21,
640  _lev_ctrl_genpurpose8 = 0x23,
641  _lev_ctrl_effect1depth = 0x25,
642  _lev_ctrl_effect2depth = 0x27,
643  _lev_ctrl_effect3depth = 0x29,
644  _lev_ctrl_effect4depth = 0x2b,
645  _lev_ctrl_effect5depth = 0x2d,
646  _lev_ctrl_channelaftertouch = 0x2f,
647  _lev_ctrl_velocity = 0xff,
648 
649  // format extension (these controllers are so far only supported by LinuxSampler & gigedit) they will *NOT* work with Gigasampler/GigaStudio !
650  // (the assigned values here are their official MIDI CC number plus the highest bit set):
651  _lev_ctrl_CC3_EXT = 0x83,
652 
653  _lev_ctrl_CC6_EXT = 0x86,
654  _lev_ctrl_CC7_EXT = 0x87,
655  _lev_ctrl_CC8_EXT = 0x88,
656  _lev_ctrl_CC9_EXT = 0x89,
657  _lev_ctrl_CC10_EXT = 0x8a,
658  _lev_ctrl_CC11_EXT = 0x8b,
659 
660  _lev_ctrl_CC14_EXT = 0x8e,
661  _lev_ctrl_CC15_EXT = 0x8f,
662 
663  _lev_ctrl_CC20_EXT = 0x94,
664  _lev_ctrl_CC21_EXT = 0x95,
665  _lev_ctrl_CC22_EXT = 0x96,
666  _lev_ctrl_CC23_EXT = 0x97,
667  _lev_ctrl_CC24_EXT = 0x98,
668  _lev_ctrl_CC25_EXT = 0x99,
669  _lev_ctrl_CC26_EXT = 0x9a,
670  _lev_ctrl_CC27_EXT = 0x9b,
671  _lev_ctrl_CC28_EXT = 0x9c,
672  _lev_ctrl_CC29_EXT = 0x9d,
673  _lev_ctrl_CC30_EXT = 0x9e,
674  _lev_ctrl_CC31_EXT = 0x9f,
675 
676  _lev_ctrl_CC68_EXT = 0xc4,
677  _lev_ctrl_CC69_EXT = 0xc5,
678  _lev_ctrl_CC70_EXT = 0xc6,
679  _lev_ctrl_CC71_EXT = 0xc7,
680  _lev_ctrl_CC72_EXT = 0xc8,
681  _lev_ctrl_CC73_EXT = 0xc9,
682  _lev_ctrl_CC74_EXT = 0xca,
683  _lev_ctrl_CC75_EXT = 0xcb,
684  _lev_ctrl_CC76_EXT = 0xcc,
685  _lev_ctrl_CC77_EXT = 0xcd,
686  _lev_ctrl_CC78_EXT = 0xce,
687  _lev_ctrl_CC79_EXT = 0xcf,
688 
689  _lev_ctrl_CC84_EXT = 0xd4,
690  _lev_ctrl_CC85_EXT = 0xd5,
691  _lev_ctrl_CC86_EXT = 0xd6,
692  _lev_ctrl_CC87_EXT = 0xd7,
693 
694  _lev_ctrl_CC89_EXT = 0xd9,
695  _lev_ctrl_CC90_EXT = 0xda,
696 
697  _lev_ctrl_CC96_EXT = 0xe0,
698  _lev_ctrl_CC97_EXT = 0xe1,
699 
700  _lev_ctrl_CC102_EXT = 0xe6,
701  _lev_ctrl_CC103_EXT = 0xe7,
702  _lev_ctrl_CC104_EXT = 0xe8,
703  _lev_ctrl_CC105_EXT = 0xe9,
704  _lev_ctrl_CC106_EXT = 0xea,
705  _lev_ctrl_CC107_EXT = 0xeb,
706  _lev_ctrl_CC108_EXT = 0xec,
707  _lev_ctrl_CC109_EXT = 0xed,
708  _lev_ctrl_CC110_EXT = 0xee,
709  _lev_ctrl_CC111_EXT = 0xef,
710  _lev_ctrl_CC112_EXT = 0xf0,
711  _lev_ctrl_CC113_EXT = 0xf1,
712  _lev_ctrl_CC114_EXT = 0xf2,
713  _lev_ctrl_CC115_EXT = 0xf3,
714  _lev_ctrl_CC116_EXT = 0xf4,
715  _lev_ctrl_CC117_EXT = 0xf5,
716  _lev_ctrl_CC118_EXT = 0xf6,
717  _lev_ctrl_CC119_EXT = 0xf7
718  } _lev_ctrl_t;
719  typedef std::map<uint32_t, double*> VelocityTableMap;
720 
721  static size_t Instances;
722  static VelocityTableMap* pVelocityTables;
723  double* pVelocityAttenuationTable;
724  double* pVelocityReleaseTable;
725  double* pVelocityCutoffTable;
726  Region* pRegion;
727 
728  leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController);
729  _lev_ctrl_t EncodeLeverageController(leverage_ctrl_t DecodedController);
730  double* GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth);
731  double* GetCutoffVelocityTable(curve_type_t vcfVelocityCurve, uint8_t vcfVelocityDynamicRange, uint8_t vcfVelocityScale, vcf_cutoff_ctrl_t vcfCutoffController);
732  double* GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);
733  double* CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);
734  };
735 
761  class Sample : public DLS::Sample {
762  public:
763  uint32_t Manufacturer;
764  uint32_t Product;
765  uint32_t SamplePeriod;
766  uint32_t MIDIUnityNote;
767  uint32_t FineTune;
768  smpte_format_t SMPTEFormat;
769  uint32_t SMPTEOffset;
770  uint32_t Loops;
771  uint32_t LoopID;
772  loop_type_t LoopType;
773  uint32_t LoopStart;
774  uint32_t LoopEnd;
775  uint32_t LoopSize;
776  uint32_t LoopFraction;
777  uint32_t LoopPlayCount;
778  bool Compressed;
779  uint32_t TruncatedBits;
780  bool Dithered;
781 
782  // own methods
783  buffer_t LoadSampleData();
784  buffer_t LoadSampleData(file_offset_t SampleCount);
785  buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
786  buffer_t LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount);
787  buffer_t GetCache();
788  // own static methods
789  static buffer_t CreateDecompressionBuffer(file_offset_t MaxReadSize);
790  static void DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);
791  // overridden methods
792  void ReleaseSampleData();
793  void Resize(file_offset_t NewSize);
794  file_offset_t SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
795  file_offset_t GetPos() const;
796  file_offset_t Read(void* pBuffer, file_offset_t SampleCount, buffer_t* pExternalDecompressionBuffer = NULL);
797  file_offset_t ReadAndLoop(void* pBuffer, file_offset_t SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL);
798  file_offset_t Write(void* pBuffer, file_offset_t SampleCount);
799  Group* GetGroup() const;
800  virtual void UpdateChunks(progress_t* pProgress);
801  void CopyAssignMeta(const Sample* orig);
802  void CopyAssignWave(const Sample* orig);
803  uint32_t GetWaveDataCRC32Checksum();
804  bool VerifyWaveData(uint32_t* pActually = NULL);
805  protected:
806  static size_t Instances;
807  static buffer_t InternalDecompressionBuffer;
808  Group* pGroup;
809  file_offset_t FrameOffset;
810  file_offset_t* FrameTable;
811  file_offset_t SamplePos;
812  file_offset_t SamplesInLastFrame;
813  file_offset_t WorstCaseFrameSize;
814  file_offset_t SamplesPerFrame;
815  buffer_t RAMCache;
816  unsigned long FileNo;
817  RIFF::Chunk* pCk3gix;
818  RIFF::Chunk* pCkSmpl;
819  uint32_t crc;
820 
821  Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset, unsigned long fileNo = 0, int index = -1);
822  ~Sample();
823  uint32_t CalculateWaveDataChecksum();
824 
825  // Guess size (in bytes) of a compressed sample
826  inline file_offset_t GuessSize(file_offset_t samples) {
827  // 16 bit: assume all frames are compressed - 1 byte
828  // per sample and 5 bytes header per 2048 samples
829 
830  // 24 bit: assume next best compression rate - 1.5
831  // bytes per sample and 13 bytes header per 256
832  // samples
833  const file_offset_t size =
834  BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13
835  : samples + (samples >> 10) * 5;
836  // Double for stereo and add one worst case sample
837  // frame
838  return (Channels == 2 ? size << 1 : size) + WorstCaseFrameSize;
839  }
840 
841  // Worst case amount of sample points that can be read with the
842  // given decompression buffer.
843  inline file_offset_t WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {
844  return (file_offset_t) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);
845  }
846  private:
847  void ScanCompressedSample();
848  friend class File;
849  friend class Region;
850  friend class Group; // allow to modify protected member pGroup
851  };
852 
853  // TODO: <3dnl> list not used yet - not important though (just contains optional descriptions for the dimensions)
874  class Region : public DLS::Region {
875  public:
876  unsigned int Dimensions;
877  dimension_def_t pDimensionDefinitions[8];
878  uint32_t DimensionRegions;
879  DimensionRegion* pDimensionRegions[256];
880  unsigned int Layers;
881 
882  // own methods
883  DimensionRegion* GetDimensionRegionByValue(const uint DimValues[8]);
884  DimensionRegion* GetDimensionRegionByBit(const uint8_t DimBits[8]);
885  int GetDimensionRegionIndexByValue(const uint DimValues[8]);
886  Sample* GetSample();
887  void AddDimension(dimension_def_t* pDimDef);
888  void DeleteDimension(dimension_def_t* pDimDef);
889  dimension_def_t* GetDimensionDefinition(dimension_t type);
890  void DeleteDimensionZone(dimension_t type, int zone);
891  void SplitDimensionZone(dimension_t type, int zone);
892  void SetDimensionType(dimension_t oldType, dimension_t newType);
893  // overridden methods
894  virtual void SetKeyRange(uint16_t Low, uint16_t High);
895  virtual void UpdateChunks(progress_t* pProgress);
896  virtual void CopyAssign(const Region* orig);
897  protected:
898  Region(Instrument* pInstrument, RIFF::List* rgnList);
899  void LoadDimensionRegions(RIFF::List* rgn);
900  void UpdateVelocityTable();
901  Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress = NULL);
902  void CopyAssign(const Region* orig, const std::map<Sample*,Sample*>* mSamples);
903  DimensionRegion* GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase);
904  ~Region();
905  friend class Instrument;
906  };
907 
950  class MidiRule {
951  public:
952  virtual ~MidiRule() { }
953  protected:
954  virtual void UpdateChunks(uint8_t* pData) const = 0;
955  friend class Instrument;
956  };
957 
971  class MidiRuleCtrlTrigger : public MidiRule {
972  public:
973  uint8_t ControllerNumber;
974  uint8_t Triggers;
975  struct trigger_t {
976  uint8_t TriggerPoint;
977  bool Descending;
978  uint8_t VelSensitivity;
979  uint8_t Key;
980  bool NoteOff;
981  uint8_t Velocity;
982  bool OverridePedal;
983  } pTriggers[32];
984 
985  protected:
986  MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg);
987  MidiRuleCtrlTrigger();
988  void UpdateChunks(uint8_t* pData) const;
989  friend class Instrument;
990  };
991 
1012  class MidiRuleLegato : public MidiRule {
1013  public:
1014  uint8_t LegatoSamples;
1015  bool BypassUseController;
1016  uint8_t BypassKey;
1017  uint8_t BypassController;
1018  uint16_t ThresholdTime;
1019  uint16_t ReleaseTime;
1020  range_t KeyRange;
1021  uint8_t ReleaseTriggerKey;
1022  uint8_t AltSustain1Key;
1023  uint8_t AltSustain2Key;
1024 
1025  protected:
1026  MidiRuleLegato(RIFF::Chunk* _3ewg);
1027  MidiRuleLegato();
1028  void UpdateChunks(uint8_t* pData) const;
1029  friend class Instrument;
1030  };
1031 
1044  class MidiRuleAlternator : public MidiRule {
1045  public:
1046  uint8_t Articulations;
1047  String pArticulations[32];
1048 
1049  range_t PlayRange;
1050 
1051  uint8_t Patterns;
1052  struct pattern_t {
1053  String Name;
1054  int Size;
1055  const uint8_t& operator[](int i) const {
1056  return data[i];
1057  }
1058  uint8_t& operator[](int i) {
1059  return data[i];
1060  }
1061  private:
1062  uint8_t data[32];
1063  } pPatterns[32];
1064 
1065  typedef enum {
1066  selector_none,
1067  selector_key_switch,
1068  selector_controller
1069  } selector_t;
1070  selector_t Selector;
1071  range_t KeySwitchRange;
1072  uint8_t Controller;
1073 
1074  bool Polyphonic;
1075  bool Chained;
1076 
1077  protected:
1078  MidiRuleAlternator(RIFF::Chunk* _3ewg);
1079  MidiRuleAlternator();
1080  void UpdateChunks(uint8_t* pData) const;
1081  friend class Instrument;
1082  };
1083 
1097  class MidiRuleUnknown : public MidiRule {
1098  protected:
1099  MidiRuleUnknown() { }
1100  void UpdateChunks(uint8_t* pData) const { }
1101  friend class Instrument;
1102  };
1103 
1124  class Script {
1125  public:
1126  enum Encoding_t {
1127  ENCODING_ASCII = 0
1128  };
1129  enum Compression_t {
1130  COMPRESSION_NONE = 0
1131  };
1132  enum Language_t {
1133  LANGUAGE_NKSP = 0
1134  };
1135 
1136  String Name;
1137  Compression_t Compression;
1138  Encoding_t Encoding;
1139  Language_t Language;
1140  bool Bypass;
1141 
1142  String GetScriptAsText();
1143  void SetScriptAsText(const String& text);
1144  void SetGroup(ScriptGroup* pGroup);
1145  ScriptGroup* GetGroup() const;
1146  void CopyAssign(const Script* orig);
1147  protected:
1148  Script(ScriptGroup* group, RIFF::Chunk* ckScri);
1149  virtual ~Script();
1150  void UpdateChunks(progress_t* pProgress);
1151  void RemoveAllScriptReferences();
1152  friend class ScriptGroup;
1153  friend class Instrument;
1154  private:
1155  ScriptGroup* pGroup;
1156  RIFF::Chunk* pChunk;
1157  std::vector<uint8_t> data;
1158  uint32_t crc;
1159  };
1160 
1172  class ScriptGroup {
1173  public:
1174  String Name;
1175 
1176  Script* GetScript(uint index);
1177  Script* AddScript();
1178  void DeleteScript(Script* pScript);
1179  protected:
1180  ScriptGroup(File* file, RIFF::List* lstRTIS);
1181  virtual ~ScriptGroup();
1182  void LoadScripts();
1183  void UpdateChunks(progress_t* pProgress);
1184  friend class Script;
1185  friend class File;
1186  private:
1187  File* pFile;
1188  RIFF::List* pList;
1189  std::list<Script*>* pScripts;
1190  };
1191 
1207  class Instrument : protected DLS::Instrument {
1208  public:
1209  // derived attributes from DLS::Resource
1210  using DLS::Resource::pInfo;
1211  using DLS::Resource::pDLSID;
1212  // derived attributes from DLS::Instrument
1219  // own attributes
1220  int32_t Attenuation;
1221  uint16_t EffectSend;
1222  int16_t FineTune;
1223  uint16_t PitchbendRange;
1224  bool PianoReleaseMode;
1225  range_t DimensionKeyRange;
1226 
1227 
1228  // derived methods from DLS::Resource
1229  using DLS::Resource::GetParent;
1230  // overridden methods
1231  Region* GetFirstRegion();
1232  Region* GetNextRegion();
1233  Region* AddRegion();
1234  void DeleteRegion(Region* pRegion);
1235  void MoveTo(Instrument* dst);
1236  virtual void UpdateChunks(progress_t* pProgress);
1237  virtual void CopyAssign(const Instrument* orig);
1238  // own methods
1239  Region* GetRegion(unsigned int Key);
1240  MidiRule* GetMidiRule(int i);
1241  MidiRuleCtrlTrigger* AddMidiRuleCtrlTrigger();
1242  MidiRuleLegato* AddMidiRuleLegato();
1243  MidiRuleAlternator* AddMidiRuleAlternator();
1244  void DeleteMidiRule(int i);
1245  // real-time instrument script methods
1246  Script* GetScriptOfSlot(uint index);
1247  void AddScriptSlot(Script* pScript, bool bypass = false);
1248  void SwapScriptSlots(uint index1, uint index2);
1249  void RemoveScriptSlot(uint index);
1250  void RemoveScript(Script* pScript);
1251  uint ScriptSlotCount() const;
1252  bool IsScriptSlotBypassed(uint index);
1253  void SetScriptSlotBypassed(uint index, bool bBypass);
1254  protected:
1255  Region* RegionKeyTable[128];
1256 
1257  Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress = NULL);
1258  ~Instrument();
1259  void CopyAssign(const Instrument* orig, const std::map<Sample*,Sample*>* mSamples);
1260  void UpdateRegionKeyTable();
1261  void LoadScripts();
1262  void UpdateScriptFileOffsets();
1263  friend class File;
1264  friend class Region; // so Region can call UpdateRegionKeyTable()
1265  private:
1266  struct _ScriptPooolEntry {
1267  uint32_t fileOffset;
1268  bool bypass;
1269  };
1270  struct _ScriptPooolRef {
1271  Script* script;
1272  bool bypass;
1273  };
1274  MidiRule** pMidiRules;
1275  std::vector<_ScriptPooolEntry> scriptPoolFileOffsets;
1276  std::vector<_ScriptPooolRef>* pScriptRefs;
1277  };
1278 
1290  class Group {
1291  public:
1292  String Name;
1293 
1294  Sample* GetFirstSample();
1295  Sample* GetNextSample();
1296  void AddSample(Sample* pSample);
1297  protected:
1298  Group(File* file, RIFF::Chunk* ck3gnm);
1299  virtual ~Group();
1300  virtual void UpdateChunks(progress_t* pProgress);
1301  void MoveAll();
1302  friend class File;
1303  private:
1304  File* pFile;
1305  RIFF::Chunk* pNameChunk;
1306  };
1307 
1344  class File : protected DLS::File {
1345  public:
1346  static const DLS::version_t VERSION_2;
1347  static const DLS::version_t VERSION_3;
1348  static const DLS::version_t VERSION_4;
1349 
1350  // derived attributes from DLS::Resource
1351  using DLS::Resource::pInfo;
1352  using DLS::Resource::pDLSID;
1353  // derived attributes from DLS::File
1354  using DLS::File::pVersion;
1355  using DLS::File::Instruments;
1356 
1357  // derived methods from DLS::Resource
1358  using DLS::Resource::GetParent;
1359  // derived methods from DLS::File
1360  using DLS::File::Save;
1361  using DLS::File::GetFileName;
1362  using DLS::File::SetFileName;
1363  // overridden methods
1364  File();
1365  File(RIFF::File* pRIFF);
1366  Sample* GetFirstSample(progress_t* pProgress = NULL);
1367  Sample* GetNextSample();
1368  Sample* GetSample(uint index);
1369  Sample* AddSample();
1370  size_t CountSamples();
1371  void DeleteSample(Sample* pSample);
1372  Instrument* GetFirstInstrument();
1373  Instrument* GetNextInstrument();
1374  Instrument* GetInstrument(uint index, progress_t* pProgress = NULL);
1375  Instrument* AddInstrument();
1376  Instrument* AddDuplicateInstrument(const Instrument* orig);
1377  size_t CountInstruments();
1378  void DeleteInstrument(Instrument* pInstrument);
1379  Group* GetFirstGroup();
1380  Group* GetNextGroup();
1381  Group* GetGroup(uint index);
1382  Group* GetGroup(String name);
1383  Group* AddGroup();
1384  void DeleteGroup(Group* pGroup);
1385  void DeleteGroupOnly(Group* pGroup);
1386  void SetAutoLoad(bool b);
1387  bool GetAutoLoad();
1388  void AddContentOf(File* pFile);
1389  ScriptGroup* GetScriptGroup(uint index);
1390  ScriptGroup* GetScriptGroup(const String& name);
1391  ScriptGroup* AddScriptGroup();
1392  void DeleteScriptGroup(ScriptGroup* pGroup);
1393  virtual ~File();
1394  virtual void UpdateChunks(progress_t* pProgress);
1395  protected:
1396  // overridden protected methods from DLS::File
1397  virtual void LoadSamples();
1398  virtual void LoadInstruments();
1399  virtual void LoadGroups();
1400  virtual void UpdateFileOffsets();
1401  // own protected methods
1402  virtual void LoadSamples(progress_t* pProgress);
1403  virtual void LoadInstruments(progress_t* pProgress);
1404  virtual void LoadScriptGroups();
1405  void SetSampleChecksum(Sample* pSample, uint32_t crc);
1406  uint32_t GetSampleChecksum(Sample* pSample);
1407  uint32_t GetSampleChecksumByIndex(int index);
1408  bool VerifySampleChecksumTable();
1409  bool RebuildSampleChecksumTable();
1410  int GetWaveTableIndexOf(gig::Sample* pSample);
1411  friend class Region;
1412  friend class Sample;
1413  friend class Instrument;
1414  friend class Group; // so Group can access protected member pRIFF
1415  friend class ScriptGroup; // so ScriptGroup can access protected member pRIFF
1416  private:
1417  std::list<Group*>* pGroups;
1418  std::list<Group*>::iterator GroupsIterator;
1419  bool bAutoLoad;
1420  std::list<ScriptGroup*>* pScriptGroups;
1421  };
1422 
1431  class Exception : public DLS::Exception {
1432  public:
1433  Exception(String format, ...);
1434  Exception(String format, va_list arg);
1435  void PrintMessage();
1436  protected:
1437  Exception();
1438  };
1439 
1440 #if HAVE_RTTI
1441  size_t enumCount(const std::type_info& type);
1442  const char* enumKey(const std::type_info& type, size_t value);
1443  bool enumKey(const std::type_info& type, String key);
1444  const char** enumKeys(const std::type_info& type);
1445 #endif // HAVE_RTTI
1446  size_t enumCount(String typeName);
1447  const char* enumKey(String typeName, size_t value);
1448  bool enumKey(String typeName, String key);
1449  const char** enumKeys(String typeName);
1450  size_t enumValue(String key);
1451 
1452  String libraryName();
1453  String libraryVersion();
1454 
1455 } // namespace gig
1456 
1457 #endif // __GIG_H__
sample_loop_t * pSampleLoops
Points to the beginning of a sample loop array, or is NULL if there are no loops defined.
Definition: DLS.h:373
Destination container for serialization, and source container for deserialization.
uint32_t Regions
Reflects the number of Region defintions this Instrument has.
Definition: DLS.h:468
Parses DLS Level 1 and 2 compliant files and provides abstract access to the data.
Definition: DLS.h:498
stream_whence_t
File stream position dependent to these relations.
Definition: RIFF.h:165
String libraryName()
Returns the name of this C++ library.
Definition: RIFF.cpp:2291
Will be thrown whenever a DLS specific error occurs while trying to access a DLS File.
Definition: DLS.h:553
String libraryVersion()
Returns version of this C++ library.
Definition: RIFF.cpp:2299
uint16_t MIDIBank
Reflects combination of MIDIBankCoarse and MIDIBankFine (bank 1 - bank 16384). Do not change this val...
Definition: DLS.h:464
uint8_t MIDIBankCoarse
Reflects the MIDI Bank number for MIDI Control Change 0 (bank 1 - 128).
Definition: DLS.h:465
void DeleteSampleLoop(sample_loop_t *pLoopDef)
Deletes an existing sample loop.
Definition: DLS.cpp:655
RIFF List Chunk.
Definition: RIFF.h:294
Abstract base class which provides mandatory informations about sample players in general...
Definition: DLS.h:365
void SetFileName(const String &name)
You may call this method store a future file name, so you don&#39;t have to to pass it to the Save() call...
Definition: DLS.cpp:1686
uint32_t SampleLoops
Reflects the number of sample loops.
Definition: DLS.h:372
virtual void Save(const String &Path, progress_t *pProgress=NULL)
Save changes to another file.
Definition: DLS.cpp:1803
uint64_t file_offset_t
Type used by libgig for handling file positioning during file I/O tasks.
Definition: RIFF.h:148
Ordinary RIFF Chunk.
Definition: RIFF.h:218
uint32_t MIDIProgram
Specifies the MIDI Program Change Number this Instrument should be assigned to.
Definition: DLS.h:467
Used for indicating the progress of a certain task.
Definition: RIFF.h:204
version_t * pVersion
Points to a version_t structure if the file provided a version number else is set to NULL...
Definition: DLS.h:500
uint8_t MIDIBankFine
Reflects the MIDI Bank number for MIDI Control Change 32 (bank 1 - 128).
Definition: DLS.h:466
RIFF File.
Definition: RIFF.h:344
Encapsulates sample waves used for playback.
Definition: DLS.h:396
String GetFileName()
File name of this DLS file.
Definition: DLS.cpp:1678
Definition: gig.cpp:62
dlsid_t * pDLSID
Points to a dlsid_t structure if the file provided a DLS ID else is NULL.
Definition: DLS.h:349
uint32_t Instruments
Reflects the number of available Instrument objects.
Definition: DLS.h:501
Provides all neccessary information for the synthesis of a DLS Instrument.
Definition: DLS.h:461
int32_t Gain
Definition: DLS.h:369
Quadtuple version number ("major.minor.release.build").
Definition: DLS.h:111
Serialization / deserialization framework.
Definition: gig.h:91
Info * pInfo
Points (in any case) to an Info object, providing additional, optional infos and comments.
Definition: DLS.h:348
Defines Region information of an Instrument.
Definition: DLS.h:431
bool IsDrum
Indicates if the Instrument is a drum type, as they differ in the synthesis model of DLS from melodic...
Definition: DLS.h:463
void AddSampleLoop(sample_loop_t *pLoopDef)
Adds a new sample loop with the provided loop definition.
Definition: DLS.cpp:633