/[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 3487 by schoenebeck, Fri Feb 22 12:12:50 2019 UTC revision 3488 by schoenebeck, Thu Feb 28 17:49:07 2019 UTC
# Line 1026  namespace RIFF { Line 1026  namespace RIFF {
1026          ullCurrentChunkSize = ullNewChunkSize;          ullCurrentChunkSize = ullNewChunkSize;
1027          WriteHeader(ullOriginalPos);          WriteHeader(ullOriginalPos);
1028    
1029          __notify_progress(pProgress, 1.0); // notify done          if (pProgress)
1030                __notify_progress(pProgress, 1.0); // notify done
1031    
1032          // update chunk's position pointers          // update chunk's position pointers
1033          ullStartPos = ullOriginalPos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize);          ullStartPos = ullOriginalPos + CHUNK_HEADER_SIZE(pFile->FileOffsetSize);
# Line 1513  namespace RIFF { Line 1514  namespace RIFF {
1514              }              }
1515              SetPos(ullOriginalPos); // restore position before this call              SetPos(ullOriginalPos); // restore position before this call
1516          }          }
1517          __notify_progress(pProgress, 1.0); // notify done          if (pProgress)
1518                __notify_progress(pProgress, 1.0); // notify done
1519      }      }
1520    
1521      void List::LoadSubChunksRecursively(progress_t* pProgress) {      void List::LoadSubChunksRecursively(progress_t* pProgress) {
1522          const int n = (int) CountSubLists();          const int n = (int) CountSubLists();
1523          int i = 0;          int i = 0;
1524          for (List* pList = GetFirstSubList(); pList; pList = GetNextSubList(), ++i) {          for (List* pList = GetFirstSubList(); pList; pList = GetNextSubList(), ++i) {
1525              // divide local progress into subprogress              if (pProgress) {
1526              progress_t subprogress;                  // divide local progress into subprogress
1527              __divide_progress(pProgress, &subprogress, n, i);                  progress_t subprogress;
1528              // do the actual work                  __divide_progress(pProgress, &subprogress, n, i);
1529              pList->LoadSubChunksRecursively(&subprogress);                  // do the actual work
1530                    pList->LoadSubChunksRecursively(&subprogress);
1531                } else
1532                    pList->LoadSubChunksRecursively(NULL);
1533          }          }
1534          __notify_progress(pProgress, 1.0); // notify done          if (pProgress)
1535                __notify_progress(pProgress, 1.0); // notify done
1536      }      }
1537    
1538      /** @brief Write list chunk persistently e.g. to disk.      /** @brief Write list chunk persistently e.g. to disk.
# Line 1556  namespace RIFF { Line 1562  namespace RIFF {
1562              size_t i = 0;              size_t i = 0;
1563              const size_t n = pSubChunks->size();              const size_t n = pSubChunks->size();
1564              for (ChunkList::iterator iter = pSubChunks->begin(), end = pSubChunks->end(); iter != end; ++iter, ++i) {              for (ChunkList::iterator iter = pSubChunks->begin(), end = pSubChunks->end(); iter != end; ++iter, ++i) {
1565                  // divide local progress into subprogress for loading current Instrument                  if (pProgress) {
1566                  progress_t subprogress;                      // divide local progress into subprogress for loading current Instrument
1567                  __divide_progress(pProgress, &subprogress, n, i);                      progress_t subprogress;
1568                  // do the actual work                      __divide_progress(pProgress, &subprogress, n, i);
1569                  ullWritePos = (*iter)->WriteChunk(ullWritePos, ullCurrentDataOffset, &subprogress);                      // do the actual work
1570                        ullWritePos = (*iter)->WriteChunk(ullWritePos, ullCurrentDataOffset, &subprogress);
1571                    } else
1572                        ullWritePos = (*iter)->WriteChunk(ullWritePos, ullCurrentDataOffset, NULL);
1573              }              }
1574          }          }
1575    
# Line 1571  namespace RIFF { Line 1580  namespace RIFF {
1580          // offset of this list chunk in new written file may have changed          // offset of this list chunk in new written file may have changed
1581          ullStartPos = ullOriginalPos + LIST_HEADER_SIZE(pFile->FileOffsetSize);          ullStartPos = ullOriginalPos + LIST_HEADER_SIZE(pFile->FileOffsetSize);
1582    
1583           __notify_progress(pProgress, 1.0); // notify done          if (pProgress)
1584                __notify_progress(pProgress, 1.0); // notify done
1585    
1586          return ullWritePos;          return ullWritePos;
1587      }      }
# Line 1920  namespace RIFF { Line 1930  namespace RIFF {
1930              throw Exception("Saving a RIFF file with layout_flat is not implemented yet");              throw Exception("Saving a RIFF file with layout_flat is not implemented yet");
1931    
1932          // make sure the RIFF tree is built (from the original file)          // make sure the RIFF tree is built (from the original file)
1933          {          if (pProgress) {
1934              // divide progress into subprogress              // divide progress into subprogress
1935              progress_t subprogress;              progress_t subprogress;
1936              __divide_progress(pProgress, &subprogress, 3.f, 0.f); // arbitrarily subdivided into 1/3 of total progress              __divide_progress(pProgress, &subprogress, 3.f, 0.f); // arbitrarily subdivided into 1/3 of total progress
# Line 1928  namespace RIFF { Line 1938  namespace RIFF {
1938              LoadSubChunksRecursively(&subprogress);              LoadSubChunksRecursively(&subprogress);
1939              // notify subprogress done              // notify subprogress done
1940              __notify_progress(&subprogress, 1.f);              __notify_progress(&subprogress, 1.f);
1941          }          } else
1942                LoadSubChunksRecursively(NULL);
1943    
1944          // reopen file in write mode          // reopen file in write mode
1945          SetMode(stream_mode_read_write);          SetMode(stream_mode_read_write);
# Line 1958  namespace RIFF { Line 1969  namespace RIFF {
1969    
1970              // divide progress into subprogress              // divide progress into subprogress
1971              progress_t subprogress;              progress_t subprogress;
1972              __divide_progress(pProgress, &subprogress, 3.f, 1.f); // arbitrarily subdivided into 1/3 of total progress              if (pProgress)
1973                    __divide_progress(pProgress, &subprogress, 3.f, 1.f); // arbitrarily subdivided into 1/3 of total progress
1974    
1975              // ... we enlarge this file first ...              // ... we enlarge this file first ...
1976              ResizeFile(newFileSize);              ResizeFile(newFileSize);
# Line 1992  namespace RIFF { Line 2004  namespace RIFF {
2004                  fseeko(hFileWrite, ullPos + positiveSizeDiff, SEEK_SET);                  fseeko(hFileWrite, ullPos + positiveSizeDiff, SEEK_SET);
2005                  iBytesMoved = fwrite(pCopyBuffer, 1, iBytesMoved, hFileWrite);                  iBytesMoved = fwrite(pCopyBuffer, 1, iBytesMoved, hFileWrite);
2006                  #endif                  #endif
2007                  if (!(iNotif % 8) && iBytesMoved > 0)                  if (pProgress && !(iNotif % 8) && iBytesMoved > 0)
2008                      __notify_progress(&subprogress, float(workingFileSize - ullPos) / float(workingFileSize));                      __notify_progress(&subprogress, float(workingFileSize - ullPos) / float(workingFileSize));
2009              }              }
2010              delete[] pCopyBuffer;              delete[] pCopyBuffer;
2011              if (iBytesMoved < 0) throw Exception("Could not modify file while trying to enlarge it");              if (iBytesMoved < 0) throw Exception("Could not modify file while trying to enlarge it");
2012    
2013              __notify_progress(&subprogress, 1.f); // notify subprogress done              if (pProgress)
2014                    __notify_progress(&subprogress, 1.f); // notify subprogress done
2015          }          }
2016    
2017          // rebuild / rewrite complete RIFF tree ...          // rebuild / rewrite complete RIFF tree ...
2018    
2019          // divide progress into subprogress          // divide progress into subprogress
2020          progress_t subprogress;          progress_t subprogress;
2021          __divide_progress(pProgress, &subprogress, 3.f, 2.f); // arbitrarily subdivided into 1/3 of total progress          if (pProgress)
2022                __divide_progress(pProgress, &subprogress, 3.f, 2.f); // arbitrarily subdivided into 1/3 of total progress
2023          // do the actual work          // do the actual work
2024          const file_offset_t finalSize = WriteChunk(0, positiveSizeDiff, &subprogress);          const file_offset_t finalSize = WriteChunk(0, positiveSizeDiff, pProgress ? &subprogress : NULL);
2025          const file_offset_t finalActualSize = __GetFileSize(hFileWrite);          const file_offset_t finalActualSize = __GetFileSize(hFileWrite);
2026          // notify subprogress done          // notify subprogress done
2027          __notify_progress(&subprogress, 1.f);          if (pProgress)
2028                __notify_progress(&subprogress, 1.f);
2029    
2030          // resize file to the final size          // resize file to the final size
2031          if (finalSize < finalActualSize) ResizeFile(finalSize);          if (finalSize < finalActualSize) ResizeFile(finalSize);
2032    
2033          __notify_progress(pProgress, 1.0); // notify done          if (pProgress)
2034                __notify_progress(pProgress, 1.0); // notify done
2035      }      }
2036    
2037      /** @brief Save changes to another file.      /** @brief Save changes to another file.
# Line 2040  namespace RIFF { Line 2056  namespace RIFF {
2056              throw Exception("Saving a RIFF file with layout_flat is not implemented yet");              throw Exception("Saving a RIFF file with layout_flat is not implemented yet");
2057    
2058          // make sure the RIFF tree is built (from the original file)          // make sure the RIFF tree is built (from the original file)
2059          {          if (pProgress) {
2060              // divide progress into subprogress              // divide progress into subprogress
2061              progress_t subprogress;              progress_t subprogress;
2062              __divide_progress(pProgress, &subprogress, 2.f, 0.f); // arbitrarily subdivided into 1/2 of total progress              __divide_progress(pProgress, &subprogress, 2.f, 0.f); // arbitrarily subdivided into 1/2 of total progress
# Line 2048  namespace RIFF { Line 2064  namespace RIFF {
2064              LoadSubChunksRecursively(&subprogress);              LoadSubChunksRecursively(&subprogress);
2065              // notify subprogress done              // notify subprogress done
2066              __notify_progress(&subprogress, 1.f);              __notify_progress(&subprogress, 1.f);
2067          }          } else
2068                LoadSubChunksRecursively(NULL);
2069    
2070          if (!bIsNewFile) SetMode(stream_mode_read);          if (!bIsNewFile) SetMode(stream_mode_read);
2071          // open the other (new) file for writing and truncate it to zero size          // open the other (new) file for writing and truncate it to zero size
# Line 2087  namespace RIFF { Line 2104  namespace RIFF {
2104    
2105          // write complete RIFF tree to the other (new) file          // write complete RIFF tree to the other (new) file
2106          file_offset_t ullTotalSize;          file_offset_t ullTotalSize;
2107          {          if (pProgress) {
2108              // divide progress into subprogress              // divide progress into subprogress
2109              progress_t subprogress;              progress_t subprogress;
2110              __divide_progress(pProgress, &subprogress, 2.f, 1.f); // arbitrarily subdivided into 1/2 of total progress              __divide_progress(pProgress, &subprogress, 2.f, 1.f); // arbitrarily subdivided into 1/2 of total progress
# Line 2095  namespace RIFF { Line 2112  namespace RIFF {
2112              ullTotalSize = WriteChunk(0, 0, &subprogress);              ullTotalSize = WriteChunk(0, 0, &subprogress);
2113              // notify subprogress done              // notify subprogress done
2114              __notify_progress(&subprogress, 1.f);              __notify_progress(&subprogress, 1.f);
2115          }          } else
2116                ullTotalSize = WriteChunk(0, 0, NULL);
2117    
2118          file_offset_t ullActualSize = __GetFileSize(hFileWrite);          file_offset_t ullActualSize = __GetFileSize(hFileWrite);
2119    
2120          // resize file to the final size (if the file was originally larger)          // resize file to the final size (if the file was originally larger)
# Line 2116  namespace RIFF { Line 2135  namespace RIFF {
2135          Mode = (stream_mode_t) -1;       // Just set it to an undefined mode ...          Mode = (stream_mode_t) -1;       // Just set it to an undefined mode ...
2136          SetMode(stream_mode_read_write); // ... so SetMode() has to reopen the file handles.          SetMode(stream_mode_read_write); // ... so SetMode() has to reopen the file handles.
2137    
2138          __notify_progress(pProgress, 1.0); // notify done          if (pProgress)
2139                __notify_progress(pProgress, 1.0); // notify done
2140      }      }
2141    
2142      void File::ResizeFile(file_offset_t ullNewSize) {      void File::ResizeFile(file_offset_t ullNewSize) {

Legend:
Removed from v.3487  
changed lines
  Added in v.3488

  ViewVC Help
Powered by ViewVC