25 |
|
|
26 |
#include <time.h> |
#include <time.h> |
27 |
|
|
28 |
|
#ifdef __APPLE__ |
29 |
|
#include <CoreFoundation/CFUUID.h> |
30 |
|
#elif defined(HAVE_UUID_UUID_H) |
31 |
|
#include <uuid/uuid.h> |
32 |
|
#endif |
33 |
|
|
34 |
#include "helper.h" |
#include "helper.h" |
35 |
|
|
36 |
// macros to decode connection transforms |
// macros to decode connection transforms |
148 |
const int iEntrySize = 12; // 12 bytes per connection block |
const int iEntrySize = 12; // 12 bytes per connection block |
149 |
pArticulationCk->Resize(HeaderSize + Connections * iEntrySize); |
pArticulationCk->Resize(HeaderSize + Connections * iEntrySize); |
150 |
uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pArticulationCk->LoadChunkData(); |
151 |
memcpy(&pData[0], &HeaderSize, 2); |
store16(&pData[0], HeaderSize); |
152 |
memcpy(&pData[2], &Connections, 2); |
store16(&pData[2], Connections); |
153 |
for (uint32_t i = 0; i < Connections; i++) { |
for (uint32_t i = 0; i < Connections; i++) { |
154 |
Connection::conn_block_t c = pConnections[i].ToConnBlock(); |
Connection::conn_block_t c = pConnections[i].ToConnBlock(); |
155 |
memcpy(&pData[HeaderSize + i * iEntrySize], &c.source, 2); |
store16(&pData[HeaderSize + i * iEntrySize], c.source); |
156 |
memcpy(&pData[HeaderSize + i * iEntrySize + 2], &c.control, 2); |
store16(&pData[HeaderSize + i * iEntrySize + 2], c.control); |
157 |
memcpy(&pData[HeaderSize + i * iEntrySize + 4], &c.destination, 2); |
store16(&pData[HeaderSize + i * iEntrySize + 4], c.destination); |
158 |
memcpy(&pData[HeaderSize + i * iEntrySize + 6], &c.transform, 2); |
store16(&pData[HeaderSize + i * iEntrySize + 6], c.transform); |
159 |
memcpy(&pData[HeaderSize + i * iEntrySize + 8], &c.scale, 4); |
store32(&pData[HeaderSize + i * iEntrySize + 8], c.scale); |
160 |
} |
} |
161 |
} |
} |
162 |
|
|
239 |
* @param list - pointer to a list chunk which contains an INFO list chunk |
* @param list - pointer to a list chunk which contains an INFO list chunk |
240 |
*/ |
*/ |
241 |
Info::Info(RIFF::List* list) { |
Info::Info(RIFF::List* list) { |
242 |
UseFixedLengthStrings = false; |
FixedStringLengths = NULL; |
243 |
pResourceListChunk = list; |
pResourceListChunk = list; |
244 |
if (list) { |
if (list) { |
245 |
RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO); |
RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO); |
292 |
* @param lstINFO - parent (INFO) RIFF list chunk |
* @param lstINFO - parent (INFO) RIFF list chunk |
293 |
* @param s - current value of info field |
* @param s - current value of info field |
294 |
* @param sDefault - default value |
* @param sDefault - default value |
|
* @param bUseFixedLengthStrings - should a specific string size be forced in the chunk? |
|
|
* @param size - wanted size of the INFO chunk. This is ignored if bUseFixedLengthStrings is false. |
|
295 |
*/ |
*/ |
296 |
void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault, bool bUseFixedLengthStrings, int size) { |
void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) { |
297 |
|
int size = 0; |
298 |
|
if (FixedStringLengths) { |
299 |
|
for (int i = 0 ; FixedStringLengths[i].length ; i++) { |
300 |
|
if (FixedStringLengths[i].chunkId == ChunkID) { |
301 |
|
size = FixedStringLengths[i].length; |
302 |
|
break; |
303 |
|
} |
304 |
|
} |
305 |
|
} |
306 |
RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID); |
RIFF::Chunk* ck = lstINFO->GetSubChunk(ChunkID); |
307 |
::SaveString(ChunkID, ck, lstINFO, s, sDefault, bUseFixedLengthStrings, size); // function from helper.h |
::SaveString(ChunkID, ck, lstINFO, s, sDefault, size != 0, size); // function from helper.h |
308 |
} |
} |
309 |
|
|
310 |
/** @brief Update chunks with current info values. |
/** @brief Update chunks with current info values. |
349 |
|
|
350 |
// save values |
// save values |
351 |
|
|
352 |
// (the string size values are for gig files; they are only |
SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String("")); |
353 |
// used if UseFixedLengthStrings is set to true) |
SaveString(CHUNK_ID_IART, lstINFO, Artists, String("")); |
354 |
SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName, UseFixedLengthStrings, |
SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String("")); |
355 |
resourceType == RIFF_TYPE_DLS ? 128 : 64); |
SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments); |
356 |
SaveString(CHUNK_ID_IARL, lstINFO, ArchivalLocation, String(""), UseFixedLengthStrings, 256); |
SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String("")); |
357 |
SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate, UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_ICRD, lstINFO, CreationDate, defaultCreationDate); |
358 |
SaveString(CHUNK_ID_ICMT, lstINFO, Comments, defaultComments, UseFixedLengthStrings, 1024); |
SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String("")); |
359 |
SaveString(CHUNK_ID_IPRD, lstINFO, Product, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String("")); |
360 |
SaveString(CHUNK_ID_ICOP, lstINFO, Copyright, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String("")); |
361 |
SaveString(CHUNK_ID_IART, lstINFO, Artists, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_IMED, lstINFO, Medium, String("")); |
362 |
SaveString(CHUNK_ID_IGNR, lstINFO, Genre, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_INAM, lstINFO, Name, defaultName); |
363 |
SaveString(CHUNK_ID_IKEY, lstINFO, Keywords, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_IPRD, lstINFO, Product, String("")); |
364 |
SaveString(CHUNK_ID_IENG, lstINFO, Engineer, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String("")); |
365 |
SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String(""), UseFixedLengthStrings, 128); |
SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware); |
366 |
SaveString(CHUNK_ID_ISFT, lstINFO, Software, defaultSoftware, UseFixedLengthStrings, |
SaveString(CHUNK_ID_ISRC, lstINFO, Source, String("")); |
367 |
resourceType == LIST_TYPE_INS ? |
SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String("")); |
368 |
(Software == "" ? defaultSoftware.length() : Software.length()) : 128); |
SaveString(CHUNK_ID_ITCH, lstINFO, Technician, String("")); |
|
SaveString(CHUNK_ID_IMED, lstINFO, Medium, String(""), UseFixedLengthStrings, 128); |
|
|
SaveString(CHUNK_ID_ISRC, lstINFO, Source, String(""), UseFixedLengthStrings, 128); |
|
|
SaveString(CHUNK_ID_ISRF, lstINFO, SourceForm, String(""), UseFixedLengthStrings, 128); |
|
|
SaveString(CHUNK_ID_ICMS, lstINFO, Commissioned, String(""), UseFixedLengthStrings, 128); |
|
|
SaveString(CHUNK_ID_ISBJ, lstINFO, Subject, String(""), UseFixedLengthStrings, 128); |
|
369 |
} |
} |
370 |
|
|
371 |
|
|
414 |
*/ |
*/ |
415 |
void Resource::UpdateChunks() { |
void Resource::UpdateChunks() { |
416 |
pInfo->UpdateChunks(); |
pInfo->UpdateChunks(); |
417 |
//TODO: save DLSID |
|
418 |
|
if (pDLSID) { |
419 |
|
// make sure 'dlid' chunk exists |
420 |
|
RIFF::Chunk* ckDLSID = pResourceList->GetSubChunk(CHUNK_ID_DLID); |
421 |
|
if (!ckDLSID) ckDLSID = pResourceList->AddSubChunk(CHUNK_ID_DLID, 16); |
422 |
|
uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData(); |
423 |
|
// update 'dlid' chunk |
424 |
|
store32(&pData[0], pDLSID->ulData1); |
425 |
|
store16(&pData[4], pDLSID->usData2); |
426 |
|
store16(&pData[6], pDLSID->usData3); |
427 |
|
memcpy(&pData[8], pDLSID->abData, 8); |
428 |
|
} |
429 |
} |
} |
430 |
|
|
431 |
|
/** |
432 |
|
* Generates a new DLSID for the resource. |
433 |
|
*/ |
434 |
|
void Resource::GenerateDLSID() { |
435 |
|
#if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE) |
436 |
|
|
437 |
|
if (!pDLSID) pDLSID = new dlsid_t; |
438 |
|
|
439 |
|
#ifdef WIN32 |
440 |
|
|
441 |
|
UUID uuid; |
442 |
|
UuidCreate(&uuid); |
443 |
|
pDLSID->ulData1 = uuid.Data1; |
444 |
|
pDLSID->usData2 = uuid.Data2; |
445 |
|
pDLSID->usData3 = uuid.Data3; |
446 |
|
memcpy(pDLSID->abData, uuid.Data4, 8); |
447 |
|
|
448 |
|
#elif defined(__APPLE__) |
449 |
|
|
450 |
|
CFUUIDRef uuidRef = CFUUIDCreate(NULL); |
451 |
|
CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef); |
452 |
|
CFRelease(uuidRef); |
453 |
|
pDLSID->ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24; |
454 |
|
pDLSID->usData2 = uuid.byte4 | uuid.byte5 << 8; |
455 |
|
pDLSID->usData3 = uuid.byte6 | uuid.byte7 << 8; |
456 |
|
pDLSID->abData[0] = uuid.byte8; |
457 |
|
pDLSID->abData[1] = uuid.byte9; |
458 |
|
pDLSID->abData[2] = uuid.byte10; |
459 |
|
pDLSID->abData[3] = uuid.byte11; |
460 |
|
pDLSID->abData[4] = uuid.byte12; |
461 |
|
pDLSID->abData[5] = uuid.byte13; |
462 |
|
pDLSID->abData[6] = uuid.byte14; |
463 |
|
pDLSID->abData[7] = uuid.byte15; |
464 |
|
#else |
465 |
|
uuid_t uuid; |
466 |
|
uuid_generate(uuid); |
467 |
|
pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24; |
468 |
|
pDLSID->usData2 = uuid[4] | uuid[5] << 8; |
469 |
|
pDLSID->usData3 = uuid[6] | uuid[7] << 8; |
470 |
|
memcpy(pDLSID->abData, &uuid[8], 8); |
471 |
|
#endif |
472 |
|
#endif |
473 |
|
} |
474 |
|
|
475 |
|
|
476 |
// *************** Sampler *************** |
// *************** Sampler *************** |
487 |
SamplerOptions = wsmp->ReadUint32(); |
SamplerOptions = wsmp->ReadUint32(); |
488 |
SampleLoops = wsmp->ReadUint32(); |
SampleLoops = wsmp->ReadUint32(); |
489 |
} else { // 'wsmp' chunk missing |
} else { // 'wsmp' chunk missing |
490 |
uiHeaderSize = 0; |
uiHeaderSize = 20; |
491 |
UnityNote = 64; |
UnityNote = 60; |
492 |
FineTune = 0; // +- 0 cents |
FineTune = 0; // +- 0 cents |
493 |
Gain = 0; // 0 dB |
Gain = 0; // 0 dB |
494 |
SamplerOptions = F_WSMP_NO_COMPRESSION; |
SamplerOptions = F_WSMP_NO_COMPRESSION; |
512 |
if (pSampleLoops) delete[] pSampleLoops; |
if (pSampleLoops) delete[] pSampleLoops; |
513 |
} |
} |
514 |
|
|
515 |
|
void Sampler::SetGain(int32_t gain) { |
516 |
|
Gain = gain; |
517 |
|
} |
518 |
|
|
519 |
/** |
/** |
520 |
* Apply all sample player options to the respective RIFF chunk. You |
* Apply all sample player options to the respective RIFF chunk. You |
521 |
* have to call File::Save() to make changes persistent. |
* have to call File::Save() to make changes persistent. |
523 |
void Sampler::UpdateChunks() { |
void Sampler::UpdateChunks() { |
524 |
// make sure 'wsmp' chunk exists |
// make sure 'wsmp' chunk exists |
525 |
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP); |
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP); |
526 |
|
int wsmpSize = uiHeaderSize + SampleLoops * 16; |
527 |
if (!wsmp) { |
if (!wsmp) { |
528 |
uiHeaderSize = 20; |
wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize); |
529 |
wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, uiHeaderSize + SampleLoops * 16); |
} else if (wsmp->GetSize() != wsmpSize) { |
530 |
|
wsmp->Resize(wsmpSize); |
531 |
} |
} |
532 |
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData(); |
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData(); |
533 |
// update headers size |
// update headers size |
534 |
memcpy(&pData[0], &uiHeaderSize, 4); |
store32(&pData[0], uiHeaderSize); |
535 |
// update respective sampler options bits |
// update respective sampler options bits |
536 |
SamplerOptions = (NoSampleDepthTruncation) ? SamplerOptions | F_WSMP_NO_TRUNCATION |
SamplerOptions = (NoSampleDepthTruncation) ? SamplerOptions | F_WSMP_NO_TRUNCATION |
537 |
: SamplerOptions & (~F_WSMP_NO_TRUNCATION); |
: SamplerOptions & (~F_WSMP_NO_TRUNCATION); |
538 |
SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION |
SamplerOptions = (NoSampleCompression) ? SamplerOptions | F_WSMP_NO_COMPRESSION |
539 |
: SamplerOptions & (~F_WSMP_NO_COMPRESSION); |
: SamplerOptions & (~F_WSMP_NO_COMPRESSION); |
540 |
memcpy(&pData[4], &UnityNote, 2); |
store16(&pData[4], UnityNote); |
541 |
memcpy(&pData[6], &FineTune, 2); |
store16(&pData[6], FineTune); |
542 |
memcpy(&pData[8], &Gain, 4); |
store32(&pData[8], Gain); |
543 |
memcpy(&pData[12], &SamplerOptions, 4); |
store32(&pData[12], SamplerOptions); |
544 |
memcpy(&pData[16], &SampleLoops, 4); |
store32(&pData[16], SampleLoops); |
545 |
// update loop definitions |
// update loop definitions |
546 |
for (uint32_t i = 0; i < SampleLoops; i++) { |
for (uint32_t i = 0; i < SampleLoops; i++) { |
547 |
//FIXME: this does not handle extended loop structs correctly |
//FIXME: this does not handle extended loop structs correctly |
548 |
memcpy(&pData[uiHeaderSize + i * 16], pSampleLoops + i, 4 * 4); |
store32(&pData[uiHeaderSize + i * 16], pSampleLoops[i].Size); |
549 |
|
store32(&pData[uiHeaderSize + i * 16 + 4], pSampleLoops[i].LoopType); |
550 |
|
store32(&pData[uiHeaderSize + i * 16 + 8], pSampleLoops[i].LoopStart); |
551 |
|
store32(&pData[uiHeaderSize + i * 16 + 12], pSampleLoops[i].LoopLength); |
552 |
} |
} |
553 |
} |
} |
554 |
|
|
555 |
|
/** |
556 |
|
* Adds a new sample loop with the provided loop definition. |
557 |
|
* |
558 |
|
* @param pLoopDef - points to a loop definition that is to be copied |
559 |
|
*/ |
560 |
|
void Sampler::AddSampleLoop(sample_loop_t* pLoopDef) { |
561 |
|
sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1]; |
562 |
|
// copy old loops array |
563 |
|
for (int i = 0; i < SampleLoops; i++) { |
564 |
|
pNewLoops[i] = pSampleLoops[i]; |
565 |
|
} |
566 |
|
// add the new loop |
567 |
|
pNewLoops[SampleLoops] = *pLoopDef; |
568 |
|
// auto correct size field |
569 |
|
pNewLoops[SampleLoops].Size = sizeof(DLS::sample_loop_t); |
570 |
|
// free the old array and update the member variables |
571 |
|
if (SampleLoops) delete[] pSampleLoops; |
572 |
|
pSampleLoops = pNewLoops; |
573 |
|
SampleLoops++; |
574 |
|
} |
575 |
|
|
576 |
|
/** |
577 |
|
* Deletes an existing sample loop. |
578 |
|
* |
579 |
|
* @param pLoopDef - pointer to existing loop definition |
580 |
|
* @throws Exception - if given loop definition does not exist |
581 |
|
*/ |
582 |
|
void Sampler::DeleteSampleLoop(sample_loop_t* pLoopDef) { |
583 |
|
sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops - 1]; |
584 |
|
// copy old loops array (skipping given loop) |
585 |
|
for (int i = 0, o = 0; i < SampleLoops; i++) { |
586 |
|
if (&pSampleLoops[i] == pLoopDef) continue; |
587 |
|
if (o == SampleLoops - 1) |
588 |
|
throw Exception("Could not delete Sample Loop, because it does not exist"); |
589 |
|
pNewLoops[o] = pSampleLoops[i]; |
590 |
|
o++; |
591 |
|
} |
592 |
|
// free the old array and update the member variables |
593 |
|
if (SampleLoops) delete[] pSampleLoops; |
594 |
|
pSampleLoops = pNewLoops; |
595 |
|
SampleLoops--; |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
// *************** Sample *************** |
// *************** Sample *************** |
830 |
if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format |
if (!pCkFormat) pCkFormat = pWaveList->AddSubChunk(CHUNK_ID_FMT, 16); // assumes PCM format |
831 |
uint8_t* pData = (uint8_t*) pCkFormat->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pCkFormat->LoadChunkData(); |
832 |
// update 'fmt' chunk |
// update 'fmt' chunk |
833 |
memcpy(&pData[0], &FormatTag, 2); |
store16(&pData[0], FormatTag); |
834 |
memcpy(&pData[2], &Channels, 2); |
store16(&pData[2], Channels); |
835 |
memcpy(&pData[4], &SamplesPerSecond, 4); |
store32(&pData[4], SamplesPerSecond); |
836 |
memcpy(&pData[8], &AverageBytesPerSecond, 4); |
store32(&pData[8], AverageBytesPerSecond); |
837 |
memcpy(&pData[12], &BlockAlign, 2); |
store16(&pData[12], BlockAlign); |
838 |
memcpy(&pData[14], &BitDepth, 2); // assuming PCM format |
store16(&pData[14], BitDepth); // assuming PCM format |
839 |
} |
} |
840 |
|
|
841 |
|
|
919 |
} |
} |
920 |
|
|
921 |
/** |
/** |
922 |
|
* Modifies the key range of this Region and makes sure the respective |
923 |
|
* chunks are in correct order. |
924 |
|
* |
925 |
|
* @param Low - lower end of key range |
926 |
|
* @param High - upper end of key range |
927 |
|
*/ |
928 |
|
void Region::SetKeyRange(uint16_t Low, uint16_t High) { |
929 |
|
KeyRange.low = Low; |
930 |
|
KeyRange.high = High; |
931 |
|
|
932 |
|
// make sure regions are already loaded |
933 |
|
Instrument* pInstrument = (Instrument*) GetParent(); |
934 |
|
if (!pInstrument->pRegions) pInstrument->LoadRegions(); |
935 |
|
if (!pInstrument->pRegions) return; |
936 |
|
|
937 |
|
// find the r which is the first one to the right of this region |
938 |
|
// at its new position |
939 |
|
Region* r = NULL; |
940 |
|
Region* prev_region = NULL; |
941 |
|
for ( |
942 |
|
Instrument::RegionList::iterator iter = pInstrument->pRegions->begin(); |
943 |
|
iter != pInstrument->pRegions->end(); iter++ |
944 |
|
) { |
945 |
|
if ((*iter)->KeyRange.low > this->KeyRange.low) { |
946 |
|
r = *iter; |
947 |
|
break; |
948 |
|
} |
949 |
|
prev_region = *iter; |
950 |
|
} |
951 |
|
|
952 |
|
// place this region before r if it's not already there |
953 |
|
if (prev_region != this) pInstrument->MoveRegion(this, r); |
954 |
|
} |
955 |
|
|
956 |
|
/** |
957 |
* Apply Region settings to the respective RIFF chunks. You have to |
* Apply Region settings to the respective RIFF chunks. You have to |
958 |
* call File::Save() to make changes persistent. |
* call File::Save() to make changes persistent. |
959 |
* |
* |
968 |
? FormatOptionFlags | F_RGN_OPTION_SELFNONEXCLUSIVE |
? FormatOptionFlags | F_RGN_OPTION_SELFNONEXCLUSIVE |
969 |
: FormatOptionFlags & (~F_RGN_OPTION_SELFNONEXCLUSIVE); |
: FormatOptionFlags & (~F_RGN_OPTION_SELFNONEXCLUSIVE); |
970 |
// update 'rgnh' chunk |
// update 'rgnh' chunk |
971 |
memcpy(&pData[0], &KeyRange, 2 * 2); |
store16(&pData[0], KeyRange.low); |
972 |
memcpy(&pData[4], &VelocityRange, 2 * 2); |
store16(&pData[2], KeyRange.high); |
973 |
memcpy(&pData[8], &FormatOptionFlags, 2); |
store16(&pData[4], VelocityRange.low); |
974 |
memcpy(&pData[10], &KeyGroup, 2); |
store16(&pData[6], VelocityRange.high); |
975 |
if (rgnh->GetSize() >= 14) memcpy(&pData[12], &Layer, 2); |
store16(&pData[8], FormatOptionFlags); |
976 |
|
store16(&pData[10], KeyGroup); |
977 |
|
if (rgnh->GetSize() >= 14) store16(&pData[12], Layer); |
978 |
|
|
979 |
// update chunks of base classes as well (but skip Resource, |
// update chunks of base classes as well (but skip Resource, |
980 |
// as a rgn doesn't seem to have dlid and INFO chunks) |
// as a rgn doesn't seem to have dlid and INFO chunks) |
1004 |
} |
} |
1005 |
} |
} |
1006 |
} |
} |
|
if (index < 0) throw Exception("Could not save Region, could not find Region's sample"); |
|
1007 |
WavePoolTableIndex = index; |
WavePoolTableIndex = index; |
1008 |
// update 'wlnk' chunk |
// update 'wlnk' chunk |
1009 |
memcpy(&pData[0], &WaveLinkOptionFlags, 2); |
store16(&pData[0], WaveLinkOptionFlags); |
1010 |
memcpy(&pData[2], &PhaseGroup, 2); |
store16(&pData[2], PhaseGroup); |
1011 |
memcpy(&pData[4], &Channel, 4); |
store32(&pData[4], Channel); |
1012 |
memcpy(&pData[8], &WavePoolTableIndex, 4); |
store32(&pData[8], WavePoolTableIndex); |
1013 |
} |
} |
1014 |
|
|
1015 |
|
|
1131 |
locale.bank = MIDI_BANK_ENCODE(MIDIBankCoarse, MIDIBankFine); |
locale.bank = MIDI_BANK_ENCODE(MIDIBankCoarse, MIDIBankFine); |
1132 |
locale.bank = (IsDrum) ? locale.bank | DRUM_TYPE_MASK : locale.bank & (~DRUM_TYPE_MASK); |
locale.bank = (IsDrum) ? locale.bank | DRUM_TYPE_MASK : locale.bank & (~DRUM_TYPE_MASK); |
1133 |
MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine); // just a sync, when we're at it |
MIDIBank = MIDI_BANK_MERGE(MIDIBankCoarse, MIDIBankFine); // just a sync, when we're at it |
1134 |
memcpy(&pData[0], &Regions, 4); |
store32(&pData[0], Regions); |
1135 |
memcpy(&pData[4], &locale, 2 * 4); |
store32(&pData[4], locale.bank); |
1136 |
|
store32(&pData[8], locale.instrument); |
1137 |
// update Region's chunks |
// update Region's chunks |
1138 |
if (!pRegions) return; |
if (!pRegions) return; |
1139 |
RegionList::iterator iter = pRegions->begin(); |
RegionList::iterator iter = pRegions->begin(); |
1175 |
* a DLS file. |
* a DLS file. |
1176 |
*/ |
*/ |
1177 |
File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) { |
File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) { |
1178 |
|
pRIFF->SetByteOrder(RIFF::endian_little); |
1179 |
pVersion = new version_t; |
pVersion = new version_t; |
1180 |
pVersion->major = 0; |
pVersion->major = 0; |
1181 |
pVersion->minor = 0; |
pVersion->minor = 0; |
1430 |
RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS); |
RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS); |
1431 |
if (!ckVersion) ckVersion = pRIFF->AddSubChunk(CHUNK_ID_VERS, 8); |
if (!ckVersion) ckVersion = pRIFF->AddSubChunk(CHUNK_ID_VERS, 8); |
1432 |
uint8_t* pData = (uint8_t*) ckVersion->LoadChunkData(); |
uint8_t* pData = (uint8_t*) ckVersion->LoadChunkData(); |
1433 |
memcpy(pData, pVersion, 2 * 4); |
store16(&pData[0], pVersion->minor); |
1434 |
|
store16(&pData[2], pVersion->major); |
1435 |
|
store16(&pData[4], pVersion->build); |
1436 |
|
store16(&pData[6], pVersion->release); |
1437 |
} |
} |
1438 |
|
|
1439 |
// update 'colh' chunk |
// update 'colh' chunk |
1441 |
RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH); |
RIFF::Chunk* colh = pRIFF->GetSubChunk(CHUNK_ID_COLH); |
1442 |
if (!colh) colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4); |
if (!colh) colh = pRIFF->AddSubChunk(CHUNK_ID_COLH, 4); |
1443 |
uint8_t* pData = (uint8_t*) colh->LoadChunkData(); |
uint8_t* pData = (uint8_t*) colh->LoadChunkData(); |
1444 |
memcpy(pData, &Instruments, 4); |
store32(pData, Instruments); |
1445 |
|
|
1446 |
// update instrument's chunks |
// update instrument's chunks |
1447 |
if (pInstruments) { |
if (pInstruments) { |
1461 |
ptbl->Resize(iPtblSize); |
ptbl->Resize(iPtblSize); |
1462 |
pData = (uint8_t*) ptbl->LoadChunkData(); |
pData = (uint8_t*) ptbl->LoadChunkData(); |
1463 |
WavePoolCount = iSamples; |
WavePoolCount = iSamples; |
1464 |
memcpy(&pData[4], &WavePoolCount, 4); |
store32(&pData[4], WavePoolCount); |
1465 |
// we actually update the sample offsets in the pool table when we Save() |
// we actually update the sample offsets in the pool table when we Save() |
1466 |
memset(&pData[WavePoolHeaderSize], 0, iPtblSize - WavePoolHeaderSize); |
memset(&pData[WavePoolHeaderSize], 0, iPtblSize - WavePoolHeaderSize); |
1467 |
|
|
1550 |
unsigned long ulOriginalPos = ptbl->GetPos(); |
unsigned long ulOriginalPos = ptbl->GetPos(); |
1551 |
// update headers |
// update headers |
1552 |
ptbl->SetPos(0); |
ptbl->SetPos(0); |
1553 |
ptbl->WriteUint32(&WavePoolHeaderSize); |
uint32_t tmp = WavePoolHeaderSize; |
1554 |
ptbl->WriteUint32(&WavePoolCount); |
ptbl->WriteUint32(&tmp); |
1555 |
|
tmp = WavePoolCount; |
1556 |
|
ptbl->WriteUint32(&tmp); |
1557 |
// update offsets |
// update offsets |
1558 |
ptbl->SetPos(WavePoolHeaderSize); |
ptbl->SetPos(WavePoolHeaderSize); |
1559 |
if (b64BitWavePoolOffsets) { |
if (b64BitWavePoolOffsets) { |
1560 |
for (int i = 0 ; i < WavePoolCount ; i++) { |
for (int i = 0 ; i < WavePoolCount ; i++) { |
1561 |
ptbl->WriteUint32(&pWavePoolTableHi[i]); |
tmp = pWavePoolTableHi[i]; |
1562 |
ptbl->WriteUint32(&pWavePoolTable[i]); |
ptbl->WriteUint32(&tmp); |
1563 |
|
tmp = pWavePoolTable[i]; |
1564 |
|
ptbl->WriteUint32(&tmp); |
1565 |
} |
} |
1566 |
} else { // conventional 32 bit offsets |
} else { // conventional 32 bit offsets |
1567 |
for (int i = 0 ; i < WavePoolCount ; i++) |
for (int i = 0 ; i < WavePoolCount ; i++) { |
1568 |
ptbl->WriteUint32(&pWavePoolTable[i]); |
tmp = pWavePoolTable[i]; |
1569 |
|
ptbl->WriteUint32(&tmp); |
1570 |
|
} |
1571 |
} |
} |
1572 |
// restore 'ptbl' chunk's original read/write position |
// restore 'ptbl' chunk's original read/write position |
1573 |
ptbl->SetPos(ulOriginalPos); |
ptbl->SetPos(ulOriginalPos); |