--- libgig/trunk/src/RIFF.h 2009/07/30 08:16:02 1953 +++ libgig/trunk/src/RIFF.h 2014/05/31 20:54:39 2584 @@ -2,7 +2,7 @@ * * * libgig - C++ cross-platform Gigasampler format file access library * * * - * Copyright (C) 2003-2009 by Christian Schoenebeck * + * Copyright (C) 2003-2014 by Christian Schoenebeck * * * * * * This library is free software; you can redistribute it and/or modify * @@ -77,10 +77,34 @@ # define CHUNK_ID_RIFF 0x52494646 # define CHUNK_ID_RIFX 0x52494658 # define CHUNK_ID_LIST 0x4C495354 + +# define LIST_TYPE_INFO 0x494E464F +# define CHUNK_ID_ICMT 0x49434D54 +# define CHUNK_ID_ICOP 0x49434F50 +# define CHUNK_ID_ICRD 0x49435244 +# define CHUNK_ID_IENG 0x49454E47 +# define CHUNK_ID_INAM 0x494E414D +# define CHUNK_ID_IPRD 0x49505244 +# define CHUNK_ID_ISFT 0x49534654 + +# define CHUNK_ID_SMPL 0x736D706C + #else // little endian # define CHUNK_ID_RIFF 0x46464952 # define CHUNK_ID_RIFX 0x58464952 # define CHUNK_ID_LIST 0x5453494C + +# define LIST_TYPE_INFO 0x4F464E49 +# define CHUNK_ID_ICMT 0x544D4349 +# define CHUNK_ID_ICOP 0x504F4349 +# define CHUNK_ID_ICRD 0x44524349 +# define CHUNK_ID_IENG 0x474E4549 +# define CHUNK_ID_INAM 0x4D414E49 +# define CHUNK_ID_IPRD 0x44525049 +# define CHUNK_ID_ISFT 0x54465349 + +# define CHUNK_ID_SMPL 0x6C706D73 + #endif // WORDS_BIGENDIAN #define CHUNK_HEADER_SIZE 8 @@ -145,6 +169,12 @@ endian_native = 2 } endian_t; + /** General chunk structure of a file. */ + enum layout_t { + layout_standard = 0, ///< Standard RIFF file layout: First chunk in file is a List chunk which contains all other chunks and there are no chunks outside the scope of that very first (List) chunk. + layout_flat = 1 ///< Not a "real" RIFF file: First chunk in file is an ordinary data chunk, not a List chunk, and there might be other chunks after that first chunk. + }; + /** @brief Ordinary RIFF Chunk * * Provides convenient methods to access data of ordinary RIFF chunks @@ -155,8 +185,9 @@ Chunk(File* pFile, unsigned long StartPos, List* Parent); String GetChunkIDString(); uint32_t GetChunkID() { return ChunkID; } ///< Chunk ID in unsigned integer representation. + File* GetFile() { return pFile; } ///< Returns pointer to the chunk's File object. List* GetParent() { return pParent; } ///< Returns pointer to the chunk's parent list chunk. - unsigned long GetSize() { return CurrentChunkSize; } ///< Chunk size in bytes (without header, thus the chunk data body) + unsigned long GetSize() const { return CurrentChunkSize; } ///< Chunk size in bytes (without header, thus the chunk data body) unsigned long GetNewSize() { return NewChunkSize; } ///< New chunk size if it was modified with Resize(). unsigned long GetPos() { return ulPos; } ///< Position within the chunk data body unsigned long GetFilePos() { return ulStartPos + ulPos; } ///< Current, actual offset in file. @@ -176,6 +207,7 @@ uint16_t ReadUint16(); int32_t ReadInt32(); uint32_t ReadUint32(); + void ReadString(String& s, int size); unsigned long Write(void* pData, unsigned long WordCount, unsigned long WordSize); unsigned long WriteInt8(int8_t* pData, unsigned long WordCount = 1); unsigned long WriteUint8(uint8_t* pData, unsigned long WordCount = 1); @@ -263,7 +295,8 @@ Chunk* AddSubChunk(uint32_t uiChunkID, uint uiBodySize); List* AddSubList(uint32_t uiListType); void DeleteSubChunk(Chunk* pSubChunk); - void MoveSubChunk(Chunk* pSrc, Chunk* pDst); + void MoveSubChunk(Chunk* pSrc, Chunk* pDst); // read API doc comments !!! + void MoveSubChunk(Chunk* pSrc, List* pNewParent); virtual ~List(); protected: typedef std::map ChunkMap; @@ -296,10 +329,14 @@ public: File(uint32_t FileType); File(const String& path); + File(const String& path, uint32_t FileType, endian_t Endian, layout_t layout); stream_mode_t GetMode(); bool SetMode(stream_mode_t NewMode); void SetByteOrder(endian_t Endian); String GetFileName(); + void SetFileName(const String& path); + bool IsNew() const; + layout_t GetLayout() const; virtual void Save(); virtual void Save(const String& path); virtual ~File(); @@ -316,6 +353,8 @@ #endif // POSIX String Filename; bool bEndianNative; + bool bIsNewFile; + layout_t Layout; ///< An ordinary RIFF file is always set to layout_standard. void LogAsResized(Chunk* pResizedChunk); void UnlogResized(Chunk* pResizedChunk); @@ -325,6 +364,7 @@ stream_mode_t Mode; ChunkList ResizedChunks; ///< All chunks which have been resized (enlarged / shortened). + void __openExistingFile(const String& path, uint32_t* FileType = NULL); unsigned long GetFileSize(); void ResizeFile(unsigned long ulNewSize); #if POSIX @@ -334,6 +374,7 @@ #else unsigned long __GetFileSize(FILE* hFile); #endif + void Cleanup(); }; /**