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

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

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

revision 918 by persson, Sat Sep 2 08:45:37 2006 UTC revision 933 by schoenebeck, Fri Nov 24 12:50:05 2006 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file loader library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2005 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2006 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 228  namespace DLS { Line 228  namespace DLS {
228    
229      /** @brief Constructor.      /** @brief Constructor.
230       *       *
231       * Initializes the info strings with values provided by a INFO list chunk.       * Initializes the info strings with values provided by an INFO list chunk.
232       *       *
233       * @param list - pointer to a list chunk which contains a INFO list chunk       * @param list - pointer to a list chunk which contains an INFO list chunk
234       */       */
235      Info::Info(RIFF::List* list) {      Info::Info(RIFF::List* list) {
236          UseFixedLengthStrings = false;          UseFixedLengthStrings = false;
# Line 254  namespace DLS { Line 254  namespace DLS {
254                  LoadString(CHUNK_ID_ISRC, lstINFO, Source);                  LoadString(CHUNK_ID_ISRC, lstINFO, Source);
255                  LoadString(CHUNK_ID_ISRF, lstINFO, SourceForm);                  LoadString(CHUNK_ID_ISRF, lstINFO, SourceForm);
256                  LoadString(CHUNK_ID_ICMS, lstINFO, Commissioned);                  LoadString(CHUNK_ID_ICMS, lstINFO, Commissioned);
257                    LoadString(CHUNK_ID_ISBJ, lstINFO, Subject);
258              }              }
259          }          }
260      }      }
# Line 268  namespace DLS { Line 269  namespace DLS {
269       */       */
270      void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {      void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
271          RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);          RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
272          if (ck) {          ::LoadString(ck, s); // function from helper.h
             const char* str = (char*)ck->LoadChunkData();  
             int size = ck->GetSize();  
             int len;  
             for (len = 0 ; len < size ; len++)  
                 if (str[len] == '\0') break;  
             s.assign(str, len);  
             ck->ReleaseChunkData();  
         }  
273      }      }
274    
275      /** @brief Apply given INFO field to the respective chunk.      /** @brief Apply given INFO field to the respective chunk.
# Line 293  namespace DLS { Line 286  namespace DLS {
286       * @param lstINFO  - parent (INFO) RIFF list chunk       * @param lstINFO  - parent (INFO) RIFF list chunk
287       * @param s        - current value of info field       * @param s        - current value of info field
288       * @param sDefault - default value       * @param sDefault - default value
289       * @param size     - wanted size of the INFO chunk. This is ignored if UseFixedLengthStrings is false.       * @param bUseFixedLengthStrings - should a specific string size be forced in the chunk?
290         * @param size     - wanted size of the INFO chunk. This is ignored if bUseFixedLengthStrings is false.
291       */       */
292      void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault, int size) {      void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault, bool bUseFixedLengthStrings, int size) {
293          RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);          RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
294          if (ck) { // if chunk exists already, use 's' as value          ::SaveString(ChunkID, ck, lstINFO, s, sDefault, bUseFixedLengthStrings, size); // function from helper.h
             if (!UseFixedLengthStrings) size = s.size() + 1;  
             ck->Resize(size);  
             char* pData = (char*) ck->LoadChunkData();  
             strncpy(pData, s.c_str(), size);  
         } else if (s != "" || sDefault != "") { // create chunk  
             const String& sToSave = (s != "") ? s : sDefault;  
             if (!UseFixedLengthStrings) size = sToSave.size() + 1;  
             ck = lstINFO->AddSubChunk(ChunkID, size);  
             char* pData = (char*) ck->LoadChunkData();  
             strncpy(pData, sToSave.c_str(), size);  
         }  
295      }      }
296    
297      /** @brief Update chunks with current info values.      /** @brief Update chunks with current info values.
# Line 355  namespace DLS { Line 338  namespace DLS {
338    
339          // (the string size values are for gig files; they are only          // (the string size values are for gig files; they are only
340          // used if UseFixedLengthStrings is set to true)          // used if UseFixedLengthStrings is set to true)
341          SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName,          SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName, UseFixedLengthStrings,
342                     resourceType == RIFF_TYPE_DLS ? 128 : 64);                     resourceType == RIFF_TYPE_DLS ? 128 : 64);
343          SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""), 256);          SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""), UseFixedLengthStrings, 256);
344          SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate, 128);          SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate, UseFixedLengthStrings, 128);
345          SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments, 1024);          SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments, UseFixedLengthStrings, 1024);
346          SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""), 128);          SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""), UseFixedLengthStrings, 128);
347          SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""), 128);          SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""), UseFixedLengthStrings, 128);
348          SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""), 128);          SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""), UseFixedLengthStrings, 128);
349          SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""), 128);          SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""), UseFixedLengthStrings, 128);
350          SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""), 128);          SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""), UseFixedLengthStrings, 128);
351          SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""), 128);          SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""), UseFixedLengthStrings, 128);
352          SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""), 128);          SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""), UseFixedLengthStrings, 128);
353          SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware,          SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware, UseFixedLengthStrings,
354                     resourceType == LIST_TYPE_INS ?                     resourceType == LIST_TYPE_INS ?
355                     (Software == "" ? defaultSoftware.length() : Software.length()) : 128);                     (Software == "" ? defaultSoftware.length() : Software.length()) : 128);
356          SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""), 128);          SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""), UseFixedLengthStrings, 128);
357          SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""), 128);          SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""), UseFixedLengthStrings, 128);
358          SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""), 128);          SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""), UseFixedLengthStrings, 128);
359          SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""), 128);          SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""), UseFixedLengthStrings, 128);
360            SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String(""), UseFixedLengthStrings, 128);
361      }      }
362    
363    
# Line 485  namespace DLS { Line 469  namespace DLS {
469                                                     : SamplerOptions & (~F_WSMP_NO_TRUNCATION);                                                     : SamplerOptions & (~F_WSMP_NO_TRUNCATION);
470          SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION          SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION
471                                                 : SamplerOptions & (~F_WSMP_NO_COMPRESSION);                                                 : SamplerOptions & (~F_WSMP_NO_COMPRESSION);
472            memcpy(&pData[4], &UnityNote, 2);
473            memcpy(&pData[6], &FineTune, 2);
474            memcpy(&pData[8], &Gain, 4);
475            memcpy(&pData[12], &SamplerOptions, 4);
476            memcpy(&pData[16], &SampleLoops, 4);
477          // update loop definitions          // update loop definitions
478          for (uint32_t i = 0; i < SampleLoops; i++) {          for (uint32_t i = 0; i < SampleLoops; i++) {
479              //FIXME: this does not handle extended loop structs correctly              //FIXME: this does not handle extended loop structs correctly
# Line 527  namespace DLS { Line 516  namespace DLS {
516              // PCM format specific              // PCM format specific
517              if (FormatTag == WAVE_FORMAT_PCM) {              if (FormatTag == WAVE_FORMAT_PCM) {
518                  BitDepth     = pCkFormat->ReadUint16();                  BitDepth     = pCkFormat->ReadUint16();
519                  FrameSize    = (FormatTag == WAVE_FORMAT_PCM) ? (BitDepth / 8) * Channels                  FrameSize    = (BitDepth / 8) * Channels;
                                                             : 0;  
520              } else { // unsupported sample data format              } else { // unsupported sample data format
521                  BitDepth     = 0;                  BitDepth     = 0;
522                  FrameSize    = 0;                  FrameSize    = 0;

Legend:
Removed from v.918  
changed lines
  Added in v.933

  ViewVC Help
Powered by ViewVC