/[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 2685 by schoenebeck, Sat Jan 3 21:44:42 2015 UTC revision 2703 by schoenebeck, Tue Jan 13 15:28:37 2015 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-2014 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2015 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 1475  namespace RIFF { Line 1475  namespace RIFF {
1475  // *************** File ***************  // *************** File ***************
1476  // *  // *
1477    
 //HACK: to avoid breaking DLL compatibility to older versions of libgig we roll the new std::set<Chunk*> into the old std::list<Chunk*> container, should be replaced on member variable level soon though  
 #define _GET_RESIZED_CHUNKS() \  
         (reinterpret_cast<std::set<Chunk*>*>(ResizedChunks.front()))  
   
1478      /** @brief Create new RIFF file.      /** @brief Create new RIFF file.
1479       *       *
1480       * Use this constructor if you want to create a new RIFF file completely       * Use this constructor if you want to create a new RIFF file completely
# Line 1496  namespace RIFF { Line 1492  namespace RIFF {
1492      File::File(uint32_t FileType)      File::File(uint32_t FileType)
1493          : List(this), bIsNewFile(true), Layout(layout_standard)          : List(this), bIsNewFile(true), Layout(layout_standard)
1494      {      {
         //HACK: see _GET_RESIZED_CHUNKS() comment  
         ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>));  
1495          #if defined(WIN32)          #if defined(WIN32)
1496          hFileRead = hFileWrite = INVALID_HANDLE_VALUE;          hFileRead = hFileWrite = INVALID_HANDLE_VALUE;
1497          #else          #else
# Line 1585  namespace RIFF { Line 1579  namespace RIFF {
1579       *                         given RIFF file or RIFF-alike file       *                         given RIFF file or RIFF-alike file
1580       */       */
1581      void File::__openExistingFile(const String& path, uint32_t* FileType) {      void File::__openExistingFile(const String& path, uint32_t* FileType) {
1582          //HACK: see _GET_RESIZED_CHUNKS() comment          ResizedChunks.clear();
         ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>));  
1583          #if POSIX          #if POSIX
1584          hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK);          hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK);
1585          if (hFileRead == -1) {          if (hFileRead == -1) {
# Line 1814  namespace RIFF { Line 1807  namespace RIFF {
1807    
1808          // first we sum up all positive chunk size changes (and skip all negative ones)          // first we sum up all positive chunk size changes (and skip all negative ones)
1809          unsigned long ulPositiveSizeDiff = 0;          unsigned long ulPositiveSizeDiff = 0;
1810          std::set<Chunk*>* resizedChunks = _GET_RESIZED_CHUNKS();          for (std::set<Chunk*>::const_iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) {
         for (std::set<Chunk*>::const_iterator iter = resizedChunks->begin(), end = resizedChunks->end(); iter != end; ++iter) {  
1811              if ((*iter)->GetNewSize() == 0) {              if ((*iter)->GetNewSize() == 0) {
1812                  throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(*iter));                  throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(*iter));
1813              }              }
# Line 1886  namespace RIFF { Line 1878  namespace RIFF {
1878          if (ulTotalSize < ulActualSize) ResizeFile(ulTotalSize);          if (ulTotalSize < ulActualSize) ResizeFile(ulTotalSize);
1879    
1880          // forget all resized chunks          // forget all resized chunks
1881          resizedChunks->clear();          ResizedChunks.clear();
1882    
1883          __notify_progress(pProgress, 1.0); // notify done          __notify_progress(pProgress, 1.0); // notify done
1884      }      }
# Line 1968  namespace RIFF { Line 1960  namespace RIFF {
1960          if (ulTotalSize < ulActualSize) ResizeFile(ulTotalSize);          if (ulTotalSize < ulActualSize) ResizeFile(ulTotalSize);
1961    
1962          // forget all resized chunks          // forget all resized chunks
1963          _GET_RESIZED_CHUNKS()->clear();          ResizedChunks.clear();
1964    
1965          #if POSIX          #if POSIX
1966          if (hFileWrite) close(hFileWrite);          if (hFileWrite) close(hFileWrite);
# Line 2028  namespace RIFF { Line 2020  namespace RIFF {
2020          #endif // POSIX          #endif // POSIX
2021          DeleteChunkList();          DeleteChunkList();
2022          pFile = NULL;          pFile = NULL;
2023          //HACK: see _GET_RESIZED_CHUNKS() comment          ResizedChunks.clear();
         delete _GET_RESIZED_CHUNKS();  
2024      }      }
2025    
2026      void File::LogAsResized(Chunk* pResizedChunk) {      void File::LogAsResized(Chunk* pResizedChunk) {
2027          _GET_RESIZED_CHUNKS()->insert(pResizedChunk);          ResizedChunks.insert(pResizedChunk);
2028      }      }
2029    
2030      void File::UnlogResized(Chunk* pResizedChunk) {      void File::UnlogResized(Chunk* pResizedChunk) {
2031          _GET_RESIZED_CHUNKS()->erase(pResizedChunk);          ResizedChunks.erase(pResizedChunk);
2032      }      }
2033    
2034      unsigned long File::GetFileSize() {      unsigned long File::GetFileSize() {

Legend:
Removed from v.2685  
changed lines
  Added in v.2703

  ViewVC Help
Powered by ViewVC