--- libgig/trunk/src/DLS.h 2006/10/24 19:32:47 928 +++ libgig/trunk/src/DLS.h 2012/03/12 14:59:10 2329 @@ -1,8 +1,8 @@ /*************************************************************************** * * - * libgig - C++ cross-platform Gigasampler format file loader library * + * libgig - C++ cross-platform Gigasampler format file access library * * * - * Copyright (C) 2003-2005 by Christian Schoenebeck * + * Copyright (C) 2003-2010 by Christian Schoenebeck * * * * * * This library is free software; you can redistribute it and/or modify * @@ -28,7 +28,6 @@ #if WORDS_BIGENDIAN # define RIFF_TYPE_DLS 0x444C5320 -# define LIST_TYPE_INFO 0x494E464F # define LIST_TYPE_WVPL 0x7776706C # define LIST_TYPE_DWPL 0x6477706C ///< Seen on some files instead of a wvpl list chunk. # define LIST_TYPE_WAVE 0x77617665 @@ -42,17 +41,10 @@ # define CHUNK_ID_IARL 0x4941524C # define CHUNK_ID_IART 0x49415254 # define CHUNK_ID_ICMS 0x49434D53 -# define CHUNK_ID_ICMT 0x49434D54 -# define CHUNK_ID_ICOP 0x49434F50 -# define CHUNK_ID_ICRD 0x49435244 -# define CHUNK_ID_IENG 0x49454E47 # define CHUNK_ID_IGNR 0x49474E52 # define CHUNK_ID_IKEY 0x494B4559 # define CHUNK_ID_IMED 0x494D4544 -# define CHUNK_ID_INAM 0x494E414D -# define CHUNK_ID_IPRD 0x49505244 # define CHUNK_ID_ISBJ 0x4953424A -# define CHUNK_ID_ISFT 0x49534654 # define CHUNK_ID_ISRC 0x49535243 # define CHUNK_ID_ISRF 0x49535246 # define CHUNK_ID_ITCH 0x49544348 @@ -70,7 +62,6 @@ # define CHUNK_ID_ART2 0x61727432 #else // little endian # define RIFF_TYPE_DLS 0x20534C44 -# define LIST_TYPE_INFO 0x4F464E49 # define LIST_TYPE_WVPL 0x6C707677 # define LIST_TYPE_DWPL 0x6C707764 ///< Seen on some files instead of a wvpl list chunk. # define LIST_TYPE_WAVE 0x65766177 @@ -84,17 +75,10 @@ # define CHUNK_ID_IARL 0x4C524149 # define CHUNK_ID_IART 0x54524149 # define CHUNK_ID_ICMS 0x534D4349 -# define CHUNK_ID_ICMT 0x544D4349 -# define CHUNK_ID_ICOP 0x504F4349 -# define CHUNK_ID_ICRD 0x44524349 -# define CHUNK_ID_IENG 0x474E4549 # define CHUNK_ID_IGNR 0x524E4749 # define CHUNK_ID_IKEY 0x59454B49 # define CHUNK_ID_IMED 0x44454D49 -# define CHUNK_ID_INAM 0x4D414E49 -# define CHUNK_ID_IPRD 0x44525049 # define CHUNK_ID_ISBJ 0x4A425349 -# define CHUNK_ID_ISFT 0x54465349 # define CHUNK_ID_ISRC 0x43525349 # define CHUNK_ID_ISRF 0x46525349 # define CHUNK_ID_ITCH 0x48435449 @@ -112,7 +96,7 @@ # define CHUNK_ID_ART2 0x32747261 #endif // WORDS_BIGENDIAN -#define WAVE_FORMAT_PCM 0x0001 +#define DLS_WAVE_FORMAT_PCM 0x0001 //TODO: no support for conditional chunks yet @@ -224,10 +208,10 @@ /** Defines Sample Loop Points. */ struct sample_loop_t { - uint32_t Size; - uint32_t LoopType; - uint32_t LoopStart; - uint32_t LoopLength; + uint32_t Size; ///< For internal usage only: usually reflects exactly @c sizeof(sample_loop_t), otherwise if the value is larger then the DLS format was extended! + uint32_t LoopType; ///< Defines how the waveform samples will be looped (appropriate loop types for the gig format are defined by gig::loop_type_t). + uint32_t LoopStart; ///< The start value specifies the offset (in sample points) in the waveform data of the first sample point to be played in the loop. + uint32_t LoopLength; ///< Length of the looping area (in sample points). }; // just symbol prototyping @@ -258,10 +242,10 @@ uint16_t transform; uint32_t scale; }; - Connection() {}; + Connection() {} void Init(conn_block_t* Header); conn_block_t ToConnBlock(); - virtual ~Connection() {}; + virtual ~Connection() {} friend class Articulation; }; @@ -316,16 +300,23 @@ String SourceForm; ///< . Identifies the original form of the material that was digitized, such as record, sampling CD, TV sound track. This is not neccessarily the same as Medium. String Commissioned; ///< . Lists the name of the person or organization that commissioned the subject of the file, e.g., Pope Julian II. String Subject; ///< . Describes the contents of the file. - bool UseFixedLengthStrings; ///< Set this to true if the info strings should be stored with a fixed length format. This is used for gig files, not for ordinary DLS files. + bool UseFixedLengthStrings; ///< @deprecated Not used anymore, use SetFixedStringLengths() instead. + + struct string_length_t { + uint32_t chunkId; + int length; + }; Info(RIFF::List* list); + void SetFixedStringLengths(const string_length_t* lengths); virtual ~Info(); virtual void UpdateChunks(); private: - RIFF::List* pResourceListChunk; + RIFF::List* pResourceListChunk; + const string_length_t* pFixedStringLengths; ///< List of IDs and string lengths for strings that should be stored in a fixed length format. This is used for gig files, not for ordinary DLS files. - void LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s); - void SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault, int size); + static void LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s); + void SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault); }; /** Abstract base class which encapsulates data structures which all DLS resources are able to provide. */ @@ -334,8 +325,9 @@ Info* pInfo; ///< Points (in any case) to an Info object, providing additional, optional infos and comments. dlsid_t* pDLSID; ///< Points to a dlsid_t structure if the file provided a DLS ID else is NULL. - Resource* GetParent() { return pParent; }; + Resource* GetParent() { return pParent; } virtual void UpdateChunks(); + void GenerateDLSID(); protected: Resource* pParent; RIFF::List* pResourceList; @@ -349,12 +341,15 @@ public: uint8_t UnityNote; int16_t FineTune; - int32_t Gain; + int32_t Gain; ///< @deprecated Don't alter directly, use SetGain() instead! bool NoSampleDepthTruncation; bool NoSampleCompression; uint32_t SampleLoops; ///< Reflects the number of sample loops. sample_loop_t* pSampleLoops; ///< Points to the beginning of a sample loop array, or is NULL if there are no loops defined. + void AddSampleLoop(sample_loop_t* pLoopDef); + void DeleteSampleLoop(sample_loop_t* pLoopDef); + virtual void SetGain(int32_t gain); virtual void UpdateChunks(); protected: RIFF::List* pParentList; @@ -374,7 +369,7 @@ */ class Sample : public Resource { public: - uint16_t FormatTag; ///< Format ID of the waveform data (should be WAVE_FORMAT_PCM for DLS1 compliant files, this is also the default value if Sample was created with Instrument::AddSample()). + uint16_t FormatTag; ///< Format ID of the waveform data (should be DLS_WAVE_FORMAT_PCM for DLS1 compliant files, this is also the default value if Sample was created with Instrument::AddSample()). uint16_t Channels; ///< Number of channels represented in the waveform data, e.g. 1 for mono, 2 for stereo (defaults to 1=mono if Sample was created with Instrument::AddSample() previously). uint32_t SamplesPerSecond; ///< Sampling rate at which each channel should be played (defaults to 44100 if Sample was created with Instrument::AddSample() previously). uint32_t AverageBytesPerSecond; ///< The average number of bytes per second at which the waveform data should be transferred (Playback software can estimate the buffer size using this value). @@ -406,7 +401,7 @@ /** Defines Region information of an Instrument. */ class Region : public Resource, public Articulator, public Sampler { public: - range_t KeyRange; + range_t KeyRange; ///< @deprecated Only read, don't write! Use SetKeyRange() instead. range_t VelocityRange; uint16_t KeyGroup; uint16_t Layer; @@ -418,6 +413,7 @@ Sample* GetSample(); void SetSample(Sample* pSample); + virtual void SetKeyRange(uint16_t Low, uint16_t High); virtual void UpdateChunks(); protected: RIFF::List* pCkRegion; @@ -461,6 +457,9 @@ virtual void LoadRegions(); virtual ~Instrument(); friend class File; + friend class Region; + private: + void MoveRegion(Region* pSrc, Region* pDst); }; /** Parses DLS Level 1 and 2 compliant files and provides abstract access to the data. */ @@ -471,6 +470,7 @@ File(); File(RIFF::File* pRIFF); + String GetFileName(); Sample* GetFirstSample(); ///< Returns a pointer to the first Sample object of the file, NULL otherwise. Sample* GetNextSample(); ///< Returns a pointer to the next Sample object of the file, NULL otherwise. Sample* AddSample(); @@ -479,6 +479,7 @@ Instrument* GetNextInstrument(); ///< Returns a pointer to the next Instrument object of the file, NULL otherwise. Instrument* AddInstrument(); void DeleteInstrument(Instrument* pInstrument); + RIFF::File* GetExtensionFile(int index); virtual void UpdateChunks(); virtual void Save(const String& Path); virtual void Save(); @@ -508,7 +509,13 @@ void __UpdateWavePoolTable(); }; - /** Will be thrown whenever a DLS specific error occurs while trying to access a DLS File. */ + /** + * Will be thrown whenever a DLS specific error occurs while trying to + * access a DLS File. Note: In your application you should better catch + * for RIFF::Exception rather than this one, except you explicitly want + * to catch and handle DLS::Exception and RIFF::Exception independently, + * which usually shouldn't be necessary though. + */ class Exception : public RIFF::Exception { public: Exception(String Message);