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 |
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()+1 : Software.length()+1) : 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->usData1 = uuid.Data2; |
445 |
|
pDLSID->usData2 = 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 *************** |
549 |
/** |
/** |
550 |
* Adds a new sample loop with the provided loop definition. |
* Adds a new sample loop with the provided loop definition. |
551 |
* |
* |
552 |
* @param - points to a loop definition that is to be copied |
* @param pLoopDef - points to a loop definition that is to be copied |
553 |
*/ |
*/ |
554 |
void Sampler::AddSampleLoop(sample_loop_t* pLoopDef) { |
void Sampler::AddSampleLoop(sample_loop_t* pLoopDef) { |
555 |
sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1]; |
sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1]; |
1135 |
* a DLS file. |
* a DLS file. |
1136 |
*/ |
*/ |
1137 |
File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) { |
File::File() : Resource(NULL, pRIFF = new RIFF::File(RIFF_TYPE_DLS)) { |
1138 |
|
pRIFF->SetByteOrder(RIFF::endian_little); |
1139 |
pVersion = new version_t; |
pVersion = new version_t; |
1140 |
pVersion->major = 0; |
pVersion->major = 0; |
1141 |
pVersion->minor = 0; |
pVersion->minor = 0; |