/[svn]/libgig/trunk/src/helper.h
ViewVC logotype

Diff of /libgig/trunk/src/helper.h

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

revision 1179 by persson, Sat May 12 11:25:04 2007 UTC revision 2682 by schoenebeck, Mon Dec 29 16:25:51 2014 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-2006 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2014 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 28  Line 28 
28  #include <string>  #include <string>
29  #include <sstream>  #include <sstream>
30    
31    #if defined(WIN32) && !HAVE_CONFIG_H
32    # include "../win32/libgig_private.h" // like config.h, automatically generated by Dev-C++
33    # define PACKAGE "libgig"
34    # define VERSION VER_STRING // VER_STRING defined in libgig_private.h
35    #endif // WIN32
36    
37  #include "RIFF.h"  #include "RIFF.h"
38    
39  // *************** Helper Functions **************  // *************** Helper Functions **************
# Line 80  inline void store32(uint8_t* pData, uint Line 86  inline void store32(uint8_t* pData, uint
86   * @param WordSize - size of the data words (in bytes)   * @param WordSize - size of the data words (in bytes)
87   */   */
88  inline void SwapMemoryArea(void* pData, unsigned long AreaSize, uint WordSize) {  inline void SwapMemoryArea(void* pData, unsigned long AreaSize, uint WordSize) {
89        if (!AreaSize) return; // AreaSize==0 would cause a segfault here
90      switch (WordSize) { // TODO: unefficient      switch (WordSize) { // TODO: unefficient
91          case 1: {          case 1: {
92              uint8_t* pDst = (uint8_t*) pData;              uint8_t* pDst = (uint8_t*) pData;
# Line 122  inline void SwapMemoryArea(void* pData, Line 129  inline void SwapMemoryArea(void* pData,
129                  memcpy((uint8_t*) pData + lo, (uint8_t*) pData + hi, WordSize);                  memcpy((uint8_t*) pData + lo, (uint8_t*) pData + hi, WordSize);
130                  memcpy((uint8_t*) pData + hi, pCache, WordSize);                  memcpy((uint8_t*) pData + hi, pCache, WordSize);
131              }              }
132              delete[] pCache;              if (pCache) delete[] pCache;
133              break;              break;
134          }          }
135      }      }
# Line 168  inline void SaveString(uint32_t ChunkID, Line 175  inline void SaveString(uint32_t ChunkID,
175          ck->Resize(size);          ck->Resize(size);
176          char* pData = (char*) ck->LoadChunkData();          char* pData = (char*) ck->LoadChunkData();
177          strncpy(pData, s.c_str(), size);          strncpy(pData, s.c_str(), size);
178      } else if (s != "" || sDefault != "") { // create chunk      } else if (s != "" || sDefault != "" || bUseFixedLengthStrings) { // create chunk
179          const std::string& sToSave = (s != "") ? s : sDefault;          const std::string& sToSave = (s != "") ? s : sDefault;
180          if (!bUseFixedLengthStrings) size = sToSave.size() + 1;          if (!bUseFixedLengthStrings) size = sToSave.size() + 1;
181          ck = lstINFO->AddSubChunk(ChunkID, size);          ck = lstINFO->AddSubChunk(ChunkID, size);
# Line 177  inline void SaveString(uint32_t ChunkID, Line 184  inline void SaveString(uint32_t ChunkID,
184      }      }
185  }  }
186    
187    // private helper function to convert progress of a subprocess into the global progress
188    inline void __notify_progress(RIFF::progress_t* pProgress, float subprogress) {
189        if (pProgress && pProgress->callback) {
190            const float totalrange    = pProgress->__range_max - pProgress->__range_min;
191            const float totalprogress = pProgress->__range_min + subprogress * totalrange;
192            pProgress->factor         = totalprogress;
193            pProgress->callback(pProgress); // now actually notify about the progress
194        }
195    }
196    
197    // private helper function to divide a progress into subprogresses
198    inline void __divide_progress(RIFF::progress_t* pParentProgress, RIFF::progress_t* pSubProgress, float totalTasks, float currentTask) {
199        if (pParentProgress && pParentProgress->callback) {
200            const float totalrange    = pParentProgress->__range_max - pParentProgress->__range_min;
201            pSubProgress->callback    = pParentProgress->callback;
202            pSubProgress->custom      = pParentProgress->custom;
203            pSubProgress->__range_min = pParentProgress->__range_min + totalrange * currentTask / totalTasks;
204            pSubProgress->__range_max = pSubProgress->__range_min + totalrange / totalTasks;
205        }
206    }
207    
208  #endif // __LIBGIG_HELPER_H__  #endif // __LIBGIG_HELPER_H__

Legend:
Removed from v.1179  
changed lines
  Added in v.2682

  ViewVC Help
Powered by ViewVC