2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file access library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2007 by Christian Schoenebeck * |
* Copyright (C) 2003-2009 by Christian Schoenebeck * |
6 |
* <cuse@users.sourceforge.net> * |
* <cuse@users.sourceforge.net> * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
23 |
|
|
24 |
#include "DLS.h" |
#include "DLS.h" |
25 |
|
|
26 |
|
#include <algorithm> |
27 |
#include <time.h> |
#include <time.h> |
28 |
|
|
29 |
#ifdef __APPLE__ |
#ifdef __APPLE__ |
240 |
* @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 |
241 |
*/ |
*/ |
242 |
Info::Info(RIFF::List* list) { |
Info::Info(RIFF::List* list) { |
243 |
FixedStringLengths = NULL; |
pFixedStringLengths = NULL; |
244 |
pResourceListChunk = list; |
pResourceListChunk = list; |
245 |
if (list) { |
if (list) { |
246 |
RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO); |
RIFF::List* lstINFO = list->GetSubList(LIST_TYPE_INFO); |
269 |
Info::~Info() { |
Info::~Info() { |
270 |
} |
} |
271 |
|
|
272 |
|
/** |
273 |
|
* Forces specific Info fields to be of a fixed length when being saved |
274 |
|
* to a file. By default the respective RIFF chunk of an Info field |
275 |
|
* will have a size analogue to its actual string length. With this |
276 |
|
* method however this behavior can be overridden, allowing to force an |
277 |
|
* arbitrary fixed size individually for each Info field. |
278 |
|
* |
279 |
|
* This method is used as a workaround for the gig format, not for DLS. |
280 |
|
* |
281 |
|
* @param lengths - NULL terminated array of string_length_t elements |
282 |
|
*/ |
283 |
|
void Info::SetFixedStringLengths(const string_length_t* lengths) { |
284 |
|
pFixedStringLengths = lengths; |
285 |
|
} |
286 |
|
|
287 |
/** @brief Load given INFO field. |
/** @brief Load given INFO field. |
288 |
* |
* |
289 |
* Load INFO field from INFO chunk with chunk ID \a ChunkID from INFO |
* Load INFO field from INFO chunk with chunk ID \a ChunkID from INFO |
311 |
*/ |
*/ |
312 |
void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) { |
void Info::SaveString(uint32_t ChunkID, RIFF::List* lstINFO, const String& s, const String& sDefault) { |
313 |
int size = 0; |
int size = 0; |
314 |
if (FixedStringLengths) { |
if (pFixedStringLengths) { |
315 |
for (int i = 0 ; FixedStringLengths[i].length ; i++) { |
for (int i = 0 ; pFixedStringLengths[i].length ; i++) { |
316 |
if (FixedStringLengths[i].chunkId == ChunkID) { |
if (pFixedStringLengths[i].chunkId == ChunkID) { |
317 |
size = FixedStringLengths[i].length; |
size = pFixedStringLengths[i].length; |
318 |
break; |
break; |
319 |
} |
} |
320 |
} |
} |
600 |
// copy old loops array (skipping given loop) |
// copy old loops array (skipping given loop) |
601 |
for (int i = 0, o = 0; i < SampleLoops; i++) { |
for (int i = 0, o = 0; i < SampleLoops; i++) { |
602 |
if (&pSampleLoops[i] == pLoopDef) continue; |
if (&pSampleLoops[i] == pLoopDef) continue; |
603 |
if (o == SampleLoops - 1) |
if (o == SampleLoops - 1) { |
604 |
|
delete[] pNewLoops; |
605 |
throw Exception("Could not delete Sample Loop, because it does not exist"); |
throw Exception("Could not delete Sample Loop, because it does not exist"); |
606 |
|
} |
607 |
pNewLoops[o] = pSampleLoops[i]; |
pNewLoops[o] = pSampleLoops[i]; |
608 |
o++; |
o++; |
609 |
} |
} |
1433 |
} |
} |
1434 |
|
|
1435 |
/** |
/** |
1436 |
|
* Returns extension file of given index. Extension files are used |
1437 |
|
* sometimes to circumvent the 2 GB file size limit of the RIFF format and |
1438 |
|
* of certain operating systems in general. In this case, instead of just |
1439 |
|
* using one file, the content is spread among several files with similar |
1440 |
|
* file name scheme. This is especially used by some GigaStudio sound |
1441 |
|
* libraries. |
1442 |
|
* |
1443 |
|
* @param index - index of extension file |
1444 |
|
* @returns sought extension file, NULL if index out of bounds |
1445 |
|
* @see GetFileName() |
1446 |
|
*/ |
1447 |
|
RIFF::File* File::GetExtensionFile(int index) { |
1448 |
|
if (index < 0 || index >= ExtensionFiles.size()) return NULL; |
1449 |
|
std::list<RIFF::File*>::iterator iter = ExtensionFiles.begin(); |
1450 |
|
for (int i = 0; iter != ExtensionFiles.end(); ++iter, ++i) |
1451 |
|
if (i == index) return *iter; |
1452 |
|
return NULL; |
1453 |
|
} |
1454 |
|
|
1455 |
|
/** @brief File name of this DLS file. |
1456 |
|
* |
1457 |
|
* This method returns the file name as it was provided when loading |
1458 |
|
* the respective DLS file. However in case the File object associates |
1459 |
|
* an empty, that is new DLS file, which was not yet saved to disk, |
1460 |
|
* this method will return an empty string. |
1461 |
|
* |
1462 |
|
* @see GetExtensionFile() |
1463 |
|
*/ |
1464 |
|
String File::GetFileName() { |
1465 |
|
return pRIFF->GetFileName(); |
1466 |
|
} |
1467 |
|
|
1468 |
|
/** |
1469 |
* Apply all the DLS file's current instruments, samples and settings to |
* Apply all the DLS file's current instruments, samples and settings to |
1470 |
* the respective RIFF chunks. You have to call Save() to make changes |
* the respective RIFF chunks. You have to call Save() to make changes |
1471 |
* persistent. |
* persistent. |