libgig  3.3.0.svn3
DLS.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * libgig - C++ cross-platform Gigasampler format file access library *
4  * *
5  * Copyright (C) 2003-2009 by Christian Schoenebeck *
6  * <cuse@users.sourceforge.net> *
7  * *
8  * This library is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  ***************************************************************************/
23 
24 #include "DLS.h"
25 
26 #include <algorithm>
27 #include <time.h>
28 
29 #ifdef __APPLE__
30 #include <CoreFoundation/CFUUID.h>
31 #elif defined(HAVE_UUID_UUID_H)
32 #include <uuid/uuid.h>
33 #endif
34 
35 #include "helper.h"
36 
37 // macros to decode connection transforms
38 #define CONN_TRANSFORM_SRC(x) ((x >> 10) & 0x000F)
39 #define CONN_TRANSFORM_CTL(x) ((x >> 4) & 0x000F)
40 #define CONN_TRANSFORM_DST(x) (x & 0x000F)
41 #define CONN_TRANSFORM_BIPOLAR_SRC(x) (x & 0x4000)
42 #define CONN_TRANSFORM_BIPOLAR_CTL(x) (x & 0x0100)
43 #define CONN_TRANSFORM_INVERT_SRC(x) (x & 0x8000)
44 #define CONN_TRANSFORM_INVERT_CTL(x) (x & 0x0200)
45 
46 // macros to encode connection transforms
47 #define CONN_TRANSFORM_SRC_ENCODE(x) ((x & 0x000F) << 10)
48 #define CONN_TRANSFORM_CTL_ENCODE(x) ((x & 0x000F) << 4)
49 #define CONN_TRANSFORM_DST_ENCODE(x) (x & 0x000F)
50 #define CONN_TRANSFORM_BIPOLAR_SRC_ENCODE(x) ((x) ? 0x4000 : 0)
51 #define CONN_TRANSFORM_BIPOLAR_CTL_ENCODE(x) ((x) ? 0x0100 : 0)
52 #define CONN_TRANSFORM_INVERT_SRC_ENCODE(x) ((x) ? 0x8000 : 0)
53 #define CONN_TRANSFORM_INVERT_CTL_ENCODE(x) ((x) ? 0x0200 : 0)
54 
55 #define DRUM_TYPE_MASK 0x80000000
56 
57 #define F_RGN_OPTION_SELFNONEXCLUSIVE 0x0001
58 
59 #define F_WAVELINK_PHASE_MASTER 0x0001
60 #define F_WAVELINK_MULTICHANNEL 0x0002
61 
62 #define F_WSMP_NO_TRUNCATION 0x0001
63 #define F_WSMP_NO_COMPRESSION 0x0002
64 
65 #define MIDI_BANK_COARSE(x) ((x & 0x00007F00) >> 8) // CC0
66 #define MIDI_BANK_FINE(x) (x & 0x0000007F) // CC32
67 #define MIDI_BANK_MERGE(coarse, fine) ((((uint16_t) coarse) << 7) | fine) // CC0 + CC32
68 #define MIDI_BANK_ENCODE(coarse, fine) (((coarse & 0x0000007F) << 8) | (fine & 0x0000007F))
69 
70 namespace DLS {
71 
72 // *************** Connection ***************
73 // *
74 
76  Source = (conn_src_t) Header->source;
77  Control = (conn_src_t) Header->control;
79  Scale = Header->scale;
87  }
88 
90  conn_block_t c;
91  c.source = Source;
92  c.control = Control;
94  c.scale = Scale;
102  return c;
103  }
104 
105 
106 
107 // *************** Articulation ***************
108 // *
109 
119  pArticulationCk = artl;
120  if (artl->GetChunkID() != CHUNK_ID_ART2 &&
121  artl->GetChunkID() != CHUNK_ID_ARTL) {
122  throw DLS::Exception("<artl-ck> or <art2-ck> chunk expected");
123  }
124  HeaderSize = artl->ReadUint32();
125  Connections = artl->ReadUint32();
126  artl->SetPos(HeaderSize);
127 
129  Connection::conn_block_t connblock;
130  for (uint32_t i = 0; i < Connections; i++) {
131  artl->Read(&connblock.source, 1, 2);
132  artl->Read(&connblock.control, 1, 2);
133  artl->Read(&connblock.destination, 1, 2);
134  artl->Read(&connblock.transform, 1, 2);
135  artl->Read(&connblock.scale, 1, 4);
136  pConnections[i].Init(&connblock);
137  }
138  }
139 
141  if (pConnections) delete[] pConnections;
142  }
143 
149  const int iEntrySize = 12; // 12 bytes per connection block
150  pArticulationCk->Resize(HeaderSize + Connections * iEntrySize);
151  uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData();
152  store16(&pData[0], HeaderSize);
153  store16(&pData[2], Connections);
154  for (uint32_t i = 0; i < Connections; i++) {
156  store16(&pData[HeaderSize + i * iEntrySize], c.source);
157  store16(&pData[HeaderSize + i * iEntrySize + 2], c.control);
158  store16(&pData[HeaderSize + i * iEntrySize + 4], c.destination);
159  store16(&pData[HeaderSize + i * iEntrySize + 6], c.transform);
160  store32(&pData[HeaderSize + i * iEntrySize + 8], c.scale);
161  }
162  }
163 
164 
165 
166 // *************** Articulator ***************
167 // *
168 
170  pParentList = ParentList;
171  pArticulations = NULL;
172  }
173 
176  if (!pArticulations) return NULL;
178  return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
179  }
180 
182  if (!pArticulations) return NULL;
184  return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
185  }
186 
188  // prefer articulation level 2
190  if (!lart) lart = pParentList->GetSubList(LIST_TYPE_LART);
191  if (lart) {
192  uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2
193  : CHUNK_ID_ARTL;
194  RIFF::Chunk* art = lart->GetFirstSubChunk();
195  while (art) {
196  if (art->GetChunkID() == artCkType) {
198  pArticulations->push_back(new Articulation(art));
199  }
200  art = lart->GetNextSubChunk();
201  }
202  }
203  }
204 
206  if (pArticulations) {
207  ArticulationList::iterator iter = pArticulations->begin();
208  ArticulationList::iterator end = pArticulations->end();
209  while (iter != end) {
210  delete *iter;
211  iter++;
212  }
213  delete pArticulations;
214  }
215  }
216 
222  if (pArticulations) {
223  ArticulationList::iterator iter = pArticulations->begin();
224  ArticulationList::iterator end = pArticulations->end();
225  for (; iter != end; ++iter) {
226  (*iter)->UpdateChunks();
227  }
228  }
229  }
230 
231 
232 
233 // *************** Info ***************
234 // *
235 
243  pFixedStringLengths = NULL;
244  pResourceListChunk = list;
245  if (list) {
246  RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO);
247  if (lstINFO) {
248  LoadString(CHUNK_ID_INAM, lstINFO, Name);
249  LoadString(CHUNK_ID_IARL, lstINFO, ArchivalLocation);
250  LoadString(CHUNK_ID_ICRD, lstINFO, CreationDate);
251  LoadString(CHUNK_ID_ICMT, lstINFO, Comments);
252  LoadString(CHUNK_ID_IPRD, lstINFO, Product);
253  LoadString(CHUNK_ID_ICOP, lstINFO, Copyright);
254  LoadString(CHUNK_ID_IART, lstINFO, Artists);
255  LoadString(CHUNK_ID_IGNR, lstINFO, Genre);
256  LoadString(CHUNK_ID_IKEY, lstINFO, Keywords);
257  LoadString(CHUNK_ID_IENG, lstINFO, Engineer);
258  LoadString(CHUNK_ID_ITCH, lstINFO, Technician);
259  LoadString(CHUNK_ID_ISFT, lstINFO, Software);
260  LoadString(CHUNK_ID_IMED, lstINFO, Medium);
261  LoadString(CHUNK_ID_ISRC, lstINFO, Source);
262  LoadString(CHUNK_ID_ISRF, lstINFO, SourceForm);
263  LoadString(CHUNK_ID_ICMS, lstINFO, Commissioned);
264  LoadString(CHUNK_ID_ISBJ, lstINFO, Subject);
265  }
266  }
267  }
268 
270  }
271 
284  pFixedStringLengths = lengths;
285  }
286 
292  void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
293  RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
294  ::LoadString(ck, s); // function from helper.h
295  }
296 
312  void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) {
313  int size = 0;
314  if (pFixedStringLengths) {
315  for (int i = 0 ; pFixedStringLengths[i].length ; i++) {
316  if (pFixedStringLengths[i].chunkId == ChunkID) {
317  size = pFixedStringLengths[i].length;
318  break;
319  }
320  }
321  }
322  RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
323  ::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size); // function from helper.h
324  }
325 
332  if (!pResourceListChunk) return;
333 
334  // make sure INFO list chunk exists
335  RIFF::List* lstINFO = pResourceListChunk->GetSubList(LIST_TYPE_INFO);
336 
337  String defaultName = "";
338  String defaultCreationDate = "";
339  String defaultSoftware = "";
340  String defaultComments = "";
341 
342  uint32_t resourceType = pResourceListChunk->GetListType();
343 
344  if (!lstINFO) {
345  lstINFO = pResourceListChunk->AddSubList(LIST_TYPE_INFO);
346 
347  // assemble default values
348  defaultName = "NONAME";
349 
350  if (resourceType == RIFF_TYPE_DLS) {
351  // get current date
352  time_t now = time(NULL);
353  tm* pNowBroken = localtime(&now);
354  char buf[11];
355  strftime(buf, 11, "%F", pNowBroken);
356  defaultCreationDate = buf;
357 
358  defaultComments = "Created with " + libraryName() + " " + libraryVersion();
359  }
360  if (resourceType == RIFF_TYPE_DLS || resourceType == LIST_TYPE_INS)
361  {
362  defaultSoftware = libraryName() + " " + libraryVersion();
363  }
364  }
365 
366  // save values
367 
368  SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""));
369  SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""));
370  SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""));
371  SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments);
372  SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""));
373  SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate);
374  SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""));
375  SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""));
376  SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""));
377  SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""));
378  SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName);
379  SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""));
380  SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String(""));
381  SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware);
382  SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""));
383  SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""));
384  SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""));
385  }
386 
387 
388 
389 // *************** Resource ***************
390 // *
391 
401  Resource::Resource(Resource* Parent, RIFF::List* lstResource) {
402  pParent = Parent;
403  pResourceList = lstResource;
404 
405  pInfo = new Info(lstResource);
406 
407  RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);
408  if (ckDLSID) {
409  pDLSID = new dlsid_t;
410  ckDLSID->Read(&pDLSID->ulData1, 1, 4);
411  ckDLSID->Read(&pDLSID->usData2, 1, 2);
412  ckDLSID->Read(&pDLSID->usData3, 1, 2);
413  ckDLSID->Read(pDLSID->abData, 8, 1);
414  }
415  else pDLSID = NULL;
416  }
417 
419  if (pDLSID) delete pDLSID;
420  if (pInfo) delete pInfo;
421  }
422 
432  pInfo->UpdateChunks();
433 
434  if (pDLSID) {
435  // make sure 'dlid' chunk exists
437  if (!ckDLSID) ckDLSID = pResourceList->AddSubChunk(CHUNK_ID_DLID, 16);
438  uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
439  // update 'dlid' chunk
440  store32(&pData[0], pDLSID->ulData1);
441  store16(&pData[4], pDLSID->usData2);
442  store16(&pData[6], pDLSID->usData3);
443  memcpy(&pData[8], pDLSID->abData, 8);
444  }
445  }
446 
451 #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
452 
453  if (!pDLSID) pDLSID = new dlsid_t;
454 
455 #ifdef WIN32
456 
457  UUID uuid;
458  UuidCreate(&uuid);
459  pDLSID->ulData1 = uuid.Data1;
460  pDLSID->usData2 = uuid.Data2;
461  pDLSID->usData3 = uuid.Data3;
462  memcpy(pDLSID->abData, uuid.Data4, 8);
463 
464 #elif defined(__APPLE__)
465 
466  CFUUIDRef uuidRef = CFUUIDCreate(NULL);
467  CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
468  CFRelease(uuidRef);
469  pDLSID->ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
470  pDLSID->usData2 = uuid.byte4 | uuid.byte5 << 8;
471  pDLSID->usData3 = uuid.byte6 | uuid.byte7 << 8;
472  pDLSID->abData[0] = uuid.byte8;
473  pDLSID->abData[1] = uuid.byte9;
474  pDLSID->abData[2] = uuid.byte10;
475  pDLSID->abData[3] = uuid.byte11;
476  pDLSID->abData[4] = uuid.byte12;
477  pDLSID->abData[5] = uuid.byte13;
478  pDLSID->abData[6] = uuid.byte14;
479  pDLSID->abData[7] = uuid.byte15;
480 #else
481  uuid_t uuid;
482  uuid_generate(uuid);
483  pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
484  pDLSID->usData2 = uuid[4] | uuid[5] << 8;
485  pDLSID->usData3 = uuid[6] | uuid[7] << 8;
486  memcpy(pDLSID->abData, &uuid[8], 8);
487 #endif
488 #endif
489  }
490 
491 
492 // *************** Sampler ***************
493 // *
494 
496  pParentList = ParentList;
497  RIFF::Chunk* wsmp = ParentList->GetSubChunk(CHUNK_ID_WSMP);
498  if (wsmp) {
499  uiHeaderSize = wsmp->ReadUint32();
500  UnityNote = wsmp->ReadUint16();
501  FineTune = wsmp->ReadInt16();
502  Gain = wsmp->ReadInt32();
503  SamplerOptions = wsmp->ReadUint32();
504  SampleLoops = wsmp->ReadUint32();
505  } else { // 'wsmp' chunk missing
506  uiHeaderSize = 20;
507  UnityNote = 60;
508  FineTune = 0; // +- 0 cents
509  Gain = 0; // 0 dB
511  SampleLoops = 0;
512  }
516  if (SampleLoops) {
517  wsmp->SetPos(uiHeaderSize);
518  for (uint32_t i = 0; i < SampleLoops; i++) {
519  wsmp->Read(pSampleLoops + i, 4, 4);
520  if (pSampleLoops[i].Size > sizeof(sample_loop_t)) { // if loop struct was extended
521  wsmp->SetPos(pSampleLoops[i].Size - sizeof(sample_loop_t), RIFF::stream_curpos);
522  }
523  }
524  }
525  }
526 
528  if (pSampleLoops) delete[] pSampleLoops;
529  }
530 
531  void Sampler::SetGain(int32_t gain) {
532  Gain = gain;
533  }
534 
540  // make sure 'wsmp' chunk exists
542  int wsmpSize = uiHeaderSize + SampleLoops * 16;
543  if (!wsmp) {
544  wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize);
545  } else if (wsmp->GetSize() != wsmpSize) {
546  wsmp->Resize(wsmpSize);
547  }
548  uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
549  // update headers size
550  store32(&pData[0], uiHeaderSize);
551  // update respective sampler options bits
556  store16(&pData[4], UnityNote);
557  store16(&pData[6], FineTune);
558  store32(&pData[8], Gain);
559  store32(&pData[12], SamplerOptions);
560  store32(&pData[16], SampleLoops);
561  // update loop definitions
562  for (uint32_t i = 0; i < SampleLoops; i++) {
563  //FIXME: this does not handle extended loop structs correctly
564  store32(&pData[uiHeaderSize + i * 16], pSampleLoops[i].Size);
565  store32(&pData[uiHeaderSize + i * 16 + 4], pSampleLoops[i].LoopType);
566  store32(&pData[uiHeaderSize + i * 16 + 8], pSampleLoops[i].LoopStart);
567  store32(&pData[uiHeaderSize + i * 16 + 12], pSampleLoops[i].LoopLength);
568  }
569  }
570 
577  sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1];
578  // copy old loops array
579  for (int i = 0; i < SampleLoops; i++) {
580  pNewLoops[i] = pSampleLoops[i];
581  }
582  // add the new loop
583  pNewLoops[SampleLoops] = *pLoopDef;
584  // auto correct size field
585  pNewLoops[SampleLoops].Size = sizeof(DLS::sample_loop_t);
586  // free the old array and update the member variables
587  if (SampleLoops) delete[] pSampleLoops;
588  pSampleLoops = pNewLoops;
589  SampleLoops++;
590  }
591 
599  sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops - 1];
600  // copy old loops array (skipping given loop)
601  for (int i = 0, o = 0; i < SampleLoops; i++) {
602  if (&pSampleLoops[i] == pLoopDef) continue;
603  if (o == SampleLoops - 1) {
604  delete[] pNewLoops;
605  throw Exception("Could not delete Sample Loop, because it does not exist");
606  }
607  pNewLoops[o] = pSampleLoops[i];
608  o++;
609  }
610  // free the old array and update the member variables
611  if (SampleLoops) delete[] pSampleLoops;
612  pSampleLoops = pNewLoops;
613  SampleLoops--;
614  }
615 
616 
617 
618 // *************** Sample ***************
619 // *
620 
636  Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : Resource(pFile, waveList) {
637  pWaveList = waveList;
638  ulWavePoolOffset = WavePoolOffset - LIST_HEADER_SIZE;
639  pCkFormat = waveList->GetSubChunk(CHUNK_ID_FMT);
640  pCkData = waveList->GetSubChunk(CHUNK_ID_DATA);
641  if (pCkFormat) {
642  // common fields
648  // PCM format specific
651  FrameSize = (BitDepth / 8) * Channels;
652  } else { // unsupported sample data format
653  BitDepth = 0;
654  FrameSize = 0;
655  }
656  } else { // 'fmt' chunk missing
658  BitDepth = 16;
659  Channels = 1;
660  SamplesPerSecond = 44100;
662  FrameSize = (BitDepth / 8) * Channels;
664  }
666  : 0
667  : 0;
668  }
669 
677  pParent->DeleteSubChunk(pWaveList);
678  }
679 
707  return (pCkData) ? pCkData->LoadChunkData() : NULL;
708  }
709 
717  }
718 
729  unsigned long Sample::GetSize() {
730  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0;
731  return (pCkData) ? pCkData->GetSize() / FrameSize : 0;
732  }
733 
762  void Sample::Resize(int iNewSize) {
763  if (FormatTag != DLS_WAVE_FORMAT_PCM) throw Exception("Sample's format is not DLS_WAVE_FORMAT_PCM");
764  if (iNewSize < 1) throw Exception("Sample size must be at least one sample point");
765  const int iSizeInBytes = iNewSize * FrameSize;
767  if (pCkData) pCkData->Resize(iSizeInBytes);
768  else pCkData = pWaveList->AddSubChunk(CHUNK_ID_DATA, iSizeInBytes);
769  }
770 
787  unsigned long Sample::SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence) {
788  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
789  if (!pCkData) throw Exception("No data chunk created for sample yet, call Sample::Resize() to create one");
790  unsigned long orderedBytes = SampleCount * FrameSize;
791  unsigned long result = pCkData->SetPos(orderedBytes, Whence);
792  return (result == orderedBytes) ? SampleCount
793  : result / FrameSize;
794  }
795 
805  unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {
806  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
807  return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
808  }
809 
825  unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) {
826  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
827  if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small");
828  return pCkData->Write(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
829  }
830 
840  throw Exception("Could not save sample, only PCM format is supported");
841  // we refuse to do anything if not sample wave form was provided yet
842  if (!pCkData)
843  throw Exception("Could not save sample, there is no sample data to save");
844  // update chunks of base class as well
846  // make sure 'fmt' chunk exists
848  if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format
849  uint8_t* pData = (uint8_t*) pCkFormat->LoadChunkData();
850  // update 'fmt' chunk
851  store16(&pData[0], FormatTag);
852  store16(&pData[2], Channels);
853  store32(&pData[4], SamplesPerSecond);
854  store32(&pData[8], AverageBytesPerSecond);
855  store16(&pData[12], BlockAlign);
856  store16(&pData[14], BitDepth); // assuming PCM format
857  }
858 
859 
860 
861 // *************** Region ***************
862 // *
863 
864  Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : Resource(pInstrument, rgnList), Articulator(rgnList), Sampler(rgnList) {
865  pCkRegion = rgnList;
866 
867  // articulation informations
868  RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);
869  if (rgnh) {
870  rgnh->Read(&KeyRange, 2, 2);
871  rgnh->Read(&VelocityRange, 2, 2);
872  FormatOptionFlags = rgnh->ReadUint16();
873  KeyGroup = rgnh->ReadUint16();
874  // Layer is optional
875  if (rgnh->RemainingBytes() >= sizeof(uint16_t)) {
876  rgnh->Read(&Layer, 1, sizeof(uint16_t));
877  } else Layer = 0;
878  } else { // 'rgnh' chunk is missing
879  KeyRange.low = 0;
880  KeyRange.high = 127;
881  VelocityRange.low = 0;
882  VelocityRange.high = 127;
884  KeyGroup = 0;
885  Layer = 0;
886  }
888 
889  // sample informations
890  RIFF::Chunk* wlnk = rgnList->GetSubChunk(CHUNK_ID_WLNK);
891  if (wlnk) {
893  PhaseGroup = wlnk->ReadUint16();
894  Channel = wlnk->ReadUint32();
895  WavePoolTableIndex = wlnk->ReadUint32();
896  } else { // 'wlnk' chunk is missing
898  PhaseGroup = 0;
899  Channel = 0; // mono
900  WavePoolTableIndex = 0; // first entry in wave pool table
901  }
904 
905  pSample = NULL;
906  }
907 
914  pParent->DeleteSubChunk(pCkRegion);
915  }
916 
918  if (pSample) return pSample;
919  File* file = (File*) GetParent()->GetParent();
920  unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
921  Sample* sample = file->GetFirstSample();
922  while (sample) {
923  if (sample->ulWavePoolOffset == soughtoffset) return (pSample = sample);
924  sample = file->GetNextSample();
925  }
926  return NULL;
927  }
928 
934  void Region::SetSample(Sample* pSample) {
935  this->pSample = pSample;
936  WavePoolTableIndex = 0; // we update this offset when we Save()
937  }
938 
946  void Region::SetKeyRange(uint16_t Low, uint16_t High) {
947  KeyRange.low = Low;
948  KeyRange.high = High;
949 
950  // make sure regions are already loaded
951  Instrument* pInstrument = (Instrument*) GetParent();
952  if (!pInstrument->pRegions) pInstrument->LoadRegions();
953  if (!pInstrument->pRegions) return;
954 
955  // find the r which is the first one to the right of this region
956  // at its new position
957  Region* r = NULL;
958  Region* prev_region = NULL;
959  for (
960  Instrument::RegionList::iterator iter = pInstrument->pRegions->begin();
961  iter != pInstrument->pRegions->end(); iter++
962  ) {
963  if ((*iter)->KeyRange.low > this->KeyRange.low) {
964  r = *iter;
965  break;
966  }
967  prev_region = *iter;
968  }
969 
970  // place this region before r if it's not already there
971  if (prev_region != this) pInstrument->MoveRegion(this, r);
972  }
973 
981  // make sure 'rgnh' chunk exists
983  if (!rgnh) rgnh = pCkRegion->AddSubChunk(CHUNK_ID_RGNH, Layer ? 14 : 12);
984  uint8_t* pData = (uint8_t*) rgnh->LoadChunkData();
988  // update 'rgnh' chunk
989  store16(&pData[0], KeyRange.low);
990  store16(&pData[2], KeyRange.high);
991  store16(&pData[4], VelocityRange.low);
992  store16(&pData[6], VelocityRange.high);
993  store16(&pData[8], FormatOptionFlags);
994  store16(&pData[10], KeyGroup);
995  if (rgnh->GetSize() >= 14) store16(&pData[12], Layer);
996 
997  // update chunks of base classes as well (but skip Resource,
998  // as a rgn doesn't seem to have dlid and INFO chunks)
1001 
1002  // make sure 'wlnk' chunk exists
1004  if (!wlnk) wlnk = pCkRegion->AddSubChunk(CHUNK_ID_WLNK, 12);
1005  pData = (uint8_t*) wlnk->LoadChunkData();
1012  // get sample's wave pool table index
1013  int index = -1;
1014  File* pFile = (File*) GetParent()->GetParent();
1015  if (pFile->pSamples) {
1016  File::SampleList::iterator iter = pFile->pSamples->begin();
1017  File::SampleList::iterator end = pFile->pSamples->end();
1018  for (int i = 0; iter != end; ++iter, i++) {
1019  if (*iter == pSample) {
1020  index = i;
1021  break;
1022  }
1023  }
1024  }
1025  WavePoolTableIndex = index;
1026  // update 'wlnk' chunk
1027  store16(&pData[0], WaveLinkOptionFlags);
1028  store16(&pData[2], PhaseGroup);
1029  store32(&pData[4], Channel);
1030  store32(&pData[8], WavePoolTableIndex);
1031  }
1032 
1033 
1034 
1035 // *************** Instrument ***************
1036 // *
1037 
1051  Instrument::Instrument(File* pFile, RIFF::List* insList) : Resource(pFile, insList), Articulator(insList) {
1052  pCkInstrument = insList;
1053 
1054  midi_locale_t locale;
1056  if (insh) {
1057  Regions = insh->ReadUint32();
1058  insh->Read(&locale, 2, 4);
1059  } else { // 'insh' chunk missing
1060  Regions = 0;
1061  locale.bank = 0;
1062  locale.instrument = 0;
1063  }
1064 
1065  MIDIProgram = locale.instrument;
1066  IsDrum = locale.bank & DRUM_TYPE_MASK;
1067  MIDIBankCoarse = (uint8_t) MIDI_BANK_COARSE(locale.bank);
1068  MIDIBankFine = (uint8_t) MIDI_BANK_FINE(locale.bank);
1070 
1071  pRegions = NULL;
1072  }
1073 
1075  if (!pRegions) LoadRegions();
1076  if (!pRegions) return NULL;
1077  RegionsIterator = pRegions->begin();
1078  return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1079  }
1080 
1082  if (!pRegions) return NULL;
1083  RegionsIterator++;
1084  return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1085  }
1086 
1088  if (!pRegions) pRegions = new RegionList;
1090  if (lrgn) {
1091  uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2
1092  RIFF::List* rgn = lrgn->GetFirstSubList();
1093  while (rgn) {
1094  if (rgn->GetListType() == regionCkType) {
1095  pRegions->push_back(new Region(this, rgn));
1096  }
1097  rgn = lrgn->GetNextSubList();
1098  }
1099  }
1100  }
1101 
1103  if (!pRegions) LoadRegions();
1105  if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);
1106  RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
1107  Region* pNewRegion = new Region(this, rgn);
1108  pRegions->push_back(pNewRegion);
1109  Regions = pRegions->size();
1110  return pNewRegion;
1111  }
1112 
1113  void Instrument::MoveRegion(Region* pSrc, Region* pDst) {
1115  lrgn->MoveSubChunk(pSrc->pCkRegion, pDst ? pDst->pCkRegion : 0);
1116 
1117  pRegions->remove(pSrc);
1118  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);
1119  pRegions->insert(iter, pSrc);
1120  }
1121 
1123  if (!pRegions) return;
1124  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
1125  if (iter == pRegions->end()) return;
1126  pRegions->erase(iter);
1127  Regions = pRegions->size();
1128  delete pRegion;
1129  }
1130 
1138  // first update base classes' chunks
1141  // make sure 'insh' chunk exists
1143  if (!insh) insh = pCkInstrument->AddSubChunk(CHUNK_ID_INSH, 12);
1144  uint8_t* pData = (uint8_t*) insh->LoadChunkData();
1145  // update 'insh' chunk
1146  Regions = (pRegions) ? pRegions->size() : 0;
1147  midi_locale_t locale;
1148  locale.instrument = MIDIProgram;
1150  locale.bank = (IsDrum) ? locale.bank | DRUM_TYPE_MASK : locale.bank & (~DRUM_TYPE_MASK);
1151  MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine); // just a sync, when we're at it
1152  store32(&pData[0], Regions);
1153  store32(&pData[4], locale.bank);
1154  store32(&pData[8], locale.instrument);
1155  // update Region's chunks
1156  if (!pRegions) return;
1157  RegionList::iterator iter = pRegions->begin();
1158  RegionList::iterator end = pRegions->end();
1159  for (; iter != end; ++iter) {
1160  (*iter)->UpdateChunks();
1161  }
1162  }
1163 
1170  if (pRegions) {
1171  RegionList::iterator iter = pRegions->begin();
1172  RegionList::iterator end = pRegions->end();
1173  while (iter != end) {
1174  delete *iter;
1175  iter++;
1176  }
1177  delete pRegions;
1178  }
1179  // remove instrument's chunks
1181  pParent->DeleteSubChunk(pCkInstrument);
1182  }
1183 
1184 
1185 
1186 // *************** File ***************
1187 // *
1188 
1195  File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) {
1197  pVersion = new version_t;
1198  pVersion->major = 0;
1199  pVersion->minor = 0;
1200  pVersion->release = 0;
1201  pVersion->build = 0;
1202 
1203  Instruments = 0;
1204  WavePoolCount = 0;
1205  pWavePoolTable = NULL;
1206  pWavePoolTableHi = NULL;
1207  WavePoolHeaderSize = 8;
1208 
1209  pSamples = NULL;
1210  pInstruments = NULL;
1211 
1212  b64BitWavePoolOffsets = false;
1213  }
1214 
1224  File::File(RIFF::File* pRIFF) : Resource(NULL, pRIFF) {
1225  if (!pRIFF) throw DLS::Exception("NULL pointer reference to RIFF::File object.");
1226  this->pRIFF = pRIFF;
1227 
1228  RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1229  if (ckVersion) {
1230  pVersion = new version_t;
1231  ckVersion->Read(pVersion, 4, 2);
1232  }
1233  else pVersion = NULL;
1234 
1235  RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
1236  if (!colh) throw DLS::Exception("Mandatory chunks in RIFF list chunk not found.");
1237  Instruments = colh->ReadUint32();
1238 
1239  RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
1240  if (!ptbl) { // pool table is missing - this is probably an ".art" file
1241  WavePoolCount = 0;
1242  pWavePoolTable = NULL;
1243  pWavePoolTableHi = NULL;
1244  WavePoolHeaderSize = 8;
1245  b64BitWavePoolOffsets = false;
1246  } else {
1247  WavePoolHeaderSize = ptbl->ReadUint32();
1248  WavePoolCount = ptbl->ReadUint32();
1249  pWavePoolTable = new uint32_t[WavePoolCount];
1250  pWavePoolTableHi = new uint32_t[WavePoolCount];
1251  ptbl->SetPos(WavePoolHeaderSize);
1252 
1253  // Check for 64 bit offsets (used in gig v3 files)
1255  if (b64BitWavePoolOffsets) {
1256  for (int i = 0 ; i < WavePoolCount ; i++) {
1257  pWavePoolTableHi[i] = ptbl->ReadUint32();
1258  pWavePoolTable[i] = ptbl->ReadUint32();
1259  if (pWavePoolTable[i] & 0x80000000)
1260  throw DLS::Exception("Files larger than 2 GB not yet supported");
1261  }
1262  } else { // conventional 32 bit offsets
1263  ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
1264  for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;
1265  }
1266  }
1267 
1268  pSamples = NULL;
1269  pInstruments = NULL;
1270  }
1271 
1273  if (pInstruments) {
1274  InstrumentList::iterator iter = pInstruments->begin();
1275  InstrumentList::iterator end = pInstruments->end();
1276  while (iter != end) {
1277  delete *iter;
1278  iter++;
1279  }
1280  delete pInstruments;
1281  }
1282 
1283  if (pSamples) {
1284  SampleList::iterator iter = pSamples->begin();
1285  SampleList::iterator end = pSamples->end();
1286  while (iter != end) {
1287  delete *iter;
1288  iter++;
1289  }
1290  delete pSamples;
1291  }
1292 
1293  if (pWavePoolTable) delete[] pWavePoolTable;
1294  if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1295  if (pVersion) delete pVersion;
1296  for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1297  delete *i;
1298  }
1299 
1301  if (!pSamples) LoadSamples();
1302  if (!pSamples) return NULL;
1303  SamplesIterator = pSamples->begin();
1304  return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1305  }
1306 
1308  if (!pSamples) return NULL;
1309  SamplesIterator++;
1310  return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1311  }
1312 
1314  if (!pSamples) pSamples = new SampleList;
1316  if (wvpl) {
1317  unsigned long wvplFileOffset = wvpl->GetFilePos();
1318  RIFF::List* wave = wvpl->GetFirstSubList();
1319  while (wave) {
1320  if (wave->GetListType() == LIST_TYPE_WAVE) {
1321  unsigned long waveFileOffset = wave->GetFilePos();
1322  pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1323  }
1324  wave = wvpl->GetNextSubList();
1325  }
1326  }
1327  else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)
1329  if (dwpl) {
1330  unsigned long dwplFileOffset = dwpl->GetFilePos();
1331  RIFF::List* wave = dwpl->GetFirstSubList();
1332  while (wave) {
1333  if (wave->GetListType() == LIST_TYPE_WAVE) {
1334  unsigned long waveFileOffset = wave->GetFilePos();
1335  pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1336  }
1337  wave = dwpl->GetNextSubList();
1338  }
1339  }
1340  }
1341  }
1342 
1351  if (!pSamples) LoadSamples();
1354  // create new Sample object and its respective 'wave' list chunk
1355  RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
1356  Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/);
1357  pSamples->push_back(pSample);
1358  return pSample;
1359  }
1360 
1368  void File::DeleteSample(Sample* pSample) {
1369  if (!pSamples) return;
1370  SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample);
1371  if (iter == pSamples->end()) return;
1372  pSamples->erase(iter);
1373  delete pSample;
1374  }
1375 
1377  if (!pInstruments) LoadInstruments();
1378  if (!pInstruments) return NULL;
1379  InstrumentsIterator = pInstruments->begin();
1380  return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
1381  }
1382 
1384  if (!pInstruments) return NULL;
1386  return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
1387  }
1388 
1391  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1392  if (lstInstruments) {
1393  RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1394  while (lstInstr) {
1395  if (lstInstr->GetListType() == LIST_TYPE_INS) {
1396  pInstruments->push_back(new Instrument(this, lstInstr));
1397  }
1398  lstInstr = lstInstruments->GetNextSubList();
1399  }
1400  }
1401  }
1402 
1411  if (!pInstruments) LoadInstruments();
1413  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1414  RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
1415  Instrument* pInstrument = new Instrument(this, lstInstr);
1416  pInstruments->push_back(pInstrument);
1417  return pInstrument;
1418  }
1419 
1427  void File::DeleteInstrument(Instrument* pInstrument) {
1428  if (!pInstruments) return;
1429  InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument);
1430  if (iter == pInstruments->end()) return;
1431  pInstruments->erase(iter);
1432  delete pInstrument;
1433  }
1434 
1448  if (index < 0 || index >= ExtensionFiles.size()) return NULL;
1449  std::list<RIFF::File*>::iterator iter = ExtensionFiles.begin();
1450  for (int i = 0; iter != ExtensionFiles.end(); ++iter, ++i)
1451  if (i == index) return *iter;
1452  return NULL;
1453  }
1454 
1465  return pRIFF->GetFileName();
1466  }
1467 
1476  // first update base class's chunks
1478 
1479  // if version struct exists, update 'vers' chunk
1480  if (pVersion) {
1481  RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1482  if (!ckVersion) ckVersion = pRIFF->AddSubChunk(CHUNK_ID_VERS, 8);
1483  uint8_t* pData = (uint8_t*) ckVersion->LoadChunkData();
1484  store16(&pData[0], pVersion->minor);
1485  store16(&pData[2], pVersion->major);
1486  store16(&pData[4], pVersion->build);
1487  store16(&pData[6], pVersion->release);
1488  }
1489 
1490  // update 'colh' chunk
1491  Instruments = (pInstruments) ? pInstruments->size() : 0;
1493  if (!colh) colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);
1494  uint8_t* pData = (uint8_t*) colh->LoadChunkData();
1495  store32(pData, Instruments);
1496 
1497  // update instrument's chunks
1498  if (pInstruments) {
1499  InstrumentList::iterator iter = pInstruments->begin();
1500  InstrumentList::iterator end = pInstruments->end();
1501  for (; iter != end; ++iter) {
1502  (*iter)->UpdateChunks();
1503  }
1504  }
1505 
1506  // update 'ptbl' chunk
1507  const int iSamples = (pSamples) ? pSamples->size() : 0;
1508  const int iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1510  if (!ptbl) ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, 1 /*anything, we'll resize*/);
1511  const int iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
1512  ptbl->Resize(iPtblSize);
1513  pData = (uint8_t*) ptbl->LoadChunkData();
1514  WavePoolCount = iSamples;
1515  store32(&pData[4], WavePoolCount);
1516  // we actually update the sample offsets in the pool table when we Save()
1517  memset(&pData[WavePoolHeaderSize], 0, iPtblSize - WavePoolHeaderSize);
1518 
1519  // update sample's chunks
1520  if (pSamples) {
1521  SampleList::iterator iter = pSamples->begin();
1522  SampleList::iterator end = pSamples->end();
1523  for (; iter != end; ++iter) {
1524  (*iter)->UpdateChunks();
1525  }
1526  }
1527  }
1528 
1542  void File::Save(const String& Path) {
1543  UpdateChunks();
1544  pRIFF->Save(Path);
1545  __UpdateWavePoolTableChunk();
1546  }
1547 
1557  void File::Save() {
1558  UpdateChunks();
1559  pRIFF->Save();
1560  __UpdateWavePoolTableChunk();
1561  }
1562 
1569  // enusre 'lins' list chunk exists (mandatory for instrument definitions)
1570  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1571  if (!lstInstruments) pRIFF->AddSubList(LIST_TYPE_LINS);
1572  // ensure 'ptbl' chunk exists (mandatory for samples)
1574  if (!ptbl) {
1575  const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1576  ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, WavePoolHeaderSize + iOffsetSize);
1577  }
1578  // enusre 'wvpl' list chunk exists (mandatory for samples)
1580  if (!wvpl) pRIFF->AddSubList(LIST_TYPE_WVPL);
1581  }
1582 
1592  void File::__UpdateWavePoolTableChunk() {
1593  __UpdateWavePoolTable();
1595  const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1596  // check if 'ptbl' chunk is large enough
1597  WavePoolCount = (pSamples) ? pSamples->size() : 0;
1598  const unsigned long ulRequiredSize = WavePoolHeaderSize + iOffsetSize * WavePoolCount;
1599  if (ptbl->GetSize() < ulRequiredSize) throw Exception("Fatal error, 'ptbl' chunk too small");
1600  // save the 'ptbl' chunk's current read/write position
1601  unsigned long ulOriginalPos = ptbl->GetPos();
1602  // update headers
1603  ptbl->SetPos(0);
1604  uint32_t tmp = WavePoolHeaderSize;
1605  ptbl->WriteUint32(&tmp);
1606  tmp = WavePoolCount;
1607  ptbl->WriteUint32(&tmp);
1608  // update offsets
1609  ptbl->SetPos(WavePoolHeaderSize);
1610  if (b64BitWavePoolOffsets) {
1611  for (int i = 0 ; i < WavePoolCount ; i++) {
1612  tmp = pWavePoolTableHi[i];
1613  ptbl->WriteUint32(&tmp);
1614  tmp = pWavePoolTable[i];
1615  ptbl->WriteUint32(&tmp);
1616  }
1617  } else { // conventional 32 bit offsets
1618  for (int i = 0 ; i < WavePoolCount ; i++) {
1619  tmp = pWavePoolTable[i];
1620  ptbl->WriteUint32(&tmp);
1621  }
1622  }
1623  // restore 'ptbl' chunk's original read/write position
1624  ptbl->SetPos(ulOriginalPos);
1625  }
1626 
1632  void File::__UpdateWavePoolTable() {
1633  WavePoolCount = (pSamples) ? pSamples->size() : 0;
1634  // resize wave pool table arrays
1635  if (pWavePoolTable) delete[] pWavePoolTable;
1636  if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1637  pWavePoolTable = new uint32_t[WavePoolCount];
1638  pWavePoolTableHi = new uint32_t[WavePoolCount];
1639  if (!pSamples) return;
1640  // update offsets int wave pool table
1642  uint64_t wvplFileOffset = wvpl->GetFilePos();
1643  if (b64BitWavePoolOffsets) {
1644  SampleList::iterator iter = pSamples->begin();
1645  SampleList::iterator end = pSamples->end();
1646  for (int i = 0 ; iter != end ; ++iter, i++) {
1647  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE;
1648  (*iter)->ulWavePoolOffset = _64BitOffset;
1649  pWavePoolTableHi[i] = (uint32_t) (_64BitOffset >> 32);
1650  pWavePoolTable[i] = (uint32_t) _64BitOffset;
1651  }
1652  } else { // conventional 32 bit offsets
1653  SampleList::iterator iter = pSamples->begin();
1654  SampleList::iterator end = pSamples->end();
1655  for (int i = 0 ; iter != end ; ++iter, i++) {
1656  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE;
1657  (*iter)->ulWavePoolOffset = _64BitOffset;
1658  pWavePoolTable[i] = (uint32_t) _64BitOffset;
1659  }
1660  }
1661  }
1662 
1663 
1664 
1665 // *************** Exception ***************
1666 // *
1667 
1668  Exception::Exception(String Message) : RIFF::Exception(Message) {
1669  }
1670 
1672  std::cout << "DLS::Exception: " << Message << std::endl;
1673  }
1674 
1675 
1676 // *************** functions ***************
1677 // *
1678 
1685  return PACKAGE;
1686  }
1687 
1693  return VERSION;
1694  }
1695 
1696 } // namespace DLS