libgig  4.0.0.6svn2980
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-2016 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 
151  const int iEntrySize = 12; // 12 bytes per connection block
152  pArticulationCk->Resize(HeaderSize + Connections * iEntrySize);
153  uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData();
154  store16(&pData[0], HeaderSize);
155  store16(&pData[2], Connections);
156  for (uint32_t i = 0; i < Connections; i++) {
157  Connection::conn_block_t c = pConnections[i].ToConnBlock();
158  store16(&pData[HeaderSize + i * iEntrySize], c.source);
159  store16(&pData[HeaderSize + i * iEntrySize + 2], c.control);
160  store16(&pData[HeaderSize + i * iEntrySize + 4], c.destination);
161  store16(&pData[HeaderSize + i * iEntrySize + 6], c.transform);
162  store32(&pData[HeaderSize + i * iEntrySize + 8], c.scale);
163  }
164  }
165 
166 
167 
168 // *************** Articulator ***************
169 // *
170 
172  pParentList = ParentList;
173  pArticulations = NULL;
174  }
175 
177  if (!pArticulations) LoadArticulations();
178  if (!pArticulations) return NULL;
179  ArticulationsIterator = pArticulations->begin();
180  return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
181  }
182 
184  if (!pArticulations) return NULL;
185  ArticulationsIterator++;
186  return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
187  }
188 
190  // prefer articulation level 2
191  RIFF::List* lart = pParentList->GetSubList(LIST_TYPE_LAR2);
192  if (!lart) lart = pParentList->GetSubList(LIST_TYPE_LART);
193  if (lart) {
194  uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2
195  : CHUNK_ID_ARTL;
196  RIFF::Chunk* art = lart->GetFirstSubChunk();
197  while (art) {
198  if (art->GetChunkID() == artCkType) {
199  if (!pArticulations) pArticulations = new ArticulationList;
200  pArticulations->push_back(new Articulation(art));
201  }
202  art = lart->GetNextSubChunk();
203  }
204  }
205  }
206 
208  if (pArticulations) {
209  ArticulationList::iterator iter = pArticulations->begin();
210  ArticulationList::iterator end = pArticulations->end();
211  while (iter != end) {
212  delete *iter;
213  iter++;
214  }
215  delete pArticulations;
216  }
217  }
218 
226  if (pArticulations) {
227  ArticulationList::iterator iter = pArticulations->begin();
228  ArticulationList::iterator end = pArticulations->end();
229  for (; iter != end; ++iter) {
230  (*iter)->UpdateChunks(pProgress);
231  }
232  }
233  }
234 
241  //TODO: implement deep copy assignment for this class
242  }
243 
244 
245 
246 // *************** Info ***************
247 // *
248 
256  pFixedStringLengths = NULL;
257  pResourceListChunk = list;
258  if (list) {
259  RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO);
260  if (lstINFO) {
261  LoadString(CHUNK_ID_INAM, lstINFO, Name);
262  LoadString(CHUNK_ID_IARL, lstINFO, ArchivalLocation);
263  LoadString(CHUNK_ID_ICRD, lstINFO, CreationDate);
264  LoadString(CHUNK_ID_ICMT, lstINFO, Comments);
265  LoadString(CHUNK_ID_IPRD, lstINFO, Product);
266  LoadString(CHUNK_ID_ICOP, lstINFO, Copyright);
267  LoadString(CHUNK_ID_IART, lstINFO, Artists);
268  LoadString(CHUNK_ID_IGNR, lstINFO, Genre);
269  LoadString(CHUNK_ID_IKEY, lstINFO, Keywords);
270  LoadString(CHUNK_ID_IENG, lstINFO, Engineer);
271  LoadString(CHUNK_ID_ITCH, lstINFO, Technician);
272  LoadString(CHUNK_ID_ISFT, lstINFO, Software);
273  LoadString(CHUNK_ID_IMED, lstINFO, Medium);
274  LoadString(CHUNK_ID_ISRC, lstINFO, Source);
275  LoadString(CHUNK_ID_ISRF, lstINFO, SourceForm);
276  LoadString(CHUNK_ID_ICMS, lstINFO, Commissioned);
277  LoadString(CHUNK_ID_ISBJ, lstINFO, Subject);
278  }
279  }
280  }
281 
283  }
284 
297  pFixedStringLengths = lengths;
298  }
299 
305  void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
306  RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
307  ::LoadString(ck, s); // function from helper.h
308  }
309 
325  void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) {
326  int size = 0;
327  if (pFixedStringLengths) {
328  for (int i = 0 ; pFixedStringLengths[i].length ; i++) {
329  if (pFixedStringLengths[i].chunkId == ChunkID) {
330  size = pFixedStringLengths[i].length;
331  break;
332  }
333  }
334  }
335  RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
336  ::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size); // function from helper.h
337  }
338 
346  void Info::UpdateChunks(progress_t* pProgress) {
347  if (!pResourceListChunk) return;
348 
349  // make sure INFO list chunk exists
350  RIFF::List* lstINFO = pResourceListChunk->GetSubList(LIST_TYPE_INFO);
351 
352  String defaultName = "";
353  String defaultCreationDate = "";
354  String defaultSoftware = "";
355  String defaultComments = "";
356 
357  uint32_t resourceType = pResourceListChunk->GetListType();
358 
359  if (!lstINFO) {
360  lstINFO = pResourceListChunk->AddSubList(LIST_TYPE_INFO);
361 
362  // assemble default values
363  defaultName = "NONAME";
364 
365  if (resourceType == RIFF_TYPE_DLS) {
366  // get current date
367  time_t now = time(NULL);
368  tm* pNowBroken = localtime(&now);
369  char buf[11];
370  strftime(buf, 11, "%F", pNowBroken);
371  defaultCreationDate = buf;
372 
373  defaultComments = "Created with " + libraryName() + " " + libraryVersion();
374  }
375  if (resourceType == RIFF_TYPE_DLS || resourceType == LIST_TYPE_INS)
376  {
377  defaultSoftware = libraryName() + " " + libraryVersion();
378  }
379  }
380 
381  // save values
382 
383  SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""));
384  SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""));
385  SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""));
386  SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments);
387  SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""));
388  SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate);
389  SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""));
390  SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""));
391  SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""));
392  SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""));
393  SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName);
394  SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""));
395  SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String(""));
396  SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware);
397  SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""));
398  SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""));
399  SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""));
400  }
401 
408  void Info::CopyAssign(const Info* orig) {
409  Name = orig->Name;
410  ArchivalLocation = orig->ArchivalLocation;
411  CreationDate = orig->CreationDate;
412  Comments = orig->Comments;
413  Product = orig->Product;
414  Copyright = orig->Copyright;
415  Artists = orig->Artists;
416  Genre = orig->Genre;
417  Keywords = orig->Keywords;
418  Engineer = orig->Engineer;
419  Technician = orig->Technician;
420  Software = orig->Software;
421  Medium = orig->Medium;
422  Source = orig->Source;
423  SourceForm = orig->SourceForm;
424  Commissioned = orig->Commissioned;
425  Subject = orig->Subject;
426  //FIXME: hmm, is copying this pointer a good idea?
427  pFixedStringLengths = orig->pFixedStringLengths;
428  }
429 
430 
431 
432 // *************** Resource ***************
433 // *
434 
444  Resource::Resource(Resource* Parent, RIFF::List* lstResource) {
445  pParent = Parent;
446  pResourceList = lstResource;
447 
448  pInfo = new Info(lstResource);
449 
450  RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);
451  if (ckDLSID) {
452  pDLSID = new dlsid_t;
453  ckDLSID->Read(&pDLSID->ulData1, 1, 4);
454  ckDLSID->Read(&pDLSID->usData2, 1, 2);
455  ckDLSID->Read(&pDLSID->usData3, 1, 2);
456  ckDLSID->Read(pDLSID->abData, 8, 1);
457  }
458  else pDLSID = NULL;
459  }
460 
462  if (pDLSID) delete pDLSID;
463  if (pInfo) delete pInfo;
464  }
465 
477  pInfo->UpdateChunks(pProgress);
478 
479  if (pDLSID) {
480  // make sure 'dlid' chunk exists
481  RIFF::Chunk* ckDLSID = pResourceList->GetSubChunk(CHUNK_ID_DLID);
482  if (!ckDLSID) ckDLSID = pResourceList->AddSubChunk(CHUNK_ID_DLID, 16);
483  uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
484  // update 'dlid' chunk
485  store32(&pData[0], pDLSID->ulData1);
486  store16(&pData[4], pDLSID->usData2);
487  store16(&pData[6], pDLSID->usData3);
488  memcpy(&pData[8], pDLSID->abData, 8);
489  }
490  }
491 
496 #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
497 
498  if (!pDLSID) pDLSID = new dlsid_t;
499 
500 #ifdef WIN32
501 
502  UUID uuid;
503  UuidCreate(&uuid);
504  pDLSID->ulData1 = uuid.Data1;
505  pDLSID->usData2 = uuid.Data2;
506  pDLSID->usData3 = uuid.Data3;
507  memcpy(pDLSID->abData, uuid.Data4, 8);
508 
509 #elif defined(__APPLE__)
510 
511  CFUUIDRef uuidRef = CFUUIDCreate(NULL);
512  CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
513  CFRelease(uuidRef);
514  pDLSID->ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
515  pDLSID->usData2 = uuid.byte4 | uuid.byte5 << 8;
516  pDLSID->usData3 = uuid.byte6 | uuid.byte7 << 8;
517  pDLSID->abData[0] = uuid.byte8;
518  pDLSID->abData[1] = uuid.byte9;
519  pDLSID->abData[2] = uuid.byte10;
520  pDLSID->abData[3] = uuid.byte11;
521  pDLSID->abData[4] = uuid.byte12;
522  pDLSID->abData[5] = uuid.byte13;
523  pDLSID->abData[6] = uuid.byte14;
524  pDLSID->abData[7] = uuid.byte15;
525 #else
526  uuid_t uuid;
527  uuid_generate(uuid);
528  pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
529  pDLSID->usData2 = uuid[4] | uuid[5] << 8;
530  pDLSID->usData3 = uuid[6] | uuid[7] << 8;
531  memcpy(pDLSID->abData, &uuid[8], 8);
532 #endif
533 #endif
534  }
535 
542  void Resource::CopyAssign(const Resource* orig) {
543  pInfo->CopyAssign(orig->pInfo);
544  }
545 
546 
547 // *************** Sampler ***************
548 // *
549 
551  pParentList = ParentList;
552  RIFF::Chunk* wsmp = ParentList->GetSubChunk(CHUNK_ID_WSMP);
553  if (wsmp) {
554  uiHeaderSize = wsmp->ReadUint32();
555  UnityNote = wsmp->ReadUint16();
556  FineTune = wsmp->ReadInt16();
557  Gain = wsmp->ReadInt32();
558  SamplerOptions = wsmp->ReadUint32();
559  SampleLoops = wsmp->ReadUint32();
560  } else { // 'wsmp' chunk missing
561  uiHeaderSize = 20;
562  UnityNote = 60;
563  FineTune = 0; // +- 0 cents
564  Gain = 0; // 0 dB
565  SamplerOptions = F_WSMP_NO_COMPRESSION;
566  SampleLoops = 0;
567  }
568  NoSampleDepthTruncation = SamplerOptions & F_WSMP_NO_TRUNCATION;
569  NoSampleCompression = SamplerOptions & F_WSMP_NO_COMPRESSION;
570  pSampleLoops = (SampleLoops) ? new sample_loop_t[SampleLoops] : NULL;
571  if (SampleLoops) {
572  wsmp->SetPos(uiHeaderSize);
573  for (uint32_t i = 0; i < SampleLoops; i++) {
574  wsmp->Read(pSampleLoops + i, 4, 4);
575  if (pSampleLoops[i].Size > sizeof(sample_loop_t)) { // if loop struct was extended
576  wsmp->SetPos(pSampleLoops[i].Size - sizeof(sample_loop_t), RIFF::stream_curpos);
577  }
578  }
579  }
580  }
581 
583  if (pSampleLoops) delete[] pSampleLoops;
584  }
585 
586  void Sampler::SetGain(int32_t gain) {
587  Gain = gain;
588  }
589 
597  // make sure 'wsmp' chunk exists
598  RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);
599  int wsmpSize = uiHeaderSize + SampleLoops * 16;
600  if (!wsmp) {
601  wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize);
602  } else if (wsmp->GetSize() != wsmpSize) {
603  wsmp->Resize(wsmpSize);
604  }
605  uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
606  // update headers size
607  store32(&pData[0], uiHeaderSize);
608  // update respective sampler options bits
609  SamplerOptions = (NoSampleDepthTruncation) ? SamplerOptions | F_WSMP_NO_TRUNCATION
610  : SamplerOptions & (~F_WSMP_NO_TRUNCATION);
611  SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION
612  : SamplerOptions & (~F_WSMP_NO_COMPRESSION);
613  store16(&pData[4], UnityNote);
614  store16(&pData[6], FineTune);
615  store32(&pData[8], Gain);
616  store32(&pData[12], SamplerOptions);
617  store32(&pData[16], SampleLoops);
618  // update loop definitions
619  for (uint32_t i = 0; i < SampleLoops; i++) {
620  //FIXME: this does not handle extended loop structs correctly
621  store32(&pData[uiHeaderSize + i * 16], pSampleLoops[i].Size);
622  store32(&pData[uiHeaderSize + i * 16 + 4], pSampleLoops[i].LoopType);
623  store32(&pData[uiHeaderSize + i * 16 + 8], pSampleLoops[i].LoopStart);
624  store32(&pData[uiHeaderSize + i * 16 + 12], pSampleLoops[i].LoopLength);
625  }
626  }
627 
634  sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1];
635  // copy old loops array
636  for (int i = 0; i < SampleLoops; i++) {
637  pNewLoops[i] = pSampleLoops[i];
638  }
639  // add the new loop
640  pNewLoops[SampleLoops] = *pLoopDef;
641  // auto correct size field
642  pNewLoops[SampleLoops].Size = sizeof(DLS::sample_loop_t);
643  // free the old array and update the member variables
644  if (SampleLoops) delete[] pSampleLoops;
645  pSampleLoops = pNewLoops;
646  SampleLoops++;
647  }
648 
656  sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops - 1];
657  // copy old loops array (skipping given loop)
658  for (int i = 0, o = 0; i < SampleLoops; i++) {
659  if (&pSampleLoops[i] == pLoopDef) continue;
660  if (o == SampleLoops - 1) {
661  delete[] pNewLoops;
662  throw Exception("Could not delete Sample Loop, because it does not exist");
663  }
664  pNewLoops[o] = pSampleLoops[i];
665  o++;
666  }
667  // free the old array and update the member variables
668  if (SampleLoops) delete[] pSampleLoops;
669  pSampleLoops = pNewLoops;
670  SampleLoops--;
671  }
672 
679  void Sampler::CopyAssign(const Sampler* orig) {
680  // copy trivial scalars
681  UnityNote = orig->UnityNote;
682  FineTune = orig->FineTune;
683  Gain = orig->Gain;
684  NoSampleDepthTruncation = orig->NoSampleDepthTruncation;
685  NoSampleCompression = orig->NoSampleCompression;
686  SamplerOptions = orig->SamplerOptions;
687 
688  // copy sample loops
689  if (SampleLoops) delete[] pSampleLoops;
690  pSampleLoops = new sample_loop_t[orig->SampleLoops];
691  memcpy(pSampleLoops, orig->pSampleLoops, orig->SampleLoops * sizeof(sample_loop_t));
692  SampleLoops = orig->SampleLoops;
693  }
694 
695 
696 // *************** Sample ***************
697 // *
698 
714  Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset) : Resource(pFile, waveList) {
715  pWaveList = waveList;
716  ullWavePoolOffset = WavePoolOffset - LIST_HEADER_SIZE(waveList->GetFile()->GetFileOffsetSize());
717  pCkFormat = waveList->GetSubChunk(CHUNK_ID_FMT);
718  pCkData = waveList->GetSubChunk(CHUNK_ID_DATA);
719  if (pCkFormat) {
720  // common fields
721  FormatTag = pCkFormat->ReadUint16();
722  Channels = pCkFormat->ReadUint16();
723  SamplesPerSecond = pCkFormat->ReadUint32();
724  AverageBytesPerSecond = pCkFormat->ReadUint32();
725  BlockAlign = pCkFormat->ReadUint16();
726  // PCM format specific
728  BitDepth = pCkFormat->ReadUint16();
729  FrameSize = (BitDepth / 8) * Channels;
730  } else { // unsupported sample data format
731  BitDepth = 0;
732  FrameSize = 0;
733  }
734  } else { // 'fmt' chunk missing
736  BitDepth = 16;
737  Channels = 1;
738  SamplesPerSecond = 44100;
740  FrameSize = (BitDepth / 8) * Channels;
742  }
744  : 0
745  : 0;
746  }
747 
755  pParent->DeleteSubChunk(pWaveList);
756  }
757 
769  void Sample::CopyAssignCore(const Sample* orig) {
770  // handle base classes
771  Resource::CopyAssign(orig);
772  // handle actual own attributes of this class
773  FormatTag = orig->FormatTag;
774  Channels = orig->Channels;
777  BlockAlign = orig->BlockAlign;
778  BitDepth = orig->BitDepth;
779  SamplesTotal = orig->SamplesTotal;
780  FrameSize = orig->FrameSize;
781  }
782 
789  void Sample::CopyAssign(const Sample* orig) {
790  CopyAssignCore(orig);
791 
792  // copy sample waveform data (reading directly from disc)
793  Resize(orig->GetSize());
794  char* buf = (char*) LoadSampleData();
795  Sample* pOrig = (Sample*) orig; //HACK: circumventing the constness here for now
796  const file_offset_t restorePos = pOrig->pCkData->GetPos();
797  pOrig->SetPos(0);
798  for (file_offset_t todo = pOrig->GetSize(), i = 0; todo; ) {
799  const int iReadAtOnce = 64*1024;
800  file_offset_t n = (iReadAtOnce < todo) ? iReadAtOnce : todo;
801  n = pOrig->Read(&buf[i], n);
802  if (!n) break;
803  todo -= n;
804  i += (n * pOrig->FrameSize);
805  }
806  pOrig->pCkData->SetPos(restorePos);
807  }
808 
836  return (pCkData) ? pCkData->LoadChunkData() : NULL;
837  }
838 
846  }
847 
859  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0;
860  return (pCkData) ? pCkData->GetSize() / FrameSize : 0;
861  }
862 
892  if (FormatTag != DLS_WAVE_FORMAT_PCM) throw Exception("Sample's format is not DLS_WAVE_FORMAT_PCM");
893  if (NewSize < 1) throw Exception("Sample size must be at least one sample point");
894  if ((NewSize >> 48) != 0)
895  throw Exception("Unrealistic high DLS sample size detected");
896  const file_offset_t sizeInBytes = NewSize * FrameSize;
898  if (pCkData) pCkData->Resize(sizeInBytes);
899  else pCkData = pWaveList->AddSubChunk(CHUNK_ID_DATA, sizeInBytes);
900  }
901 
919  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
920  if (!pCkData) throw Exception("No data chunk created for sample yet, call Sample::Resize() to create one");
921  file_offset_t orderedBytes = SampleCount * FrameSize;
922  file_offset_t result = pCkData->SetPos(orderedBytes, Whence);
923  return (result == orderedBytes) ? SampleCount
924  : result / FrameSize;
925  }
926 
936  file_offset_t Sample::Read(void* pBuffer, file_offset_t SampleCount) {
937  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
938  return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
939  }
940 
956  file_offset_t Sample::Write(void* pBuffer, file_offset_t SampleCount) {
957  if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
958  if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small");
959  return pCkData->Write(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
960  }
961 
970  void Sample::UpdateChunks(progress_t* pProgress) {
972  throw Exception("Could not save sample, only PCM format is supported");
973  // we refuse to do anything if not sample wave form was provided yet
974  if (!pCkData)
975  throw Exception("Could not save sample, there is no sample data to save");
976  // update chunks of base class as well
977  Resource::UpdateChunks(pProgress);
978  // make sure 'fmt' chunk exists
980  if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format
981  uint8_t* pData = (uint8_t*) pCkFormat->LoadChunkData();
982  // update 'fmt' chunk
983  store16(&pData[0], FormatTag);
984  store16(&pData[2], Channels);
985  store32(&pData[4], SamplesPerSecond);
986  store32(&pData[8], AverageBytesPerSecond);
987  store16(&pData[12], BlockAlign);
988  store16(&pData[14], BitDepth); // assuming PCM format
989  }
990 
991 
992 
993 // *************** Region ***************
994 // *
995 
996  Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : Resource(pInstrument, rgnList), Articulator(rgnList), Sampler(rgnList) {
997  pCkRegion = rgnList;
998 
999  // articulation informations
1000  RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);
1001  if (rgnh) {
1002  rgnh->Read(&KeyRange, 2, 2);
1003  rgnh->Read(&VelocityRange, 2, 2);
1004  FormatOptionFlags = rgnh->ReadUint16();
1005  KeyGroup = rgnh->ReadUint16();
1006  // Layer is optional
1007  if (rgnh->RemainingBytes() >= sizeof(uint16_t)) {
1008  rgnh->Read(&Layer, 1, sizeof(uint16_t));
1009  } else Layer = 0;
1010  } else { // 'rgnh' chunk is missing
1011  KeyRange.low = 0;
1012  KeyRange.high = 127;
1013  VelocityRange.low = 0;
1014  VelocityRange.high = 127;
1016  KeyGroup = 0;
1017  Layer = 0;
1018  }
1020 
1021  // sample informations
1022  RIFF::Chunk* wlnk = rgnList->GetSubChunk(CHUNK_ID_WLNK);
1023  if (wlnk) {
1024  WaveLinkOptionFlags = wlnk->ReadUint16();
1025  PhaseGroup = wlnk->ReadUint16();
1026  Channel = wlnk->ReadUint32();
1027  WavePoolTableIndex = wlnk->ReadUint32();
1028  } else { // 'wlnk' chunk is missing
1029  WaveLinkOptionFlags = 0;
1030  PhaseGroup = 0;
1031  Channel = 0; // mono
1032  WavePoolTableIndex = 0; // first entry in wave pool table
1033  }
1036 
1037  pSample = NULL;
1038  }
1039 
1046  pParent->DeleteSubChunk(pCkRegion);
1047  }
1048 
1050  if (pSample) return pSample;
1051  File* file = (File*) GetParent()->GetParent();
1052  uint64_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1053  Sample* sample = file->GetFirstSample();
1054  while (sample) {
1055  if (sample->ullWavePoolOffset == soughtoffset) return (pSample = sample);
1056  sample = file->GetNextSample();
1057  }
1058  return NULL;
1059  }
1060 
1067  this->pSample = pSample;
1068  WavePoolTableIndex = 0; // we update this offset when we Save()
1069  }
1070 
1078  void Region::SetKeyRange(uint16_t Low, uint16_t High) {
1079  KeyRange.low = Low;
1080  KeyRange.high = High;
1081 
1082  // make sure regions are already loaded
1083  Instrument* pInstrument = (Instrument*) GetParent();
1084  if (!pInstrument->pRegions) pInstrument->LoadRegions();
1085  if (!pInstrument->pRegions) return;
1086 
1087  // find the r which is the first one to the right of this region
1088  // at its new position
1089  Region* r = NULL;
1090  Region* prev_region = NULL;
1091  for (
1092  Instrument::RegionList::iterator iter = pInstrument->pRegions->begin();
1093  iter != pInstrument->pRegions->end(); iter++
1094  ) {
1095  if ((*iter)->KeyRange.low > this->KeyRange.low) {
1096  r = *iter;
1097  break;
1098  }
1099  prev_region = *iter;
1100  }
1101 
1102  // place this region before r if it's not already there
1103  if (prev_region != this) pInstrument->MoveRegion(this, r);
1104  }
1105 
1114  // make sure 'rgnh' chunk exists
1116  if (!rgnh) rgnh = pCkRegion->AddSubChunk(CHUNK_ID_RGNH, Layer ? 14 : 12);
1117  uint8_t* pData = (uint8_t*) rgnh->LoadChunkData();
1121  // update 'rgnh' chunk
1122  store16(&pData[0], KeyRange.low);
1123  store16(&pData[2], KeyRange.high);
1124  store16(&pData[4], VelocityRange.low);
1125  store16(&pData[6], VelocityRange.high);
1126  store16(&pData[8], FormatOptionFlags);
1127  store16(&pData[10], KeyGroup);
1128  if (rgnh->GetSize() >= 14) store16(&pData[12], Layer);
1129 
1130  // update chunks of base classes as well (but skip Resource,
1131  // as a rgn doesn't seem to have dlid and INFO chunks)
1132  Articulator::UpdateChunks(pProgress);
1133  Sampler::UpdateChunks(pProgress);
1134 
1135  // make sure 'wlnk' chunk exists
1137  if (!wlnk) wlnk = pCkRegion->AddSubChunk(CHUNK_ID_WLNK, 12);
1138  pData = (uint8_t*) wlnk->LoadChunkData();
1145  // get sample's wave pool table index
1146  int index = -1;
1147  File* pFile = (File*) GetParent()->GetParent();
1148  if (pFile->pSamples) {
1149  File::SampleList::iterator iter = pFile->pSamples->begin();
1150  File::SampleList::iterator end = pFile->pSamples->end();
1151  for (int i = 0; iter != end; ++iter, i++) {
1152  if (*iter == pSample) {
1153  index = i;
1154  break;
1155  }
1156  }
1157  }
1158  WavePoolTableIndex = index;
1159  // update 'wlnk' chunk
1160  store16(&pData[0], WaveLinkOptionFlags);
1161  store16(&pData[2], PhaseGroup);
1162  store32(&pData[4], Channel);
1163  store32(&pData[8], WavePoolTableIndex);
1164  }
1165 
1175  void Region::CopyAssign(const Region* orig) {
1176  // handle base classes
1177  Resource::CopyAssign(orig);
1179  Sampler::CopyAssign(orig);
1180  // handle actual own attributes of this class
1181  // (the trivial ones)
1182  VelocityRange = orig->VelocityRange;
1183  KeyGroup = orig->KeyGroup;
1184  Layer = orig->Layer;
1186  PhaseMaster = orig->PhaseMaster;
1187  PhaseGroup = orig->PhaseGroup;
1188  MultiChannel = orig->MultiChannel;
1189  Channel = orig->Channel;
1190  // only take the raw sample reference if the two Region objects are
1191  // part of the same file
1192  if (GetParent()->GetParent() == orig->GetParent()->GetParent()) {
1194  pSample = orig->pSample;
1195  } else {
1196  WavePoolTableIndex = -1;
1197  pSample = NULL;
1198  }
1201  // handle the last, a bit sensible attribute
1202  SetKeyRange(orig->KeyRange.low, orig->KeyRange.high);
1203  }
1204 
1205 
1206 // *************** Instrument ***************
1207 // *
1208 
1222  Instrument::Instrument(File* pFile, RIFF::List* insList) : Resource(pFile, insList), Articulator(insList) {
1223  pCkInstrument = insList;
1224 
1225  midi_locale_t locale;
1227  if (insh) {
1228  Regions = insh->ReadUint32();
1229  insh->Read(&locale, 2, 4);
1230  } else { // 'insh' chunk missing
1231  Regions = 0;
1232  locale.bank = 0;
1233  locale.instrument = 0;
1234  }
1235 
1236  MIDIProgram = locale.instrument;
1237  IsDrum = locale.bank & DRUM_TYPE_MASK;
1238  MIDIBankCoarse = (uint8_t) MIDI_BANK_COARSE(locale.bank);
1239  MIDIBankFine = (uint8_t) MIDI_BANK_FINE(locale.bank);
1241 
1242  pRegions = NULL;
1243  }
1244 
1246  if (!pRegions) LoadRegions();
1247  if (!pRegions) return NULL;
1248  RegionsIterator = pRegions->begin();
1249  return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1250  }
1251 
1253  if (!pRegions) return NULL;
1254  RegionsIterator++;
1255  return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
1256  }
1257 
1259  if (!pRegions) pRegions = new RegionList;
1261  if (lrgn) {
1262  uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2
1263  RIFF::List* rgn = lrgn->GetFirstSubList();
1264  while (rgn) {
1265  if (rgn->GetListType() == regionCkType) {
1266  pRegions->push_back(new Region(this, rgn));
1267  }
1268  rgn = lrgn->GetNextSubList();
1269  }
1270  }
1271  }
1272 
1274  if (!pRegions) LoadRegions();
1276  if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);
1277  RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
1278  Region* pNewRegion = new Region(this, rgn);
1279  pRegions->push_back(pNewRegion);
1280  Regions = pRegions->size();
1281  return pNewRegion;
1282  }
1283 
1284  void Instrument::MoveRegion(Region* pSrc, Region* pDst) {
1286  lrgn->MoveSubChunk(pSrc->pCkRegion, (RIFF::Chunk*) (pDst ? pDst->pCkRegion : 0));
1287 
1288  pRegions->remove(pSrc);
1289  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);
1290  pRegions->insert(iter, pSrc);
1291  }
1292 
1294  if (!pRegions) return;
1295  RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
1296  if (iter == pRegions->end()) return;
1297  pRegions->erase(iter);
1298  Regions = pRegions->size();
1299  delete pRegion;
1300  }
1301 
1310  // first update base classes' chunks
1311  Resource::UpdateChunks(pProgress);
1312  Articulator::UpdateChunks(pProgress);
1313  // make sure 'insh' chunk exists
1315  if (!insh) insh = pCkInstrument->AddSubChunk(CHUNK_ID_INSH, 12);
1316  uint8_t* pData = (uint8_t*) insh->LoadChunkData();
1317  // update 'insh' chunk
1318  Regions = (pRegions) ? pRegions->size() : 0;
1319  midi_locale_t locale;
1320  locale.instrument = MIDIProgram;
1322  locale.bank = (IsDrum) ? locale.bank | DRUM_TYPE_MASK : locale.bank & (~DRUM_TYPE_MASK);
1323  MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine); // just a sync, when we're at it
1324  store32(&pData[0], Regions);
1325  store32(&pData[4], locale.bank);
1326  store32(&pData[8], locale.instrument);
1327  // update Region's chunks
1328  if (!pRegions) return;
1329  RegionList::iterator iter = pRegions->begin();
1330  RegionList::iterator end = pRegions->end();
1331  for (int i = 0; iter != end; ++iter, ++i) {
1332  // divide local progress into subprogress
1333  progress_t subprogress;
1334  __divide_progress(pProgress, &subprogress, pRegions->size(), i);
1335  // do the actual work
1336  (*iter)->UpdateChunks(&subprogress);
1337  }
1338  __notify_progress(pProgress, 1.0); // notify done
1339  }
1340 
1347  if (pRegions) {
1348  RegionList::iterator iter = pRegions->begin();
1349  RegionList::iterator end = pRegions->end();
1350  while (iter != end) {
1351  delete *iter;
1352  iter++;
1353  }
1354  delete pRegions;
1355  }
1356  // remove instrument's chunks
1358  pParent->DeleteSubChunk(pCkInstrument);
1359  }
1360 
1362  // handle base classes
1363  Resource::CopyAssign(orig);
1365  // handle actual own attributes of this class
1366  // (the trivial ones)
1367  IsDrum = orig->IsDrum;
1368  MIDIBank = orig->MIDIBank;
1370  MIDIBankFine = orig->MIDIBankFine;
1371  MIDIProgram = orig->MIDIProgram;
1372  }
1373 
1384  CopyAssignCore(orig);
1385  // delete all regions first
1386  while (Regions) DeleteRegion(GetFirstRegion());
1387  // now recreate and copy regions
1388  {
1389  RegionList::const_iterator it = orig->pRegions->begin();
1390  for (int i = 0; i < orig->Regions; ++i, ++it) {
1391  Region* dstRgn = AddRegion();
1392  //NOTE: Region does semi-deep copy !
1393  dstRgn->CopyAssign(*it);
1394  }
1395  }
1396  }
1397 
1398 
1399 // *************** File ***************
1400 // *
1401 
1408  File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) {
1410  pVersion = new version_t;
1411  pVersion->major = 0;
1412  pVersion->minor = 0;
1413  pVersion->release = 0;
1414  pVersion->build = 0;
1415 
1416  Instruments = 0;
1417  WavePoolCount = 0;
1418  pWavePoolTable = NULL;
1419  pWavePoolTableHi = NULL;
1420  WavePoolHeaderSize = 8;
1421 
1422  pSamples = NULL;
1423  pInstruments = NULL;
1424 
1425  b64BitWavePoolOffsets = false;
1426  }
1427 
1438  if (!pRIFF) throw DLS::Exception("NULL pointer reference to RIFF::File object.");
1439  this->pRIFF = pRIFF;
1440 
1441  RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1442  if (ckVersion) {
1443  pVersion = new version_t;
1444  ckVersion->Read(pVersion, 4, 2);
1445  }
1446  else pVersion = NULL;
1447 
1448  RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
1449  if (!colh) throw DLS::Exception("Mandatory chunks in RIFF list chunk not found.");
1450  Instruments = colh->ReadUint32();
1451 
1452  RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
1453  if (!ptbl) { // pool table is missing - this is probably an ".art" file
1454  WavePoolCount = 0;
1455  pWavePoolTable = NULL;
1456  pWavePoolTableHi = NULL;
1457  WavePoolHeaderSize = 8;
1458  b64BitWavePoolOffsets = false;
1459  } else {
1460  WavePoolHeaderSize = ptbl->ReadUint32();
1461  WavePoolCount = ptbl->ReadUint32();
1462  pWavePoolTable = new uint32_t[WavePoolCount];
1463  pWavePoolTableHi = new uint32_t[WavePoolCount];
1464  ptbl->SetPos(WavePoolHeaderSize);
1465 
1466  // Check for 64 bit offsets (used in gig v3 files)
1468  if (b64BitWavePoolOffsets) {
1469  for (int i = 0 ; i < WavePoolCount ; i++) {
1470  pWavePoolTableHi[i] = ptbl->ReadUint32();
1471  pWavePoolTable[i] = ptbl->ReadUint32();
1472  //NOTE: disabled this 2GB check, not sure why this check was still left here (Christian, 2016-05-12)
1473  //if (pWavePoolTable[i] & 0x80000000)
1474  // throw DLS::Exception("Files larger than 2 GB not yet supported");
1475  }
1476  } else { // conventional 32 bit offsets
1477  ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
1478  for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;
1479  }
1480  }
1481 
1482  pSamples = NULL;
1483  pInstruments = NULL;
1484  }
1485 
1487  if (pInstruments) {
1488  InstrumentList::iterator iter = pInstruments->begin();
1489  InstrumentList::iterator end = pInstruments->end();
1490  while (iter != end) {
1491  delete *iter;
1492  iter++;
1493  }
1494  delete pInstruments;
1495  }
1496 
1497  if (pSamples) {
1498  SampleList::iterator iter = pSamples->begin();
1499  SampleList::iterator end = pSamples->end();
1500  while (iter != end) {
1501  delete *iter;
1502  iter++;
1503  }
1504  delete pSamples;
1505  }
1506 
1507  if (pWavePoolTable) delete[] pWavePoolTable;
1508  if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1509  if (pVersion) delete pVersion;
1510  for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1511  delete *i;
1512  }
1513 
1515  if (!pSamples) LoadSamples();
1516  if (!pSamples) return NULL;
1517  SamplesIterator = pSamples->begin();
1518  return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1519  }
1520 
1522  if (!pSamples) return NULL;
1523  SamplesIterator++;
1524  return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
1525  }
1526 
1528  if (!pSamples) pSamples = new SampleList;
1530  if (wvpl) {
1531  file_offset_t wvplFileOffset = wvpl->GetFilePos();
1532  RIFF::List* wave = wvpl->GetFirstSubList();
1533  while (wave) {
1534  if (wave->GetListType() == LIST_TYPE_WAVE) {
1535  file_offset_t waveFileOffset = wave->GetFilePos();
1536  pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
1537  }
1538  wave = wvpl->GetNextSubList();
1539  }
1540  }
1541  else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)
1543  if (dwpl) {
1544  file_offset_t dwplFileOffset = dwpl->GetFilePos();
1545  RIFF::List* wave = dwpl->GetFirstSubList();
1546  while (wave) {
1547  if (wave->GetListType() == LIST_TYPE_WAVE) {
1548  file_offset_t waveFileOffset = wave->GetFilePos();
1549  pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
1550  }
1551  wave = dwpl->GetNextSubList();
1552  }
1553  }
1554  }
1555  }
1556 
1565  if (!pSamples) LoadSamples();
1568  // create new Sample object and its respective 'wave' list chunk
1569  RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
1570  Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/);
1571  pSamples->push_back(pSample);
1572  return pSample;
1573  }
1574 
1582  void File::DeleteSample(Sample* pSample) {
1583  if (!pSamples) return;
1584  SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample);
1585  if (iter == pSamples->end()) return;
1586  pSamples->erase(iter);
1587  delete pSample;
1588  }
1589 
1591  if (!pInstruments) LoadInstruments();
1592  if (!pInstruments) return NULL;
1593  InstrumentsIterator = pInstruments->begin();
1594  return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
1595  }
1596 
1598  if (!pInstruments) return NULL;
1600  return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
1601  }
1602 
1605  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1606  if (lstInstruments) {
1607  RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1608  while (lstInstr) {
1609  if (lstInstr->GetListType() == LIST_TYPE_INS) {
1610  pInstruments->push_back(new Instrument(this, lstInstr));
1611  }
1612  lstInstr = lstInstruments->GetNextSubList();
1613  }
1614  }
1615  }
1616 
1625  if (!pInstruments) LoadInstruments();
1627  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1628  RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
1629  Instrument* pInstrument = new Instrument(this, lstInstr);
1630  pInstruments->push_back(pInstrument);
1631  return pInstrument;
1632  }
1633 
1641  void File::DeleteInstrument(Instrument* pInstrument) {
1642  if (!pInstruments) return;
1643  InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument);
1644  if (iter == pInstruments->end()) return;
1645  pInstruments->erase(iter);
1646  delete pInstrument;
1647  }
1648 
1662  if (index < 0 || index >= ExtensionFiles.size()) return NULL;
1663  std::list<RIFF::File*>::iterator iter = ExtensionFiles.begin();
1664  for (int i = 0; iter != ExtensionFiles.end(); ++iter, ++i)
1665  if (i == index) return *iter;
1666  return NULL;
1667  }
1668 
1679  return pRIFF->GetFileName();
1680  }
1681 
1686  void File::SetFileName(const String& name) {
1687  pRIFF->SetFileName(name);
1688  }
1689 
1698  void File::UpdateChunks(progress_t* pProgress) {
1699  // first update base class's chunks
1700  Resource::UpdateChunks(pProgress);
1701 
1702  // if version struct exists, update 'vers' chunk
1703  if (pVersion) {
1704  RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
1705  if (!ckVersion) ckVersion = pRIFF->AddSubChunk(CHUNK_ID_VERS, 8);
1706  uint8_t* pData = (uint8_t*) ckVersion->LoadChunkData();
1707  store16(&pData[0], pVersion->minor);
1708  store16(&pData[2], pVersion->major);
1709  store16(&pData[4], pVersion->build);
1710  store16(&pData[6], pVersion->release);
1711  }
1712 
1713  // update 'colh' chunk
1714  Instruments = (pInstruments) ? pInstruments->size() : 0;
1716  if (!colh) colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);
1717  uint8_t* pData = (uint8_t*) colh->LoadChunkData();
1718  store32(pData, Instruments);
1719 
1720  // update instrument's chunks
1721  if (pInstruments) {
1722  // divide local progress into subprogress
1723  progress_t subprogress;
1724  __divide_progress(pProgress, &subprogress, 20.f, 0.f); // arbitrarily subdivided into 5% of total progress
1725 
1726  // do the actual work
1727  InstrumentList::iterator iter = pInstruments->begin();
1728  InstrumentList::iterator end = pInstruments->end();
1729  for (int i = 0; iter != end; ++iter, ++i) {
1730  // divide subprogress into sub-subprogress
1731  progress_t subsubprogress;
1732  __divide_progress(&subprogress, &subsubprogress, pInstruments->size(), i);
1733  // do the actual work
1734  (*iter)->UpdateChunks(&subsubprogress);
1735  }
1736 
1737  __notify_progress(&subprogress, 1.0); // notify subprogress done
1738  }
1739 
1740  // update 'ptbl' chunk
1741  const int iSamples = (pSamples) ? pSamples->size() : 0;
1742  int iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1744  if (!ptbl) ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, 1 /*anything, we'll resize*/);
1745  int iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
1746  ptbl->Resize(iPtblSize);
1747  pData = (uint8_t*) ptbl->LoadChunkData();
1748  WavePoolCount = iSamples;
1749  store32(&pData[4], WavePoolCount);
1750  // we actually update the sample offsets in the pool table when we Save()
1751  memset(&pData[WavePoolHeaderSize], 0, iPtblSize - WavePoolHeaderSize);
1752 
1753  // update sample's chunks
1754  if (pSamples) {
1755  // divide local progress into subprogress
1756  progress_t subprogress;
1757  __divide_progress(pProgress, &subprogress, 20.f, 1.f); // arbitrarily subdivided into 95% of total progress
1758 
1759  // do the actual work
1760  SampleList::iterator iter = pSamples->begin();
1761  SampleList::iterator end = pSamples->end();
1762  for (int i = 0; iter != end; ++iter, ++i) {
1763  // divide subprogress into sub-subprogress
1764  progress_t subsubprogress;
1765  __divide_progress(&subprogress, &subsubprogress, pSamples->size(), i);
1766  // do the actual work
1767  (*iter)->UpdateChunks(&subsubprogress);
1768  }
1769 
1770  __notify_progress(&subprogress, 1.0); // notify subprogress done
1771  }
1772 
1773  // the RIFF file to be written might now been grown >= 4GB or might
1774  // been shrunk < 4GB, so we might need to update the wave pool offset
1775  // size and thus accordingly we would need to resize the wave pool
1776  // chunk
1777  const file_offset_t finalFileSize = pRIFF->GetRequiredFileSize();
1778  const bool bRequires64Bit = (finalFileSize >> 32) != 0;
1779  if (b64BitWavePoolOffsets != bRequires64Bit) {
1780  b64BitWavePoolOffsets = bRequires64Bit;
1781  iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1782  iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
1783  ptbl->Resize(iPtblSize);
1784  }
1785 
1786  __notify_progress(pProgress, 1.0); // notify done
1787  }
1788 
1803  void File::Save(const String& Path, progress_t* pProgress) {
1804  {
1805  // divide local progress into subprogress
1806  progress_t subprogress;
1807  __divide_progress(pProgress, &subprogress, 2.f, 0.f); // arbitrarily subdivided into 50% of total progress
1808  // do the actual work
1809  UpdateChunks(&subprogress);
1810 
1811  }
1812  {
1813  // divide local progress into subprogress
1814  progress_t subprogress;
1815  __divide_progress(pProgress, &subprogress, 2.f, 1.f); // arbitrarily subdivided into 50% of total progress
1816  // do the actual work
1817  pRIFF->Save(Path, &subprogress);
1818  }
1820  __notify_progress(pProgress, 1.0); // notify done
1821  }
1822 
1833  void File::Save(progress_t* pProgress) {
1834  {
1835  // divide local progress into subprogress
1836  progress_t subprogress;
1837  __divide_progress(pProgress, &subprogress, 2.f, 0.f); // arbitrarily subdivided into 50% of total progress
1838  // do the actual work
1839  UpdateChunks(&subprogress);
1840  }
1841  {
1842  // divide local progress into subprogress
1843  progress_t subprogress;
1844  __divide_progress(pProgress, &subprogress, 2.f, 1.f); // arbitrarily subdivided into 50% of total progress
1845  // do the actual work
1846  pRIFF->Save(&subprogress);
1847  }
1849  __notify_progress(pProgress, 1.0); // notify done
1850  }
1851 
1863  __UpdateWavePoolTableChunk();
1864  }
1865 
1872  // enusre 'lins' list chunk exists (mandatory for instrument definitions)
1873  RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1874  if (!lstInstruments) pRIFF->AddSubList(LIST_TYPE_LINS);
1875  // ensure 'ptbl' chunk exists (mandatory for samples)
1877  if (!ptbl) {
1878  const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1879  ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, WavePoolHeaderSize + iOffsetSize);
1880  }
1881  // enusre 'wvpl' list chunk exists (mandatory for samples)
1883  if (!wvpl) pRIFF->AddSubList(LIST_TYPE_WVPL);
1884  }
1885 
1895  void File::__UpdateWavePoolTableChunk() {
1896  __UpdateWavePoolTable();
1898  const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
1899  // check if 'ptbl' chunk is large enough
1900  WavePoolCount = (pSamples) ? pSamples->size() : 0;
1901  const file_offset_t ulRequiredSize = WavePoolHeaderSize + iOffsetSize * WavePoolCount;
1902  if (ptbl->GetSize() < ulRequiredSize) throw Exception("Fatal error, 'ptbl' chunk too small");
1903  // save the 'ptbl' chunk's current read/write position
1904  file_offset_t ullOriginalPos = ptbl->GetPos();
1905  // update headers
1906  ptbl->SetPos(0);
1907  uint32_t tmp = WavePoolHeaderSize;
1908  ptbl->WriteUint32(&tmp);
1909  tmp = WavePoolCount;
1910  ptbl->WriteUint32(&tmp);
1911  // update offsets
1912  ptbl->SetPos(WavePoolHeaderSize);
1913  if (b64BitWavePoolOffsets) {
1914  for (int i = 0 ; i < WavePoolCount ; i++) {
1915  tmp = pWavePoolTableHi[i];
1916  ptbl->WriteUint32(&tmp);
1917  tmp = pWavePoolTable[i];
1918  ptbl->WriteUint32(&tmp);
1919  }
1920  } else { // conventional 32 bit offsets
1921  for (int i = 0 ; i < WavePoolCount ; i++) {
1922  tmp = pWavePoolTable[i];
1923  ptbl->WriteUint32(&tmp);
1924  }
1925  }
1926  // restore 'ptbl' chunk's original read/write position
1927  ptbl->SetPos(ullOriginalPos);
1928  }
1929 
1935  void File::__UpdateWavePoolTable() {
1936  WavePoolCount = (pSamples) ? pSamples->size() : 0;
1937  // resize wave pool table arrays
1938  if (pWavePoolTable) delete[] pWavePoolTable;
1939  if (pWavePoolTableHi) delete[] pWavePoolTableHi;
1940  pWavePoolTable = new uint32_t[WavePoolCount];
1941  pWavePoolTableHi = new uint32_t[WavePoolCount];
1942  if (!pSamples) return;
1943  // update offsets int wave pool table
1945  uint64_t wvplFileOffset = wvpl->GetFilePos();
1946  if (b64BitWavePoolOffsets) {
1947  SampleList::iterator iter = pSamples->begin();
1948  SampleList::iterator end = pSamples->end();
1949  for (int i = 0 ; iter != end ; ++iter, i++) {
1950  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE(pRIFF->GetFileOffsetSize());
1951  (*iter)->ullWavePoolOffset = _64BitOffset;
1952  pWavePoolTableHi[i] = (uint32_t) (_64BitOffset >> 32);
1953  pWavePoolTable[i] = (uint32_t) _64BitOffset;
1954  }
1955  } else { // conventional 32 bit offsets
1956  SampleList::iterator iter = pSamples->begin();
1957  SampleList::iterator end = pSamples->end();
1958  for (int i = 0 ; iter != end ; ++iter, i++) {
1959  uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset - LIST_HEADER_SIZE(pRIFF->GetFileOffsetSize());
1960  (*iter)->ullWavePoolOffset = _64BitOffset;
1961  pWavePoolTable[i] = (uint32_t) _64BitOffset;
1962  }
1963  }
1964  }
1965 
1966 
1967 
1968 // *************** Exception ***************
1969 // *
1970 
1972  }
1973 
1975  std::cout << "DLS::Exception: " << Message << std::endl;
1976  }
1977 
1978 
1979 // *************** functions ***************
1980 // *
1981 
1988  return PACKAGE;
1989  }
1990 
1996  return VERSION;
1997  }
1998 
1999 } // namespace DLS
file_offset_t WriteUint32(uint32_t *pData, file_offset_t WordCount=1)
Writes WordCount number of 32 Bit unsigned integer words from the buffer pointed by pData to the chun...
Definition: RIFF.cpp:684
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:1383
#define CONN_TRANSFORM_BIPOLAR_CTL_ENCODE(x)
Definition: DLS.cpp:51
uint16_t BlockAlign
The block alignment (in bytes) of the waveform data. Playback software needs to process a multiple of...
Definition: DLS.h:402
file_offset_t GetFilePos() const
Current, actual offset of chunk data body start in file.
Definition: RIFF.h:227
#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:373
uint32_t Regions
Reflects the number of Region defintions this Instrument has.
Definition: DLS.h:468
range_t VelocityRange
Definition: DLS.h:434
File * GetFile() const
Returns pointer to the chunk&#39;s File object.
Definition: RIFF.h:222
bool SourceBipolar
Definition: DLS.h:250
Parses DLS Level 1 and 2 compliant files and provides abstract access to the data.
Definition: DLS.h:498
File()
Constructor.
Definition: DLS.cpp:1408
file_offset_t ReadUint16(uint16_t *pData, file_offset_t WordCount=1)
Reads WordCount number of 16 Bit unsigned integer words and copies it into the buffer pointed by pDat...
Definition: RIFF.cpp:572
stream_whence_t
File stream position dependent to these relations.
Definition: RIFF.h:164
uint16_t Layer
Definition: DLS.h:436
String CreationDate
<ICRD-ck>. Specifies the date the subject of the file was created. List dates in yyyy-mm-dd format...
Definition: DLS.h:310
Chunk * GetFirstSubChunk()
Returns the first subchunk within the list (which may be an ordinary chunk as well as a list chunk)...
Definition: RIFF.cpp:1116
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
String GetFileName() const
Definition: RIFF.cpp:1711
#define CHUNK_ID_ISBJ
Definition: DLS.h:81
String Engineer
<IENG-ck>. Stores the name of the engineer who worked on the file. Multiple engineer names are separa...
Definition: DLS.h:317
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:1078
void __ensureMandatoryChunksExist()
Checks if all (for DLS) mandatory chunks exist, if not they will be created.
Definition: DLS.cpp:1871
String Artists
<IART-ck>. Lists the artist of the original subject of the file.
Definition: DLS.h:314
#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:1514
file_offset_t SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence=RIFF::stream_start)
Sets the position within the sample (in sample points, not in bytes).
Definition: DLS.cpp:918
Instrument * GetNextInstrument()
Returns a pointer to the next Instrument object of the file, NULL otherwise.
Definition: DLS.cpp:1597
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:553
file_offset_t ReadInt32(int32_t *pData, file_offset_t WordCount=1)
Reads WordCount number of 32 Bit signed integer words and copies it into the buffer pointed by pData...
Definition: RIFF.cpp:609
conn_trn_t SourceTransform
Definition: DLS.h:248
Optional information for DLS files, instruments, samples, etc.
Definition: DLS.h:306
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:1175
uint16_t KeyGroup
Definition: DLS.h:435
virtual void UpdateChunks(progress_t *pProgress)
Update chunks with current Resource data.
Definition: DLS.cpp:476
#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:1661
virtual ~Region()
Destructor.
Definition: DLS.cpp:1044
Instrument * AddInstrument()
Add a new instrument definition.
Definition: DLS.cpp:1624
#define CHUNK_ID_PTBL
Definition: DLS.h:92
#define LIST_TYPE_WVPL
Definition: DLS.h:65
RIFF::List * pCkRegion
Definition: DLS.h:449
Instrument * GetFirstInstrument()
Returns a pointer to the first Instrument object of the file, NULL otherwise.
Definition: DLS.cpp:1590
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:316
file_offset_t ullWavePoolOffset
Definition: DLS.h:421
#define DLS_WAVE_FORMAT_PCM
Definition: DLS.h:99
#define CHUNK_ID_ART2
Definition: DLS.h:96
#define CONN_TRANSFORM_DST(x)
Definition: DLS.cpp:40
std::list< Articulation * > ArticulationList
Definition: DLS.h:296
conn_src_t
Connection Sources.
Definition: DLS.h:127
#define CONN_TRANSFORM_SRC_ENCODE(x)
Definition: DLS.cpp:47
#define CHUNK_ID_ICMT
Definition: RIFF.h:102
#define CHUNK_ID_ISFT
Definition: RIFF.h:108
List * GetParent() const
Returns pointer to the chunk&#39;s parent list chunk.
Definition: RIFF.h:223
friend class Region
Definition: DLS.h:492
uint32_t * pWavePoolTable
Definition: DLS.h:532
#define CHUNK_ID_IMED
Definition: DLS.h:80
uint32_t WavePoolTableIndex
Definition: DLS.h:450
#define CHUNK_ID_IPRD
Definition: RIFF.h:107
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:399
#define CONN_TRANSFORM_BIPOLAR_SRC(x)
Definition: DLS.cpp:41
virtual ~Info()
Definition: DLS.cpp:282
RIFF::List * pCkInstrument
Definition: DLS.h:483
file_offset_t SamplesTotal
Reflects total number of sample points (only if known sample data format is used, 0 otherwise)...
Definition: DLS.h:404
uint32_t SamplerOptions
Definition: DLS.h:383
virtual ~Resource()
Definition: DLS.cpp:461
#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:322
int16_t FineTune
Definition: DLS.h:368
bool ControlInvert
Definition: DLS.h:253
Sampler(RIFF::List *ParentList)
Definition: DLS.cpp:550
List * GetSubList(uint32_t ListType)
Returns sublist chunk with list type ListType within this chunk list.
Definition: RIFF.cpp:1090
void DeleteSubChunk(Chunk *pSubChunk)
Removes a sub chunk.
Definition: RIFF.cpp:1342
Defines Sample Loop Points.
Definition: DLS.h:231
#define LIST_TYPE_RGN2
Definition: DLS.h:74
Region * AddRegion()
Definition: DLS.cpp:1273
virtual ~Sample()
Destructor.
Definition: DLS.cpp:753
void PrintMessage()
Definition: DLS.cpp:1974
virtual void LoadSamples()
Definition: DLS.cpp:1527
bool ControlBipolar
Definition: DLS.h:254
bool NoSampleCompression
Definition: DLS.h:371
uint16_t MIDIBank
Reflects combination of MIDIBankCoarse and MIDIBankFine (bank 1 - bank 16384). Do not change this val...
Definition: DLS.h:464
virtual void SetGain(int32_t gain)
Definition: DLS.cpp:586
#define CONN_TRANSFORM_BIPOLAR_CTL(x)
Definition: DLS.cpp:42
#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:1151
file_offset_t GetPos() const
Position within the chunk data body (starting with 0).
Definition: RIFF.h:226
#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:112
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:408
std::list< Sample * > SampleList
Definition: DLS.h:521
InstrumentList::iterator InstrumentsIterator
Definition: DLS.h:529
uint8_t MIDIBankCoarse
Reflects the MIDI Bank number for MIDI Control Change 0 (bank 1 - 128).
Definition: DLS.h:465
void GenerateDLSID()
Generates a new DLSID for the resource.
Definition: DLS.cpp:495
conn_dst_t Destination
Definition: DLS.h:255
uint FrameSize
Reflects the size (in bytes) of one single sample point (only if known sample data format is used...
Definition: DLS.h:405
#define MIDI_BANK_COARSE(x)
Definition: DLS.cpp:65
RIFF::Chunk * pCkFormat
Definition: DLS.h:420
#define CHUNK_ID_IENG
Definition: RIFF.h:105
Every subject of an DLS file and the file itself can have an unique, computer generated ID...
Definition: DLS.h:119
bool MultiChannel
Definition: DLS.h:440
#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:789
Region * GetFirstRegion()
Definition: DLS.cpp:1245
void DeleteSampleLoop(sample_loop_t *pLoopDef)
Deletes an existing sample loop.
Definition: DLS.cpp:655
virtual ~Instrument()
Destructor.
Definition: DLS.cpp:1346
uint16_t low
Low value of range.
Definition: DLS.h:207
void SetByteOrder(endian_t Endian)
Set the byte order to be used when saving.
Definition: RIFF.cpp:1842
#define CONN_TRANSFORM_BIPOLAR_SRC_ENCODE(x)
Definition: DLS.cpp:50
bool b64BitWavePoolOffsets
Definition: DLS.h:534
#define DRUM_TYPE_MASK
Definition: DLS.cpp:55
RIFF List Chunk.
Definition: RIFF.h:293
#define CHUNK_ID_WSMP
Definition: DLS.h:93
file_offset_t RemainingBytes() const
Returns the number of bytes left to read in the chunk body.
Definition: RIFF.cpp:256
RIFF::Chunk * pCkData
Definition: DLS.h:419
#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:296
RegionList * pRegions
Definition: DLS.h:484
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:398
file_offset_t Read(void *pData, file_offset_t WordCount, file_offset_t WordSize)
Reads WordCount number of data words with given WordSize and copies it into a buffer pointed by pData...
Definition: RIFF.cpp:318
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:679
void ReleaseSampleData()
Free sample data from RAM.
Definition: DLS.cpp:844
#define CHUNK_ID_RGNH
Definition: DLS.h:90
file_offset_t GetSize() const
Chunk size in bytes (without header, thus the chunk data body)
Definition: RIFF.h:224
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:240
Abstract base class which provides mandatory informations about sample players in general...
Definition: DLS.h:365
bool SelfNonExclusive
Definition: DLS.h:437
String libraryName()
Returns the name of this C++ library.
Definition: DLS.cpp:1987
Sample * GetSample()
Definition: DLS.cpp:1049
Exception(String Message)
Definition: DLS.cpp:1971
file_offset_t SetPos(file_offset_t 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:224
#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:198
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:1686
uint32_t SampleLoops
Reflects the number of sample loops.
Definition: DLS.h:372
conn_trn_t DestinationTransform
Definition: DLS.h:256
virtual void Save(const String &Path, progress_t *pProgress=NULL)
Save changes to another file.
Definition: DLS.cpp:1803
Resource * pParent
Definition: DLS.h:357
SampleList * pSamples
Definition: DLS.h:526
#define CHUNK_ID_FMT
Definition: DLS.h:87
void Resize(file_offset_t NewSize)
Resize sample.
Definition: DLS.cpp:891
conn_dst_t
Connection Destinations.
Definition: DLS.h:153
bool NoSampleDepthTruncation
Definition: DLS.h:370
String Message
Definition: RIFF.h:405
virtual ~Articulator()
Definition: DLS.cpp:207
void DeleteSample(Sample *pSample)
Delete a sample.
Definition: DLS.cpp:1582
bool SourceInvert
Definition: DLS.h:249
uint16_t high
High value of range.
Definition: DLS.h:208
Articulation * GetFirstArticulation()
Definition: DLS.cpp:176
file_offset_t ReadUint32(uint32_t *pData, file_offset_t WordCount=1)
Reads WordCount number of 32 Bit unsigned integer words and copies it into the buffer pointed by pDat...
Definition: RIFF.cpp:646
uint32_t Size
For internal usage only: usually reflects exactly sizeof(sample_loop_t), otherwise if the value is la...
Definition: DLS.h:232
bool PhaseMaster
Definition: DLS.h:438
Chunk * GetSubChunk(uint32_t ChunkID)
Returns subchunk with chunk ID ChunkID within this chunk list.
Definition: RIFF.cpp:1071
#define LIST_TYPE_INS
Definition: DLS.h:69
Chunk * GetNextSubChunk()
Returns the next subchunk within the list (which may be an ordinary chunk as well as a list chunk)...
Definition: RIFF.cpp:1133
Info(RIFF::List *list)
Constructor.
Definition: DLS.cpp:255
std::list< Instrument * > InstrumentList
Definition: DLS.h:522
Region(Instrument *pInstrument, RIFF::List *rgnList)
Definition: DLS.cpp:996
#define CHUNK_ID_ICRD
Definition: RIFF.h:104
virtual void Save(progress_t *pProgress=NULL)
Save changes to same file.
Definition: RIFF.cpp:1859
#define CHUNK_ID_DLID
Definition: DLS.h:86
String Source
<ISRC-ck>. Identifies the name of the person or organization who supplied the original subject of the...
Definition: DLS.h:321
uint16_t BitDepth
Size of each sample per channel (only if known sample data format is used, 0 otherwise).
Definition: DLS.h:403
Ordinary RIFF Chunk.
Definition: RIFF.h:217
#define CHUNK_ID_ICMS
Definition: DLS.h:77
uint32_t Scale
Definition: DLS.h:257
uint8_t UnityNote
Definition: DLS.h:367
#define F_WSMP_NO_COMPRESSION
Definition: DLS.cpp:63
virtual ~File()
Definition: DLS.cpp:1486
#define CONN_TRANSFORM_SRC(x)
Definition: DLS.cpp:38
#define LIST_TYPE_RGN
Definition: DLS.h:73
Sample(File *pFile, RIFF::List *waveList, file_offset_t WavePoolOffset)
Constructor.
Definition: DLS.cpp:714
#define CHUNK_ID_INAM
Definition: RIFF.h:106
uint32_t MIDIProgram
Specifies the MIDI Program Change Number this Instrument should be assigned to.
Definition: DLS.h:467
file_offset_t GetRequiredFileSize()
Returns the required size (in bytes) for this RIFF File to be saved to disk.
Definition: RIFF.cpp:2143
virtual void UpdateChunks(progress_t *pProgress)
Update chunks with current info values.
Definition: DLS.cpp:346
String Commissioned
<ICMS-ck>. Lists the name of the person or organization that commissioned the subject of the file...
Definition: DLS.h:323
uint32_t GetChunkID() const
Chunk ID in unsigned integer representation.
Definition: RIFF.h:221
#define LIST_HEADER_SIZE(fileOffsetSize)
Definition: RIFF.h:115
#define CHUNK_ID_ITCH
Definition: DLS.h:84
friend class Articulation
Definition: DLS.h:270
#define F_RGN_OPTION_SELFNONEXCLUSIVE
Definition: DLS.cpp:57
void SetSample(Sample *pSample)
Assign another sample to this Region.
Definition: DLS.cpp:1066
Used for indicating the progress of a certain task.
Definition: RIFF.h:203
SampleList::iterator SamplesIterator
Definition: DLS.h:527
Articulation * GetNextArticulation()
Definition: DLS.cpp:183
file_offset_t Write(void *pData, file_offset_t WordCount, file_offset_t WordSize)
Writes WordCount number of data words with given WordSize from the buffer pointed by pData...
Definition: RIFF.cpp:388
conn_src_t Control
Definition: DLS.h:251
#define CONN_TRANSFORM_INVERT_CTL_ENCODE(x)
Definition: DLS.cpp:53
uint16_t WaveLinkOptionFlags
Definition: DLS.h:453
#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
virtual void UpdateChunks(progress_t *pProgress)
Apply Instrument with all its Regions to the respective RIFF chunks.
Definition: DLS.cpp:1309
#define CONN_TRANSFORM_INVERT_SRC(x)
Definition: DLS.cpp:43
void DeleteInstrument(Instrument *pInstrument)
Delete an instrument.
Definition: DLS.cpp:1641
int GetFileOffsetSize() const
Returns the current size (in bytes) of file offsets stored in the headers of all chunks of this file...
Definition: RIFF.cpp:2207
version_t * pVersion
Points to a version_t structure if the file provided a version number else is set to NULL...
Definition: DLS.h:500
String Technician
<ITCH-ck>. Identifies the technician who sampled the subject file.
Definition: DLS.h:318
Instrument(File *pFile, RIFF::List *insList)
Constructor.
Definition: DLS.cpp:1222
uint16_t major
Definition: DLS.h:113
RegionList::iterator RegionsIterator
Definition: DLS.h:485
void SetFileName(const String &path)
Definition: RIFF.cpp:1715
#define CHUNK_ID_INSH
Definition: DLS.h:89
file_offset_t GetSize() const
Returns sample size.
Definition: DLS.cpp:858
void * LoadChunkData()
Load chunk body into RAM.
Definition: RIFF.cpp:809
Region * GetNextRegion()
Definition: DLS.cpp:1252
#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:401
conn_src_t Source
Definition: DLS.h:247
uint8_t MIDIBankFine
Reflects the MIDI Bank number for MIDI Control Change 32 (bank 1 - 128).
Definition: DLS.h:466
uint16_t PhaseGroup
Definition: DLS.h:439
#define CHUNK_ID_COLH
Definition: DLS.h:94
uint32_t Channel
Definition: DLS.h:441
uint32_t WavePoolHeaderSize
Definition: DLS.h:530
#define CHUNK_ID_ICOP
Definition: RIFF.h:103
virtual void UpdateChunks(progress_t *pProgress)
Apply all articulations to the respective RIFF chunks.
Definition: DLS.cpp:225
RIFF::File * pRIFF
Definition: DLS.h:524
Abstract base class which encapsulates data structures which all DLS resources are able to provide...
Definition: DLS.h:346
void Resize(file_offset_t NewSize)
Resize chunk.
Definition: RIFF.cpp:880
RIFF File.
Definition: RIFF.h:343
void Init(conn_block_t *Header)
Definition: DLS.cpp:75
List * AddSubList(uint32_t uiListType)
Creates a new list sub chunk.
Definition: RIFF.cpp:1323
InstrumentList * pInstruments
Definition: DLS.h:528
uint16_t build
Definition: DLS.h:114
virtual void LoadInstruments()
Definition: DLS.cpp:1603
RIFF specific classes and definitions.
Definition: RIFF.h:137
virtual void UpdateChunks(progress_t *pProgress)
Apply all sample player options to the respective RIFF chunk.
Definition: DLS.cpp:596
String Software
<ISFT-ck>. Identifies the name of the sofware package used to create the file.
Definition: DLS.h:319
#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:309
uint16_t release
Definition: DLS.h:115
Encapsulates sample waves used for playback.
Definition: DLS.h:396
Sample * GetNextSample()
Returns a pointer to the next Sample object of the file, NULL otherwise.
Definition: DLS.cpp:1521
void MoveSubChunk(Chunk *pSrc, Chunk *pDst)
Moves a sub chunk witin this list.
Definition: RIFF.cpp:1275
String Name
<INAM-ck>. Stores the title of the subject of the file, such as, Seattle From Above.
Definition: DLS.h:308
uint32_t SamplesPerSecond
Sampling rate at which each channel should be played (defaults to 44100 if Sample was created with In...
Definition: DLS.h:400
String Product
<IPRD-ck>. Specifies the name of the title the file was originally intended for, such as World Ruler ...
Definition: DLS.h:312
uint32_t WavePoolCount
Definition: DLS.h:531
String GetFileName()
File name of this DLS file.
Definition: DLS.cpp:1678
String Medium
<IMED-ck>. Describes the original subject of the file, such as, record, CD, and so forth...
Definition: DLS.h:320
String Subject
<ISBJ-ck>. Describes the contents of the file.
Definition: DLS.h:324
void LoadArticulations()
Definition: DLS.cpp:189
RIFF::List * pWaveList
Definition: DLS.h:418
virtual void LoadRegions()
Definition: DLS.cpp:1258
file_offset_t Read(void *pBuffer, file_offset_t SampleCount)
Reads SampleCount number of sample points from the current position into the buffer pointed by pBuffe...
Definition: DLS.cpp:936
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:769
conn_block_t ToConnBlock()
Definition: DLS.cpp:89
virtual ~Sampler()
Definition: DLS.cpp:582
#define LIST_TYPE_LINS
Definition: DLS.h:68
Resource * GetParent()
Definition: DLS.h:351
#define CHUNK_ID_IARL
Definition: DLS.h:75
void ReleaseChunkData()
Free loaded chunk body from RAM.
Definition: RIFF.cpp:855
void DeleteRegion(Region *pRegion)
Definition: DLS.cpp:1293
Abstract base class for classes that provide articulation information (thus for Instrument and Region...
Definition: DLS.h:288
Sample * pSample
Definition: DLS.h:451
#define LIST_TYPE_INFO
Definition: RIFF.h:101
conn_trn_t ControlTransform
Definition: DLS.h:252
range_t KeyRange
Definition: DLS.h:433
#define CHUNK_ID_ISRC
Definition: DLS.h:82
virtual void UpdateChunks(progress_t *pProgress)
Apply sample and its settings to the respective RIFF chunks.
Definition: DLS.cpp:970
Provides access to the defined connections used for the synthesis model.
Definition: DLS.h:274
virtual void UpdateChunks(progress_t *pProgress)
Apply articulation connections to the respective RIFF chunks.
Definition: DLS.cpp:150
#define CONN_TRANSFORM_INVERT_CTL(x)
Definition: DLS.cpp:44
uint32_t Instruments
Reflects the number of available Instrument objects.
Definition: DLS.h:501
String Genre
<IGNR-ck>. Descirbes the original work, such as, Jazz, Classic, Rock, Techno, Rave, etc.
Definition: DLS.h:315
Provides all neccessary information for the synthesis of a DLS Instrument.
Definition: DLS.h:461
int32_t Gain
Definition: DLS.h:369
Quadtuple version number ("major.minor.release.build").
Definition: DLS.h:111
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:542
String Copyright
<ICOP-ck>. Records the copyright information for the file.
Definition: DLS.h:313
file_offset_t Write(void *pBuffer, file_offset_t SampleCount)
Write sample wave data.
Definition: DLS.cpp:956
Sample * AddSample()
Add a new sample.
Definition: DLS.cpp:1564
void CopyAssignCore(const Instrument *orig)
Definition: DLS.cpp:1361
uint32_t GetListType() const
Returns unsigned integer representation of the list&#39;s ID.
Definition: RIFF.h:297
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:348
RIFF::file_offset_t file_offset_t
Definition: DLS.h:108
String libraryVersion()
Returns version of this C++ library.
Definition: DLS.cpp:1995
Defines a connection within the synthesis model.
Definition: DLS.h:245
file_offset_t ReadInt16(int16_t *pData, file_offset_t WordCount=1)
Reads WordCount number of 16 Bit signed integer words and copies it into the buffer pointed by pData...
Definition: RIFF.cpp:535
uint16_t FormatOptionFlags
Definition: DLS.h:452
uint32_t * pWavePoolTableHi
Definition: DLS.h:533
virtual void UpdateChunks(progress_t *pProgress)
Apply Region settings to the respective RIFF chunks.
Definition: DLS.cpp:1113
String Comments
<ICMT-ck>. Provides general comments about the file or the subject of the file. Sentences might end w...
Definition: DLS.h:311
Articulator(RIFF::List *ParentList)
Definition: DLS.cpp:171
List * GetNextSubList()
Returns the next sublist (that is a subchunk with chunk ID "LIST") within the list.
Definition: RIFF.cpp:1173
Defines Region information of an Instrument.
Definition: DLS.h:431
std::list< RIFF::File * > ExtensionFiles
Definition: DLS.h:525
Articulation(RIFF::Chunk *artl)
Constructor.
Definition: DLS.cpp:118
Chunk * AddSubChunk(uint32_t uiChunkID, file_offset_t ullBodySize)
Creates a new sub chunk.
Definition: RIFF.cpp:1253
bool IsDrum
Indicates if the Instrument is a drum type, as they differ in the synthesis model of DLS from melodic...
Definition: DLS.h:463
std::list< Region * > RegionList
Definition: DLS.h:477
virtual void UpdateChunks(progress_t *pProgress)
Apply all the DLS file&#39;s current instruments, samples and settings to the respective RIFF chunks...
Definition: DLS.cpp:1698
void * LoadSampleData()
Load sample data into RAM.
Definition: DLS.cpp:835
void AddSampleLoop(sample_loop_t *pLoopDef)
Adds a new sample loop with the provided loop definition.
Definition: DLS.cpp:633
virtual void UpdateFileOffsets()
Updates all file offsets stored all over the file.
Definition: DLS.cpp:1862
Resource(Resource *Parent, RIFF::List *lstResource)
Constructor.
Definition: DLS.cpp:444