00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __GIG_H__
00025 #define __GIG_H__
00026
00027 #include "DLS.h"
00028
00029 #if WORDS_BIGENDIAN
00030 # define LIST_TYPE_3PRG 0x33707267
00031 # define LIST_TYPE_3EWL 0x3365776C
00032 # define LIST_TYPE_3GRI 0x33677269
00033 # define LIST_TYPE_3GNL 0x33676E6C
00034 # define CHUNK_ID_SMPL 0x736D706C
00035 # define CHUNK_ID_3GIX 0x33676978
00036 # define CHUNK_ID_3EWA 0x33657761
00037 # define CHUNK_ID_3LNK 0x336C6E6B
00038 # define CHUNK_ID_3EWG 0x33657767
00039 # define CHUNK_ID_EWAV 0x65776176
00040 # define CHUNK_ID_3GNM 0x33676E6D
00041 #else // little endian
00042 # define LIST_TYPE_3PRG 0x67727033
00043 # define LIST_TYPE_3EWL 0x6C776533
00044 # define LIST_TYPE_3GRI 0x69726733
00045 # define LIST_TYPE_3GNL 0x6C6E6733
00046 # define CHUNK_ID_SMPL 0x6C706D73
00047 # define CHUNK_ID_3GIX 0x78696733
00048 # define CHUNK_ID_3EWA 0x61776533
00049 # define CHUNK_ID_3LNK 0x6B6E6C33
00050 # define CHUNK_ID_3EWG 0x67776533
00051 # define CHUNK_ID_EWAV 0x76617765
00052 # define CHUNK_ID_3GNM 0x6D6E6733
00053 #endif // WORDS_BIGENDIAN
00054
00056 namespace gig {
00057
00058 typedef std::string String;
00059
00061 struct range_t {
00062 uint8_t low;
00063 uint8_t high;
00064 };
00065
00067 struct buffer_t {
00068 void* pStart;
00069 unsigned long Size;
00070 unsigned long NullExtensionSize;
00071 buffer_t() {
00072 pStart = NULL;
00073 Size = 0;
00074 NullExtensionSize = 0;
00075 }
00076 };
00077
00079 typedef enum {
00080 loop_type_normal = 0x00000000,
00081 loop_type_bidirectional = 0x00000001,
00082 loop_type_backward = 0x00000002
00083 } loop_type_t;
00084
00086 typedef enum {
00087 smpte_format_no_offset = 0x00000000,
00088 smpte_format_24_frames = 0x00000018,
00089 smpte_format_25_frames = 0x00000019,
00090 smpte_format_30_frames_dropping = 0x0000001D,
00091 smpte_format_30_frames = 0x0000001E
00092 } smpte_format_t;
00093
00095 typedef enum {
00096 curve_type_nonlinear = 0,
00097 curve_type_linear = 1,
00098 curve_type_special = 2,
00099 curve_type_unknown = 0xffffffff
00100 } curve_type_t;
00101
00103 typedef enum {
00104 dim_bypass_ctrl_none,
00105 dim_bypass_ctrl_94,
00106 dim_bypass_ctrl_95
00107 } dim_bypass_ctrl_t;
00108
00110 typedef enum {
00111 lfo3_ctrl_internal = 0x00,
00112 lfo3_ctrl_modwheel = 0x01,
00113 lfo3_ctrl_aftertouch = 0x02,
00114 lfo3_ctrl_internal_modwheel = 0x03,
00115 lfo3_ctrl_internal_aftertouch = 0x04
00116 } lfo3_ctrl_t;
00117
00119 typedef enum {
00120 lfo2_ctrl_internal = 0x00,
00121 lfo2_ctrl_modwheel = 0x01,
00122 lfo2_ctrl_foot = 0x02,
00123 lfo2_ctrl_internal_modwheel = 0x03,
00124 lfo2_ctrl_internal_foot = 0x04
00125 } lfo2_ctrl_t;
00126
00128 typedef enum {
00129 lfo1_ctrl_internal = 0x00,
00130 lfo1_ctrl_modwheel = 0x01,
00131 lfo1_ctrl_breath = 0x02,
00132 lfo1_ctrl_internal_modwheel = 0x03,
00133 lfo1_ctrl_internal_breath = 0x04
00134 } lfo1_ctrl_t;
00135
00137 typedef enum {
00138 vcf_cutoff_ctrl_none = 0x00,
00139 vcf_cutoff_ctrl_none2 = 0x01,
00140 vcf_cutoff_ctrl_modwheel = 0x81,
00141 vcf_cutoff_ctrl_effect1 = 0x8c,
00142 vcf_cutoff_ctrl_effect2 = 0x8d,
00143 vcf_cutoff_ctrl_breath = 0x82,
00144 vcf_cutoff_ctrl_foot = 0x84,
00145 vcf_cutoff_ctrl_sustainpedal = 0xc0,
00146 vcf_cutoff_ctrl_softpedal = 0xc3,
00147 vcf_cutoff_ctrl_genpurpose7 = 0xd2,
00148 vcf_cutoff_ctrl_genpurpose8 = 0xd3,
00149 vcf_cutoff_ctrl_aftertouch = 0x80
00150 } vcf_cutoff_ctrl_t;
00151
00153 typedef enum {
00154 vcf_res_ctrl_none = 0xffffffff,
00155 vcf_res_ctrl_genpurpose3 = 0,
00156 vcf_res_ctrl_genpurpose4 = 1,
00157 vcf_res_ctrl_genpurpose5 = 2,
00158 vcf_res_ctrl_genpurpose6 = 3
00159 } vcf_res_ctrl_t;
00160
00169 struct leverage_ctrl_t {
00170 typedef enum {
00171 type_none = 0x00,
00172 type_channelaftertouch = 0x2f,
00173 type_velocity = 0xff,
00174 type_controlchange = 0xfe
00175 } type_t;
00176
00177 type_t type;
00178 uint controller_number;
00179 };
00180
00186 typedef leverage_ctrl_t attenuation_ctrl_t;
00187
00193 typedef leverage_ctrl_t eg1_ctrl_t;
00194
00200 typedef leverage_ctrl_t eg2_ctrl_t;
00201
00209 typedef enum {
00210 dimension_none = 0x00,
00211 dimension_samplechannel = 0x80,
00212 dimension_layer = 0x81,
00213 dimension_velocity = 0x82,
00214 dimension_channelaftertouch = 0x83,
00215 dimension_releasetrigger = 0x84,
00216 dimension_keyboard = 0x85,
00217 dimension_roundrobin = 0x86,
00218 dimension_random = 0x87,
00219 dimension_smartmidi = 0x88,
00220 dimension_roundrobinkeyboard = 0x89,
00221 dimension_modwheel = 0x01,
00222 dimension_breath = 0x02,
00223 dimension_foot = 0x04,
00224 dimension_portamentotime = 0x05,
00225 dimension_effect1 = 0x0c,
00226 dimension_effect2 = 0x0d,
00227 dimension_genpurpose1 = 0x10,
00228 dimension_genpurpose2 = 0x11,
00229 dimension_genpurpose3 = 0x12,
00230 dimension_genpurpose4 = 0x13,
00231 dimension_sustainpedal = 0x40,
00232 dimension_portamento = 0x41,
00233 dimension_sostenutopedal = 0x42,
00234 dimension_softpedal = 0x43,
00235 dimension_genpurpose5 = 0x30,
00236 dimension_genpurpose6 = 0x31,
00237 dimension_genpurpose7 = 0x32,
00238 dimension_genpurpose8 = 0x33,
00239 dimension_effect1depth = 0x5b,
00240 dimension_effect2depth = 0x5c,
00241 dimension_effect3depth = 0x5d,
00242 dimension_effect4depth = 0x5e,
00243 dimension_effect5depth = 0x5f
00244 } dimension_t;
00245
00250 typedef enum {
00251 split_type_normal,
00252 split_type_bit
00253 } split_type_t;
00254
00256 struct dimension_def_t {
00257 dimension_t dimension;
00258 uint8_t bits;
00259 uint8_t zones;
00260 split_type_t split_type;
00261 float zone_size;
00262 };
00263
00265 typedef enum {
00266 vcf_type_lowpass = 0x00,
00267 vcf_type_lowpassturbo = 0xff,
00268 vcf_type_bandpass = 0x01,
00269 vcf_type_highpass = 0x02,
00270 vcf_type_bandreject = 0x03
00271 } vcf_type_t;
00272
00280 struct crossfade_t {
00281 #if WORDS_BIGENDIAN
00282 uint8_t out_end;
00283 uint8_t out_start;
00284 uint8_t in_end;
00285 uint8_t in_start;
00286 #else // little endian
00287 uint8_t in_start;
00288 uint8_t in_end;
00289 uint8_t out_start;
00290 uint8_t out_end;
00291 #endif // WORDS_BIGENDIAN
00292 };
00293
00295 struct playback_state_t {
00296 unsigned long position;
00297 bool reverse;
00298 unsigned long loop_cycles_left;
00299 };
00300
00313 struct progress_t {
00314 void (*callback)(progress_t*);
00315 float factor;
00316 void* custom;
00317 float __range_min;
00318 float __range_max;
00319 progress_t();
00320 };
00321
00322
00323 class File;
00324 class Instrument;
00325 class Sample;
00326 class Region;
00327 class Group;
00328
00341 class DimensionRegion : protected DLS::Sampler {
00342 public:
00343 uint8_t VelocityUpperLimit;
00344 Sample* pSample;
00345
00346 uint16_t EG1PreAttack;
00347 double EG1Attack;
00348 double EG1Decay1;
00349 double EG1Decay2;
00350 bool EG1InfiniteSustain;
00351 uint16_t EG1Sustain;
00352 double EG1Release;
00353 bool EG1Hold;
00354 eg1_ctrl_t EG1Controller;
00355 bool EG1ControllerInvert;
00356 uint8_t EG1ControllerAttackInfluence;
00357 uint8_t EG1ControllerDecayInfluence;
00358 uint8_t EG1ControllerReleaseInfluence;
00359 double LFO1Frequency;
00360 uint16_t LFO1InternalDepth;
00361 uint16_t LFO1ControlDepth;
00362 lfo1_ctrl_t LFO1Controller;
00363 bool LFO1FlipPhase;
00364 bool LFO1Sync;
00365
00366 uint16_t EG2PreAttack;
00367 double EG2Attack;
00368 double EG2Decay1;
00369 double EG2Decay2;
00370 bool EG2InfiniteSustain;
00371 uint16_t EG2Sustain;
00372 double EG2Release;
00373 eg2_ctrl_t EG2Controller;
00374 bool EG2ControllerInvert;
00375 uint8_t EG2ControllerAttackInfluence;
00376 uint8_t EG2ControllerDecayInfluence;
00377 uint8_t EG2ControllerReleaseInfluence;
00378 double LFO2Frequency;
00379 uint16_t LFO2InternalDepth;
00380 uint16_t LFO2ControlDepth;
00381 lfo2_ctrl_t LFO2Controller;
00382 bool LFO2FlipPhase;
00383 bool LFO2Sync;
00384
00385 double EG3Attack;
00386 int16_t EG3Depth;
00387 double LFO3Frequency;
00388 int16_t LFO3InternalDepth;
00389 int16_t LFO3ControlDepth;
00390 lfo3_ctrl_t LFO3Controller;
00391 bool LFO3Sync;
00392
00393 bool VCFEnabled;
00394 vcf_type_t VCFType;
00395 vcf_cutoff_ctrl_t VCFCutoffController;
00396 bool VCFCutoffControllerInvert;
00397 uint8_t VCFCutoff;
00398 curve_type_t VCFVelocityCurve;
00399 uint8_t VCFVelocityScale;
00400 uint8_t VCFVelocityDynamicRange;
00401 uint8_t VCFResonance;
00402 bool VCFResonanceDynamic;
00403 vcf_res_ctrl_t VCFResonanceController;
00404 bool VCFKeyboardTracking;
00405 uint8_t VCFKeyboardTrackingBreakpoint;
00406
00407 curve_type_t VelocityResponseCurve;
00408 uint8_t VelocityResponseDepth;
00409 uint8_t VelocityResponseCurveScaling;
00410 curve_type_t ReleaseVelocityResponseCurve;
00411 uint8_t ReleaseVelocityResponseDepth;
00412 uint8_t ReleaseTriggerDecay;
00413
00414 crossfade_t Crossfade;
00415 bool PitchTrack;
00416 dim_bypass_ctrl_t DimensionBypass;
00417 int8_t Pan;
00418 bool SelfMask;
00419 attenuation_ctrl_t AttenuationController;
00420 bool InvertAttenuationController;
00421 uint8_t AttenuationControllerThreshold;
00422 uint8_t ChannelOffset;
00423 bool SustainDefeat;
00424 bool MSDecode;
00425 uint16_t SampleStartOffset;
00426 double SampleAttenuation;
00427 uint8_t DimensionUpperLimits[8];
00428
00429
00430 DLS::Sampler::UnityNote;
00431 DLS::Sampler::FineTune;
00432 DLS::Sampler::Gain;
00433 DLS::Sampler::SampleLoops;
00434 DLS::Sampler::pSampleLoops;
00435
00436
00437 double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);
00438 double GetVelocityRelease(uint8_t MIDIKeyVelocity);
00439 double GetVelocityCutoff(uint8_t MIDIKeyVelocity);
00440
00441 virtual void UpdateChunks();
00442 protected:
00443 uint8_t* VelocityTable;
00444 DimensionRegion(RIFF::List* _3ewl);
00445 ~DimensionRegion();
00446 friend class Region;
00447 private:
00448 typedef enum {
00449 _lev_ctrl_none = 0x00,
00450 _lev_ctrl_modwheel = 0x03,
00451 _lev_ctrl_breath = 0x05,
00452 _lev_ctrl_foot = 0x07,
00453 _lev_ctrl_effect1 = 0x0d,
00454 _lev_ctrl_effect2 = 0x0f,
00455 _lev_ctrl_genpurpose1 = 0x11,
00456 _lev_ctrl_genpurpose2 = 0x13,
00457 _lev_ctrl_genpurpose3 = 0x15,
00458 _lev_ctrl_genpurpose4 = 0x17,
00459 _lev_ctrl_portamentotime = 0x0b,
00460 _lev_ctrl_sustainpedal = 0x01,
00461 _lev_ctrl_portamento = 0x19,
00462 _lev_ctrl_sostenutopedal = 0x1b,
00463 _lev_ctrl_softpedal = 0x09,
00464 _lev_ctrl_genpurpose5 = 0x1d,
00465 _lev_ctrl_genpurpose6 = 0x1f,
00466 _lev_ctrl_genpurpose7 = 0x21,
00467 _lev_ctrl_genpurpose8 = 0x23,
00468 _lev_ctrl_effect1depth = 0x25,
00469 _lev_ctrl_effect2depth = 0x27,
00470 _lev_ctrl_effect3depth = 0x29,
00471 _lev_ctrl_effect4depth = 0x2b,
00472 _lev_ctrl_effect5depth = 0x2d,
00473 _lev_ctrl_channelaftertouch = 0x2f,
00474 _lev_ctrl_velocity = 0xff
00475 } _lev_ctrl_t;
00476 typedef std::map<uint32_t, double*> VelocityTableMap;
00477
00478 static uint Instances;
00479 static VelocityTableMap* pVelocityTables;
00480 double* pVelocityAttenuationTable;
00481 double* pVelocityReleaseTable;
00482 double* pVelocityCutoffTable;
00483
00484 leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController);
00485 _lev_ctrl_t EncodeLeverageController(leverage_ctrl_t DecodedController);
00486 double* GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);
00487 double* CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling);
00488 };
00489
00500 class Sample : public DLS::Sample {
00501 public:
00502 uint32_t Manufacturer;
00503 uint32_t Product;
00504 uint32_t SamplePeriod;
00505 uint32_t MIDIUnityNote;
00506 uint32_t FineTune;
00507 smpte_format_t SMPTEFormat;
00508 uint32_t SMPTEOffset;
00509 uint32_t Loops;
00510 uint32_t LoopID;
00511 loop_type_t LoopType;
00512 uint32_t LoopStart;
00513 uint32_t LoopEnd;
00514 uint32_t LoopSize;
00515 uint32_t LoopFraction;
00516 uint32_t LoopPlayCount;
00517 bool Compressed;
00518 uint32_t TruncatedBits;
00519 bool Dithered;
00520
00521
00522 buffer_t LoadSampleData();
00523 buffer_t LoadSampleData(unsigned long SampleCount);
00524 buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
00525 buffer_t LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);
00526 buffer_t GetCache();
00527
00528 static buffer_t CreateDecompressionBuffer(unsigned long MaxReadSize);
00529 static void DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);
00530
00531 void ReleaseSampleData();
00532 void Resize(int iNewSize);
00533 unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
00534 unsigned long GetPos();
00535 unsigned long Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer = NULL);
00536 unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL);
00537 unsigned long Write(void* pBuffer, unsigned long SampleCount);
00538 Group* GetGroup() const;
00539 virtual void UpdateChunks();
00540 protected:
00541 static unsigned int Instances;
00542 static buffer_t InternalDecompressionBuffer;
00543 Group* pGroup;
00544 unsigned long FrameOffset;
00545 unsigned long* FrameTable;
00546 unsigned long SamplePos;
00547 unsigned long SamplesInLastFrame;
00548 unsigned long WorstCaseFrameSize;
00549 unsigned long SamplesPerFrame;
00550 buffer_t RAMCache;
00551 unsigned long FileNo;
00552 RIFF::Chunk* pCk3gix;
00553 RIFF::Chunk* pCkSmpl;
00554
00555 Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo = 0);
00556 ~Sample();
00557
00558
00559 inline unsigned long GuessSize(unsigned long samples) {
00560
00561
00562
00563
00564
00565
00566 const unsigned long size =
00567 BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13
00568 : samples + (samples >> 10) * 5;
00569
00570
00571 return (Channels == 2 ? size << 1 : size) + WorstCaseFrameSize;
00572 }
00573
00574
00575
00576 inline unsigned long WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {
00577 return (unsigned long) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);
00578 }
00579 private:
00580 void ScanCompressedSample();
00581 friend class File;
00582 friend class Region;
00583 friend class Group;
00584 };
00585
00586
00588 class Region : public DLS::Region {
00589 public:
00590 unsigned int Dimensions;
00591 dimension_def_t pDimensionDefinitions[8];
00592 uint32_t DimensionRegions;
00593 DimensionRegion* pDimensionRegions[256];
00594 unsigned int Layers;
00595
00596 DimensionRegion* GetDimensionRegionByValue(const uint DimValues[8]);
00597 DimensionRegion* GetDimensionRegionByBit(const uint8_t DimBits[8]);
00598 Sample* GetSample();
00599 void AddDimension(dimension_def_t* pDimDef);
00600 void DeleteDimension(dimension_def_t* pDimDef);
00601 virtual void UpdateChunks();
00602 protected:
00603 Region(Instrument* pInstrument, RIFF::List* rgnList);
00604 void LoadDimensionRegions(RIFF::List* rgn);
00605 void UpdateVelocityTable();
00606 Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress = NULL);
00607 ~Region();
00608 friend class Instrument;
00609 };
00610
00612 class Instrument : protected DLS::Instrument {
00613 public:
00614
00615 DLS::Resource::pInfo;
00616 DLS::Resource::pDLSID;
00617
00618 DLS::Instrument::IsDrum;
00619 DLS::Instrument::MIDIBank;
00620 DLS::Instrument::MIDIBankCoarse;
00621 DLS::Instrument::MIDIBankFine;
00622 DLS::Instrument::MIDIProgram;
00623 DLS::Instrument::Regions;
00624
00625 int32_t Attenuation;
00626 uint16_t EffectSend;
00627 int16_t FineTune;
00628 uint16_t PitchbendRange;
00629 bool PianoReleaseMode;
00630 range_t DimensionKeyRange;
00631
00632
00633
00634 DLS::Resource::GetParent;
00635
00636 DLS::Instrument::MoveRegion;
00637
00638 Region* GetFirstRegion();
00639 Region* GetNextRegion();
00640 Region* AddRegion();
00641 void DeleteRegion(Region* pRegion);
00642 virtual void UpdateChunks();
00643
00644 Region* GetRegion(unsigned int Key);
00645 protected:
00646 Region* RegionKeyTable[128];
00647
00648 Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress = NULL);
00649 ~Instrument();
00650 void UpdateRegionKeyTable();
00651 friend class File;
00652 };
00653
00669 class Group {
00670 public:
00671 String Name;
00672
00673 Sample* GetFirstSample();
00674 Sample* GetNextSample();
00675 void AddSample(Sample* pSample);
00676 protected:
00677 Group(File* file, RIFF::Chunk* ck3gnm);
00678 virtual ~Group();
00679 virtual void UpdateChunks();
00680 void MoveAll();
00681 friend class File;
00682 private:
00683 File* pFile;
00684 RIFF::Chunk* pNameChunk;
00685 };
00686
00688 class File : protected DLS::File {
00689 public:
00690
00691 DLS::Resource::pInfo;
00692 DLS::Resource::pDLSID;
00693
00694 DLS::File::pVersion;
00695 DLS::File::Instruments;
00696
00697
00698 DLS::Resource::GetParent;
00699
00700 DLS::File::Save;
00701
00702 File();
00703 File(RIFF::File* pRIFF);
00704 Sample* GetFirstSample(progress_t* pProgress = NULL);
00705 Sample* GetNextSample();
00706 Sample* AddSample();
00707 void DeleteSample(Sample* pSample);
00708 Instrument* GetFirstInstrument();
00709 Instrument* GetNextInstrument();
00710 Instrument* GetInstrument(uint index, progress_t* pProgress = NULL);
00711 Instrument* AddInstrument();
00712 void DeleteInstrument(Instrument* pInstrument);
00713 Group* GetFirstGroup();
00714 Group* GetNextGroup();
00715 Group* GetGroup(uint index);
00716 Group* AddGroup();
00717 void DeleteGroup(Group* pGroup);
00718 void DeleteGroupOnly(Group* pGroup);
00719 virtual ~File();
00720 virtual void UpdateChunks();
00721 protected:
00722
00723 virtual void LoadSamples();
00724 virtual void LoadInstruments();
00725 virtual void LoadGroups();
00726
00727 virtual void LoadSamples(progress_t* pProgress);
00728 virtual void LoadInstruments(progress_t* pProgress);
00729 friend class Region;
00730 friend class Sample;
00731 friend class Group;
00732 private:
00733 std::list<Group*>* pGroups;
00734 std::list<Group*>::iterator GroupsIterator;
00735 };
00736
00745 class Exception : public DLS::Exception {
00746 public:
00747 Exception(String Message);
00748 void PrintMessage();
00749 };
00750
00751 String libraryName();
00752 String libraryVersion();
00753
00754 }
00755
00756 #endif // __GIG_H__