DLS.cpp
/***************************************************************************
* *
* libgig - C++ cross-platform Gigasampler format file access library *
* *
* Copyright (C) 2003-2025 by Christian Schoenebeck *
* <cuse@users.sourceforge.net> *
* *
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
***************************************************************************/
#include "DLS.h"
#include <algorithm>
#include <vector>
#include <time.h>
#ifdef __APPLE__
#include <CoreFoundation/CFUUID.h>
#elif defined(HAVE_UUID_UUID_H)
#include <uuid/uuid.h>
#endif
#include "helper.h"
// macros to decode connection transforms
#define CONN_TRANSFORM_SRC(x) ((x >> 10) & 0x000F)
#define CONN_TRANSFORM_CTL(x) ((x >> 4) & 0x000F)
#define CONN_TRANSFORM_DST(x) (x & 0x000F)
#define CONN_TRANSFORM_BIPOLAR_SRC(x) (x & 0x4000)
#define CONN_TRANSFORM_BIPOLAR_CTL(x) (x & 0x0100)
#define CONN_TRANSFORM_INVERT_SRC(x) (x & 0x8000)
#define CONN_TRANSFORM_INVERT_CTL(x) (x & 0x0200)
// macros to encode connection transforms
#define CONN_TRANSFORM_SRC_ENCODE(x) ((x & 0x000F) << 10)
#define CONN_TRANSFORM_CTL_ENCODE(x) ((x & 0x000F) << 4)
#define CONN_TRANSFORM_DST_ENCODE(x) (x & 0x000F)
#define CONN_TRANSFORM_BIPOLAR_SRC_ENCODE(x) ((x) ? 0x4000 : 0)
#define CONN_TRANSFORM_BIPOLAR_CTL_ENCODE(x) ((x) ? 0x0100 : 0)
#define CONN_TRANSFORM_INVERT_SRC_ENCODE(x) ((x) ? 0x8000 : 0)
#define CONN_TRANSFORM_INVERT_CTL_ENCODE(x) ((x) ? 0x0200 : 0)
#define DRUM_TYPE_MASK 0x80000000
#define F_RGN_OPTION_SELFNONEXCLUSIVE 0x0001
#define F_WAVELINK_PHASE_MASTER 0x0001
#define F_WAVELINK_MULTICHANNEL 0x0002
#define F_WSMP_NO_TRUNCATION 0x0001
#define F_WSMP_NO_COMPRESSION 0x0002
#define MIDI_BANK_COARSE(x) ((x & 0x00007F00) >> 8) // CC0
#define MIDI_BANK_FINE(x) (x & 0x0000007F) // CC32
#define MIDI_BANK_MERGE(coarse, fine) ((((uint16_t) coarse) << 7) | fine) // CC0 + CC32
#define MIDI_BANK_ENCODE(coarse, fine) (((coarse & 0x0000007F) << 8) | (fine & 0x0000007F))
namespace DLS {
// *************** Connection ***************
// *
void Connection::Init(conn_block_t* Header) {
Source = (conn_src_t) Header->source;
Control = (conn_src_t) Header->control;
Destination = (conn_dst_t) Header->destination;
Scale = Header->scale;
SourceTransform = (conn_trn_t) CONN_TRANSFORM_SRC(Header->transform);
ControlTransform = (conn_trn_t) CONN_TRANSFORM_CTL(Header->transform);
DestinationTransform = (conn_trn_t) CONN_TRANSFORM_DST(Header->transform);
SourceInvert = CONN_TRANSFORM_INVERT_SRC(Header->transform);
SourceBipolar = CONN_TRANSFORM_BIPOLAR_SRC(Header->transform);
ControlInvert = CONN_TRANSFORM_INVERT_CTL(Header->transform);
ControlBipolar = CONN_TRANSFORM_BIPOLAR_CTL(Header->transform);
}
Connection::conn_block_t Connection::ToConnBlock() {
conn_block_t c;
c.source = Source;
c.control = Control;
c.destination = Destination;
c.scale = Scale;
c.transform = CONN_TRANSFORM_SRC_ENCODE(SourceTransform) |
CONN_TRANSFORM_CTL_ENCODE(ControlTransform) |
CONN_TRANSFORM_DST_ENCODE(DestinationTransform) |
CONN_TRANSFORM_INVERT_SRC_ENCODE(SourceInvert) |
CONN_TRANSFORM_BIPOLAR_SRC_ENCODE(SourceBipolar) |
CONN_TRANSFORM_INVERT_CTL_ENCODE(ControlInvert) |
CONN_TRANSFORM_BIPOLAR_CTL_ENCODE(ControlBipolar);
return c;
}
// *************** Articulation ***************
// *
Articulation::Articulation(RIFF::Chunk* artl) {
pArticulationCk = artl;
if (artl->GetChunkID() != CHUNK_ID_ART2 &&
artl->GetChunkID() != CHUNK_ID_ARTL) {
throw DLS::Exception("<artl-ck> or <art2-ck> chunk expected");
}
artl->SetPos(0);
HeaderSize = artl->ReadUint32();
Connections = artl->ReadUint32();
artl->SetPos(HeaderSize);
pConnections = new Connection[Connections];
Connection::conn_block_t connblock;
for (uint32_t i = 0; i < Connections; i++) {
artl->Read(&connblock.source, 1, 2);
artl->Read(&connblock.control, 1, 2);
artl->Read(&connblock.destination, 1, 2);
artl->Read(&connblock.transform, 1, 2);
artl->Read(&connblock.scale, 1, 4);
pConnections[i].Init(&connblock);
}
}
Articulation::~Articulation() {
if (pConnections) delete[] pConnections;
}
void Articulation::UpdateChunks(progress_t* /*pProgress*/) {
const int iEntrySize = 12; // 12 bytes per connection block
pArticulationCk->Resize(HeaderSize + Connections * iEntrySize);
uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData();
store16(&pData[0], HeaderSize);
store16(&pData[2], Connections);
for (uint32_t i = 0; i < Connections; i++) {
Connection::conn_block_t c = pConnections[i].ToConnBlock();
store16(&pData[HeaderSize + i * iEntrySize], c.source);
store16(&pData[HeaderSize + i * iEntrySize + 2], c.control);
store16(&pData[HeaderSize + i * iEntrySize + 4], c.destination);
store16(&pData[HeaderSize + i * iEntrySize + 6], c.transform);
store32(&pData[HeaderSize + i * iEntrySize + 8], c.scale);
}
}
void Articulation::DeleteChunks() {
}
// *************** Articulator ***************
// *
Articulator::Articulator(RIFF::List* ParentList) {
pParentList = ParentList;
pArticulations = NULL;
}
Articulation* Articulator::GetArticulation(size_t pos) {
if (!pArticulations) LoadArticulations();
if (!pArticulations) return NULL;
if (pos >= pArticulations->size()) return NULL;
return (*pArticulations)[pos];
}
Articulation* Articulator::GetFirstArticulation() {
if (!pArticulations) LoadArticulations();
if (!pArticulations) return NULL;
ArticulationsIterator = pArticulations->begin();
return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
}
Articulation* Articulator::GetNextArticulation() {
if (!pArticulations) return NULL;
ArticulationsIterator++;
return (ArticulationsIterator != pArticulations->end()) ? *ArticulationsIterator : NULL;
}
void Articulator::LoadArticulations() {
// prefer articulation level 2
RIFF::List* lart = pParentList->GetSubList(LIST_TYPE_LAR2);
if (!lart) lart = pParentList->GetSubList(LIST_TYPE_LART);
if (lart) {
uint32_t artCkType = (lart->GetListType() == LIST_TYPE_LAR2) ? CHUNK_ID_ART2
: CHUNK_ID_ARTL;
size_t i = 0;
for (RIFF::Chunk* art = lart->GetSubChunkAt(i); art;
art = lart->GetSubChunkAt(++i))
{
if (art->GetChunkID() == artCkType) {
if (!pArticulations) pArticulations = new ArticulationList;
pArticulations->push_back(new Articulation(art));
}
}
}
}
Articulator::~Articulator() {
if (pArticulations) {
ArticulationList::iterator iter = pArticulations->begin();
ArticulationList::iterator end = pArticulations->end();
while (iter != end) {
delete *iter;
iter++;
}
delete pArticulations;
}
}
void Articulator::UpdateChunks(progress_t* pProgress) {
if (pArticulations) {
ArticulationList::iterator iter = pArticulations->begin();
ArticulationList::iterator end = pArticulations->end();
for (; iter != end; ++iter) {
(*iter)->UpdateChunks(pProgress);
}
}
}
void Articulator::DeleteChunks() {
if (pArticulations) {
ArticulationList::iterator iter = pArticulations->begin();
ArticulationList::iterator end = pArticulations->end();
for (; iter != end; ++iter) {
(*iter)->DeleteChunks();
}
}
}
void Articulator::CopyAssign(const Articulator* /*orig*/) {
//TODO: implement deep copy assignment for this class
}
// *************** Info ***************
// *
// Pacify false -Wdeprecated-declarations warning raised by GCC bug
// when initializing 'UseFixedLengthStrings' member variable below,
// which GCC even raises if member variable is not initializes at all.
// Only do this for GCC >= 4.6, as older GCC versions don't support
// pragma push/pop. We don't have to include clang here at all, because
// clang does not have this bug.
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Info::Info(RIFF::List* list) :
UseFixedLengthStrings(false)
{
// re-enable -Wdeprecated-declarations (see comment on preceeding pragma above)
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic pop
#endif
pFixedStringLengths = NULL;
pResourceListChunk = list;
if (list) {
RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO);
if (lstINFO) {
LoadString(CHUNK_ID_INAM, lstINFO, Name);
LoadString(CHUNK_ID_IARL, lstINFO, ArchivalLocation);
LoadString(CHUNK_ID_ICRD, lstINFO, CreationDate);
LoadString(CHUNK_ID_ICMT, lstINFO, Comments);
LoadString(CHUNK_ID_IPRD, lstINFO, Product);
LoadString(CHUNK_ID_ICOP, lstINFO, Copyright);
LoadString(CHUNK_ID_IART, lstINFO, Artists);
LoadString(CHUNK_ID_IGNR, lstINFO, Genre);
LoadString(CHUNK_ID_IKEY, lstINFO, Keywords);
LoadString(CHUNK_ID_IENG, lstINFO, Engineer);
LoadString(CHUNK_ID_ITCH, lstINFO, Technician);
LoadString(CHUNK_ID_ISFT, lstINFO, Software);
LoadString(CHUNK_ID_IMED, lstINFO, Medium);
LoadString(CHUNK_ID_ISRC, lstINFO, Source);
LoadString(CHUNK_ID_ISRF, lstINFO, SourceForm);
LoadString(CHUNK_ID_ICMS, lstINFO, Commissioned);
LoadString(CHUNK_ID_ISBJ, lstINFO, Subject);
}
}
}
Info::~Info() {
}
void Info::SetFixedStringLengths(const string_length_t* lengths) {
pFixedStringLengths = lengths;
}
void Info::LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s) {
RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
::LoadString(ck, s); // function from helper.h
}
void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) {
int size = 0;
if (pFixedStringLengths) {
for (int i = 0 ; pFixedStringLengths[i].length ; i++) {
if (pFixedStringLengths[i].chunkId == ChunkID) {
size = pFixedStringLengths[i].length;
break;
}
}
}
RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID);
::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size); // function from helper.h
}
void Info::UpdateChunks(progress_t* /*pProgress*/) {
if (!pResourceListChunk) return;
// make sure INFO list chunk exists
RIFF::List* lstINFO = pResourceListChunk->GetSubList(LIST_TYPE_INFO);
String defaultName = "";
String defaultCreationDate = "";
String defaultSoftware = "";
String defaultComments = "";
uint32_t resourceType = pResourceListChunk->GetListType();
if (!lstINFO) {
lstINFO = pResourceListChunk->AddSubList(LIST_TYPE_INFO);
// assemble default values
defaultName = "NONAME";
if (resourceType == RIFF_TYPE_DLS) {
// get current date
time_t now = time(NULL);
tm* pNowBroken = localtime(&now);
char buf[11];
strftime(buf, 11, "%F", pNowBroken);
defaultCreationDate = buf;
defaultComments = "Created with " + libraryName() + " " + libraryVersion();
}
if (resourceType == RIFF_TYPE_DLS || resourceType == LIST_TYPE_INS)
{
defaultSoftware = libraryName() + " " + libraryVersion();
}
}
// save values
SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""));
SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""));
SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""));
SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments);
SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""));
SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate);
SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""));
SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""));
SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""));
SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""));
SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName);
SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""));
SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String(""));
SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware);
SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""));
SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""));
SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""));
}
void Info::DeleteChunks() {
}
void Info::CopyAssign(const Info* orig) {
Name = orig->Name;
ArchivalLocation = orig->ArchivalLocation;
CreationDate = orig->CreationDate;
Comments = orig->Comments;
Product = orig->Product;
Copyright = orig->Copyright;
Artists = orig->Artists;
Genre = orig->Genre;
Keywords = orig->Keywords;
Engineer = orig->Engineer;
Technician = orig->Technician;
Software = orig->Software;
Medium = orig->Medium;
Source = orig->Source;
SourceForm = orig->SourceForm;
Commissioned = orig->Commissioned;
Subject = orig->Subject;
//FIXME: hmm, is copying this pointer a good idea?
pFixedStringLengths = orig->pFixedStringLengths;
}
// *************** Resource ***************
// *
* INFO list chunk and a DLID chunk (the latter optional).
*
* @param Parent - pointer to parent 'Resource', NULL if this is
* the toplevel 'Resource' object
* @param lstResource - pointer to an INFO list chunk
*/
Resource::Resource(Resource* Parent, RIFF::List* lstResource) {
pParent = Parent;
pResourceList = lstResource;
pInfo = new Info(lstResource);
RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);
if (ckDLSID) {
ckDLSID->SetPos(0);
pDLSID = new dlsid_t;
ckDLSID->Read(&pDLSID->ulData1, 1, 4);
ckDLSID->Read(&pDLSID->usData2, 1, 2);
ckDLSID->Read(&pDLSID->usData3, 1, 2);
ckDLSID->Read(pDLSID->abData, 8, 1);
}
else pDLSID = NULL;
}
Resource::~Resource() {
if (pDLSID) delete pDLSID;
if (pInfo) delete pInfo;
}
*/
void Resource::DeleteChunks() {
}
*/
void Resource::UpdateChunks(progress_t* pProgress) {
pInfo->UpdateChunks(pProgress);
if (pDLSID) {
// make sure 'dlid' chunk exists
RIFF::Chunk* ckDLSID = pResourceList->GetSubChunk(CHUNK_ID_DLID);
if (!ckDLSID) ckDLSID = pResourceList->AddSubChunk(CHUNK_ID_DLID, 16);
uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
// update 'dlid' chunk
store32(&pData[0], pDLSID->ulData1);
store16(&pData[4], pDLSID->usData2);
store16(&pData[6], pDLSID->usData3);
memcpy(&pData[8], pDLSID->abData, 8);
}
}
void Resource::GenerateDLSID() {
#if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
if (!pDLSID) pDLSID = new dlsid_t;
GenerateDLSID(pDLSID);
#endif
}
void Resource::GenerateDLSID(dlsid_t* pDLSID) {
#ifdef WIN32
UUID uuid;
UuidCreate(&uuid);
pDLSID->ulData1 = uuid.Data1;
pDLSID->usData2 = uuid.Data2;
pDLSID->usData3 = uuid.Data3;
memcpy(pDLSID->abData, uuid.Data4, 8);
#elif defined(__APPLE__)
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
CFRelease(uuidRef);
pDLSID->ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
pDLSID->usData2 = uuid.byte4 | uuid.byte5 << 8;
pDLSID->usData3 = uuid.byte6 | uuid.byte7 << 8;
pDLSID->abData[0] = uuid.byte8;
pDLSID->abData[1] = uuid.byte9;
pDLSID->abData[2] = uuid.byte10;
pDLSID->abData[3] = uuid.byte11;
pDLSID->abData[4] = uuid.byte12;
pDLSID->abData[5] = uuid.byte13;
pDLSID->abData[6] = uuid.byte14;
pDLSID->abData[7] = uuid.byte15;
#elif defined(HAVE_UUID_GENERATE)
uuid_t uuid;
uuid_generate(uuid);
pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
pDLSID->usData2 = uuid[4] | uuid[5] << 8;
pDLSID->usData3 = uuid[6] | uuid[7] << 8;
memcpy(pDLSID->abData, &uuid[8], 8);
#else
# error "Missing support for uuid generation"
#endif
}
void Resource::CopyAssign(const Resource* orig) {
pInfo->CopyAssign(orig->pInfo);
}
// *************** Sampler ***************
// *
Sampler::Sampler(RIFF::List* ParentList) {
pParentList = ParentList;
RIFF::Chunk* wsmp = ParentList->GetSubChunk(CHUNK_ID_WSMP);
if (wsmp) {
wsmp->SetPos(0);
uiHeaderSize = wsmp->ReadUint32();
UnityNote = wsmp->ReadUint16();
FineTune = wsmp->ReadInt16();
Gain = wsmp->ReadInt32();
SamplerOptions = wsmp->ReadUint32();
SampleLoops = wsmp->ReadUint32();
} else { // 'wsmp' chunk missing
uiHeaderSize = 20;
UnityNote = 60;
FineTune = 0; // +- 0 cents
Gain = 0; // 0 dB
SamplerOptions = F_WSMP_NO_COMPRESSION;
SampleLoops = 0;
}
NoSampleDepthTruncation = SamplerOptions & F_WSMP_NO_TRUNCATION;
NoSampleCompression = SamplerOptions & F_WSMP_NO_COMPRESSION;
pSampleLoops = (SampleLoops) ? new sample_loop_t[SampleLoops] : NULL;
if (SampleLoops) {
wsmp->SetPos(uiHeaderSize);
for (uint32_t i = 0; i < SampleLoops; i++) {
wsmp->Read(pSampleLoops + i, 4, 4);
if (pSampleLoops[i].Size > sizeof(sample_loop_t)) { // if loop struct was extended
wsmp->SetPos(pSampleLoops[i].Size - sizeof(sample_loop_t), RIFF::stream_curpos);
}
}
}
}
Sampler::~Sampler() {
if (pSampleLoops) delete[] pSampleLoops;
}
void Sampler::SetGain(int32_t gain) {
Gain = gain;
}
void Sampler::UpdateChunks(progress_t* /*pProgress*/) {
// make sure 'wsmp' chunk exists
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);
int wsmpSize = uiHeaderSize + SampleLoops * 16;
if (!wsmp) {
wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize);
} else if (wsmp->GetSize() != wsmpSize) {
wsmp->Resize(wsmpSize);
}
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
// update headers size
store32(&pData[0], uiHeaderSize);
// update respective sampler options bits
SamplerOptions = (NoSampleDepthTruncation) ? SamplerOptions | F_WSMP_NO_TRUNCATION
: SamplerOptions & (~F_WSMP_NO_TRUNCATION);
SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION
: SamplerOptions & (~F_WSMP_NO_COMPRESSION);
store16(&pData[4], UnityNote);
store16(&pData[6], FineTune);
store32(&pData[8], Gain);
store32(&pData[12], SamplerOptions);
store32(&pData[16], SampleLoops);
// update loop definitions
for (uint32_t i = 0; i < SampleLoops; i++) {
//FIXME: this does not handle extended loop structs correctly
store32(&pData[uiHeaderSize + i * 16], pSampleLoops[i].Size);
store32(&pData[uiHeaderSize + i * 16 + 4], pSampleLoops[i].LoopType);
store32(&pData[uiHeaderSize + i * 16 + 8], pSampleLoops[i].LoopStart);
store32(&pData[uiHeaderSize + i * 16 + 12], pSampleLoops[i].LoopLength);
}
}
void Sampler::DeleteChunks() {
}
void Sampler::AddSampleLoop(sample_loop_t* pLoopDef) {
sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1];
// copy old loops array
for (int i = 0; i < SampleLoops; i++) {
pNewLoops[i] = pSampleLoops[i];
}
// add the new loop
pNewLoops[SampleLoops] = *pLoopDef;
// auto correct size field
pNewLoops[SampleLoops].Size = sizeof(DLS::sample_loop_t);
// free the old array and update the member variables
if (SampleLoops) delete[] pSampleLoops;
pSampleLoops = pNewLoops;
SampleLoops++;
}
void Sampler::DeleteSampleLoop(sample_loop_t* pLoopDef) {
sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops - 1];
// copy old loops array (skipping given loop)
for (int i = 0, o = 0; i < SampleLoops; i++) {
if (&pSampleLoops[i] == pLoopDef) continue;
if (o == SampleLoops - 1) {
delete[] pNewLoops;
throw Exception("Could not delete Sample Loop, because it does not exist");
}
pNewLoops[o] = pSampleLoops[i];
o++;
}
// free the old array and update the member variables
if (SampleLoops) delete[] pSampleLoops;
pSampleLoops = pNewLoops;
SampleLoops--;
}
void Sampler::CopyAssign(const Sampler* orig) {
// copy trivial scalars
UnityNote = orig->UnityNote;
FineTune = orig->FineTune;
Gain = orig->Gain;
NoSampleDepthTruncation = orig->NoSampleDepthTruncation;
NoSampleCompression = orig->NoSampleCompression;
SamplerOptions = orig->SamplerOptions;
// copy sample loops
if (SampleLoops) delete[] pSampleLoops;
pSampleLoops = new sample_loop_t[orig->SampleLoops];
memcpy(pSampleLoops, orig->pSampleLoops, orig->SampleLoops * sizeof(sample_loop_t));
SampleLoops = orig->SampleLoops;
}
// *************** Sample ***************
// *
Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset) : Resource(pFile, waveList) {
pWaveList = waveList;
ullWavePoolOffset = WavePoolOffset - LIST_HEADER_SIZE(waveList->GetFile()->GetFileOffsetSize());
pCkFormat = waveList->GetSubChunk(CHUNK_ID_FMT);
pCkData = waveList->GetSubChunk(CHUNK_ID_DATA);
if (pCkFormat) {
pCkFormat->SetPos(0);
// common fields
FormatTag = pCkFormat->ReadUint16();
Channels = pCkFormat->ReadUint16();
SamplesPerSecond = pCkFormat->ReadUint32();
AverageBytesPerSecond = pCkFormat->ReadUint32();
BlockAlign = pCkFormat->ReadUint16();
// PCM format specific
if (FormatTag == DLS_WAVE_FORMAT_PCM) {
BitDepth = pCkFormat->ReadUint16();
FrameSize = (BitDepth / 8) * Channels;
} else { // unsupported sample data format
BitDepth = 0;
FrameSize = 0;
}
} else { // 'fmt' chunk missing
FormatTag = DLS_WAVE_FORMAT_PCM;
BitDepth = 16;
Channels = 1;
SamplesPerSecond = 44100;
AverageBytesPerSecond = (BitDepth / 8) * SamplesPerSecond * Channels;
FrameSize = (BitDepth / 8) * Channels;
BlockAlign = FrameSize;
}
SamplesTotal = (pCkData) ? (FormatTag == DLS_WAVE_FORMAT_PCM) ? pCkData->GetSize() / FrameSize
: 0
: 0;
}
Sample::~Sample() {
if (pCkData)
pCkData->ReleaseChunkData();
if (pCkFormat)
pCkFormat->ReleaseChunkData();
}
void Sample::DeleteChunks() {
// handle base class
Resource::DeleteChunks();
// handle own RIFF chunks
if (pWaveList) {
RIFF::List* pParent = pWaveList->GetParent();
pParent->DeleteSubChunk(pWaveList);
pWaveList = NULL;
}
}
void Sample::CopyAssignCore(const Sample* orig) {
// handle base classes
Resource::CopyAssign(orig);
// handle actual own attributes of this class
FormatTag = orig->FormatTag;
Channels = orig->Channels;
SamplesPerSecond = orig->SamplesPerSecond;
AverageBytesPerSecond = orig->AverageBytesPerSecond;
BlockAlign = orig->BlockAlign;
BitDepth = orig->BitDepth;
SamplesTotal = orig->SamplesTotal;
FrameSize = orig->FrameSize;
}
void Sample::CopyAssign(const Sample* orig) {
CopyAssignCore(orig);
// copy sample waveform data (reading directly from disc)
Resize(orig->GetSize());
char* buf = (char*) LoadSampleData();
Sample* pOrig = (Sample*) orig; //HACK: circumventing the constness here for now
const file_offset_t restorePos = pOrig->pCkData->GetPos();
pOrig->SetPos(0);
for (file_offset_t todo = pOrig->GetSize(), i = 0; todo; ) {
const int iReadAtOnce = 64*1024;
file_offset_t n = (iReadAtOnce < todo) ? iReadAtOnce : todo;
n = pOrig->Read(&buf[i], n);
if (!n) break;
todo -= n;
i += (n * pOrig->FrameSize);
}
pOrig->pCkData->SetPos(restorePos);
}
void* Sample::LoadSampleData() {
return (pCkData) ? pCkData->LoadChunkData() : NULL;
}
void Sample::ReleaseSampleData() {
if (pCkData) pCkData->ReleaseChunkData();
}
file_offset_t Sample::GetSize() const {
if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0;
return (pCkData) ? pCkData->GetSize() / FrameSize : 0;
}
void Sample::Resize(file_offset_t NewSize) {
if (FormatTag != DLS_WAVE_FORMAT_PCM) throw Exception("Sample's format is not DLS_WAVE_FORMAT_PCM");
if (NewSize < 1) throw Exception("Sample size must be at least one sample point");
if ((NewSize >> 48) != 0)
throw Exception("Unrealistic high DLS sample size detected");
const file_offset_t sizeInBytes = NewSize * FrameSize;
pCkData = pWaveList->GetSubChunk(CHUNK_ID_DATA);
if (pCkData) pCkData->Resize(sizeInBytes);
else pCkData = pWaveList->AddSubChunk(CHUNK_ID_DATA, sizeInBytes);
}
file_offset_t Sample::SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence) {
if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
if (!pCkData) throw Exception("No data chunk created for sample yet, call Sample::Resize() to create one");
file_offset_t orderedBytes = SampleCount * FrameSize;
file_offset_t result = pCkData->SetPos(orderedBytes, Whence);
return (result == orderedBytes) ? SampleCount
: result / FrameSize;
}
file_offset_t Sample::Read(void* pBuffer, file_offset_t SampleCount) {
if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
}
file_offset_t Sample::Write(void* pBuffer, file_offset_t SampleCount) {
if (FormatTag != DLS_WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small");
return pCkData->Write(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
}
void Sample::UpdateChunks(progress_t* pProgress) {
if (FormatTag != DLS_WAVE_FORMAT_PCM)
throw Exception("Could not save sample, only PCM format is supported");
// we refuse to do anything if not sample wave form was provided yet
if (!pCkData)
throw Exception("Could not save sample, there is no sample data to save");
// update chunks of base class as well
Resource::UpdateChunks(pProgress);
// make sure 'fmt' chunk exists
RIFF::Chunk* pCkFormat = pWaveList->GetSubChunk(CHUNK_ID_FMT);
if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format
uint8_t* pData = (uint8_t*) pCkFormat->LoadChunkData();
// update 'fmt' chunk
store16(&pData[0], FormatTag);
store16(&pData[2], Channels);
store32(&pData[4], SamplesPerSecond);
store32(&pData[8], AverageBytesPerSecond);
store16(&pData[12], BlockAlign);
store16(&pData[14], BitDepth); // assuming PCM format
}
// *************** Region ***************
// *
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : Resource(pInstrument, rgnList), Articulator(rgnList), Sampler(rgnList) {
pCkRegion = rgnList;
// articulation information
RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);
if (rgnh) {
rgnh->SetPos(0);
rgnh->Read(&KeyRange, 2, 2);
rgnh->Read(&VelocityRange, 2, 2);
FormatOptionFlags = rgnh->ReadUint16();
KeyGroup = rgnh->ReadUint16();
// Layer is optional
if (rgnh->RemainingBytes() >= sizeof(uint16_t)) {
rgnh->Read(&Layer, 1, sizeof(uint16_t));
} else Layer = 0;
} else { // 'rgnh' chunk is missing
KeyRange.low = 0;
KeyRange.high = 127;
VelocityRange.low = 0;
VelocityRange.high = 127;
FormatOptionFlags = F_RGN_OPTION_SELFNONEXCLUSIVE;
KeyGroup = 0;
Layer = 0;
}
SelfNonExclusive = FormatOptionFlags & F_RGN_OPTION_SELFNONEXCLUSIVE;
// sample information
RIFF::Chunk* wlnk = rgnList->GetSubChunk(CHUNK_ID_WLNK);
if (wlnk) {
wlnk->SetPos(0);
WaveLinkOptionFlags = wlnk->ReadUint16();
PhaseGroup = wlnk->ReadUint16();
Channel = wlnk->ReadUint32();
WavePoolTableIndex = wlnk->ReadUint32();
} else { // 'wlnk' chunk is missing
WaveLinkOptionFlags = 0;
PhaseGroup = 0;
Channel = 0; // mono
WavePoolTableIndex = 0; // first entry in wave pool table
}
PhaseMaster = WaveLinkOptionFlags & F_WAVELINK_PHASE_MASTER;
MultiChannel = WaveLinkOptionFlags & F_WAVELINK_MULTICHANNEL;
pSample = NULL;
}
Region::~Region() {
}
void Region::DeleteChunks() {
// handle base classes
Resource::DeleteChunks();
Articulator::DeleteChunks();
Sampler::DeleteChunks();
// handle own RIFF chunks
if (pCkRegion) {
RIFF::List* pParent = pCkRegion->GetParent();
pParent->DeleteSubChunk(pCkRegion);
pCkRegion = NULL;
}
}
Sample* Region::GetSample() {
if (pSample) return pSample;
File* file = (File*) GetParent()->GetParent();
uint64_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
size_t i = 0;
for (Sample* sample = file->GetSample(i); sample;
sample = file->GetSample(++i))
{
if (sample->ullWavePoolOffset == soughtoffset) return (pSample = sample);
}
return NULL;
}
void Region::SetSample(Sample* pSample) {
this->pSample = pSample;
WavePoolTableIndex = 0; // we update this offset when we Save()
}
void Region::SetKeyRange(uint16_t Low, uint16_t High) {
KeyRange.low = Low;
KeyRange.high = High;
// make sure regions are already loaded
Instrument* pInstrument = (Instrument*) GetParent();
if (!pInstrument->pRegions) pInstrument->LoadRegions();
if (!pInstrument->pRegions) return;
// find the r which is the first one to the right of this region
// at its new position
Region* r = NULL;
Region* prev_region = NULL;
for (
Instrument::RegionList::iterator iter = pInstrument->pRegions->begin();
iter != pInstrument->pRegions->end(); iter++
) {
if ((*iter)->KeyRange.low > this->KeyRange.low) {
r = *iter;
break;
}
prev_region = *iter;
}
// place this region before r if it's not already there
if (prev_region != this) pInstrument->MoveRegion(this, r);
}
void Region::UpdateChunks(progress_t* pProgress) {
// make sure 'rgnh' chunk exists
RIFF::Chunk* rgnh = pCkRegion->GetSubChunk(CHUNK_ID_RGNH);
if (!rgnh) rgnh = pCkRegion->AddSubChunk(CHUNK_ID_RGNH, Layer ? 14 : 12);
uint8_t* pData = (uint8_t*) rgnh->LoadChunkData();
FormatOptionFlags = (SelfNonExclusive)
? FormatOptionFlags | F_RGN_OPTION_SELFNONEXCLUSIVE
: FormatOptionFlags & (~F_RGN_OPTION_SELFNONEXCLUSIVE);
// update 'rgnh' chunk
store16(&pData[0], KeyRange.low);
store16(&pData[2], KeyRange.high);
store16(&pData[4], VelocityRange.low);
store16(&pData[6], VelocityRange.high);
store16(&pData[8], FormatOptionFlags);
store16(&pData[10], KeyGroup);
if (rgnh->GetSize() >= 14) store16(&pData[12], Layer);
// update chunks of base classes as well (but skip Resource,
// as a rgn doesn't seem to have dlid and INFO chunks)
Articulator::UpdateChunks(pProgress);
Sampler::UpdateChunks(pProgress);
// make sure 'wlnk' chunk exists
RIFF::Chunk* wlnk = pCkRegion->GetSubChunk(CHUNK_ID_WLNK);
if (!wlnk) wlnk = pCkRegion->AddSubChunk(CHUNK_ID_WLNK, 12);
pData = (uint8_t*) wlnk->LoadChunkData();
WaveLinkOptionFlags = (PhaseMaster)
? WaveLinkOptionFlags | F_WAVELINK_PHASE_MASTER
: WaveLinkOptionFlags & (~F_WAVELINK_PHASE_MASTER);
WaveLinkOptionFlags = (MultiChannel)
? WaveLinkOptionFlags | F_WAVELINK_MULTICHANNEL
: WaveLinkOptionFlags & (~F_WAVELINK_MULTICHANNEL);
// get sample's wave pool table index
int index = -1;
File* pFile = (File*) GetParent()->GetParent();
if (pFile->pSamples) {
File::SampleList::iterator iter = pFile->pSamples->begin();
File::SampleList::iterator end = pFile->pSamples->end();
for (int i = 0; iter != end; ++iter, i++) {
if (*iter == pSample) {
index = i;
break;
}
}
}
WavePoolTableIndex = index;
// update 'wlnk' chunk
store16(&pData[0], WaveLinkOptionFlags);
store16(&pData[2], PhaseGroup);
store32(&pData[4], Channel);
store32(&pData[8], WavePoolTableIndex);
}
void Region::CopyAssign(const Region* orig) {
// handle base classes
Resource::CopyAssign(orig);
Articulator::CopyAssign(orig);
Sampler::CopyAssign(orig);
// handle actual own attributes of this class
// (the trivial ones)
VelocityRange = orig->VelocityRange;
KeyGroup = orig->KeyGroup;
Layer = orig->Layer;
SelfNonExclusive = orig->SelfNonExclusive;
PhaseMaster = orig->PhaseMaster;
PhaseGroup = orig->PhaseGroup;
MultiChannel = orig->MultiChannel;
Channel = orig->Channel;
// only take the raw sample reference if the two Region objects are
// part of the same file
if (GetParent()->GetParent() == orig->GetParent()->GetParent()) {
WavePoolTableIndex = orig->WavePoolTableIndex;
pSample = orig->pSample;
} else {
WavePoolTableIndex = -1;
pSample = NULL;
}
FormatOptionFlags = orig->FormatOptionFlags;
WaveLinkOptionFlags = orig->WaveLinkOptionFlags;
// handle the last, a bit sensible attribute
SetKeyRange(orig->KeyRange.low, orig->KeyRange.high);
}
// *************** Instrument ***************
// *
Instrument::Instrument(File* pFile, RIFF::List* insList) : Resource(pFile, insList), Articulator(insList) {
pCkInstrument = insList;
midi_locale_t locale;
RIFF::Chunk* insh = pCkInstrument->GetSubChunk(CHUNK_ID_INSH);
if (insh) {
insh->SetPos(0);
Regions = insh->ReadUint32();
insh->Read(&locale, 2, 4);
} else { // 'insh' chunk missing
Regions = 0;
locale.bank = 0;
locale.instrument = 0;
}
MIDIProgram = locale.instrument;
IsDrum = locale.bank & DRUM_TYPE_MASK;
MIDIBankCoarse = (uint8_t) MIDI_BANK_COARSE(locale.bank);
MIDIBankFine = (uint8_t) MIDI_BANK_FINE(locale.bank);
MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine);
pRegions = NULL;
}
size_t Instrument::CountRegions() {
if (!pRegions) LoadRegions();
if (!pRegions) return 0;
return pRegions->size();
}
Region* Instrument::GetRegionAt(size_t pos) {
if (!pRegions) LoadRegions();
if (!pRegions) return NULL;
if (pos >= pRegions->size()) return NULL;
return (*pRegions)[pos];
}
Region* Instrument::GetFirstRegion() {
if (!pRegions) LoadRegions();
if (!pRegions) return NULL;
RegionsIterator = pRegions->begin();
return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
}
Region* Instrument::GetNextRegion() {
if (!pRegions) return NULL;
RegionsIterator++;
return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL;
}
void Instrument::LoadRegions() {
if (!pRegions) pRegions = new RegionList;
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
if (lrgn) {
uint32_t regionCkType = (lrgn->GetSubList(LIST_TYPE_RGN2)) ? LIST_TYPE_RGN2 : LIST_TYPE_RGN; // prefer regions level 2
size_t i = 0;
for (RIFF::List* rgn = lrgn->GetSubListAt(i); rgn;
rgn = lrgn->GetSubListAt(++i))
{
if (rgn->GetListType() == regionCkType) {
pRegions->push_back(new Region(this, rgn));
}
}
}
}
Region* Instrument::AddRegion() {
if (!pRegions) LoadRegions();
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN);
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
Region* pNewRegion = new Region(this, rgn);
const size_t idxIt = RegionsIterator - pRegions->begin();
pRegions->push_back(pNewRegion);
RegionsIterator = pRegions->begin() + std::min(idxIt, pRegions->size()); // avoid iterator invalidation
Regions = (uint32_t) pRegions->size();
return pNewRegion;
}
void Instrument::MoveRegion(Region* pSrc, Region* pDst) {
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN);
lrgn->MoveSubChunk(pSrc->pCkRegion, (RIFF::Chunk*) (pDst ? pDst->pCkRegion : 0));
for (size_t i = 0; i < pRegions->size(); ++i) {
if ((*pRegions)[i] == pSrc) {
const size_t idxIt = RegionsIterator - pRegions->begin();
pRegions->erase(pRegions->begin() + i);
RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pDst);
pRegions->insert(iter, pSrc);
RegionsIterator = pRegions->begin() + std::min(idxIt, pRegions->size()); // avoid iterator invalidation
}
}
}
void Instrument::DeleteRegion(Region* pRegion) {
if (!pRegions) return;
RegionList::iterator iter = find(pRegions->begin(), pRegions->end(), pRegion);
if (iter == pRegions->end()) return;
const size_t idxIt = RegionsIterator - pRegions->begin();
pRegions->erase(iter);
RegionsIterator = pRegions->begin() + std::min(idxIt, pRegions->size()); // avoid iterator invalidation
Regions = (uint32_t) pRegions->size();
pRegion->DeleteChunks();
delete pRegion;
}
void Instrument::UpdateChunks(progress_t* pProgress) {
// first update base classes' chunks
Resource::UpdateChunks(pProgress);
Articulator::UpdateChunks(pProgress);
// make sure 'insh' chunk exists
RIFF::Chunk* insh = pCkInstrument->GetSubChunk(CHUNK_ID_INSH);
if (!insh) insh = pCkInstrument->AddSubChunk(CHUNK_ID_INSH, 12);
uint8_t* pData = (uint8_t*) insh->LoadChunkData();
// update 'insh' chunk
Regions = (pRegions) ? uint32_t(pRegions->size()) : 0;
midi_locale_t locale;
locale.instrument = MIDIProgram;
locale.bank = MIDI_BANK_ENCODE(MIDIBankCoarse, MIDIBankFine);
locale.bank = (IsDrum) ? locale.bank | DRUM_TYPE_MASK : locale.bank & (~DRUM_TYPE_MASK);
MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine); // just a sync, when we're at it
store32(&pData[0], Regions);
store32(&pData[4], locale.bank);
store32(&pData[8], locale.instrument);
// update Region's chunks
if (!pRegions) return;
RegionList::iterator iter = pRegions->begin();
RegionList::iterator end = pRegions->end();
for (int i = 0; iter != end; ++iter, ++i) {
if (pProgress) {
// divide local progress into subprogress
progress_t subprogress;
__divide_progress(pProgress, &subprogress, pRegions->size(), i);
// do the actual work
(*iter)->UpdateChunks(&subprogress);
} else
(*iter)->UpdateChunks(NULL);
}
if (pProgress)
__notify_progress(pProgress, 1.0); // notify done
}
Instrument::~Instrument() {
if (pRegions) {
RegionList::iterator iter = pRegions->begin();
RegionList::iterator end = pRegions->end();
while (iter != end) {
delete *iter;
iter++;
}
delete pRegions;
}
}
void Instrument::DeleteChunks() {
// handle base classes
Resource::DeleteChunks();
Articulator::DeleteChunks();
// handle RIFF chunks of members
if (pRegions) {
RegionList::iterator it = pRegions->begin();
RegionList::iterator end = pRegions->end();
for (; it != end; ++it)
(*it)->DeleteChunks();
}
// handle own RIFF chunks
if (pCkInstrument) {
RIFF::List* pParent = pCkInstrument->GetParent();
pParent->DeleteSubChunk(pCkInstrument);
pCkInstrument = NULL;
}
}
void Instrument::CopyAssignCore(const Instrument* orig) {
// handle base classes
Resource::CopyAssign(orig);
Articulator::CopyAssign(orig);
// handle actual own attributes of this class
// (the trivial ones)
IsDrum = orig->IsDrum;
MIDIBank = orig->MIDIBank;
MIDIBankCoarse = orig->MIDIBankCoarse;
MIDIBankFine = orig->MIDIBankFine;
MIDIProgram = orig->MIDIProgram;
}
void Instrument::CopyAssign(const Instrument* orig) {
CopyAssignCore(orig);
// delete all regions first
while (Regions) DeleteRegion(GetRegionAt(0));
// now recreate and copy regions
{
RegionList::const_iterator it = orig->pRegions->begin();
for (int i = 0; i < orig->Regions; ++i, ++it) {
Region* dstRgn = AddRegion();
//NOTE: Region does semi-deep copy !
dstRgn->CopyAssign(*it);
}
}
}
// *************** File ***************
// *
File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) {
pRIFF->SetByteOrder(RIFF::endian_little);
bOwningRiff = true;
pVersion = new version_t;
pVersion->major = 0;
pVersion->minor = 0;
pVersion->release = 0;
pVersion->build = 0;
Instruments = 0;
WavePoolCount = 0;
pWavePoolTable = NULL;
pWavePoolTableHi = NULL;
WavePoolHeaderSize = 8;
pSamples = NULL;
pInstruments = NULL;
b64BitWavePoolOffsets = false;
}
File::File(RIFF::File* pRIFF) : Resource(NULL, pRIFF) {
if (!pRIFF) throw DLS::Exception("NULL pointer reference to RIFF::File object.");
this->pRIFF = pRIFF;
bOwningRiff = false;
RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
if (ckVersion) {
ckVersion->SetPos(0);
pVersion = new version_t;
ckVersion->Read(pVersion, 4, 2);
}
else pVersion = NULL;
RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
if (!colh) throw DLS::Exception("Mandatory chunks in RIFF list chunk not found.");
colh->SetPos(0);
Instruments = colh->ReadUint32();
RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
if (!ptbl) { // pool table is missing - this is probably an ".art" file
WavePoolCount = 0;
pWavePoolTable = NULL;
pWavePoolTableHi = NULL;
WavePoolHeaderSize = 8;
b64BitWavePoolOffsets = false;
} else {
ptbl->SetPos(0);
WavePoolHeaderSize = ptbl->ReadUint32();
WavePoolCount = ptbl->ReadUint32();
pWavePoolTable = new uint32_t[WavePoolCount];
pWavePoolTableHi = new uint32_t[WavePoolCount];
ptbl->SetPos(WavePoolHeaderSize);
// Check for 64 bit offsets (used in gig v3 files)
b64BitWavePoolOffsets = (ptbl->GetSize() - WavePoolHeaderSize == WavePoolCount * 8);
if (b64BitWavePoolOffsets) {
for (int i = 0 ; i < WavePoolCount ; i++) {
pWavePoolTableHi[i] = ptbl->ReadUint32();
pWavePoolTable[i] = ptbl->ReadUint32();
//NOTE: disabled this 2GB check, not sure why this check was still left here (Christian, 2016-05-12)
//if (pWavePoolTable[i] & 0x80000000)
// throw DLS::Exception("Files larger than 2 GB not yet supported");
}
} else { // conventional 32 bit offsets
ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;
}
}
pSamples = NULL;
pInstruments = NULL;
}
File::~File() {
if (pInstruments) {
InstrumentList::iterator iter = pInstruments->begin();
InstrumentList::iterator end = pInstruments->end();
while (iter != end) {
delete *iter;
iter++;
}
delete pInstruments;
}
if (pSamples) {
SampleList::iterator iter = pSamples->begin();
SampleList::iterator end = pSamples->end();
while (iter != end) {
delete *iter;
iter++;
}
delete pSamples;
}
if (pWavePoolTable) delete[] pWavePoolTable;
if (pWavePoolTableHi) delete[] pWavePoolTableHi;
if (pVersion) delete pVersion;
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
delete *i;
if (bOwningRiff)
delete pRIFF;
}
Sample* File::GetSample(size_t index) {
if (!pSamples) LoadSamples();
if (!pSamples) return NULL;
if (index >= pSamples->size()) return NULL;
return (*pSamples)[index];
}
Sample* File::GetFirstSample() {
if (!pSamples) LoadSamples();
if (!pSamples) return NULL;
SamplesIterator = pSamples->begin();
return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
}
Sample* File::GetNextSample() {
if (!pSamples) return NULL;
SamplesIterator++;
return (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL;
}
void File::LoadSamples() {
if (!pSamples) pSamples = new SampleList;
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
if (wvpl) {
file_offset_t wvplFileOffset = wvpl->GetFilePos() -
wvpl->GetPos(); // should be zero, but just to be sure
size_t i = 0;
for (RIFF::List* wave = wvpl->GetSubListAt(i); wave;
wave = wvpl->GetSubListAt(++i))
{
if (wave->GetListType() == LIST_TYPE_WAVE) {
file_offset_t waveFileOffset = wave->GetFilePos() -
wave->GetPos(); // should be zero, but just to be sure
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));
}
}
}
else { // Seen a dwpl list chunk instead of a wvpl list chunk in some file (officially not DLS compliant)
RIFF::List* dwpl = pRIFF->GetSubList(LIST_TYPE_DWPL);
if (dwpl) {
file_offset_t dwplFileOffset = dwpl->GetFilePos() -
dwpl->GetPos(); // should be zero, but just to be sure
size_t i = 0;
for (RIFF::List* wave = dwpl->GetSubListAt(i); wave;
wave = dwpl->GetSubListAt(++i))
{
if (wave->GetListType() == LIST_TYPE_WAVE) {
file_offset_t waveFileOffset = wave->GetFilePos() -
wave->GetPos(); // should be zero, but just to be sure
pSamples->push_back(new Sample(this, wave, waveFileOffset - dwplFileOffset));
}
}
}
}
}
size_t File::CountSamples() {
if (!pSamples) LoadSamples();
if (!pSamples) return 0;
return pSamples->size();
}
Sample* File::AddSample() {
if (!pSamples) LoadSamples();
__ensureMandatoryChunksExist();
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
// create new Sample object and its respective 'wave' list chunk
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE);
Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/);
const size_t idxIt = SamplesIterator - pSamples->begin();
pSamples->push_back(pSample);
SamplesIterator = pSamples->begin() + std::min(idxIt, pSamples->size()); // avoid iterator invalidation
return pSample;
}
void File::DeleteSample(Sample* pSample) {
if (!pSamples) return;
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample);
if (iter == pSamples->end()) return;
const size_t idxIt = SamplesIterator - pSamples->begin();
pSamples->erase(iter);
SamplesIterator = pSamples->begin() + std::min(idxIt, pSamples->size()); // avoid iterator invalidation
pSample->DeleteChunks();
delete pSample;
}
Instrument* File::GetInstrument(size_t index) {
if (!pInstruments) LoadInstruments();
if (!pInstruments) return NULL;
if (index >= pInstruments->size()) return NULL;
return (*pInstruments)[index];
}
Instrument* File::GetFirstInstrument() {
if (!pInstruments) LoadInstruments();
if (!pInstruments) return NULL;
InstrumentsIterator = pInstruments->begin();
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
}
Instrument* File::GetNextInstrument() {
if (!pInstruments) return NULL;
InstrumentsIterator++;
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL;
}
void File::LoadInstruments() {
if (!pInstruments) pInstruments = new InstrumentList;
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
if (lstInstruments) {
size_t i = 0;
for (RIFF::List* lstInstr = lstInstruments->GetSubListAt(i);
lstInstr; lstInstr = lstInstruments->GetSubListAt(++i))
{
if (lstInstr->GetListType() == LIST_TYPE_INS) {
pInstruments->push_back(new Instrument(this, lstInstr));
}
}
}
}
Instrument* File::AddInstrument() {
if (!pInstruments) LoadInstruments();
__ensureMandatoryChunksExist();
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS);
Instrument* pInstrument = new Instrument(this, lstInstr);
const size_t idxIt = InstrumentsIterator - pInstruments->begin();
pInstruments->push_back(pInstrument);
InstrumentsIterator = pInstruments->begin() + std::min(idxIt, pInstruments->size()); // avoid iterator invalidation
return pInstrument;
}
void File::DeleteInstrument(Instrument* pInstrument) {
if (!pInstruments) return;
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument);
if (iter == pInstruments->end()) return;
const size_t idxIt = InstrumentsIterator - pInstruments->begin();
pInstruments->erase(iter);
InstrumentsIterator = pInstruments->begin() + std::min(idxIt, pInstruments->size()); // avoid iterator invalidation
pInstrument->DeleteChunks();
delete pInstrument;
}
RIFF::File* File::GetRiffFile() {
return pRIFF;
}
RIFF::File* File::GetExtensionFile(int index) {
if (index < 0 || index >= ExtensionFiles.size()) return NULL;
std::list<RIFF::File*>::iterator iter = ExtensionFiles.begin();
for (int i = 0; iter != ExtensionFiles.end(); ++iter, ++i)
if (i == index) return *iter;
return NULL;
}
String File::GetFileName() {
return pRIFF->GetFileName();
}
void File::SetFileName(const String& name) {
pRIFF->SetFileName(name);
}
void File::UpdateChunks(progress_t* pProgress) {
// first update base class's chunks
Resource::UpdateChunks(pProgress);
// if version struct exists, update 'vers' chunk
if (pVersion) {
RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
if (!ckVersion) ckVersion = pRIFF->AddSubChunk(CHUNK_ID_VERS, 8);
uint8_t* pData = (uint8_t*) ckVersion->LoadChunkData();
store16(&pData[0], pVersion->minor);
store16(&pData[2], pVersion->major);
store16(&pData[4], pVersion->build);
store16(&pData[6], pVersion->release);
}
// update 'colh' chunk
Instruments = (pInstruments) ? uint32_t(pInstruments->size()) : 0;
RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH);
if (!colh) colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);
uint8_t* pData = (uint8_t*) colh->LoadChunkData();
store32(pData, Instruments);
// update instrument's chunks
if (pInstruments) {
if (pProgress) {
// divide local progress into subprogress
progress_t subprogress;
__divide_progress(pProgress, &subprogress, 20.f, 0.f); // arbitrarily subdivided into 5% of total progress
// do the actual work
InstrumentList::iterator iter = pInstruments->begin();
InstrumentList::iterator end = pInstruments->end();
for (int i = 0; iter != end; ++iter, ++i) {
// divide subprogress into sub-subprogress
progress_t subsubprogress;
__divide_progress(&subprogress, &subsubprogress, pInstruments->size(), i);
// do the actual work
(*iter)->UpdateChunks(&subsubprogress);
}
__notify_progress(&subprogress, 1.0); // notify subprogress done
} else {
InstrumentList::iterator iter = pInstruments->begin();
InstrumentList::iterator end = pInstruments->end();
for (int i = 0; iter != end; ++iter, ++i) {
(*iter)->UpdateChunks(NULL);
}
}
}
// update 'ptbl' chunk
const int iSamples = (pSamples) ? int(pSamples->size()) : 0;
int iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
if (!ptbl) ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, 1 /*anything, we'll resize*/);
int iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
ptbl->Resize(iPtblSize);
pData = (uint8_t*) ptbl->LoadChunkData();
WavePoolCount = iSamples;
store32(&pData[4], WavePoolCount);
// we actually update the sample offsets in the pool table when we Save()
memset(&pData[WavePoolHeaderSize], 0, iPtblSize - WavePoolHeaderSize);
// update sample's chunks
if (pSamples) {
if (pProgress) {
// divide local progress into subprogress
progress_t subprogress;
__divide_progress(pProgress, &subprogress, 20.f, 1.f); // arbitrarily subdivided into 95% of total progress
// do the actual work
SampleList::iterator iter = pSamples->begin();
SampleList::iterator end = pSamples->end();
for (int i = 0; iter != end; ++iter, ++i) {
// divide subprogress into sub-subprogress
progress_t subsubprogress;
__divide_progress(&subprogress, &subsubprogress, pSamples->size(), i);
// do the actual work
(*iter)->UpdateChunks(&subsubprogress);
}
__notify_progress(&subprogress, 1.0); // notify subprogress done
} else {
SampleList::iterator iter = pSamples->begin();
SampleList::iterator end = pSamples->end();
for (int i = 0; iter != end; ++iter, ++i) {
(*iter)->UpdateChunks(NULL);
}
}
}
// if there are any extension files, gather which ones are regular
// extension files used as wave pool files (.gx00, .gx01, ... , .gx98)
// and which one is probably a convolution (GigaPulse) file (always to
// be saved as .gx99)
std::list<RIFF::File*> poolFiles; // < for (.gx00, .gx01, ... , .gx98) files
RIFF::File* pGigaPulseFile = NULL; // < for .gx99 file
if (!ExtensionFiles.empty()) {
std::list<RIFF::File*>::iterator it = ExtensionFiles.begin();
for (; it != ExtensionFiles.end(); ++it) {
//FIXME: the .gx99 file is always used by GSt for convolution
// data (GigaPulse); so we should better detect by subchunk
// whether the extension file is intended for convolution
// instead of checkking for a file name, because the latter does
// not work for saving new gigs created from scratch
const std::string oldName = (*it)->GetFileName();
const bool isGigaPulseFile = (extensionOfPath(oldName) == "gx99");
if (isGigaPulseFile)
pGigaPulseFile = *it;
else
poolFiles.push_back(*it);
}
}
// update the 'xfil' chunk which describes all extension files (wave
// pool files) except the .gx99 file
if (!poolFiles.empty()) {
const int n = poolFiles.size();
const int iHeaderSize = 4;
const int iEntrySize = 144;
// make sure chunk exists, and with correct size
RIFF::Chunk* ckXfil = pRIFF->GetSubChunk(CHUNK_ID_XFIL);
if (ckXfil)
ckXfil->Resize(iHeaderSize + n * iEntrySize);
else
ckXfil = pRIFF->AddSubChunk(CHUNK_ID_XFIL, iHeaderSize + n * iEntrySize);
uint8_t* pData = (uint8_t*) ckXfil->LoadChunkData();
// re-assemble the chunk's content
store32(pData, n);
std::list<RIFF::File*>::iterator itExtFile = poolFiles.begin();
for (int i = 0, iOffset = 4; i < n;
++itExtFile, ++i, iOffset += iEntrySize)
{
// update the filename string and 5 byte extension of each extension file
std::string file = lastPathComponent(
(*itExtFile)->GetFileName()
);
if (file.length() + 6 > 128)
throw Exception("Fatal error, extension filename length exceeds 122 byte maximum");
uint8_t* pStrings = &pData[iOffset];
memset(pStrings, 0, 128);
memcpy(pStrings, file.c_str(), file.length());
pStrings += file.length() + 1;
std::string ext = file.substr(file.length()-5);
memcpy(pStrings, ext.c_str(), 5);
// update the dlsid of the extension file
uint8_t* pId = &pData[iOffset + 128];
dlsid_t id;
RIFF::Chunk* ckDLSID = (*itExtFile)->GetSubChunk(CHUNK_ID_DLID);
if (ckDLSID) {
ckDLSID->Read(&id.ulData1, 1, 4);
ckDLSID->Read(&id.usData2, 1, 2);
ckDLSID->Read(&id.usData3, 1, 2);
ckDLSID->Read(id.abData, 8, 1);
} else {
ckDLSID = (*itExtFile)->AddSubChunk(CHUNK_ID_DLID, 16);
Resource::GenerateDLSID(&id);
uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
store32(&pData[0], id.ulData1);
store16(&pData[4], id.usData2);
store16(&pData[6], id.usData3);
memcpy(&pData[8], id.abData, 8);
}
store32(&pId[0], id.ulData1);
store16(&pId[4], id.usData2);
store16(&pId[6], id.usData3);
memcpy(&pId[8], id.abData, 8);
}
} else {
// in case there was a 'xfil' chunk, remove it
RIFF::Chunk* ckXfil = pRIFF->GetSubChunk(CHUNK_ID_XFIL);
if (ckXfil) pRIFF->DeleteSubChunk(ckXfil);
}
// update the 'doxf' chunk which describes a .gx99 extension file
// which contains convolution data (GigaPulse)
if (pGigaPulseFile) {
RIFF::Chunk* ckDoxf = pRIFF->GetSubChunk(CHUNK_ID_DOXF);
if (!ckDoxf) ckDoxf = pRIFF->AddSubChunk(CHUNK_ID_DOXF, 148);
uint8_t* pData = (uint8_t*) ckDoxf->LoadChunkData();
// update the dlsid from the extension file
uint8_t* pId = &pData[132];
RIFF::Chunk* ckDLSID = pGigaPulseFile->GetSubChunk(CHUNK_ID_DLID);
if (!ckDLSID) { //TODO: auto generate DLS ID if missing
throw Exception("Fatal error, GigaPulse file does not contain a DLS ID chunk");
} else {
dlsid_t id;
// read DLS ID from extension files's DLS ID chunk
uint8_t* pData = (uint8_t*) ckDLSID->LoadChunkData();
id.ulData1 = load32(&pData[0]);
id.usData2 = load16(&pData[4]);
id.usData3 = load16(&pData[6]);
memcpy(id.abData, &pData[8], 8);
// store DLS ID to 'doxf' chunk
store32(&pId[0], id.ulData1);
store16(&pId[4], id.usData2);
store16(&pId[6], id.usData3);
memcpy(&pId[8], id.abData, 8);
}
} else {
// in case there was a 'doxf' chunk, remove it
RIFF::Chunk* ckDoxf = pRIFF->GetSubChunk(CHUNK_ID_DOXF);
if (ckDoxf) pRIFF->DeleteSubChunk(ckDoxf);
}
// the RIFF file to be written might now been grown >= 4GB or might
// been shrunk < 4GB, so we might need to update the wave pool offset
// size and thus accordingly we would need to resize the wave pool
// chunk
const file_offset_t finalFileSize = pRIFF->GetRequiredFileSize();
const bool bRequires64Bit = (finalFileSize >> 32) != 0 || // < native 64 bit gig file
poolFiles.size() > 0; // < 32 bit gig file where the hi 32 bits are used as extension file nr
if (b64BitWavePoolOffsets != bRequires64Bit) {
b64BitWavePoolOffsets = bRequires64Bit;
iPtblOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
iPtblSize = WavePoolHeaderSize + iPtblOffsetSize * iSamples;
ptbl->Resize(iPtblSize);
}
if (pProgress)
__notify_progress(pProgress, 1.0); // notify done
}
void File::Save(const String& Path, progress_t* pProgress) {
// ensure original file is open at least in read-only mode
// (because it might be closed if this method is called from another
// thread than file was loaded on - if IsIOPerThread() was enabled)
if (pRIFF->GetMode() == RIFF::stream_mode_closed && !pRIFF->IsNew())
pRIFF->SetMode(RIFF::stream_mode_read);
// calculate number of tasks to notify progress appropriately
const size_t nExtFiles = ExtensionFiles.size();
const float tasks = nExtFiles + 1.f;
// save extension files (if required)
if (!ExtensionFiles.empty()) {
if (pProgress) {
pProgress->activity = "Saving extension files ...";
__notify_progress(pProgress, 0.f);
}
// for assembling path of extension files to be saved to
const std::string baseName = pathWithoutExtension(Path);
// save the individual extension files
std::list<RIFF::File*>::iterator it = ExtensionFiles.begin();
for (int i = 0; it != ExtensionFiles.end(); ++i, ++it) {
//FIXME: the .gx99 file is always used by GSt for convolution
// data (GigaPulse); so we should better detect by subchunk
// whether the extension file is intended for convolution
// instead of checkking for a file name, because the latter does
// not work for saving new gigs created from scratch
const std::string oldName = (*it)->GetFileName();
const bool isGigaPulseFile = (extensionOfPath(oldName) == "gx99");
std::string ext = (isGigaPulseFile) ? ".gx99" : strPrint(".gx%02d", i+1);
std::string newPath = baseName + ext;
// save extension file to its new location
if (pProgress) {
// divide local progress into subprogress
progress_t subprogress;
__divide_progress(pProgress, &subprogress, tasks, float(i)); // subdivided into amount of extension files
// do the actual work
(*it)->Save(newPath, &subprogress);
} else
(*it)->Save(newPath);
}
}
progress_t subprogress;
if (pProgress)
__divide_progress(pProgress, &subprogress, tasks, nExtFiles);
if (pProgress) {
// divide local progress into subprogress
progress_t subsubprogress;
__divide_progress(&subprogress, &subsubprogress, 1.f, 0.f, 0.05f); // assume 5% of time
subsubprogress.activity = "Updating chunks ...";
__notify_progress(&subsubprogress, 0.f);
// do the actual work
UpdateChunks(&subsubprogress);
} else
UpdateChunks(NULL);
if (pProgress) {
// divide local progress into subprogress
progress_t subsubprogress;
__divide_progress(&subprogress, &subsubprogress, 1.f, 0.05f, 0.98f); // assume 93% of time
subsubprogress.activity = "Writing file ...";
__notify_progress(&subsubprogress, 0.f);
// do the actual work
pRIFF->Save(Path, &subsubprogress);
} else
pRIFF->Save(Path);
if (pProgress) {
pProgress->activity = "Updating file offsets ...";
__notify_progress(pProgress, 0.98); // assume 2% of time
}
UpdateFileOffsets();
if (pProgress) {
pProgress->activity = "Done.";
__notify_progress(pProgress, 1.0); // notify done
}
}
void File::Save(progress_t* pProgress) {
// ensure file is open in read-write mode
// (file might be closed entirely if this method is called from another
// thread than file was loaded on - if IsIOPerThread() was enabled)
if (pRIFF->GetMode() != RIFF::stream_mode_read_write && !pRIFF->IsNew())
pRIFF->SetMode(RIFF::stream_mode_read_write);
// calculate number of tasks to notify progress appropriately
const size_t nExtFiles = ExtensionFiles.size();
const float tasks = nExtFiles + 1.f;
// save extension files (if required)
if (!ExtensionFiles.empty()) {
if (pProgress) {
pProgress->activity = "Saving extension files ...";
__notify_progress(pProgress, 0.f);
}
std::list<RIFF::File*>::iterator it = ExtensionFiles.begin();
for (int i = 0; it != ExtensionFiles.end(); ++i, ++it) {
// save extension file
if (pProgress) {
// divide local progress into subprogress
progress_t subprogress;
__divide_progress(pProgress, &subprogress, tasks, float(i)); // subdivided into amount of extension files
// do the actual work
(*it)->Save(&subprogress);
} else
(*it)->Save();
}
}
progress_t subprogress;
if (pProgress)
__divide_progress(pProgress, &subprogress, tasks, nExtFiles);
if (pProgress) {
// divide local progress into subprogress
progress_t subsubprogress;
__divide_progress(&subprogress, &subsubprogress, 1.f, 0.f, 0.05f); // assume 5% of time
subsubprogress.activity = "Updating chunks ...";
__notify_progress(&subsubprogress, 0.f);
// do the actual work
UpdateChunks(&subsubprogress);
} else
UpdateChunks(NULL);
if (pProgress) {
// divide local progress into subprogress
progress_t subsubprogress;
__divide_progress(&subprogress, &subsubprogress, 1.f, 0.05f, 0.98f); // assume 93% of time
subsubprogress.activity = "Writing file ...";
__notify_progress(&subsubprogress, 0.f);
// do the actual work
pRIFF->Save(&subsubprogress);
} else
pRIFF->Save();
if (pProgress) {
pProgress->activity = "Updating file offsets ...";
__notify_progress(pProgress, 0.98); // assume 2% of time
}
UpdateFileOffsets();
if (pProgress)
__notify_progress(pProgress, 1.0); // notify done
}
void File::UpdateFileOffsets() {
__UpdateWavePoolTableChunk();
}
void File::__ensureMandatoryChunksExist() {
// enusre 'lins' list chunk exists (mandatory for instrument definitions)
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
if (!lstInstruments) pRIFF->AddSubList(LIST_TYPE_LINS);
// ensure 'ptbl' chunk exists (mandatory for samples)
RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
if (!ptbl) {
const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
ptbl = pRIFF->AddSubChunk(CHUNK_ID_PTBL, WavePoolHeaderSize + iOffsetSize);
}
// enusre 'wvpl' list chunk exists (mandatory for samples)
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
if (!wvpl) pRIFF->AddSubList(LIST_TYPE_WVPL);
}
void File::__UpdateWavePoolTableChunk() {
__UpdateWavePoolTable();
RIFF::Chunk* ptbl = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
const int iOffsetSize = (b64BitWavePoolOffsets) ? 8 : 4;
// check if 'ptbl' chunk is large enough
WavePoolCount = (pSamples) ? uint32_t(pSamples->size()) : 0;
const file_offset_t ulRequiredSize = WavePoolHeaderSize + iOffsetSize * WavePoolCount;
if (ptbl->GetSize() < ulRequiredSize) throw Exception("Fatal error, 'ptbl' chunk too small");
// save the 'ptbl' chunk's current read/write position
file_offset_t ullOriginalPos = ptbl->GetPos();
// update headers
ptbl->SetPos(0);
uint32_t tmp = WavePoolHeaderSize;
ptbl->WriteUint32(&tmp);
tmp = WavePoolCount;
ptbl->WriteUint32(&tmp);
// update offsets
ptbl->SetPos(WavePoolHeaderSize);
if (b64BitWavePoolOffsets) {
for (int i = 0 ; i < WavePoolCount ; i++) {
tmp = pWavePoolTableHi[i];
ptbl->WriteUint32(&tmp);
tmp = pWavePoolTable[i];
ptbl->WriteUint32(&tmp);
}
} else { // conventional 32 bit offsets
for (int i = 0 ; i < WavePoolCount ; i++) {
tmp = pWavePoolTable[i];
ptbl->WriteUint32(&tmp);
}
}
// restore 'ptbl' chunk's original read/write position
ptbl->SetPos(ullOriginalPos);
}
void File::__UpdateWavePoolTable() {
WavePoolCount = (pSamples) ? uint32_t(pSamples->size()) : 0;
// resize wave pool table arrays
if (pWavePoolTable) delete[] pWavePoolTable;
if (pWavePoolTableHi) delete[] pWavePoolTableHi;
pWavePoolTable = new uint32_t[WavePoolCount];
pWavePoolTableHi = new uint32_t[WavePoolCount];
if (!pSamples) return;
// update offsets in wave pool table
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);
uint64_t wvplFileOffset = wvpl->GetFilePos() -
wvpl->GetPos(); // mandatory, since position might have changed
if (!b64BitWavePoolOffsets) { // conventional 32 bit offsets (and no extension files) ...
SampleList::iterator iter = pSamples->begin();
SampleList::iterator end = pSamples->end();
for (int i = 0 ; iter != end ; ++iter, i++) {
uint64_t _64BitOffset =
(*iter)->pWaveList->GetFilePos() -
(*iter)->pWaveList->GetPos() - // should be zero, but just to be sure
wvplFileOffset -
LIST_HEADER_SIZE(pRIFF->GetFileOffsetSize());
(*iter)->ullWavePoolOffset = _64BitOffset;
pWavePoolTable[i] = (uint32_t) _64BitOffset;
}
} else { // a) native 64 bit offsets without extension files or b) 32 bit offsets with extension files ...
if (ExtensionFiles.empty()) { // native 64 bit offsets (and no extension files) [not compatible with GigaStudio] ...
SampleList::iterator iter = pSamples->begin();
SampleList::iterator end = pSamples->end();
for (int i = 0 ; iter != end ; ++iter, i++) {
uint64_t _64BitOffset =
(*iter)->pWaveList->GetFilePos() -
(*iter)->pWaveList->GetPos() - // should be zero, but just to be sure
wvplFileOffset -
LIST_HEADER_SIZE(pRIFF->GetFileOffsetSize());
(*iter)->ullWavePoolOffset = _64BitOffset;
pWavePoolTableHi[i] = (uint32_t) (_64BitOffset >> 32);
pWavePoolTable[i] = (uint32_t) _64BitOffset;
}
} else { // 32 bit offsets with extension files (GigaStudio legacy support) ...
// the main gig and the extension files may contain wave data
std::vector<RIFF::File*> poolFiles;
poolFiles.push_back(pRIFF);
poolFiles.insert(poolFiles.end(), ExtensionFiles.begin(), ExtensionFiles.end());
RIFF::File* pCurPoolFile = NULL;
int fileNo = 0;
int waveOffset = 0;
SampleList::iterator iter = pSamples->begin();
SampleList::iterator end = pSamples->end();
for (int i = 0 ; iter != end ; ++iter, i++) {
RIFF::File* pPoolFile = (*iter)->pWaveList->GetFile();
// if this sample is located in the same pool file as the
// last we reuse the previously computed fileNo and waveOffset
if (pPoolFile != pCurPoolFile) { // it is a different pool file than the last sample ...
pCurPoolFile = pPoolFile;
std::vector<RIFF::File*>::iterator sIter;
sIter = std::find(poolFiles.begin(), poolFiles.end(), pPoolFile);
if (sIter != poolFiles.end())
fileNo = std::distance(poolFiles.begin(), sIter);
else
throw DLS::Exception("Fatal error, unknown pool file");
RIFF::List* extWvpl = pCurPoolFile->GetSubList(LIST_TYPE_WVPL);
if (!extWvpl)
throw DLS::Exception("Fatal error, pool file has no 'wvpl' list chunk");
waveOffset =
extWvpl->GetFilePos() -
extWvpl->GetPos() + // mandatory, since position might have changed
LIST_HEADER_SIZE(pCurPoolFile->GetFileOffsetSize());
}
uint64_t _64BitOffset =
(*iter)->pWaveList->GetFilePos() -
(*iter)->pWaveList->GetPos() - // should be zero, but just to be sure
waveOffset;
// pWavePoolTableHi stores file number when extension files are in use
pWavePoolTableHi[i] = (uint32_t) fileNo;
pWavePoolTable[i] = (uint32_t) _64BitOffset;
(*iter)->ullWavePoolOffset = _64BitOffset;
}
}
}
}
// *************** Exception ***************
// *
Exception::Exception() : RIFF::Exception() {
}
Exception::Exception(String format, ...) : RIFF::Exception() {
va_list arg;
va_start(arg, format);
Message = assemble(format, arg);
va_end(arg);
}
Exception::Exception(String format, va_list arg) : RIFF::Exception() {
Message = assemble(format, arg);
}
void Exception::PrintMessage() const {
std::cout << "DLS::Exception: " << Message << std::endl;
}
// *************** functions ***************
// *
String libraryName() {
return PACKAGE;
}
String libraryVersion() {
return VERSION;
}
} // namespace DLS
DLS::Articulation
Provides access to the defined connections used for the synthesis model.
Definition DLS.h:328
DLS::Articulation::pConnections
Connection * pConnections
Points to the beginning of a Connection array.
Definition DLS.h:330
DLS::Articulation::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Articulation object.
Definition DLS.cpp:179
DLS::Articulation::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply articulation connections to the respective RIFF chunks.
Definition DLS.cpp:154
DLS::Articulation::Connections
uint32_t Connections
Reflects the number of Connections.
Definition DLS.h:331
DLS::Articulation::Articulation
Articulation(RIFF::Chunk *artl)
Constructor.
Definition DLS.cpp:119
DLS::Articulator
Abstract base class for classes that provide articulation information (thus for Instrument and Region...
Definition DLS.h:343
DLS::Articulator::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply all articulations to the respective RIFF chunks.
Definition DLS.cpp:277
DLS::Articulator::GetNextArticulation
Articulation * GetNextArticulation()
Returns the next Articulation from the list of articulations.
Definition DLS.cpp:234
DLS::Articulator::GetFirstArticulation
Articulation * GetFirstArticulation()
Returns the first Articulation in the list of articulations.
Definition DLS.cpp:216
DLS::Articulator::GetArticulation
Articulation * GetArticulation(size_t pos)
Returns Articulation at supplied pos position within the articulation list.
Definition DLS.cpp:200
DLS::Articulator::CopyAssign
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:306
DLS::Articulator::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Articulator object.
Definition DLS.cpp:291
DLS::Connection
Defines a connection within the synthesis model.
Definition DLS.h:249
DLS::Exception
Will be thrown whenever a DLS specific error occurs while trying to access a DLS File.
Definition DLS.h:624
DLS::File
Parses DLS Level 1 and 2 compliant files and provides abstract access to the data.
Definition DLS.h:564
DLS::File::pVersion
version_t * pVersion
Points to a version_t structure if the file provided a version number else is set to NULL.
Definition DLS.h:566
DLS::File::AddInstrument
Instrument * AddInstrument()
Add a new instrument definition.
Definition DLS.cpp:1965
DLS::File::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply all the DLS file's current instruments, samples and settings to the respective RIFF chunks.
Definition DLS.cpp:2052
DLS::File::__ensureMandatoryChunksExist
void __ensureMandatoryChunksExist()
Checks if all (for DLS) mandatory chunks exist, if not they will be created.
Definition DLS.cpp:2471
DLS::File::File
File()
Constructor.
Definition DLS.cpp:1660
DLS::File::GetNextInstrument
Instrument * GetNextInstrument()
Returns a pointer to the next Instrument object of the file, NULL otherwise.
Definition DLS.cpp:1937
DLS::File::GetSample
Sample * GetSample(size_t index)
Returns Sample object of index.
Definition DLS.cpp:1780
DLS::File::GetNextSample
Sample * GetNextSample()
Returns a pointer to the next Sample object of the file, NULL otherwise.
Definition DLS.cpp:1808
DLS::File::SetFileName
void SetFileName(const String &name)
You may call this method store a future file name, so you don't have to to pass it to the Save() call...
Definition DLS.cpp:2040
DLS::File::UpdateFileOffsets
virtual void UpdateFileOffsets()
Updates all file offsets stored all over the file.
Definition DLS.cpp:2462
DLS::File::DeleteInstrument
void DeleteInstrument(Instrument *pInstrument)
Delete an instrument.
Definition DLS.cpp:1984
DLS::File::Instruments
uint32_t Instruments
Reflects the number of available Instrument objects.
Definition DLS.h:567
DLS::File::Save
virtual void Save(const String &Path, progress_t *pProgress=NULL)
Save changes to another file.
Definition DLS.cpp:2294
DLS::File::GetInstrument
Instrument * GetInstrument(size_t index)
Returns the instrument with the given index from the list of instruments of this file.
Definition DLS.cpp:1909
DLS::File::bOwningRiff
bool bOwningRiff
If true then pRIFF was implicitly allocated by this class and hence pRIFF will automatically be freed...
Definition DLS.h:605
DLS::File::CountSamples
size_t CountSamples()
Returns the total amount of samples of this DLS file.
Definition DLS.cpp:1858
DLS::File::DeleteSample
void DeleteSample(Sample *pSample)
Delete a sample.
Definition DLS.cpp:1891
DLS::File::GetRiffFile
RIFF::File * GetRiffFile()
Returns the underlying RIFF::File used for persistency of this DLS::File object.
Definition DLS.cpp:1999
DLS::File::GetFirstSample
Sample * GetFirstSample()
Returns a pointer to the first Sample object of the file, NULL otherwise.
Definition DLS.cpp:1794
DLS::File::GetFirstInstrument
Instrument * GetFirstInstrument()
Returns a pointer to the first Instrument object of the file, NULL otherwise.
Definition DLS.cpp:1923
DLS::File::AddSample
Sample * AddSample()
Add a new sample.
Definition DLS.cpp:1871
DLS::File::GetExtensionFile
RIFF::File * GetExtensionFile(int index)
Returns extension file of given index.
Definition DLS.cpp:2015
DLS::File::GetFileName
String GetFileName()
File name of this DLS file.
Definition DLS.cpp:2032
DLS::Info
Optional information for DLS files, instruments, samples, etc.
Definition DLS.h:363
DLS::Info::Subject
String Subject
<ISBJ-ck>. Describes the contents of the file.
Definition DLS.h:381
DLS::Info::Genre
String Genre
<IGNR-ck>. Descirbes the original work, such as, Jazz, Classic, Rock, Techno, Rave,...
Definition DLS.h:372
DLS::Info::Keywords
String Keywords
<IKEY-ck>. Provides a list of keywords that refer to the file or subject of the file....
Definition DLS.h:373
DLS::Info::SourceForm
String SourceForm
<ISRF-ck>. Identifies the original form of the material that was digitized, such as record,...
Definition DLS.h:379
DLS::Info::Comments
String Comments
<ICMT-ck>. Provides general comments about the file or the subject of the file. Sentences might end w...
Definition DLS.h:368
DLS::Info::Medium
String Medium
<IMED-ck>. Describes the original subject of the file, such as, record, CD, and so forth.
Definition DLS.h:377
DLS::Info::SetFixedStringLengths
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:379
DLS::Info::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Info object.
Definition DLS.cpp:494
DLS::Info::Info
Info(RIFF::List *list)
Constructor.
Definition DLS.cpp:332
DLS::Info::Software
String Software
<ISFT-ck>. Identifies the name of the sofware package used to create the file.
Definition DLS.h:376
DLS::Info::Artists
String Artists
<IART-ck>. Lists the artist of the original subject of the file.
Definition DLS.h:371
DLS::Info::Product
String Product
<IPRD-ck>. Specifies the name of the title the file was originally intended for, such as World Ruler ...
Definition DLS.h:369
DLS::Info::CopyAssign
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:503
DLS::Info::Name
String Name
<INAM-ck>. Stores the title of the subject of the file, such as, Seattle From Above.
Definition DLS.h:365
DLS::Info::CreationDate
String CreationDate
<ICRD-ck>. Specifies the date the subject of the file was created. List dates in yyyy-mm-dd format.
Definition DLS.h:367
DLS::Info::ArchivalLocation
String ArchivalLocation
<IARL-ck>. Indicates where the subject of the file is stored.
Definition DLS.h:366
DLS::Info::Engineer
String Engineer
<IENG-ck>. Stores the name of the engineer who worked on the file. Multiple engineer names are separa...
Definition DLS.h:374
DLS::Info::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Update chunks with current info values.
Definition DLS.cpp:429
DLS::Info::UseFixedLengthStrings
bool UseFixedLengthStrings
Definition DLS.h:382
DLS::Info::Commissioned
String Commissioned
<ICMS-ck>. Lists the name of the person or organization that commissioned the subject of the file,...
Definition DLS.h:380
DLS::Info::Copyright
String Copyright
<ICOP-ck>. Records the copyright information for the file.
Definition DLS.h:370
DLS::Info::Source
String Source
<ISRC-ck>. Identifies the name of the person or organization who supplied the original subject of the...
Definition DLS.h:378
DLS::Info::Technician
String Technician
<ITCH-ck>. Identifies the technician who sampled the subject file.
Definition DLS.h:375
DLS::Instrument
Provides all neccessary information for the synthesis of a DLS Instrument.
Definition DLS.h:524
DLS::Instrument::~Instrument
virtual ~Instrument()
Destructor.
Definition DLS.cpp:1576
DLS::Instrument::CopyAssign
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:1635
DLS::Instrument::MIDIBankFine
uint8_t MIDIBankFine
Reflects the MIDI Bank number for MIDI Control Change 32 (bank 1 - 128).
Definition DLS.h:529
DLS::Instrument::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Instrument object.
Definition DLS.cpp:1592
DLS::Instrument::GetFirstRegion
Region * GetFirstRegion()
Returns the first Region of the instrument.
Definition DLS.cpp:1451
DLS::Instrument::GetNextRegion
Region * GetNextRegion()
Returns the next Region of the instrument.
Definition DLS.cpp:1468
DLS::Instrument::MIDIBankCoarse
uint8_t MIDIBankCoarse
Reflects the MIDI Bank number for MIDI Control Change 0 (bank 1 - 128).
Definition DLS.h:528
DLS::Instrument::IsDrum
bool IsDrum
Indicates if the Instrument is a drum type, as they differ in the synthesis model of DLS from melodic...
Definition DLS.h:526
DLS::Instrument::Regions
uint32_t Regions
Reflects the number of Region defintions this Instrument has.
Definition DLS.h:531
DLS::Instrument::MIDIBank
uint16_t MIDIBank
Reflects combination of MIDIBankCoarse and MIDIBankFine (bank 1 - bank 16384). Do not change this val...
Definition DLS.h:527
DLS::Instrument::Instrument
Instrument(File *pFile, RIFF::List *insList)
Constructor.
Definition DLS.cpp:1389
DLS::Instrument::MIDIProgram
uint32_t MIDIProgram
Specifies the MIDI Program Change Number this Instrument should be assigned to.
Definition DLS.h:530
DLS::Instrument::GetRegionAt
Region * GetRegionAt(size_t pos)
Returns Region at supplied pos position within the region list of this instrument.
Definition DLS.cpp:1435
DLS::Instrument::CountRegions
size_t CountRegions()
Returns the amount of regions of this instrument.
Definition DLS.cpp:1419
DLS::Instrument::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply Instrument with all its Regions to the respective RIFF chunks.
Definition DLS.cpp:1536
DLS::Region
Defines Region information of an Instrument.
Definition DLS.h:493
DLS::Region::CopyAssign
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:1342
DLS::Region::~Region
virtual ~Region()
Destructor.
Definition DLS.cpp:1194
DLS::Region::SetSample
void SetSample(Sample *pSample)
Assign another sample to this Region.
Definition DLS.cpp:1233
DLS::Region::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply Region settings to the respective RIFF chunks.
Definition DLS.cpp:1280
DLS::Region::KeyRange
range_t KeyRange
Definition DLS.h:495
DLS::Region::SetKeyRange
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:1245
DLS::Region::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Region object.
Definition DLS.cpp:1201
DLS::Resource
Abstract base class which encapsulates data structures which all DLS resources are able to provide.
Definition DLS.h:404
DLS::Resource::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Resource object.
Definition DLS.cpp:572
DLS::Resource::Resource
Resource(Resource *Parent, RIFF::List *lstResource)
Constructor.
Definition DLS.cpp:539
DLS::Resource::pInfo
Info * pInfo
Points (in any case) to an Info object, providing additional, optional infos and comments.
Definition DLS.h:406
DLS::Resource::pDLSID
dlsid_t * pDLSID
Points to a dlsid_t structure if the file provided a DLS ID else is NULL.
Definition DLS.h:407
DLS::Resource::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Update chunks with current Resource data.
Definition DLS.cpp:585
DLS::Resource::GenerateDLSID
void GenerateDLSID()
Generates a new DLSID for the resource.
Definition DLS.cpp:604
DLS::Resource::CopyAssign
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:654
DLS::Sample
Encapsulates sample waves used for playback.
Definition DLS.h:457
DLS::Sample::Read
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:1081
DLS::Sample::ReleaseSampleData
void ReleaseSampleData()
Free sample data from RAM.
Definition DLS.cpp:989
DLS::Sample::CopyAssignCore
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:914
DLS::Sample::BlockAlign
uint16_t BlockAlign
The block alignment (in bytes) of the waveform data. Playback software needs to process a multiple of...
Definition DLS.h:463
DLS::Sample::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply sample and its settings to the respective RIFF chunks.
Definition DLS.cpp:1115
DLS::Sample::Resize
void Resize(file_offset_t NewSize)
Resize sample.
Definition DLS.cpp:1036
DLS::Sample::SetPos
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:1063
DLS::Sample::BitDepth
uint16_t BitDepth
Size of each sample per channel (only if known sample data format is used, 0 otherwise).
Definition DLS.h:464
DLS::Sample::CopyAssign
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:934
DLS::Sample::LoadSampleData
void * LoadSampleData()
Load sample data into RAM.
Definition DLS.cpp:980
DLS::Sample::Channels
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:460
DLS::Sample::GetSize
file_offset_t GetSize() const
Returns sample size.
Definition DLS.cpp:1003
DLS::Sample::SamplesPerSecond
uint32_t SamplesPerSecond
Sampling rate at which each channel should be played (defaults to 44100 if Sample was created with In...
Definition DLS.h:461
DLS::Sample::SamplesTotal
file_offset_t SamplesTotal
Reflects total number of sample points (only if known sample data format is used, 0 otherwise),...
Definition DLS.h:465
DLS::Sample::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Sample object.
Definition DLS.cpp:891
DLS::Sample::FormatTag
uint16_t FormatTag
Format ID of the waveform data (should be DLS_WAVE_FORMAT_PCM for DLS1 compliant files,...
Definition DLS.h:459
DLS::Sample::FrameSize
uint FrameSize
Reflects the size (in bytes) of one single sample point (only if known sample data format is used,...
Definition DLS.h:466
DLS::Sample::AverageBytesPerSecond
uint32_t AverageBytesPerSecond
The average number of bytes per second at which the waveform data should be transferred (Playback sof...
Definition DLS.h:462
DLS::Sample::~Sample
virtual ~Sample()
Destructor.
Definition DLS.cpp:880
DLS::Sample::Sample
Sample(File *pFile, RIFF::List *waveList, file_offset_t WavePoolOffset)
Constructor.
Definition DLS.cpp:840
DLS::Sample::Write
file_offset_t Write(void *pBuffer, file_offset_t SampleCount)
Write sample wave data.
Definition DLS.cpp:1101
DLS::Sampler
Abstract base class which provides mandatory informations about sample players in general.
Definition DLS.h:425
DLS::Sampler::DeleteChunks
virtual void DeleteChunks()
Remove all RIFF chunks associated with this Sampler object.
Definition DLS.cpp:751
DLS::Sampler::UpdateChunks
virtual void UpdateChunks(progress_t *pProgress)
Apply all sample player options to the respective RIFF chunk.
Definition DLS.cpp:710
DLS::Sampler::CopyAssign
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:805
DLS::Sampler::AddSampleLoop
void AddSampleLoop(sample_loop_t *pLoopDef)
Adds a new sample loop with the provided loop definition.
Definition DLS.cpp:759
DLS::Sampler::SampleLoops
uint32_t SampleLoops
Reflects the number of sample loops.
Definition DLS.h:432
DLS::Sampler::pSampleLoops
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:433
DLS::Sampler::DeleteSampleLoop
void DeleteSampleLoop(sample_loop_t *pLoopDef)
Deletes an existing sample loop.
Definition DLS.cpp:781
DLS::Sampler::Gain
int32_t Gain
Definition DLS.h:429
RIFF::Chunk
Ordinary RIFF Chunk.
Definition RIFF.h:186
RIFF::Chunk::GetFile
File * GetFile() const
Returns pointer to the chunk's File object.
Definition RIFF.h:191
RIFF::Chunk::GetParent
List * GetParent() const
Returns pointer to the chunk's parent list chunk.
Definition RIFF.h:192
RIFF::Chunk::Resize
void Resize(file_offset_t NewSize)
Resize chunk.
Definition RIFF.cpp:1058
RIFF::Chunk::SetPos
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:365
RIFF::Chunk::GetFilePos
file_offset_t GetFilePos() const
Current, actual offset in file of current chunk data body read/write position.
Definition RIFF.cpp:348
RIFF::Chunk::RemainingBytes
file_offset_t RemainingBytes() const
Returns the number of bytes left to read in the chunk body.
Definition RIFF.cpp:400
RIFF::Chunk::ReadUint32
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:812
RIFF::Chunk::GetPos
file_offset_t GetPos() const
Current read/write position within the chunk data body (starting with 0).
Definition RIFF.cpp:335
RIFF::Chunk::ReadUint16
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:734
RIFF::Chunk::Read
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:465
RIFF::Chunk::ReadInt16
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:695
RIFF::Chunk::GetChunkID
uint32_t GetChunkID() const
Chunk ID in unsigned integer representation.
Definition RIFF.h:190
RIFF::Chunk::LoadChunkData
void * LoadChunkData()
Load chunk body into RAM.
Definition RIFF.cpp:984
RIFF::Chunk::ReadInt32
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:773
RIFF::Chunk::WriteUint32
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:852
RIFF::Chunk::GetSize
file_offset_t GetSize() const
Chunk size in bytes (without header, thus the chunk data body).
Definition RIFF.h:193
RIFF::File
RIFF File.
Definition RIFF.h:314
RIFF::File::GetFileOffsetSize
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:2593
RIFF::File::GetRequiredFileSize
file_offset_t GetRequiredFileSize()
Returns the required size (in bytes) for this RIFF File to be saved to disk.
Definition RIFF.cpp:2529
RIFF::List
RIFF List Chunk.
Definition RIFF.h:262
RIFF::List::GetSubChunk
Chunk * GetSubChunk(uint32_t ChunkID)
Returns subchunk with chunk ID ChunkID within this chunk list.
Definition RIFF.cpp:1273
RIFF::List::MoveSubChunk
void MoveSubChunk(Chunk *pSrc, Chunk *pDst)
Moves a sub chunk witin this list.
Definition RIFF.cpp:1511
RIFF::List::AddSubList
List * AddSubList(uint32_t uiListType)
Creates a new list sub chunk.
Definition RIFF.cpp:1568
RIFF::List::DeleteSubChunk
void DeleteSubChunk(Chunk *pSubChunk)
Removes a sub chunk.
Definition RIFF.cpp:1591
RIFF::List::GetSubListAt
List * GetSubListAt(size_t pos)
Returns sublist chunk with list type ListType at supplied pos position among all subchunks of type Li...
Definition RIFF.cpp:1291
RIFF::List::GetSubList
List * GetSubList(uint32_t ListType)
Returns sublist chunk with list type ListType within this chunk list.
Definition RIFF.cpp:1314
RIFF::List::GetListType
uint32_t GetListType() const
Returns unsigned integer representation of the list's ID.
Definition RIFF.h:266
RIFF::List::GetSubChunkAt
Chunk * GetSubChunkAt(size_t pos)
Returns subchunk at supplied pos position within this chunk list.
Definition RIFF.cpp:1256
gig::File::pDLSID
dlsid_t * pDLSID
Points to a dlsid_t structure if the file provided a DLS ID else is NULL.
Definition DLS.h:407
DLS
DLS specific classes and definitions.
Definition DLS.h:108
DLS::libraryName
String libraryName()
Returns the name of this C++ library.
Definition DLS.cpp:2650
DLS::libraryVersion
String libraryVersion()
Returns version of this C++ library.
Definition DLS.cpp:2658
DLS::conn_src_t
conn_src_t
Connection Sources.
Definition DLS.h:131
DLS::conn_dst_t
conn_dst_t
Connection Destinations.
Definition DLS.h:157
DLS::conn_trn_t
conn_trn_t
Connection Transforms.
Definition DLS.h:202
RIFF
RIFF specific classes and definitions.
Definition RIFF.h:101
RIFF::stream_whence_t
stream_whence_t
File stream position dependent to these relations.
Definition RIFF.h:128
RIFF::file_offset_t
uint64_t file_offset_t
Type used by libgig for handling file positioning during file I/O tasks.
Definition RIFF.h:111
DLS::dlsid_t
Every subject of an DLS file and the file itself can have an unique, computer generated ID.
Definition DLS.h:123
DLS::range_t::low
uint16_t low
Low value of range.
Definition DLS.h:211
DLS::range_t::high
uint16_t high
High value of range.
Definition DLS.h:212
DLS::sample_loop_t
Defines Sample Loop Points.
Definition DLS.h:235
DLS::sample_loop_t::Size
uint32_t Size
For internal usage only: usually reflects exactly sizeof(sample_loop_t), otherwise if the value is la...
Definition DLS.h:236
DLS::version_t
Quadtuple version number ("major.minor.release.build").
Definition DLS.h:115
RIFF::progress_t::activity
const char * activity
Text which describes current ongoing action (e.g. to be displayed along a progress bar).
Definition RIFF.h:171