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();
252 pFixedStringLengths = NULL;
253 pResourceListChunk = list;
293 pFixedStringLengths = lengths;
323 if (pFixedStringLengths) {
324 for (
int i = 0 ; pFixedStringLengths[i].
length ; i++) {
325 if (pFixedStringLengths[i].chunkId == ChunkID) {
326 size = pFixedStringLengths[i].
length;
332 ::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size);
341 if (!pResourceListChunk)
return;
347 String defaultCreationDate =
"";
348 String defaultSoftware =
"";
349 String defaultComments =
"";
351 uint32_t resourceType = pResourceListChunk->
GetListType();
357 defaultName =
"NONAME";
361 time_t now = time(NULL);
362 tm* pNowBroken = localtime(&now);
364 strftime(buf, 11,
"%F", pNowBroken);
365 defaultCreationDate = buf;
421 pFixedStringLengths = orig->pFixedStringLengths;
488 #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
501 #elif defined(__APPLE__)
503 CFUUIDRef uuidRef = CFUUIDCreate(NULL);
504 CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
506 pDLSID->
ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
520 pDLSID->
ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
592 }
else if (wsmp->
GetSize() != wsmpSize) {
605 store32(&pData[8],
Gain);
607 store32(&pData[16], SampleLoops);
650 if (o == SampleLoops - 1) {
652 throw Exception(
"Could not delete Sample Loop, because it does not exist");
832 if (iNewSize < 1)
throw Exception(
"Sample size must be at least one sample point");
833 const int iSizeInBytes = iNewSize *
FrameSize;
857 if (!
pCkData)
throw Exception(
"No data chunk created for sample yet, call Sample::Resize() to create one");
858 unsigned long orderedBytes = SampleCount *
FrameSize;
859 unsigned long result =
pCkData->
SetPos(orderedBytes, Whence);
860 return (result == orderedBytes) ? SampleCount
895 if (
GetSize() < SampleCount)
throw Exception(
"Could not write sample data, current sample size to small");
908 throw Exception(
"Could not save sample, only PCM format is supported");
911 throw Exception(
"Could not save sample, there is no sample data to save");
1021 if (!pInstrument->
pRegions)
return;
1026 Region* prev_region = NULL;
1028 Instrument::RegionList::iterator iter = pInstrument->
pRegions->begin();
1029 iter != pInstrument->
pRegions->end(); iter++
1031 if ((*iter)->KeyRange.low > this->KeyRange.low) {
1035 prev_region = *iter;
1039 if (prev_region !=
this) pInstrument->MoveRegion(
this, r);
1084 File::SampleList::iterator iter = pFile->
pSamples->begin();
1085 File::SampleList::iterator end = pFile->
pSamples->end();
1086 for (
int i = 0; iter != end; ++iter, i++) {
1157 insh->
Read(&locale, 2, 4);
1212 void Instrument::MoveRegion(
Region* pSrc,
Region* pDst) {
1217 RegionList::iterator iter = find(
pRegions->begin(),
pRegions->end(), pDst);
1223 RegionList::iterator iter = find(
pRegions->begin(),
pRegions->end(), pRegion);
1224 if (iter ==
pRegions->end())
return;
1252 store32(&pData[4], locale.
bank);
1256 RegionList::iterator iter =
pRegions->begin();
1257 RegionList::iterator end =
pRegions->end();
1258 for (; iter != end; ++iter) {
1259 (*iter)->UpdateChunks();
1270 RegionList::iterator iter =
pRegions->begin();
1271 RegionList::iterator end =
pRegions->end();
1272 while (iter != end) {
1311 RegionList::const_iterator it = orig->
pRegions->begin();
1312 for (
int i = 0; i < orig->
Regions; ++i, ++it) {
1360 if (!pRIFF)
throw DLS::Exception(
"NULL pointer reference to RIFF::File object.");
1361 this->pRIFF =
pRIFF;
1371 if (!colh)
throw DLS::Exception(
"Mandatory chunks in RIFF list chunk not found.");
1395 throw DLS::Exception(
"Files larger than 2 GB not yet supported");
1411 while (iter != end) {
1419 SampleList::iterator iter =
pSamples->begin();
1420 SampleList::iterator end =
pSamples->end();
1421 while (iter != end) {
1452 unsigned long wvplFileOffset = wvpl->
GetFilePos();
1456 unsigned long waveFileOffset = wave->
GetFilePos();
1457 pSamples->push_back(
new Sample(
this, wave, waveFileOffset - wvplFileOffset));
1465 unsigned long dwplFileOffset = dwpl->
GetFilePos();
1469 unsigned long waveFileOffset = wave->
GetFilePos();
1470 pSamples->push_back(
new Sample(
this, wave, waveFileOffset - dwplFileOffset));
1505 SampleList::iterator iter = find(
pSamples->begin(),
pSamples->end(), pSample);
1506 if (iter ==
pSamples->end())
return;
1527 if (lstInstruments) {
1586 if (i == index)
return *iter;
1636 for (; iter != end; ++iter) {
1637 (*iter)->UpdateChunks();
1656 SampleList::iterator iter =
pSamples->begin();
1657 SampleList::iterator end =
pSamples->end();
1658 for (; iter != end; ++iter) {
1659 (*iter)->UpdateChunks();
1680 __UpdateWavePoolTableChunk();
1695 __UpdateWavePoolTableChunk();
1727 void File::__UpdateWavePoolTableChunk() {
1728 __UpdateWavePoolTable();
1734 if (ptbl->
GetSize() < ulRequiredSize)
throw Exception(
"Fatal error, 'ptbl' chunk too small");
1736 unsigned long ulOriginalPos = ptbl->
GetPos();
1759 ptbl->
SetPos(ulOriginalPos);
1767 void File::__UpdateWavePoolTable() {
1777 uint64_t wvplFileOffset = wvpl->
GetFilePos();
1779 SampleList::iterator iter =
pSamples->begin();
1780 SampleList::iterator end =
pSamples->end();
1781 for (
int i = 0 ; iter != end ; ++iter, i++) {
1782 uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset -
LIST_HEADER_SIZE;
1783 (*iter)->ulWavePoolOffset = _64BitOffset;
1788 SampleList::iterator iter =
pSamples->begin();
1789 SampleList::iterator end =
pSamples->end();
1790 for (
int i = 0 ; iter != end ; ++iter, i++) {
1791 uint64_t _64BitOffset = (*iter)->pWaveList->GetFilePos() - wvplFileOffset -
LIST_HEADER_SIZE;
1792 (*iter)->ulWavePoolOffset = _64BitOffset;
1807 std::cout <<
"DLS::Exception: " <<
Message << std::endl;