30 #include <CoreFoundation/CFUUID.h>
31 #elif defined(HAVE_UUID_UUID_H)
32 #include <uuid/uuid.h>
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)
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)
55 #define DRUM_TYPE_MASK 0x80000000
57 #define F_RGN_OPTION_SELFNONEXCLUSIVE 0x0001
59 #define F_WAVELINK_PHASE_MASTER 0x0001
60 #define F_WAVELINK_MULTICHANNEL 0x0002
62 #define F_WSMP_NO_TRUNCATION 0x0001
63 #define F_WSMP_NO_COMPRESSION 0x0002
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))
149 const int iEntrySize = 12;
209 while (iter != end) {
225 for (; iter != end; ++iter) {
226 (*iter)->UpdateChunks();
243 pFixedStringLengths = NULL;
244 pResourceListChunk = list;
284 pFixedStringLengths = lengths;
314 if (pFixedStringLengths) {
315 for (
int i = 0 ; pFixedStringLengths[i].
length ; i++) {
316 if (pFixedStringLengths[i].chunkId == ChunkID) {
317 size = pFixedStringLengths[i].
length;
323 ::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size);
332 if (!pResourceListChunk)
return;
338 String defaultCreationDate =
"";
339 String defaultSoftware =
"";
340 String defaultComments =
"";
342 uint32_t resourceType = pResourceListChunk->
GetListType();
348 defaultName =
"NONAME";
352 time_t now = time(NULL);
353 tm* pNowBroken = localtime(&now);
355 strftime(buf, 11,
"%F", pNowBroken);
356 defaultCreationDate = buf;
451 #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
464 #elif defined(__APPLE__)
466 CFUUIDRef uuidRef = CFUUIDCreate(NULL);
467 CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
469 pDLSID->
ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
483 pDLSID->
ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
545 }
else if (wsmp->
GetSize() != wsmpSize) {
558 store32(&pData[8],
Gain);
560 store32(&pData[16], SampleLoops);
603 if (o == SampleLoops - 1) {
605 throw Exception(
"Could not delete Sample Loop, because it does not exist");
764 if (iNewSize < 1)
throw Exception(
"Sample size must be at least one sample point");
765 const int iSizeInBytes = iNewSize *
FrameSize;
789 if (!
pCkData)
throw Exception(
"No data chunk created for sample yet, call Sample::Resize() to create one");
790 unsigned long orderedBytes = SampleCount *
FrameSize;
791 unsigned long result =
pCkData->
SetPos(orderedBytes, Whence);
792 return (result == orderedBytes) ? SampleCount
827 if (
GetSize() < SampleCount)
throw Exception(
"Could not write sample data, current sample size to small");
840 throw Exception(
"Could not save sample, only PCM format is supported");
843 throw Exception(
"Could not save sample, there is no sample data to save");
958 Region* prev_region = NULL;
960 Instrument::RegionList::iterator iter = pInstrument->
pRegions->begin();
961 iter != pInstrument->
pRegions->end(); iter++
963 if ((*iter)->KeyRange.low > this->KeyRange.low) {
971 if (prev_region !=
this) pInstrument->MoveRegion(
this, r);
1016 File::SampleList::iterator iter = pFile->
pSamples->begin();
1017 File::SampleList::iterator end = pFile->
pSamples->end();
1018 for (
int i = 0; iter != end; ++iter, i++) {
1058 insh->
Read(&locale, 2, 4);
1113 void Instrument::MoveRegion(
Region* pSrc,
Region* pDst) {
1118 RegionList::iterator iter = find(
pRegions->begin(),
pRegions->end(), pDst);
1124 RegionList::iterator iter = find(
pRegions->begin(),
pRegions->end(), pRegion);
1125 if (iter ==
pRegions->end())
return;
1153 store32(&pData[4], locale.
bank);
1157 RegionList::iterator iter =
pRegions->begin();
1158 RegionList::iterator end =
pRegions->end();
1159 for (; iter != end; ++iter) {
1160 (*iter)->UpdateChunks();
1171 RegionList::iterator iter =
pRegions->begin();
1172 RegionList::iterator end =
pRegions->end();
1173 while (iter != end) {
1225 if (!pRIFF)
throw DLS::Exception(
"NULL pointer reference to RIFF::File object.");
1226 this->pRIFF =
pRIFF;
1236 if (!colh)
throw DLS::Exception(
"Mandatory chunks in RIFF list chunk not found.");
1260 throw DLS::Exception(
"Files larger than 2 GB not yet supported");
1276 while (iter != end) {
1284 SampleList::iterator iter =
pSamples->begin();
1285 SampleList::iterator end =
pSamples->end();
1286 while (iter != end) {
1317 unsigned long wvplFileOffset = wvpl->
GetFilePos();
1321 unsigned long waveFileOffset = wave->
GetFilePos();
1322 pSamples->push_back(
new Sample(
this, wave, waveFileOffset - wvplFileOffset));
1330 unsigned long dwplFileOffset = dwpl->
GetFilePos();
1334 unsigned long waveFileOffset = wave->
GetFilePos();
1335 pSamples->push_back(
new Sample(
this, wave, waveFileOffset - dwplFileOffset));
1370 SampleList::iterator iter = find(
pSamples->begin(),
pSamples->end(), pSample);
1371 if (iter ==
pSamples->end())
return;
1392 if (lstInstruments) {
1451 if (i == index)
return *iter;
1501 for (; iter != end; ++iter) {
1502 (*iter)->UpdateChunks();
1521 SampleList::iterator iter =
pSamples->begin();
1522 SampleList::iterator end =
pSamples->end();
1523 for (; iter != end; ++iter) {
1524 (*iter)->UpdateChunks();
1545 __UpdateWavePoolTableChunk();
1560 __UpdateWavePoolTableChunk();
1592 void File::__UpdateWavePoolTableChunk() {
1593 __UpdateWavePoolTable();
1599 if (ptbl->
GetSize() < ulRequiredSize)
throw Exception(
"Fatal error, 'ptbl' chunk too small");
1601 unsigned long ulOriginalPos = ptbl->
GetPos();
1624 ptbl->
SetPos(ulOriginalPos);
1632 void File::__UpdateWavePoolTable() {
1642 uint64_t wvplFileOffset = wvpl->
GetFilePos();
1644 SampleList::iterator iter =
pSamples->begin();
1645 SampleList::iterator end =
pSamples->end();
1646 for (
int i = 0 ; iter != end ; ++iter, i++) {
1647 uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset -
LIST_HEADER_SIZE;
1648 (*iter)->ulWavePoolOffset = _64BitOffset;
1653 SampleList::iterator iter =
pSamples->begin();
1654 SampleList::iterator end =
pSamples->end();
1655 for (
int i = 0 ; iter != end ; ++iter, i++) {
1656 uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset -
LIST_HEADER_SIZE;
1657 (*iter)->ulWavePoolOffset = _64BitOffset;
1672 std::cout <<
"DLS::Exception: " <<
Message << std::endl;