50 # include <sys/types.h> 51 # include <sys/stat.h> 58 typedef __int8 int8_t;
59 typedef __int16 int16_t;
60 typedef __int32 int32_t;
61 typedef __int64 int64_t;
62 typedef unsigned __int8 uint8_t;
63 typedef unsigned __int16 uint16_t;
64 typedef unsigned __int32 uint32_t;
65 typedef unsigned __int64 uint64_t;
72 typedef unsigned int uint;
78 # define CHUNK_ID_RIFF 0x52494646 79 # define CHUNK_ID_RIFX 0x52494658 80 # define CHUNK_ID_LIST 0x4C495354 82 # define LIST_TYPE_INFO 0x494E464F 83 # define CHUNK_ID_ICMT 0x49434D54 84 # define CHUNK_ID_ICOP 0x49434F50 85 # define CHUNK_ID_ICRD 0x49435244 86 # define CHUNK_ID_IENG 0x49454E47 87 # define CHUNK_ID_INAM 0x494E414D 88 # define CHUNK_ID_IPRD 0x49505244 89 # define CHUNK_ID_ISFT 0x49534654 91 # define CHUNK_ID_SMPL 0x736D706C 93 #else // little endian 94 # define CHUNK_ID_RIFF 0x46464952 95 # define CHUNK_ID_RIFX 0x58464952 96 # define CHUNK_ID_LIST 0x5453494C 98 # define LIST_TYPE_INFO 0x4F464E49 99 # define CHUNK_ID_ICMT 0x544D4349 100 # define CHUNK_ID_ICOP 0x504F4349 101 # define CHUNK_ID_ICRD 0x44524349 102 # define CHUNK_ID_IENG 0x474E4549 103 # define CHUNK_ID_INAM 0x4D414E49 104 # define CHUNK_ID_IPRD 0x44525049 105 # define CHUNK_ID_ISFT 0x54465349 107 # define CHUNK_ID_SMPL 0x6C706D73 109 #endif // WORDS_BIGENDIAN 111 #define CHUNK_HEADER_SIZE 8 112 #define LIST_HEADER_SIZE 12 113 #define RIFF_HEADER_SIZE 12 142 typedef std::string
String;
219 unsigned long Read(
void* pData,
unsigned long WordCount,
unsigned long WordSize);
220 unsigned long ReadInt8(int8_t* pData,
unsigned long WordCount = 1);
221 unsigned long ReadUint8(uint8_t* pData,
unsigned long WordCount = 1);
222 unsigned long ReadInt16(int16_t* pData,
unsigned long WordCount = 1);
223 unsigned long ReadUint16(uint16_t* pData,
unsigned long WordCount = 1);
224 unsigned long ReadInt32(int32_t* pData,
unsigned long WordCount = 1);
225 unsigned long ReadUint32(uint32_t* pData,
unsigned long WordCount = 1);
233 unsigned long Write(
void* pData,
unsigned long WordCount,
unsigned long WordSize);
234 unsigned long WriteInt8(int8_t* pData,
unsigned long WordCount = 1);
235 unsigned long WriteUint8(uint8_t* pData,
unsigned long WordCount = 1);
236 unsigned long WriteInt16(int16_t* pData,
unsigned long WordCount = 1);
237 unsigned long WriteUint16(uint16_t* pData,
unsigned long WordCount = 1);
238 unsigned long WriteInt32(int32_t* pData,
unsigned long WordCount = 1);
239 unsigned long WriteUint32(uint32_t* pData,
unsigned long WordCount = 1);
242 void Resize(
int iNewSize);
259 unsigned long ReadSceptical(
void* pData,
unsigned long WordCount,
unsigned long WordSize);
261 uint8_t byteCache = *((uint8_t*) Word);
262 *((uint8_t*) Word) = *((uint8_t*) Word + 1);
263 *((uint8_t*) Word + 1) = byteCache;
266 uint8_t byteCache = *((uint8_t*) Word);
267 *((uint8_t*) Word) = *((uint8_t*) Word + 3);
268 *((uint8_t*) Word + 3) = byteCache;
269 byteCache = *((uint8_t*) Word + 1);
270 *((uint8_t*) Word + 1) = *((uint8_t*) Word + 2);
271 *((uint8_t*) Word + 2) = byteCache;
273 inline void swapBytes(
void* Word,
unsigned long WordSize) {
275 unsigned long lo = 0, hi = WordSize - 1;
276 for (; lo < hi; hi--, lo++) {
277 byteCache = *((uint8_t*) Word + lo);
278 *((uint8_t*) Word + lo) = *((uint8_t*) Word + hi);
279 *((uint8_t*) Word + hi) = byteCache;
284 for (
int i = 0; i < 4; i++) {
285 uint8_t
byte = *((uint8_t*)(&word) + i);
291 virtual unsigned long WriteChunk(
unsigned long ulWritePos,
unsigned long ulCurrentDataOffset,
progress_t* pProgress = NULL);
340 virtual unsigned long WriteChunk(
unsigned long ulWritePos,
unsigned long ulCurrentDataOffset,
progress_t* pProgress = NULL);
353 File(uint32_t FileType);
390 void __openExistingFile(
const String& path, uint32_t* FileType = NULL);
391 unsigned long GetFileSize();
392 void ResizeFile(
unsigned long ulNewSize);
394 unsigned long __GetFileSize(
int hFile);
396 unsigned long __GetFileSize(HANDLE hFile);
398 unsigned long __GetFileSize(FILE* hFile);
bool IsNew() const
Returns true if this file has been created new from scratch and has not been stored to disk yet.
unsigned long WriteUint32(uint32_t *pData, unsigned long WordCount=1)
Writes WordCount number of 32 Bit unsigned integer words from the buffer pointed by pData to the chun...
int16_t ReadInt16()
Reads one 16 Bit signed integer word and increments the position within the chunk.
void UnlogResized(Chunk *pResizedChunk)
void swapBytes_16(void *Word)
stream_whence_t
File stream position dependent to these relations.
unsigned long Read(void *pData, unsigned long WordCount, unsigned long WordSize)
Reads WordCount number of data words with given WordSize and copies it into a buffer pointed by pData...
Chunk * GetFirstSubChunk()
Returns the first subchunk within the list.
String libraryName()
Returns the name of this C++ library.
virtual unsigned long WriteChunk(unsigned long ulWritePos, unsigned long ulCurrentDataOffset, progress_t *pProgress=NULL)
Write list chunk persistently e.g.
File(uint32_t FileType)
Create new RIFF file.
unsigned long WriteUint16(uint16_t *pData, unsigned long WordCount=1)
Writes WordCount number of 16 Bit unsigned integer words from the buffer pointed by pData to the chun...
uint32_t GetChunkID()
Chunk ID in unsigned integer representation.
layout_t Layout
An ordinary RIFF file is always set to layout_standard.
void(* callback)(progress_t *)
Callback function pointer which has to be assigned to a function for progress notification.
void ReadHeader(unsigned long fPos)
void swapBytes(void *Word, unsigned long WordSize)
stream_state_t
Current state of the file stream.
unsigned long SetPos(unsigned long Where, stream_whence_t Whence=stream_start)
Sets the position within the chunk body, thus within the data portion of the chunk (in bytes).
void ReadString(String &s, int size)
Reads a null-padded string of size characters and copies it into the string s.
void WriteHeader(unsigned long fPos)
String libraryVersion()
Returns version of this C++ library.
List * GetSubList(uint32_t ListType)
Returns sublist chunk with list type ListType within this chunk list.
void DeleteSubChunk(Chunk *pSubChunk)
Removes a sub chunk.
unsigned long WriteInt16(int16_t *pData, unsigned long WordCount=1)
Writes WordCount number of 16 Bit signed integer words from the buffer pointed by pData to the chunk'...
int hFileWrite
handle / descriptor for writing to (some) file
unsigned long RemainingBytes()
Returns the number of bytes left to read in the chunk body.
List * GetFirstSubList()
Returns the first sublist within the list (that is a subchunk with chunk ID "LIST").
Exception(String Message)
stream_mode_t
Whether file stream is open in read or in read/write mode.
std::list< Chunk * > ChunkList
unsigned long GetPos()
Position within the chunk data body.
void SetByteOrder(endian_t Endian)
Set the byte order to be used when saving.
std::set< Chunk * > ChunkSet
int8_t ReadInt8()
Reads one 8 Bit signed integer word and increments the position within the chunk.
void ReadHeader(unsigned long fPos)
String GetListTypeString()
Returns string representation of the lists's id.
ChunkList::iterator ListIterator
float __range_min
Only for internal usage, do not modify!
unsigned long WriteInt32(int32_t *pData, unsigned long WordCount=1)
Writes WordCount number of 32 Bit signed integer words from the buffer pointed by pData to the chunk'...
Chunk * GetSubChunk(uint32_t ChunkID)
Returns subchunk with chunk ID ChunkID within this chunk list.
Chunk * GetNextSubChunk()
Returns the next subchunk within the list.
unsigned long ReadSceptical(void *pData, unsigned long WordCount, unsigned long WordSize)
Just an internal wrapper for the main Read() method with additional Exception throwing on errors.
int32_t ReadInt32()
Reads one 32 Bit signed integer word and increments the position within the chunk.
virtual void Save(progress_t *pProgress=NULL)
Save changes to same file.
layout_t
General chunk structure of a file.
stream_state_t GetState()
Returns the current state of the chunk object.
uint32_t GetListType()
Returns unsigned integer representation of the list's ID.
unsigned long GetFilePos()
Current, actual offset in file.
uint32_t ReadUint32()
Reads one 32 Bit unsigned integer word and increments the position within the chunk.
ChunkList::iterator ChunksIterator
File * GetFile()
Returns pointer to the chunk's File object.
void * custom
This pointer can be used for arbitrary data.
unsigned long Write(void *pData, unsigned long WordCount, unsigned long WordSize)
Writes WordCount number of data words with given WordSize from the buffer pointed by pData.
Used for indicating the progress of a certain task.
virtual unsigned long WriteChunk(unsigned long ulWritePos, unsigned long ulCurrentDataOffset, progress_t *pProgress=NULL)
Write chunk persistently e.g.
List * GetParent()
Returns pointer to the chunk's parent list chunk.
void swapBytes_32(void *Word)
Chunk * AddSubChunk(uint32_t uiChunkID, uint uiBodySize)
Creates a new sub chunk.
int hFileRead
handle / descriptor for reading from file
Not a "real" RIFF file: First chunk in file is an ordinary data chunk, not a List chunk,...
void LogAsResized(Chunk *pResizedChunk)
virtual void __resetPos()
Sets Chunk's read/write position to zero.
uint16_t ReadUint16()
Reads one 16 Bit unsigned integer word and increments the position within the chunk.
virtual void __resetPos()
Sets List Chunk's read/write position to zero and causes all sub chunks to do the same.
uint32_t CurrentChunkSize
endian_t
Alignment of data bytes in memory (system dependant).
void SetFileName(const String &path)
void * LoadChunkData()
Load chunk body into RAM.
unsigned long WriteInt8(int8_t *pData, unsigned long WordCount=1)
Writes WordCount number of 8 Bit signed integer words from the buffer pointed by pData to the chunk's...
void LoadSubChunksRecursively(progress_t *pProgress=NULL)
Standard RIFF file layout: First chunk in file is a List chunk which contains all other chunks and th...
unsigned long ulChunkDataSize
layout_t GetLayout() const
List * AddSubList(uint32_t uiListType)
Creates a new list sub chunk.
RIFF specific classes and definitions.
unsigned long GetSize() const
Chunk size in bytes (without header, thus the chunk data body)
float factor
Reflects current progress as value between 0.0 and 1.0.
List(File *pFile, unsigned long StartPos, List *Parent)
void MoveSubChunk(Chunk *pSrc, Chunk *pDst)
Moves a sub chunk witin this list.
unsigned int CountSubChunks()
Returns number of subchunks within the list.
String convertToString(uint32_t word)
bool SetMode(stream_mode_t NewMode)
Change file access mode.
float __range_max
Only for internal usage, do not modify!
Will be thrown whenever an error occurs while handling a RIFF file.
unsigned long WriteUint8(uint8_t *pData, unsigned long WordCount=1)
Writes WordCount number of 8 Bit unsigned integer words from the buffer pointed by pData to the chunk...
void LoadSubChunks(progress_t *pProgress=NULL)
void ReleaseChunkData()
Free loaded chunk body from RAM.
unsigned int CountSubLists()
Returns number of sublists within the list.
String GetChunkIDString()
Returns the String representation of the chunk's ID (e.g.
unsigned long GetNewSize()
New chunk size if it was modified with Resize().
void WriteHeader(unsigned long fPos)
std::map< uint32_t, RIFF::Chunk * > ChunkMap
void Resize(int iNewSize)
Resize chunk.
List * GetNextSubList()
Returns the next sublist (that is a subchunk with chunk ID "LIST") within the list.
Chunk(File *pFile, unsigned long StartPos, List *Parent)
uint8_t ReadUint8()
Reads one 8 Bit unsigned integer word and increments the position within the chunk.