Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DLS.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   libgig - C++ cross-platform Gigasampler format file loader library    *
00004  *                                                                         *
00005  *   Copyright (C) 2003-2005 by Christian Schoenebeck                      *
00006  *                              <cuse@users.sourceforge.net>               *
00007  *                                                                         *
00008  *   This library is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This library is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this library; if not, write to the Free Software           *
00020  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00021  *   MA  02111-1307  USA                                                   *
00022  ***************************************************************************/
00023 
00024 #ifndef __DLS_H__
00025 #define __DLS_H__
00026 
00027 #include "RIFF.h"
00028 
00029 #if WORDS_BIGENDIAN
00030 # define LIST_TYPE_INFO 0x494E464F
00031 # define LIST_TYPE_WVPL 0x7776706C
00032 # define LIST_TYPE_DWPL 0x6477706C  
00033 # define LIST_TYPE_WAVE 0x77617665
00034 # define LIST_TYPE_LINS 0X6C696E73
00035 # define LIST_TYPE_INS  0X696E7320
00036 # define LIST_TYPE_LRGN 0x6C72676E
00037 # define LIST_TYPE_LART 0x6C617274
00038 # define LIST_TYPE_LAR2 0x6C617232
00039 # define LIST_TYPE_RGN  0x72676E20
00040 # define LIST_TYPE_RGN2 0x72676E32
00041 # define LIST_TYPE_ART1 0x61727431
00042 # define LIST_TYPE_ART2 0x61727432
00043 # define CHUNK_ID_IARL  0x4941524C
00044 # define CHUNK_ID_IART  0x49415254
00045 # define CHUNK_ID_ICMS  0x49434D53
00046 # define CHUNK_ID_ICMT  0x49434D54
00047 # define CHUNK_ID_ICOP  0x49434F50
00048 # define CHUNK_ID_ICRD  0x49435244
00049 # define CHUNK_ID_IENG  0x49454E47
00050 # define CHUNK_ID_IGNR  0x49474E52
00051 # define CHUNK_ID_IKEY  0x494B4559
00052 # define CHUNK_ID_IMED  0x494D4544
00053 # define CHUNK_ID_INAM  0x494E414D
00054 # define CHUNK_ID_IPRD  0x49505244
00055 # define CHUNK_ID_ISBJ  0x4953424A
00056 # define CHUNK_ID_ISFT  0x49534654
00057 # define CHUNK_ID_ISRC  0x49535243
00058 # define CHUNK_ID_ISRF  0x49535246
00059 # define CHUNK_ID_ITCH  0x49544348
00060 # define CHUNK_ID_VERS  0x76657273
00061 # define CHUNK_ID_DLID  0x646C6964
00062 # define CHUNK_ID_FMT   0x666D7420
00063 # define CHUNK_ID_DATA  0x64617461
00064 # define CHUNK_ID_INSH  0x696E7368
00065 # define CHUNK_ID_RGNH  0x72676E68
00066 # define CHUNK_ID_WLNK  0x776C6E6B
00067 # define CHUNK_ID_PTBL  0x7074626C
00068 # define CHUNK_ID_WSMP  0x77736D70
00069 # define CHUNK_ID_COLH  0x636F6C68
00070 #else  // little endian
00071 # define LIST_TYPE_INFO 0x4F464E49
00072 # define LIST_TYPE_WVPL 0x6C707677
00073 # define LIST_TYPE_DWPL 0x6C707764  
00074 # define LIST_TYPE_WAVE 0x65766177
00075 # define LIST_TYPE_LINS 0X736E696C
00076 # define LIST_TYPE_INS  0X20736E69
00077 # define LIST_TYPE_LRGN 0x6E67726C
00078 # define LIST_TYPE_LART 0x7472616C
00079 # define LIST_TYPE_LAR2 0x3272616C
00080 # define LIST_TYPE_RGN  0x206E6772
00081 # define LIST_TYPE_RGN2 0x326E6772
00082 # define LIST_TYPE_ART1 0x31747261
00083 # define LIST_TYPE_ART2 0x32747261
00084 # define CHUNK_ID_IARL  0x4C524149
00085 # define CHUNK_ID_IART  0x54524149
00086 # define CHUNK_ID_ICMS  0x534D4349
00087 # define CHUNK_ID_ICMT  0x544D4349
00088 # define CHUNK_ID_ICOP  0x504F4349
00089 # define CHUNK_ID_ICRD  0x44524349
00090 # define CHUNK_ID_IENG  0x474E4549
00091 # define CHUNK_ID_IGNR  0x524E4749
00092 # define CHUNK_ID_IKEY  0x59454B49
00093 # define CHUNK_ID_IMED  0x44525049
00094 # define CHUNK_ID_INAM  0x4D414E49
00095 # define CHUNK_ID_IPRD  0x44525049
00096 # define CHUNK_ID_ISBJ  0x4A425349
00097 # define CHUNK_ID_ISFT  0x54465349
00098 # define CHUNK_ID_ISRC  0x43525349
00099 # define CHUNK_ID_ISRF  0x46525349
00100 # define CHUNK_ID_ITCH  0x48435449
00101 # define CHUNK_ID_VERS  0x73726576
00102 # define CHUNK_ID_DLID  0x64696C64
00103 # define CHUNK_ID_FMT   0x20746D66
00104 # define CHUNK_ID_DATA  0x61746164
00105 # define CHUNK_ID_INSH  0x68736E69
00106 # define CHUNK_ID_RGNH  0x686E6772
00107 # define CHUNK_ID_WLNK  0x6B6E6C77
00108 # define CHUNK_ID_PTBL  0x6C627470
00109 # define CHUNK_ID_WSMP  0x706D7377
00110 # define CHUNK_ID_COLH  0x686C6F63
00111 #endif // WORDS_BIGENDIAN
00112 
00113 #define WAVE_FORMAT_PCM                 0x0001
00114 
00115 #define DRUM_TYPE_MASK                  0x00000001
00116 
00117 #define F_RGN_OPTION_SELFNONEXCLUSIVE   0x0001
00118 
00119 #define F_WAVELINK_PHASE_MASTER         0x0001
00120 #define F_WAVELINK_MULTICHANNEL         0x0002
00121 
00122 #define F_WSMP_NO_TRUNCATION            0x0001
00123 #define F_WSMP_NO_COMPRESSION           0x0002
00124 
00125 #define MIDI_BANK_COARSE(x)             ((x & 0x00007F00) >> 8)                 // CC0
00126 #define MIDI_BANK_FINE(x)               (x & 0x0000007F)                        // CC32
00127 #define MIDI_BANK_MERGE(coarse, fine)   ((((uint16_t) coarse) << 7) | fine)     // CC0 + CC32
00128 #define CONN_TRANSFORM_SRC(x)           ((x >> 10) & 0x000F)
00129 #define CONN_TRANSFORM_CTL(x)           ((x >> 4) & 0x000F)
00130 #define CONN_TRANSFORM_DST(x)           (x & 0x000F)
00131 #define CONN_TRANSFORM_BIPOLAR_SRC(x)   (x & 0x4000)
00132 #define CONN_TRANSFORM_BIPOLAR_CTL(x)   (x & 0x0100)
00133 #define CONN_TRANSFORM_INVERT_SRC(x)    (x & 0x8000)
00134 #define CONN_TRANSFORM_INVERT_CTL(x)    (x & 0x0200)
00135 
00136 
00137 //TODO: no support for conditional chunks <cdl> yet
00138 
00140 namespace DLS {
00141 
00142     typedef std::string String;
00143 
00145     struct version_t {
00146         uint16_t minor;
00147         uint16_t major;
00148         uint16_t build;
00149         uint16_t release;
00150     };
00151 
00153     struct dlsid_t {
00154         uint32_t ulData1;
00155         uint16_t usData2;
00156         uint16_t usData3;
00157         uint8_t  abData[8];
00158     };
00159 
00161     typedef enum {
00162         // Modulator Sources
00163         conn_src_none            = 0x0000,
00164         conn_src_lfo             = 0x0001,
00165         conn_src_keyonvelocity   = 0x0002,
00166         conn_src_keynumber       = 0x0003,
00167         conn_src_eg1             = 0x0004,
00168         conn_src_eg2             = 0x0005,
00169         conn_src_pitchwheel      = 0x0006,
00170         conn_src_polypressure    = 0x0007,
00171         conn_src_channelpressure = 0x0008,
00172         conn_src_vibrato         = 0x0009,
00173         // MIDI Controller Sources
00174         conn_src_cc1             = 0x0081,
00175         conn_src_cc7             = 0x0087,
00176         conn_src_cc10            = 0x008A,
00177         conn_src_cc11            = 0x008B,
00178         conn_src_cc91            = 0x00DB,
00179         conn_src_cc93            = 0x00DD,
00180         // Registered Parameter Numbers
00181         conn_src_rpn0            = 0x0100,
00182         conn_src_rpn1            = 0x0101,
00183         conn_src_rpn2            = 0x0102
00184     } conn_src_t;
00185 
00187     typedef enum {
00188         // Generic Destinations
00189         conn_dst_none             = 0x0000,
00190         conn_dst_gain             = 0x0001,
00191         conn_dst_reserved         = 0x0002,
00192         conn_dst_pitch            = 0x0003,
00193         conn_dst_pan              = 0x0004,
00194         conn_dst_keynumber        = 0x0005,
00195         // Channel Output Destinations
00196         conn_dst_left             = 0x0010,
00197         conn_dst_right            = 0x0011,
00198         conn_dst_center           = 0x0012,
00199         conn_dst_lfe_channel      = 0x0013,
00200         conn_dst_leftrear         = 0x0014,
00201         conn_dst_rightrear        = 0x0015,
00202         conn_dst_chorus           = 0x0080,
00203         conn_dst_reverb           = 0x0081,
00204         // Modulator LFO Destinations
00205         conn_dst_lfo_frequency    = 0x0104,
00206         conn_dst_lfo_startdelay   = 0x0105,
00207         // Vibrato LFO Destinations
00208         conn_dst_vib_frequency    = 0x0114,
00209         conn_dst_vib_startdelay   = 0x0115,
00210         // EG Destinations
00211         conn_dst_eg1_attacktime   = 0x0206,
00212         conn_dst_eg1_decaytime    = 0x0207,
00213         conn_dst_eg1_reserved     = 0x0208,
00214         conn_dst_eg1_releasetime  = 0x0209,
00215         conn_dst_eg1_sustainlevel = 0x020A,
00216         conn_dst_eg1_delaytime    = 0x020B,
00217         conn_dst_eg1_holdtime     = 0x020C,
00218         conn_dst_eg1_shutdowntime = 0x020D,
00219         conn_dst_eg2_attacktime   = 0x030A,
00220         conn_dst_eg2_decaytime    = 0x030B,
00221         conn_dst_eg2_reserved     = 0x030C,
00222         conn_dst_eg2_releasetime  = 0x030D,
00223         conn_dst_eg2_sustainlevel = 0x030E,
00224         conn_dst_eg2_delaytime    = 0x030F,
00225         conn_dst_eg2_holdtime     = 0x0310,
00226         // Filter Destinations
00227         conn_dst_filter_cutoff    = 0x0500,
00228         conn_dst_filter_q         = 0x0501
00229     } conn_dst_t;
00230 
00232     typedef enum {
00233         conn_trn_none    = 0x0000,
00234         conn_trn_concave = 0x0001,
00235         conn_trn_convex  = 0x0002,
00236         conn_trn_switch  = 0x0003
00237     } conn_trn_t;
00238 
00240     struct range_t {
00241         uint16_t low;  
00242         uint16_t high; 
00243     };
00244 
00246     struct sample_loop_t {
00247         uint32_t Size;
00248         uint32_t LoopType;
00249         uint32_t LoopStart;
00250         uint32_t LoopLength;
00251     };
00252 
00253     // just symbol prototyping
00254     class File;
00255     class Instrument;
00256     class Region;
00257     class Sample;
00258 
00260     class Connection {
00261         public:
00262             conn_src_t Source;
00263             conn_trn_t SourceTransform;
00264             bool       SourceInvert;
00265             bool       SourceBipolar;
00266             conn_src_t Control;
00267             conn_trn_t ControlTransform;
00268             bool       ControlInvert;
00269             bool       ControlBipolar;
00270             conn_dst_t Destination;
00271             conn_trn_t DestinationTransform;
00272             uint32_t   Scale;
00273         protected:
00274             struct conn_block_t {
00275                 uint16_t source;
00276                 uint16_t control;
00277                 uint16_t destination;
00278                 uint16_t transform;
00279                 uint32_t scale;
00280             };
00281             Connection() {};
00282             void Init(conn_block_t* Header);
00283             virtual ~Connection() {};
00284             friend class Articulation;
00285     };
00286 
00288     class Articulation {
00289         public:
00290             Connection*  pConnections; 
00291             uint32_t     Connections;  
00292             Articulation(RIFF::List* artList);
00293             virtual ~Articulation();
00294     };
00295 
00297     class Articulator {
00298         public:
00299             Articulator(RIFF::List* ParentList);
00300             Articulation* GetFirstArticulation();
00301             Articulation* GetNextArticulation();
00302         protected:
00303             typedef std::list<Articulation*> ArticulationList;
00304             RIFF::List*                 pParentList;
00305             ArticulationList*           pArticulations;
00306             ArticulationList::iterator  ArticulationsIterator;
00307 
00308             void LoadArticulations();
00309             virtual ~Articulator();
00310     };
00311 
00313     class Info {
00314         public:
00315             String Name;             
00316             String ArchivalLocation; 
00317             String CreationDate;     
00318             String Comments;         
00319             String Product;          
00320             String Copyright;        
00321             String Artists;          
00322             String Genre;            
00323             String Keywords;         
00324             String Engineer;         
00325             String Technician;       
00326             String Software;         
00327             String Medium;           
00328             String Source;           
00329             String SourceForm;       
00330             String Commissioned;     
00331 
00332             Info(RIFF::List* list);
00333         private:
00334             inline void LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
00335                 RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
00336                 if (ck) {
00337                     // TODO: no check for ZSTR terminated strings yet
00338                     s = (char*) ck->LoadChunkData();
00339                     ck->ReleaseChunkData();
00340                 }
00341             }
00342     };
00343 
00345     class Resource {
00346         public:
00347             Info*    pInfo;        
00348             dlsid_t* pDLSID;       
00349 
00350             Resource* GetParent() { return pParent; };
00351         protected:
00352             Resource* pParent;
00353 
00354             Resource(Resource* Parent, RIFF::List* lstResource);
00355             virtual ~Resource();
00356     };
00357 
00359     class Sampler {
00360         public:
00361             uint8_t        UnityNote;
00362             int16_t        FineTune;
00363             int32_t        Gain;
00364             bool           NoSampleDepthTruncation;
00365             bool           NoSampleCompression;
00366             uint32_t       SampleLoops;              
00367             sample_loop_t* pSampleLoops;             
00368         protected:
00369             uint32_t       SamplerOptions;
00370             Sampler(RIFF::List* ParentList);
00371             virtual ~Sampler();
00372     };
00373 
00375     class Sample : public Resource {
00376         public:
00377             uint16_t      FormatTag;             
00378             uint16_t      Channels;              
00379             uint32_t      SamplesPerSecond;      
00380             uint32_t      AverageBytesPerSecond; 
00381             uint16_t      BlockAlign;            
00382             uint16_t      BitDepth;              
00383             unsigned long SamplesTotal;          
00384             uint          FrameSize;             
00385 
00386             void*         LoadSampleData();              
00387             void          ReleaseSampleData();           
00388             unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
00389             unsigned long Read(void* pBuffer, unsigned long SampleCount);
00390         protected:
00391             RIFF::Chunk*  pCkData;
00392             RIFF::Chunk*  pCkFormat;
00393             unsigned long ulWavePoolOffset;  // needed for comparison with the wave pool link table, thus the link to instruments
00394 
00395             Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset);
00396             friend class File;
00397             friend class Region; // Region has to compare the wave pool offset to get its sample
00398     };
00399 
00401     class Region : public Resource, public Articulator, public Sampler {
00402         public:
00403             range_t     KeyRange;
00404             range_t     VelocityRange;
00405             uint16_t    KeyGroup;
00406             uint16_t    Layer;
00407             bool        SelfNonExclusive;
00408             bool        PhaseMaster;
00409             uint16_t    PhaseGroup;
00410             bool        MultiChannel;
00411             uint32_t    Channel;
00412 
00413             Sample*     GetSample();
00414         protected:
00415             RIFF::List* pCkRegion;
00416             uint32_t    WavePoolTableIndex; // index in the wave pool table to the sample wave this region is linked to
00417             Sample*     pSample;            // every region refers to exactly one sample
00418 
00419             Region(Instrument* pInstrument, RIFF::List* rgnList);
00420             virtual ~Region();
00421             friend class Instrument;
00422     };
00423 
00425     class Instrument : public Resource, public Articulator {
00426         public:
00427             bool     IsDrum;         
00428             uint16_t MIDIBank;       
00429             uint8_t  MIDIBankCoarse; 
00430             uint8_t  MIDIBankFine;   
00431             uint32_t MIDIProgram;    
00432             uint32_t Regions;        
00433 
00434             Region*  GetFirstRegion();
00435             Region*  GetNextRegion();
00436         protected:
00437             typedef std::list<Region*> RegionList;
00438             struct midi_locale_t {
00439                 uint32_t bank;
00440                 uint32_t instrument;
00441             };
00442 
00443             RIFF::List*          pCkInstrument;
00444             RegionList*          pRegions;
00445             RegionList::iterator RegionsIterator;
00446 
00447             Instrument(File* pFile, RIFF::List* insList);
00448             void LoadRegions();
00449             virtual ~Instrument();
00450             friend class File;
00451     };
00452 
00454     class File : public Resource {
00455         public:
00456             version_t* pVersion;              
00457             uint32_t   Instruments;           
00458 
00459             File(RIFF::File* pRIFF);
00460             Sample*     GetFirstSample();     
00461             Sample*     GetNextSample();      
00462             Instrument* GetFirstInstrument(); 
00463             Instrument* GetNextInstrument();  
00464             virtual ~File();
00465         protected:
00466             typedef std::list<Sample*>     SampleList;
00467             typedef std::list<Instrument*> InstrumentList;
00468 
00469             RIFF::File*              pRIFF;
00470             SampleList*              pSamples;
00471             SampleList::iterator     SamplesIterator;
00472             InstrumentList*          pInstruments;
00473             InstrumentList::iterator InstrumentsIterator;
00474             uint32_t                 WavePoolCount;
00475             uint32_t*                pWavePoolTable;
00476 
00477             void LoadSamples();
00478             void LoadInstruments();
00479             friend class Region; // Region has to look in the wave pool table to get its sample
00480     };
00481 
00483     class Exception : public RIFF::Exception {
00484         public:
00485             Exception(String Message);
00486             void PrintMessage();
00487     };
00488 
00489     String libraryName();
00490     String libraryVersion();
00491 
00492 } // namespace DLS
00493 
00494 #endif // __DLS_H__

Generated on Thu May 26 00:50:17 2005 for libgig by  doxygen 1.4.2