--- libgig/trunk/src/DLS.h 2006/02/06 17:58:21 834 +++ libgig/trunk/src/DLS.h 2014/05/10 02:06:58 2543 @@ -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-2014 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 0x44525049 -# define CHUNK_ID_INAM 0x4D414E49 -# define CHUNK_ID_IPRD 0x44525049 +# define CHUNK_ID_IMED 0x44454D49 # 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 @@ -220,14 +204,24 @@ struct range_t { uint16_t low; ///< Low value of range. uint16_t high; ///< High value of range. + + inline bool operator< (const range_t& other) const { + if (low < other.low) return true; + if (low > other.low) return false; + return high < other.high; + } + + inline bool operator== (const range_t& other) const { + return low == other.low && high == other.high; + } }; /** 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 +252,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; }; @@ -286,6 +280,7 @@ Articulation* GetFirstArticulation(); Articulation* GetNextArticulation(); virtual void UpdateChunks(); + virtual void CopyAssign(const Articulator* orig); protected: typedef std::list ArticulationList; RIFF::List* pParentList; @@ -315,14 +310,24 @@ String Source; ///< . Identifies the name of the person or organization who supplied the original subject of the file. 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; ///< @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(); + virtual void CopyAssign(const Info* orig); 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); + 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); }; @@ -332,8 +337,11 @@ 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; } + const Resource* GetParent() const { return pParent; } virtual void UpdateChunks(); + void GenerateDLSID(); + virtual void CopyAssign(const Resource* orig); protected: Resource* pParent; RIFF::List* pResourceList; @@ -347,13 +355,17 @@ 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(); + virtual void CopyAssign(const Sampler* orig); protected: RIFF::List* pParentList; uint32_t uiHeaderSize; @@ -372,7 +384,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). @@ -383,12 +395,13 @@ void* LoadSampleData(); void ReleaseSampleData(); - unsigned long GetSize(); + unsigned long GetSize() const; void Resize(int iNewSize); unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start); unsigned long Read(void* pBuffer, unsigned long SampleCount); unsigned long Write(void* pBuffer, unsigned long SampleCount); virtual void UpdateChunks(); + virtual void CopyAssign(const Sample* orig); protected: RIFF::List* pWaveList; RIFF::Chunk* pCkData; @@ -397,6 +410,7 @@ Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset); virtual ~Sample(); + void CopyAssignCore(const Sample* orig); friend class File; friend class Region; // Region has to compare the wave pool offset to get its sample }; @@ -404,7 +418,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; @@ -416,7 +430,9 @@ Sample* GetSample(); void SetSample(Sample* pSample); + virtual void SetKeyRange(uint16_t Low, uint16_t High); virtual void UpdateChunks(); + virtual void CopyAssign(const Region* orig); protected: RIFF::List* pCkRegion; uint32_t WavePoolTableIndex; // index in the wave pool table to the sample wave this region is linked to @@ -444,6 +460,7 @@ Region* AddRegion(); void DeleteRegion(Region* pRegion); virtual void UpdateChunks(); + virtual void CopyAssign(const Instrument* orig); protected: typedef std::list RegionList; struct midi_locale_t { @@ -456,9 +473,13 @@ RegionList::iterator RegionsIterator; Instrument(File* pFile, RIFF::List* insList); + void CopyAssignCore(const Instrument* orig); 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. */ @@ -469,6 +490,8 @@ File(); File(RIFF::File* pRIFF); + String GetFileName(); + void SetFileName(const String& name); 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(); @@ -477,6 +500,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(); @@ -506,7 +530,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);