libgig  3.3.0.svn21
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-2013 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 
128  pConnections = new Connection[Connections];
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++) {
155  Connection::conn_block_t c = pConnections[i].ToConnBlock();
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 
175  if (!pArticulations) LoadArticulations();
176  if (!pArticulations) return NULL;
177  ArticulationsIterator = pArticulations->begin();
178  return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
179  }
180 
182  if (!pArticulations) return NULL;
183  ArticulationsIterator++;
184  return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
185  }
186 
188  // prefer articulation level 2
189  RIFF::List* lart = pParentList->GetSubList(LIST_TYPE_LAR2);
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) {
197  if (!pArticulations) pArticulations = new ArticulationList;
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 
237  //TODO: implement deep copy assignment for this class
238  }
239 
240 
241 
242 // *************** Info ***************
243 // *
244 
252  pFixedStringLengths = NULL;
253  pResourceListChunk = list;
254  if (list) {
255  RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO);
256  if (lstINFO) {
257  LoadString(CHUNK_ID_INAM, lstINFO, Name);
258  LoadString(CHUNK_ID_IARL, lstINFO, ArchivalLocation);
259  LoadString(CHUNK_ID_ICRD, lstINFO, CreationDate);
260  LoadString(CHUNK_ID_ICMT, lstINFO, Comments);
261  LoadString(CHUNK_ID_IPRD, lstINFO, Product);
262  LoadString(CHUNK_ID_ICOP, lstINFO, Copyright);
263  LoadString(CHUNK_ID_IART, lstINFO, Artists);
264  LoadString(CHUNK_ID_IGNR, lstINFO, Genre);
265  LoadString(CHUNK_ID_IKEY, lstINFO, Keywords);
266  LoadString(CHUNK_ID_IENG, lstINFO, Engineer);
267  LoadString(CHUNK_ID_ITCH, lstINFO, Technician);
268  LoadString(CHUNK_ID_ISFT, lstINFO, Software);
269  LoadString(CHUNK_ID_IMED, lstINFO, Medium);
270  LoadString(CHUNK_ID_ISRC, lstINFO, Source);
271  LoadString(CHUNK_ID_ISRF, lstINFO, SourceForm);
272  LoadString(CHUNK_ID_ICMS, lstINFO, Commissioned);
273  LoadString(CHUNK_ID_ISBJ, lstINFO, Subject);
274  }
275  }
276  }
277 
279  }
280 
293  pFixedStringLengths = lengths;
294  }
295 
301  void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
302  RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
303  ::LoadString(ck, s); // function from helper.h
304  }
305 
321  void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) {
322  int size = 0;
323  if (pFixedStringLengths) {
324  for (int i = 0 ; pFixedStringLengths[i].length ; i++) {
325  if (pFixedStringLengths[i].chunkId == ChunkID) {
326  size = pFixedStringLengths[i].length;
327  break;
328  }
329  }
330  }
331  RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
332  ::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size); // function from helper.h
333  }
334 
341  if (!pResourceListChunk) return;
342 
343  // make sure INFO list chunk exists
344  RIFF::List* lstINFO = pResourceListChunk->GetSubList(LIST_TYPE_INFO);
345 
346  String defaultName = "";
347  String defaultCreationDate = "";
348  String defaultSoftware = "";
349  String defaultComments = "";
350 
351  uint32_t resourceType = pResourceListChunk->GetListType();
352 
353  if (!lstINFO) {
354  lstINFO = pResourceListChunk->AddSubList(LIST_TYPE_INFO);
355 
356  // assemble default values
357  defaultName = "NONAME";
358 
359  if (resourceType == RIFF_TYPE_DLS) {
360  // get current date
361  time_t now = time(NULL);
362  tm* pNowBroken = localtime(&now);
363  char buf[11];
364  strftime(buf, 11, "%F", pNowBroken);
365  defaultCreationDate = buf;
366 
367  defaultComments = "Created with " + libraryName() + " " + libraryVersion();
368  }
369  if (resourceType == RIFF_TYPE_DLS || resourceType == LIST_TYPE_INS)
370  {
371  defaultSoftware = libraryName() + " " + libraryVersion();
372  }
373  }
374 
375  // save values
376 
377  SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""));
378  SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""));
379  SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""));
380  SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments);
381  SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""));
382  SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate);
383  SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""));
384  SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""));
385  SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""));
386  SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""));
387  SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName);
388  SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""));
389  SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String(""));
390  SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware);
391  SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""));
392  SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""));
393  SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""));
394  }
395 
402  void Info::CopyAssign(const Info* orig) {
403  Name = orig->Name;
404  ArchivalLocation = orig->ArchivalLocation;
405  CreationDate = orig->CreationDate;
406  Comments = orig->Comments;
407  Product = orig->Product;
408  Copyright = orig->Copyright;
409  Artists = orig->Artists;
410  Genre = orig->Genre;
411  Keywords = orig->Keywords;
412  Engineer = orig->Engineer;
413  Technician = orig->Technician;
414  Software = orig->Software;
415  Medium = orig->Medium;
416  Source = orig->Source;
417  SourceForm = orig->SourceForm;
418  Commissioned = orig->Commissioned;
419  Subject = orig->Subject;
420  //FIXME: hmm, is copying this pointer a good idea?
421  pFixedStringLengths = orig->pFixedStringLengths;
422  }
423 
424 
425 
426 // *************** Resource ***************
427 // *
428 
438  Resource::Resource(Resource* Parent, RIFF::List* lstResource) {
439  pParent = Parent;
440  pResourceList = lstResource;
441 
442  pInfo = new Info(lstResource);
443 
444  RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);
445  if (ckDLSID) {
446  pDLSID = new dlsid_t;
447  ckDLSID->Read(&pDLSID->ulData1, 1, 4);
448  ckDLSID->Read(&pDLSID->usData2, 1, 2);
449  ckDLSID->Read(&pDLSID->usData3, 1, 2);
450  ckDLSID->Read(pDLSID->abData, 8, 1);
451  }
452  else pDLSID = NULL;
453  }
454 
456  if (pDLSID) delete pDLSID;
457  if (pInfo) delete pInfo;
458  }
459 
469  pInfo->UpdateChunks();
470 
471  if (pDLSID) {
472  // make sure 'dlid' chunk exists
473  RIFF::Chunk* ckDLSID = pResourceList->GetSubChunk(CHUNK_ID_DLID);
474  if (!ckDLSID) ckDLSID = pResourceList->AddSubChunk(CHUNK_ID_DLID, 16);
475  uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
476  // update 'dlid' chunk
477  store32(&pData[0], pDLSID->ulData1);
478  store16(&pData[4], pDLSID->usData2);
479  store16(&pData[6], pDLSID->usData3);
480  memcpy(&pData[8], pDLSID->abData, 8);
481  }
482  }
483 
488 #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
489 
490  if (!pDLSID) pDLSID = new dlsid_t;
491 
492 #ifdef WIN32
493 
494  UUID uuid;
495  UuidCreate(&uuid);
496  pDLSID->ulData1 = uuid.Data1;
497  pDLSID->usData2 = uuid.Data2;
498  pDLSID->usData3 = uuid.Data3;
499  memcpy(pDLSID->abData, uuid.Data4, 8);
500 
501 #elif defined(__APPLE__)
502 
503  CFUUIDRef uuidRef = CFUUIDCreate(NULL);
504  CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
505  CFRelease(uuidRef);
506  pDLSID->ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
507  pDLSID->usData2 = uuid.byte4 | uuid.byte5 << 8;
508  pDLSID->usData3 = uuid.byte6 | uuid.byte7 << 8;
509  pDLSID->abData[0] = uuid.byte8;
510  pDLSID->abData[1] = uuid.byte9;
511  pDLSID->abData[2] = uuid.byte10;
512  pDLSID->abData[3] = uuid.byte11;
513  pDLSID->abData[4] = uuid.byte12;
514  pDLSID->abData[5] = uuid.byte13;
515  pDLSID->abData[6] = uuid.byte14;
516  pDLSID->abData[7] = uuid.byte15;
517 #else
518  uuid_t uuid;
519  uuid_generate(uuid);
520  pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
521  pDLSID->usData2 = uuid[4] | uuid[5] << 8;
522  pDLSID->usData3 = uuid[6] | uuid[7] << 8;
523  memcpy(pDLSID->abData, &uuid[8], 8);
524 #endif
525 #endif
526  }
527 
534  void Resource::CopyAssign(const Resource* orig) {
535  pInfo->CopyAssign(orig->pInfo);
536  }
537 
538 
539 // *************** Sampler ***************
540 // *
541 
543  pParentList = ParentList;
544  RIFF::Chunk* wsmp = ParentList->GetSubChunk(CHUNK_ID_WSMP);
545  if (wsmp) {
546  uiHeaderSize = wsmp->ReadUint32();
547  UnityNote = wsmp->ReadUint16();
548  FineTune = wsmp->ReadInt16();
549  Gain = wsmp->ReadInt32();
550  SamplerOptions = wsmp->ReadUint32();
551  SampleLoops = wsmp->ReadUint32();
552  } else { // 'wsmp' chunk missing
553  uiHeaderSize = 20;
554  UnityNote = 60;
555  FineTune = 0; // +- 0 cents
556  Gain = 0; // 0 dB
557  SamplerOptions = F_WSMP_NO_COMPRESSION;
558  SampleLoops = 0;
559  }
560  NoSampleDepthTruncation = SamplerOptions & F_WSMP_NO_TRUNCATION;
561  NoSampleCompression = SamplerOptions & F_WSMP_NO_COMPRESSION;
562  pSampleLoops = (SampleLoops) ? new sample_loop_t[SampleLoops] : NULL;
563  if (SampleLoops) {
564  wsmp->SetPos(uiHeaderSize);
565  for (uint32_t i = 0; i < SampleLoops; i++) {
566  wsmp->Read(pSampleLoops + i, 4, 4);
567  if (pSampleLoops[i].Size > sizeof(sample_loop_t)) { // if loop struct was extended
568  wsmp->SetPos(pSampleLoops[i].Size - sizeof(sample_loop_t), RIFF::stream_curpos);
569  }
570  }
571  }
572  }
573 
575  if (pSampleLoops) delete[] pSampleLoops;
576  }
577 
578  void Sampler::SetGain(int32_t gain) {
579  Gain = gain;
580  }
581 
587  // make sure 'wsmp' chunk exists
588  RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);
589  int wsmpSize = uiHeaderSize + SampleLoops * 16;
590  if (!wsmp) {
591  wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize);
592  } else if (wsmp->GetSize() != wsmpSize) {
593  wsmp->Resize(wsmpSize);
594  }
595  uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
596  // update headers size
597  store32(&pData[0], uiHeaderSize);
598  // update respective sampler options bits
599  SamplerOptions = (NoSampleDepthTruncation) ? SamplerOptions | F_WSMP_NO_TRUNCATION
600  : SamplerOptions & (~F_WSMP_NO_TRUNCATION);
601  SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION
602  : SamplerOptions & (~F_WSMP_NO_COMPRESSION);
603  store16(&pData[4], UnityNote);
604  store16(&pData[6], FineTune);
605  store32(&pData[8], Gain);
606  store32(&pData[12], SamplerOptions);
607  store32(&pData[16], SampleLoops);
608  // update loop definitions
609  for (uint32_t i = 0; i < SampleLoops; i++) {
610  //FIXME: this does not handle extended loop structs correctly
611  store32(&pData[uiHeaderSize + i * 16], pSampleLoops[i].Size);
612  store32(&pData[uiHeaderSize + i * 16 + 4], pSampleLoops[i].LoopType);
613  store32(&pData[uiHeaderSize + i * 16 + 8], pSampleLoops[i].LoopStart);
614  store32(&pData[uiHeaderSize + i * 16 + 12], pSampleLoops[i].LoopLength);
615  }
616  }
617 
624  sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1];
625  // copy old loops array
626  for (int i = 0; i < SampleLoops; i++) {
627  pNewLoops[i] = pSampleLoops[i];
628  }
629  // add the new loop
630  pNewLoops[SampleLoops] = *pLoopDef;
631  // auto correct size field
632  pNewLoops[SampleLoops].Size = sizeof(DLS::sample_loop_t);
633  // free the old array and update the member variables
634  if (SampleLoops) delete[] pSampleLoops;
635  pSampleLoops = pNewLoops;
636  SampleLoops++;
637  }
638 
646  sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops - 1];
647  // copy old loops array (skipping given loop)
648  for (int i = 0, o = 0; i < SampleLoops; i++) {
649  if (&pSampleLoops[i] == pLoopDef) continue;
650  if (o == SampleLoops - 1) {
651  delete[] pNewLoops;
652  throw Exception("Could not delete Sample Loop, because it does not exist");
653  }
654  pNewLoops[o] = pSampleLoops[i];
655  o++;
656  }
657  // free the old array and update the member variables
658  if (SampleLoops) delete[] pSampleLoops;
659  pSampleLoops = pNewLoops;
660  SampleLoops--;
661  }
662 
669  void Sampler::CopyAssign(const Sampler* orig) {
670  // copy trivial scalars
671  UnityNote = orig->UnityNote;
672  FineTune = orig->FineTune;
673  Gain = orig->Gain;
674  NoSampleDepthTruncation = orig->NoSampleDepthTruncation;
675  NoSampleCompression = orig->NoSampleCompression;
676  SamplerOptions = orig->SamplerOptions;
677 
678  // copy sample loops
679  if (SampleLoops) delete[] pSampleLoops;
680  pSampleLoops = new sample_loop_t[orig->SampleLoops];
681  memcpy(pSampleLoops, orig->pSampleLoops, orig->SampleLoops * sizeof(sample_loop_t));
682  SampleLoops = orig->SampleLoops;
683  }
684 
685 
686 // *************** Sample ***************
687 // *
688 
704  Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : Resource(pFile, waveList) {
705  pWaveList = waveList;
706  ulWavePoolOffset = WavePoolOffset - LIST_HEADER_SIZE;
707  pCkFormat = waveList->GetSubChunk(CHUNK_ID_FMT);
708  pCkData = waveList->GetSubChunk(CHUNK_ID_DATA);
709  if (pCkFormat) {
710  // common fields
716  // PCM format specific
719  FrameSize = (BitDepth / 8) * Channels;
720  } else { // unsupported sample data format
721  BitDepth = 0;
722  FrameSize = 0;
723  }
724  } else { // 'fmt' chunk missing
726  BitDepth = 16;
727  Channels = 1;
728  SamplesPerSecond = 44100;
730  FrameSize = (BitDepth / 8) * Channels;
732  }
734  : 0
735  : 0;
736  }
737 
745  pParent->DeleteSubChunk(pWaveList);
746  }
747 
759  void Sample::CopyAssignCore(const Sample* orig) {
760  // handle base classes
761  Resource::CopyAssign(orig);
762  // handle actual own attributes of this class
763  FormatTag = orig->FormatTag;
764  Channels = orig->Channels;
767  BlockAlign = orig->BlockAlign;
768  BitDepth = orig->BitDepth;
769  SamplesTotal = orig->SamplesTotal;
770  FrameSize = orig->FrameSize;
771  }
772 
779  void Sample::CopyAssign(const Sample* orig) {
780  CopyAssignCore(orig);
781 
782  // copy sample waveform data (reading directly from disc)
783  Resize(orig->GetSize());
784  char* buf = (char*) LoadSampleData();
785  Sample* pOrig = (Sample*) orig; //HACK: circumventing the constness here for now
786  const unsigned long restorePos = pOrig->pCkData->GetPos();
787  pOrig->SetPos(0);
788  for (unsigned long todo = pOrig->GetSize(), i = 0; todo; ) {
789  const int iReadAtOnce = 64*1024;
790  unsigned long n = (iReadAtOnce < todo) ? iReadAtOnce : todo;
791  n = pOrig->Read(&buf[i], n);
792  if (!n) break;
793  todo -= n;
794  i += (n * pOrig->FrameSize);
795  }
796  pOrig->pCkData->SetPos(restorePos);
797  }
798 
826  return (pCkData) ? pCkData->LoadChunkData() : NULL;
827  }
828 
836  }
837 
848  unsigned long Sample::GetSize() const {
849  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0;
850  return (pCkData) ? pCkData->GetSize() / FrameSize : 0;
851  }
852 
881  void Sample::Resize(int iNewSize) {
882  if (FormatTag != DLS_WAVE_FORMAT_PCM) throw Exception("Sample's format is not DLS_WAVE_FORMAT_PCM");
883  if (iNewSize < 1) throw Exception("Sample size must be at least one sample point");
884  const int iSizeInBytes = iNewSize * FrameSize;
886  if (pCkData) pCkData->Resize(iSizeInBytes);
887  else pCkData = pWaveList->AddSubChunk(CHUNK_ID_DATA, iSizeInBytes);
888  }
889 
906  unsigned long Sample::SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence) {
907  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
908  if (!pCkData) throw Exception("No data chunk created for sample yet, call Sample::Resize() to create one");
909  unsigned long orderedBytes = SampleCount * FrameSize;
910  unsigned long result = pCkData->SetPos(orderedBytes, Whence);
911  return (result == orderedBytes) ? SampleCount
912  : result / FrameSize;
913  }
914 
924  unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {
925  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
926  return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
927  }
928 
944  unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) {
945  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
946  if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small");
947  return pCkData->Write(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
948  }
949 
959  throw Exception("Could not save sample, only PCM format is supported");
960  // we refuse to do anything if not sample wave form was provided yet
961  if (!pCkData)
962  throw Exception("Could not save sample, there is no sample data to save");
963  // update chunks of base class as well
965  // make sure 'fmt' chunk exists
967  if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format
968  uint8_t* pData = (uint8_t*) pCkFormat->LoadChunkData();
969  // update 'fmt' chunk
970  store16(&pData[0], FormatTag);
971  store16(&pData[2], Channels);
972  store32(&pData[4], SamplesPerSecond);
973  store32(&pData[8], AverageBytesPerSecond);
974  store16(&pData[12], BlockAlign);
975  store16(&pData[14], BitDepth); // assuming PCM format
976  }
977 
978 
979 
980 // *************** Region ***************
981 // *
982 
983  Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : Resource(pInstrument, rgnList), Articulator(rgnList), Sampler(rgnList) {
984  pCkRegion = rgnList;
985 
986  // articulation informations
987  RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);
988  if (rgnh) {
989  rgnh->Read(&KeyRange, 2, 2);
990  rgnh->Read(&VelocityRange, 2, 2);
991  FormatOptionFlags = rgnh->ReadUint16();
992  KeyGroup = rgnh->ReadUint16();
993  // Layer is optional
994  if (rgnh->RemainingBytes() >= sizeof(uint16_t)) {
995  rgnh->Read(&Layer, 1, sizeof(uint16_t));
996  } else Layer = 0;
997  } else { // 'rgnh' chunk is missing
998  KeyRange.low = 0;
999  KeyRange.high = 127;
1000  VelocityRange.low = 0;
1001  VelocityRange.high = 127;
1003  KeyGroup = 0;
1004  Layer = 0;
1005  }
1007 
1008  // sample informations
1009  RIFF::Chunk* wlnk = rgnList->GetSubChunk(CHUNK_ID_WLNK);
1010  if (wlnk) {
1011  WaveLinkOptionFlags = wlnk->ReadUint16();
1012  PhaseGroup = wlnk->ReadUint16();
1013  Channel = wlnk->ReadUint32();
1014  WavePoolTableIndex = wlnk->ReadUint32();
1015  } else { // 'wlnk' chunk is missing
1016  WaveLinkOptionFlags = 0;
1017  PhaseGroup = 0;
1018  Channel = 0; // mono
1019  WavePoolTableIndex = 0; // first entry in wave pool table
1020  }
1023 
1024  pSample = NULL;
1025  }
1026 
1033  pParent->DeleteSubChunk(pCkRegion);
1034  }
1035 
1037  if (pSample) return pSample;
1038  File* file = (File*) GetParent()->GetParent();
1039  unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1040  Sample* sample = file->GetFirstSample();
1041  while (sample) {
1042  if (sample->ulWavePoolOffset == soughtoffset) return (pSample = sample);
1043  sample = file->GetNextSample();
1044  }
1045  return NULL;
1046  }
1047 
1054  this->pSample = pSample;
1055  WavePoolTableIndex = 0; // we update this offset when we Save()
1056  }
1057 
1065  void Region::SetKeyRange(uint16_t Low, uint16_t High) {
1066  KeyRange.low = Low;
1067  KeyRange.high = High;
1068 
1069  // make sure regions are already loaded
1070  Instrument* pInstrument = (Instrument*) GetParent();
1071  if (!pInstrument->pRegions) pInstrument->LoadRegions();
1072  if (!pInstrument->pRegions) return;
1073 
1074  // find the r which is the first one to the right of this region
1075  // at its new position
1076  Region* r = NULL;
1077  Region* prev_region = NULL;
1078  for (
1079  Instrument::RegionList::iterator iter = pInstrument->pRegions->begin();
1080  iter != pInstrument->pRegions->end(); iter++
1081  ) {
1082  if ((*iter)->KeyRange.low > this->KeyRange.low) {
1083  r = *iter;
1084  break;
1085  }
1086  prev_region = *iter;
1087  }
1088 
1089  // place this region before r if it's not already there
1090  if (prev_region != this) pInstrument->MoveRegion(this, r);
1091  }
1092 
1100  // make sure 'rgnh' chunk exists
1102  if (!rgnh) rgnh = pCkRegion->AddSubChunk(CHUNK_ID_RGNH, Layer ? 14 : 12);
1103  uint8_t* pData = (uint8_t*) rgnh->LoadChunkData();
1107  // update 'rgnh' chunk
1108  store16(&pData[0], KeyRange.low);
1109  store16(&pData[2], KeyRange.high);
1110  store16(&pData[4], VelocityRange.low);
1111  store16(&pData[6], VelocityRange.high);
1112  store16(&pData[8], FormatOptionFlags);
1113  store16(&pData[10], KeyGroup);
1114  if (rgnh->GetSize() >= 14) store16(&pData[12], Layer);
1115 
1116  // update chunks of base classes as well (but skip Resource,
1117  // as a rgn doesn't seem to have dlid and INFO chunks)
1120 
1121  // make sure 'wlnk' chunk exists
1123  if (!wlnk) wlnk = pCkRegion->AddSubChunk(CHUNK_ID_WLNK, 12);
1124  pData = (uint8_t*) wlnk->LoadChunkData();
1131  // get sample's wave pool table index
1132  int index = -1;
1133  File* pFile = (File*) GetParent()->GetParent();
1134  if (pFile->pSamples) {
1135  File::SampleList::iterator iter = pFile->pSamples->begin();
1136  File::SampleList::iterator end = pFile->pSamples->end();
1137  for (int i = 0; iter != end; ++iter, i++) {
1138  if (*iter == pSample) {
1139  index = i;
1140  break;
1141  }
1142  }
1143  }
1144  WavePoolTableIndex = index;
1145  // update 'wlnk' chunk
1146  store16(&pData[0], WaveLinkOptionFlags);
1147  store16(&pData[2], PhaseGroup);
1148  store32(&pData[4], Channel);
1149  store32(&pData[8], WavePoolTableIndex);
1150  }
1151 
1161  void Region::CopyAssign(const Region* orig) {
1162  // handle base classes
1163  Resource::CopyAssign(orig);
1165  Sampler::CopyAssign(orig);
1166  // handle actual own attributes of this class
1167  // (the trivial ones)
1168  VelocityRange = orig->VelocityRange;
1169  KeyGroup = orig->KeyGroup;
1170  Layer = orig->Layer;
1172  PhaseMaster = orig->PhaseMaster;
1173  PhaseGroup = orig->PhaseGroup;
1174  MultiChannel = orig->MultiChannel;
1175  Channel = orig->Channel;
1176  // only take the raw sample reference if the two Region objects are
1177  // part of the same file
1178  if (GetParent()->GetParent() == orig->GetParent()->GetParent()) {
1180  pSample = orig->pSample;
1181  } else {
1182  WavePoolTableIndex = -1;
1183  pSample = NULL;
1184  }
1187  // handle the last, a bit sensible attribute
1188  SetKeyRange(orig->KeyRange.low, orig->KeyRange.high);
1189  }
1190 
1191 
1192 // *************** Instrument ***************
1193 // *
1194 
1208  Instrument::Instrument(File* pFile, RIFF::List* insList) : Resource(pFile, insList), Articulator(insList) {
1209  pCkInstrument = insList;
1210 
1211  midi_locale_t locale;
1213  if (insh) {
1214  Regions = insh->ReadUint32();
1215  insh->Read(&locale, 2, 4);
1216  } else { // 'insh' chunk missing
1217  Regions = 0;
1218  locale.bank = 0;
1219  locale.instrument = 0;
1220  }
1221 
1222  MIDIProgram = locale.instrument;
1223  IsDrum = locale.bank & DRUM_TYPE_MASK;
1224  MIDIBankCoarse = (uint8_t) MIDI_BANK_COARSE(locale.bank);
1225  MIDIBankFine = (uint8_t) MIDI_BANK_FINE(locale.bank);
1227 
1228  pRegions = NULL;
1229  }
1230 
1232  if (!pRegions) LoadRegions();
1233  if (!pRegions) return NULL;
1234  RegionsIterator = pRegions->begin();
1235  return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1236  }
1237 
1239  if (!pRegions) return NULL;
1240  RegionsIterator++;
1241  return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1242  }
1243 
1245  if (!pRegions) pRegions = new RegionList;
1247  if (lrgn) {
1248  uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2
1249  RIFF::List* rgn = lrgn->GetFirstSubList();
1250  while (rgn) {
1251  if (rgn->GetListType() == regionCkType) {
1252  pRegions->push_back(new Region(this, rgn));
1253  }
1254  rgn = lrgn->GetNextSubList();
1255  }
1256  }
1257  }
1258 
1260  if (!pRegions) LoadRegions();
1262  if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);
1263  RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
1264  Region* pNewRegion = new Region(this, rgn);
1265  pRegions->push_back(pNewRegion);
1266  Regions = pRegions->size();
1267  return pNewRegion;
1268  }
1269 
1270  void Instrument::MoveRegion(Region* pSrc, Region* pDst) {
1272  lrgn->MoveSubChunk(pSrc->pCkRegion, pDst ? pDst->pCkRegion : 0);
1273 
1274  pRegions->remove(pSrc);
1275  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);
1276  pRegions->insert(iter, pSrc);
1277  }
1278 
1280  if (!pRegions) return;
1281  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
1282  if (iter == pRegions->end()) return;
1283  pRegions->erase(iter);
1284  Regions = pRegions->size();
1285  delete pRegion;
1286  }
1287 
1295  // first update base classes' chunks
1298  // make sure 'insh' chunk exists
1300  if (!insh) insh = pCkInstrument->AddSubChunk(CHUNK_ID_INSH, 12);
1301  uint8_t* pData = (uint8_t*) insh->LoadChunkData();
1302  // update 'insh' chunk
1303  Regions = (pRegions) ? pRegions->size() : 0;
1304  midi_locale_t locale;
1305  locale.instrument = MIDIProgram;
1307  locale.bank = (IsDrum) ? locale.bank | DRUM_TYPE_MASK : locale.bank & (~DRUM_TYPE_MASK);
1308  MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine); // just a sync, when we're at it
1309  store32(&pData[0], Regions);
1310  store32(&pData[4], locale.bank);
1311  store32(&pData[8], locale.instrument);
1312  // update Region's chunks
1313  if (!pRegions) return;
1314  RegionList::iterator iter = pRegions->begin();
1315  RegionList::iterator end = pRegions->end();
1316  for (; iter != end; ++iter) {
1317  (*iter)->UpdateChunks();
1318  }
1319  }
1320 
1327  if (pRegions) {
1328  RegionList::iterator iter = pRegions->begin();
1329  RegionList::iterator end = pRegions->end();
1330  while (iter != end) {
1331  delete *iter;
1332  iter++;
1333  }
1334  delete pRegions;
1335  }
1336  // remove instrument's chunks
1338  pParent->DeleteSubChunk(pCkInstrument);
1339  }
1340 
1342  // handle base classes
1343  Resource::CopyAssign(orig);
1345  // handle actual own attributes of this class
1346  // (the trivial ones)
1347  IsDrum = orig->IsDrum;
1348  MIDIBank = orig->MIDIBank;
1350  MIDIBankFine = orig->MIDIBankFine;
1351  MIDIProgram = orig->MIDIProgram;
1352  }
1353 
1364  CopyAssignCore(orig);
1365  // delete all regions first
1366  while (Regions) DeleteRegion(GetFirstRegion());
1367  // now recreate and copy regions
1368  {
1369  RegionList::const_iterator it = orig->pRegions->begin();
1370  for (int i = 0; i < orig->Regions; ++i, ++it) {
1371  Region* dstRgn = AddRegion();
1372  //NOTE: Region does semi-deep copy !
1373  dstRgn->CopyAssign(*it);
1374  }
1375  }
1376  }
1377 
1378 
1379 // *************** File ***************
1380 // *
1381 
1388  File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) {
1390  pVersion = new version_t;
1391  pVersion->major = 0;
1392  pVersion->minor = 0;
1393  pVersion->release = 0;
1394  pVersion->build = 0;
1395 
1396  Instruments = 0;
1397  WavePoolCount = 0;
1398  pWavePoolTable = NULL;
1399  pWavePoolTableHi = NULL;
1400  WavePoolHeaderSize = 8;
1401 
1402  pSamples = NULL;
1403  pInstruments = NULL;
1404 
1405  b64BitWavePoolOffsets = false;
1406  }
1407 
1418  if (!pRIFF) throw DLS::Exception("NULL pointer reference to RIFF::File object.");
1419  this->pRIFF = pRIFF;
1420 
1421  RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1422  if (ckVersion) {
1423  pVersion = new version_t;
1424  ckVersion->Read(pVersion, 4, 2);
1425  }
1426  else pVersion = NULL;
1427 
1428  RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
1429  if (!colh) throw DLS::Exception("Mandatory chunks in RIFF list chunk not found.");
1430  Instruments = colh->ReadUint32();
1431 
1432  RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
1433  if (!ptbl) { // pool table is missing - this is probably an ".art" file
1434  WavePoolCount = 0;
1435  pWavePoolTable = NULL;
1436  pWavePoolTableHi = NULL;
1437  WavePoolHeaderSize = 8;
1438  b64BitWavePoolOffsets = false;
1439  } else {
1440  WavePoolHeaderSize = ptbl->ReadUint32();
1441  WavePoolCount = ptbl->ReadUint32();
1442  pWavePoolTable = new uint32_t[WavePoolCount];
1443  pWavePoolTableHi = new uint32_t[WavePoolCount];
1444  ptbl->SetPos(WavePoolHeaderSize);
1445 
1446  // Check for 64 bit offsets (used in gig v3 files)
1448  if (b64BitWavePoolOffsets) {
1449  for (int i = 0 ; i < WavePoolCount ; i++) {
1450  pWavePoolTableHi[i] = ptbl->ReadUint32();
1451  pWavePoolTable[i] = ptbl->ReadUint32();
1452  if (pWavePoolTable[i] & 0x80000000)
1453  throw DLS::Exception("Files larger than 2 GB not yet supported");
1454  }
1455  } else { // conventional 32 bit offsets
1456  ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
1457  for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;
1458  }
1459  }
1460 
1461  pSamples = NULL;
1462  pInstruments = NULL;
1463  }
1464 
1466  if (pInstruments) {
1467  InstrumentList::iterator iter = pInstruments->begin();
1468  InstrumentList::iterator end = pInstruments->end();
1469  while (iter != end) {
1470  delete *iter;
1471  iter++;
1472  }
1473  delete pInstruments;
1474  }
1475 
1476  if (pSamples) {
1477  SampleList::iterator iter = pSamples->begin();
1478  SampleList::iterator end = pSamples->end();
1479  while (iter != end) {
1480  delete *iter;
1481  iter++;
1482  }
1483  delete pSamples;
1484  }
1485 
1486  if (pWavePoolTable) delete[] pWavePoolTable;
1487  if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1488  if (pVersion) delete pVersion;
1489  for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1490  delete *i;
1491  }
1492 
1494  if (!pSamples) LoadSamples();
1495  if (!pSamples) return NULL;
1496  SamplesIterator = pSamples->begin();
1497  return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1498  }
1499 
1501  if (!pSamples) return NULL;
1502  SamplesIterator++;
1503  return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1504  }
1505 
1507  if (!pSamples) pSamples = new SampleList;
1509  if (wvpl) {
1510  unsigned long wvplFileOffset = wvpl->GetFilePos();
1511  RIFF::List* wave = wvpl->GetFirstSubList();
1512  while (wave) {
1513  if (wave->GetListType() == LIST_TYPE_WAVE) {
1514  unsigned long waveFileOffset = wave->GetFilePos();
1515  pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1516  }
1517  wave = wvpl->GetNextSubList();
1518  }
1519  }
1520  else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)
1522  if (dwpl) {
1523  unsigned long dwplFileOffset = dwpl->GetFilePos();
1524  RIFF::List* wave = dwpl->GetFirstSubList();
1525  while (wave) {
1526  if (wave->GetListType() == LIST_TYPE_WAVE) {
1527  unsigned long waveFileOffset = wave->GetFilePos();
1528  pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1529  }
1530  wave = dwpl->GetNextSubList();
1531  }
1532  }
1533  }
1534  }
1535 
1544  if (!pSamples) LoadSamples();
1547  // create new Sample object and its respective 'wave' list chunk
1548  RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
1549  Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/);
1550  pSamples->push_back(pSample);
1551  return pSample;
1552  }
1553 
1561  void File::DeleteSample(Sample* pSample) {
1562  if (!pSamples) return;
1563  SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample);
1564  if (iter == pSamples->end()) return;
1565  pSamples->erase(iter);
1566  delete pSample;
1567  }
1568 
1570  if (!pInstruments) LoadInstruments();
1571  if (!pInstruments) return NULL;
1572  InstrumentsIterator = pInstruments->begin();
1573  return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
1574  }
1575 
1577  if (!pInstruments) return NULL;
1579  return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
1580  }
1581 
1584  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1585  if (lstInstruments) {
1586  RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1587  while (lstInstr) {
1588  if (lstInstr->GetListType() == LIST_TYPE_INS) {
1589  pInstruments->push_back(new Instrument(this, lstInstr));
1590  }
1591  lstInstr = lstInstruments->GetNextSubList();
1592  }
1593  }
1594  }
1595 
1604  if (!pInstruments) LoadInstruments();
1606  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1607  RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
1608  Instrument* pInstrument = new Instrument(this, lstInstr);
1609  pInstruments->push_back(pInstrument);
1610  return pInstrument;
1611  }
1612 
1620  void File::DeleteInstrument(Instrument* pInstrument) {
1621  if (!pInstruments) return;
1622  InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument);
1623  if (iter == pInstruments->end()) return;
1624  pInstruments->erase(iter);
1625  delete pInstrument;
1626  }
1627 
1641  if (index < 0 || index >= ExtensionFiles.size()) return NULL;
1642  std::list<RIFF::File*>::iterator iter = ExtensionFiles.begin();
1643  for (int i = 0; iter != ExtensionFiles.end(); ++iter, ++i)
1644  if (i == index) return *iter;
1645  return NULL;
1646  }
1647 
1658  return pRIFF->GetFileName();
1659  }
1660 
1665  void File::SetFileName(const String& name) {
1666  pRIFF->SetFileName(name);
1667  }
1668 
1677  // first update base class's chunks
1679 
1680  // if version struct exists, update 'vers' chunk
1681  if (pVersion) {
1682  RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1683  if (!ckVersion) ckVersion = pRIFF->AddSubChunk(CHUNK_ID_VERS, 8);
1684  uint8_t* pData = (uint8_t*) ckVersion->LoadChunkData();
1685  store16(&pData[0], pVersion->minor);
1686  store16(&pData[2], pVersion->major);
1687  store16(&pData[4], pVersion->build);
1688  store16(&pData[6], pVersion->release);
1689  }
1690 
1691  // update 'colh' chunk
1692  Instruments = (pInstruments) ? pInstruments->size() : 0;
1694  if (!colh) colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);
1695  uint8_t* pData = (uint8_t*) colh->LoadChunkData();
1696  store32(pData, Instruments);
1697 
1698  // update instrument's chunks
1699  if (pInstruments) {
1700  InstrumentList::iterator iter = pInstruments->begin();
1701  InstrumentList::iterator end = pInstruments->end();
1702  for (; iter != end; ++iter) {
1703  (*iter)->UpdateChunks();
1704  }
1705  }
1706 
1707  // update 'ptbl' chunk
1708  const int iSamples = (pSamples) ? pSamples->size() : 0;
1709  const int iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1711  if (!ptbl) ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, 1 /*anything, we'll resize*/);
1712  const int iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
1713  ptbl->Resize(iPtblSize);
1714  pData = (uint8_t*) ptbl->LoadChunkData();
1715  WavePoolCount = iSamples;
1716  store32(&pData[4], WavePoolCount);
1717  // we actually update the sample offsets in the pool table when we Save()
1718  memset(&pData[WavePoolHeaderSize], 0, iPtblSize - WavePoolHeaderSize);
1719 
1720  // update sample's chunks
1721  if (pSamples) {
1722  SampleList::iterator iter = pSamples->begin();
1723  SampleList::iterator end = pSamples->end();
1724  for (; iter != end; ++iter) {
1725  (*iter)->UpdateChunks();
1726  }
1727  }
1728  }
1729 
1743  void File::Save(const String& Path) {
1744  UpdateChunks();
1745  pRIFF->Save(Path);
1747  }
1748 
1758  void File::Save() {
1759  UpdateChunks();
1760  pRIFF->Save();
1762  }
1763 
1775  __UpdateWavePoolTableChunk();
1776  }
1777 
1784  // enusre 'lins' list chunk exists (mandatory for instrument definitions)
1785  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1786  if (!lstInstruments) pRIFF->AddSubList(LIST_TYPE_LINS);
1787  // ensure 'ptbl' chunk exists (mandatory for samples)
1789  if (!ptbl) {
1790  const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1791  ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, WavePoolHeaderSize + iOffsetSize);
1792  }
1793  // enusre 'wvpl' list chunk exists (mandatory for samples)
1795  if (!wvpl) pRIFF->AddSubList(LIST_TYPE_WVPL);
1796  }
1797 
1807  void File::__UpdateWavePoolTableChunk() {
1808  __UpdateWavePoolTable();
1810  const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1811  // check if 'ptbl' chunk is large enough
1812  WavePoolCount = (pSamples) ? pSamples->size() : 0;
1813  const unsigned long ulRequiredSize = WavePoolHeaderSize + iOffsetSize * WavePoolCount;
1814  if (ptbl->GetSize() < ulRequiredSize) throw Exception("Fatal error, 'ptbl' chunk too small");
1815  // save the 'ptbl' chunk's current read/write position
1816  unsigned long ulOriginalPos = ptbl->GetPos();
1817  // update headers
1818  ptbl->SetPos(0);
1819  uint32_t tmp = WavePoolHeaderSize;
1820  ptbl->WriteUint32(&tmp);
1821  tmp = WavePoolCount;
1822  ptbl->WriteUint32(&tmp);
1823  // update offsets
1824  ptbl->SetPos(WavePoolHeaderSize);
1825  if (b64BitWavePoolOffsets) {
1826  for (int i = 0 ; i < WavePoolCount ; i++) {
1827  tmp = pWavePoolTableHi[i];
1828  ptbl->WriteUint32(&tmp);
1829  tmp = pWavePoolTable[i];
1830  ptbl->WriteUint32(&tmp);
1831  }
1832  } else { // conventional 32 bit offsets
1833  for (int i = 0 ; i < WavePoolCount ; i++) {
1834  tmp = pWavePoolTable[i];
1835  ptbl->WriteUint32(&tmp);
1836  }
1837  }
1838  // restore 'ptbl' chunk's original read/write position
1839  ptbl->SetPos(ulOriginalPos);
1840  }
1841 
1847  void File::__UpdateWavePoolTable() {
1848  WavePoolCount = (pSamples) ? pSamples->size() : 0;
1849  // resize wave pool table arrays
1850  if (pWavePoolTable) delete[] pWavePoolTable;
1851  if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1852  pWavePoolTable = new uint32_t[WavePoolCount];
1853  pWavePoolTableHi = new uint32_t[WavePoolCount];
1854  if (!pSamples) return;
1855  // update offsets int wave pool table
1857  uint64_t wvplFileOffset = wvpl->GetFilePos();
1858  if (b64BitWavePoolOffsets) {
1859  SampleList::iterator iter = pSamples->begin();
1860  SampleList::iterator end = pSamples->end();
1861  for (int i = 0 ; iter != end ; ++iter, i++) {
1862  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE;
1863  (*iter)->ulWavePoolOffset = _64BitOffset;
1864  pWavePoolTableHi[i] = (uint32_t) (_64BitOffset >> 32);
1865  pWavePoolTable[i] = (uint32_t) _64BitOffset;
1866  }
1867  } else { // conventional 32 bit offsets
1868  SampleList::iterator iter = pSamples->begin();
1869  SampleList::iterator end = pSamples->end();
1870  for (int i = 0 ; iter != end ; ++iter, i++) {
1871  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE;
1872  (*iter)->ulWavePoolOffset = _64BitOffset;
1873  pWavePoolTable[i] = (uint32_t) _64BitOffset;
1874  }
1875  }
1876  }
1877 
1878 
1879 
1880 // *************** Exception ***************
1881 // *
1882 
1884  }
1885 
1887  std::cout << "DLS::Exception: " << Message << std::endl;
1888  }
1889 
1890 
1891 // *************** functions ***************
1892 // *
1893 
1900  return PACKAGE;
1901  }
1902 
1908  return VERSION;
1909  }
1910 
1911 } // namespace DLS
virtual void CopyAssign(const Instrument *orig)
Make a (semi) deep copy of the Instrument object given by orig and assign it to this object...
Definition: DLS.cpp:1363
#define CONN_TRANSFORM_BIPOLAR_CTL_ENCODE(x)
Definition: DLS.cpp:51
unsigned long WriteUint32(uint32_t *pData, unsigned long WordCount=1)
Writes WordCount number of 32 Bit unsigned integer words from the buffer pointed by pData to the chun...
Definition: RIFF.cpp:632
uint16_t BlockAlign
The block alignment (in bytes) of the waveform data. Playback software needs to process a multiple of...
Definition: DLS.h:400
#define LIST_TYPE_DWPL
Seen on some files instead of a wvpl list chunk.
Definition: DLS.h:66
sample_loop_t * pSampleLoops
Points to the beginning of a sample loop array, or is NULL if there are no loops defined.
Definition: DLS.h:371
virtual void UpdateChunks()
Update chunks with current info values.
Definition: DLS.cpp:340
uint32_t Regions
Reflects the number of Region defintions this Instrument has.
Definition: DLS.h:465
range_t VelocityRange
Definition: DLS.h:431
bool SourceBipolar
Definition: DLS.h:248
virtual void UpdateChunks()
Apply Instrument with all its Regions to the respective RIFF chunks.
Definition: DLS.cpp:1294
Parses DLS Level 1 and 2 compliant files and provides abstract access to the data.
Definition: DLS.h:495
File()
Constructor.
Definition: DLS.cpp:1388
stream_whence_t
File stream position dependent to these relations.
Definition: RIFF.h:158
uint16_t Layer
Definition: DLS.h:433
unsigned long Read(void *pData, unsigned long WordCount, unsigned long WordSize)
Reads WordCount number of data words with given WordSize and copies it into a buffer pointed by pData...
Definition: RIFF.cpp:284
String CreationDate
<ICRD-ck>. Specifies the date the subject of the file was created. List dates in yyyy-mm-dd format...
Definition: DLS.h:308
Chunk * GetFirstSubChunk()
Returns the first subchunk within the list.
Definition: RIFF.cpp:1050
virtual ~Articulation()
Definition: DLS.cpp:140
#define F_WAVELINK_PHASE_MASTER
Definition: DLS.cpp:59
#define LIST_TYPE_WAVE
Definition: DLS.h:67
#define CHUNK_ID_ARTL
Definition: DLS.h:95
virtual void UpdateChunks()
Apply all articulations to the respective RIFF chunks.
Definition: DLS.cpp:221
#define CHUNK_ID_ISBJ
Definition: DLS.h:81
uint32_t GetChunkID()
Chunk ID in unsigned integer representation.
Definition: RIFF.h:187
String Engineer
<IENG-ck>. Stores the name of the engineer who worked on the file. Multiple engineer names are separa...
Definition: DLS.h:315
virtual void SetKeyRange(uint16_t Low, uint16_t High)
Modifies the key range of this Region and makes sure the respective chunks are in correct order...
Definition: DLS.cpp:1065
void __ensureMandatoryChunksExist()
Checks if all (for DLS) mandatory chunks exist, if not they will be created.
Definition: DLS.cpp:1783
String Artists
<IART-ck>. Lists the artist of the original subject of the file.
Definition: DLS.h:312
#define CHUNK_ID_ISRF
Definition: DLS.h:83
#define LIST_TYPE_LART
Definition: DLS.h:71
Sample * GetFirstSample()
Returns a pointer to the first Sample object of the file, NULL otherwise.
Definition: DLS.cpp:1493
Instrument * GetNextInstrument()
Returns a pointer to the next Instrument object of the file, NULL otherwise.
Definition: DLS.cpp:1576
std::string String
Definition: DLS.h:106
Will be thrown whenever a DLS specific error occurs while trying to access a DLS File.
Definition: DLS.h:550
conn_trn_t SourceTransform
Definition: DLS.h:246
Optional information for DLS files, instruments, samples, etc.
Definition: DLS.h:304
virtual void CopyAssign(const Region *orig)
Make a (semi) deep copy of the Region object given by orig and assign it to this object.
Definition: DLS.cpp:1161
unsigned long Read(void *pBuffer, unsigned long SampleCount)
Reads SampleCount number of sample points from the current position into the buffer pointed by pBuffe...
Definition: DLS.cpp:924
uint16_t KeyGroup
Definition: DLS.h:432
#define CONN_TRANSFORM_INVERT_SRC_ENCODE(x)
Definition: DLS.cpp:52
RIFF::File * GetExtensionFile(int index)
Returns extension file of given index.
Definition: DLS.cpp:1640
virtual ~Region()
Destructor.
Definition: DLS.cpp:1031
Instrument * AddInstrument()
Add a new instrument definition.
Definition: DLS.cpp:1603
#define CHUNK_ID_PTBL
Definition: DLS.h:92
#define LIST_TYPE_WVPL
Definition: DLS.h:65
String GetFileName()
Definition: RIFF.cpp:1601
RIFF::List * pCkRegion
Definition: DLS.h:446
Instrument * GetFirstInstrument()
Returns a pointer to the first Instrument object of the file, NULL otherwise.
Definition: DLS.cpp:1569
String Keywords
<IKEY-ck>. Provides a list of keywords that refer to the file or subject of the file. Keywords are separated with semicolon and blank, e.g., FX; death; murder.
Definition: DLS.h:314
#define DLS_WAVE_FORMAT_PCM
Definition: DLS.h:99
unsigned long GetSize() const
Returns sample size.
Definition: DLS.cpp:848
#define CHUNK_ID_ART2
Definition: DLS.h:96
#define CONN_TRANSFORM_DST(x)
Definition: DLS.cpp:40
std::list< Articulation * > ArticulationList
Definition: DLS.h:294
conn_src_t
Connection Sources.
Definition: DLS.h:125
unsigned long SetPos(unsigned long Where, stream_whence_t Whence=stream_start)
Sets the position within the chunk body, thus within the data portion of the chunk (in bytes)...
Definition: RIFF.cpp:203
#define CONN_TRANSFORM_SRC_ENCODE(x)
Definition: DLS.cpp:47
#define CHUNK_ID_ICMT
Definition: RIFF.h:98
#define CHUNK_ID_ISFT
Definition: RIFF.h:104
friend class Region
Definition: DLS.h:489
uint32_t * pWavePoolTable
Definition: DLS.h:529
#define CHUNK_ID_IMED
Definition: DLS.h:80
uint32_t WavePoolTableIndex
Definition: DLS.h:447
#define CHUNK_ID_IPRD
Definition: RIFF.h:103
uint16_t Channels
Number of channels represented in the waveform data, e.g. 1 for mono, 2 for stereo (defaults to 1=mon...
Definition: DLS.h:397
#define CONN_TRANSFORM_BIPOLAR_SRC(x)
Definition: DLS.cpp:41
virtual ~Info()
Definition: DLS.cpp:278
#define LIST_HEADER_SIZE
Definition: RIFF.h:111
RIFF::List * pCkInstrument
Definition: DLS.h:480
uint32_t SamplerOptions
Definition: DLS.h:381
virtual ~Resource()
Definition: DLS.cpp:455
#define CHUNK_ID_DATA
Definition: DLS.h:88
String SourceForm
<ISRF-ck>. Identifies the original form of the material that was digitized, such as record...
Definition: DLS.h:320
int16_t FineTune
Definition: DLS.h:366
bool ControlInvert
Definition: DLS.h:251
Sampler(RIFF::List *ParentList)
Definition: DLS.cpp:542
List * GetSubList(uint32_t ListType)
Returns sublist chunk with list type ListType within this chunk list.
Definition: RIFF.cpp:1025
void DeleteSubChunk(Chunk *pSubChunk)
Removes a sub chunk.
Definition: RIFF.cpp:1277
Defines Sample Loop Points.
Definition: DLS.h:229
#define LIST_TYPE_RGN2
Definition: DLS.h:74
virtual void UpdateChunks()
Apply articulation connections to the respective RIFF chunks.
Definition: DLS.cpp:148
Region * AddRegion()
Definition: DLS.cpp:1259
unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence=RIFF::stream_start)
Sets the position within the sample (in sample points, not in bytes).
Definition: DLS.cpp:906
virtual ~Sample()
Destructor.
Definition: DLS.cpp:743
void PrintMessage()
Definition: DLS.cpp:1886
virtual void LoadSamples()
Definition: DLS.cpp:1506
bool ControlBipolar
Definition: DLS.h:252
bool NoSampleCompression
Definition: DLS.h:369
uint16_t MIDIBank
Reflects combination of MIDIBankCoarse and MIDIBankFine (bank 1 - bank 16384). Do not change this val...
Definition: DLS.h:461
virtual void SetGain(int32_t gain)
Definition: DLS.cpp:578
#define CONN_TRANSFORM_BIPOLAR_CTL(x)
Definition: DLS.cpp:42
unsigned long RemainingBytes()
Returns the number of bytes left to read in the chunk body.
Definition: RIFF.cpp:235
#define RIFF_TYPE_DLS
Definition: DLS.h:64
void LoadString(RIFF::Chunk *ck, std::string &s, int strLength)
Definition: SF.cpp:60
List * GetFirstSubList()
Returns the first sublist within the list (that is a subchunk with chunk ID "LIST").
Definition: RIFF.cpp:1084
#define MIDI_BANK_MERGE(coarse, fine)
Definition: DLS.cpp:67
#define MIDI_BANK_FINE(x)
Definition: DLS.cpp:66
#define CHUNK_ID_IKEY
Definition: DLS.h:79
uint16_t minor
Definition: DLS.h:110
virtual void CopyAssign(const Info *orig)
Make a deep copy of the Info object given by orig and assign it to this object.
Definition: DLS.cpp:402
std::list< Sample * > SampleList
Definition: DLS.h:518
virtual void UpdateChunks()
Apply all the DLS file&#39;s current instruments, samples and settings to the respective RIFF chunks...
Definition: DLS.cpp:1676
InstrumentList::iterator InstrumentsIterator
Definition: DLS.h:526
uint8_t MIDIBankCoarse
Reflects the MIDI Bank number for MIDI Control Change 0 (bank 1 - 128).
Definition: DLS.h:462
void GenerateDLSID()
Generates a new DLSID for the resource.
Definition: DLS.cpp:487
conn_dst_t Destination
Definition: DLS.h:253
uint FrameSize
Reflects the size (in bytes) of one single sample point (only if known sample data format is used...
Definition: DLS.h:403
#define MIDI_BANK_COARSE(x)
Definition: DLS.cpp:65
RIFF::Chunk * pCkFormat
Definition: DLS.h:417
unsigned long ReadUint32(uint32_t *pData, unsigned long WordCount=1)
Reads WordCount number of 32 Bit unsigned integer words and copies it into the buffer pointed by pDat...
Definition: RIFF.cpp:594
#define CHUNK_ID_IENG
Definition: RIFF.h:101
Every subject of an DLS file and the file itself can have an unique, computer generated ID...
Definition: DLS.h:117
unsigned long GetPos()
Position within the chunk data body.
Definition: RIFF.h:192
bool MultiChannel
Definition: DLS.h:437
#define F_WAVELINK_MULTICHANNEL
Definition: DLS.cpp:60
virtual void CopyAssign(const Sample *orig)
Make a deep copy of the Sample object given by orig and assign it to this object. ...
Definition: DLS.cpp:779
Region * GetFirstRegion()
Definition: DLS.cpp:1231
void DeleteSampleLoop(sample_loop_t *pLoopDef)
Deletes an existing sample loop.
Definition: DLS.cpp:645
virtual ~Instrument()
Destructor.
Definition: DLS.cpp:1326
uint16_t low
Low value of range.
Definition: DLS.h:205
void SetByteOrder(endian_t Endian)
Set the byte order to be used when saving.
Definition: RIFF.cpp:1732
#define CONN_TRANSFORM_BIPOLAR_SRC_ENCODE(x)
Definition: DLS.cpp:50
bool b64BitWavePoolOffsets
Definition: DLS.h:531
#define DRUM_TYPE_MASK
Definition: DLS.cpp:55
RIFF List Chunk.
Definition: RIFF.h:280
#define CHUNK_ID_WSMP
Definition: DLS.h:93
RIFF::Chunk * pCkData
Definition: DLS.h:416
#define CHUNK_ID_VERS
Definition: DLS.h:85
void SetFixedStringLengths(const string_length_t *lengths)
Forces specific Info fields to be of a fixed length when being saved to a file.
Definition: DLS.cpp:292
RegionList * pRegions
Definition: DLS.h:481
uint16_t FormatTag
Format ID of the waveform data (should be DLS_WAVE_FORMAT_PCM for DLS1 compliant files, this is also the default value if Sample was created with Instrument::AddSample()).
Definition: DLS.h:396
virtual void CopyAssign(const Sampler *orig)
Make a deep copy of the Sampler object given by orig and assign it to this object.
Definition: DLS.cpp:669
void ReleaseSampleData()
Free sample data from RAM.
Definition: DLS.cpp:834
#define CHUNK_ID_RGNH
Definition: DLS.h:90
virtual void CopyAssign(const Articulator *orig)
Not yet implemented in this version, since the .gig format does not need to copy DLS articulators and...
Definition: DLS.cpp:236
Abstract base class which provides mandatory informations about sample players in general...
Definition: DLS.h:363
bool SelfNonExclusive
Definition: DLS.h:434
String libraryName()
Returns the name of this C++ library.
Definition: DLS.cpp:1899
Sample * GetSample()
Definition: DLS.cpp:1036
Exception(String Message)
Definition: DLS.cpp:1883
#define CHUNK_ID_WLNK
Definition: DLS.h:91
#define CONN_TRANSFORM_DST_ENCODE(x)
Definition: DLS.cpp:49
conn_trn_t
Connection Transforms.
Definition: DLS.h:196
void SetFileName(const String &name)
You may call this method store a future file name, so you don&#39;t have to to pass it to the Save() call...
Definition: DLS.cpp:1665
uint32_t SampleLoops
Reflects the number of sample loops.
Definition: DLS.h:370
conn_trn_t DestinationTransform
Definition: DLS.h:254
Resource * pParent
Definition: DLS.h:355
void Resize(int iNewSize)
Resize sample.
Definition: DLS.cpp:881
SampleList * pSamples
Definition: DLS.h:523
#define CHUNK_ID_FMT
Definition: DLS.h:87
conn_dst_t
Connection Destinations.
Definition: DLS.h:151
bool NoSampleDepthTruncation
Definition: DLS.h:368
String Message
Definition: RIFF.h:385
virtual ~Articulator()
Definition: DLS.cpp:205
void DeleteSample(Sample *pSample)
Delete a sample.
Definition: DLS.cpp:1561
bool SourceInvert
Definition: DLS.h:247
unsigned long ReadInt32(int32_t *pData, unsigned long WordCount=1)
Reads WordCount number of 32 Bit signed integer words and copies it into the buffer pointed by pData...
Definition: RIFF.cpp:557
uint16_t high
High value of range.
Definition: DLS.h:206
virtual void UpdateChunks()
Apply Region settings to the respective RIFF chunks.
Definition: DLS.cpp:1099
Articulation * GetFirstArticulation()
Definition: DLS.cpp:174
uint32_t Size
For internal usage only: usually reflects exactly sizeof(sample_loop_t), otherwise if the value is la...
Definition: DLS.h:230
bool PhaseMaster
Definition: DLS.h:435
Chunk * GetSubChunk(uint32_t ChunkID)
Returns subchunk with chunk ID ChunkID within this chunk list.
Definition: RIFF.cpp:1006
#define LIST_TYPE_INS
Definition: DLS.h:69
Chunk * GetNextSubChunk()
Returns the next subchunk within the list.
Definition: RIFF.cpp:1066
Info(RIFF::List *list)
Constructor.
Definition: DLS.cpp:251
std::list< Instrument * > InstrumentList
Definition: DLS.h:519
Region(Instrument *pInstrument, RIFF::List *rgnList)
Definition: DLS.cpp:983
#define CHUNK_ID_ICRD
Definition: RIFF.h:100
#define CHUNK_ID_DLID
Definition: DLS.h:86
unsigned long SamplesTotal
Reflects total number of sample points (only if known sample data format is used, 0 otherwise)...
Definition: DLS.h:402
String Source
<ISRC-ck>. Identifies the name of the person or organization who supplied the original subject of the...
Definition: DLS.h:319
uint16_t BitDepth
Size of each sample per channel (only if known sample data format is used, 0 otherwise).
Definition: DLS.h:401
Ordinary RIFF Chunk.
Definition: RIFF.h:183
uint32_t GetListType()
Returns unsigned integer representation of the list&#39;s ID.
Definition: RIFF.h:284
#define CHUNK_ID_ICMS
Definition: DLS.h:77
unsigned long GetFilePos()
Current, actual offset in file.
Definition: RIFF.h:193
uint32_t Scale
Definition: DLS.h:255
uint8_t UnityNote
Definition: DLS.h:365
#define F_WSMP_NO_COMPRESSION
Definition: DLS.cpp:63
virtual ~File()
Definition: DLS.cpp:1465
#define CONN_TRANSFORM_SRC(x)
Definition: DLS.cpp:38
#define LIST_TYPE_RGN
Definition: DLS.h:73
#define CHUNK_ID_INAM
Definition: RIFF.h:102
uint32_t MIDIProgram
Specifies the MIDI Program Change Number this Instrument should be assigned to.
Definition: DLS.h:464
String Commissioned
<ICMS-ck>. Lists the name of the person or organization that commissioned the subject of the file...
Definition: DLS.h:321
#define CHUNK_ID_ITCH
Definition: DLS.h:84
friend class Articulation
Definition: DLS.h:268
unsigned long ReadInt16(int16_t *pData, unsigned long WordCount=1)
Reads WordCount number of 16 Bit signed integer words and copies it into the buffer pointed by pData...
Definition: RIFF.cpp:483
#define F_RGN_OPTION_SELFNONEXCLUSIVE
Definition: DLS.cpp:57
void SetSample(Sample *pSample)
Assign another sample to this Region.
Definition: DLS.cpp:1053
unsigned long Write(void *pData, unsigned long WordCount, unsigned long WordSize)
Writes WordCount number of data words with given WordSize from the buffer pointed by pData...
Definition: RIFF.cpp:342
SampleList::iterator SamplesIterator
Definition: DLS.h:524
List * GetParent()
Returns pointer to the chunk&#39;s parent list chunk.
Definition: RIFF.h:189
Articulation * GetNextArticulation()
Definition: DLS.cpp:181
Chunk * AddSubChunk(uint32_t uiChunkID, uint uiBodySize)
Creates a new sub chunk.
Definition: RIFF.cpp:1186
conn_src_t Control
Definition: DLS.h:249
#define CONN_TRANSFORM_INVERT_CTL_ENCODE(x)
Definition: DLS.cpp:53
uint16_t WaveLinkOptionFlags
Definition: DLS.h:450
#define F_WSMP_NO_TRUNCATION
Definition: DLS.cpp:62
#define CONN_TRANSFORM_CTL(x)
Definition: DLS.cpp:39
#define MIDI_BANK_ENCODE(coarse, fine)
Definition: DLS.cpp:68
#define LIST_TYPE_LAR2
Definition: DLS.h:72
#define CONN_TRANSFORM_INVERT_SRC(x)
Definition: DLS.cpp:43
void DeleteInstrument(Instrument *pInstrument)
Delete an instrument.
Definition: DLS.cpp:1620
unsigned long Write(void *pBuffer, unsigned long SampleCount)
Write sample wave data.
Definition: DLS.cpp:944
version_t * pVersion
Points to a version_t structure if the file provided a version number else is set to NULL...
Definition: DLS.h:497
String Technician
<ITCH-ck>. Identifies the technician who sampled the subject file.
Definition: DLS.h:316
Instrument(File *pFile, RIFF::List *insList)
Constructor.
Definition: DLS.cpp:1208
uint16_t major
Definition: DLS.h:111
RegionList::iterator RegionsIterator
Definition: DLS.h:482
void SetFileName(const String &path)
Definition: RIFF.cpp:1605
#define CHUNK_ID_INSH
Definition: DLS.h:89
void * LoadChunkData()
Load chunk body into RAM.
Definition: RIFF.cpp:757
Region * GetNextRegion()
Definition: DLS.cpp:1238
#define LIST_TYPE_LRGN
Definition: DLS.h:70
#define CHUNK_ID_IGNR
Definition: DLS.h:78
#define CHUNK_ID_IART
Definition: DLS.h:76
uint32_t AverageBytesPerSecond
The average number of bytes per second at which the waveform data should be transferred (Playback sof...
Definition: DLS.h:399
conn_src_t Source
Definition: DLS.h:245
uint8_t MIDIBankFine
Reflects the MIDI Bank number for MIDI Control Change 32 (bank 1 - 128).
Definition: DLS.h:463
uint16_t PhaseGroup
Definition: DLS.h:436
#define CHUNK_ID_COLH
Definition: DLS.h:94
unsigned long GetSize() const
Chunk size in bytes (without header, thus the chunk data body)
Definition: RIFF.h:190
uint32_t Channel
Definition: DLS.h:438
uint32_t WavePoolHeaderSize
Definition: DLS.h:527
#define CHUNK_ID_ICOP
Definition: RIFF.h:99
RIFF::File * pRIFF
Definition: DLS.h:521
Abstract base class which encapsulates data structures which all DLS resources are able to provide...
Definition: DLS.h:344
RIFF File.
Definition: RIFF.h:328
void Init(conn_block_t *Header)
Definition: DLS.cpp:75
List * AddSubList(uint32_t uiListType)
Creates a new list sub chunk.
Definition: RIFF.cpp:1257
InstrumentList * pInstruments
Definition: DLS.h:525
uint16_t build
Definition: DLS.h:112
virtual void LoadInstruments()
Definition: DLS.cpp:1582
virtual void UpdateChunks()
Apply sample and its settings to the respective RIFF chunks.
Definition: DLS.cpp:957
RIFF specific classes and definitions.
Definition: RIFF.h:134
String Software
<ISFT-ck>. Identifies the name of the sofware package used to create the file.
Definition: DLS.h:317
virtual void UpdateChunks()
Update chunks with current Resource data.
Definition: DLS.cpp:468
#define CONN_TRANSFORM_CTL_ENCODE(x)
Definition: DLS.cpp:48
String ArchivalLocation
<IARL-ck>. Indicates where the subject of the file is stored.
Definition: DLS.h:307
unsigned long ulWavePoolOffset
Definition: DLS.h:418
virtual void Save()
Save changes to same file.
Definition: DLS.cpp:1758
uint16_t release
Definition: DLS.h:113
Encapsulates sample waves used for playback.
Definition: DLS.h:394
Sample * GetNextSample()
Returns a pointer to the next Sample object of the file, NULL otherwise.
Definition: DLS.cpp:1500
void MoveSubChunk(Chunk *pSrc, Chunk *pDst)
Moves a sub chunk witin this list.
Definition: RIFF.cpp:1209
String Name
<INAM-ck>. Stores the title of the subject of the file, such as, Seattle From Above.
Definition: DLS.h:306
uint32_t SamplesPerSecond
Sampling rate at which each channel should be played (defaults to 44100 if Sample was created with In...
Definition: DLS.h:398
String Product
<IPRD-ck>. Specifies the name of the title the file was originally intended for, such as World Ruler ...
Definition: DLS.h:310
Sample(File *pFile, RIFF::List *waveList, unsigned long WavePoolOffset)
Constructor.
Definition: DLS.cpp:704
uint32_t WavePoolCount
Definition: DLS.h:528
String GetFileName()
File name of this DLS file.
Definition: DLS.cpp:1657
String Medium
<IMED-ck>. Describes the original subject of the file, such as, record, CD, and so forth...
Definition: DLS.h:318
String Subject
<ISBJ-ck>. Describes the contents of the file.
Definition: DLS.h:322
void LoadArticulations()
Definition: DLS.cpp:187
RIFF::List * pWaveList
Definition: DLS.h:415
virtual void LoadRegions()
Definition: DLS.cpp:1244
virtual void Save()
Save changes to same file.
Definition: RIFF.cpp:1750
unsigned long ReadUint16(uint16_t *pData, unsigned long WordCount=1)
Reads WordCount number of 16 Bit unsigned integer words and copies it into the buffer pointed by pDat...
Definition: RIFF.cpp:520
void CopyAssignCore(const Sample *orig)
Make a deep copy of the Sample object given by orig (without the actual sample waveform data however)...
Definition: DLS.cpp:759
conn_block_t ToConnBlock()
Definition: DLS.cpp:89
virtual ~Sampler()
Definition: DLS.cpp:574
#define LIST_TYPE_LINS
Definition: DLS.h:68
Resource * GetParent()
Definition: DLS.h:349
#define CHUNK_ID_IARL
Definition: DLS.h:75
void ReleaseChunkData()
Free loaded chunk body from RAM.
Definition: RIFF.cpp:801
void DeleteRegion(Region *pRegion)
Definition: DLS.cpp:1279
Abstract base class for classes that provide articulation information (thus for Instrument and Region...
Definition: DLS.h:286
Sample * pSample
Definition: DLS.h:448
#define LIST_TYPE_INFO
Definition: RIFF.h:97
conn_trn_t ControlTransform
Definition: DLS.h:250
range_t KeyRange
Definition: DLS.h:430
#define CHUNK_ID_ISRC
Definition: DLS.h:82
Provides access to the defined connections used for the synthesis model.
Definition: DLS.h:272
#define CONN_TRANSFORM_INVERT_CTL(x)
Definition: DLS.cpp:44
uint32_t Instruments
Reflects the number of available Instrument objects.
Definition: DLS.h:498
String Genre
<IGNR-ck>. Descirbes the original work, such as, Jazz, Classic, Rock, Techno, Rave, etc.
Definition: DLS.h:313
Provides all neccessary information for the synthesis of a DLS Instrument.
Definition: DLS.h:458
int32_t Gain
Definition: DLS.h:367
Quadtuple version number ("major.minor.release.build").
Definition: DLS.h:109
virtual void CopyAssign(const Resource *orig)
Make a deep copy of the Resource object given by orig and assign it to this object.
Definition: DLS.cpp:534
String Copyright
<ICOP-ck>. Records the copyright information for the file.
Definition: DLS.h:311
Sample * AddSample()
Add a new sample.
Definition: DLS.cpp:1543
void CopyAssignCore(const Instrument *orig)
Definition: DLS.cpp:1341
DLS specific classes and definitions.
Definition: DLS.h:104
Info * pInfo
Points (in any case) to an Info object, providing additional, optional infos and comments.
Definition: DLS.h:346
String libraryVersion()
Returns version of this C++ library.
Definition: DLS.cpp:1907
virtual void UpdateChunks()
Apply all sample player options to the respective RIFF chunk.
Definition: DLS.cpp:586
Defines a connection within the synthesis model.
Definition: DLS.h:243
uint16_t FormatOptionFlags
Definition: DLS.h:449
uint32_t * pWavePoolTableHi
Definition: DLS.h:530
String Comments
<ICMT-ck>. Provides general comments about the file or the subject of the file. Sentences might end w...
Definition: DLS.h:309
void Resize(int iNewSize)
Resize chunk.
Definition: RIFF.cpp:826
Articulator(RIFF::List *ParentList)
Definition: DLS.cpp:169
List * GetNextSubList()
Returns the next sublist (that is a subchunk with chunk ID "LIST") within the list.
Definition: RIFF.cpp:1106
Defines Region information of an Instrument.
Definition: DLS.h:428
std::list< RIFF::File * > ExtensionFiles
Definition: DLS.h:522
Articulation(RIFF::Chunk *artl)
Constructor.
Definition: DLS.cpp:118
bool IsDrum
Indicates if the Instrument is a drum type, as they differ in the synthesis model of DLS from melodic...
Definition: DLS.h:460
std::list< Region * > RegionList
Definition: DLS.h:474
void * LoadSampleData()
Load sample data into RAM.
Definition: DLS.cpp:825
void AddSampleLoop(sample_loop_t *pLoopDef)
Adds a new sample loop with the provided loop definition.
Definition: DLS.cpp:623
virtual void UpdateFileOffsets()
Updates all file offsets stored all over the file.
Definition: DLS.cpp:1774
Resource(Resource *Parent, RIFF::List *lstResource)
Constructor.
Definition: DLS.cpp:438