/[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 1218 by persson, Fri Jun 1 19:19:28 2007 UTC revision 3926 by schoenebeck, Tue Jun 15 10:16:40 2021 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-2007 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2021 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 23  Line 23 
23    
24  #include "DLS.h"  #include "DLS.h"
25    
26    #include <algorithm>
27    #include <vector>
28  #include <time.h>  #include <time.h>
29    
30  #ifdef __APPLE__  #ifdef __APPLE__
# Line 120  namespace DLS { Line 122  namespace DLS {
122              artl->GetChunkID() != CHUNK_ID_ARTL) {              artl->GetChunkID() != CHUNK_ID_ARTL) {
123                throw DLS::Exception("<artl-ck> or <art2-ck> chunk expected");                throw DLS::Exception("<artl-ck> or <art2-ck> chunk expected");
124          }          }
125    
126            artl->SetPos(0);
127    
128          HeaderSize  = artl->ReadUint32();          HeaderSize  = artl->ReadUint32();
129          Connections = artl->ReadUint32();          Connections = artl->ReadUint32();
130          artl->SetPos(HeaderSize);          artl->SetPos(HeaderSize);
# Line 143  namespace DLS { Line 148  namespace DLS {
148      /**      /**
149       * Apply articulation connections to the respective RIFF chunks. You       * Apply articulation connections to the respective RIFF chunks. You
150       * have to call File::Save() to make changes persistent.       * have to call File::Save() to make changes persistent.
151         *
152         * @param pProgress - callback function for progress notification
153       */       */
154      void Articulation::UpdateChunks() {      void Articulation::UpdateChunks(progress_t* pProgress) {
155          const int iEntrySize = 12; // 12 bytes per connection block          const int iEntrySize = 12; // 12 bytes per connection block
156          pArticulationCk->Resize(HeaderSize + Connections * iEntrySize);          pArticulationCk->Resize(HeaderSize + Connections * iEntrySize);
157          uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData();          uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData();
# Line 160  namespace DLS { Line 167  namespace DLS {
167          }          }
168      }      }
169    
170        /** @brief Remove all RIFF chunks associated with this Articulation object.
171         *
172         * At the moment Articulation::DeleteChunks() does nothing. It is
173         * recommended to call this method explicitly though from deriving classes's
174         * own overridden implementation of this method to avoid potential future
175         * compatiblity issues.
176         *
177         * See Storage::DeleteChunks() for details.
178         */
179        void Articulation::DeleteChunks() {
180        }
181    
182    
183    
184  // *************** Articulator  ***************  // *************** Articulator  ***************
# Line 190  namespace DLS { Line 209  namespace DLS {
209          if (lart) {          if (lart) {
210              uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2              uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2
211                                                                           : CHUNK_ID_ARTL;                                                                           : CHUNK_ID_ARTL;
212              RIFF::Chunk* art = lart->GetFirstSubChunk();              size_t i = 0;
213              while (art) {              for (RIFF::Chunk* art = lart->GetSubChunkAt(i); art;
214                     art = lart->GetSubChunkAt(++i))
215                {
216                  if (art->GetChunkID() == artCkType) {                  if (art->GetChunkID() == artCkType) {
217                      if (!pArticulations) pArticulations = new ArticulationList;                      if (!pArticulations) pArticulations = new ArticulationList;
218                      pArticulations->push_back(new Articulation(art));                      pArticulations->push_back(new Articulation(art));
219                  }                  }
                 art = lart->GetNextSubChunk();  
220              }              }
221          }          }
222      }      }
# Line 216  namespace DLS { Line 236  namespace DLS {
236      /**      /**
237       * Apply all articulations to the respective RIFF chunks. You have to       * Apply all articulations to the respective RIFF chunks. You have to
238       * call File::Save() to make changes persistent.       * call File::Save() to make changes persistent.
239         *
240         * @param pProgress - callback function for progress notification
241       */       */
242      void Articulator::UpdateChunks() {      void Articulator::UpdateChunks(progress_t* pProgress) {
243          if (pArticulations) {          if (pArticulations) {
244              ArticulationList::iterator iter = pArticulations->begin();              ArticulationList::iterator iter = pArticulations->begin();
245              ArticulationList::iterator end  = pArticulations->end();              ArticulationList::iterator end  = pArticulations->end();
246              for (; iter != end; ++iter) {              for (; iter != end; ++iter) {
247                  (*iter)->UpdateChunks();                  (*iter)->UpdateChunks(pProgress);
248              }              }
249          }          }
250      }      }
251    
252        /** @brief Remove all RIFF chunks associated with this Articulator object.
253         *
254         * See Storage::DeleteChunks() for details.
255         */
256        void Articulator::DeleteChunks() {
257            if (pArticulations) {
258                ArticulationList::iterator iter = pArticulations->begin();
259                ArticulationList::iterator end  = pArticulations->end();
260                for (; iter != end; ++iter) {
261                    (*iter)->DeleteChunks();
262                }
263            }
264        }
265    
266        /**
267         * Not yet implemented in this version, since the .gig format does
268         * not need to copy DLS articulators and so far nobody used pure
269         * DLS instrument AFAIK.
270         */
271        void Articulator::CopyAssign(const Articulator* orig) {
272            //TODO: implement deep copy assignment for this class
273        }
274    
275    
276    
277  // *************** Info  ***************  // *************** Info  ***************
# Line 239  namespace DLS { Line 284  namespace DLS {
284       * @param list - pointer to a list chunk which contains an INFO list chunk       * @param list - pointer to a list chunk which contains an INFO list chunk
285       */       */
286      Info::Info(RIFF::List* list) {      Info::Info(RIFF::List* list) {
287          FixedStringLengths = NULL;          pFixedStringLengths = NULL;
288          pResourceListChunk = list;          pResourceListChunk = list;
289          if (list) {          if (list) {
290              RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO);              RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO);
# Line 268  namespace DLS { Line 313  namespace DLS {
313      Info::~Info() {      Info::~Info() {
314      }      }
315    
316        /**
317         * Forces specific Info fields to be of a fixed length when being saved
318         * to a file. By default the respective RIFF chunk of an Info field
319         * will have a size analogue to its actual string length. With this
320         * method however this behavior can be overridden, allowing to force an
321         * arbitrary fixed size individually for each Info field.
322         *
323         * This method is used as a workaround for the gig format, not for DLS.
324         *
325         * @param lengths - NULL terminated array of string_length_t elements
326         */
327        void Info::SetFixedStringLengths(const string_length_t* lengths) {
328            pFixedStringLengths = lengths;
329        }
330    
331      /** @brief Load given INFO field.      /** @brief Load given INFO field.
332       *       *
333       * Load INFO field from INFO chunk with chunk ID \a ChunkID from INFO       * Load INFO field from INFO chunk with chunk ID \a ChunkID from INFO
# Line 295  namespace DLS { Line 355  namespace DLS {
355       */       */
356      void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) {      void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) {
357          int size = 0;          int size = 0;
358          if (FixedStringLengths) {          if (pFixedStringLengths) {
359              for (int i = 0 ; FixedStringLengths[i].length ; i++) {              for (int i = 0 ; pFixedStringLengths[i].length ; i++) {
360                  if (FixedStringLengths[i].chunkId == ChunkID) {                  if (pFixedStringLengths[i].chunkId == ChunkID) {
361                      size = FixedStringLengths[i].length;                      size = pFixedStringLengths[i].length;
362                      break;                      break;
363                  }                  }
364              }              }
# Line 311  namespace DLS { Line 371  namespace DLS {
371       *       *
372       * Apply current INFO field values to the respective INFO chunks. You       * Apply current INFO field values to the respective INFO chunks. You
373       * have to call File::Save() to make changes persistent.       * have to call File::Save() to make changes persistent.
374         *
375         * @param pProgress - callback function for progress notification
376       */       */
377      void Info::UpdateChunks() {      void Info::UpdateChunks(progress_t* pProgress) {
378          if (!pResourceListChunk) return;          if (!pResourceListChunk) return;
379    
380          // make sure INFO list chunk exists          // make sure INFO list chunk exists
# Line 368  namespace DLS { Line 430  namespace DLS {
430          SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""));          SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""));
431      }      }
432    
433        /** @brief Remove all RIFF chunks associated with this Info object.
434         *
435         * At the moment Info::DeleteChunks() does nothing. It is
436         * recommended to call this method explicitly though from deriving classes's
437         * own overridden implementation of this method to avoid potential future
438         * compatiblity issues.
439         *
440         * See Storage::DeleteChunks() for details.
441         */
442        void Info::DeleteChunks() {
443        }
444    
445        /**
446         * Make a deep copy of the Info object given by @a orig and assign it to
447         * this object.
448         *
449         * @param orig - original Info object to be copied from
450         */
451        void Info::CopyAssign(const Info* orig) {
452            Name = orig->Name;
453            ArchivalLocation = orig->ArchivalLocation;
454            CreationDate = orig->CreationDate;
455            Comments = orig->Comments;
456            Product = orig->Product;
457            Copyright = orig->Copyright;
458            Artists = orig->Artists;
459            Genre = orig->Genre;
460            Keywords = orig->Keywords;
461            Engineer = orig->Engineer;
462            Technician = orig->Technician;
463            Software = orig->Software;
464            Medium = orig->Medium;
465            Source = orig->Source;
466            SourceForm = orig->SourceForm;
467            Commissioned = orig->Commissioned;
468            Subject = orig->Subject;
469            //FIXME: hmm, is copying this pointer a good idea?
470            pFixedStringLengths = orig->pFixedStringLengths;
471        }
472    
473    
474    
475  // *************** Resource ***************  // *************** Resource ***************
# Line 390  namespace DLS { Line 492  namespace DLS {
492    
493          RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);          RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);
494          if (ckDLSID) {          if (ckDLSID) {
495                ckDLSID->SetPos(0);
496    
497              pDLSID = new dlsid_t;              pDLSID = new dlsid_t;
498              ckDLSID->Read(&pDLSID->ulData1, 1, 4);              ckDLSID->Read(&pDLSID->ulData1, 1, 4);
499              ckDLSID->Read(&pDLSID->usData2, 1, 2);              ckDLSID->Read(&pDLSID->usData2, 1, 2);
# Line 404  namespace DLS { Line 508  namespace DLS {
508          if (pInfo)  delete pInfo;          if (pInfo)  delete pInfo;
509      }      }
510    
511        /** @brief Remove all RIFF chunks associated with this Resource object.
512         *
513         * At the moment Resource::DeleteChunks() does nothing. It is recommended
514         * to call this method explicitly though from deriving classes's own
515         * overridden implementation of this method to avoid potential future
516         * compatiblity issues.
517         *
518         * See Storage::DeleteChunks() for details.
519         */
520        void Resource::DeleteChunks() {
521        }
522    
523      /** @brief Update chunks with current Resource data.      /** @brief Update chunks with current Resource data.
524       *       *
525       * Apply Resource data persistently below the previously given resource       * Apply Resource data persistently below the previously given resource
# Line 411  namespace DLS { Line 527  namespace DLS {
527       * will not be applied at the moment (yet).       * will not be applied at the moment (yet).
528       *       *
529       * You have to call File::Save() to make changes persistent.       * You have to call File::Save() to make changes persistent.
530         *
531         * @param pProgress - callback function for progress notification
532       */       */
533      void Resource::UpdateChunks() {      void Resource::UpdateChunks(progress_t* pProgress) {
534          pInfo->UpdateChunks();          pInfo->UpdateChunks(pProgress);
535    
536          if (pDLSID) {          if (pDLSID) {
537              // make sure 'dlid' chunk exists              // make sure 'dlid' chunk exists
# Line 432  namespace DLS { Line 550  namespace DLS {
550       * Generates a new DLSID for the resource.       * Generates a new DLSID for the resource.
551       */       */
552      void Resource::GenerateDLSID() {      void Resource::GenerateDLSID() {
553  #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)          #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
   
554          if (!pDLSID) pDLSID = new dlsid_t;          if (!pDLSID) pDLSID = new dlsid_t;
555            GenerateDLSID(pDLSID);
556            #endif
557        }
558    
559        void Resource::GenerateDLSID(dlsid_t* pDLSID) {
560  #ifdef WIN32  #ifdef WIN32
   
561          UUID uuid;          UUID uuid;
562          UuidCreate(&uuid);          UuidCreate(&uuid);
563          pDLSID->ulData1 = uuid.Data1;          pDLSID->ulData1 = uuid.Data1;
564          pDLSID->usData1 = uuid.Data2;          pDLSID->usData2 = uuid.Data2;
565          pDLSID->usData2 = uuid.Data3;          pDLSID->usData3 = uuid.Data3;
566          memcpy(pDLSID->abData, uuid.Data4, 8);          memcpy(pDLSID->abData, uuid.Data4, 8);
567    
568  #elif defined(__APPLE__)  #elif defined(__APPLE__)
# Line 461  namespace DLS { Line 581  namespace DLS {
581          pDLSID->abData[5] = uuid.byte13;          pDLSID->abData[5] = uuid.byte13;
582          pDLSID->abData[6] = uuid.byte14;          pDLSID->abData[6] = uuid.byte14;
583          pDLSID->abData[7] = uuid.byte15;          pDLSID->abData[7] = uuid.byte15;
584  #else  #elif defined(HAVE_UUID_GENERATE)
585          uuid_t uuid;          uuid_t uuid;
586          uuid_generate(uuid);          uuid_generate(uuid);
587          pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;          pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
588          pDLSID->usData2 = uuid[4] | uuid[5] << 8;          pDLSID->usData2 = uuid[4] | uuid[5] << 8;
589          pDLSID->usData3 = uuid[6] | uuid[7] << 8;          pDLSID->usData3 = uuid[6] | uuid[7] << 8;
590          memcpy(pDLSID->abData, &uuid[8], 8);          memcpy(pDLSID->abData, &uuid[8], 8);
591  #endif  #else
592    # error "Missing support for uuid generation"
593  #endif  #endif
594      }      }
595        
596        /**
597         * Make a deep copy of the Resource object given by @a orig and assign it
598         * to this object.
599         *
600         * @param orig - original Resource object to be copied from
601         */
602        void Resource::CopyAssign(const Resource* orig) {
603            pInfo->CopyAssign(orig->pInfo);
604        }
605    
606    
607  // *************** Sampler ***************  // *************** Sampler ***************
# Line 480  namespace DLS { Line 611  namespace DLS {
611          pParentList       = ParentList;          pParentList       = ParentList;
612          RIFF::Chunk* wsmp = ParentList->GetSubChunk(CHUNK_ID_WSMP);          RIFF::Chunk* wsmp = ParentList->GetSubChunk(CHUNK_ID_WSMP);
613          if (wsmp) {          if (wsmp) {
614                wsmp->SetPos(0);
615    
616              uiHeaderSize   = wsmp->ReadUint32();              uiHeaderSize   = wsmp->ReadUint32();
617              UnityNote      = wsmp->ReadUint16();              UnityNote      = wsmp->ReadUint16();
618              FineTune       = wsmp->ReadInt16();              FineTune       = wsmp->ReadInt16();
# Line 487  namespace DLS { Line 620  namespace DLS {
620              SamplerOptions = wsmp->ReadUint32();              SamplerOptions = wsmp->ReadUint32();
621              SampleLoops    = wsmp->ReadUint32();              SampleLoops    = wsmp->ReadUint32();
622          } else { // 'wsmp' chunk missing          } else { // 'wsmp' chunk missing
623              uiHeaderSize   = 0;              uiHeaderSize   = 20;
624              UnityNote      = 60;              UnityNote      = 60;
625              FineTune       = 0; // +- 0 cents              FineTune       = 0; // +- 0 cents
626              Gain           = 0; // 0 dB              Gain           = 0; // 0 dB
# Line 512  namespace DLS { Line 645  namespace DLS {
645          if (pSampleLoops) delete[] pSampleLoops;          if (pSampleLoops) delete[] pSampleLoops;
646      }      }
647    
648        void Sampler::SetGain(int32_t gain) {
649            Gain = gain;
650        }
651    
652      /**      /**
653       * Apply all sample player options to the respective RIFF chunk. You       * Apply all sample player options to the respective RIFF chunk. You
654       * have to call File::Save() to make changes persistent.       * have to call File::Save() to make changes persistent.
655         *
656         * @param pProgress - callback function for progress notification
657       */       */
658      void Sampler::UpdateChunks() {      void Sampler::UpdateChunks(progress_t* pProgress) {
659          // make sure 'wsmp' chunk exists          // make sure 'wsmp' chunk exists
660          RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);          RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);
661            int wsmpSize = uiHeaderSize + SampleLoops * 16;
662          if (!wsmp) {          if (!wsmp) {
663              uiHeaderSize = 20;              wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize);
664              wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, uiHeaderSize + SampleLoops * 16);          } else if (wsmp->GetSize() != wsmpSize) {
665                wsmp->Resize(wsmpSize);
666          }          }
667          uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();          uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
668          // update headers size          // update headers size
# Line 546  namespace DLS { Line 687  namespace DLS {
687          }          }
688      }      }
689    
690        /** @brief Remove all RIFF chunks associated with this Sampler object.
691         *
692         * At the moment Sampler::DeleteChunks() does nothing. It is
693         * recommended to call this method explicitly though from deriving classes's
694         * own overridden implementation of this method to avoid potential future
695         * compatiblity issues.
696         *
697         * See Storage::DeleteChunks() for details.
698         */
699        void Sampler::DeleteChunks() {
700        }
701    
702      /**      /**
703       * Adds a new sample loop with the provided loop definition.       * Adds a new sample loop with the provided loop definition.
704       *       *
# Line 578  namespace DLS { Line 731  namespace DLS {
731          // copy old loops array (skipping given loop)          // copy old loops array (skipping given loop)
732          for (int i = 0, o = 0; i < SampleLoops; i++) {          for (int i = 0, o = 0; i < SampleLoops; i++) {
733              if (&pSampleLoops[i] == pLoopDef) continue;              if (&pSampleLoops[i] == pLoopDef) continue;
734              if (o == SampleLoops - 1)              if (o == SampleLoops - 1) {
735                    delete[] pNewLoops;
736                  throw Exception("Could not delete Sample Loop, because it does not exist");                  throw Exception("Could not delete Sample Loop, because it does not exist");
737                }
738              pNewLoops[o] = pSampleLoops[i];              pNewLoops[o] = pSampleLoops[i];
739              o++;              o++;
740          }          }
# Line 588  namespace DLS { Line 743  namespace DLS {
743          pSampleLoops = pNewLoops;          pSampleLoops = pNewLoops;
744          SampleLoops--;          SampleLoops--;
745      }      }
746        
747        /**
748         * Make a deep copy of the Sampler object given by @a orig and assign it
749         * to this object.
750         *
751         * @param orig - original Sampler object to be copied from
752         */
753        void Sampler::CopyAssign(const Sampler* orig) {
754            // copy trivial scalars
755            UnityNote = orig->UnityNote;
756            FineTune = orig->FineTune;
757            Gain = orig->Gain;
758            NoSampleDepthTruncation = orig->NoSampleDepthTruncation;
759            NoSampleCompression = orig->NoSampleCompression;
760            SamplerOptions = orig->SamplerOptions;
761            
762            // copy sample loops
763            if (SampleLoops) delete[] pSampleLoops;
764            pSampleLoops = new sample_loop_t[orig->SampleLoops];
765            memcpy(pSampleLoops, orig->pSampleLoops, orig->SampleLoops * sizeof(sample_loop_t));
766            SampleLoops = orig->SampleLoops;
767        }
768    
769    
770  // *************** Sample ***************  // *************** Sample ***************
# Line 609  namespace DLS { Line 785  namespace DLS {
785       * @param WavePoolOffset - offset of this sample data from wave pool       * @param WavePoolOffset - offset of this sample data from wave pool
786       *                         ('wvpl') list chunk       *                         ('wvpl') list chunk
787       */       */
788      Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : Resource(pFile, waveList) {      Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset) : Resource(pFile, waveList) {
789          pWaveList = waveList;          pWaveList = waveList;
790          ulWavePoolOffset = WavePoolOffset - LIST_HEADER_SIZE;          ullWavePoolOffset = WavePoolOffset - LIST_HEADER_SIZE(waveList->GetFile()->GetFileOffsetSize());
791          pCkFormat = waveList->GetSubChunk(CHUNK_ID_FMT);          pCkFormat = waveList->GetSubChunk(CHUNK_ID_FMT);
792          pCkData   = waveList->GetSubChunk(CHUNK_ID_DATA);          pCkData   = waveList->GetSubChunk(CHUNK_ID_DATA);
793          if (pCkFormat) {          if (pCkFormat) {
794                pCkFormat->SetPos(0);
795    
796              // common fields              // common fields
797              FormatTag              = pCkFormat->ReadUint16();              FormatTag              = pCkFormat->ReadUint16();
798              Channels               = pCkFormat->ReadUint16();              Channels               = pCkFormat->ReadUint16();
# Line 645  namespace DLS { Line 823  namespace DLS {
823    
824      /** @brief Destructor.      /** @brief Destructor.
825       *       *
826       * Removes RIFF chunks associated with this Sample and frees all       * Frees all memory occupied by this sample.
      * memory occupied by this sample.  
827       */       */
828      Sample::~Sample() {      Sample::~Sample() {
829          RIFF::List* pParent = pWaveList->GetParent();          if (pCkData)
830          pParent->DeleteSubChunk(pWaveList);              pCkData->ReleaseChunkData();
831            if (pCkFormat)
832                pCkFormat->ReleaseChunkData();
833        }
834    
835        /** @brief Remove all RIFF chunks associated with this Sample object.
836         *
837         * See Storage::DeleteChunks() for details.
838         */
839        void Sample::DeleteChunks() {
840            // handle base class
841            Resource::DeleteChunks();
842    
843            // handle own RIFF chunks
844            if (pWaveList) {
845                RIFF::List* pParent = pWaveList->GetParent();
846                pParent->DeleteSubChunk(pWaveList);
847                pWaveList = NULL;
848            }
849        }
850    
851        /**
852         * Make a deep copy of the Sample object given by @a orig (without the
853         * actual sample waveform data however) and assign it to this object.
854         *
855         * This is a special internal variant of CopyAssign() which only copies the
856         * most mandatory member variables. It will be called by gig::Sample
857         * descendent instead of CopyAssign() since gig::Sample has its own
858         * implementation to access and copy the actual sample waveform data.
859         *
860         * @param orig - original Sample object to be copied from
861         */
862        void Sample::CopyAssignCore(const Sample* orig) {
863            // handle base classes
864            Resource::CopyAssign(orig);
865            // handle actual own attributes of this class
866            FormatTag = orig->FormatTag;
867            Channels = orig->Channels;
868            SamplesPerSecond = orig->SamplesPerSecond;
869            AverageBytesPerSecond = orig->AverageBytesPerSecond;
870            BlockAlign = orig->BlockAlign;
871            BitDepth = orig->BitDepth;
872            SamplesTotal = orig->SamplesTotal;
873            FrameSize = orig->FrameSize;
874        }
875        
876        /**
877         * Make a deep copy of the Sample object given by @a orig and assign it to
878         * this object.
879         *
880         * @param orig - original Sample object to be copied from
881         */
882        void Sample::CopyAssign(const Sample* orig) {
883            CopyAssignCore(orig);
884            
885            // copy sample waveform data (reading directly from disc)
886            Resize(orig->GetSize());
887            char* buf = (char*) LoadSampleData();
888            Sample* pOrig = (Sample*) orig; //HACK: circumventing the constness here for now
889            const file_offset_t restorePos = pOrig->pCkData->GetPos();
890            pOrig->SetPos(0);
891            for (file_offset_t todo = pOrig->GetSize(), i = 0; todo; ) {
892                const int iReadAtOnce = 64*1024;
893                file_offset_t n = (iReadAtOnce < todo) ? iReadAtOnce : todo;
894                n = pOrig->Read(&buf[i], n);
895                if (!n) break;
896                todo -= n;
897                i += (n * pOrig->FrameSize);
898            }
899            pOrig->pCkData->SetPos(restorePos);
900      }      }
901    
902      /** @brief Load sample data into RAM.      /** @brief Load sample data into RAM.
# Line 702  namespace DLS { Line 948  namespace DLS {
948       * @returns number of sample points or 0 if FormatTag != DLS_WAVE_FORMAT_PCM       * @returns number of sample points or 0 if FormatTag != DLS_WAVE_FORMAT_PCM
949       * @see FrameSize, FormatTag       * @see FrameSize, FormatTag
950       */       */
951      unsigned long Sample::GetSize() {      file_offset_t Sample::GetSize() const {
952          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0;          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0;
953          return (pCkData) ? pCkData->GetSize() / FrameSize : 0;          return (pCkData) ? pCkData->GetSize() / FrameSize : 0;
954      }      }
# Line 729  namespace DLS { Line 975  namespace DLS {
975       * FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with       * FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with
976       * other formats will fail!       * other formats will fail!
977       *       *
978       * @param iNewSize - new sample wave data size in sample points (must be       * @param NewSize - new sample wave data size in sample points (must be
979       *                   greater than zero)       *                  greater than zero)
980       * @throws Excecption if FormatTag != DLS_WAVE_FORMAT_PCM       * @throws Exception if FormatTag != DLS_WAVE_FORMAT_PCM
981       * @throws Exception if \a iNewSize is less than 1       * @throws Exception if \a NewSize is less than 1 or unrealistic large
982       * @see File::Save(), FrameSize, FormatTag       * @see File::Save(), FrameSize, FormatTag
983       */       */
984      void Sample::Resize(int iNewSize) {      void Sample::Resize(file_offset_t NewSize) {
985          if (FormatTag != DLS_WAVE_FORMAT_PCM) throw Exception("Sample's format is not DLS_WAVE_FORMAT_PCM");          if (FormatTag != DLS_WAVE_FORMAT_PCM) throw Exception("Sample's format is not DLS_WAVE_FORMAT_PCM");
986          if (iNewSize < 1) throw Exception("Sample size must be at least one sample point");          if (NewSize < 1) throw Exception("Sample size must be at least one sample point");
987          const int iSizeInBytes = iNewSize * FrameSize;          if ((NewSize >> 48) != 0)
988                throw Exception("Unrealistic high DLS sample size detected");
989            const file_offset_t sizeInBytes = NewSize * FrameSize;
990          pCkData = pWaveList->GetSubChunk(CHUNK_ID_DATA);          pCkData = pWaveList->GetSubChunk(CHUNK_ID_DATA);
991          if (pCkData) pCkData->Resize(iSizeInBytes);          if (pCkData) pCkData->Resize(sizeInBytes);
992          else pCkData = pWaveList->AddSubChunk(CHUNK_ID_DATA, iSizeInBytes);          else pCkData = pWaveList->AddSubChunk(CHUNK_ID_DATA, sizeInBytes);
993      }      }
994    
995      /**      /**
# Line 760  namespace DLS { Line 1008  namespace DLS {
1008       * @throws Exception if no data RIFF chunk was created for the sample yet       * @throws Exception if no data RIFF chunk was created for the sample yet
1009       * @see FrameSize, FormatTag       * @see FrameSize, FormatTag
1010       */       */
1011      unsigned long Sample::SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence) {      file_offset_t Sample::SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence) {
1012          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
1013          if (!pCkData) throw Exception("No data chunk created for sample yet, call Sample::Resize() to create one");          if (!pCkData) throw Exception("No data chunk created for sample yet, call Sample::Resize() to create one");
1014          unsigned long orderedBytes = SampleCount * FrameSize;          file_offset_t orderedBytes = SampleCount * FrameSize;
1015          unsigned long result = pCkData->SetPos(orderedBytes, Whence);          file_offset_t result = pCkData->SetPos(orderedBytes, Whence);
1016          return (result == orderedBytes) ? SampleCount          return (result == orderedBytes) ? SampleCount
1017                                          : result / FrameSize;                                          : result / FrameSize;
1018      }      }
# Line 778  namespace DLS { Line 1026  namespace DLS {
1026       * @param pBuffer      destination buffer       * @param pBuffer      destination buffer
1027       * @param SampleCount  number of sample points to read       * @param SampleCount  number of sample points to read
1028       */       */
1029      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {      file_offset_t Sample::Read(void* pBuffer, file_offset_t SampleCount) {
1030          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
1031          return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?          return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
1032      }      }
# Line 798  namespace DLS { Line 1046  namespace DLS {
1046       * @throws Exception if current sample size is too small       * @throws Exception if current sample size is too small
1047       * @see LoadSampleData()       * @see LoadSampleData()
1048       */       */
1049      unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) {      file_offset_t Sample::Write(void* pBuffer, file_offset_t SampleCount) {
1050          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format          if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
1051          if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small");          if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small");
1052          return pCkData->Write(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?          return pCkData->Write(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
# Line 808  namespace DLS { Line 1056  namespace DLS {
1056       * Apply sample and its settings to the respective RIFF chunks. You have       * Apply sample and its settings to the respective RIFF chunks. You have
1057       * to call File::Save() to make changes persistent.       * to call File::Save() to make changes persistent.
1058       *       *
1059         * @param pProgress - callback function for progress notification
1060       * @throws Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data       * @throws Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data
1061       *                   was provided yet       *                   was provided yet
1062       */       */
1063      void Sample::UpdateChunks() {      void Sample::UpdateChunks(progress_t* pProgress) {
1064          if (FormatTag != DLS_WAVE_FORMAT_PCM)          if (FormatTag != DLS_WAVE_FORMAT_PCM)
1065              throw Exception("Could not save sample, only PCM format is supported");              throw Exception("Could not save sample, only PCM format is supported");
1066          // we refuse to do anything if not sample wave form was provided yet          // we refuse to do anything if not sample wave form was provided yet
1067          if (!pCkData)          if (!pCkData)
1068              throw Exception("Could not save sample, there is no sample data to save");              throw Exception("Could not save sample, there is no sample data to save");
1069          // update chunks of base class as well          // update chunks of base class as well
1070          Resource::UpdateChunks();          Resource::UpdateChunks(pProgress);
1071          // make sure 'fmt' chunk exists          // make sure 'fmt' chunk exists
1072          RIFF::Chunk* pCkFormat = pWaveList->GetSubChunk(CHUNK_ID_FMT);          RIFF::Chunk* pCkFormat = pWaveList->GetSubChunk(CHUNK_ID_FMT);
1073          if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format          if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format
# Line 840  namespace DLS { Line 1089  namespace DLS {
1089      Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : Resource(pInstrument, rgnList), Articulator(rgnList), Sampler(rgnList) {      Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : Resource(pInstrument, rgnList), Articulator(rgnList), Sampler(rgnList) {
1090          pCkRegion = rgnList;          pCkRegion = rgnList;
1091    
1092          // articulation informations          // articulation information
1093          RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);          RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);
1094          if (rgnh) {          if (rgnh) {
1095                rgnh->SetPos(0);
1096    
1097              rgnh->Read(&KeyRange, 2, 2);              rgnh->Read(&KeyRange, 2, 2);
1098              rgnh->Read(&VelocityRange, 2, 2);              rgnh->Read(&VelocityRange, 2, 2);
1099              FormatOptionFlags = rgnh->ReadUint16();              FormatOptionFlags = rgnh->ReadUint16();
# Line 862  namespace DLS { Line 1113  namespace DLS {
1113          }          }
1114          SelfNonExclusive = FormatOptionFlags & F_RGN_OPTION_SELFNONEXCLUSIVE;          SelfNonExclusive = FormatOptionFlags & F_RGN_OPTION_SELFNONEXCLUSIVE;
1115    
1116          // sample informations          // sample information
1117          RIFF::Chunk* wlnk = rgnList->GetSubChunk(CHUNK_ID_WLNK);          RIFF::Chunk* wlnk = rgnList->GetSubChunk(CHUNK_ID_WLNK);
1118          if (wlnk) {          if (wlnk) {
1119                wlnk->SetPos(0);
1120    
1121              WaveLinkOptionFlags = wlnk->ReadUint16();              WaveLinkOptionFlags = wlnk->ReadUint16();
1122              PhaseGroup          = wlnk->ReadUint16();              PhaseGroup          = wlnk->ReadUint16();
1123              Channel             = wlnk->ReadUint32();              Channel             = wlnk->ReadUint32();
# Line 883  namespace DLS { Line 1136  namespace DLS {
1136    
1137      /** @brief Destructor.      /** @brief Destructor.
1138       *       *
1139       * Removes RIFF chunks associated with this Region.       * Intended to free up all memory occupied by this Region object. ATM this
1140         * destructor implementation does nothing though.
1141       */       */
1142      Region::~Region() {      Region::~Region() {
1143          RIFF::List* pParent = pCkRegion->GetParent();      }
1144          pParent->DeleteSubChunk(pCkRegion);  
1145        /** @brief Remove all RIFF chunks associated with this Region object.
1146         *
1147         * See Storage::DeleteChunks() for details.
1148         */
1149        void Region::DeleteChunks() {
1150            // handle base classes
1151            Resource::DeleteChunks();
1152            Articulator::DeleteChunks();
1153            Sampler::DeleteChunks();
1154    
1155            // handle own RIFF chunks
1156            if (pCkRegion) {
1157                RIFF::List* pParent = pCkRegion->GetParent();
1158                pParent->DeleteSubChunk(pCkRegion);
1159                pCkRegion = NULL;
1160            }
1161      }      }
1162    
1163      Sample* Region::GetSample() {      Sample* Region::GetSample() {
1164          if (pSample) return pSample;          if (pSample) return pSample;
1165          File* file = (File*) GetParent()->GetParent();          File* file = (File*) GetParent()->GetParent();
1166          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];          uint64_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1167          Sample* sample = file->GetFirstSample();          Sample* sample = file->GetFirstSample();
1168          while (sample) {          while (sample) {
1169              if (sample->ulWavePoolOffset == soughtoffset) return (pSample = sample);              if (sample->ullWavePoolOffset == soughtoffset) return (pSample = sample);
1170              sample = file->GetNextSample();              sample = file->GetNextSample();
1171          }          }
1172          return NULL;          return NULL;
# Line 913  namespace DLS { Line 1183  namespace DLS {
1183      }      }
1184    
1185      /**      /**
1186         * Modifies the key range of this Region and makes sure the respective
1187         * chunks are in correct order.
1188         *
1189         * @param Low  - lower end of key range
1190         * @param High - upper end of key range
1191         */
1192        void Region::SetKeyRange(uint16_t Low, uint16_t High) {
1193            KeyRange.low  = Low;
1194            KeyRange.high = High;
1195    
1196            // make sure regions are already loaded
1197            Instrument* pInstrument = (Instrument*) GetParent();
1198            if (!pInstrument->pRegions) pInstrument->LoadRegions();
1199            if (!pInstrument->pRegions) return;
1200    
1201            // find the r which is the first one to the right of this region
1202            // at its new position
1203            Region* r = NULL;
1204            Region* prev_region = NULL;
1205            for (
1206                Instrument::RegionList::iterator iter = pInstrument->pRegions->begin();
1207                iter != pInstrument->pRegions->end(); iter++
1208            ) {
1209                if ((*iter)->KeyRange.low > this->KeyRange.low) {
1210                    r = *iter;
1211                    break;
1212                }
1213                prev_region = *iter;
1214            }
1215    
1216            // place this region before r if it's not already there
1217            if (prev_region != this) pInstrument->MoveRegion(this, r);
1218        }
1219    
1220        /**
1221       * Apply Region settings to the respective RIFF chunks. You have to       * Apply Region settings to the respective RIFF chunks. You have to
1222       * call File::Save() to make changes persistent.       * call File::Save() to make changes persistent.
1223       *       *
1224         * @param pProgress - callback function for progress notification
1225       * @throws Exception - if the Region's sample could not be found       * @throws Exception - if the Region's sample could not be found
1226       */       */
1227      void Region::UpdateChunks() {      void Region::UpdateChunks(progress_t* pProgress) {
1228          // make sure 'rgnh' chunk exists          // make sure 'rgnh' chunk exists
1229          RIFF::Chunk* rgnh = pCkRegion->GetSubChunk(CHUNK_ID_RGNH);          RIFF::Chunk* rgnh = pCkRegion->GetSubChunk(CHUNK_ID_RGNH);
1230          if (!rgnh) rgnh = pCkRegion->AddSubChunk(CHUNK_ID_RGNH, Layer ? 14 : 12);          if (!rgnh) rgnh = pCkRegion->AddSubChunk(CHUNK_ID_RGNH, Layer ? 14 : 12);
# Line 937  namespace DLS { Line 1243  namespace DLS {
1243    
1244          // update chunks of base classes as well (but skip Resource,          // update chunks of base classes as well (but skip Resource,
1245          // as a rgn doesn't seem to have dlid and INFO chunks)          // as a rgn doesn't seem to have dlid and INFO chunks)
1246          Articulator::UpdateChunks();          Articulator::UpdateChunks(pProgress);
1247          Sampler::UpdateChunks();          Sampler::UpdateChunks(pProgress);
1248    
1249          // make sure 'wlnk' chunk exists          // make sure 'wlnk' chunk exists
1250          RIFF::Chunk* wlnk = pCkRegion->GetSubChunk(CHUNK_ID_WLNK);          RIFF::Chunk* wlnk = pCkRegion->GetSubChunk(CHUNK_ID_WLNK);
# Line 963  namespace DLS { Line 1269  namespace DLS {
1269                  }                  }
1270              }              }
1271          }          }
         if (index < 0) throw Exception("Could not save Region, could not find Region's sample");  
1272          WavePoolTableIndex = index;          WavePoolTableIndex = index;
1273          // update 'wlnk' chunk          // update 'wlnk' chunk
1274          store16(&pData[0], WaveLinkOptionFlags);          store16(&pData[0], WaveLinkOptionFlags);
# Line 971  namespace DLS { Line 1276  namespace DLS {
1276          store32(&pData[4], Channel);          store32(&pData[4], Channel);
1277          store32(&pData[8], WavePoolTableIndex);          store32(&pData[8], WavePoolTableIndex);
1278      }      }
1279        
1280        /**
1281         * Make a (semi) deep copy of the Region object given by @a orig and assign
1282         * it to this object.
1283         *
1284         * Note that the sample pointer referenced by @a orig is simply copied as
1285         * memory address. Thus the respective sample is shared, not duplicated!
1286         *
1287         * @param orig - original Region object to be copied from
1288         */
1289        void Region::CopyAssign(const Region* orig) {
1290            // handle base classes
1291            Resource::CopyAssign(orig);
1292            Articulator::CopyAssign(orig);
1293            Sampler::CopyAssign(orig);
1294            // handle actual own attributes of this class
1295            // (the trivial ones)
1296            VelocityRange = orig->VelocityRange;
1297            KeyGroup = orig->KeyGroup;
1298            Layer = orig->Layer;
1299            SelfNonExclusive = orig->SelfNonExclusive;
1300            PhaseMaster = orig->PhaseMaster;
1301            PhaseGroup = orig->PhaseGroup;
1302            MultiChannel = orig->MultiChannel;
1303            Channel = orig->Channel;
1304            // only take the raw sample reference if the two Region objects are
1305            // part of the same file
1306            if (GetParent()->GetParent() == orig->GetParent()->GetParent()) {
1307                WavePoolTableIndex = orig->WavePoolTableIndex;
1308                pSample = orig->pSample;
1309            } else {
1310                WavePoolTableIndex = -1;
1311                pSample = NULL;
1312            }
1313            FormatOptionFlags = orig->FormatOptionFlags;
1314            WaveLinkOptionFlags = orig->WaveLinkOptionFlags;
1315            // handle the last, a bit sensible attribute
1316            SetKeyRange(orig->KeyRange.low, orig->KeyRange.high);
1317        }
1318    
1319    
1320  // *************** Instrument ***************  // *************** Instrument ***************
# Line 996  namespace DLS { Line 1339  namespace DLS {
1339          midi_locale_t locale;          midi_locale_t locale;
1340          RIFF::Chunk* insh = pCkInstrument->GetSubChunk(CHUNK_ID_INSH);          RIFF::Chunk* insh = pCkInstrument->GetSubChunk(CHUNK_ID_INSH);
1341          if (insh) {          if (insh) {
1342                insh->SetPos(0);
1343    
1344              Regions = insh->ReadUint32();              Regions = insh->ReadUint32();
1345              insh->Read(&locale, 2, 4);              insh->Read(&locale, 2, 4);
1346          } else { // 'insh' chunk missing          } else { // 'insh' chunk missing
# Line 1013  namespace DLS { Line 1358  namespace DLS {
1358          pRegions = NULL;          pRegions = NULL;
1359      }      }
1360    
1361        /**
1362         * Returns Region at supplied @a pos position within the region list of
1363         * this instrument. If supplied @a pos is out of bounds then @c NULL is
1364         * returned.
1365         *
1366         * @param pos - position of sought Region in region list
1367         * @returns pointer address to requested region or @c NULL if @a pos is
1368         *          out of bounds
1369         */
1370        Region* Instrument::GetRegionAt(size_t pos) {
1371            if (!pRegions) LoadRegions();
1372            if (!pRegions) return NULL;
1373            if (pos >= pRegions->size()) return NULL;
1374            return (*pRegions)[pos];
1375        }
1376    
1377        /**
1378         * Returns the first Region of the instrument. You have to call this
1379         * method once before you use GetNextRegion().
1380         *
1381         * @returns  pointer address to first region or NULL if there is none
1382         * @see      GetNextRegion()
1383         * @deprecated  This method is not reentrant-safe, use GetRegionAt()
1384         *              instead.
1385         */
1386      Region* Instrument::GetFirstRegion() {      Region* Instrument::GetFirstRegion() {
1387          if (!pRegions) LoadRegions();          if (!pRegions) LoadRegions();
1388          if (!pRegions) return NULL;          if (!pRegions) return NULL;
# Line 1020  namespace DLS { Line 1390  namespace DLS {
1390          return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;          return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1391      }      }
1392    
1393        /**
1394         * Returns the next Region of the instrument. You have to call
1395         * GetFirstRegion() once before you can use this method. By calling this
1396         * method multiple times it iterates through the available Regions.
1397         *
1398         * @returns  pointer address to the next region or NULL if end reached
1399         * @see      GetFirstRegion()
1400         * @deprecated  This method is not reentrant-safe, use GetRegionAt()
1401         *              instead.
1402         */
1403      Region* Instrument::GetNextRegion() {      Region* Instrument::GetNextRegion() {
1404          if (!pRegions) return NULL;          if (!pRegions) return NULL;
1405          RegionsIterator++;          RegionsIterator++;
# Line 1031  namespace DLS { Line 1411  namespace DLS {
1411          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
1412          if (lrgn) {          if (lrgn) {
1413              uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2              uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2
1414              RIFF::List* rgn = lrgn->GetFirstSubList();              size_t i = 0;
1415              while (rgn) {              for (RIFF::List* rgn = lrgn->GetSubListAt(i); rgn;
1416                     rgn = lrgn->GetSubListAt(++i))
1417                {
1418                  if (rgn->GetListType() == regionCkType) {                  if (rgn->GetListType() == regionCkType) {
1419                      pRegions->push_back(new Region(this, rgn));                      pRegions->push_back(new Region(this, rgn));
1420                  }                  }
                 rgn = lrgn->GetNextSubList();  
1421              }              }
1422          }          }
1423      }      }
# Line 1048  namespace DLS { Line 1429  namespace DLS {
1429          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
1430          Region* pNewRegion = new Region(this, rgn);          Region* pNewRegion = new Region(this, rgn);
1431          pRegions->push_back(pNewRegion);          pRegions->push_back(pNewRegion);
1432          Regions = pRegions->size();          Regions = (uint32_t) pRegions->size();
1433          return pNewRegion;          return pNewRegion;
1434      }      }
1435    
1436      void Instrument::MoveRegion(Region* pSrc, Region* pDst) {      void Instrument::MoveRegion(Region* pSrc, Region* pDst) {
1437          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);          RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
1438          lrgn->MoveSubChunk(pSrc->pCkRegion, pDst ? pDst->pCkRegion : 0);          lrgn->MoveSubChunk(pSrc->pCkRegion, (RIFF::Chunk*) (pDst ? pDst->pCkRegion : 0));
1439            for (size_t i = 0; i < pRegions->size(); ++i) {
1440          pRegions->remove(pSrc);              if ((*pRegions)[i] == pSrc) {
1441          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);                  pRegions->erase(pRegions->begin() + i);
1442          pRegions->insert(iter, pSrc);                  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);
1443                    pRegions->insert(iter, pSrc);
1444                }
1445            }
1446      }      }
1447    
1448      void Instrument::DeleteRegion(Region* pRegion) {      void Instrument::DeleteRegion(Region* pRegion) {
# Line 1066  namespace DLS { Line 1450  namespace DLS {
1450          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);          RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
1451          if (iter == pRegions->end()) return;          if (iter == pRegions->end()) return;
1452          pRegions->erase(iter);          pRegions->erase(iter);
1453          Regions = pRegions->size();          Regions = (uint32_t) pRegions->size();
1454            pRegion->DeleteChunks();
1455          delete pRegion;          delete pRegion;
1456      }      }
1457    
# Line 1074  namespace DLS { Line 1459  namespace DLS {
1459       * Apply Instrument with all its Regions to the respective RIFF chunks.       * Apply Instrument with all its Regions to the respective RIFF chunks.
1460       * You have to call File::Save() to make changes persistent.       * You have to call File::Save() to make changes persistent.
1461       *       *
1462         * @param pProgress - callback function for progress notification
1463       * @throws Exception - on errors       * @throws Exception - on errors
1464       */       */
1465      void Instrument::UpdateChunks() {      void Instrument::UpdateChunks(progress_t* pProgress) {
1466          // first update base classes' chunks          // first update base classes' chunks
1467          Resource::UpdateChunks();          Resource::UpdateChunks(pProgress);
1468          Articulator::UpdateChunks();          Articulator::UpdateChunks(pProgress);
1469          // make sure 'insh' chunk exists          // make sure 'insh' chunk exists
1470          RIFF::Chunk* insh = pCkInstrument->GetSubChunk(CHUNK_ID_INSH);          RIFF::Chunk* insh = pCkInstrument->GetSubChunk(CHUNK_ID_INSH);
1471          if (!insh) insh = pCkInstrument->AddSubChunk(CHUNK_ID_INSH, 12);          if (!insh) insh = pCkInstrument->AddSubChunk(CHUNK_ID_INSH, 12);
1472          uint8_t* pData = (uint8_t*) insh->LoadChunkData();          uint8_t* pData = (uint8_t*) insh->LoadChunkData();
1473          // update 'insh' chunk          // update 'insh' chunk
1474          Regions = (pRegions) ? pRegions->size() : 0;          Regions = (pRegions) ? uint32_t(pRegions->size()) : 0;
1475          midi_locale_t locale;          midi_locale_t locale;
1476          locale.instrument = MIDIProgram;          locale.instrument = MIDIProgram;
1477          locale.bank       = MIDI_BANK_ENCODE(MIDIBankCoarse, MIDIBankFine);          locale.bank       = MIDI_BANK_ENCODE(MIDIBankCoarse, MIDIBankFine);
# Line 1098  namespace DLS { Line 1484  namespace DLS {
1484          if (!pRegions) return;          if (!pRegions) return;
1485          RegionList::iterator iter = pRegions->begin();          RegionList::iterator iter = pRegions->begin();
1486          RegionList::iterator end  = pRegions->end();          RegionList::iterator end  = pRegions->end();
1487          for (; iter != end; ++iter) {          for (int i = 0; iter != end; ++iter, ++i) {
1488              (*iter)->UpdateChunks();              if (pProgress) {
1489                    // divide local progress into subprogress
1490                    progress_t subprogress;
1491                    __divide_progress(pProgress, &subprogress, pRegions->size(), i);
1492                    // do the actual work
1493                    (*iter)->UpdateChunks(&subprogress);
1494                } else
1495                    (*iter)->UpdateChunks(NULL);
1496          }          }
1497            if (pProgress)
1498                __notify_progress(pProgress, 1.0); // notify done
1499      }      }
1500    
1501      /** @brief Destructor.      /** @brief Destructor.
1502       *       *
1503       * Removes RIFF chunks associated with this Instrument and frees all       * Frees all memory occupied by this instrument.
      * memory occupied by this instrument.  
1504       */       */
1505      Instrument::~Instrument() {      Instrument::~Instrument() {
1506          if (pRegions) {          if (pRegions) {
# Line 1118  namespace DLS { Line 1512  namespace DLS {
1512              }              }
1513              delete pRegions;              delete pRegions;
1514          }          }
         // remove instrument's chunks  
         RIFF::List* pParent = pCkInstrument->GetParent();  
         pParent->DeleteSubChunk(pCkInstrument);  
