--- libgig/trunk/src/DLS.h 2007/04/11 16:33:56 1154 +++ libgig/trunk/src/DLS.h 2014/05/13 11:17:24 2547 @@ -2,7 +2,7 @@ * * * libgig - C++ cross-platform Gigasampler format file access library * * * - * Copyright (C) 2003-2007 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 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 @@ -220,6 +204,25 @@ 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; + } + + inline bool overlaps(uint16_t scalar) const { + return low <= scalar && scalar <= high; + } + + inline bool overlaps(const range_t& other) const { + return overlaps(other.low) || overlaps(other.high) || + other.overlaps(low) || other.overlaps(high); + } }; /** Defines Sample Loop Points. */ @@ -258,10 +261,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 +289,7 @@ Articulation* GetFirstArticulation(); Articulation* GetNextArticulation(); virtual void UpdateChunks(); + virtual void CopyAssign(const Articulator* orig); protected: typedef std::list ArticulationList; RIFF::List* pParentList; @@ -316,16 +320,24 @@ 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(); + 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. static void LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s); - static void SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault, bool bUseFixedLengthStrings, int size); + 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 +346,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; @@ -349,7 +364,7 @@ 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. @@ -357,7 +372,9 @@ 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; @@ -387,12 +404,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; @@ -401,6 +419,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 }; @@ -408,7 +427,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; @@ -420,7 +439,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 @@ -446,9 +467,9 @@ Region* GetFirstRegion(); Region* GetNextRegion(); Region* AddRegion(); - void MoveRegion(Region* pSrc, Region* pDst); void DeleteRegion(Region* pRegion); virtual void UpdateChunks(); + virtual void CopyAssign(const Instrument* orig); protected: typedef std::list RegionList; struct midi_locale_t { @@ -461,9 +482,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. */ @@ -474,6 +499,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(); @@ -482,6 +509,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();