/[svn]/libgig/trunk/src/RIFF.cpp
ViewVC logotype

Diff of /libgig/trunk/src/RIFF.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3053 by schoenebeck, Wed Dec 14 18:55:08 2016 UTC revision 3478 by schoenebeck, Thu Feb 21 20:10:08 2019 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2016 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2019 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 64  namespace RIFF { Line 64  namespace RIFF {
64          __range_max = 1.0f;          __range_max = 1.0f;
65      }      }
66    
67        /**
68         * Divides this progress task into the requested amount of sub-progress
69         * tasks and returns a vector with those subprogress tasks.
70         *
71         * @param iSubtasks - total amount sub tasks this task should be subdivided
72         * @returns subtasks
73         */
74        std::vector<progress_t> progress_t::subdivide(int iSubtasks) {
75            std::vector<progress_t> v;
76            for (int i = 0; i < iSubtasks; ++i) {
77                progress_t p;
78                __divide_progress(this, &p, iSubtasks, i);
79                v.push_back(p);
80            }
81            return v;
82        }
83    
84    
85    
86  // *************** Chunk **************  // *************** Chunk **************
87  // *  // *
88    
89      Chunk::Chunk(File* pFile) {      Chunk::Chunk(File* pFile) {
90          #if DEBUG          #if DEBUG_RIFF
91          std::cout << "Chunk::Chunk(File* pFile)" << std::endl;          std::cout << "Chunk::Chunk(File* pFile)" << std::endl;
92          #endif // DEBUG          #endif // DEBUG_RIFF
93          ullPos     = 0;          ullPos     = 0;
94          pParent    = NULL;          pParent    = NULL;
95          pChunkData = NULL;          pChunkData = NULL;
# Line 84  namespace RIFF { Line 101  namespace RIFF {
101      }      }
102    
103      Chunk::Chunk(File* pFile, file_offset_t StartPos, List* Parent) {      Chunk::Chunk(File* pFile, file_offset_t StartPos, List* Parent) {
104          #if DEBUG          #if DEBUG_RIFF
105          std::cout << "Chunk::Chunk(File*,file_offset_t,List*),StartPos=" << StartPos << std::endl;          std::cout << "Chunk::Chunk(File*,file_offset_t,List*),StartPos=" << StartPos << std::endl;
106          #endif // DEBUG          #endif // DEBUG_RIFF
107          this->pFile   = pFile;          this->pFile   = pFile;
108          ullStartPos   = StartPos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize);          ullStartPos   = StartPos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize);
109          pParent       = Parent;          pParent       = Parent;
# Line 115  namespace RIFF { Line 132  namespace RIFF {
132      }      }
133    
134      void Chunk::ReadHeader(file_offset_t filePos) {      void Chunk::ReadHeader(file_offset_t filePos) {
135          #if DEBUG          #if DEBUG_RIFF
136          std::cout << "Chunk::Readheader(" << filePos << ") ";          std::cout << "Chunk::Readheader(" << filePos << ") ";
137          #endif // DEBUG          #endif // DEBUG_RIFF
138          ChunkID = 0;          ChunkID = 0;
139          ullNewChunkSize = ullCurrentChunkSize = 0;          ullNewChunkSize = ullCurrentChunkSize = 0;
140          #if POSIX          #if POSIX
# Line 153  namespace RIFF { Line 170  namespace RIFF {
170                  else                  else
171                      swapBytes_64(&ullCurrentChunkSize);                      swapBytes_64(&ullCurrentChunkSize);
172              }              }
173              #if DEBUG              #if DEBUG_RIFF
174              std::cout << "ckID=" << convertToString(ChunkID) << " ";              std::cout << "ckID=" << convertToString(ChunkID) << " ";
175              std::cout << "ckSize=" << ullCurrentChunkSize << " ";              std::cout << "ckSize=" << ullCurrentChunkSize << " ";
176              std::cout << "bEndianNative=" << pFile->bEndianNative << std::endl;              std::cout << "bEndianNative=" << pFile->bEndianNative << std::endl;
177              #endif // DEBUG              #endif // DEBUG_RIFF
178              ullNewChunkSize = ullCurrentChunkSize;              ullNewChunkSize = ullCurrentChunkSize;
179          }          }
180      }      }
# Line 222  namespace RIFF { Line 239  namespace RIFF {
239       *                  data       *                  data
240       */       */
241      file_offset_t Chunk::SetPos(file_offset_t Where, stream_whence_t Whence) {      file_offset_t Chunk::SetPos(file_offset_t Where, stream_whence_t Whence) {
242          #if DEBUG          #if DEBUG_RIFF
243          std::cout << "Chunk::SetPos(file_offset_t,stream_whence_t)" << std::endl;          std::cout << "Chunk::SetPos(file_offset_t,stream_whence_t)" << std::endl;
244          #endif // DEBUG          #endif // DEBUG_RIFF
245          switch (Whence) {          switch (Whence) {
246              case stream_curpos:              case stream_curpos:
247                  ullPos += Where;                  ullPos += Where;
# Line 254  namespace RIFF { Line 271  namespace RIFF {
271       *  @returns  number of bytes left to read       *  @returns  number of bytes left to read
272       */       */
273      file_offset_t Chunk::RemainingBytes() const {      file_offset_t Chunk::RemainingBytes() const {
274          #if DEBUG          #if DEBUG_RIFF
275          std::cout << "Chunk::Remainingbytes()=" << ullCurrentChunkSize - ullPos << std::endl;          std::cout << "Chunk::Remainingbytes()=" << ullCurrentChunkSize - ullPos << std::endl;
276          #endif // DEBUG          #endif // DEBUG_RIFF
277          return (ullCurrentChunkSize > ullPos) ? ullCurrentChunkSize - ullPos : 0;          return (ullCurrentChunkSize > ullPos) ? ullCurrentChunkSize - ullPos : 0;
278      }      }
279    
# Line 285  namespace RIFF { Line 302  namespace RIFF {
302       *    possible without SetPos()       *    possible without SetPos()
303       */       */
304      stream_state_t Chunk::GetState() const {      stream_state_t Chunk::GetState() const {
305          #if DEBUG          #if DEBUG_RIFF
306          std::cout << "Chunk::GetState()" << std::endl;          std::cout << "Chunk::GetState()" << std::endl;
307          #endif // DEBUG          #endif // DEBUG_RIFF
308          #if POSIX          #if POSIX
309          if (pFile->hFileRead == 0) return stream_closed;          if (pFile->hFileRead == 0) return stream_closed;
310          #elif defined (WIN32)          #elif defined (WIN32)
# Line 316  namespace RIFF { Line 333  namespace RIFF {
333       *                    of file reached or error occurred       *                    of file reached or error occurred
334       */       */
335      file_offset_t Chunk::Read(void* pData, file_offset_t WordCount, file_offset_t WordSize) {      file_offset_t Chunk::Read(void* pData, file_offset_t WordCount, file_offset_t WordSize) {
336          #if DEBUG          #if DEBUG_RIFF
337          std::cout << "Chunk::Read(void*,file_offset_t,file_offset_t)" << std::endl;          std::cout << "Chunk::Read(void*,file_offset_t,file_offset_t)" << std::endl;
338          #endif // DEBUG          #endif // DEBUG_RIFF
339          //if (ulStartPos == 0) return 0; // is only 0 if this is a new chunk, so nothing to read (yet)          //if (ulStartPos == 0) return 0; // is only 0 if this is a new chunk, so nothing to read (yet)
340          if (ullPos >= ullCurrentChunkSize) return 0;          if (ullPos >= ullCurrentChunkSize) return 0;
341          if (ullPos + WordCount * WordSize >= ullCurrentChunkSize) WordCount = (ullCurrentChunkSize - ullPos) / WordSize;          if (ullPos + WordCount * WordSize >= ullCurrentChunkSize) WordCount = (ullCurrentChunkSize - ullPos) / WordSize;
# Line 326  namespace RIFF { Line 343  namespace RIFF {
343          if (lseek(pFile->hFileRead, ullStartPos + ullPos, SEEK_SET) < 0) return 0;          if (lseek(pFile->hFileRead, ullStartPos + ullPos, SEEK_SET) < 0) return 0;
344          ssize_t readWords = read(pFile->hFileRead, pData, WordCount * WordSize);          ssize_t readWords = read(pFile->hFileRead, pData, WordCount * WordSize);
345          if (readWords < 1) {          if (readWords < 1) {
346              #if DEBUG              #if DEBUG_RIFF
347              std::cerr << "POSIX read() failed: " << strerror(errno) << std::endl << std::flush;              std::cerr << "POSIX read() failed: " << strerror(errno) << std::endl << std::flush;
348              #endif // DEBUG              #endif // DEBUG_RIFF
349              return 0;              return 0;
350          }          }
351          readWords /= WordSize;          readWords /= WordSize;
# Line 459  namespace RIFF { Line 476  namespace RIFF {
476       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
477       */       */
478      file_offset_t Chunk::ReadInt8(int8_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadInt8(int8_t* pData, file_offset_t WordCount) {
479          #if DEBUG          #if DEBUG_RIFF
480          std::cout << "Chunk::ReadInt8(int8_t*,file_offset_t)" << std::endl;          std::cout << "Chunk::ReadInt8(int8_t*,file_offset_t)" << std::endl;
481          #endif // DEBUG          #endif // DEBUG_RIFF
482          return ReadSceptical(pData, WordCount, 1);          return ReadSceptical(pData, WordCount, 1);
483      }      }
484    
# Line 496  namespace RIFF { Line 513  namespace RIFF {
513       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
514       */       */
515      file_offset_t Chunk::ReadUint8(uint8_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadUint8(uint8_t* pData, file_offset_t WordCount) {
516          #if DEBUG          #if DEBUG_RIFF
517          std::cout << "Chunk::ReadUint8(uint8_t*,file_offset_t)" << std::endl;          std::cout << "Chunk::ReadUint8(uint8_t*,file_offset_t)" << std::endl;
518          #endif // DEBUG          #endif // DEBUG_RIFF
519          return ReadSceptical(pData, WordCount, 1);          return ReadSceptical(pData, WordCount, 1);
520      }      }
521    
# Line 533  namespace RIFF { Line 550  namespace RIFF {
550       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
551       */       */
552      file_offset_t Chunk::ReadInt16(int16_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadInt16(int16_t* pData, file_offset_t WordCount) {
553          #if DEBUG          #if DEBUG_RIFF
554          std::cout << "Chunk::ReadInt16(int16_t*,file_offset_t)" << std::endl;          std::cout << "Chunk::ReadInt16(int16_t*,file_offset_t)" << std::endl;
555          #endif // DEBUG          #endif // DEBUG_RIFF
556          return ReadSceptical(pData, WordCount, 2);          return ReadSceptical(pData, WordCount, 2);
557      }      }
558    
# Line 570  namespace RIFF { Line 587  namespace RIFF {
587       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
588       */       */
589      file_offset_t Chunk::ReadUint16(uint16_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadUint16(uint16_t* pData, file_offset_t WordCount) {
590          #if DEBUG          #if DEBUG_RIFF
591          std::cout << "Chunk::ReadUint16(uint16_t*,file_offset_t)" << std::endl;          std::cout << "Chunk::ReadUint16(uint16_t*,file_offset_t)" << std::endl;
592          #endif // DEBUG          #endif // DEBUG_RIFF
593          return ReadSceptical(pData, WordCount, 2);          return ReadSceptical(pData, WordCount, 2);
594      }      }
595    
# Line 607  namespace RIFF { Line 624  namespace RIFF {
624       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
625       */       */
626      file_offset_t Chunk::ReadInt32(int32_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadInt32(int32_t* pData, file_offset_t WordCount) {
627          #if DEBUG          #if DEBUG_RIFF
628          std::cout << "Chunk::ReadInt32(int32_t*,file_offset_t)" << std::endl;          std::cout << "Chunk::ReadInt32(int32_t*,file_offset_t)" << std::endl;
629          #endif // DEBUG          #endif // DEBUG_RIFF
630          return ReadSceptical(pData, WordCount, 4);          return ReadSceptical(pData, WordCount, 4);
631      }      }
632    
# Line 644  namespace RIFF { Line 661  namespace RIFF {
661       *                          \a WordCount integers could be read!       *                          \a WordCount integers could be read!
662       */       */
663      file_offset_t Chunk::ReadUint32(uint32_t* pData, file_offset_t WordCount) {      file_offset_t Chunk::ReadUint32(uint32_t* pData, file_offset_t WordCount) {
664          #if DEBUG          #if DEBUG_RIFF
665          std::cout << "Chunk::ReadUint32(uint32_t*,file_offset_t)" << std::endl;          std::cout << "Chunk::ReadUint32(uint32_t*,file_offset_t)" << std::endl;
666          #endif // DEBUG          #endif // DEBUG_RIFF
667          return ReadSceptical(pData, WordCount, 4);          return ReadSceptical(pData, WordCount, 4);
668      }      }
669    
# Line 693  namespace RIFF { Line 710  namespace RIFF {
710       * @throws RIFF::Exception  if an error occurred       * @throws RIFF::Exception  if an error occurred
711       */       */
712      int8_t Chunk::ReadInt8() {      int8_t Chunk::ReadInt8() {
713          #if DEBUG          #if DEBUG_RIFF
714          std::cout << "Chunk::ReadInt8()" << std::endl;          std::cout << "Chunk::ReadInt8()" << std::endl;
715          #endif // DEBUG          #endif // DEBUG_RIFF
716          int8_t word;          int8_t word;
717          ReadSceptical(&word,1,1);          ReadSceptical(&word,1,1);
718          return word;          return word;
# Line 709  namespace RIFF { Line 726  namespace RIFF {
726       * @throws RIFF::Exception  if an error occurred       * @throws RIFF::Exception  if an error occurred
727       */       */
728      uint8_t Chunk::ReadUint8() {      uint8_t Chunk::ReadUint8() {
729          #if DEBUG          #if DEBUG_RIFF
730          std::cout << "Chunk::ReadUint8()" << std::endl;          std::cout << "Chunk::ReadUint8()" << std::endl;
731          #endif // DEBUG          #endif // DEBUG_RIFF
732          uint8_t word;          uint8_t word;
733          ReadSceptical(&word,1,1);          ReadSceptical(&word,1,1);
734          return word;          return word;
# Line 726  namespace RIFF { Line 743  namespace RIFF {
743       * @throws RIFF::Exception  if an error occurred       * @throws RIFF::Exception  if an error occurred
744       */       */
745      int16_t Chunk::ReadInt16() {      int16_t Chunk::ReadInt16() {
746          #if DEBUG          #if DEBUG_RIFF
747          std::cout << "Chunk::ReadInt16()" << std::endl;          std::cout << "Chunk::ReadInt16()" << std::endl;
748          #endif // DEBUG          #endif // DEBUG_RIFF
749          int16_t word;          int16_t word;
750          ReadSceptical(&word,1,2);          ReadSceptical(&word,1,2);
751          return word;          return word;
# Line 743  namespace RIFF { Line 760  namespace RIFF {
760       * @throws RIFF::Exception  if an error occurred       * @throws RIFF::Exception  if an error occurred
761       */       */
762      uint16_t Chunk::ReadUint16() {      uint16_t Chunk::ReadUint16() {
763          #if DEBUG          #if DEBUG_RIFF
764          std::cout << "Chunk::ReadUint16()" << std::endl;          std::cout << "Chunk::ReadUint16()" << std::endl;
765          #endif // DEBUG          #endif // DEBUG_RIFF
766          uint16_t word;          uint16_t word;
767          ReadSceptical(&word,1,2);          ReadSceptical(&word,1,2);
768          return word;          return word;
# Line 760  namespace RIFF { Line 777  namespace RIFF {
777       * @throws RIFF::Exception  if an error occurred       * @throws RIFF::Exception  if an error occurred
778       */       */
779      int32_t Chunk::ReadInt32() {      int32_t Chunk::ReadInt32() {
780          #if DEBUG          #if DEBUG_RIFF
781          std::cout << "Chunk::ReadInt32()" << std::endl;          std::cout << "Chunk::ReadInt32()" << std::endl;
782          #endif // DEBUG          #endif // DEBUG_RIFF
783          int32_t word;          int32_t word;
784          ReadSceptical(&word,1,4);          ReadSceptical(&word,1,4);
785          return word;          return word;
# Line 777  namespace RIFF { Line 794  namespace RIFF {
794       * @throws RIFF::Exception  if an error occurred       * @throws RIFF::Exception  if an error occurred
795       */       */
796      uint32_t Chunk::ReadUint32() {      uint32_t Chunk::ReadUint32() {
797          #if DEBUG          #if DEBUG_RIFF
798          std::cout << "Chunk::ReadUint32()" << std::endl;          std::cout << "Chunk::ReadUint32()" << std::endl;
799          #endif // DEBUG          #endif // DEBUG_RIFF
800          uint32_t word;          uint32_t word;
801          ReadSceptical(&word,1,4);          ReadSceptical(&word,1,4);
802          return word;          return word;
# Line 1008  namespace RIFF { Line 1025  namespace RIFF {
1025  // *  // *
1026    
1027      List::List(File* pFile) : Chunk(pFile) {      List::List(File* pFile) : Chunk(pFile) {
1028          #if DEBUG          #if DEBUG_RIFF
1029          std::cout << "List::List(File* pFile)" << std::endl;          std::cout << "List::List(File* pFile)" << std::endl;
1030          #endif // DEBUG          #endif // DEBUG_RIFF
1031          pSubChunks    = NULL;          pSubChunks    = NULL;
1032          pSubChunksMap = NULL;          pSubChunksMap = NULL;
1033      }      }
1034    
1035      List::List(File* pFile, file_offset_t StartPos, List* Parent)      List::List(File* pFile, file_offset_t StartPos, List* Parent)
1036        : Chunk(pFile, StartPos, Parent) {        : Chunk(pFile, StartPos, Parent) {
1037          #if DEBUG          #if DEBUG_RIFF
1038          std::cout << "List::List(File*,file_offset_t,List*)" << std::endl;          std::cout << "List::List(File*,file_offset_t,List*)" << std::endl;
1039          #endif // DEBUG          #endif // DEBUG_RIFF
1040          pSubChunks    = NULL;          pSubChunks    = NULL;
1041          pSubChunksMap = NULL;          pSubChunksMap = NULL;
1042          ReadHeader(StartPos);          ReadHeader(StartPos);
# Line 1034  namespace RIFF { Line 1051  namespace RIFF {
1051      }      }
1052    
1053      List::~List() {      List::~List() {
1054          #if DEBUG          #if DEBUG_RIFF
1055          std::cout << "List::~List()" << std::endl;          std::cout << "List::~List()" << std::endl;
1056          #endif // DEBUG          #endif // DEBUG_RIFF
1057          DeleteChunkList();          DeleteChunkList();
1058      }      }
1059    
# Line 1069  namespace RIFF { Line 1086  namespace RIFF {
1086       *                   that ID       *                   that ID
1087       */       */
1088      Chunk* List::GetSubChunk(uint32_t ChunkID) {      Chunk* List::GetSubChunk(uint32_t ChunkID) {
1089          #if DEBUG          #if DEBUG_RIFF
1090          std::cout << "List::GetSubChunk(uint32_t)" << std::endl;          std::cout << "List::GetSubChunk(uint32_t)" << std::endl;
1091          #endif // DEBUG          #endif // DEBUG_RIFF
1092          if (!pSubChunksMap) LoadSubChunks();          if (!pSubChunksMap) LoadSubChunks();
1093          return (*pSubChunksMap)[ChunkID];          return (*pSubChunksMap)[ChunkID];
1094      }      }
# Line 1088  namespace RIFF { Line 1105  namespace RIFF {
1105       *                    that type       *                    that type
1106       */       */
1107      List* List::GetSubList(uint32_t ListType) {      List* List::GetSubList(uint32_t ListType) {
1108          #if DEBUG          #if DEBUG_RIFF
1109          std::cout << "List::GetSubList(uint32_t)" << std::endl;          std::cout << "List::GetSubList(uint32_t)" << std::endl;
1110          #endif // DEBUG          #endif // DEBUG_RIFF
1111          if (!pSubChunks) LoadSubChunks();          if (!pSubChunks) LoadSubChunks();
1112          ChunkList::iterator iter = pSubChunks->begin();          ChunkList::iterator iter = pSubChunks->begin();
1113          ChunkList::iterator end  = pSubChunks->end();          ChunkList::iterator end  = pSubChunks->end();
# Line 1114  namespace RIFF { Line 1131  namespace RIFF {
1131       *            otherwise       *            otherwise
1132       */       */
1133      Chunk* List::GetFirstSubChunk() {      Chunk* List::GetFirstSubChunk() {
1134          #if DEBUG          #if DEBUG_RIFF
1135          std::cout << "List::GetFirstSubChunk()" << std::endl;          std::cout << "List::GetFirstSubChunk()" << std::endl;
1136          #endif // DEBUG          #endif // DEBUG_RIFF
1137          if (!pSubChunks) LoadSubChunks();          if (!pSubChunks) LoadSubChunks();
1138          ChunksIterator = pSubChunks->begin();          ChunksIterator = pSubChunks->begin();
1139          return (ChunksIterator != pSubChunks->end()) ? *ChunksIterator : NULL;          return (ChunksIterator != pSubChunks->end()) ? *ChunksIterator : NULL;
# Line 1131  namespace RIFF { Line 1148  namespace RIFF {
1148       *            end of list is reached       *            end of list is reached
1149       */       */
1150      Chunk* List::GetNextSubChunk() {      Chunk* List::GetNextSubChunk() {
1151          #if DEBUG          #if DEBUG_RIFF
1152          std::cout << "List::GetNextSubChunk()" << std::endl;          std::cout << "List::GetNextSubChunk()" << std::endl;
1153          #endif // DEBUG          #endif // DEBUG_RIFF
1154          if (!pSubChunks) return NULL;          if (!pSubChunks) return NULL;
1155          ChunksIterator++;          ChunksIterator++;
1156          return (ChunksIterator != pSubChunks->end()) ? *ChunksIterator : NULL;          return (ChunksIterator != pSubChunks->end()) ? *ChunksIterator : NULL;
# Line 1149  namespace RIFF { Line 1166  namespace RIFF {
1166       *            otherwise       *            otherwise
1167       */       */
1168      List* List::GetFirstSubList() {      List* List::GetFirstSubList() {
1169          #if DEBUG          #if DEBUG_RIFF
1170          std::cout << "List::GetFirstSubList()" << std::endl;          std::cout << "List::GetFirstSubList()" << std::endl;
1171          #endif // DEBUG          #endif // DEBUG_RIFF
1172          if (!pSubChunks) LoadSubChunks();          if (!pSubChunks) LoadSubChunks();
1173          ListIterator            = pSubChunks->begin();          ListIterator            = pSubChunks->begin();
1174          ChunkList::iterator end = pSubChunks->end();          ChunkList::iterator end = pSubChunks->end();
# Line 1171  namespace RIFF { Line 1188  namespace RIFF {
1188       *            end of list is reached       *            end of list is reached
1189       */       */
1190      List* List::GetNextSubList() {      List* List::GetNextSubList() {
1191          #if DEBUG          #if DEBUG_RIFF
1192          std::cout << "List::GetNextSubList()" << std::endl;          std::cout << "List::GetNextSubList()" << std::endl;
1193          #endif // DEBUG          #endif // DEBUG_RIFF
1194          if (!pSubChunks) return NULL;          if (!pSubChunks) return NULL;
1195          if (ListIterator == pSubChunks->end()) return NULL;          if (ListIterator == pSubChunks->end()) return NULL;
1196          ListIterator++;          ListIterator++;
# Line 1375  namespace RIFF { Line 1392  namespace RIFF {
1392      }      }
1393    
1394      void List::ReadHeader(file_offset_t filePos) {      void List::ReadHeader(file_offset_t filePos) {
1395          #if DEBUG          #if DEBUG_RIFF
1396          std::cout << "List::Readheader(file_offset_t) ";          std::cout << "List::Readheader(file_offset_t) ";
1397          #endif // DEBUG          #endif // DEBUG_RIFF
1398          Chunk::ReadHeader(filePos);          Chunk::ReadHeader(filePos);
1399          if (ullCurrentChunkSize < 4) return;          if (ullCurrentChunkSize < 4) return;
1400          ullNewChunkSize = ullCurrentChunkSize -= 4;          ullNewChunkSize = ullCurrentChunkSize -= 4;
# Line 1394  namespace RIFF { Line 1411  namespace RIFF {
1411          fseeko(pFile->hFileRead, filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize), SEEK_SET);          fseeko(pFile->hFileRead, filePos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize), SEEK_SET);
1412          fread(&ListType, 4, 1, pFile->hFileRead);          fread(&ListType, 4, 1, pFile->hFileRead);
1413          #endif // POSIX          #endif // POSIX
1414          #if DEBUG          #if DEBUG_RIFF
1415          std::cout << "listType=" << convertToString(ListType) << std::endl;          std::cout << "listType=" << convertToString(ListType) << std::endl;
1416          #endif // DEBUG          #endif // DEBUG_RIFF
1417          if (!pFile->bEndianNative) {          if (!pFile->bEndianNative) {
1418              //swapBytes_32(&ListType);              //swapBytes_32(&ListType);
1419          }          }
# Line 1423  namespace RIFF { Line 1440  namespace RIFF {
1440      }      }
1441    
1442      void List::LoadSubChunks(progress_t* pProgress) {      void List::LoadSubChunks(progress_t* pProgress) {
1443          #if DEBUG          #if DEBUG_RIFF
1444          std::cout << "List::LoadSubChunks()";          std::cout << "List::LoadSubChunks()";
1445          #endif // DEBUG          #endif // DEBUG_RIFF
1446          if (!pSubChunks) {          if (!pSubChunks) {
1447              pSubChunks    = new ChunkList();              pSubChunks    = new ChunkList();
1448              pSubChunksMap = new ChunkMap();              pSubChunksMap = new ChunkMap();
# Line 1440  namespace RIFF { Line 1457  namespace RIFF {
1457                  Chunk* ck;                  Chunk* ck;
1458                  uint32_t ckid;                  uint32_t ckid;
1459                  Read(&ckid, 4, 1);                  Read(&ckid, 4, 1);
1460                  #if DEBUG                  #if DEBUG_RIFF
1461                  std::cout << " ckid=" << convertToString(ckid) << std::endl;                  std::cout << " ckid=" << convertToString(ckid) << std::endl;
1462                  #endif // DEBUG                  #endif // DEBUG_RIFF
1463                  if (ckid == CHUNK_ID_LIST) {                  if (ckid == CHUNK_ID_LIST) {
1464                      ck = new RIFF::List(pFile, ullStartPos + ullPos - 4, this);                      ck = new RIFF::List(pFile, ullStartPos + ullPos - 4, this);
1465                      SetPos(ck->GetSize() + LIST_HEADER_SIZE(pFile->FileOffsetSize) - 4, RIFF::stream_curpos);                      SetPos(ck->GetSize() + LIST_HEADER_SIZE(pFile->FileOffsetSize) - 4, RIFF::stream_curpos);
# Line 1583  namespace RIFF { Line 1600  namespace RIFF {
1600          : List(this), Filename(path), bIsNewFile(false), Layout(layout_standard),          : List(this), Filename(path), bIsNewFile(false), Layout(layout_standard),
1601            FileOffsetPreference(offset_size_auto)            FileOffsetPreference(offset_size_auto)
1602      {      {
1603          #if DEBUG          #if DEBUG_RIFF
1604          std::cout << "File::File("<<path<<")" << std::endl;          std::cout << "File::File("<<path<<")" << std::endl;
1605          #endif // DEBUG          #endif // DEBUG_RIFF
1606          bEndianNative = true;          bEndianNative = true;
1607          FileOffsetSize = 4;          FileOffsetSize = 4;
1608          try {          try {
# Line 1812  namespace RIFF { Line 1829  namespace RIFF {
1829                      #if POSIX                      #if POSIX
1830                      if (hFileRead)  close(hFileRead);                      if (hFileRead)  close(hFileRead);
1831                      if (hFileWrite) close(hFileWrite);                      if (hFileWrite) close(hFileWrite);
1832                        hFileRead = hFileWrite = 0;
1833                      #elif defined(WIN32)                      #elif defined(WIN32)
1834                      if (hFileRead  != INVALID_HANDLE_VALUE) CloseHandle(hFileRead);                      if (hFileRead  != INVALID_HANDLE_VALUE) CloseHandle(hFileRead);
1835                      if (hFileWrite != INVALID_HANDLE_VALUE) CloseHandle(hFileWrite);                      if (hFileWrite != INVALID_HANDLE_VALUE) CloseHandle(hFileWrite);
1836                        hFileRead = hFileWrite = INVALID_HANDLE_VALUE;
1837                      #else                      #else
1838                      if (hFileRead)  fclose(hFileRead);                      if (hFileRead)  fclose(hFileRead);
1839                      if (hFileWrite) fclose(hFileWrite);                      if (hFileWrite) fclose(hFileWrite);
1840                        hFileRead = hFileWrite = NULL;
1841                      #endif                      #endif
                     hFileRead = hFileWrite = 0;  
1842                      break;                      break;
1843                  default:                  default:
1844                      throw Exception("Unknown file access mode");                      throw Exception("Unknown file access mode");
# Line 2079  namespace RIFF { Line 2098  namespace RIFF {
2098      }      }
2099    
2100      File::~File() {      File::~File() {
2101          #if DEBUG          #if DEBUG_RIFF
2102          std::cout << "File::~File()" << std::endl;          std::cout << "File::~File()" << std::endl;
2103          #endif // DEBUG          #endif // DEBUG_RIFF
2104          Cleanup();          Cleanup();
2105      }      }
2106    
# Line 2251  namespace RIFF { Line 2270  namespace RIFF {
2270  // *************** Exception ***************  // *************** Exception ***************
2271  // *  // *
2272    
2273        Exception::Exception() {
2274        }
2275    
2276        Exception::Exception(String format, ...) {
2277            va_list arg;
2278            va_start(arg, format);
2279            Message = assemble(format, arg);
2280            va_end(arg);
2281        }
2282    
2283        Exception::Exception(String format, va_list arg) {
2284            Message = assemble(format, arg);
2285        }
2286    
2287      void Exception::PrintMessage() {      void Exception::PrintMessage() {
2288          std::cout << "RIFF::Exception: " << Message << std::endl;          std::cout << "RIFF::Exception: " << Message << std::endl;
2289      }      }
2290    
2291        String Exception::assemble(String format, va_list arg) {
2292            char* buf = NULL;
2293            vasprintf(&buf, format.c_str(), arg);
2294            String s = buf;
2295            free(buf);
2296            return s;
2297        }
2298    
2299    
2300  // *************** functions ***************  // *************** functions ***************
2301  // *  // *

Legend:
Removed from v.3053  
changed lines
  Added in v.3478

  ViewVC Help
Powered by ViewVC