1515      }      }
1516    
1517        /** @brief Remove all RIFF chunks associated with this Instrument object.
1518         *
1519         * See Storage::DeleteChunks() for details.
1520         */
1521        void Instrument::DeleteChunks() {
1522            // handle base classes
1523            Resource::DeleteChunks();
1524            Articulator::DeleteChunks();
1525    
1526            // handle RIFF chunks of members
1527            if (pRegions) {
1528                RegionList::iterator it  = pRegions->begin();
1529                RegionList::iterator end = pRegions->end();
1530                for (; it != end; ++it)
1531                    (*it)->DeleteChunks();
1532            }
1533    
1534            // handle own RIFF chunks
1535            if (pCkInstrument) {
1536                RIFF::List* pParent = pCkInstrument->GetParent();
1537                pParent->DeleteSubChunk(pCkInstrument);
1538                pCkInstrument = NULL;
1539            }
1540        }
1541    
1542        void Instrument::CopyAssignCore(const Instrument* orig) {
1543            // handle base classes
1544            Resource::CopyAssign(orig);
1545            Articulator::CopyAssign(orig);
1546            // handle actual own attributes of this class
1547            // (the trivial ones)
1548            IsDrum = orig->IsDrum;
1549            MIDIBank = orig->MIDIBank;
1550            MIDIBankCoarse = orig->MIDIBankCoarse;
1551            MIDIBankFine = orig->MIDIBankFine;
1552            MIDIProgram = orig->MIDIProgram;
1553        }
1554        
1555        /**
1556         * Make a (semi) deep copy of the Instrument object given by @a orig and assign
1557         * it to this object.
1558         *
1559         * Note that all sample pointers referenced by @a orig are simply copied as
1560         * memory address. Thus the respective samples are shared, not duplicated!
1561         *
1562         * @param orig - original Instrument object to be copied from
1563         */
1564        void Instrument::CopyAssign(const Instrument* orig) {
1565            CopyAssignCore(orig);
1566            // delete all regions first
1567            while (Regions) DeleteRegion(GetFirstRegion());
1568            // now recreate and copy regions
1569            {
1570                RegionList::const_iterator it = orig->pRegions->begin();
1571                for (int i = 0; i < orig->Regions; ++i, ++it) {
1572                    Region* dstRgn = AddRegion();
1573                    //NOTE: Region does semi-deep copy !
1574                    dstRgn->CopyAssign(*it);
1575                }
1576            }
1577        }
1578    
1579    
1580  // *************** File ***************  // *************** File ***************
# Line 1136  namespace DLS { Line 1588  namespace DLS {
1588       */       */
1589      File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) {      File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) {
1590          pRIFF->SetByteOrder(RIFF::endian_little);          pRIFF->SetByteOrder(RIFF::endian_little);
1591            bOwningRiff = true;
1592          pVersion = new version_t;          pVersion = new version_t;
1593          pVersion->major   = 0;          pVersion->major   = 0;
1594          pVersion->minor   = 0;          pVersion->minor   = 0;
# Line 1166  namespace DLS { Line 1619  namespace DLS {
1619      File::File(RIFF::File* pRIFF) : Resource(NULL, pRIFF) {      File::File(RIFF::File* pRIFF) : Resource(NULL, pRIFF) {
1620          if (!pRIFF) throw DLS::Exception("NULL pointer reference to RIFF::File object.");          if (!pRIFF) throw DLS::Exception("NULL pointer reference to RIFF::File object.");
1621          this->pRIFF = pRIFF;          this->pRIFF = pRIFF;
1622            bOwningRiff = false;
1623          RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);          RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1624          if (ckVersion) {          if (ckVersion) {
1625                ckVersion->SetPos(0);
1626    
1627              pVersion = new version_t;              pVersion = new version_t;
1628              ckVersion->Read(pVersion, 4, 2);              ckVersion->Read(pVersion, 4, 2);
1629          }          }
# Line 1176  namespace DLS { Line 1631  namespace DLS {
1631    
1632          RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);          RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
1633          if (!colh) throw DLS::Exception("Mandatory chunks in RIFF list chunk not found.");          if (!colh) throw DLS::Exception("Mandatory chunks in RIFF list chunk not found.");
1634            colh->SetPos(0);
1635          Instruments = colh->ReadUint32();          Instruments = colh->ReadUint32();
1636    
1637          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
# Line 1186  namespace DLS { Line 1642  namespace DLS {
1642              WavePoolHeaderSize = 8;              WavePoolHeaderSize = 8;
1643              b64BitWavePoolOffsets = false;              b64BitWavePoolOffsets = false;
1644          } else {          } else {
1645                ptbl->SetPos(0);
1646    
1647              WavePoolHeaderSize = ptbl->ReadUint32();              WavePoolHeaderSize = ptbl->ReadUint32();
1648              WavePoolCount  = ptbl->ReadUint32();              WavePoolCount  = ptbl->ReadUint32();
1649              pWavePoolTable = new uint32_t[WavePoolCount];              pWavePoolTable = new uint32_t[WavePoolCount];
# Line 1198  namespace DLS { Line 1656  namespace DLS {
1656                  for (int i = 0 ; i < WavePoolCount ; i++) {                  for (int i = 0 ; i < WavePoolCount ; i++) {
1657                      pWavePoolTableHi[i] = ptbl->ReadUint32();                      pWavePoolTableHi[i] = ptbl->ReadUint32();
1658                      pWavePoolTable[i] = ptbl->ReadUint32();                      pWavePoolTable[i] = ptbl->ReadUint32();
1659                      if (pWavePoolTable[i] & 0x80000000)                      //NOTE: disabled this 2GB check, not sure why this check was still left here (Christian, 2016-05-12)
1660                          throw DLS::Exception("Files larger than 2 GB not yet supported");                      //if (pWavePoolTable[i] & 0x80000000)
1661                        //    throw DLS::Exception("Files larger than 2 GB not yet supported");
1662                  }                  }
1663              } else { // conventional 32 bit offsets              } else { // conventional 32 bit offsets
1664                  ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));                  ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
# Line 1237  namespace DLS { Line 1696  namespace DLS {
1696          if (pVersion) delete pVersion;          if (pVersion) delete pVersion;
1697          for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)          for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1698              delete *i;              delete *i;
1699            if (bOwningRiff)
1700                delete pRIFF;
1701      }      }
1702    
1703      Sample* File::GetFirstSample() {      Sample* File::GetFirstSample() {
# Line 1256  namespace DLS { Line 1717  namespace DLS {
1717          if (!pSamples) pSamples = new SampleList;          if (!pSamples) pSamples = new SampleList;
1718          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
1719          if (wvpl) {          if (wvpl) {
1720              unsigned long wvplFileOffset = wvpl->GetFilePos();              file_offset_t wvplFileOffset = wvpl->GetFilePos() -
1721              RIFF::List* wave = wvpl->GetFirstSubList();                                             wvpl->GetPos(); // should be zero, but just to be sure
1722              while (wave) {              size_t i = 0;
1723                for (RIFF::List* wave = wvpl->GetSubListAt(i); wave;
1724                     wave = wvpl->GetSubListAt(++i))
1725                {
1726                  if (wave->GetListType() == LIST_TYPE_WAVE) {                  if (wave->GetListType() == LIST_TYPE_WAVE) {
1727                      unsigned long waveFileOffset = wave->GetFilePos();                      file_offset_t waveFileOffset = wave->GetFilePos() -
1728                                                       wave->GetPos(); // should be zero, but just to be sure
1729                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1730                  }                  }
                 wave = wvpl->GetNextSubList();  
1731              }              }
1732          }          }
1733          else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)          else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)
1734              RIFF::List* dwpl = pRIFF->GetSubList(LIST_TYPE_DWPL);              RIFF::List* dwpl = pRIFF->GetSubList(LIST_TYPE_DWPL);
1735              if (dwpl) {              if (dwpl) {
1736                  unsigned long dwplFileOffset = dwpl->GetFilePos();                  file_offset_t dwplFileOffset = dwpl->GetFilePos() -
1737                  RIFF::List* wave = dwpl->GetFirstSubList();                                                 dwpl->GetPos(); // should be zero, but just to be sure
1738                  while (wave) {                  size_t i = 0;
1739                    for (RIFF::List* wave = dwpl->GetSubListAt(i); wave;
1740                         wave = dwpl->GetSubListAt(++i))
1741                    {
1742                      if (wave->GetListType() == LIST_TYPE_WAVE) {                      if (wave->GetListType() == LIST_TYPE_WAVE) {
1743                          unsigned long waveFileOffset = wave->GetFilePos();                          file_offset_t waveFileOffset = wave->GetFilePos() -
1744                                                           wave->GetPos(); // should be zero, but just to be sure
1745                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1746                      }                      }
                     wave = dwpl->GetNextSubList();  
1747                  }                  }
1748              }              }
1749          }          }
# Line 1312  namespace DLS { Line 1779  namespace DLS {
1779          SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample);          SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample);
1780          if (iter == pSamples->end()) return;          if (iter == pSamples->end()) return;
1781          pSamples->erase(iter);          pSamples->erase(iter);
1782            pSample->DeleteChunks();
1783          delete pSample;          delete pSample;
1784      }      }
1785    
# Line 1332  namespace DLS { Line 1800  namespace DLS {
1800          if (!pInstruments) pInstruments = new InstrumentList;          if (!pInstruments) pInstruments = new InstrumentList;
1801          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1802          if (lstInstruments) {          if (lstInstruments) {
1803              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();              size_t i = 0;
1804              while (lstInstr) {              for (RIFF::List* lstInstr = lstInstruments->GetSubListAt(i);
1805                     lstInstr; lstInstr = lstInstruments->GetSubListAt(++i))
1806                {
1807                  if (lstInstr->GetListType() == LIST_TYPE_INS) {                  if (lstInstr->GetListType() == LIST_TYPE_INS) {
1808                      pInstruments->push_back(new Instrument(this, lstInstr));                      pInstruments->push_back(new Instrument(this, lstInstr));
1809                  }                  }
                 lstInstr = lstInstruments->GetNextSubList();  
1810              }              }
1811          }          }
1812      }      }
# Line 1371  namespace DLS { Line 1840  namespace DLS {
1840          InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument);          InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument);
1841          if (iter == pInstruments->end()) return;          if (iter == pInstruments->end()) return;
1842          pInstruments->erase(iter);          pInstruments->erase(iter);
1843            pInstrument->DeleteChunks();
1844          delete pInstrument;          delete pInstrument;
1845      }      }
1846    
1847      /**      /**
1848         * Returns the underlying RIFF::File used for persistency of this DLS::File
1849         * object.
1850         */
1851        RIFF::File* File::GetRiffFile() {
1852            return pRIFF;
1853        }
1854    
1855        /**
1856         * Returns extension file of given index. Extension files are used
1857         * sometimes to circumvent the 2 GB file size limit of the RIFF format and
1858         * of certain operating systems in general. In this case, instead of just
1859         * using one file, the content is spread among several files with similar
1860         * file name scheme. This is especially used by some GigaStudio sound
1861         * libraries.
1862         *
1863         * @param index - index of extension file
1864         * @returns sought extension file, NULL if index out of bounds
1865         * @see GetFileName()
1866         */
1867        RIFF::File* File::GetExtensionFile(int index) {
1868            if (index < 0 || index >= ExtensionFiles.size()) return NULL;
1869            std::list<RIFF::File*>::iterator iter = ExtensionFiles.begin();
1870            for (int i = 0; iter != ExtensionFiles.end(); ++iter, ++i)
1871                if (i == index) return *iter;
1872            return NULL;
1873        }
1874    
1875        /** @brief File name of this DLS file.
1876         *
1877         * This method returns the file name as it was provided when loading
1878         * the respective DLS file. However in case the File object associates
1879         * an empty, that is new DLS file, which was not yet saved to disk,
1880         * this method will return an empty string.
1881         *
1882         * @see GetExtensionFile()
1883         */
1884        String File::GetFileName() {
1885            return pRIFF->GetFileName();
1886        }
1887        
1888        /**
1889         * You may call this method store a future file name, so you don't have to
1890         * to pass it to the Save() call later on.
1891         */
1892        void File::SetFileName(const String& name) {
1893            pRIFF->SetFileName(name);
1894        }
1895    
1896        /**
1897       * Apply all the DLS file's current instruments, samples and settings to       * Apply all the DLS file's current instruments, samples and settings to
1898       * the respective RIFF chunks. You have to call Save() to make changes       * the respective RIFF chunks. You have to call Save() to make changes
1899       * persistent.       * persistent.
1900       *       *
1901         * @param pProgress - callback function for progress notification
1902       * @throws Exception - on errors       * @throws Exception - on errors
1903       */       */
1904      void File::UpdateChunks() {      void File::UpdateChunks(progress_t* pProgress) {
1905          // first update base class's chunks          // first update base class's chunks
1906          Resource::UpdateChunks();          Resource::UpdateChunks(pProgress);
1907    
1908          // if version struct exists, update 'vers' chunk          // if version struct exists, update 'vers' chunk
1909          if (pVersion) {          if (pVersion) {
# Line 1397  namespace DLS { Line 1917  namespace DLS {
1917          }          }
1918    
1919          // update 'colh' chunk          // update 'colh' chunk
1920          Instruments = (pInstruments) ? pInstruments->size() : 0;          Instruments = (pInstruments) ? uint32_t(pInstruments->size()) : 0;
1921          RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);          RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
1922          if (!colh)   colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);          if (!colh)   colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);
1923          uint8_t* pData = (uint8_t*) colh->LoadChunkData();          uint8_t* pData = (uint8_t*) colh->LoadChunkData();
# Line 1405  namespace DLS { Line 1925  namespace DLS {
1925    
1926          // update instrument's chunks          // update instrument's chunks
1927          if (pInstruments) {          if (pInstruments) {
1928              InstrumentList::iterator iter = pInstruments->begin();              if (pProgress) {
1929              InstrumentList::iterator end  = pInstruments->end();                  // divide local progress into subprogress
1930              for (; iter != end; ++iter) {                  progress_t subprogress;
1931                  (*iter)->UpdateChunks();                  __divide_progress(pProgress, &subprogress, 20.f, 0.f); // arbitrarily subdivided into 5% of total progress
1932    
1933                    // do the actual work
1934                    InstrumentList::iterator iter = pInstruments->begin();
1935                    InstrumentList::iterator end  = pInstruments->end();
1936                    for (int i = 0; iter != end; ++iter, ++i) {
1937                        // divide subprogress into sub-subprogress
1938                        progress_t subsubprogress;
1939                        __divide_progress(&subprogress, &subsubprogress, pInstruments->size(), i);
1940                        // do the actual work
1941                        (*iter)->UpdateChunks(&subsubprogress);
1942                    }
1943    
1944                    __notify_progress(&subprogress, 1.0); // notify subprogress done
1945                } else {
1946                    InstrumentList::iterator iter = pInstruments->begin();
1947                    InstrumentList::iterator end  = pInstruments->end();
1948                    for (int i = 0; iter != end; ++iter, ++i) {
1949                        (*iter)->UpdateChunks(NULL);
1950                    }
1951              }              }
1952          }          }
1953    
1954          // update 'ptbl' chunk          // update 'ptbl' chunk
1955          const int iSamples = (pSamples) ? pSamples->size() : 0;          const int iSamples = (pSamples) ? int(pSamples->size()) : 0;
1956          const int iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;          int iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1957          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
1958          if (!ptbl)   ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, 1 /*anything, we'll resize*/);          if (!ptbl)   ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, 1 /*anything, we'll resize*/);
1959          const int iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;          int iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
1960          ptbl->Resize(iPtblSize);          ptbl->Resize(iPtblSize);
1961          pData = (uint8_t*) ptbl->LoadChunkData();          pData = (uint8_t*) ptbl->LoadChunkData();
1962          WavePoolCount = iSamples;          WavePoolCount = iSamples;
# Line 1427  namespace DLS { Line 1966  namespace DLS {
1966    
1967          // update sample's chunks          // update sample's chunks
1968          if (pSamples) {          if (pSamples) {
1969              SampleList::iterator iter = pSamples->begin();              if (pProgress) {
1970              SampleList::iterator end  = pSamples->end();                  // divide local progress into subprogress
1971              for (; iter != end; ++iter) {                  progress_t subprogress;
1972                  (*iter)->UpdateChunks();                  __divide_progress(pProgress, &subprogress, 20.f, 1.f); // arbitrarily subdivided into 95% of total progress
1973    
1974                    // do the actual work
1975                    SampleList::iterator iter = pSamples->begin();
1976                    SampleList::iterator end  = pSamples->end();
1977                    for (int i = 0; iter != end; ++iter, ++i) {
1978                        // divide subprogress into sub-subprogress
1979                        progress_t subsubprogress;
1980                        __divide_progress(&subprogress, &subsubprogress, pSamples->size(), i);
1981                        // do the actual work
1982                        (*iter)->UpdateChunks(&subsubprogress);
1983                    }
1984    
1985                    __notify_progress(&subprogress, 1.0); // notify subprogress done
1986                } else {
1987                    SampleList::iterator iter = pSamples->begin();
1988                    SampleList::iterator end  = pSamples->end();
1989                    for (int i = 0; iter != end; ++iter, ++i) {
1990                        (*iter)->UpdateChunks(NULL);
1991                    }
1992              }              }
1993          }          }
1994    
1995            // if there are any extension files, gather which ones are regular
1996            // extension files used as wave pool files (.gx00, .gx01, ... , .gx98)
1997            // and which one is probably a convolution (GigaPulse) file (always to
1998            // be saved as .gx99)
1999            std::list<RIFF::File*> poolFiles;  // < for (.gx00, .gx01, ... , .gx98) files
2000            RIFF::File* pGigaPulseFile = NULL; // < for .gx99 file
2001            if (!ExtensionFiles.empty()) {
2002                std::list<RIFF::File*>::iterator it = ExtensionFiles.begin();
2003                for (; it != ExtensionFiles.end(); ++it) {
2004                    //FIXME: the .gx99 file is always used by GSt for convolution
2005                    // data (GigaPulse); so we should better detect by subchunk
2006                    // whether the extension file is intended for convolution
2007                    // instead of checkking for a file name, because the latter does
2008                    // not work for saving new gigs created from scratch
2009                    const std::string oldName = (*it)->GetFileName();
2010                    const bool isGigaPulseFile = (extensionOfPath(oldName) == "gx99");
2011                    if (isGigaPulseFile)
2012                        pGigaPulseFile = *it;
2013                    else
2014                        poolFiles.push_back(*it);
2015                }
2016            }
2017    
2018            // update the 'xfil' chunk which describes all extension files (wave
2019            // pool files) except the .gx99 file
2020            if (!poolFiles.empty()) {
2021                const int n = poolFiles.size();
2022                const int iHeaderSize = 4;
2023                const int iEntrySize = 144;
2024    
2025                // make sure chunk exists, and with correct size
2026                RIFF::Chunk* ckXfil = pRIFF->GetSubChunk(CHUNK_ID_XFIL);
2027                if (ckXfil)
2028                    ckXfil->Resize(iHeaderSize + n * iEntrySize);
2029                else
2030                    ckXfil = pRIFF->AddSubChunk(CHUNK_ID_XFIL, iHeaderSize + n * iEntrySize);
2031    
2032                uint8_t* pData = (uint8_t*) ckXfil->LoadChunkData();
2033    
2034                // re-assemble the chunk's content
2035                store32(pData, n);
2036                std::list<RIFF::File*>::iterator itExtFile = poolFiles.begin();
2037                for (int i = 0, iOffset = 4; i < n;
2038                     ++itExtFile, ++i, iOffset += iEntrySize)
2039                {
2040                    // update the filename string and 5 byte extension of each extension file
2041                    std::string file = lastPathComponent(
2042                        (*itExtFile)->GetFileName()
2043                    );
2044                    if (file.length() + 6 > 128)
2045                        throw Exception("Fatal error, extension filename length exceeds 122 byte maximum");
2046                    uint8_t* pStrings = &pData[iOffset];
2047                    memset(pStrings, 0, 128);
2048                    memcpy(pStrings, file.c_str(), file.length());
2049                    pStrings += file.length() + 1;
2050                    std::string ext = file.substr(file.length()-5);
2051                    memcpy(pStrings, ext.c_str(), 5);
2052                    // update the dlsid of the extension file
2053                    uint8_t* pId = &pData[iOffset + 128];
2054                    dlsid_t id;
2055                    RIFF::Chunk* ckDLSID = (*itExtFile)->GetSubChunk(CHUNK_ID_DLID);
2056                    if (ckDLSID) {
2057                        ckDLSID->Read(&id.ulData1, 1, 4);
2058                        ckDLSID->Read(&id.usData2, 1, 2);
2059                        ckDLSID->Read(&id.usData3, 1, 2);
2060                        ckDLSID->Read(id.abData, 8, 1);
2061                    } else {
2062                        ckDLSID = (*itExtFile)->AddSubChunk(CHUNK_ID_DLID, 16);
2063                        Resource::GenerateDLSID(&id);
2064                        uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
2065                        store32(&pData[0], id.ulData1);
2066                        store16(&pData[4], id.usData2);
2067                        store16(&pData[6], id.usData3);
2068                        memcpy(&pData[8], id.abData, 8);
2069                    }
2070                    store32(&pId[0], id.ulData1);
2071                    store16(&pId[4], id.usData2);
2072                    store16(&pId[6], id.usData3);
2073                    memcpy(&pId[8], id.abData, 8);
2074                }
2075            } else {
2076                // in case there was a 'xfil' chunk, remove it
2077                RIFF::Chunk* ckXfil = pRIFF->GetSubChunk(CHUNK_ID_XFIL);
2078                if (ckXfil) pRIFF->DeleteSubChunk(ckXfil);
2079            }
2080    
2081            // update the 'doxf' chunk which describes a .gx99 extension file
2082            // which contains convolution data (GigaPulse)
2083            if (pGigaPulseFile) {
2084                RIFF::Chunk* ckDoxf = pRIFF->GetSubChunk(CHUNK_ID_DOXF);
2085                if (!ckDoxf) ckDoxf = pRIFF->AddSubChunk(CHUNK_ID_DOXF, 148);
2086    
2087                uint8_t* pData = (uint8_t*) ckDoxf->LoadChunkData();
2088    
2089                // update the dlsid from the extension file
2090                uint8_t* pId = &pData[132];
2091                RIFF::Chunk* ckDLSID = pGigaPulseFile->GetSubChunk(CHUNK_ID_DLID);
2092                if (!ckDLSID) { //TODO: auto generate DLS ID if missing
2093                    throw Exception("Fatal error, GigaPulse file does not contain a DLS ID chunk");
2094                } else {
2095                    dlsid_t id;
2096                    // read DLS ID from extension files's DLS ID chunk
2097                    uint8_t* pData = (uint8_t*) ckDLSID->LoadChunkData();
2098                    id.ulData1 = load32(&pData[0]);
2099                    id.usData2 = load16(&pData[4]);
2100                    id.usData3 = load16(&pData[6]);
2101                    memcpy(id.abData, &pData[8], 8);
2102                    // store DLS ID to 'doxf' chunk
2103                    store32(&pId[0], id.ulData1);
2104                    store16(&pId[4], id.usData2);
2105                    store16(&pId[6], id.usData3);
2106                    memcpy(&pId[8], id.abData, 8);
2107                }
2108            } else {
2109                // in case there was a 'doxf' chunk, remove it
2110                RIFF::Chunk* ckDoxf = pRIFF->GetSubChunk(CHUNK_ID_DOXF);
2111                if (ckDoxf) pRIFF->DeleteSubChunk(ckDoxf);
2112            }
2113    
2114            // the RIFF file to be written might now been grown >= 4GB or might
2115            // been shrunk < 4GB, so we might need to update the wave pool offset
2116            // size and thus accordingly we would need to resize the wave pool
2117            // chunk
2118            const file_offset_t finalFileSize = pRIFF->GetRequiredFileSize();
2119            const bool bRequires64Bit = (finalFileSize >> 32) != 0 || // < native 64 bit gig file
2120                                         poolFiles.size() > 0;        // < 32 bit gig file where the hi 32 bits are used as extension file nr
2121            if (b64BitWavePoolOffsets != bRequires64Bit) {
2122                b64BitWavePoolOffsets = bRequires64Bit;
2123                iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
2124                iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
2125                ptbl->Resize(iPtblSize);
2126            }
2127    
2128            if (pProgress)
2129                __notify_progress(pProgress, 1.0); // notify done
2130      }      }
2131    
2132      /** @brief Save changes to another file.      /** @brief Save changes to another file.
# Line 1447  namespace DLS { Line 2141  namespace DLS {
2141       * the new file (given by \a Path) afterwards.       * the new file (given by \a Path) afterwards.
2142       *       *
2143       * @param Path - path and file name where everything should be written to       * @param Path - path and file name where everything should be written to
2144         * @param pProgress - optional: callback function for progress notification
2145       */       */
2146      void File::Save(const String& Path) {      void File::Save(const String& Path, progress_t* pProgress) {
2147          UpdateChunks();          // calculate number of tasks to notify progress appropriately
2148          pRIFF->Save(Path);          const size_t nExtFiles = ExtensionFiles.size();
2149          __UpdateWavePoolTableChunk();          const float tasks = 2.f + nExtFiles;
2150    
2151            // save extension files (if required)
2152            if (!ExtensionFiles.empty()) {
2153                // for assembling path of extension files to be saved to
2154                const std::string baseName = pathWithoutExtension(Path);
2155                // save the individual extension files
2156                std::list<RIFF::File*>::iterator it = ExtensionFiles.begin();
2157                for (int i = 0; it != ExtensionFiles.end(); ++i, ++it) {
2158                    //FIXME: the .gx99 file is always used by GSt for convolution
2159                    // data (GigaPulse); so we should better detect by subchunk
2160                    // whether the extension file is intended for convolution
2161                    // instead of checkking for a file name, because the latter does
2162                    // not work for saving new gigs created from scratch
2163                    const std::string oldName = (*it)->GetFileName();
2164                    const bool isGigaPulseFile = (extensionOfPath(oldName) == "gx99");
2165                    std::string ext = (isGigaPulseFile) ? ".gx99" : strPrint(".gx%02d", i+1);
2166                    std::string newPath = baseName + ext;
2167                    // save extension file to its new location
2168                    if (pProgress) {
2169                         // divide local progress into subprogress
2170                        progress_t subprogress;
2171                        __divide_progress(pProgress, &subprogress, tasks, 0.f + i); // subdivided into amount of extension files
2172                        // do the actual work
2173                        (*it)->Save(newPath, &subprogress);
2174                    } else
2175                        (*it)->Save(newPath);
2176                }
2177            }
2178    
2179            if (pProgress) {
2180                // divide local progress into subprogress
2181                progress_t subprogress;
2182                __divide_progress(pProgress, &subprogress, tasks, 1.f + nExtFiles); // arbitrarily subdivided into 50% (minus extension files progress)
2183                // do the actual work
2184                UpdateChunks(&subprogress);
2185            } else
2186                UpdateChunks(NULL);
2187    
2188            if (pProgress) {
2189                // divide local progress into subprogress
2190                progress_t subprogress;
2191                __divide_progress(pProgress, &subprogress, tasks, 2.f + nExtFiles); // arbitrarily subdivided into 50% (minus extension files progress)
2192                // do the actual work
2193                pRIFF->Save(Path, &subprogress);
2194            } else
2195                pRIFF->Save(Path);
2196    
2197            UpdateFileOffsets();
2198    
2199            if (pProgress)
2200                __notify_progress(pProgress, 1.0); // notify done
2201      }      }
2202    
2203      /** @brief Save changes to same file.      /** @brief Save changes to same file.
# Line 1460  namespace DLS { Line 2206  namespace DLS {
2206       * file. The file might temporarily grow to a higher size than it will       * file. The file might temporarily grow to a higher size than it will
2207       * have at the end of the saving process.       * have at the end of the saving process.
2208       *       *
2209       * @throws RIFF::Exception if any kind of IO error occured       * @param pProgress - optional: callback function for progress notification
2210       * @throws DLS::Exception  if any kind of DLS specific error occured       * @throws RIFF::Exception if any kind of IO error occurred
2211         * @throws DLS::Exception  if any kind of DLS specific error occurred
2212         */
2213        void File::Save(progress_t* pProgress) {
2214            // calculate number of tasks to notify progress appropriately
2215            const size_t nExtFiles = ExtensionFiles.size();
2216            const float tasks = 2.f + nExtFiles;
2217    
2218            // save extension files (if required)
2219            if (!ExtensionFiles.empty()) {
2220                std::list<RIFF::File*>::iterator it = ExtensionFiles.begin();
2221                for (int i = 0; it != ExtensionFiles.end(); ++i, ++it) {
2222                    // save extension file
2223                    if (pProgress) {
2224                        // divide local progress into subprogress
2225                        progress_t subprogress;
2226                        __divide_progress(pProgress, &subprogress, tasks, 0.f + i); // subdivided into amount of extension files
2227                        // do the actual work
2228                        (*it)->Save(&subprogress);
2229                    } else
2230                        (*it)->Save();
2231                }
2232            }
2233    
2234            if (pProgress) {
2235                // divide local progress into subprogress
2236                progress_t subprogress;
2237                __divide_progress(pProgress, &subprogress, tasks, 1.f + nExtFiles); // arbitrarily subdivided into 50% (minus extension files progress)
2238                // do the actual work
2239                UpdateChunks(&subprogress);
2240            } else
2241                UpdateChunks(NULL);
2242    
2243            if (pProgress) {
2244                // divide local progress into subprogress
2245                progress_t subprogress;
2246                __divide_progress(pProgress, &subprogress, tasks, 2.f + nExtFiles); // arbitrarily subdivided into 50% (minus extension files progress)
2247                // do the actual work
2248                pRIFF->Save(&subprogress);
2249            } else
2250                pRIFF->Save();
2251    
2252            UpdateFileOffsets();
2253    
2254            if (pProgress)
2255                __notify_progress(pProgress, 1.0); // notify done
2256        }
2257    
2258        /** @brief Updates all file offsets stored all over the file.
2259         *
2260         * This virtual method is called whenever the overall file layout has been
2261         * changed (i.e. file or individual RIFF chunks have been resized). It is
2262         * then the responsibility of this method to update all file offsets stored
2263         * in the file format. For example samples are referenced by instruments by
2264         * file offsets. The gig format also stores references to instrument
2265         * scripts as file offsets, and thus it overrides this method to update
2266         * those file offsets as well.
2267       */       */
2268      void File::Save() {      void File::UpdateFileOffsets() {
         UpdateChunks();  
         pRIFF->Save();  
2269          __UpdateWavePoolTableChunk();          __UpdateWavePoolTableChunk();
2270      }      }
2271    
# Line 1503  namespace DLS { Line 2303  namespace DLS {
2303          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);          RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
2304          const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;          const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
2305          // check if 'ptbl' chunk is large enough          // check if 'ptbl' chunk is large enough
2306          WavePoolCount = (pSamples) ? pSamples->size() : 0;          WavePoolCount = (pSamples) ? uint32_t(pSamples->size()) : 0;
2307          const unsigned long ulRequiredSize = WavePoolHeaderSize + iOffsetSize * WavePoolCount;          const file_offset_t ulRequiredSize = WavePoolHeaderSize + iOffsetSize * WavePoolCount;
2308          if (ptbl->GetSize() < ulRequiredSize) throw Exception("Fatal error, 'ptbl' chunk too small");          if (ptbl->GetSize() < ulRequiredSize) throw Exception("Fatal error, 'ptbl' chunk too small");
2309          // save the 'ptbl' chunk's current read/write position          // save the 'ptbl' chunk's current read/write position
2310          unsigned long ulOriginalPos = ptbl->GetPos();          file_offset_t ullOriginalPos = ptbl->GetPos();
2311          // update headers          // update headers
2312          ptbl->SetPos(0);          ptbl->SetPos(0);
2313          uint32_t tmp = WavePoolHeaderSize;          uint32_t tmp = WavePoolHeaderSize;
# Line 1530  namespace DLS { Line 2330  namespace DLS {
2330              }              }
2331          }          }
2332          // restore 'ptbl' chunk's original read/write position          // restore 'ptbl' chunk's original read/write position
2333          ptbl->SetPos(ulOriginalPos);          ptbl->SetPos(ullOriginalPos);
2334      }      }
2335    
2336      /**      /**
# Line 1539  namespace DLS { Line 2339  namespace DLS {
2339       * exists already.       * exists already.
2340       */       */
2341      void File::__UpdateWavePoolTable() {      void File::__UpdateWavePoolTable() {
2342          WavePoolCount = (pSamples) ? pSamples->size() : 0;          WavePoolCount = (pSamples) ? uint32_t(pSamples->size()) : 0;
2343          // resize wave pool table arrays          // resize wave pool table arrays
2344          if (pWavePoolTable)   delete[] pWavePoolTable;          if (pWavePoolTable)   delete[] pWavePoolTable;
2345          if (pWavePoolTableHi) delete[] pWavePoolTableHi;          if (pWavePoolTableHi) delete[] pWavePoolTableHi;
2346          pWavePoolTable   = new uint32_t[WavePoolCount];          pWavePoolTable   = new uint32_t[WavePoolCount];
2347          pWavePoolTableHi = new uint32_t[WavePoolCount];          pWavePoolTableHi = new uint32_t[WavePoolCount];
2348          if (!pSamples) return;          if (!pSamples) return;
2349          // update offsets int wave pool table          // update offsets in wave pool table
2350          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
2351          uint64_t wvplFileOffset = wvpl->GetFilePos();          uint64_t wvplFileOffset = wvpl->GetFilePos() -
2352          if (b64BitWavePoolOffsets) {                                    wvpl->GetPos(); // mandatory, since position might have changed
2353              SampleList::iterator iter = pSamples->begin();          if (!b64BitWavePoolOffsets) { // conventional 32 bit offsets (and no extension files) ...
             SampleList::iterator end  = pSamples->end();  
             for (int i = 0 ; iter != end ; ++iter, i++) {  
                 uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE;  
                 (*iter)->ulWavePoolOffset = _64BitOffset;  
                 pWavePoolTableHi[i] = (uint32_t) (_64BitOffset >> 32);  
                 pWavePoolTable[i]   = (uint32_t) _64BitOffset;  
             }  
         } else { // conventional 32 bit offsets  
2354              SampleList::iterator iter = pSamples->begin();              SampleList::iterator iter = pSamples->begin();
2355              SampleList::iterator end  = pSamples->end();              SampleList::iterator end  = pSamples->end();
2356              for (int i = 0 ; iter != end ; ++iter, i++) {              for (int i = 0 ; iter != end ; ++iter, i++) {
2357                  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE;                  uint64_t _64BitOffset =
2358                  (*iter)->ulWavePoolOffset = _64BitOffset;                      (*iter)->pWaveList->GetFilePos() -
2359                        (*iter)->pWaveList->GetPos() - // should be zero, but just to be sure
2360                        wvplFileOffset -
2361                        LIST_HEADER_SIZE(pRIFF->GetFileOffsetSize());
2362                    (*iter)->ullWavePoolOffset = _64BitOffset;
2363                  pWavePoolTable[i] = (uint32_t) _64BitOffset;                  pWavePoolTable[i] = (uint32_t) _64BitOffset;
2364              }              }
2365            } else { // a) native 64 bit offsets without extension files or b) 32 bit offsets with extension files ...
2366                if (ExtensionFiles.empty()) { // native 64 bit offsets (and no extension files) [not compatible with GigaStudio] ...
2367                    SampleList::iterator iter = pSamples->begin();
2368                    SampleList::iterator end  = pSamples->end();
2369                    for (int i = 0 ; iter != end ; ++iter, i++) {
2370                        uint64_t _64BitOffset =
2371                            (*iter)->pWaveList->GetFilePos() -
2372                            (*iter)->pWaveList->GetPos() - // should be zero, but just to be sure
2373                            wvplFileOffset -
2374                            LIST_HEADER_SIZE(pRIFF->GetFileOffsetSize());
2375                        (*iter)->ullWavePoolOffset = _64BitOffset;
2376                        pWavePoolTableHi[i] = (uint32_t) (_64BitOffset >> 32);
2377                        pWavePoolTable[i]   = (uint32_t) _64BitOffset;
2378                    }
2379                } else { // 32 bit offsets with extension files (GigaStudio legacy support) ...
2380                    // the main gig and the extension files may contain wave data
2381                    std::vector<RIFF::File*> poolFiles;
2382                    poolFiles.push_back(pRIFF);
2383                    poolFiles.insert(poolFiles.end(), ExtensionFiles.begin(), ExtensionFiles.end());
2384    
2385                    RIFF::File* pCurPoolFile = NULL;
2386                    int fileNo = 0;
2387                    int waveOffset = 0;
2388                    SampleList::iterator iter = pSamples->begin();
2389                    SampleList::iterator end  = pSamples->end();
2390                    for (int i = 0 ; iter != end ; ++iter, i++) {
2391                        RIFF::File* pPoolFile = (*iter)->pWaveList->GetFile();
2392                        // if this sample is located in the same pool file as the
2393                        // last we reuse the previously computed fileNo and waveOffset
2394                        if (pPoolFile != pCurPoolFile) { // it is a different pool file than the last sample ...
2395                            pCurPoolFile = pPoolFile;
2396    
2397                            std::vector<RIFF::File*>::iterator sIter;
2398                            sIter = std::find(poolFiles.begin(), poolFiles.end(), pPoolFile);
2399                            if (sIter != poolFiles.end())
2400                                fileNo = std::distance(poolFiles.begin(), sIter);
2401                            else
2402                                throw DLS::Exception("Fatal error, unknown pool file");
2403    
2404                            RIFF::List* extWvpl = pCurPoolFile->GetSubList(LIST_TYPE_WVPL);
2405                            if (!extWvpl)
2406                                throw DLS::Exception("Fatal error, pool file has no 'wvpl' list chunk");
2407                            waveOffset =
2408                                extWvpl->GetFilePos() -
2409                                extWvpl->GetPos() + // mandatory, since position might have changed
2410                                LIST_HEADER_SIZE(pCurPoolFile->GetFileOffsetSize());
2411                        }
2412                        uint64_t _64BitOffset =
2413                            (*iter)->pWaveList->GetFilePos() -
2414                            (*iter)->pWaveList->GetPos() - // should be zero, but just to be sure
2415                            waveOffset;
2416                        // pWavePoolTableHi stores file number when extension files are in use
2417                        pWavePoolTableHi[i] = (uint32_t) fileNo;
2418                        pWavePoolTable[i]   = (uint32_t) _64BitOffset;
2419                        (*iter)->ullWavePoolOffset = _64BitOffset;
2420                    }
2421                }
2422          }          }
2423      }      }
2424    
2425    
   
2426  // *************** Exception ***************  // *************** Exception ***************
2427  // *  // *
2428    
2429      Exception::Exception(String Message) : RIFF::Exception(Message) {      Exception::Exception() : RIFF::Exception() {
2430        }
2431    
2432        Exception::Exception(String format, ...) : RIFF::Exception() {
2433            va_list arg;
2434            va_start(arg, format);
2435            Message = assemble(format, arg);
2436            va_end(arg);
2437        }
2438    
2439        Exception::Exception(String format, va_list arg) : RIFF::Exception() {
2440            Message = assemble(format, arg);
2441      }      }
2442    
2443      void Exception::PrintMessage() {      void Exception::PrintMessage() {

Legend:
Removed from v.1218  
changed lines
  Added in v.3926

  ViewVC Help
Powered by ViewVC