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-2016 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 * |
25 |
|
|
26 |
#include "helper.h" |
#include "helper.h" |
27 |
|
|
28 |
|
#include <algorithm> |
29 |
#include <math.h> |
#include <math.h> |
30 |
#include <iostream> |
#include <iostream> |
31 |
|
#include <assert.h> |
32 |
|
|
33 |
|
/// libgig's current file format version (for extending the original Giga file |
34 |
|
/// format with libgig's own custom data / custom features). |
35 |
|
#define GIG_FILE_EXT_VERSION 2 |
36 |
|
|
37 |
/// Initial size of the sample buffer which is used for decompression of |
/// Initial size of the sample buffer which is used for decompression of |
38 |
/// compressed sample wave streams - this value should always be bigger than |
/// compressed sample wave streams - this value should always be bigger than |
57 |
|
|
58 |
namespace gig { |
namespace gig { |
59 |
|
|
|
// *************** progress_t *************** |
|
|
// * |
|
|
|
|
|
progress_t::progress_t() { |
|
|
callback = NULL; |
|
|
custom = NULL; |
|
|
__range_min = 0.0f; |
|
|
__range_max = 1.0f; |
|
|
} |
|
|
|
|
|
// private helper function to convert progress of a subprocess into the global progress |
|
|
static void __notify_progress(progress_t* pProgress, float subprogress) { |
|
|
if (pProgress && pProgress->callback) { |
|
|
const float totalrange = pProgress->__range_max - pProgress->__range_min; |
|
|
const float totalprogress = pProgress->__range_min + subprogress * totalrange; |
|
|
pProgress->factor = totalprogress; |
|
|
pProgress->callback(pProgress); // now actually notify about the progress |
|
|
} |
|
|
} |
|
|
|
|
|
// private helper function to divide a progress into subprogresses |
|
|
static void __divide_progress(progress_t* pParentProgress, progress_t* pSubProgress, float totalTasks, float currentTask) { |
|
|
if (pParentProgress && pParentProgress->callback) { |
|
|
const float totalrange = pParentProgress->__range_max - pParentProgress->__range_min; |
|
|
pSubProgress->callback = pParentProgress->callback; |
|
|
pSubProgress->custom = pParentProgress->custom; |
|
|
pSubProgress->__range_min = pParentProgress->__range_min + totalrange * currentTask / totalTasks; |
|
|
pSubProgress->__range_max = pSubProgress->__range_min + totalrange / totalTasks; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
60 |
// *************** Internal functions for sample decompression *************** |
// *************** Internal functions for sample decompression *************** |
61 |
// * |
// * |
62 |
|
|
95 |
void Decompress16(int compressionmode, const unsigned char* params, |
void Decompress16(int compressionmode, const unsigned char* params, |
96 |
int srcStep, int dstStep, |
int srcStep, int dstStep, |
97 |
const unsigned char* pSrc, int16_t* pDst, |
const unsigned char* pSrc, int16_t* pDst, |
98 |
unsigned long currentframeoffset, |
file_offset_t currentframeoffset, |
99 |
unsigned long copysamples) |
file_offset_t copysamples) |
100 |
{ |
{ |
101 |
switch (compressionmode) { |
switch (compressionmode) { |
102 |
case 0: // 16 bit uncompressed |
case 0: // 16 bit uncompressed |
132 |
|
|
133 |
void Decompress24(int compressionmode, const unsigned char* params, |
void Decompress24(int compressionmode, const unsigned char* params, |
134 |
int dstStep, const unsigned char* pSrc, uint8_t* pDst, |
int dstStep, const unsigned char* pSrc, uint8_t* pDst, |
135 |
unsigned long currentframeoffset, |
file_offset_t currentframeoffset, |
136 |
unsigned long copysamples, int truncatedBits) |
file_offset_t copysamples, int truncatedBits) |
137 |
{ |
{ |
138 |
int y, dy, ddy, dddy; |
int y, dy, ddy, dddy; |
139 |
|
|
228 |
} |
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
// *************** Internal CRC-32 (Cyclic Redundancy Check) functions *************** |
233 |
|
// * |
234 |
|
|
235 |
|
static uint32_t* __initCRCTable() { |
236 |
|
static uint32_t res[256]; |
237 |
|
|
238 |
|
for (int i = 0 ; i < 256 ; i++) { |
239 |
|
uint32_t c = i; |
240 |
|
for (int j = 0 ; j < 8 ; j++) { |
241 |
|
c = (c & 1) ? 0xedb88320 ^ (c >> 1) : c >> 1; |
242 |
|
} |
243 |
|
res[i] = c; |
244 |
|
} |
245 |
|
return res; |
246 |
|
} |
247 |
|
|
248 |
|
static const uint32_t* __CRCTable = __initCRCTable(); |
249 |
|
|
250 |
|
/** |
251 |
|
* Initialize a CRC variable. |
252 |
|
* |
253 |
|
* @param crc - variable to be initialized |
254 |
|
*/ |
255 |
|
inline static void __resetCRC(uint32_t& crc) { |
256 |
|
crc = 0xffffffff; |
257 |
|
} |
258 |
|
|
259 |
|
/** |
260 |
|
* Used to calculate checksums of the sample data in a gig file. The |
261 |
|
* checksums are stored in the 3crc chunk of the gig file and |
262 |
|
* automatically updated when a sample is written with Sample::Write(). |
263 |
|
* |
264 |
|
* One should call __resetCRC() to initialize the CRC variable to be |
265 |
|
* used before calling this function the first time. |
266 |
|
* |
267 |
|
* After initializing the CRC variable one can call this function |
268 |
|
* arbitrary times, i.e. to split the overall CRC calculation into |
269 |
|
* steps. |
270 |
|
* |
271 |
|
* Once the whole data was processed by __calculateCRC(), one should |
272 |
|
* call __encodeCRC() to get the final CRC result. |
273 |
|
* |
274 |
|
* @param buf - pointer to data the CRC shall be calculated of |
275 |
|
* @param bufSize - size of the data to be processed |
276 |
|
* @param crc - variable the CRC sum shall be stored to |
277 |
|
*/ |
278 |
|
static void __calculateCRC(unsigned char* buf, int bufSize, uint32_t& crc) { |
279 |
|
for (int i = 0 ; i < bufSize ; i++) { |
280 |
|
crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); |
281 |
|
} |
282 |
|
} |
283 |
|
|
284 |
|
/** |
285 |
|
* Returns the final CRC result. |
286 |
|
* |
287 |
|
* @param crc - variable previously passed to __calculateCRC() |
288 |
|
*/ |
289 |
|
inline static uint32_t __encodeCRC(const uint32_t& crc) { |
290 |
|
return crc ^ 0xffffffff; |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
// *************** Other Internal functions *************** |
296 |
|
// * |
297 |
|
|
298 |
|
static split_type_t __resolveSplitType(dimension_t dimension) { |
299 |
|
return ( |
300 |
|
dimension == dimension_layer || |
301 |
|
dimension == dimension_samplechannel || |
302 |
|
dimension == dimension_releasetrigger || |
303 |
|
dimension == dimension_keyboard || |
304 |
|
dimension == dimension_roundrobin || |
305 |
|
dimension == dimension_random || |
306 |
|
dimension == dimension_smartmidi || |
307 |
|
dimension == dimension_roundrobinkeyboard |
308 |
|
) ? split_type_bit : split_type_normal; |
309 |
|
} |
310 |
|
|
311 |
|
static int __resolveZoneSize(dimension_def_t& dimension_definition) { |
312 |
|
return (dimension_definition.split_type == split_type_normal) |
313 |
|
? int(128.0 / dimension_definition.zones) : 0; |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
|
318 |
// *************** Sample *************** |
// *************** Sample *************** |
319 |
// * |
// * |
320 |
|
|
321 |
unsigned int Sample::Instances = 0; |
size_t Sample::Instances = 0; |
322 |
buffer_t Sample::InternalDecompressionBuffer; |
buffer_t Sample::InternalDecompressionBuffer; |
323 |
|
|
324 |
/** @brief Constructor. |
/** @brief Constructor. |
339 |
* @param fileNo - number of an extension file where this sample |
* @param fileNo - number of an extension file where this sample |
340 |
* is located, 0 otherwise |
* is located, 0 otherwise |
341 |
*/ |
*/ |
342 |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
343 |
pInfo->UseFixedLengthStrings = true; |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
344 |
|
{ CHUNK_ID_INAM, 64 }, |
345 |
|
{ 0, 0 } |
346 |
|
}; |
347 |
|
pInfo->SetFixedStringLengths(fixedStringLengths); |
348 |
Instances++; |
Instances++; |
349 |
FileNo = fileNo; |
FileNo = fileNo; |
350 |
|
|
351 |
|
__resetCRC(crc); |
352 |
|
|
353 |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
354 |
if (pCk3gix) { |
if (pCk3gix) { |
355 |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
381 |
Manufacturer = 0; |
Manufacturer = 0; |
382 |
Product = 0; |
Product = 0; |
383 |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
384 |
MIDIUnityNote = 64; |
MIDIUnityNote = 60; |
385 |
FineTune = 0; |
FineTune = 0; |
386 |
|
SMPTEFormat = smpte_format_no_offset; |
387 |
SMPTEOffset = 0; |
SMPTEOffset = 0; |
388 |
Loops = 0; |
Loops = 0; |
389 |
LoopID = 0; |
LoopID = 0; |
390 |
|
LoopType = loop_type_normal; |
391 |
LoopStart = 0; |
LoopStart = 0; |
392 |
LoopEnd = 0; |
LoopEnd = 0; |
393 |
LoopFraction = 0; |
LoopFraction = 0; |
427 |
} |
} |
428 |
|
|
429 |
/** |
/** |
430 |
|
* Make a (semi) deep copy of the Sample object given by @a orig (without |
431 |
|
* the actual waveform data) and assign it to this object. |
432 |
|
* |
433 |
|
* Discussion: copying .gig samples is a bit tricky. It requires three |
434 |
|
* steps: |
435 |
|
* 1. Copy sample's meta informations (done by CopyAssignMeta()) including |
436 |
|
* its new sample waveform data size. |
437 |
|
* 2. Saving the file (done by File::Save()) so that it gains correct size |
438 |
|
* and layout for writing the actual wave form data directly to disc |
439 |
|
* in next step. |
440 |
|
* 3. Copy the waveform data with disk streaming (done by CopyAssignWave()). |
441 |
|
* |
442 |
|
* @param orig - original Sample object to be copied from |
443 |
|
*/ |
444 |
|
void Sample::CopyAssignMeta(const Sample* orig) { |
445 |
|
// handle base classes |
446 |
|
DLS::Sample::CopyAssignCore(orig); |
447 |
|
|
448 |
|
// handle actual own attributes of this class |
449 |
|
Manufacturer = orig->Manufacturer; |
450 |
|
Product = orig->Product; |
451 |
|
SamplePeriod = orig->SamplePeriod; |
452 |
|
MIDIUnityNote = orig->MIDIUnityNote; |
453 |
|
FineTune = orig->FineTune; |
454 |
|
SMPTEFormat = orig->SMPTEFormat; |
455 |
|
SMPTEOffset = orig->SMPTEOffset; |
456 |
|
Loops = orig->Loops; |
457 |
|
LoopID = orig->LoopID; |
458 |
|
LoopType = orig->LoopType; |
459 |
|
LoopStart = orig->LoopStart; |
460 |
|
LoopEnd = orig->LoopEnd; |
461 |
|
LoopSize = orig->LoopSize; |
462 |
|
LoopFraction = orig->LoopFraction; |
463 |
|
LoopPlayCount = orig->LoopPlayCount; |
464 |
|
|
465 |
|
// schedule resizing this sample to the given sample's size |
466 |
|
Resize(orig->GetSize()); |
467 |
|
} |
468 |
|
|
469 |
|
/** |
470 |
|
* Should be called after CopyAssignMeta() and File::Save() sequence. |
471 |
|
* Read more about it in the discussion of CopyAssignMeta(). This method |
472 |
|
* copies the actual waveform data by disk streaming. |
473 |
|
* |
474 |
|
* @e CAUTION: this method is currently not thread safe! During this |
475 |
|
* operation the sample must not be used for other purposes by other |
476 |
|
* threads! |
477 |
|
* |
478 |
|
* @param orig - original Sample object to be copied from |
479 |
|
*/ |
480 |
|
void Sample::CopyAssignWave(const Sample* orig) { |
481 |
|
const int iReadAtOnce = 32*1024; |
482 |
|
char* buf = new char[iReadAtOnce * orig->FrameSize]; |
483 |
|
Sample* pOrig = (Sample*) orig; //HACK: remove constness for now |
484 |
|
file_offset_t restorePos = pOrig->GetPos(); |
485 |
|
pOrig->SetPos(0); |
486 |
|
SetPos(0); |
487 |
|
for (file_offset_t n = pOrig->Read(buf, iReadAtOnce); n; |
488 |
|
n = pOrig->Read(buf, iReadAtOnce)) |
489 |
|
{ |
490 |
|
Write(buf, n); |
491 |
|
} |
492 |
|
pOrig->SetPos(restorePos); |
493 |
|
delete [] buf; |
494 |
|
} |
495 |
|
|
496 |
|
/** |
497 |
* Apply sample and its settings to the respective RIFF chunks. You have |
* Apply sample and its settings to the respective RIFF chunks. You have |
498 |
* to call File::Save() to make changes persistent. |
* to call File::Save() to make changes persistent. |
499 |
* |
* |
500 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
501 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
502 |
* |
* |
503 |
|
* @param pProgress - callback function for progress notification |
504 |
* @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data |
* @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data |
505 |
* was provided yet |
* was provided yet |
506 |
* @throws gig::Exception if there is any invalid sample setting |
* @throws gig::Exception if there is any invalid sample setting |
507 |
*/ |
*/ |
508 |
void Sample::UpdateChunks() { |
void Sample::UpdateChunks(progress_t* pProgress) { |
509 |
// first update base class's chunks |
// first update base class's chunks |
510 |
DLS::Sample::UpdateChunks(); |
DLS::Sample::UpdateChunks(pProgress); |
511 |
|
|
512 |
// make sure 'smpl' chunk exists |
// make sure 'smpl' chunk exists |
513 |
pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL); |
pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL); |
514 |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
if (!pCkSmpl) { |
515 |
|
pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
516 |
|
memset(pCkSmpl->LoadChunkData(), 0, 60); |
517 |
|
} |
518 |
// update 'smpl' chunk |
// update 'smpl' chunk |
519 |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
520 |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
521 |
memcpy(&pData[0], &Manufacturer, 4); |
store32(&pData[0], Manufacturer); |
522 |
memcpy(&pData[4], &Product, 4); |
store32(&pData[4], Product); |
523 |
memcpy(&pData[8], &SamplePeriod, 4); |
store32(&pData[8], SamplePeriod); |
524 |
memcpy(&pData[12], &MIDIUnityNote, 4); |
store32(&pData[12], MIDIUnityNote); |
525 |
memcpy(&pData[16], &FineTune, 4); |
store32(&pData[16], FineTune); |
526 |
memcpy(&pData[20], &SMPTEFormat, 4); |
store32(&pData[20], SMPTEFormat); |
527 |
memcpy(&pData[24], &SMPTEOffset, 4); |
store32(&pData[24], SMPTEOffset); |
528 |
memcpy(&pData[28], &Loops, 4); |
store32(&pData[28], Loops); |
529 |
|
|
530 |
// we skip 'manufByt' for now (4 bytes) |
// we skip 'manufByt' for now (4 bytes) |
531 |
|
|
532 |
memcpy(&pData[36], &LoopID, 4); |
store32(&pData[36], LoopID); |
533 |
memcpy(&pData[40], &LoopType, 4); |
store32(&pData[40], LoopType); |
534 |
memcpy(&pData[44], &LoopStart, 4); |
store32(&pData[44], LoopStart); |
535 |
memcpy(&pData[48], &LoopEnd, 4); |
store32(&pData[48], LoopEnd); |
536 |
memcpy(&pData[52], &LoopFraction, 4); |
store32(&pData[52], LoopFraction); |
537 |
memcpy(&pData[56], &LoopPlayCount, 4); |
store32(&pData[56], LoopPlayCount); |
538 |
|
|
539 |
// make sure '3gix' chunk exists |
// make sure '3gix' chunk exists |
540 |
pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX); |
554 |
} |
} |
555 |
// update '3gix' chunk |
// update '3gix' chunk |
556 |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
557 |
memcpy(&pData[0], &iSampleGroup, 2); |
store16(&pData[0], iSampleGroup); |
558 |
|
|
559 |
|
// if the library user toggled the "Compressed" attribute from true to |
560 |
|
// false, then the EWAV chunk associated with compressed samples needs |
561 |
|
// to be deleted |
562 |
|
RIFF::Chunk* ewav = pWaveList->GetSubChunk(CHUNK_ID_EWAV); |
563 |
|
if (ewav && !Compressed) { |
564 |
|
pWaveList->DeleteSubChunk(ewav); |
565 |
|
} |
566 |
} |
} |
567 |
|
|
568 |
/// Scans compressed samples for mandatory informations (e.g. actual number of total sample points). |
/// Scans compressed samples for mandatory informations (e.g. actual number of total sample points). |
569 |
void Sample::ScanCompressedSample() { |
void Sample::ScanCompressedSample() { |
570 |
//TODO: we have to add some more scans here (e.g. determine compression rate) |
//TODO: we have to add some more scans here (e.g. determine compression rate) |
571 |
this->SamplesTotal = 0; |
this->SamplesTotal = 0; |
572 |
std::list<unsigned long> frameOffsets; |
std::list<file_offset_t> frameOffsets; |
573 |
|
|
574 |
SamplesPerFrame = BitDepth == 24 ? 256 : 2048; |
SamplesPerFrame = BitDepth == 24 ? 256 : 2048; |
575 |
WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag |
WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag |
585 |
const int mode_l = pCkData->ReadUint8(); |
const int mode_l = pCkData->ReadUint8(); |
586 |
const int mode_r = pCkData->ReadUint8(); |
const int mode_r = pCkData->ReadUint8(); |
587 |
if (mode_l > 5 || mode_r > 5) throw gig::Exception("Unknown compression mode"); |
if (mode_l > 5 || mode_r > 5) throw gig::Exception("Unknown compression mode"); |
588 |
const unsigned long frameSize = bytesPerFrame[mode_l] + bytesPerFrame[mode_r]; |
const file_offset_t frameSize = bytesPerFrame[mode_l] + bytesPerFrame[mode_r]; |
589 |
|
|
590 |
if (pCkData->RemainingBytes() <= frameSize) { |
if (pCkData->RemainingBytes() <= frameSize) { |
591 |
SamplesInLastFrame = |
SamplesInLastFrame = |
604 |
|
|
605 |
const int mode = pCkData->ReadUint8(); |
const int mode = pCkData->ReadUint8(); |
606 |
if (mode > 5) throw gig::Exception("Unknown compression mode"); |
if (mode > 5) throw gig::Exception("Unknown compression mode"); |
607 |
const unsigned long frameSize = bytesPerFrame[mode]; |
const file_offset_t frameSize = bytesPerFrame[mode]; |
608 |
|
|
609 |
if (pCkData->RemainingBytes() <= frameSize) { |
if (pCkData->RemainingBytes() <= frameSize) { |
610 |
SamplesInLastFrame = |
SamplesInLastFrame = |
620 |
|
|
621 |
// Build the frames table (which is used for fast resolving of a frame's chunk offset) |
// Build the frames table (which is used for fast resolving of a frame's chunk offset) |
622 |
if (FrameTable) delete[] FrameTable; |
if (FrameTable) delete[] FrameTable; |
623 |
FrameTable = new unsigned long[frameOffsets.size()]; |
FrameTable = new file_offset_t[frameOffsets.size()]; |
624 |
std::list<unsigned long>::iterator end = frameOffsets.end(); |
std::list<file_offset_t>::iterator end = frameOffsets.end(); |
625 |
std::list<unsigned long>::iterator iter = frameOffsets.begin(); |
std::list<file_offset_t>::iterator iter = frameOffsets.begin(); |
626 |
for (int i = 0; iter != end; i++, iter++) { |
for (int i = 0; iter != end; i++, iter++) { |
627 |
FrameTable[i] = *iter; |
FrameTable[i] = *iter; |
628 |
} |
} |
663 |
* the cached sample data in bytes |
* the cached sample data in bytes |
664 |
* @see ReleaseSampleData(), Read(), SetPos() |
* @see ReleaseSampleData(), Read(), SetPos() |
665 |
*/ |
*/ |
666 |
buffer_t Sample::LoadSampleData(unsigned long SampleCount) { |
buffer_t Sample::LoadSampleData(file_offset_t SampleCount) { |
667 |
return LoadSampleDataWithNullSamplesExtension(SampleCount, 0); // 0 amount of NullSamples |
return LoadSampleDataWithNullSamplesExtension(SampleCount, 0); // 0 amount of NullSamples |
668 |
} |
} |
669 |
|
|
722 |
* size of the cached sample data in bytes |
* size of the cached sample data in bytes |
723 |
* @see ReleaseSampleData(), Read(), SetPos() |
* @see ReleaseSampleData(), Read(), SetPos() |
724 |
*/ |
*/ |
725 |
buffer_t Sample::LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount) { |
buffer_t Sample::LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount) { |
726 |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
727 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
728 |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
file_offset_t allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
729 |
|
SetPos(0); // reset read position to begin of sample |
730 |
RAMCache.pStart = new int8_t[allocationsize]; |
RAMCache.pStart = new int8_t[allocationsize]; |
731 |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
732 |
RAMCache.NullExtensionSize = allocationsize - RAMCache.Size; |
RAMCache.NullExtensionSize = allocationsize - RAMCache.Size; |
764 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
765 |
RAMCache.pStart = NULL; |
RAMCache.pStart = NULL; |
766 |
RAMCache.Size = 0; |
RAMCache.Size = 0; |
767 |
|
RAMCache.NullExtensionSize = 0; |
768 |
} |
} |
769 |
|
|
770 |
/** @brief Resize sample. |
/** @brief Resize sample. |
789 |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
790 |
* other formats will fail! |
* other formats will fail! |
791 |
* |
* |
792 |
* @param iNewSize - new sample wave data size in sample points (must be |
* @param NewSize - new sample wave data size in sample points (must be |
793 |
* greater than zero) |
* greater than zero) |
794 |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
795 |
* or if \a iNewSize is less than 1 |
* @throws DLS::Exception if \a NewSize is less than 1 or unrealistic large |
796 |
* @throws gig::Exception if existing sample is compressed |
* @throws gig::Exception if existing sample is compressed |
797 |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
798 |
* DLS::Sample::FormatTag, File::Save() |
* DLS::Sample::FormatTag, File::Save() |
799 |
*/ |
*/ |
800 |
void Sample::Resize(int iNewSize) { |
void Sample::Resize(file_offset_t NewSize) { |
801 |
if (Compressed) throw gig::Exception("There is no support for modifying compressed samples (yet)"); |
if (Compressed) throw gig::Exception("There is no support for modifying compressed samples (yet)"); |
802 |
DLS::Sample::Resize(iNewSize); |
DLS::Sample::Resize(NewSize); |
803 |
} |
} |
804 |
|
|
805 |
/** |
/** |
823 |
* @returns the new sample position |
* @returns the new sample position |
824 |
* @see Read() |
* @see Read() |
825 |
*/ |
*/ |
826 |
unsigned long Sample::SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence) { |
file_offset_t Sample::SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence) { |
827 |
if (Compressed) { |
if (Compressed) { |
828 |
switch (Whence) { |
switch (Whence) { |
829 |
case RIFF::stream_curpos: |
case RIFF::stream_curpos: |
841 |
} |
} |
842 |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
843 |
|
|
844 |
unsigned long frame = this->SamplePos / 2048; // to which frame to jump |
file_offset_t frame = this->SamplePos / 2048; // to which frame to jump |
845 |
this->FrameOffset = this->SamplePos % 2048; // offset (in sample points) within that frame |
this->FrameOffset = this->SamplePos % 2048; // offset (in sample points) within that frame |
846 |
pCkData->SetPos(FrameTable[frame]); // set chunk pointer to the start of sought frame |
pCkData->SetPos(FrameTable[frame]); // set chunk pointer to the start of sought frame |
847 |
return this->SamplePos; |
return this->SamplePos; |
848 |
} |
} |
849 |
else { // not compressed |
else { // not compressed |
850 |
unsigned long orderedBytes = SampleCount * this->FrameSize; |
file_offset_t orderedBytes = SampleCount * this->FrameSize; |
851 |
unsigned long result = pCkData->SetPos(orderedBytes, Whence); |
file_offset_t result = pCkData->SetPos(orderedBytes, Whence); |
852 |
return (result == orderedBytes) ? SampleCount |
return (result == orderedBytes) ? SampleCount |
853 |
: result / this->FrameSize; |
: result / this->FrameSize; |
854 |
} |
} |
857 |
/** |
/** |
858 |
* Returns the current position in the sample (in sample points). |
* Returns the current position in the sample (in sample points). |
859 |
*/ |
*/ |
860 |
unsigned long Sample::GetPos() { |
file_offset_t Sample::GetPos() const { |
861 |
if (Compressed) return SamplePos; |
if (Compressed) return SamplePos; |
862 |
else return pCkData->GetPos() / FrameSize; |
else return pCkData->GetPos() / FrameSize; |
863 |
} |
} |
896 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
897 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
898 |
*/ |
*/ |
899 |
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, |
file_offset_t Sample::ReadAndLoop(void* pBuffer, file_offset_t SampleCount, playback_state_t* pPlaybackState, |
900 |
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
901 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
file_offset_t samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
902 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
903 |
|
|
904 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
936 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
937 |
// backward playback |
// backward playback |
938 |
|
|
939 |
unsigned long swapareastart = totalreadsamples; |
file_offset_t swapareastart = totalreadsamples; |
940 |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
file_offset_t loopoffset = GetPos() - loop.LoopStart; |
941 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
file_offset_t samplestoreadinloop = Min(samplestoread, loopoffset); |
942 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
file_offset_t reverseplaybackend = GetPos() - samplestoreadinloop; |
943 |
|
|
944 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
945 |
|
|
959 |
} |
} |
960 |
|
|
961 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
962 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
if (totalreadsamples > swapareastart) //FIXME: this if() is just a crash workaround for now (#102), but totalreadsamples <= swapareastart should never be the case, so there's probably still a bug above! |
963 |
|
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
964 |
} |
} |
965 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
966 |
break; |
break; |
987 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
988 |
// backward playback |
// backward playback |
989 |
|
|
990 |
unsigned long swapareastart = totalreadsamples; |
file_offset_t swapareastart = totalreadsamples; |
991 |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
file_offset_t loopoffset = GetPos() - loop.LoopStart; |
992 |
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * loop.LoopLength - loopoffset) |
file_offset_t samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * loop.LoopLength - loopoffset) |
993 |
: samplestoread; |
: samplestoread; |
994 |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
file_offset_t reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
995 |
|
|
996 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
997 |
|
|
1071 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
1072 |
* @see SetPos(), CreateDecompressionBuffer() |
* @see SetPos(), CreateDecompressionBuffer() |
1073 |
*/ |
*/ |
1074 |
unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer) { |
file_offset_t Sample::Read(void* pBuffer, file_offset_t SampleCount, buffer_t* pExternalDecompressionBuffer) { |
1075 |
if (SampleCount == 0) return 0; |
if (SampleCount == 0) return 0; |
1076 |
if (!Compressed) { |
if (!Compressed) { |
1077 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
1086 |
else { |
else { |
1087 |
if (this->SamplePos >= this->SamplesTotal) return 0; |
if (this->SamplePos >= this->SamplesTotal) return 0; |
1088 |
//TODO: efficiency: maybe we should test for an average compression rate |
//TODO: efficiency: maybe we should test for an average compression rate |
1089 |
unsigned long assumedsize = GuessSize(SampleCount), |
file_offset_t assumedsize = GuessSize(SampleCount), |
1090 |
remainingbytes = 0, // remaining bytes in the local buffer |
remainingbytes = 0, // remaining bytes in the local buffer |
1091 |
remainingsamples = SampleCount, |
remainingsamples = SampleCount, |
1092 |
copysamples, skipsamples, |
copysamples, skipsamples, |
1109 |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
1110 |
|
|
1111 |
while (remainingsamples && remainingbytes) { |
while (remainingsamples && remainingbytes) { |
1112 |
unsigned long framesamples = SamplesPerFrame; |
file_offset_t framesamples = SamplesPerFrame; |
1113 |
unsigned long framebytes, rightChannelOffset = 0, nextFrameOffset; |
file_offset_t framebytes, rightChannelOffset = 0, nextFrameOffset; |
1114 |
|
|
1115 |
int mode_l = *pSrc++, mode_r = 0; |
int mode_l = *pSrc++, mode_r = 0; |
1116 |
|
|
1250 |
* |
* |
1251 |
* Note: there is currently no support for writing compressed samples. |
* Note: there is currently no support for writing compressed samples. |
1252 |
* |
* |
1253 |
|
* For 16 bit samples, the data in the source buffer should be |
1254 |
|
* int16_t (using native endianness). For 24 bit, the buffer |
1255 |
|
* should contain three bytes per sample, little-endian. |
1256 |
|
* |
1257 |
* @param pBuffer - source buffer |
* @param pBuffer - source buffer |
1258 |
* @param SampleCount - number of sample points to write |
* @param SampleCount - number of sample points to write |
1259 |
* @throws DLS::Exception if current sample size is too small |
* @throws DLS::Exception if current sample size is too small |
1260 |
* @throws gig::Exception if sample is compressed |
* @throws gig::Exception if sample is compressed |
1261 |
* @see DLS::LoadSampleData() |
* @see DLS::LoadSampleData() |
1262 |
*/ |
*/ |
1263 |
unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) { |
file_offset_t Sample::Write(void* pBuffer, file_offset_t SampleCount) { |
1264 |
if (Compressed) throw gig::Exception("There is no support for writing compressed gig samples (yet)"); |
if (Compressed) throw gig::Exception("There is no support for writing compressed gig samples (yet)"); |
1265 |
return DLS::Sample::Write(pBuffer, SampleCount); |
|
1266 |
|
// if this is the first write in this sample, reset the |
1267 |
|
// checksum calculator |
1268 |
|
if (pCkData->GetPos() == 0) { |
1269 |
|
__resetCRC(crc); |
1270 |
|
} |
1271 |
|
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
1272 |
|
file_offset_t res; |
1273 |
|
if (BitDepth == 24) { |
1274 |
|
res = pCkData->Write(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
1275 |
|
} else { // 16 bit |
1276 |
|
res = Channels == 2 ? pCkData->Write(pBuffer, SampleCount << 1, 2) >> 1 |
1277 |
|
: pCkData->Write(pBuffer, SampleCount, 2); |
1278 |
|
} |
1279 |
|
__calculateCRC((unsigned char *)pBuffer, SampleCount * FrameSize, crc); |
1280 |
|
|
1281 |
|
// if this is the last write, update the checksum chunk in the |
1282 |
|
// file |
1283 |
|
if (pCkData->GetPos() == pCkData->GetSize()) { |
1284 |
|
File* pFile = static_cast<File*>(GetParent()); |
1285 |
|
pFile->SetSampleChecksum(this, __encodeCRC(crc)); |
1286 |
|
} |
1287 |
|
return res; |
1288 |
} |
} |
1289 |
|
|
1290 |
/** |
/** |
1303 |
* @returns allocated decompression buffer |
* @returns allocated decompression buffer |
1304 |
* @see DestroyDecompressionBuffer() |
* @see DestroyDecompressionBuffer() |
1305 |
*/ |
*/ |
1306 |
buffer_t Sample::CreateDecompressionBuffer(unsigned long MaxReadSize) { |
buffer_t Sample::CreateDecompressionBuffer(file_offset_t MaxReadSize) { |
1307 |
buffer_t result; |
buffer_t result; |
1308 |
const double worstCaseHeaderOverhead = |
const double worstCaseHeaderOverhead = |
1309 |
(256.0 /*frame size*/ + 12.0 /*header*/ + 2.0 /*compression type flag (stereo)*/) / 256.0; |
(256.0 /*frame size*/ + 12.0 /*header*/ + 2.0 /*compression type flag (stereo)*/) / 256.0; |
1310 |
result.Size = (unsigned long) (double(MaxReadSize) * 3.0 /*(24 Bit)*/ * 2.0 /*stereo*/ * worstCaseHeaderOverhead); |
result.Size = (file_offset_t) (double(MaxReadSize) * 3.0 /*(24 Bit)*/ * 2.0 /*stereo*/ * worstCaseHeaderOverhead); |
1311 |
result.pStart = new int8_t[result.Size]; |
result.pStart = new int8_t[result.Size]; |
1312 |
result.NullExtensionSize = 0; |
result.NullExtensionSize = 0; |
1313 |
return result; |
return result; |
1357 |
// *************** DimensionRegion *************** |
// *************** DimensionRegion *************** |
1358 |
// * |
// * |
1359 |
|
|
1360 |
uint DimensionRegion::Instances = 0; |
size_t DimensionRegion::Instances = 0; |
1361 |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
1362 |
|
|
1363 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1364 |
Instances++; |
Instances++; |
1365 |
|
|
1366 |
pSample = NULL; |
pSample = NULL; |
1367 |
|
pRegion = pParent; |
1368 |
|
|
1369 |
|
if (_3ewl->GetSubChunk(CHUNK_ID_WSMP)) memcpy(&Crossfade, &SamplerOptions, 4); |
1370 |
|
else memset(&Crossfade, 0, 4); |
1371 |
|
|
|
memcpy(&Crossfade, &SamplerOptions, 4); |
|
1372 |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
1373 |
|
|
1374 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
1482 |
: vcf_res_ctrl_none; |
: vcf_res_ctrl_none; |
1483 |
uint16_t eg3depth = _3ewa->ReadUint16(); |
uint16_t eg3depth = _3ewa->ReadUint16(); |
1484 |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
1485 |
: (-1) * (int16_t) ((eg3depth ^ 0xffff) + 1); /* binary complementary for negatives */ |
: (-1) * (int16_t) ((eg3depth ^ 0xfff) + 1); /* binary complementary for negatives */ |
1486 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1487 |
ChannelOffset = _3ewa->ReadUint8() / 4; |
ChannelOffset = _3ewa->ReadUint8() / 4; |
1488 |
uint8_t regoptions = _3ewa->ReadUint8(); |
uint8_t regoptions = _3ewa->ReadUint8(); |
1532 |
LFO1ControlDepth = 0; |
LFO1ControlDepth = 0; |
1533 |
LFO3ControlDepth = 0; |
LFO3ControlDepth = 0; |
1534 |
EG1Attack = 0.0; |
EG1Attack = 0.0; |
1535 |
EG1Decay1 = 0.0; |
EG1Decay1 = 0.005; |
1536 |
EG1Sustain = 0; |
EG1Sustain = 1000; |
1537 |
EG1Release = 0.0; |
EG1Release = 0.3; |
1538 |
EG1Controller.type = eg1_ctrl_t::type_none; |
EG1Controller.type = eg1_ctrl_t::type_none; |
1539 |
EG1Controller.controller_number = 0; |
EG1Controller.controller_number = 0; |
1540 |
EG1ControllerInvert = false; |
EG1ControllerInvert = false; |
1549 |
EG2ControllerReleaseInfluence = 0; |
EG2ControllerReleaseInfluence = 0; |
1550 |
LFO1Frequency = 1.0; |
LFO1Frequency = 1.0; |
1551 |
EG2Attack = 0.0; |
EG2Attack = 0.0; |
1552 |
EG2Decay1 = 0.0; |
EG2Decay1 = 0.005; |
1553 |
EG2Sustain = 0; |
EG2Sustain = 1000; |
1554 |
EG2Release = 0.0; |
EG2Release = 0.3; |
1555 |
LFO2ControlDepth = 0; |
LFO2ControlDepth = 0; |
1556 |
LFO2Frequency = 1.0; |
LFO2Frequency = 1.0; |
1557 |
LFO2InternalDepth = 0; |
LFO2InternalDepth = 0; |
1558 |
EG1Decay2 = 0.0; |
EG1Decay2 = 0.0; |
1559 |
EG1InfiniteSustain = false; |
EG1InfiniteSustain = true; |
1560 |
EG1PreAttack = 1000; |
EG1PreAttack = 0; |
1561 |
EG2Decay2 = 0.0; |
EG2Decay2 = 0.0; |
1562 |
EG2InfiniteSustain = false; |
EG2InfiniteSustain = true; |
1563 |
EG2PreAttack = 1000; |
EG2PreAttack = 0; |
1564 |
VelocityResponseCurve = curve_type_nonlinear; |
VelocityResponseCurve = curve_type_nonlinear; |
1565 |
VelocityResponseDepth = 3; |
VelocityResponseDepth = 3; |
1566 |
ReleaseVelocityResponseCurve = curve_type_nonlinear; |
ReleaseVelocityResponseCurve = curve_type_nonlinear; |
1603 |
VCFVelocityDynamicRange = 0x04; |
VCFVelocityDynamicRange = 0x04; |
1604 |
VCFVelocityCurve = curve_type_linear; |
VCFVelocityCurve = curve_type_linear; |
1605 |
VCFType = vcf_type_lowpass; |
VCFType = vcf_type_lowpass; |
1606 |
memset(DimensionUpperLimits, 0, 8); |
memset(DimensionUpperLimits, 127, 8); |
1607 |
} |
} |
1608 |
|
|
1609 |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
1610 |
VelocityResponseDepth, |
VelocityResponseDepth, |
1611 |
VelocityResponseCurveScaling); |
VelocityResponseCurveScaling); |
1612 |
|
|
1613 |
curve_type_t curveType = ReleaseVelocityResponseCurve; |
pVelocityReleaseTable = GetReleaseVelocityTable( |
1614 |
uint8_t depth = ReleaseVelocityResponseDepth; |
ReleaseVelocityResponseCurve, |
1615 |
|
ReleaseVelocityResponseDepth |
1616 |
|
); |
1617 |
|
|
1618 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, |
1619 |
|
VCFVelocityDynamicRange, |
1620 |
|
VCFVelocityScale, |
1621 |
|
VCFCutoffController); |
1622 |
|
|
1623 |
// this models a strange behaviour or bug in GSt: two of the |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1624 |
// velocity response curves for release time are not used even |
VelocityTable = 0; |
1625 |
// if specified, instead another curve is chosen. |
} |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
|
|
(curveType == curve_type_special && depth == 4)) { |
|
|
curveType = curve_type_nonlinear; |
|
|
depth = 3; |
|
|
} |
|
|
pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0); |
|
1626 |
|
|
1627 |
curveType = VCFVelocityCurve; |
/* |
1628 |
depth = VCFVelocityDynamicRange; |
* Constructs a DimensionRegion by copying all parameters from |
1629 |
|
* another DimensionRegion |
1630 |
|
*/ |
1631 |
|
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
1632 |
|
Instances++; |
1633 |
|
//NOTE: I think we cannot call CopyAssign() here (in a constructor) as long as its a virtual method |
1634 |
|
*this = src; // default memberwise shallow copy of all parameters |
1635 |
|
pParentList = _3ewl; // restore the chunk pointer |
1636 |
|
|
1637 |
|
// deep copy of owned structures |
1638 |
|
if (src.VelocityTable) { |
1639 |
|
VelocityTable = new uint8_t[128]; |
1640 |
|
for (int k = 0 ; k < 128 ; k++) |
1641 |
|
VelocityTable[k] = src.VelocityTable[k]; |
1642 |
|
} |
1643 |
|
if (src.pSampleLoops) { |
1644 |
|
pSampleLoops = new DLS::sample_loop_t[src.SampleLoops]; |
1645 |
|
for (int k = 0 ; k < src.SampleLoops ; k++) |
1646 |
|
pSampleLoops[k] = src.pSampleLoops[k]; |
1647 |
|
} |
1648 |
|
} |
1649 |
|
|
1650 |
|
/** |
1651 |
|
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1652 |
|
* and assign it to this object. |
1653 |
|
* |
1654 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
1655 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
1656 |
|
* |
1657 |
|
* @param orig - original DimensionRegion object to be copied from |
1658 |
|
*/ |
1659 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig) { |
1660 |
|
CopyAssign(orig, NULL); |
1661 |
|
} |
1662 |
|
|
1663 |
// even stranger GSt: two of the velocity response curves for |
/** |
1664 |
// filter cutoff are not used, instead another special curve |
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1665 |
// is chosen. This curve is not used anywhere else. |
* and assign it to this object. |
1666 |
if ((curveType == curve_type_nonlinear && depth == 0) || |
* |
1667 |
(curveType == curve_type_special && depth == 4)) { |
* @param orig - original DimensionRegion object to be copied from |
1668 |
curveType = curve_type_special; |
* @param mSamples - crosslink map between the foreign file's samples and |
1669 |
depth = 5; |
* this file's samples |
1670 |
|
*/ |
1671 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples) { |
1672 |
|
// delete all allocated data first |
1673 |
|
if (VelocityTable) delete [] VelocityTable; |
1674 |
|
if (pSampleLoops) delete [] pSampleLoops; |
1675 |
|
|
1676 |
|
// backup parent list pointer |
1677 |
|
RIFF::List* p = pParentList; |
1678 |
|
|
1679 |
|
gig::Sample* pOriginalSample = pSample; |
1680 |
|
gig::Region* pOriginalRegion = pRegion; |
1681 |
|
|
1682 |
|
//NOTE: copy code copied from assignment constructor above, see comment there as well |
1683 |
|
|
1684 |
|
*this = *orig; // default memberwise shallow copy of all parameters |
1685 |
|
|
1686 |
|
// restore members that shall not be altered |
1687 |
|
pParentList = p; // restore the chunk pointer |
1688 |
|
pRegion = pOriginalRegion; |
1689 |
|
|
1690 |
|
// only take the raw sample reference reference if the |
1691 |
|
// two DimensionRegion objects are part of the same file |
1692 |
|
if (pOriginalRegion->GetParent()->GetParent() != orig->pRegion->GetParent()->GetParent()) { |
1693 |
|
pSample = pOriginalSample; |
1694 |
|
} |
1695 |
|
|
1696 |
|
if (mSamples && mSamples->count(orig->pSample)) { |
1697 |
|
pSample = mSamples->find(orig->pSample)->second; |
1698 |
|
} |
1699 |
|
|
1700 |
|
// deep copy of owned structures |
1701 |
|
if (orig->VelocityTable) { |
1702 |
|
VelocityTable = new uint8_t[128]; |
1703 |
|
for (int k = 0 ; k < 128 ; k++) |
1704 |
|
VelocityTable[k] = orig->VelocityTable[k]; |
1705 |
|
} |
1706 |
|
if (orig->pSampleLoops) { |
1707 |
|
pSampleLoops = new DLS::sample_loop_t[orig->SampleLoops]; |
1708 |
|
for (int k = 0 ; k < orig->SampleLoops ; k++) |
1709 |
|
pSampleLoops[k] = orig->pSampleLoops[k]; |
1710 |
} |
} |
1711 |
pVelocityCutoffTable = GetVelocityTable(curveType, depth, |
} |
|
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
|
1712 |
|
|
1713 |
|
/** |
1714 |
|
* Updates the respective member variable and updates @c SampleAttenuation |
1715 |
|
* which depends on this value. |
1716 |
|
*/ |
1717 |
|
void DimensionRegion::SetGain(int32_t gain) { |
1718 |
|
DLS::Sampler::SetGain(gain); |
1719 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
|
VelocityTable = 0; |
|
1720 |
} |
} |
1721 |
|
|
1722 |
/** |
/** |
1725 |
* |
* |
1726 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
1727 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
1728 |
|
* |
1729 |
|
* @param pProgress - callback function for progress notification |
1730 |
*/ |
*/ |
1731 |
void DimensionRegion::UpdateChunks() { |
void DimensionRegion::UpdateChunks(progress_t* pProgress) { |
1732 |
// first update base class's chunk |
// first update base class's chunk |
1733 |
DLS::Sampler::UpdateChunks(); |
DLS::Sampler::UpdateChunks(pProgress); |
1734 |
|
|
1735 |
|
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP); |
1736 |
|
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData(); |
1737 |
|
pData[12] = Crossfade.in_start; |
1738 |
|
pData[13] = Crossfade.in_end; |
1739 |
|
pData[14] = Crossfade.out_start; |
1740 |
|
pData[15] = Crossfade.out_end; |
1741 |
|
|
1742 |
// make sure '3ewa' chunk exists |
// make sure '3ewa' chunk exists |
1743 |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
1744 |
if (!_3ewa) _3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, 140); |
if (!_3ewa) { |
1745 |
uint8_t* pData = (uint8_t*) _3ewa->LoadChunkData(); |
File* pFile = (File*) GetParent()->GetParent()->GetParent(); |
1746 |
|
bool version3 = pFile->pVersion && pFile->pVersion->major == 3; |
1747 |
|
_3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, version3 ? 148 : 140); |
1748 |
|
} |
1749 |
|
pData = (uint8_t*) _3ewa->LoadChunkData(); |
1750 |
|
|
1751 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1752 |
|
|
1753 |
const uint32_t chunksize = _3ewa->GetSize(); |
const uint32_t chunksize = _3ewa->GetNewSize(); |
1754 |
memcpy(&pData[0], &chunksize, 4); // unknown, always chunk size? |
store32(&pData[0], chunksize); // unknown, always chunk size? |
1755 |
|
|
1756 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
1757 |
memcpy(&pData[4], &lfo3freq, 4); |
store32(&pData[4], lfo3freq); |
1758 |
|
|
1759 |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
1760 |
memcpy(&pData[8], &eg3attack, 4); |
store32(&pData[8], eg3attack); |
1761 |
|
|
1762 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1763 |
|
|
1764 |
memcpy(&pData[14], &LFO1InternalDepth, 2); |
store16(&pData[14], LFO1InternalDepth); |
1765 |
|
|
1766 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1767 |
|
|
1768 |
memcpy(&pData[18], &LFO3InternalDepth, 2); |
store16(&pData[18], LFO3InternalDepth); |
1769 |
|
|
1770 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1771 |
|
|
1772 |
memcpy(&pData[22], &LFO1ControlDepth, 2); |
store16(&pData[22], LFO1ControlDepth); |
1773 |
|
|
1774 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1775 |
|
|
1776 |
memcpy(&pData[26], &LFO3ControlDepth, 2); |
store16(&pData[26], LFO3ControlDepth); |
1777 |
|
|
1778 |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
1779 |
memcpy(&pData[28], &eg1attack, 4); |
store32(&pData[28], eg1attack); |
1780 |
|
|
1781 |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
1782 |
memcpy(&pData[32], &eg1decay1, 4); |
store32(&pData[32], eg1decay1); |
1783 |
|
|
1784 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1785 |
|
|
1786 |
memcpy(&pData[38], &EG1Sustain, 2); |
store16(&pData[38], EG1Sustain); |
1787 |
|
|
1788 |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
1789 |
memcpy(&pData[40], &eg1release, 4); |
store32(&pData[40], eg1release); |
1790 |
|
|
1791 |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
1792 |
memcpy(&pData[44], &eg1ctl, 1); |
pData[44] = eg1ctl; |
1793 |
|
|
1794 |
const uint8_t eg1ctrloptions = |
const uint8_t eg1ctrloptions = |
1795 |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
(EG1ControllerInvert ? 0x01 : 0x00) | |
1796 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
1797 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
1798 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
1799 |
memcpy(&pData[45], &eg1ctrloptions, 1); |
pData[45] = eg1ctrloptions; |
1800 |
|
|
1801 |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
1802 |
memcpy(&pData[46], &eg2ctl, 1); |
pData[46] = eg2ctl; |
1803 |
|
|
1804 |
const uint8_t eg2ctrloptions = |
const uint8_t eg2ctrloptions = |
1805 |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
(EG2ControllerInvert ? 0x01 : 0x00) | |
1806 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
1807 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
1808 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
1809 |
memcpy(&pData[47], &eg2ctrloptions, 1); |
pData[47] = eg2ctrloptions; |
1810 |
|
|
1811 |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
1812 |
memcpy(&pData[48], &lfo1freq, 4); |
store32(&pData[48], lfo1freq); |
1813 |
|
|
1814 |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
1815 |
memcpy(&pData[52], &eg2attack, 4); |
store32(&pData[52], eg2attack); |
1816 |
|
|
1817 |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
1818 |
memcpy(&pData[56], &eg2decay1, 4); |
store32(&pData[56], eg2decay1); |
1819 |
|
|
1820 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1821 |
|
|
1822 |
memcpy(&pData[62], &EG2Sustain, 2); |
store16(&pData[62], EG2Sustain); |
1823 |
|
|
1824 |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
1825 |
memcpy(&pData[64], &eg2release, 4); |
store32(&pData[64], eg2release); |
1826 |
|
|
1827 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1828 |
|
|
1829 |
memcpy(&pData[70], &LFO2ControlDepth, 2); |
store16(&pData[70], LFO2ControlDepth); |
1830 |
|
|
1831 |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
1832 |
memcpy(&pData[72], &lfo2freq, 4); |
store32(&pData[72], lfo2freq); |
1833 |
|
|
1834 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1835 |
|
|
1836 |
memcpy(&pData[78], &LFO2InternalDepth, 2); |
store16(&pData[78], LFO2InternalDepth); |
1837 |
|
|
1838 |
const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2); |
const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2); |
1839 |
memcpy(&pData[80], &eg1decay2, 4); |
store32(&pData[80], eg1decay2); |
1840 |
|
|
1841 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1842 |
|
|
1843 |
memcpy(&pData[86], &EG1PreAttack, 2); |
store16(&pData[86], EG1PreAttack); |
1844 |
|
|
1845 |
const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2); |
const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2); |
1846 |
memcpy(&pData[88], &eg2decay2, 4); |
store32(&pData[88], eg2decay2); |
1847 |
|
|
1848 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1849 |
|
|
1850 |
memcpy(&pData[94], &EG2PreAttack, 2); |
store16(&pData[94], EG2PreAttack); |
1851 |
|
|
1852 |
{ |
{ |
1853 |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
1865 |
default: |
default: |
1866 |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
1867 |
} |
} |
1868 |
memcpy(&pData[96], &velocityresponse, 1); |
pData[96] = velocityresponse; |
1869 |
} |
} |
1870 |
|
|
1871 |
{ |
{ |
1884 |
default: |
default: |
1885 |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
1886 |
} |
} |
1887 |
memcpy(&pData[97], &releasevelocityresponse, 1); |
pData[97] = releasevelocityresponse; |
1888 |
} |
} |
1889 |
|
|
1890 |
memcpy(&pData[98], &VelocityResponseCurveScaling, 1); |
pData[98] = VelocityResponseCurveScaling; |
1891 |
|
|
1892 |
memcpy(&pData[99], &AttenuationControllerThreshold, 1); |
pData[99] = AttenuationControllerThreshold; |
1893 |
|
|
1894 |
// next 4 bytes unknown |
// next 4 bytes unknown |
1895 |
|
|
1896 |
memcpy(&pData[104], &SampleStartOffset, 2); |
store16(&pData[104], SampleStartOffset); |
1897 |
|
|
1898 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1899 |
|
|
1912 |
default: |
default: |
1913 |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
1914 |
} |
} |
1915 |
memcpy(&pData[108], &pitchTrackDimensionBypass, 1); |
pData[108] = pitchTrackDimensionBypass; |
1916 |
} |
} |
1917 |
|
|
1918 |
const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit |
const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit |
1919 |
memcpy(&pData[109], &pan, 1); |
pData[109] = pan; |
1920 |
|
|
1921 |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
1922 |
memcpy(&pData[110], &selfmask, 1); |
pData[110] = selfmask; |
1923 |
|
|
1924 |
// next byte unknown |
// next byte unknown |
1925 |
|
|
1928 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
1929 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
1930 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
1931 |
memcpy(&pData[112], &lfo3ctrl, 1); |
pData[112] = lfo3ctrl; |
1932 |
} |
} |
1933 |
|
|
1934 |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
1935 |
memcpy(&pData[113], &attenctl, 1); |
pData[113] = attenctl; |
1936 |
|
|
1937 |
{ |
{ |
1938 |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
1939 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
1940 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
1941 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
1942 |
memcpy(&pData[114], &lfo2ctrl, 1); |
pData[114] = lfo2ctrl; |
1943 |
} |
} |
1944 |
|
|
1945 |
{ |
{ |
1948 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
1949 |
if (VCFResonanceController != vcf_res_ctrl_none) |
if (VCFResonanceController != vcf_res_ctrl_none) |
1950 |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
1951 |
memcpy(&pData[115], &lfo1ctrl, 1); |
pData[115] = lfo1ctrl; |
1952 |
} |
} |
1953 |
|
|
1954 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
1955 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xfff); /* binary complementary for negatives */ |
1956 |
memcpy(&pData[116], &eg3depth, 1); |
store16(&pData[116], eg3depth); |
1957 |
|
|
1958 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1959 |
|
|
1960 |
const uint8_t channeloffset = ChannelOffset * 4; |
const uint8_t channeloffset = ChannelOffset * 4; |
1961 |
memcpy(&pData[120], &channeloffset, 1); |
pData[120] = channeloffset; |
1962 |
|
|
1963 |
{ |
{ |
1964 |
uint8_t regoptions = 0; |
uint8_t regoptions = 0; |
1965 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
1966 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
1967 |
memcpy(&pData[121], ®options, 1); |
pData[121] = regoptions; |
1968 |
} |
} |
1969 |
|
|
1970 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1971 |
|
|
1972 |
memcpy(&pData[124], &VelocityUpperLimit, 1); |
pData[124] = VelocityUpperLimit; |
1973 |
|
|
1974 |
// next 3 bytes unknown |
// next 3 bytes unknown |
1975 |
|
|
1976 |
memcpy(&pData[128], &ReleaseTriggerDecay, 1); |
pData[128] = ReleaseTriggerDecay; |
1977 |
|
|
1978 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1979 |
|
|
1980 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
1981 |
memcpy(&pData[131], &eg1hold, 1); |
pData[131] = eg1hold; |
1982 |
|
|
1983 |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfcutoff = (VCFEnabled ? 0x80 : 0x00) | /* bit 7 */ |
1984 |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
1985 |
memcpy(&pData[132], &vcfcutoff, 1); |
pData[132] = vcfcutoff; |
1986 |
|
|
1987 |
memcpy(&pData[133], &VCFCutoffController, 1); |
pData[133] = VCFCutoffController; |
1988 |
|
|
1989 |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert ? 0x80 : 0x00) | /* bit 7 */ |
1990 |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
1991 |
memcpy(&pData[134], &vcfvelscale, 1); |
pData[134] = vcfvelscale; |
1992 |
|
|
1993 |
// next byte unknown |
// next byte unknown |
1994 |
|
|
1995 |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
const uint8_t vcfresonance = (VCFResonanceDynamic ? 0x00 : 0x80) | /* bit 7 */ |
1996 |
(VCFResonance & 0x7f); /* lower 7 bits */ |
(VCFResonance & 0x7f); /* lower 7 bits */ |
1997 |
memcpy(&pData[136], &vcfresonance, 1); |
pData[136] = vcfresonance; |
1998 |
|
|
1999 |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking ? 0x80 : 0x00) | /* bit 7 */ |
2000 |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
2001 |
memcpy(&pData[137], &vcfbreakpoint, 1); |
pData[137] = vcfbreakpoint; |
2002 |
|
|
2003 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 + |
2004 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
2005 |
memcpy(&pData[138], &vcfvelocity, 1); |
pData[138] = vcfvelocity; |
2006 |
|
|
2007 |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
2008 |
memcpy(&pData[139], &vcftype, 1); |
pData[139] = vcftype; |
2009 |
|
|
2010 |
if (chunksize >= 148) { |
if (chunksize >= 148) { |
2011 |
memcpy(&pData[140], DimensionUpperLimits, 8); |
memcpy(&pData[140], DimensionUpperLimits, 8); |
2012 |
} |
} |
2013 |
} |
} |
2014 |
|
|
2015 |
|
double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { |
2016 |
|
curve_type_t curveType = releaseVelocityResponseCurve; |
2017 |
|
uint8_t depth = releaseVelocityResponseDepth; |
2018 |
|
// this models a strange behaviour or bug in GSt: two of the |
2019 |
|
// velocity response curves for release time are not used even |
2020 |
|
// if specified, instead another curve is chosen. |
2021 |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
2022 |
|
(curveType == curve_type_special && depth == 4)) { |
2023 |
|
curveType = curve_type_nonlinear; |
2024 |
|
depth = 3; |
2025 |
|
} |
2026 |
|
return GetVelocityTable(curveType, depth, 0); |
2027 |
|
} |
2028 |
|
|
2029 |
|
double* DimensionRegion::GetCutoffVelocityTable(curve_type_t vcfVelocityCurve, |
2030 |
|
uint8_t vcfVelocityDynamicRange, |
2031 |
|
uint8_t vcfVelocityScale, |
2032 |
|
vcf_cutoff_ctrl_t vcfCutoffController) |
2033 |
|
{ |
2034 |
|
curve_type_t curveType = vcfVelocityCurve; |
2035 |
|
uint8_t depth = vcfVelocityDynamicRange; |
2036 |
|
// even stranger GSt: two of the velocity response curves for |
2037 |
|
// filter cutoff are not used, instead another special curve |
2038 |
|
// is chosen. This curve is not used anywhere else. |
2039 |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
2040 |
|
(curveType == curve_type_special && depth == 4)) { |
2041 |
|
curveType = curve_type_special; |
2042 |
|
depth = 5; |
2043 |
|
} |
2044 |
|
return GetVelocityTable(curveType, depth, |
2045 |
|
(vcfCutoffController <= vcf_cutoff_ctrl_none2) |
2046 |
|
? vcfVelocityScale : 0); |
2047 |
|
} |
2048 |
|
|
2049 |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
2050 |
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
2051 |
{ |
{ |
2061 |
return table; |
return table; |
2062 |
} |
} |
2063 |
|
|
2064 |
|
Region* DimensionRegion::GetParent() const { |
2065 |
|
return pRegion; |
2066 |
|
} |
2067 |
|
|
2068 |
|
// show error if some _lev_ctrl_* enum entry is not listed in the following function |
2069 |
|
// (commented out for now, because "diagnostic push" not supported prior GCC 4.6) |
2070 |
|
// TODO: uncomment and add a GCC version check (see also commented "#pragma GCC diagnostic pop" below) |
2071 |
|
//#pragma GCC diagnostic push |
2072 |
|
//#pragma GCC diagnostic error "-Wswitch" |
2073 |
|
|
2074 |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
2075 |
leverage_ctrl_t decodedcontroller; |
leverage_ctrl_t decodedcontroller; |
2076 |
switch (EncodedController) { |
switch (EncodedController) { |
2182 |
decodedcontroller.controller_number = 95; |
decodedcontroller.controller_number = 95; |
2183 |
break; |
break; |
2184 |
|
|
2185 |
|
// format extension (these controllers are so far only supported by |
2186 |
|
// LinuxSampler & gigedit) they will *NOT* work with |
2187 |
|
// Gigasampler/GigaStudio ! |
2188 |
|
case _lev_ctrl_CC3_EXT: |
2189 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2190 |
|
decodedcontroller.controller_number = 3; |
2191 |
|
break; |
2192 |
|
case _lev_ctrl_CC6_EXT: |
2193 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2194 |
|
decodedcontroller.controller_number = 6; |
2195 |
|
break; |
2196 |
|
case _lev_ctrl_CC7_EXT: |
2197 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2198 |
|
decodedcontroller.controller_number = 7; |
2199 |
|
break; |
2200 |
|
case _lev_ctrl_CC8_EXT: |
2201 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2202 |
|
decodedcontroller.controller_number = 8; |
2203 |
|
break; |
2204 |
|
case _lev_ctrl_CC9_EXT: |
2205 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2206 |
|
decodedcontroller.controller_number = 9; |
2207 |
|
break; |
2208 |
|
case _lev_ctrl_CC10_EXT: |
2209 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2210 |
|
decodedcontroller.controller_number = 10; |
2211 |
|
break; |
2212 |
|
case _lev_ctrl_CC11_EXT: |
2213 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2214 |
|
decodedcontroller.controller_number = 11; |
2215 |
|
break; |
2216 |
|
case _lev_ctrl_CC14_EXT: |
2217 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2218 |
|
decodedcontroller.controller_number = 14; |
2219 |
|
break; |
2220 |
|
case _lev_ctrl_CC15_EXT: |
2221 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2222 |
|
decodedcontroller.controller_number = 15; |
2223 |
|
break; |
2224 |
|
case _lev_ctrl_CC20_EXT: |
2225 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2226 |
|
decodedcontroller.controller_number = 20; |
2227 |
|
break; |
2228 |
|
case _lev_ctrl_CC21_EXT: |
2229 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2230 |
|
decodedcontroller.controller_number = 21; |
2231 |
|
break; |
2232 |
|
case _lev_ctrl_CC22_EXT: |
2233 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2234 |
|
decodedcontroller.controller_number = 22; |
2235 |
|
break; |
2236 |
|
case _lev_ctrl_CC23_EXT: |
2237 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2238 |
|
decodedcontroller.controller_number = 23; |
2239 |
|
break; |
2240 |
|
case _lev_ctrl_CC24_EXT: |
2241 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2242 |
|
decodedcontroller.controller_number = 24; |
2243 |
|
break; |
2244 |
|
case _lev_ctrl_CC25_EXT: |
2245 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2246 |
|
decodedcontroller.controller_number = 25; |
2247 |
|
break; |
2248 |
|
case _lev_ctrl_CC26_EXT: |
2249 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2250 |
|
decodedcontroller.controller_number = 26; |
2251 |
|
break; |
2252 |
|
case _lev_ctrl_CC27_EXT: |
2253 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2254 |
|
decodedcontroller.controller_number = 27; |
2255 |
|
break; |
2256 |
|
case _lev_ctrl_CC28_EXT: |
2257 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2258 |
|
decodedcontroller.controller_number = 28; |
2259 |
|
break; |
2260 |
|
case _lev_ctrl_CC29_EXT: |
2261 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2262 |
|
decodedcontroller.controller_number = 29; |
2263 |
|
break; |
2264 |
|
case _lev_ctrl_CC30_EXT: |
2265 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2266 |
|
decodedcontroller.controller_number = 30; |
2267 |
|
break; |
2268 |
|
case _lev_ctrl_CC31_EXT: |
2269 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2270 |
|
decodedcontroller.controller_number = 31; |
2271 |
|
break; |
2272 |
|
case _lev_ctrl_CC68_EXT: |
2273 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2274 |
|
decodedcontroller.controller_number = 68; |
2275 |
|
break; |
2276 |
|
case _lev_ctrl_CC69_EXT: |
2277 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2278 |
|
decodedcontroller.controller_number = 69; |
2279 |
|
break; |
2280 |
|
case _lev_ctrl_CC70_EXT: |
2281 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2282 |
|
decodedcontroller.controller_number = 70; |
2283 |
|
break; |
2284 |
|
case _lev_ctrl_CC71_EXT: |
2285 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2286 |
|
decodedcontroller.controller_number = 71; |
2287 |
|
break; |
2288 |
|
case _lev_ctrl_CC72_EXT: |
2289 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2290 |
|
decodedcontroller.controller_number = 72; |
2291 |
|
break; |
2292 |
|
case _lev_ctrl_CC73_EXT: |
2293 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2294 |
|
decodedcontroller.controller_number = 73; |
2295 |
|
break; |
2296 |
|
case _lev_ctrl_CC74_EXT: |
2297 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2298 |
|
decodedcontroller.controller_number = 74; |
2299 |
|
break; |
2300 |
|
case _lev_ctrl_CC75_EXT: |
2301 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2302 |
|
decodedcontroller.controller_number = 75; |
2303 |
|
break; |
2304 |
|
case _lev_ctrl_CC76_EXT: |
2305 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2306 |
|
decodedcontroller.controller_number = 76; |
2307 |
|
break; |
2308 |
|
case _lev_ctrl_CC77_EXT: |
2309 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2310 |
|
decodedcontroller.controller_number = 77; |
2311 |
|
break; |
2312 |
|
case _lev_ctrl_CC78_EXT: |
2313 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2314 |
|
decodedcontroller.controller_number = 78; |
2315 |
|
break; |
2316 |
|
case _lev_ctrl_CC79_EXT: |
2317 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2318 |
|
decodedcontroller.controller_number = 79; |
2319 |
|
break; |
2320 |
|
case _lev_ctrl_CC84_EXT: |
2321 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2322 |
|
decodedcontroller.controller_number = 84; |
2323 |
|
break; |
2324 |
|
case _lev_ctrl_CC85_EXT: |
2325 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2326 |
|
decodedcontroller.controller_number = 85; |
2327 |
|
break; |
2328 |
|
case _lev_ctrl_CC86_EXT: |
2329 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2330 |
|
decodedcontroller.controller_number = 86; |
2331 |
|
break; |
2332 |
|
case _lev_ctrl_CC87_EXT: |
2333 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2334 |
|
decodedcontroller.controller_number = 87; |
2335 |
|
break; |
2336 |
|
case _lev_ctrl_CC89_EXT: |
2337 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2338 |
|
decodedcontroller.controller_number = 89; |
2339 |
|
break; |
2340 |
|
case _lev_ctrl_CC90_EXT: |
2341 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2342 |
|
decodedcontroller.controller_number = 90; |
2343 |
|
break; |
2344 |
|
case _lev_ctrl_CC96_EXT: |
2345 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2346 |
|
decodedcontroller.controller_number = 96; |
2347 |
|
break; |
2348 |
|
case _lev_ctrl_CC97_EXT: |
2349 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2350 |
|
decodedcontroller.controller_number = 97; |
2351 |
|
break; |
2352 |
|
case _lev_ctrl_CC102_EXT: |
2353 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2354 |
|
decodedcontroller.controller_number = 102; |
2355 |
|
break; |
2356 |
|
case _lev_ctrl_CC103_EXT: |
2357 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2358 |
|
decodedcontroller.controller_number = 103; |
2359 |
|
break; |
2360 |
|
case _lev_ctrl_CC104_EXT: |
2361 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2362 |
|
decodedcontroller.controller_number = 104; |
2363 |
|
break; |
2364 |
|
case _lev_ctrl_CC105_EXT: |
2365 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2366 |
|
decodedcontroller.controller_number = 105; |
2367 |
|
break; |
2368 |
|
case _lev_ctrl_CC106_EXT: |
2369 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2370 |
|
decodedcontroller.controller_number = 106; |
2371 |
|
break; |
2372 |
|
case _lev_ctrl_CC107_EXT: |
2373 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2374 |
|
decodedcontroller.controller_number = 107; |
2375 |
|
break; |
2376 |
|
case _lev_ctrl_CC108_EXT: |
2377 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2378 |
|
decodedcontroller.controller_number = 108; |
2379 |
|
break; |
2380 |
|
case _lev_ctrl_CC109_EXT: |
2381 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2382 |
|
decodedcontroller.controller_number = 109; |
2383 |
|
break; |
2384 |
|
case _lev_ctrl_CC110_EXT: |
2385 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2386 |
|
decodedcontroller.controller_number = 110; |
2387 |
|
break; |
2388 |
|
case _lev_ctrl_CC111_EXT: |
2389 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2390 |
|
decodedcontroller.controller_number = 111; |
2391 |
|
break; |
2392 |
|
case _lev_ctrl_CC112_EXT: |
2393 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2394 |
|
decodedcontroller.controller_number = 112; |
2395 |
|
break; |
2396 |
|
case _lev_ctrl_CC113_EXT: |
2397 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2398 |
|
decodedcontroller.controller_number = 113; |
2399 |
|
break; |
2400 |
|
case _lev_ctrl_CC114_EXT: |
2401 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2402 |
|
decodedcontroller.controller_number = 114; |
2403 |
|
break; |
2404 |
|
case _lev_ctrl_CC115_EXT: |
2405 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2406 |
|
decodedcontroller.controller_number = 115; |
2407 |
|
break; |
2408 |
|
case _lev_ctrl_CC116_EXT: |
2409 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2410 |
|
decodedcontroller.controller_number = 116; |
2411 |
|
break; |
2412 |
|
case _lev_ctrl_CC117_EXT: |
2413 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2414 |
|
decodedcontroller.controller_number = 117; |
2415 |
|
break; |
2416 |
|
case _lev_ctrl_CC118_EXT: |
2417 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2418 |
|
decodedcontroller.controller_number = 118; |
2419 |
|
break; |
2420 |
|
case _lev_ctrl_CC119_EXT: |
2421 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2422 |
|
decodedcontroller.controller_number = 119; |
2423 |
|
break; |
2424 |
|
|
2425 |
// unknown controller type |
// unknown controller type |
2426 |
default: |
default: |
2427 |
throw gig::Exception("Unknown leverage controller type."); |
throw gig::Exception("Unknown leverage controller type."); |
2428 |
} |
} |
2429 |
return decodedcontroller; |
return decodedcontroller; |
2430 |
} |
} |
2431 |
|
|
2432 |
|
// see above (diagnostic push not supported prior GCC 4.6) |
2433 |
|
//#pragma GCC diagnostic pop |
2434 |
|
|
2435 |
DimensionRegion::_lev_ctrl_t DimensionRegion::EncodeLeverageController(leverage_ctrl_t DecodedController) { |
DimensionRegion::_lev_ctrl_t DimensionRegion::EncodeLeverageController(leverage_ctrl_t DecodedController) { |
2436 |
_lev_ctrl_t encodedcontroller; |
_lev_ctrl_t encodedcontroller; |
2518 |
case 95: |
case 95: |
2519 |
encodedcontroller = _lev_ctrl_effect5depth; |
encodedcontroller = _lev_ctrl_effect5depth; |
2520 |
break; |
break; |
2521 |
|
|
2522 |
|
// format extension (these controllers are so far only |
2523 |
|
// supported by LinuxSampler & gigedit) they will *NOT* |
2524 |
|
// work with Gigasampler/GigaStudio ! |
2525 |
|
case 3: |
2526 |
|
encodedcontroller = _lev_ctrl_CC3_EXT; |
2527 |
|
break; |
2528 |
|
case 6: |
2529 |
|
encodedcontroller = _lev_ctrl_CC6_EXT; |
2530 |
|
break; |
2531 |
|
case 7: |
2532 |
|
encodedcontroller = _lev_ctrl_CC7_EXT; |
2533 |
|
break; |
2534 |
|
case 8: |
2535 |
|
encodedcontroller = _lev_ctrl_CC8_EXT; |
2536 |
|
break; |
2537 |
|
case 9: |
2538 |
|
encodedcontroller = _lev_ctrl_CC9_EXT; |
2539 |
|
break; |
2540 |
|
case 10: |
2541 |
|
encodedcontroller = _lev_ctrl_CC10_EXT; |
2542 |
|
break; |
2543 |
|
case 11: |
2544 |
|
encodedcontroller = _lev_ctrl_CC11_EXT; |
2545 |
|
break; |
2546 |
|
case 14: |
2547 |
|
encodedcontroller = _lev_ctrl_CC14_EXT; |
2548 |
|
break; |
2549 |
|
case 15: |
2550 |
|
encodedcontroller = _lev_ctrl_CC15_EXT; |
2551 |
|
break; |
2552 |
|
case 20: |
2553 |
|
encodedcontroller = _lev_ctrl_CC20_EXT; |
2554 |
|
break; |
2555 |
|
case 21: |
2556 |
|
encodedcontroller = _lev_ctrl_CC21_EXT; |
2557 |
|
break; |
2558 |
|
case 22: |
2559 |
|
encodedcontroller = _lev_ctrl_CC22_EXT; |
2560 |
|
break; |
2561 |
|
case 23: |
2562 |
|
encodedcontroller = _lev_ctrl_CC23_EXT; |
2563 |
|
break; |
2564 |
|
case 24: |
2565 |
|
encodedcontroller = _lev_ctrl_CC24_EXT; |
2566 |
|
break; |
2567 |
|
case 25: |
2568 |
|
encodedcontroller = _lev_ctrl_CC25_EXT; |
2569 |
|
break; |
2570 |
|
case 26: |
2571 |
|
encodedcontroller = _lev_ctrl_CC26_EXT; |
2572 |
|
break; |
2573 |
|
case 27: |
2574 |
|
encodedcontroller = _lev_ctrl_CC27_EXT; |
2575 |
|
break; |
2576 |
|
case 28: |
2577 |
|
encodedcontroller = _lev_ctrl_CC28_EXT; |
2578 |
|
break; |
2579 |
|
case 29: |
2580 |
|
encodedcontroller = _lev_ctrl_CC29_EXT; |
2581 |
|
break; |
2582 |
|
case 30: |
2583 |
|
encodedcontroller = _lev_ctrl_CC30_EXT; |
2584 |
|
break; |
2585 |
|
case 31: |
2586 |
|
encodedcontroller = _lev_ctrl_CC31_EXT; |
2587 |
|
break; |
2588 |
|
case 68: |
2589 |
|
encodedcontroller = _lev_ctrl_CC68_EXT; |
2590 |
|
break; |
2591 |
|
case 69: |
2592 |
|
encodedcontroller = _lev_ctrl_CC69_EXT; |
2593 |
|
break; |
2594 |
|
case 70: |
2595 |
|
encodedcontroller = _lev_ctrl_CC70_EXT; |
2596 |
|
break; |
2597 |
|
case 71: |
2598 |
|
encodedcontroller = _lev_ctrl_CC71_EXT; |
2599 |
|
break; |
2600 |
|
case 72: |
2601 |
|
encodedcontroller = _lev_ctrl_CC72_EXT; |
2602 |
|
break; |
2603 |
|
case 73: |
2604 |
|
encodedcontroller = _lev_ctrl_CC73_EXT; |
2605 |
|
break; |
2606 |
|
case 74: |
2607 |
|
encodedcontroller = _lev_ctrl_CC74_EXT; |
2608 |
|
break; |
2609 |
|
case 75: |
2610 |
|
encodedcontroller = _lev_ctrl_CC75_EXT; |
2611 |
|
break; |
2612 |
|
case 76: |
2613 |
|
encodedcontroller = _lev_ctrl_CC76_EXT; |
2614 |
|
break; |
2615 |
|
case 77: |
2616 |
|
encodedcontroller = _lev_ctrl_CC77_EXT; |
2617 |
|
break; |
2618 |
|
case 78: |
2619 |
|
encodedcontroller = _lev_ctrl_CC78_EXT; |
2620 |
|
break; |
2621 |
|
case 79: |
2622 |
|
encodedcontroller = _lev_ctrl_CC79_EXT; |
2623 |
|
break; |
2624 |
|
case 84: |
2625 |
|
encodedcontroller = _lev_ctrl_CC84_EXT; |
2626 |
|
break; |
2627 |
|
case 85: |
2628 |
|
encodedcontroller = _lev_ctrl_CC85_EXT; |
2629 |
|
break; |
2630 |
|
case 86: |
2631 |
|
encodedcontroller = _lev_ctrl_CC86_EXT; |
2632 |
|
break; |
2633 |
|
case 87: |
2634 |
|
encodedcontroller = _lev_ctrl_CC87_EXT; |
2635 |
|
break; |
2636 |
|
case 89: |
2637 |
|
encodedcontroller = _lev_ctrl_CC89_EXT; |
2638 |
|
break; |
2639 |
|
case 90: |
2640 |
|
encodedcontroller = _lev_ctrl_CC90_EXT; |
2641 |
|
break; |
2642 |
|
case 96: |
2643 |
|
encodedcontroller = _lev_ctrl_CC96_EXT; |
2644 |
|
break; |
2645 |
|
case 97: |
2646 |
|
encodedcontroller = _lev_ctrl_CC97_EXT; |
2647 |
|
break; |
2648 |
|
case 102: |
2649 |
|
encodedcontroller = _lev_ctrl_CC102_EXT; |
2650 |
|
break; |
2651 |
|
case 103: |
2652 |
|
encodedcontroller = _lev_ctrl_CC103_EXT; |
2653 |
|
break; |
2654 |
|
case 104: |
2655 |
|
encodedcontroller = _lev_ctrl_CC104_EXT; |
2656 |
|
break; |
2657 |
|
case 105: |
2658 |
|
encodedcontroller = _lev_ctrl_CC105_EXT; |
2659 |
|
break; |
2660 |
|
case 106: |
2661 |
|
encodedcontroller = _lev_ctrl_CC106_EXT; |
2662 |
|
break; |
2663 |
|
case 107: |
2664 |
|
encodedcontroller = _lev_ctrl_CC107_EXT; |
2665 |
|
break; |
2666 |
|
case 108: |
2667 |
|
encodedcontroller = _lev_ctrl_CC108_EXT; |
2668 |
|
break; |
2669 |
|
case 109: |
2670 |
|
encodedcontroller = _lev_ctrl_CC109_EXT; |
2671 |
|
break; |
2672 |
|
case 110: |
2673 |
|
encodedcontroller = _lev_ctrl_CC110_EXT; |
2674 |
|
break; |
2675 |
|
case 111: |
2676 |
|
encodedcontroller = _lev_ctrl_CC111_EXT; |
2677 |
|
break; |
2678 |
|
case 112: |
2679 |
|
encodedcontroller = _lev_ctrl_CC112_EXT; |
2680 |
|
break; |
2681 |
|
case 113: |
2682 |
|
encodedcontroller = _lev_ctrl_CC113_EXT; |
2683 |
|
break; |
2684 |
|
case 114: |
2685 |
|
encodedcontroller = _lev_ctrl_CC114_EXT; |
2686 |
|
break; |
2687 |
|
case 115: |
2688 |
|
encodedcontroller = _lev_ctrl_CC115_EXT; |
2689 |
|
break; |
2690 |
|
case 116: |
2691 |
|
encodedcontroller = _lev_ctrl_CC116_EXT; |
2692 |
|
break; |
2693 |
|
case 117: |
2694 |
|
encodedcontroller = _lev_ctrl_CC117_EXT; |
2695 |
|
break; |
2696 |
|
case 118: |
2697 |
|
encodedcontroller = _lev_ctrl_CC118_EXT; |
2698 |
|
break; |
2699 |
|
case 119: |
2700 |
|
encodedcontroller = _lev_ctrl_CC119_EXT; |
2701 |
|
break; |
2702 |
|
|
2703 |
default: |
default: |
2704 |
throw gig::Exception("leverage controller number is not supported by the gig format"); |
throw gig::Exception("leverage controller number is not supported by the gig format"); |
2705 |
} |
} |
2706 |
|
break; |
2707 |
default: |
default: |
2708 |
throw gig::Exception("Unknown leverage controller type."); |
throw gig::Exception("Unknown leverage controller type."); |
2709 |
} |
} |
2749 |
return pVelocityCutoffTable[MIDIKeyVelocity]; |
return pVelocityCutoffTable[MIDIKeyVelocity]; |
2750 |
} |
} |
2751 |
|
|
2752 |
|
/** |
2753 |
|
* Updates the respective member variable and the lookup table / cache |
2754 |
|
* that depends on this value. |
2755 |
|
*/ |
2756 |
|
void DimensionRegion::SetVelocityResponseCurve(curve_type_t curve) { |
2757 |
|
pVelocityAttenuationTable = |
2758 |
|
GetVelocityTable( |
2759 |
|
curve, VelocityResponseDepth, VelocityResponseCurveScaling |
2760 |
|
); |
2761 |
|
VelocityResponseCurve = curve; |
2762 |
|
} |
2763 |
|
|
2764 |
|
/** |
2765 |
|
* Updates the respective member variable and the lookup table / cache |
2766 |
|
* that depends on this value. |
2767 |
|
*/ |
2768 |
|
void DimensionRegion::SetVelocityResponseDepth(uint8_t depth) { |
2769 |
|
pVelocityAttenuationTable = |
2770 |
|
GetVelocityTable( |
2771 |
|
VelocityResponseCurve, depth, VelocityResponseCurveScaling |
2772 |
|
); |
2773 |
|
VelocityResponseDepth = depth; |
2774 |
|
} |
2775 |
|
|
2776 |
|
/** |
2777 |
|
* Updates the respective member variable and the lookup table / cache |
2778 |
|
* that depends on this value. |
2779 |
|
*/ |
2780 |
|
void DimensionRegion::SetVelocityResponseCurveScaling(uint8_t scaling) { |
2781 |
|
pVelocityAttenuationTable = |
2782 |
|
GetVelocityTable( |
2783 |
|
VelocityResponseCurve, VelocityResponseDepth, scaling |
2784 |
|
); |
2785 |
|
VelocityResponseCurveScaling = scaling; |
2786 |
|
} |
2787 |
|
|
2788 |
|
/** |
2789 |
|
* Updates the respective member variable and the lookup table / cache |
2790 |
|
* that depends on this value. |
2791 |
|
*/ |
2792 |
|
void DimensionRegion::SetReleaseVelocityResponseCurve(curve_type_t curve) { |
2793 |
|
pVelocityReleaseTable = GetReleaseVelocityTable(curve, ReleaseVelocityResponseDepth); |
2794 |
|
ReleaseVelocityResponseCurve = curve; |
2795 |
|
} |
2796 |
|
|
2797 |
|
/** |
2798 |
|
* Updates the respective member variable and the lookup table / cache |
2799 |
|
* that depends on this value. |
2800 |
|
*/ |
2801 |
|
void DimensionRegion::SetReleaseVelocityResponseDepth(uint8_t depth) { |
2802 |
|
pVelocityReleaseTable = GetReleaseVelocityTable(ReleaseVelocityResponseCurve, depth); |
2803 |
|
ReleaseVelocityResponseDepth = depth; |
2804 |
|
} |
2805 |
|
|
2806 |
|
/** |
2807 |
|
* Updates the respective member variable and the lookup table / cache |
2808 |
|
* that depends on this value. |
2809 |
|
*/ |
2810 |
|
void DimensionRegion::SetVCFCutoffController(vcf_cutoff_ctrl_t controller) { |
2811 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, VCFVelocityDynamicRange, VCFVelocityScale, controller); |
2812 |
|
VCFCutoffController = controller; |
2813 |
|
} |
2814 |
|
|
2815 |
|
/** |
2816 |
|
* Updates the respective member variable and the lookup table / cache |
2817 |
|
* that depends on this value. |
2818 |
|
*/ |
2819 |
|
void DimensionRegion::SetVCFVelocityCurve(curve_type_t curve) { |
2820 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(curve, VCFVelocityDynamicRange, VCFVelocityScale, VCFCutoffController); |
2821 |
|
VCFVelocityCurve = curve; |
2822 |
|
} |
2823 |
|
|
2824 |
|
/** |
2825 |
|
* Updates the respective member variable and the lookup table / cache |
2826 |
|
* that depends on this value. |
2827 |
|
*/ |
2828 |
|
void DimensionRegion::SetVCFVelocityDynamicRange(uint8_t range) { |
2829 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, range, VCFVelocityScale, VCFCutoffController); |
2830 |
|
VCFVelocityDynamicRange = range; |
2831 |
|
} |
2832 |
|
|
2833 |
|
/** |
2834 |
|
* Updates the respective member variable and the lookup table / cache |
2835 |
|
* that depends on this value. |
2836 |
|
*/ |
2837 |
|
void DimensionRegion::SetVCFVelocityScale(uint8_t scaling) { |
2838 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, VCFVelocityDynamicRange, scaling, VCFCutoffController); |
2839 |
|
VCFVelocityScale = scaling; |
2840 |
|
} |
2841 |
|
|
2842 |
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
2843 |
|
|
2844 |
// line-segment approximations of the 15 velocity curves |
// line-segment approximations of the 15 velocity curves |
2911 |
// * |
// * |
2912 |
|
|
2913 |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
|
pInfo->UseFixedLengthStrings = true; |
|
|
|
|
2914 |
// Initialization |
// Initialization |
2915 |
Dimensions = 0; |
Dimensions = 0; |
2916 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2922 |
|
|
2923 |
// Actual Loading |
// Actual Loading |
2924 |
|
|
2925 |
|
if (!file->GetAutoLoad()) return; |
2926 |
|
|
2927 |
LoadDimensionRegions(rgnList); |
LoadDimensionRegions(rgnList); |
2928 |
|
|
2929 |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
2932 |
for (int i = 0; i < dimensionBits; i++) { |
for (int i = 0; i < dimensionBits; i++) { |
2933 |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
2934 |
uint8_t bits = _3lnk->ReadUint8(); |
uint8_t bits = _3lnk->ReadUint8(); |
2935 |
_3lnk->ReadUint8(); // probably the position of the dimension |
_3lnk->ReadUint8(); // bit position of the dimension (bits[0] + bits[1] + ... + bits[i-1]) |
2936 |
_3lnk->ReadUint8(); // unknown |
_3lnk->ReadUint8(); // (1 << bit position of next dimension) - (1 << bit position of this dimension) |
2937 |
uint8_t zones = _3lnk->ReadUint8(); // new for v3: number of zones doesn't have to be == pow(2,bits) |
uint8_t zones = _3lnk->ReadUint8(); // new for v3: number of zones doesn't have to be == pow(2,bits) |
2938 |
if (dimension == dimension_none) { // inactive dimension |
if (dimension == dimension_none) { // inactive dimension |
2939 |
pDimensionDefinitions[i].dimension = dimension_none; |
pDimensionDefinitions[i].dimension = dimension_none; |
2946 |
pDimensionDefinitions[i].dimension = dimension; |
pDimensionDefinitions[i].dimension = dimension; |
2947 |
pDimensionDefinitions[i].bits = bits; |
pDimensionDefinitions[i].bits = bits; |
2948 |
pDimensionDefinitions[i].zones = zones ? zones : 0x01 << bits; // = pow(2,bits) |
pDimensionDefinitions[i].zones = zones ? zones : 0x01 << bits; // = pow(2,bits) |
2949 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = __resolveSplitType(dimension); |
2950 |
dimension == dimension_samplechannel || |
pDimensionDefinitions[i].zone_size = __resolveZoneSize(pDimensionDefinitions[i]); |
|
dimension == dimension_releasetrigger || |
|
|
dimension == dimension_keyboard || |
|
|
dimension == dimension_roundrobin || |
|
|
dimension == dimension_random || |
|
|
dimension == dimension_smartmidi || |
|
|
dimension == dimension_roundrobinkeyboard) ? split_type_bit |
|
|
: split_type_normal; |
|
|
pDimensionDefinitions[i].zone_size = |
|
|
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
|
|
: 0; |
|
2951 |
Dimensions++; |
Dimensions++; |
2952 |
|
|
2953 |
// if this is a layer dimension, remember the amount of layers |
// if this is a layer dimension, remember the amount of layers |
2967 |
else |
else |
2968 |
_3lnk->SetPos(44); |
_3lnk->SetPos(44); |
2969 |
|
|
2970 |
// load sample references |
// load sample references (if auto loading is enabled) |
2971 |
for (uint i = 0; i < DimensionRegions; i++) { |
if (file->GetAutoLoad()) { |
2972 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
for (uint i = 0; i < DimensionRegions; i++) { |
2973 |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
2974 |
|
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2975 |
|
} |
2976 |
|
GetSample(); // load global region sample reference |
2977 |
|
} |
2978 |
|
} else { |
2979 |
|
DimensionRegions = 0; |
2980 |
|
for (int i = 0 ; i < 8 ; i++) { |
2981 |
|
pDimensionDefinitions[i].dimension = dimension_none; |
2982 |
|
pDimensionDefinitions[i].bits = 0; |
2983 |
|
pDimensionDefinitions[i].zones = 0; |
2984 |
} |
} |
|
GetSample(); // load global region sample reference |
|
2985 |
} |
} |
2986 |
|
|
2987 |
// make sure there is at least one dimension region |
// make sure there is at least one dimension region |
2989 |
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
2990 |
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
2991 |
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
2992 |
pDimensionRegions[0] = new DimensionRegion(_3ewl); |
pDimensionRegions[0] = new DimensionRegion(this, _3ewl); |
2993 |
DimensionRegions = 1; |
DimensionRegions = 1; |
2994 |
} |
} |
2995 |
} |
} |
3001 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
3002 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
3003 |
* |
* |
3004 |
|
* @param pProgress - callback function for progress notification |
3005 |
* @throws gig::Exception if samples cannot be dereferenced |
* @throws gig::Exception if samples cannot be dereferenced |
3006 |
*/ |
*/ |
3007 |
void Region::UpdateChunks() { |
void Region::UpdateChunks(progress_t* pProgress) { |
3008 |
|
// in the gig format we don't care about the Region's sample reference |
3009 |
|
// but we still have to provide some existing one to not corrupt the |
3010 |
|
// file, so to avoid the latter we simply always assign the sample of |
3011 |
|
// the first dimension region of this region |
3012 |
|
pSample = pDimensionRegions[0]->pSample; |
3013 |
|
|
3014 |
// first update base class's chunks |
// first update base class's chunks |
3015 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(pProgress); |
3016 |
|
|
3017 |
// update dimension region's chunks |
// update dimension region's chunks |
3018 |
for (int i = 0; i < DimensionRegions; i++) { |
for (int i = 0; i < DimensionRegions; i++) { |
3019 |
pDimensionRegions[i]->UpdateChunks(); |
pDimensionRegions[i]->UpdateChunks(pProgress); |
3020 |
} |
} |
3021 |
|
|
3022 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
3023 |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
bool version3 = pFile->pVersion && pFile->pVersion->major == 3; |
3024 |
const int iMaxDimensionRegions = (pFile->pVersion && pFile->pVersion->major == 3) ? 256 : 32; |
const int iMaxDimensions = version3 ? 8 : 5; |
3025 |
|
const int iMaxDimensionRegions = version3 ? 256 : 32; |
3026 |
|
|
3027 |
// make sure '3lnk' chunk exists |
// make sure '3lnk' chunk exists |
3028 |
RIFF::Chunk* _3lnk = pCkRegion->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = pCkRegion->GetSubChunk(CHUNK_ID_3LNK); |
3029 |
if (!_3lnk) { |
if (!_3lnk) { |
3030 |
const int _3lnkChunkSize = (pFile->pVersion && pFile->pVersion->major == 3) ? 1092 : 172; |
const int _3lnkChunkSize = version3 ? 1092 : 172; |
3031 |
_3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); |
_3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); |
3032 |
|
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
3033 |
|
|
3034 |
|
// move 3prg to last position |
3035 |
|
pCkRegion->MoveSubChunk(pCkRegion->GetSubList(LIST_TYPE_3PRG), (RIFF::Chunk*)NULL); |
3036 |
} |
} |
3037 |
|
|
3038 |
// update dimension definitions in '3lnk' chunk |
// update dimension definitions in '3lnk' chunk |
3039 |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
3040 |
memcpy(&pData[0], &DimensionRegions, 4); |
store32(&pData[0], DimensionRegions); |
3041 |
|
int shift = 0; |
3042 |
for (int i = 0; i < iMaxDimensions; i++) { |
for (int i = 0; i < iMaxDimensions; i++) { |
3043 |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
3044 |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
3045 |
// next 2 bytes unknown |
pData[6 + i * 8] = pDimensionDefinitions[i].dimension == dimension_none ? 0 : shift; |
3046 |
|
pData[7 + i * 8] = (1 << (shift + pDimensionDefinitions[i].bits)) - (1 << shift); |
3047 |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
3048 |
// next 3 bytes unknown |
// next 3 bytes unknown, always zero? |
3049 |
|
|
3050 |
|
shift += pDimensionDefinitions[i].bits; |
3051 |
} |
} |
3052 |
|
|
3053 |
// update wave pool table in '3lnk' chunk |
// update wave pool table in '3lnk' chunk |
3054 |
const int iWavePoolOffset = (pFile->pVersion && pFile->pVersion->major == 3) ? 68 : 44; |
const int iWavePoolOffset = version3 ? 68 : 44; |
3055 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
3056 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
3057 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
3064 |
break; |
break; |
3065 |
} |
} |
3066 |
} |
} |
|
if (iWaveIndex < 0) throw gig::Exception("Could not update gig::Region, could not find DimensionRegion's sample"); |
|
3067 |
} |
} |
3068 |
memcpy(&pData[iWavePoolOffset + i * 4], &iWaveIndex, 4); |
store32(&pData[iWavePoolOffset + i * 4], iWaveIndex); |
3069 |
} |
} |
3070 |
} |
} |
3071 |
|
|
3076 |
RIFF::List* _3ewl = _3prg->GetFirstSubList(); |
RIFF::List* _3ewl = _3prg->GetFirstSubList(); |
3077 |
while (_3ewl) { |
while (_3ewl) { |
3078 |
if (_3ewl->GetListType() == LIST_TYPE_3EWL) { |
if (_3ewl->GetListType() == LIST_TYPE_3EWL) { |
3079 |
pDimensionRegions[dimensionRegionNr] = new DimensionRegion(_3ewl); |
pDimensionRegions[dimensionRegionNr] = new DimensionRegion(this, _3ewl); |
3080 |
dimensionRegionNr++; |
dimensionRegionNr++; |
3081 |
} |
} |
3082 |
_3ewl = _3prg->GetNextSubList(); |
_3ewl = _3prg->GetNextSubList(); |
3085 |
} |
} |
3086 |
} |
} |
3087 |
|
|
3088 |
|
void Region::SetKeyRange(uint16_t Low, uint16_t High) { |
3089 |
|
// update KeyRange struct and make sure regions are in correct order |
3090 |
|
DLS::Region::SetKeyRange(Low, High); |
3091 |
|
// update Region key table for fast lookup |
3092 |
|
((gig::Instrument*)GetParent())->UpdateRegionKeyTable(); |
3093 |
|
} |
3094 |
|
|
3095 |
void Region::UpdateVelocityTable() { |
void Region::UpdateVelocityTable() { |
3096 |
// get velocity dimension's index |
// get velocity dimension's index |
3097 |
int veldim = -1; |
int veldim = -1; |
3178 |
* dimension bits limit is violated |
* dimension bits limit is violated |
3179 |
*/ |
*/ |
3180 |
void Region::AddDimension(dimension_def_t* pDimDef) { |
void Region::AddDimension(dimension_def_t* pDimDef) { |
3181 |
|
// some initial sanity checks of the given dimension definition |
3182 |
|
if (pDimDef->zones < 2) |
3183 |
|
throw gig::Exception("Could not add new dimension, amount of requested zones must always be at least two"); |
3184 |
|
if (pDimDef->bits < 1) |
3185 |
|
throw gig::Exception("Could not add new dimension, amount of requested requested zone bits must always be at least one"); |
3186 |
|
if (pDimDef->dimension == dimension_samplechannel) { |
3187 |
|
if (pDimDef->zones != 2) |
3188 |
|
throw gig::Exception("Could not add new 'sample channel' dimensions, the requested amount of zones must always be 2 for this dimension type"); |
3189 |
|
if (pDimDef->bits != 1) |
3190 |
|
throw gig::Exception("Could not add new 'sample channel' dimensions, the requested amount of zone bits must always be 1 for this dimension type"); |
3191 |
|
} |
3192 |
|
|
3193 |
// check if max. amount of dimensions reached |
// check if max. amount of dimensions reached |
3194 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3195 |
const int iMaxDimensions = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
3209 |
if (pDimensionDefinitions[i].dimension == pDimDef->dimension) |
if (pDimensionDefinitions[i].dimension == pDimDef->dimension) |
3210 |
throw gig::Exception("Could not add new dimension, there is already a dimension of the same type"); |
throw gig::Exception("Could not add new dimension, there is already a dimension of the same type"); |
3211 |
|
|
3212 |
|
// pos is where the new dimension should be placed, normally |
3213 |
|
// last in list, except for the samplechannel dimension which |
3214 |
|
// has to be first in list |
3215 |
|
int pos = pDimDef->dimension == dimension_samplechannel ? 0 : Dimensions; |
3216 |
|
int bitpos = 0; |
3217 |
|
for (int i = 0 ; i < pos ; i++) |
3218 |
|
bitpos += pDimensionDefinitions[i].bits; |
3219 |
|
|
3220 |
|
// make room for the new dimension |
3221 |
|
for (int i = Dimensions ; i > pos ; i--) pDimensionDefinitions[i] = pDimensionDefinitions[i - 1]; |
3222 |
|
for (int i = 0 ; i < (1 << iCurrentBits) ; i++) { |
3223 |
|
for (int j = Dimensions ; j > pos ; j--) { |
3224 |
|
pDimensionRegions[i]->DimensionUpperLimits[j] = |
3225 |
|
pDimensionRegions[i]->DimensionUpperLimits[j - 1]; |
3226 |
|
} |
3227 |
|
} |
3228 |
|
|
3229 |
// assign definition of new dimension |
// assign definition of new dimension |
3230 |
pDimensionDefinitions[Dimensions] = *pDimDef; |
pDimensionDefinitions[pos] = *pDimDef; |
3231 |
|
|
3232 |
|
// auto correct certain dimension definition fields (where possible) |
3233 |
|
pDimensionDefinitions[pos].split_type = |
3234 |
|
__resolveSplitType(pDimensionDefinitions[pos].dimension); |
3235 |
|
pDimensionDefinitions[pos].zone_size = |
3236 |
|
__resolveZoneSize(pDimensionDefinitions[pos]); |
3237 |
|
|
3238 |
|
// create new dimension region(s) for this new dimension, and make |
3239 |
|
// sure that the dimension regions are placed correctly in both the |
3240 |
|
// RIFF list and the pDimensionRegions array |
3241 |
|
RIFF::Chunk* moveTo = NULL; |
3242 |
|
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
3243 |
|
for (int i = (1 << iCurrentBits) - (1 << bitpos) ; i >= 0 ; i -= (1 << bitpos)) { |
3244 |
|
for (int k = 0 ; k < (1 << bitpos) ; k++) { |
3245 |
|
pDimensionRegions[(i << pDimDef->bits) + k] = pDimensionRegions[i + k]; |
3246 |
|
} |
3247 |
|
for (int j = 1 ; j < (1 << pDimDef->bits) ; j++) { |
3248 |
|
for (int k = 0 ; k < (1 << bitpos) ; k++) { |
3249 |
|
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
3250 |
|
if (moveTo) _3prg->MoveSubChunk(pNewDimRgnListChunk, moveTo); |
3251 |
|
// create a new dimension region and copy all parameter values from |
3252 |
|
// an existing dimension region |
3253 |
|
pDimensionRegions[(i << pDimDef->bits) + (j << bitpos) + k] = |
3254 |
|
new DimensionRegion(pNewDimRgnListChunk, *pDimensionRegions[i + k]); |
3255 |
|
|
3256 |
// create new dimension region(s) for this new dimension |
DimensionRegions++; |
3257 |
for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) { |
} |
3258 |
//TODO: maybe we should copy existing dimension regions if possible instead of simply creating new ones with default values |
} |
3259 |
RIFF::List* pNewDimRgnListChunk = pCkRegion->AddSubList(LIST_TYPE_3EWL); |
moveTo = pDimensionRegions[i]->pParentList; |
3260 |
pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk); |
} |
3261 |
DimensionRegions++; |
|
3262 |
|
// initialize the upper limits for this dimension |
3263 |
|
int mask = (1 << bitpos) - 1; |
3264 |
|
for (int z = 0 ; z < pDimDef->zones ; z++) { |
3265 |
|
uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1); |
3266 |
|
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
3267 |
|
pDimensionRegions[((i & ~mask) << pDimDef->bits) | |
3268 |
|
(z << bitpos) | |
3269 |
|
(i & mask)]->DimensionUpperLimits[pos] = upperLimit; |
3270 |
|
} |
3271 |
} |
} |
3272 |
|
|
3273 |
Dimensions++; |
Dimensions++; |
3310 |
for (int i = iDimensionNr + 1; i < Dimensions; i++) |
for (int i = iDimensionNr + 1; i < Dimensions; i++) |
3311 |
iUpperBits += pDimensionDefinitions[i].bits; |
iUpperBits += pDimensionDefinitions[i].bits; |
3312 |
|
|
3313 |
|
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
3314 |
|
|
3315 |
// delete dimension regions which belong to the given dimension |
// delete dimension regions which belong to the given dimension |
3316 |
// (that is where the dimension's bit > 0) |
// (that is where the dimension's bit > 0) |
3317 |
for (int iUpperBit = 0; iUpperBit < 1 << iUpperBits; iUpperBit++) { |
for (int iUpperBit = 0; iUpperBit < 1 << iUpperBits; iUpperBit++) { |
3320 |
int iToDelete = iUpperBit << (pDimensionDefinitions[iDimensionNr].bits + iLowerBits) | |
int iToDelete = iUpperBit << (pDimensionDefinitions[iDimensionNr].bits + iLowerBits) | |
3321 |
iObsoleteBit << iLowerBits | |
iObsoleteBit << iLowerBits | |
3322 |
iLowerBit; |
iLowerBit; |
3323 |
|
|
3324 |
|
_3prg->DeleteSubChunk(pDimensionRegions[iToDelete]->pParentList); |
3325 |
delete pDimensionRegions[iToDelete]; |
delete pDimensionRegions[iToDelete]; |
3326 |
pDimensionRegions[iToDelete] = NULL; |
pDimensionRegions[iToDelete] = NULL; |
3327 |
DimensionRegions--; |
DimensionRegions--; |
3342 |
} |
} |
3343 |
} |
} |
3344 |
|
|
3345 |
|
// remove the this dimension from the upper limits arrays |
3346 |
|
for (int j = 0 ; j < 256 && pDimensionRegions[j] ; j++) { |
3347 |
|
DimensionRegion* d = pDimensionRegions[j]; |
3348 |
|
for (int i = iDimensionNr + 1; i < Dimensions; i++) { |
3349 |
|
d->DimensionUpperLimits[i - 1] = d->DimensionUpperLimits[i]; |
3350 |
|
} |
3351 |
|
d->DimensionUpperLimits[Dimensions - 1] = 127; |
3352 |
|
} |
3353 |
|
|
3354 |
// 'remove' dimension definition |
// 'remove' dimension definition |
3355 |
for (int i = iDimensionNr + 1; i < Dimensions; i++) { |
for (int i = iDimensionNr + 1; i < Dimensions; i++) { |
3356 |
pDimensionDefinitions[i - 1] = pDimensionDefinitions[i]; |
pDimensionDefinitions[i - 1] = pDimensionDefinitions[i]; |
3365 |
if (pDimDef->dimension == dimension_layer) Layers = 1; |
if (pDimDef->dimension == dimension_layer) Layers = 1; |
3366 |
} |
} |
3367 |
|
|
3368 |
|
/** @brief Delete one split zone of a dimension (decrement zone amount). |
3369 |
|
* |
3370 |
|
* Instead of deleting an entire dimensions, this method will only delete |
3371 |
|
* one particular split zone given by @a zone of the Region's dimension |
3372 |
|
* given by @a type. So this method will simply decrement the amount of |
3373 |
|
* zones by one of the dimension in question. To be able to do that, the |
3374 |
|
* respective dimension must exist on this Region and it must have at least |
3375 |
|
* 3 zones. All DimensionRegion objects associated with the zone will be |
3376 |
|
* deleted. |
3377 |
|
* |
3378 |
|
* @param type - identifies the dimension where a zone shall be deleted |
3379 |
|
* @param zone - index of the dimension split zone that shall be deleted |
3380 |
|
* @throws gig::Exception if requested zone could not be deleted |
3381 |
|
*/ |
3382 |
|
void Region::DeleteDimensionZone(dimension_t type, int zone) { |
3383 |
|
dimension_def_t* oldDef = GetDimensionDefinition(type); |
3384 |
|
if (!oldDef) |
3385 |
|
throw gig::Exception("Could not delete dimension zone, no such dimension of given type"); |
3386 |
|
if (oldDef->zones <= 2) |
3387 |
|
throw gig::Exception("Could not delete dimension zone, because it would end up with only one zone."); |
3388 |
|
if (zone < 0 || zone >= oldDef->zones) |
3389 |
|
throw gig::Exception("Could not delete dimension zone, requested zone index out of bounds."); |
3390 |
|
|
3391 |
|
const int newZoneSize = oldDef->zones - 1; |
3392 |
|
|
3393 |
|
// create a temporary Region which just acts as a temporary copy |
3394 |
|
// container and will be deleted at the end of this function and will |
3395 |
|
// also not be visible through the API during this process |
3396 |
|
gig::Region* tempRgn = NULL; |
3397 |
|
{ |
3398 |
|
// adding these temporary chunks is probably not even necessary |
3399 |
|
Instrument* instr = static_cast<Instrument*>(GetParent()); |
3400 |
|
RIFF::List* pCkInstrument = instr->pCkInstrument; |
3401 |
|
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN); |
3402 |
|
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
3403 |
|
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
3404 |
|
tempRgn = new Region(instr, rgn); |
3405 |
|
} |
3406 |
|
|
3407 |
|
// copy this region's dimensions (with already the dimension split size |
3408 |
|
// requested by the arguments of this method call) to the temporary |
3409 |
|
// region, and don't use Region::CopyAssign() here for this task, since |
3410 |
|
// it would also alter fast lookup helper variables here and there |
3411 |
|
dimension_def_t newDef; |
3412 |
|
for (int i = 0; i < Dimensions; ++i) { |
3413 |
|
dimension_def_t def = pDimensionDefinitions[i]; // copy, don't reference |
3414 |
|
// is this the dimension requested by the method arguments? ... |
3415 |
|
if (def.dimension == type) { // ... if yes, decrement zone amount by one |
3416 |
|
def.zones = newZoneSize; |
3417 |
|
if ((1 << (def.bits - 1)) == def.zones) def.bits--; |
3418 |
|
newDef = def; |
3419 |
|
} |
3420 |
|
tempRgn->AddDimension(&def); |
3421 |
|
} |
3422 |
|
|
3423 |
|
// find the dimension index in the tempRegion which is the dimension |
3424 |
|
// type passed to this method (paranoidly expecting different order) |
3425 |
|
int tempReducedDimensionIndex = -1; |
3426 |
|
for (int d = 0; d < tempRgn->Dimensions; ++d) { |
3427 |
|
if (tempRgn->pDimensionDefinitions[d].dimension == type) { |
3428 |
|
tempReducedDimensionIndex = d; |
3429 |
|
break; |
3430 |
|
} |
3431 |
|
} |
3432 |
|
|
3433 |
|
// copy dimension regions from this region to the temporary region |
3434 |
|
for (int iDst = 0; iDst < 256; ++iDst) { |
3435 |
|
DimensionRegion* dstDimRgn = tempRgn->pDimensionRegions[iDst]; |
3436 |
|
if (!dstDimRgn) continue; |
3437 |
|
std::map<dimension_t,int> dimCase; |
3438 |
|
bool isValidZone = true; |
3439 |
|
for (int d = 0, baseBits = 0; d < tempRgn->Dimensions; ++d) { |
3440 |
|
const int dstBits = tempRgn->pDimensionDefinitions[d].bits; |
3441 |
|
dimCase[tempRgn->pDimensionDefinitions[d].dimension] = |
3442 |
|
(iDst >> baseBits) & ((1 << dstBits) - 1); |
3443 |
|
baseBits += dstBits; |
3444 |
|
// there are also DimensionRegion objects of unused zones, skip them |
3445 |
|
if (dimCase[tempRgn->pDimensionDefinitions[d].dimension] >= tempRgn->pDimensionDefinitions[d].zones) { |
3446 |
|
isValidZone = false; |
3447 |
|
break; |
3448 |
|
} |
3449 |
|
} |
3450 |
|
if (!isValidZone) continue; |
3451 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3452 |
|
// have different order in source and destination regions |
3453 |
|
const bool isLastZone = (dimCase[type] == newZoneSize - 1); |
3454 |
|
if (dimCase[type] >= zone) dimCase[type]++; |
3455 |
|
DimensionRegion* srcDimRgn = GetDimensionRegionByBit(dimCase); |
3456 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3457 |
|
// if this is the upper most zone of the dimension passed to this |
3458 |
|
// method, then correct (raise) its upper limit to 127 |
3459 |
|
if (newDef.split_type == split_type_normal && isLastZone) |
3460 |
|
dstDimRgn->DimensionUpperLimits[tempReducedDimensionIndex] = 127; |
3461 |
|
} |
3462 |
|
|
3463 |
|
// now tempRegion's dimensions and DimensionRegions basically reflect |
3464 |
|
// what we wanted to get for this actual Region here, so we now just |
3465 |
|
// delete and recreate the dimension in question with the new amount |
3466 |
|
// zones and then copy back from tempRegion |
3467 |
|
DeleteDimension(oldDef); |
3468 |
|
AddDimension(&newDef); |
3469 |
|
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3470 |
|
DimensionRegion* srcDimRgn = tempRgn->pDimensionRegions[iSrc]; |
3471 |
|
if (!srcDimRgn) continue; |
3472 |
|
std::map<dimension_t,int> dimCase; |
3473 |
|
for (int d = 0, baseBits = 0; d < tempRgn->Dimensions; ++d) { |
3474 |
|
const int srcBits = tempRgn->pDimensionDefinitions[d].bits; |
3475 |
|
dimCase[tempRgn->pDimensionDefinitions[d].dimension] = |
3476 |
|
(iSrc >> baseBits) & ((1 << srcBits) - 1); |
3477 |
|
baseBits += srcBits; |
3478 |
|
} |
3479 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3480 |
|
// have different order in source and destination regions |
3481 |
|
DimensionRegion* dstDimRgn = GetDimensionRegionByBit(dimCase); |
3482 |
|
if (!dstDimRgn) continue; |
3483 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3484 |
|
} |
3485 |
|
|
3486 |
|
// delete temporary region |
3487 |
|
delete tempRgn; |
3488 |
|
|
3489 |
|
UpdateVelocityTable(); |
3490 |
|
} |
3491 |
|
|
3492 |
|
/** @brief Divide split zone of a dimension in two (increment zone amount). |
3493 |
|
* |
3494 |
|
* This will increment the amount of zones for the dimension (given by |
3495 |
|
* @a type) by one. It will do so by dividing the zone (given by @a zone) |
3496 |
|
* in the middle of its zone range in two. So the two zones resulting from |
3497 |
|
* the zone being splitted, will be an equivalent copy regarding all their |
3498 |
|
* articulation informations and sample reference. The two zones will only |
3499 |
|
* differ in their zone's upper limit |
3500 |
|
* (DimensionRegion::DimensionUpperLimits). |
3501 |
|
* |
3502 |
|
* @param type - identifies the dimension where a zone shall be splitted |
3503 |
|
* @param zone - index of the dimension split zone that shall be splitted |
3504 |
|
* @throws gig::Exception if requested zone could not be splitted |
3505 |
|
*/ |
3506 |
|
void Region::SplitDimensionZone(dimension_t type, int zone) { |
3507 |
|
dimension_def_t* oldDef = GetDimensionDefinition(type); |
3508 |
|
if (!oldDef) |
3509 |
|
throw gig::Exception("Could not split dimension zone, no such dimension of given type"); |
3510 |
|
if (zone < 0 || zone >= oldDef->zones) |
3511 |
|
throw gig::Exception("Could not split dimension zone, requested zone index out of bounds."); |
3512 |
|
|
3513 |
|
const int newZoneSize = oldDef->zones + 1; |
3514 |
|
|
3515 |
|
// create a temporary Region which just acts as a temporary copy |
3516 |
|
// container and will be deleted at the end of this function and will |
3517 |
|
// also not be visible through the API during this process |
3518 |
|
gig::Region* tempRgn = NULL; |
3519 |
|
{ |
3520 |
|
// adding these temporary chunks is probably not even necessary |
3521 |
|
Instrument* instr = static_cast<Instrument*>(GetParent()); |
3522 |
|
RIFF::List* pCkInstrument = instr->pCkInstrument; |
3523 |
|
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN); |
3524 |
|
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
3525 |
|
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
3526 |
|
tempRgn = new Region(instr, rgn); |
3527 |
|
} |
3528 |
|
|
3529 |
|
// copy this region's dimensions (with already the dimension split size |
3530 |
|
// requested by the arguments of this method call) to the temporary |
3531 |
|
// region, and don't use Region::CopyAssign() here for this task, since |
3532 |
|
// it would also alter fast lookup helper variables here and there |
3533 |
|
dimension_def_t newDef; |
3534 |
|
for (int i = 0; i < Dimensions; ++i) { |
3535 |
|
dimension_def_t def = pDimensionDefinitions[i]; // copy, don't reference |
3536 |
|
// is this the dimension requested by the method arguments? ... |
3537 |
|
if (def.dimension == type) { // ... if yes, increment zone amount by one |
3538 |
|
def.zones = newZoneSize; |
3539 |
|
if ((1 << oldDef->bits) < newZoneSize) def.bits++; |
3540 |
|
newDef = def; |
3541 |
|
} |
3542 |
|
tempRgn->AddDimension(&def); |
3543 |
|
} |
3544 |
|
|
3545 |
|
// find the dimension index in the tempRegion which is the dimension |
3546 |
|
// type passed to this method (paranoidly expecting different order) |
3547 |
|
int tempIncreasedDimensionIndex = -1; |
3548 |
|
for (int d = 0; d < tempRgn->Dimensions; ++d) { |
3549 |
|
if (tempRgn->pDimensionDefinitions[d].dimension == type) { |
3550 |
|
tempIncreasedDimensionIndex = d; |
3551 |
|
break; |
3552 |
|
} |
3553 |
|
} |
3554 |
|
|
3555 |
|
// copy dimension regions from this region to the temporary region |
3556 |
|
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3557 |
|
DimensionRegion* srcDimRgn = pDimensionRegions[iSrc]; |
3558 |
|
if (!srcDimRgn) continue; |
3559 |
|
std::map<dimension_t,int> dimCase; |
3560 |
|
bool isValidZone = true; |
3561 |
|
for (int d = 0, baseBits = 0; d < Dimensions; ++d) { |
3562 |
|
const int srcBits = pDimensionDefinitions[d].bits; |
3563 |
|
dimCase[pDimensionDefinitions[d].dimension] = |
3564 |
|
(iSrc >> baseBits) & ((1 << srcBits) - 1); |
3565 |
|
// there are also DimensionRegion objects for unused zones, skip them |
3566 |
|
if (dimCase[pDimensionDefinitions[d].dimension] >= pDimensionDefinitions[d].zones) { |
3567 |
|
isValidZone = false; |
3568 |
|
break; |
3569 |
|
} |
3570 |
|
baseBits += srcBits; |
3571 |
|
} |
3572 |
|
if (!isValidZone) continue; |
3573 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3574 |
|
// have different order in source and destination regions |
3575 |
|
if (dimCase[type] > zone) dimCase[type]++; |
3576 |
|
DimensionRegion* dstDimRgn = tempRgn->GetDimensionRegionByBit(dimCase); |
3577 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3578 |
|
// if this is the requested zone to be splitted, then also copy |
3579 |
|
// the source DimensionRegion to the newly created target zone |
3580 |
|
// and set the old zones upper limit lower |
3581 |
|
if (dimCase[type] == zone) { |
3582 |
|
// lower old zones upper limit |
3583 |
|
if (newDef.split_type == split_type_normal) { |
3584 |
|
const int high = |
3585 |
|
dstDimRgn->DimensionUpperLimits[tempIncreasedDimensionIndex]; |
3586 |
|
int low = 0; |
3587 |
|
if (zone > 0) { |
3588 |
|
std::map<dimension_t,int> lowerCase = dimCase; |
3589 |
|
lowerCase[type]--; |
3590 |
|
DimensionRegion* dstDimRgnLow = tempRgn->GetDimensionRegionByBit(lowerCase); |
3591 |
|
low = dstDimRgnLow->DimensionUpperLimits[tempIncreasedDimensionIndex]; |
3592 |
|
} |
3593 |
|
dstDimRgn->DimensionUpperLimits[tempIncreasedDimensionIndex] = low + (high - low) / 2; |
3594 |
|
} |
3595 |
|
// fill the newly created zone of the divided zone as well |
3596 |
|
dimCase[type]++; |
3597 |
|
dstDimRgn = tempRgn->GetDimensionRegionByBit(dimCase); |
3598 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3599 |
|
} |
3600 |
|
} |
3601 |
|
|
3602 |
|
// now tempRegion's dimensions and DimensionRegions basically reflect |
3603 |
|
// what we wanted to get for this actual Region here, so we now just |
3604 |
|
// delete and recreate the dimension in question with the new amount |
3605 |
|
// zones and then copy back from tempRegion |
3606 |
|
DeleteDimension(oldDef); |
3607 |
|
AddDimension(&newDef); |
3608 |
|
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3609 |
|
DimensionRegion* srcDimRgn = tempRgn->pDimensionRegions[iSrc]; |
3610 |
|
if (!srcDimRgn) continue; |
3611 |
|
std::map<dimension_t,int> dimCase; |
3612 |
|
for (int d = 0, baseBits = 0; d < tempRgn->Dimensions; ++d) { |
3613 |
|
const int srcBits = tempRgn->pDimensionDefinitions[d].bits; |
3614 |
|
dimCase[tempRgn->pDimensionDefinitions[d].dimension] = |
3615 |
|
(iSrc >> baseBits) & ((1 << srcBits) - 1); |
3616 |
|
baseBits += srcBits; |
3617 |
|
} |
3618 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3619 |
|
// have different order in source and destination regions |
3620 |
|
DimensionRegion* dstDimRgn = GetDimensionRegionByBit(dimCase); |
3621 |
|
if (!dstDimRgn) continue; |
3622 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3623 |
|
} |
3624 |
|
|
3625 |
|
// delete temporary region |
3626 |
|
delete tempRgn; |
3627 |
|
|
3628 |
|
UpdateVelocityTable(); |
3629 |
|
} |
3630 |
|
|
3631 |
|
/** @brief Change type of an existing dimension. |
3632 |
|
* |
3633 |
|
* Alters the dimension type of a dimension already existing on this |
3634 |
|
* region. If there is currently no dimension on this Region with type |
3635 |
|
* @a oldType, then this call with throw an Exception. Likewise there are |
3636 |
|
* cases where the requested dimension type cannot be performed. For example |
3637 |
|
* if the new dimension type shall be gig::dimension_samplechannel, and the |
3638 |
|
* current dimension has more than 2 zones. In such cases an Exception is |
3639 |
|
* thrown as well. |
3640 |
|
* |
3641 |
|
* @param oldType - identifies the existing dimension to be changed |
3642 |
|
* @param newType - to which dimension type it should be changed to |
3643 |
|
* @throws gig::Exception if requested change cannot be performed |
3644 |
|
*/ |
3645 |
|
void Region::SetDimensionType(dimension_t oldType, dimension_t newType) { |
3646 |
|
if (oldType == newType) return; |
3647 |
|
dimension_def_t* def = GetDimensionDefinition(oldType); |
3648 |
|
if (!def) |
3649 |
|
throw gig::Exception("No dimension with provided old dimension type exists on this region"); |
3650 |
|
if (newType == dimension_samplechannel && def->zones != 2) |
3651 |
|
throw gig::Exception("Cannot change to dimension type 'sample channel', because existing dimension does not have 2 zones"); |
3652 |
|
if (GetDimensionDefinition(newType)) |
3653 |
|
throw gig::Exception("There is already a dimension with requested new dimension type on this region"); |
3654 |
|
def->dimension = newType; |
3655 |
|
def->split_type = __resolveSplitType(newType); |
3656 |
|
} |
3657 |
|
|
3658 |
|
DimensionRegion* Region::GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase) { |
3659 |
|
uint8_t bits[8] = {}; |
3660 |
|
for (std::map<dimension_t,int>::const_iterator it = DimCase.begin(); |
3661 |
|
it != DimCase.end(); ++it) |
3662 |
|
{ |
3663 |
|
for (int d = 0; d < Dimensions; ++d) { |
3664 |
|
if (pDimensionDefinitions[d].dimension == it->first) { |
3665 |
|
bits[d] = it->second; |
3666 |
|
goto nextDimCaseSlice; |
3667 |
|
} |
3668 |
|
} |
3669 |
|
assert(false); // do crash ... too harsh maybe ? ignore it instead ? |
3670 |
|
nextDimCaseSlice: |
3671 |
|
; // noop |
3672 |
|
} |
3673 |
|
return GetDimensionRegionByBit(bits); |
3674 |
|
} |
3675 |
|
|
3676 |
|
/** |
3677 |
|
* Searches in the current Region for a dimension of the given dimension |
3678 |
|
* type and returns the precise configuration of that dimension in this |
3679 |
|
* Region. |
3680 |
|
* |
3681 |
|
* @param type - dimension type of the sought dimension |
3682 |
|
* @returns dimension definition or NULL if there is no dimension with |
3683 |
|
* sought type in this Region. |
3684 |
|
*/ |
3685 |
|
dimension_def_t* Region::GetDimensionDefinition(dimension_t type) { |
3686 |
|
for (int i = 0; i < Dimensions; ++i) |
3687 |
|
if (pDimensionDefinitions[i].dimension == type) |
3688 |
|
return &pDimensionDefinitions[i]; |
3689 |
|
return NULL; |
3690 |
|
} |
3691 |
|
|
3692 |
Region::~Region() { |
Region::~Region() { |
3693 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
3694 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
3746 |
} |
} |
3747 |
bitpos += pDimensionDefinitions[i].bits; |
bitpos += pDimensionDefinitions[i].bits; |
3748 |
} |
} |
3749 |
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
DimensionRegion* dimreg = pDimensionRegions[dimregidx & 255]; |
3750 |
|
if (!dimreg) return NULL; |
3751 |
if (veldim != -1) { |
if (veldim != -1) { |
3752 |
// (dimreg is now the dimension region for the lowest velocity) |
// (dimreg is now the dimension region for the lowest velocity) |
3753 |
if (dimreg->VelocityTable) // custom defined zone ranges |
if (dimreg->VelocityTable) // custom defined zone ranges |
3754 |
bits = dimreg->VelocityTable[DimValues[veldim]]; |
bits = dimreg->VelocityTable[DimValues[veldim] & 127]; |
3755 |
else // normal split type |
else // normal split type |
3756 |
bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size); |
bits = uint8_t((DimValues[veldim] & 127) / pDimensionDefinitions[veldim].zone_size); |
3757 |
|
|
3758 |
dimregidx |= bits << velbitpos; |
const uint8_t limiter_mask = (1 << pDimensionDefinitions[veldim].bits) - 1; |
3759 |
dimreg = pDimensionRegions[dimregidx]; |
dimregidx |= (bits & limiter_mask) << velbitpos; |
3760 |
|
dimreg = pDimensionRegions[dimregidx & 255]; |
3761 |
} |
} |
3762 |
return dimreg; |
return dimreg; |
3763 |
} |
} |
3764 |
|
|
3765 |
|
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
3766 |
|
uint8_t bits; |
3767 |
|
int veldim = -1; |
3768 |
|
int velbitpos; |
3769 |
|
int bitpos = 0; |
3770 |
|
int dimregidx = 0; |
3771 |
|
for (uint i = 0; i < Dimensions; i++) { |
3772 |
|
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
3773 |
|
// the velocity dimension must be handled after the other dimensions |
3774 |
|
veldim = i; |
3775 |
|
velbitpos = bitpos; |
3776 |
|
} else { |
3777 |
|
switch (pDimensionDefinitions[i].split_type) { |
3778 |
|
case split_type_normal: |
3779 |
|
if (pDimensionRegions[0]->DimensionUpperLimits[i]) { |
3780 |
|
// gig3: all normal dimensions (not just the velocity dimension) have custom zone ranges |
3781 |
|
for (bits = 0 ; bits < pDimensionDefinitions[i].zones ; bits++) { |
3782 |
|
if (DimValues[i] <= pDimensionRegions[bits << bitpos]->DimensionUpperLimits[i]) break; |
3783 |
|
} |
3784 |
|
} else { |
3785 |
|
// gig2: evenly sized zones |
3786 |
|
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
3787 |
|
} |
3788 |
|
break; |
3789 |
|
case split_type_bit: // the value is already the sought dimension bit number |
3790 |
|
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
3791 |
|
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
3792 |
|
break; |
3793 |
|
} |
3794 |
|
dimregidx |= bits << bitpos; |
3795 |
|
} |
3796 |
|
bitpos += pDimensionDefinitions[i].bits; |
3797 |
|
} |
3798 |
|
dimregidx &= 255; |
3799 |
|
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
3800 |
|
if (!dimreg) return -1; |
3801 |
|
if (veldim != -1) { |
3802 |
|
// (dimreg is now the dimension region for the lowest velocity) |
3803 |
|
if (dimreg->VelocityTable) // custom defined zone ranges |
3804 |
|
bits = dimreg->VelocityTable[DimValues[veldim] & 127]; |
3805 |
|
else // normal split type |
3806 |
|
bits = uint8_t((DimValues[veldim] & 127) / pDimensionDefinitions[veldim].zone_size); |
3807 |
|
|
3808 |
|
const uint8_t limiter_mask = (1 << pDimensionDefinitions[veldim].bits) - 1; |
3809 |
|
dimregidx |= (bits & limiter_mask) << velbitpos; |
3810 |
|
dimregidx &= 255; |
3811 |
|
} |
3812 |
|
return dimregidx; |
3813 |
|
} |
3814 |
|
|
3815 |
/** |
/** |
3816 |
* Returns the appropriate DimensionRegion for the given dimension bit |
* Returns the appropriate DimensionRegion for the given dimension bit |
3817 |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
3850 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
3851 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3852 |
if (!file->pWavePoolTable) return NULL; |
if (!file->pWavePoolTable) return NULL; |
3853 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
// for new files or files >= 2 GB use 64 bit wave pool offsets |
3854 |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
if (file->pRIFF->IsNew() || (file->pRIFF->GetCurrentFileSize() >> 31)) { |
3855 |
Sample* sample = file->GetFirstSample(pProgress); |
// use 64 bit wave pool offsets (treating this as large file) |
3856 |
while (sample) { |
uint64_t soughtoffset = |
3857 |
if (sample->ulWavePoolOffset == soughtoffset && |
uint64_t(file->pWavePoolTable[WavePoolTableIndex]) | |
3858 |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
uint64_t(file->pWavePoolTableHi[WavePoolTableIndex]) << 32; |
3859 |
sample = file->GetNextSample(); |
Sample* sample = file->GetFirstSample(pProgress); |
3860 |
|
while (sample) { |
3861 |
|
if (sample->ullWavePoolOffset == soughtoffset) |
3862 |
|
return static_cast<gig::Sample*>(sample); |
3863 |
|
sample = file->GetNextSample(); |
3864 |
|
} |
3865 |
|
} else { |
3866 |
|
// use extension files and 32 bit wave pool offsets |
3867 |
|
file_offset_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
3868 |
|
file_offset_t soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
3869 |
|
Sample* sample = file->GetFirstSample(pProgress); |
3870 |
|
while (sample) { |
3871 |
|
if (sample->ullWavePoolOffset == soughtoffset && |
3872 |
|
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
3873 |
|
sample = file->GetNextSample(); |
3874 |
|
} |
3875 |
|
} |
3876 |
|
return NULL; |
3877 |
|
} |
3878 |
|
|
3879 |
|
/** |
3880 |
|
* Make a (semi) deep copy of the Region object given by @a orig |
3881 |
|
* and assign it to this object. |
3882 |
|
* |
3883 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
3884 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
3885 |
|
* |
3886 |
|
* @param orig - original Region object to be copied from |
3887 |
|
*/ |
3888 |
|
void Region::CopyAssign(const Region* orig) { |
3889 |
|
CopyAssign(orig, NULL); |
3890 |
|
} |
3891 |
|
|
3892 |
|
/** |
3893 |
|
* Make a (semi) deep copy of the Region object given by @a orig and |
3894 |
|
* assign it to this object |
3895 |
|
* |
3896 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
3897 |
|
* this file's samples |
3898 |
|
*/ |
3899 |
|
void Region::CopyAssign(const Region* orig, const std::map<Sample*,Sample*>* mSamples) { |
3900 |
|
// handle base classes |
3901 |
|
DLS::Region::CopyAssign(orig); |
3902 |
|
|
3903 |
|
if (mSamples && mSamples->count((gig::Sample*)orig->pSample)) { |
3904 |
|
pSample = mSamples->find((gig::Sample*)orig->pSample)->second; |
3905 |
|
} |
3906 |
|
|
3907 |
|
// handle own member variables |
3908 |
|
for (int i = Dimensions - 1; i >= 0; --i) { |
3909 |
|
DeleteDimension(&pDimensionDefinitions[i]); |
3910 |
|
} |
3911 |
|
Layers = 0; // just to be sure |
3912 |
|
for (int i = 0; i < orig->Dimensions; i++) { |
3913 |
|
// we need to copy the dim definition here, to avoid the compiler |
3914 |
|
// complaining about const-ness issue |
3915 |
|
dimension_def_t def = orig->pDimensionDefinitions[i]; |
3916 |
|
AddDimension(&def); |
3917 |
|
} |
3918 |
|
for (int i = 0; i < 256; i++) { |
3919 |
|
if (pDimensionRegions[i] && orig->pDimensionRegions[i]) { |
3920 |
|
pDimensionRegions[i]->CopyAssign( |
3921 |
|
orig->pDimensionRegions[i], |
3922 |
|
mSamples |
3923 |
|
); |
3924 |
|
} |
3925 |
|
} |
3926 |
|
Layers = orig->Layers; |
3927 |
|
} |
3928 |
|
|
3929 |
|
|
3930 |
|
// *************** MidiRule *************** |
3931 |
|
// * |
3932 |
|
|
3933 |
|
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) { |
3934 |
|
_3ewg->SetPos(36); |
3935 |
|
Triggers = _3ewg->ReadUint8(); |
3936 |
|
_3ewg->SetPos(40); |
3937 |
|
ControllerNumber = _3ewg->ReadUint8(); |
3938 |
|
_3ewg->SetPos(46); |
3939 |
|
for (int i = 0 ; i < Triggers ; i++) { |
3940 |
|
pTriggers[i].TriggerPoint = _3ewg->ReadUint8(); |
3941 |
|
pTriggers[i].Descending = _3ewg->ReadUint8(); |
3942 |
|
pTriggers[i].VelSensitivity = _3ewg->ReadUint8(); |
3943 |
|
pTriggers[i].Key = _3ewg->ReadUint8(); |
3944 |
|
pTriggers[i].NoteOff = _3ewg->ReadUint8(); |
3945 |
|
pTriggers[i].Velocity = _3ewg->ReadUint8(); |
3946 |
|
pTriggers[i].OverridePedal = _3ewg->ReadUint8(); |
3947 |
|
_3ewg->ReadUint8(); |
3948 |
|
} |
3949 |
|
} |
3950 |
|
|
3951 |
|
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger() : |
3952 |
|
ControllerNumber(0), |
3953 |
|
Triggers(0) { |
3954 |
|
} |
3955 |
|
|
3956 |
|
void MidiRuleCtrlTrigger::UpdateChunks(uint8_t* pData) const { |
3957 |
|
pData[32] = 4; |
3958 |
|
pData[33] = 16; |
3959 |
|
pData[36] = Triggers; |
3960 |
|
pData[40] = ControllerNumber; |
3961 |
|
for (int i = 0 ; i < Triggers ; i++) { |
3962 |
|
pData[46 + i * 8] = pTriggers[i].TriggerPoint; |
3963 |
|
pData[47 + i * 8] = pTriggers[i].Descending; |
3964 |
|
pData[48 + i * 8] = pTriggers[i].VelSensitivity; |
3965 |
|
pData[49 + i * 8] = pTriggers[i].Key; |
3966 |
|
pData[50 + i * 8] = pTriggers[i].NoteOff; |
3967 |
|
pData[51 + i * 8] = pTriggers[i].Velocity; |
3968 |
|
pData[52 + i * 8] = pTriggers[i].OverridePedal; |
3969 |
|
} |
3970 |
|
} |
3971 |
|
|
3972 |
|
MidiRuleLegato::MidiRuleLegato(RIFF::Chunk* _3ewg) { |
3973 |
|
_3ewg->SetPos(36); |
3974 |
|
LegatoSamples = _3ewg->ReadUint8(); // always 12 |
3975 |
|
_3ewg->SetPos(40); |
3976 |
|
BypassUseController = _3ewg->ReadUint8(); |
3977 |
|
BypassKey = _3ewg->ReadUint8(); |
3978 |
|
BypassController = _3ewg->ReadUint8(); |
3979 |
|
ThresholdTime = _3ewg->ReadUint16(); |
3980 |
|
_3ewg->ReadInt16(); |
3981 |
|
ReleaseTime = _3ewg->ReadUint16(); |
3982 |
|
_3ewg->ReadInt16(); |
3983 |
|
KeyRange.low = _3ewg->ReadUint8(); |
3984 |
|
KeyRange.high = _3ewg->ReadUint8(); |
3985 |
|
_3ewg->SetPos(64); |
3986 |
|
ReleaseTriggerKey = _3ewg->ReadUint8(); |
3987 |
|
AltSustain1Key = _3ewg->ReadUint8(); |
3988 |
|
AltSustain2Key = _3ewg->ReadUint8(); |
3989 |
|
} |
3990 |
|
|
3991 |
|
MidiRuleLegato::MidiRuleLegato() : |
3992 |
|
LegatoSamples(12), |
3993 |
|
BypassUseController(false), |
3994 |
|
BypassKey(0), |
3995 |
|
BypassController(1), |
3996 |
|
ThresholdTime(20), |
3997 |
|
ReleaseTime(20), |
3998 |
|
ReleaseTriggerKey(0), |
3999 |
|
AltSustain1Key(0), |
4000 |
|
AltSustain2Key(0) |
4001 |
|
{ |
4002 |
|
KeyRange.low = KeyRange.high = 0; |
4003 |
|
} |
4004 |
|
|
4005 |
|
void MidiRuleLegato::UpdateChunks(uint8_t* pData) const { |
4006 |
|
pData[32] = 0; |
4007 |
|
pData[33] = 16; |
4008 |
|
pData[36] = LegatoSamples; |
4009 |
|
pData[40] = BypassUseController; |
4010 |
|
pData[41] = BypassKey; |
4011 |
|
pData[42] = BypassController; |
4012 |
|
store16(&pData[43], ThresholdTime); |
4013 |
|
store16(&pData[47], ReleaseTime); |
4014 |
|
pData[51] = KeyRange.low; |
4015 |
|
pData[52] = KeyRange.high; |
4016 |
|
pData[64] = ReleaseTriggerKey; |
4017 |
|
pData[65] = AltSustain1Key; |
4018 |
|
pData[66] = AltSustain2Key; |
4019 |
|
} |
4020 |
|
|
4021 |
|
MidiRuleAlternator::MidiRuleAlternator(RIFF::Chunk* _3ewg) { |
4022 |
|
_3ewg->SetPos(36); |
4023 |
|
Articulations = _3ewg->ReadUint8(); |
4024 |
|
int flags = _3ewg->ReadUint8(); |
4025 |
|
Polyphonic = flags & 8; |
4026 |
|
Chained = flags & 4; |
4027 |
|
Selector = (flags & 2) ? selector_controller : |
4028 |
|
(flags & 1) ? selector_key_switch : selector_none; |
4029 |
|
Patterns = _3ewg->ReadUint8(); |
4030 |
|
_3ewg->ReadUint8(); // chosen row |
4031 |
|
_3ewg->ReadUint8(); // unknown |
4032 |
|
_3ewg->ReadUint8(); // unknown |
4033 |
|
_3ewg->ReadUint8(); // unknown |
4034 |
|
KeySwitchRange.low = _3ewg->ReadUint8(); |
4035 |
|
KeySwitchRange.high = _3ewg->ReadUint8(); |
4036 |
|
Controller = _3ewg->ReadUint8(); |
4037 |
|
PlayRange.low = _3ewg->ReadUint8(); |
4038 |
|
PlayRange.high = _3ewg->ReadUint8(); |
4039 |
|
|
4040 |
|
int n = std::min(int(Articulations), 32); |
4041 |
|
for (int i = 0 ; i < n ; i++) { |
4042 |
|
_3ewg->ReadString(pArticulations[i], 32); |
4043 |
|
} |
4044 |
|
_3ewg->SetPos(1072); |
4045 |
|
n = std::min(int(Patterns), 32); |
4046 |
|
for (int i = 0 ; i < n ; i++) { |
4047 |
|
_3ewg->ReadString(pPatterns[i].Name, 16); |
4048 |
|
pPatterns[i].Size = _3ewg->ReadUint8(); |
4049 |
|
_3ewg->Read(&pPatterns[i][0], 1, 32); |
4050 |
|
} |
4051 |
|
} |
4052 |
|
|
4053 |
|
MidiRuleAlternator::MidiRuleAlternator() : |
4054 |
|
Articulations(0), |
4055 |
|
Patterns(0), |
4056 |
|
Selector(selector_none), |
4057 |
|
Controller(0), |
4058 |
|
Polyphonic(false), |
4059 |
|
Chained(false) |
4060 |
|
{ |
4061 |
|
PlayRange.low = PlayRange.high = 0; |
4062 |
|
KeySwitchRange.low = KeySwitchRange.high = 0; |
4063 |
|
} |
4064 |
|
|
4065 |
|
void MidiRuleAlternator::UpdateChunks(uint8_t* pData) const { |
4066 |
|
pData[32] = 3; |
4067 |
|
pData[33] = 16; |
4068 |
|
pData[36] = Articulations; |
4069 |
|
pData[37] = (Polyphonic ? 8 : 0) | (Chained ? 4 : 0) | |
4070 |
|
(Selector == selector_controller ? 2 : |
4071 |
|
(Selector == selector_key_switch ? 1 : 0)); |
4072 |
|
pData[38] = Patterns; |
4073 |
|
|
4074 |
|
pData[43] = KeySwitchRange.low; |
4075 |
|
pData[44] = KeySwitchRange.high; |
4076 |
|
pData[45] = Controller; |
4077 |
|
pData[46] = PlayRange.low; |
4078 |
|
pData[47] = PlayRange.high; |
4079 |
|
|
4080 |
|
char* str = reinterpret_cast<char*>(pData); |
4081 |
|
int pos = 48; |
4082 |
|
int n = std::min(int(Articulations), 32); |
4083 |
|
for (int i = 0 ; i < n ; i++, pos += 32) { |
4084 |
|
strncpy(&str[pos], pArticulations[i].c_str(), 32); |
4085 |
|
} |
4086 |
|
|
4087 |
|
pos = 1072; |
4088 |
|
n = std::min(int(Patterns), 32); |
4089 |
|
for (int i = 0 ; i < n ; i++, pos += 49) { |
4090 |
|
strncpy(&str[pos], pPatterns[i].Name.c_str(), 16); |
4091 |
|
pData[pos + 16] = pPatterns[i].Size; |
4092 |
|
memcpy(&pData[pos + 16], &(pPatterns[i][0]), 32); |
4093 |
|
} |
4094 |
|
} |
4095 |
|
|
4096 |
|
// *************** Script *************** |
4097 |
|
// * |
4098 |
|
|
4099 |
|
Script::Script(ScriptGroup* group, RIFF::Chunk* ckScri) { |
4100 |
|
pGroup = group; |
4101 |
|
pChunk = ckScri; |
4102 |
|
if (ckScri) { // object is loaded from file ... |
4103 |
|
// read header |
4104 |
|
uint32_t headerSize = ckScri->ReadUint32(); |
4105 |
|
Compression = (Compression_t) ckScri->ReadUint32(); |
4106 |
|
Encoding = (Encoding_t) ckScri->ReadUint32(); |
4107 |
|
Language = (Language_t) ckScri->ReadUint32(); |
4108 |
|
Bypass = (Language_t) ckScri->ReadUint32() & 1; |
4109 |
|
crc = ckScri->ReadUint32(); |
4110 |
|
uint32_t nameSize = ckScri->ReadUint32(); |
4111 |
|
Name.resize(nameSize, ' '); |
4112 |
|
for (int i = 0; i < nameSize; ++i) |
4113 |
|
Name[i] = ckScri->ReadUint8(); |
4114 |
|
// to handle potential future extensions of the header |
4115 |
|
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4116 |
|
// read actual script data |
4117 |
|
uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos(); |
4118 |
|
data.resize(scriptSize); |
4119 |
|
for (int i = 0; i < scriptSize; ++i) |
4120 |
|
data[i] = ckScri->ReadUint8(); |
4121 |
|
} else { // this is a new script object, so just initialize it as such ... |
4122 |
|
Compression = COMPRESSION_NONE; |
4123 |
|
Encoding = ENCODING_ASCII; |
4124 |
|
Language = LANGUAGE_NKSP; |
4125 |
|
Bypass = false; |
4126 |
|
crc = 0; |
4127 |
|
Name = "Unnamed Script"; |
4128 |
|
} |
4129 |
|
} |
4130 |
|
|
4131 |
|
Script::~Script() { |
4132 |
|
} |
4133 |
|
|
4134 |
|
/** |
4135 |
|
* Returns the current script (i.e. as source code) in text format. |
4136 |
|
*/ |
4137 |
|
String Script::GetScriptAsText() { |
4138 |
|
String s; |
4139 |
|
s.resize(data.size(), ' '); |
4140 |
|
memcpy(&s[0], &data[0], data.size()); |
4141 |
|
return s; |
4142 |
|
} |
4143 |
|
|
4144 |
|
/** |
4145 |
|
* Replaces the current script with the new script source code text given |
4146 |
|
* by @a text. |
4147 |
|
* |
4148 |
|
* @param text - new script source code |
4149 |
|
*/ |
4150 |
|
void Script::SetScriptAsText(const String& text) { |
4151 |
|
data.resize(text.size()); |
4152 |
|
memcpy(&data[0], &text[0], text.size()); |
4153 |
|
} |
4154 |
|
|
4155 |
|
/** |
4156 |
|
* Apply this script to the respective RIFF chunks. You have to call |
4157 |
|
* File::Save() to make changes persistent. |
4158 |
|
* |
4159 |
|
* Usually there is absolutely no need to call this method explicitly. |
4160 |
|
* It will be called automatically when File::Save() was called. |
4161 |
|
* |
4162 |
|
* @param pProgress - callback function for progress notification |
4163 |
|
*/ |
4164 |
|
void Script::UpdateChunks(progress_t* pProgress) { |
4165 |
|
// recalculate CRC32 check sum |
4166 |
|
__resetCRC(crc); |
4167 |
|
__calculateCRC(&data[0], data.size(), crc); |
4168 |
|
__encodeCRC(crc); |
4169 |
|
// make sure chunk exists and has the required size |
4170 |
|
const int chunkSize = 7*sizeof(int32_t) + Name.size() + data.size(); |
4171 |
|
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
4172 |
|
else pChunk->Resize(chunkSize); |
4173 |
|
// fill the chunk data to be written to disk |
4174 |
|
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
4175 |
|
int pos = 0; |
4176 |
|
store32(&pData[pos], 6*sizeof(int32_t) + Name.size()); // total header size |
4177 |
|
pos += sizeof(int32_t); |
4178 |
|
store32(&pData[pos], Compression); |
4179 |
|
pos += sizeof(int32_t); |
4180 |
|
store32(&pData[pos], Encoding); |
4181 |
|
pos += sizeof(int32_t); |
4182 |
|
store32(&pData[pos], Language); |
4183 |
|
pos += sizeof(int32_t); |
4184 |
|
store32(&pData[pos], Bypass ? 1 : 0); |
4185 |
|
pos += sizeof(int32_t); |
4186 |
|
store32(&pData[pos], crc); |
4187 |
|
pos += sizeof(int32_t); |
4188 |
|
store32(&pData[pos], Name.size()); |
4189 |
|
pos += sizeof(int32_t); |
4190 |
|
for (int i = 0; i < Name.size(); ++i, ++pos) |
4191 |
|
pData[pos] = Name[i]; |
4192 |
|
for (int i = 0; i < data.size(); ++i, ++pos) |
4193 |
|
pData[pos] = data[i]; |
4194 |
|
} |
4195 |
|
|
4196 |
|
/** |
4197 |
|
* Move this script from its current ScriptGroup to another ScriptGroup |
4198 |
|
* given by @a pGroup. |
4199 |
|
* |
4200 |
|
* @param pGroup - script's new group |
4201 |
|
*/ |
4202 |
|
void Script::SetGroup(ScriptGroup* pGroup) { |
4203 |
|
if (this->pGroup == pGroup) return; |
4204 |
|
if (pChunk) |
4205 |
|
pChunk->GetParent()->MoveSubChunk(pChunk, pGroup->pList); |
4206 |
|
this->pGroup = pGroup; |
4207 |
|
} |
4208 |
|
|
4209 |
|
/** |
4210 |
|
* Returns the script group this script currently belongs to. Each script |
4211 |
|
* is a member of exactly one ScriptGroup. |
4212 |
|
* |
4213 |
|
* @returns current script group |
4214 |
|
*/ |
4215 |
|
ScriptGroup* Script::GetGroup() const { |
4216 |
|
return pGroup; |
4217 |
|
} |
4218 |
|
|
4219 |
|
void Script::RemoveAllScriptReferences() { |
4220 |
|
File* pFile = pGroup->pFile; |
4221 |
|
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4222 |
|
Instrument* instr = pFile->GetInstrument(i); |
4223 |
|
instr->RemoveScript(this); |
4224 |
|
} |
4225 |
|
} |
4226 |
|
|
4227 |
|
// *************** ScriptGroup *************** |
4228 |
|
// * |
4229 |
|
|
4230 |
|
ScriptGroup::ScriptGroup(File* file, RIFF::List* lstRTIS) { |
4231 |
|
pFile = file; |
4232 |
|
pList = lstRTIS; |
4233 |
|
pScripts = NULL; |
4234 |
|
if (lstRTIS) { |
4235 |
|
RIFF::Chunk* ckName = lstRTIS->GetSubChunk(CHUNK_ID_LSNM); |
4236 |
|
::LoadString(ckName, Name); |
4237 |
|
} else { |
4238 |
|
Name = "Default Group"; |
4239 |
|
} |
4240 |
|
} |
4241 |
|
|
4242 |
|
ScriptGroup::~ScriptGroup() { |
4243 |
|
if (pScripts) { |
4244 |
|
std::list<Script*>::iterator iter = pScripts->begin(); |
4245 |
|
std::list<Script*>::iterator end = pScripts->end(); |
4246 |
|
while (iter != end) { |
4247 |
|
delete *iter; |
4248 |
|
++iter; |
4249 |
|
} |
4250 |
|
delete pScripts; |
4251 |
} |
} |
4252 |
|
} |
4253 |
|
|
4254 |
|
/** |
4255 |
|
* Apply this script group to the respective RIFF chunks. You have to call |
4256 |
|
* File::Save() to make changes persistent. |
4257 |
|
* |
4258 |
|
* Usually there is absolutely no need to call this method explicitly. |
4259 |
|
* It will be called automatically when File::Save() was called. |
4260 |
|
* |
4261 |
|
* @param pProgress - callback function for progress notification |
4262 |
|
*/ |
4263 |
|
void ScriptGroup::UpdateChunks(progress_t* pProgress) { |
4264 |
|
if (pScripts) { |
4265 |
|
if (!pList) |
4266 |
|
pList = pFile->pRIFF->GetSubList(LIST_TYPE_3LS)->AddSubList(LIST_TYPE_RTIS); |
4267 |
|
|
4268 |
|
// now store the name of this group as <LSNM> chunk as subchunk of the <RTIS> list chunk |
4269 |
|
::SaveString(CHUNK_ID_LSNM, NULL, pList, Name, String("Unnamed Group"), true, 64); |
4270 |
|
|
4271 |
|
for (std::list<Script*>::iterator it = pScripts->begin(); |
4272 |
|
it != pScripts->end(); ++it) |
4273 |
|
{ |
4274 |
|
(*it)->UpdateChunks(pProgress); |
4275 |
|
} |
4276 |
|
} |
4277 |
|
} |
4278 |
|
|
4279 |
|
/** @brief Get instrument script. |
4280 |
|
* |
4281 |
|
* Returns the real-time instrument script with the given index. |
4282 |
|
* |
4283 |
|
* @param index - number of the sought script (0..n) |
4284 |
|
* @returns sought script or NULL if there's no such script |
4285 |
|
*/ |
4286 |
|
Script* ScriptGroup::GetScript(uint index) { |
4287 |
|
if (!pScripts) LoadScripts(); |
4288 |
|
std::list<Script*>::iterator it = pScripts->begin(); |
4289 |
|
for (uint i = 0; it != pScripts->end(); ++i, ++it) |
4290 |
|
if (i == index) return *it; |
4291 |
return NULL; |
return NULL; |
4292 |
} |
} |
4293 |
|
|
4294 |
|
/** @brief Add new instrument script. |
4295 |
|
* |
4296 |
|
* Adds a new real-time instrument script to the file. The script is not |
4297 |
|
* actually used / executed unless it is referenced by an instrument to be |
4298 |
|
* used. This is similar to samples, which you can add to a file, without |
4299 |
|
* an instrument necessarily actually using it. |
4300 |
|
* |
4301 |
|
* You have to call Save() to make this persistent to the file. |
4302 |
|
* |
4303 |
|
* @return new empty script object |
4304 |
|
*/ |
4305 |
|
Script* ScriptGroup::AddScript() { |
4306 |
|
if (!pScripts) LoadScripts(); |
4307 |
|
Script* pScript = new Script(this, NULL); |
4308 |
|
pScripts->push_back(pScript); |
4309 |
|
return pScript; |
4310 |
|
} |
4311 |
|
|
4312 |
|
/** @brief Delete an instrument script. |
4313 |
|
* |
4314 |
|
* This will delete the given real-time instrument script. References of |
4315 |
|
* instruments that are using that script will be removed accordingly. |
4316 |
|
* |
4317 |
|
* You have to call Save() to make this persistent to the file. |
4318 |
|
* |
4319 |
|
* @param pScript - script to delete |
4320 |
|
* @throws gig::Exception if given script could not be found |
4321 |
|
*/ |
4322 |
|
void ScriptGroup::DeleteScript(Script* pScript) { |
4323 |
|
if (!pScripts) LoadScripts(); |
4324 |
|
std::list<Script*>::iterator iter = |
4325 |
|
find(pScripts->begin(), pScripts->end(), pScript); |
4326 |
|
if (iter == pScripts->end()) |
4327 |
|
throw gig::Exception("Could not delete script, could not find given script"); |
4328 |
|
pScripts->erase(iter); |
4329 |
|
pScript->RemoveAllScriptReferences(); |
4330 |
|
if (pScript->pChunk) |
4331 |
|
pScript->pChunk->GetParent()->DeleteSubChunk(pScript->pChunk); |
4332 |
|
delete pScript; |
4333 |
|
} |
4334 |
|
|
4335 |
|
void ScriptGroup::LoadScripts() { |
4336 |
|
if (pScripts) return; |
4337 |
|
pScripts = new std::list<Script*>; |
4338 |
|
if (!pList) return; |
4339 |
|
|
4340 |
|
for (RIFF::Chunk* ck = pList->GetFirstSubChunk(); ck; |
4341 |
|
ck = pList->GetNextSubChunk()) |
4342 |
|
{ |
4343 |
|
if (ck->GetChunkID() == CHUNK_ID_SCRI) { |
4344 |
|
pScripts->push_back(new Script(this, ck)); |
4345 |
|
} |
4346 |
|
} |
4347 |
|
} |
4348 |
|
|
4349 |
// *************** Instrument *************** |
// *************** Instrument *************** |
4350 |
// * |
// * |
4351 |
|
|
4352 |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
4353 |
pInfo->UseFixedLengthStrings = true; |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
4354 |
|
{ CHUNK_ID_INAM, 64 }, |
4355 |
|
{ CHUNK_ID_ISFT, 12 }, |
4356 |
|
{ 0, 0 } |
4357 |
|
}; |
4358 |
|
pInfo->SetFixedStringLengths(fixedStringLengths); |
4359 |
|
|
4360 |
// Initialization |
// Initialization |
4361 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
4362 |
|
EffectSend = 0; |
4363 |
|
Attenuation = 0; |
4364 |
|
FineTune = 0; |
4365 |
|
PitchbendRange = 0; |
4366 |
|
PianoReleaseMode = false; |
4367 |
|
DimensionKeyRange.low = 0; |
4368 |
|
DimensionKeyRange.high = 0; |
4369 |
|
pMidiRules = new MidiRule*[3]; |
4370 |
|
pMidiRules[0] = NULL; |
4371 |
|
pScriptRefs = NULL; |
4372 |
|
|
4373 |
// Loading |
// Loading |
4374 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
4383 |
PianoReleaseMode = dimkeystart & 0x01; |
PianoReleaseMode = dimkeystart & 0x01; |
4384 |
DimensionKeyRange.low = dimkeystart >> 1; |
DimensionKeyRange.low = dimkeystart >> 1; |
4385 |
DimensionKeyRange.high = _3ewg->ReadUint8(); |
DimensionKeyRange.high = _3ewg->ReadUint8(); |
4386 |
|
|
4387 |
|
if (_3ewg->GetSize() > 32) { |
4388 |
|
// read MIDI rules |
4389 |
|
int i = 0; |
4390 |
|
_3ewg->SetPos(32); |
4391 |
|
uint8_t id1 = _3ewg->ReadUint8(); |
4392 |
|
uint8_t id2 = _3ewg->ReadUint8(); |
4393 |
|
|
4394 |
|
if (id2 == 16) { |
4395 |
|
if (id1 == 4) { |
4396 |
|
pMidiRules[i++] = new MidiRuleCtrlTrigger(_3ewg); |
4397 |
|
} else if (id1 == 0) { |
4398 |
|
pMidiRules[i++] = new MidiRuleLegato(_3ewg); |
4399 |
|
} else if (id1 == 3) { |
4400 |
|
pMidiRules[i++] = new MidiRuleAlternator(_3ewg); |
4401 |
|
} else { |
4402 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
4403 |
|
} |
4404 |
|
} |
4405 |
|
else if (id1 != 0 || id2 != 0) { |
4406 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
4407 |
|
} |
4408 |
|
//TODO: all the other types of rules |
4409 |
|
|
4410 |
|
pMidiRules[i] = NULL; |
4411 |
|
} |
4412 |
} |
} |
4413 |
} |
} |
4414 |
|
|
4415 |
if (!pRegions) pRegions = new RegionList; |
if (pFile->GetAutoLoad()) { |
4416 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
if (!pRegions) pRegions = new RegionList; |
4417 |
if (lrgn) { |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
4418 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
if (lrgn) { |
4419 |
while (rgn) { |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
4420 |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
while (rgn) { |
4421 |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
4422 |
pRegions->push_back(new Region(this, rgn)); |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
4423 |
|
pRegions->push_back(new Region(this, rgn)); |
4424 |
|
} |
4425 |
|
rgn = lrgn->GetNextSubList(); |
4426 |
|
} |
4427 |
|
// Creating Region Key Table for fast lookup |
4428 |
|
UpdateRegionKeyTable(); |
4429 |
|
} |
4430 |
|
} |
4431 |
|
|
4432 |
|
// own gig format extensions |
4433 |
|
RIFF::List* lst3LS = insList->GetSubList(LIST_TYPE_3LS); |
4434 |
|
if (lst3LS) { |
4435 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4436 |
|
if (ckSCSL) { |
4437 |
|
int headerSize = ckSCSL->ReadUint32(); |
4438 |
|
int slotCount = ckSCSL->ReadUint32(); |
4439 |
|
if (slotCount) { |
4440 |
|
int slotSize = ckSCSL->ReadUint32(); |
4441 |
|
ckSCSL->SetPos(headerSize); // in case of future header extensions |
4442 |
|
int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future slot extensions |
4443 |
|
for (int i = 0; i < slotCount; ++i) { |
4444 |
|
_ScriptPooolEntry e; |
4445 |
|
e.fileOffset = ckSCSL->ReadUint32(); |
4446 |
|
e.bypass = ckSCSL->ReadUint32() & 1; |
4447 |
|
if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions |
4448 |
|
scriptPoolFileOffsets.push_back(e); |
4449 |
|
} |
4450 |
} |
} |
|
rgn = lrgn->GetNextSubList(); |
|
4451 |
} |
} |
|
// Creating Region Key Table for fast lookup |
|
|
UpdateRegionKeyTable(); |
|
4452 |
} |
} |
4453 |
|
|
4454 |
__notify_progress(pProgress, 1.0f); // notify done |
__notify_progress(pProgress, 1.0f); // notify done |
4455 |
} |
} |
4456 |
|
|
4457 |
void Instrument::UpdateRegionKeyTable() { |
void Instrument::UpdateRegionKeyTable() { |
4458 |
|
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
4459 |
RegionList::iterator iter = pRegions->begin(); |
RegionList::iterator iter = pRegions->begin(); |
4460 |
RegionList::iterator end = pRegions->end(); |
RegionList::iterator end = pRegions->end(); |
4461 |
for (; iter != end; ++iter) { |
for (; iter != end; ++iter) { |
4467 |
} |
} |
4468 |
|
|
4469 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
4470 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
4471 |
|
delete pMidiRules[i]; |
4472 |
|
} |
4473 |
|
delete[] pMidiRules; |
4474 |
|
if (pScriptRefs) delete pScriptRefs; |
4475 |
} |
} |
4476 |
|
|
4477 |
/** |
/** |
4481 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
4482 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
4483 |
* |
* |
4484 |
|
* @param pProgress - callback function for progress notification |
4485 |
* @throws gig::Exception if samples cannot be dereferenced |
* @throws gig::Exception if samples cannot be dereferenced |
4486 |
*/ |
*/ |
4487 |
void Instrument::UpdateChunks() { |
void Instrument::UpdateChunks(progress_t* pProgress) { |
4488 |
// first update base classes' chunks |
// first update base classes' chunks |
4489 |
DLS::Instrument::UpdateChunks(); |
DLS::Instrument::UpdateChunks(pProgress); |
4490 |
|
|
4491 |
// update Regions' chunks |
// update Regions' chunks |
4492 |
{ |
{ |
4493 |
RegionList::iterator iter = pRegions->begin(); |
RegionList::iterator iter = pRegions->begin(); |
4494 |
RegionList::iterator end = pRegions->end(); |
RegionList::iterator end = pRegions->end(); |
4495 |
for (; iter != end; ++iter) |
for (; iter != end; ++iter) |
4496 |
(*iter)->UpdateChunks(); |
(*iter)->UpdateChunks(pProgress); |
4497 |
} |
} |
4498 |
|
|
4499 |
// make sure 'lart' RIFF list chunk exists |
// make sure 'lart' RIFF list chunk exists |
4501 |
if (!lart) lart = pCkInstrument->AddSubList(LIST_TYPE_LART); |
if (!lart) lart = pCkInstrument->AddSubList(LIST_TYPE_LART); |
4502 |
// make sure '3ewg' RIFF chunk exists |
// make sure '3ewg' RIFF chunk exists |
4503 |
RIFF::Chunk* _3ewg = lart->GetSubChunk(CHUNK_ID_3EWG); |
RIFF::Chunk* _3ewg = lart->GetSubChunk(CHUNK_ID_3EWG); |
4504 |
if (!_3ewg) _3ewg = lart->AddSubChunk(CHUNK_ID_3EWG, 12); |
if (!_3ewg) { |
4505 |
|
File* pFile = (File*) GetParent(); |
4506 |
|
|
4507 |
|
// 3ewg is bigger in gig3, as it includes the iMIDI rules |
4508 |
|
int size = (pFile->pVersion && pFile->pVersion->major == 3) ? 16416 : 12; |
4509 |
|
_3ewg = lart->AddSubChunk(CHUNK_ID_3EWG, size); |
4510 |
|
memset(_3ewg->LoadChunkData(), 0, size); |
4511 |
|
} |
4512 |
// update '3ewg' RIFF chunk |
// update '3ewg' RIFF chunk |
4513 |
uint8_t* pData = (uint8_t*) _3ewg->LoadChunkData(); |
uint8_t* pData = (uint8_t*) _3ewg->LoadChunkData(); |
4514 |
memcpy(&pData[0], &EffectSend, 2); |
store16(&pData[0], EffectSend); |
4515 |
memcpy(&pData[2], &Attenuation, 4); |
store32(&pData[2], Attenuation); |
4516 |
memcpy(&pData[6], &FineTune, 2); |
store16(&pData[6], FineTune); |
4517 |
memcpy(&pData[8], &PitchbendRange, 2); |
store16(&pData[8], PitchbendRange); |
4518 |
const uint8_t dimkeystart = (PianoReleaseMode) ? 0x01 : 0x00 | |
const uint8_t dimkeystart = (PianoReleaseMode ? 0x01 : 0x00) | |
4519 |
DimensionKeyRange.low << 1; |
DimensionKeyRange.low << 1; |
4520 |
memcpy(&pData[10], &dimkeystart, 1); |
pData[10] = dimkeystart; |
4521 |
memcpy(&pData[11], &DimensionKeyRange.high, 1); |
pData[11] = DimensionKeyRange.high; |
4522 |
|
|
4523 |
|
if (pMidiRules[0] == 0 && _3ewg->GetSize() >= 34) { |
4524 |
|
pData[32] = 0; |
4525 |
|
pData[33] = 0; |
4526 |
|
} else { |
4527 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
4528 |
|
pMidiRules[i]->UpdateChunks(pData); |
4529 |
|
} |
4530 |
|
} |
4531 |
|
|
4532 |
|
// own gig format extensions |
4533 |
|
if (ScriptSlotCount()) { |
4534 |
|
// make sure we have converted the original loaded script file |
4535 |
|
// offsets into valid Script object pointers |
4536 |
|
LoadScripts(); |
4537 |
|
|
4538 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4539 |
|
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
4540 |
|
const int slotCount = pScriptRefs->size(); |
4541 |
|
const int headerSize = 3 * sizeof(uint32_t); |
4542 |
|
const int slotSize = 2 * sizeof(uint32_t); |
4543 |
|
const int totalChunkSize = headerSize + slotCount * slotSize; |
4544 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4545 |
|
if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalChunkSize); |
4546 |
|
else ckSCSL->Resize(totalChunkSize); |
4547 |
|
uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData(); |
4548 |
|
int pos = 0; |
4549 |
|
store32(&pData[pos], headerSize); |
4550 |
|
pos += sizeof(uint32_t); |
4551 |
|
store32(&pData[pos], slotCount); |
4552 |
|
pos += sizeof(uint32_t); |
4553 |
|
store32(&pData[pos], slotSize); |
4554 |
|
pos += sizeof(uint32_t); |
4555 |
|
for (int i = 0; i < slotCount; ++i) { |
4556 |
|
// arbitrary value, the actual file offset will be updated in |
4557 |
|
// UpdateScriptFileOffsets() after the file has been resized |
4558 |
|
int bogusFileOffset = 0; |
4559 |
|
store32(&pData[pos], bogusFileOffset); |
4560 |
|
pos += sizeof(uint32_t); |
4561 |
|
store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0); |
4562 |
|
pos += sizeof(uint32_t); |
4563 |
|
} |
4564 |
|
} else { |
4565 |
|
// no script slots, so get rid of any LS custom RIFF chunks (if any) |
4566 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4567 |
|
if (lst3LS) pCkInstrument->DeleteSubChunk(lst3LS); |
4568 |
|
} |
4569 |
|
} |
4570 |
|
|
4571 |
|
void Instrument::UpdateScriptFileOffsets() { |
4572 |
|
// own gig format extensions |
4573 |
|
if (pScriptRefs && pScriptRefs->size() > 0) { |
4574 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4575 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4576 |
|
const int slotCount = pScriptRefs->size(); |
4577 |
|
const int headerSize = 3 * sizeof(uint32_t); |
4578 |
|
ckSCSL->SetPos(headerSize); |
4579 |
|
for (int i = 0; i < slotCount; ++i) { |
4580 |
|
uint32_t fileOffset = |
4581 |
|
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4582 |
|
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4583 |
|
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()); |
4584 |
|
ckSCSL->WriteUint32(&fileOffset); |
4585 |
|
// jump over flags entry (containing the bypass flag) |
4586 |
|
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
4587 |
|
} |
4588 |
|
} |
4589 |
} |
} |
4590 |
|
|
4591 |
/** |
/** |
4596 |
* there is no Region defined for the given \a Key |
* there is no Region defined for the given \a Key |
4597 |
*/ |
*/ |
4598 |
Region* Instrument::GetRegion(unsigned int Key) { |
Region* Instrument::GetRegion(unsigned int Key) { |
4599 |
if (!pRegions || !pRegions->size() || Key > 127) return NULL; |
if (!pRegions || pRegions->empty() || Key > 127) return NULL; |
4600 |
return RegionKeyTable[Key]; |
return RegionKeyTable[Key]; |
4601 |
|
|
4602 |
/*for (int i = 0; i < Regions; i++) { |
/*for (int i = 0; i < Regions; i++) { |
4654 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
4655 |
} |
} |
4656 |
|
|
4657 |
|
/** |
4658 |
|
* Move this instrument at the position before @arg dst. |
4659 |
|
* |
4660 |
|
* This method can be used to reorder the sequence of instruments in a |
4661 |
|
* .gig file. This might be helpful especially on large .gig files which |
4662 |
|
* contain a large number of instruments within the same .gig file. So |
4663 |
|
* grouping such instruments to similar ones, can help to keep track of them |
4664 |
|
* when working with such complex .gig files. |
4665 |
|
* |
4666 |
|
* When calling this method, this instrument will be removed from in its |
4667 |
|
* current position in the instruments list and moved to the requested |
4668 |
|
* target position provided by @param dst. You may also pass NULL as |
4669 |
|
* argument to this method, in that case this intrument will be moved to the |
4670 |
|
* very end of the .gig file's instrument list. |
4671 |
|
* |
4672 |
|
* You have to call Save() to make the order change persistent to the .gig |
4673 |
|
* file. |
4674 |
|
* |
4675 |
|
* Currently this method is limited to moving the instrument within the same |
4676 |
|
* .gig file. Trying to move it to another .gig file by calling this method |
4677 |
|
* will throw an exception. |
4678 |
|
* |
4679 |
|
* @param dst - destination instrument at which this instrument will be |
4680 |
|
* moved to, or pass NULL for moving to end of list |
4681 |
|
* @throw gig::Exception if this instrument and target instrument are not |
4682 |
|
* part of the same file |
4683 |
|
*/ |
4684 |
|
void Instrument::MoveTo(Instrument* dst) { |
4685 |
|
if (dst && GetParent() != dst->GetParent()) |
4686 |
|
throw Exception( |
4687 |
|
"gig::Instrument::MoveTo() can only be used for moving within " |
4688 |
|
"the same gig file." |
4689 |
|
); |
4690 |
|
|
4691 |
|
File* pFile = (File*) GetParent(); |
4692 |
|
|
4693 |
|
// move this instrument within the instrument list |
4694 |
|
{ |
4695 |
|
File::InstrumentList& list = *pFile->pInstruments; |
4696 |
|
|
4697 |
|
File::InstrumentList::iterator itFrom = |
4698 |
|
std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(this)); |
4699 |
|
|
4700 |
|
File::InstrumentList::iterator itTo = |
4701 |
|
std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(dst)); |
4702 |
|
|
4703 |
|
list.splice(itTo, list, itFrom); |
4704 |
|
} |
4705 |
|
|
4706 |
|
// move the instrument's actual list RIFF chunk appropriately |
4707 |
|
RIFF::List* lstCkInstruments = pFile->pRIFF->GetSubList(LIST_TYPE_LINS); |
4708 |
|
lstCkInstruments->MoveSubChunk( |
4709 |
|
this->pCkInstrument, |
4710 |
|
(RIFF::Chunk*) ((dst) ? dst->pCkInstrument : NULL) |
4711 |
|
); |
4712 |
|
} |
4713 |
|
|
4714 |
|
/** |
4715 |
|
* Returns a MIDI rule of the instrument. |
4716 |
|
* |
4717 |
|
* The list of MIDI rules, at least in gig v3, always contains at |
4718 |
|
* most two rules. The second rule can only be the DEF filter |
4719 |
|
* (which currently isn't supported by libgig). |
4720 |
|
* |
4721 |
|
* @param i - MIDI rule number |
4722 |
|
* @returns pointer address to MIDI rule number i or NULL if there is none |
4723 |
|
*/ |
4724 |
|
MidiRule* Instrument::GetMidiRule(int i) { |
4725 |
|
return pMidiRules[i]; |
4726 |
|
} |
4727 |
|
|
4728 |
|
/** |
4729 |
|
* Adds the "controller trigger" MIDI rule to the instrument. |
4730 |
|
* |
4731 |
|
* @returns the new MIDI rule |
4732 |
|
*/ |
4733 |
|
MidiRuleCtrlTrigger* Instrument::AddMidiRuleCtrlTrigger() { |
4734 |
|
delete pMidiRules[0]; |
4735 |
|
MidiRuleCtrlTrigger* r = new MidiRuleCtrlTrigger; |
4736 |
|
pMidiRules[0] = r; |
4737 |
|
pMidiRules[1] = 0; |
4738 |
|
return r; |
4739 |
|
} |
4740 |
|
|
4741 |
|
/** |
4742 |
|
* Adds the legato MIDI rule to the instrument. |
4743 |
|
* |
4744 |
|
* @returns the new MIDI rule |
4745 |
|
*/ |
4746 |
|
MidiRuleLegato* Instrument::AddMidiRuleLegato() { |
4747 |
|
delete pMidiRules[0]; |
4748 |
|
MidiRuleLegato* r = new MidiRuleLegato; |
4749 |
|
pMidiRules[0] = r; |
4750 |
|
pMidiRules[1] = 0; |
4751 |
|
return r; |
4752 |
|
} |
4753 |
|
|
4754 |
|
/** |
4755 |
|
* Adds the alternator MIDI rule to the instrument. |
4756 |
|
* |
4757 |
|
* @returns the new MIDI rule |
4758 |
|
*/ |
4759 |
|
MidiRuleAlternator* Instrument::AddMidiRuleAlternator() { |
4760 |
|
delete pMidiRules[0]; |
4761 |
|
MidiRuleAlternator* r = new MidiRuleAlternator; |
4762 |
|
pMidiRules[0] = r; |
4763 |
|
pMidiRules[1] = 0; |
4764 |
|
return r; |
4765 |
|
} |
4766 |
|
|
4767 |
|
/** |
4768 |
|
* Deletes a MIDI rule from the instrument. |
4769 |
|
* |
4770 |
|
* @param i - MIDI rule number |
4771 |
|
*/ |
4772 |
|
void Instrument::DeleteMidiRule(int i) { |
4773 |
|
delete pMidiRules[i]; |
4774 |
|
pMidiRules[i] = 0; |
4775 |
|
} |
4776 |
|
|
4777 |
|
void Instrument::LoadScripts() { |
4778 |
|
if (pScriptRefs) return; |
4779 |
|
pScriptRefs = new std::vector<_ScriptPooolRef>; |
4780 |
|
if (scriptPoolFileOffsets.empty()) return; |
4781 |
|
File* pFile = (File*) GetParent(); |
4782 |
|
for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) { |
4783 |
|
uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset; |
4784 |
|
for (uint i = 0; pFile->GetScriptGroup(i); ++i) { |
4785 |
|
ScriptGroup* group = pFile->GetScriptGroup(i); |
4786 |
|
for (uint s = 0; group->GetScript(s); ++s) { |
4787 |
|
Script* script = group->GetScript(s); |
4788 |
|
if (script->pChunk) { |
4789 |
|
uint32_t offset = script->pChunk->GetFilePos() - |
4790 |
|
script->pChunk->GetPos() - |
4791 |
|
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()); |
4792 |
|
if (offset == soughtOffset) |
4793 |
|
{ |
4794 |
|
_ScriptPooolRef ref; |
4795 |
|
ref.script = script; |
4796 |
|
ref.bypass = scriptPoolFileOffsets[k].bypass; |
4797 |
|
pScriptRefs->push_back(ref); |
4798 |
|
break; |
4799 |
|
} |
4800 |
|
} |
4801 |
|
} |
4802 |
|
} |
4803 |
|
} |
4804 |
|
// we don't need that anymore |
4805 |
|
scriptPoolFileOffsets.clear(); |
4806 |
|
} |
4807 |
|
|
4808 |
|
/** @brief Get instrument script (gig format extension). |
4809 |
|
* |
4810 |
|
* Returns the real-time instrument script of instrument script slot |
4811 |
|
* @a index. |
4812 |
|
* |
4813 |
|
* @note This is an own format extension which did not exist i.e. in the |
4814 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4815 |
|
* gigedit. |
4816 |
|
* |
4817 |
|
* @param index - instrument script slot index |
4818 |
|
* @returns script or NULL if index is out of bounds |
4819 |
|
*/ |
4820 |
|
Script* Instrument::GetScriptOfSlot(uint index) { |
4821 |
|
LoadScripts(); |
4822 |
|
if (index >= pScriptRefs->size()) return NULL; |
4823 |
|
return pScriptRefs->at(index).script; |
4824 |
|
} |
4825 |
|
|
4826 |
|
/** @brief Add new instrument script slot (gig format extension). |
4827 |
|
* |
4828 |
|
* Add the given real-time instrument script reference to this instrument, |
4829 |
|
* which shall be executed by the sampler for for this instrument. The |
4830 |
|
* script will be added to the end of the script list of this instrument. |
4831 |
|
* The positions of the scripts in the Instrument's Script list are |
4832 |
|
* relevant, because they define in which order they shall be executed by |
4833 |
|
* the sampler. For this reason it is also legal to add the same script |
4834 |
|
* twice to an instrument, for example you might have a script called |
4835 |
|
* "MyFilter" which performs an event filter task, and you might have |
4836 |
|
* another script called "MyNoteTrigger" which triggers new notes, then you |
4837 |
|
* might for example have the following list of scripts on the instrument: |
4838 |
|
* |
4839 |
|
* 1. Script "MyFilter" |
4840 |
|
* 2. Script "MyNoteTrigger" |
4841 |
|
* 3. Script "MyFilter" |
4842 |
|
* |
4843 |
|
* Which would make sense, because the 2nd script launched new events, which |
4844 |
|
* you might need to filter as well. |
4845 |
|
* |
4846 |
|
* There are two ways to disable / "bypass" scripts. You can either disable |
4847 |
|
* a script locally for the respective script slot on an instrument (i.e. by |
4848 |
|
* passing @c false to the 2nd argument of this method, or by calling |
4849 |
|
* SetScriptBypassed()). Or you can disable a script globally for all slots |
4850 |
|
* and all instruments by setting Script::Bypass. |
4851 |
|
* |
4852 |
|
* @note This is an own format extension which did not exist i.e. in the |
4853 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4854 |
|
* gigedit. |
4855 |
|
* |
4856 |
|
* @param pScript - script that shall be executed for this instrument |
4857 |
|
* @param bypass - if enabled, the sampler shall skip executing this |
4858 |
|
* script (in the respective list position) |
4859 |
|
* @see SetScriptBypassed() |
4860 |
|
*/ |
4861 |
|
void Instrument::AddScriptSlot(Script* pScript, bool bypass) { |
4862 |
|
LoadScripts(); |
4863 |
|
_ScriptPooolRef ref = { pScript, bypass }; |
4864 |
|
pScriptRefs->push_back(ref); |
4865 |
|
} |
4866 |
|
|
4867 |
|
/** @brief Flip two script slots with each other (gig format extension). |
4868 |
|
* |
4869 |
|
* Swaps the position of the two given scripts in the Instrument's Script |
4870 |
|
* list. The positions of the scripts in the Instrument's Script list are |
4871 |
|
* relevant, because they define in which order they shall be executed by |
4872 |
|
* the sampler. |
4873 |
|
* |
4874 |
|
* @note This is an own format extension which did not exist i.e. in the |
4875 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4876 |
|
* gigedit. |
4877 |
|
* |
4878 |
|
* @param index1 - index of the first script slot to swap |
4879 |
|
* @param index2 - index of the second script slot to swap |
4880 |
|
*/ |
4881 |
|
void Instrument::SwapScriptSlots(uint index1, uint index2) { |
4882 |
|
LoadScripts(); |
4883 |
|
if (index1 >= pScriptRefs->size() || index2 >= pScriptRefs->size()) |
4884 |
|
return; |
4885 |
|
_ScriptPooolRef tmp = (*pScriptRefs)[index1]; |
4886 |
|
(*pScriptRefs)[index1] = (*pScriptRefs)[index2]; |
4887 |
|
(*pScriptRefs)[index2] = tmp; |
4888 |
|
} |
4889 |
|
|
4890 |
|
/** @brief Remove script slot. |
4891 |
|
* |
4892 |
|
* Removes the script slot with the given slot index. |
4893 |
|
* |
4894 |
|
* @param index - index of script slot to remove |
4895 |
|
*/ |
4896 |
|
void Instrument::RemoveScriptSlot(uint index) { |
4897 |
|
LoadScripts(); |
4898 |
|
if (index >= pScriptRefs->size()) return; |
4899 |
|
pScriptRefs->erase( pScriptRefs->begin() + index ); |
4900 |
|
} |
4901 |
|
|
4902 |
|
/** @brief Remove reference to given Script (gig format extension). |
4903 |
|
* |
4904 |
|
* This will remove all script slots on the instrument which are referencing |
4905 |
|
* the given script. |
4906 |
|
* |
4907 |
|
* @note This is an own format extension which did not exist i.e. in the |
4908 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4909 |
|
* gigedit. |
4910 |
|
* |
4911 |
|
* @param pScript - script reference to remove from this instrument |
4912 |
|
* @see RemoveScriptSlot() |
4913 |
|
*/ |
4914 |
|
void Instrument::RemoveScript(Script* pScript) { |
4915 |
|
LoadScripts(); |
4916 |
|
for (int i = pScriptRefs->size() - 1; i >= 0; --i) { |
4917 |
|
if ((*pScriptRefs)[i].script == pScript) { |
4918 |
|
pScriptRefs->erase( pScriptRefs->begin() + i ); |
4919 |
|
} |
4920 |
|
} |
4921 |
|
} |
4922 |
|
|
4923 |
|
/** @brief Instrument's amount of script slots. |
4924 |
|
* |
4925 |
|
* This method returns the amount of script slots this instrument currently |
4926 |
|
* uses. |
4927 |
|
* |
4928 |
|
* A script slot is a reference of a real-time instrument script to be |
4929 |
|
* executed by the sampler. The scripts will be executed by the sampler in |
4930 |
|
* sequence of the slots. One (same) script may be referenced multiple |
4931 |
|
* times in different slots. |
4932 |
|
* |
4933 |
|
* @note This is an own format extension which did not exist i.e. in the |
4934 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4935 |
|
* gigedit. |
4936 |
|
*/ |
4937 |
|
uint Instrument::ScriptSlotCount() const { |
4938 |
|
return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size(); |
4939 |
|
} |
4940 |
|
|
4941 |
|
/** @brief Whether script execution shall be skipped. |
4942 |
|
* |
4943 |
|
* Defines locally for the Script reference slot in the Instrument's Script |
4944 |
|
* list, whether the script shall be skipped by the sampler regarding |
4945 |
|
* execution. |
4946 |
|
* |
4947 |
|
* It is also possible to ignore exeuction of the script globally, for all |
4948 |
|
* slots and for all instruments by setting Script::Bypass. |
4949 |
|
* |
4950 |
|
* @note This is an own format extension which did not exist i.e. in the |
4951 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4952 |
|
* gigedit. |
4953 |
|
* |
4954 |
|
* @param index - index of the script slot on this instrument |
4955 |
|
* @see Script::Bypass |
4956 |
|
*/ |
4957 |
|
bool Instrument::IsScriptSlotBypassed(uint index) { |
4958 |
|
if (index >= ScriptSlotCount()) return false; |
4959 |
|
return pScriptRefs ? pScriptRefs->at(index).bypass |
4960 |
|
: scriptPoolFileOffsets.at(index).bypass; |
4961 |
|
|
4962 |
|
} |
4963 |
|
|
4964 |
|
/** @brief Defines whether execution shall be skipped. |
4965 |
|
* |
4966 |
|
* You can call this method to define locally whether or whether not the |
4967 |
|
* given script slot shall be executed by the sampler. |
4968 |
|
* |
4969 |
|
* @note This is an own format extension which did not exist i.e. in the |
4970 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4971 |
|
* gigedit. |
4972 |
|
* |
4973 |
|
* @param index - script slot index on this instrument |
4974 |
|
* @param bBypass - if true, the script slot will be skipped by the sampler |
4975 |
|
* @see Script::Bypass |
4976 |
|
*/ |
4977 |
|
void Instrument::SetScriptSlotBypassed(uint index, bool bBypass) { |
4978 |
|
if (index >= ScriptSlotCount()) return; |
4979 |
|
if (pScriptRefs) |
4980 |
|
pScriptRefs->at(index).bypass = bBypass; |
4981 |
|
else |
4982 |
|
scriptPoolFileOffsets.at(index).bypass = bBypass; |
4983 |
|
} |
4984 |
|
|
4985 |
|
/** |
4986 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
4987 |
|
* and assign it to this object. |
4988 |
|
* |
4989 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
4990 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
4991 |
|
* |
4992 |
|
* @param orig - original Instrument object to be copied from |
4993 |
|
*/ |
4994 |
|
void Instrument::CopyAssign(const Instrument* orig) { |
4995 |
|
CopyAssign(orig, NULL); |
4996 |
|
} |
4997 |
|
|
4998 |
|
/** |
4999 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
5000 |
|
* and assign it to this object. |
5001 |
|
* |
5002 |
|
* @param orig - original Instrument object to be copied from |
5003 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
5004 |
|
* this file's samples |
5005 |
|
*/ |
5006 |
|
void Instrument::CopyAssign(const Instrument* orig, const std::map<Sample*,Sample*>* mSamples) { |
5007 |
|
// handle base class |
5008 |
|
// (without copying DLS region stuff) |
5009 |
|
DLS::Instrument::CopyAssignCore(orig); |
5010 |
|
|
5011 |
|
// handle own member variables |
5012 |
|
Attenuation = orig->Attenuation; |
5013 |
|
EffectSend = orig->EffectSend; |
5014 |
|
FineTune = orig->FineTune; |
5015 |
|
PitchbendRange = orig->PitchbendRange; |
5016 |
|
PianoReleaseMode = orig->PianoReleaseMode; |
5017 |
|
DimensionKeyRange = orig->DimensionKeyRange; |
5018 |
|
scriptPoolFileOffsets = orig->scriptPoolFileOffsets; |
5019 |
|
pScriptRefs = orig->pScriptRefs; |
5020 |
|
|
5021 |
|
// free old midi rules |
5022 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
5023 |
|
delete pMidiRules[i]; |
5024 |
|
} |
5025 |
|
//TODO: MIDI rule copying |
5026 |
|
pMidiRules[0] = NULL; |
5027 |
|
|
5028 |
|
// delete all old regions |
5029 |
|
while (Regions) DeleteRegion(GetFirstRegion()); |
5030 |
|
// create new regions and copy them from original |
5031 |
|
{ |
5032 |
|
RegionList::const_iterator it = orig->pRegions->begin(); |
5033 |
|
for (int i = 0; i < orig->Regions; ++i, ++it) { |
5034 |
|
Region* dstRgn = AddRegion(); |
5035 |
|
//NOTE: Region does semi-deep copy ! |
5036 |
|
dstRgn->CopyAssign( |
5037 |
|
static_cast<gig::Region*>(*it), |
5038 |
|
mSamples |
5039 |
|
); |
5040 |
|
} |
5041 |
|
} |
5042 |
|
|
5043 |
|
UpdateRegionKeyTable(); |
5044 |
|
} |
5045 |
|
|
5046 |
|
|
5047 |
// *************** Group *************** |
// *************** Group *************** |
5060 |
} |
} |
5061 |
|
|
5062 |
Group::~Group() { |
Group::~Group() { |
5063 |
|
// remove the chunk associated with this group (if any) |
5064 |
|
if (pNameChunk) pNameChunk->GetParent()->DeleteSubChunk(pNameChunk); |
5065 |
} |
} |
5066 |
|
|
5067 |
/** @brief Update chunks with current group settings. |
/** @brief Update chunks with current group settings. |
5068 |
* |
* |
5069 |
* Apply current Group field values to the respective. You have to call |
* Apply current Group field values to the respective chunks. You have |
5070 |
* File::Save() to make changes persistent. |
* to call File::Save() to make changes persistent. |
5071 |
|
* |
5072 |
|
* Usually there is absolutely no need to call this method explicitly. |
5073 |
|
* It will be called automatically when File::Save() was called. |
5074 |
|
* |
5075 |
|
* @param pProgress - callback function for progress notification |
5076 |
*/ |
*/ |
5077 |
void Group::UpdateChunks() { |
void Group::UpdateChunks(progress_t* pProgress) { |
5078 |
// make sure <3gri> and <3gnl> list chunks exist |
// make sure <3gri> and <3gnl> list chunks exist |
5079 |
RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); |
RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); |
5080 |
if (!_3gri) _3gri = pFile->pRIFF->AddSubList(LIST_TYPE_3GRI); |
if (!_3gri) { |
5081 |
|
_3gri = pFile->pRIFF->AddSubList(LIST_TYPE_3GRI); |
5082 |
|
pFile->pRIFF->MoveSubChunk(_3gri, pFile->pRIFF->GetSubChunk(CHUNK_ID_PTBL)); |
5083 |
|
} |
5084 |
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
5085 |
if (!_3gnl) _3gnl = pFile->pRIFF->AddSubList(LIST_TYPE_3GNL); |
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
5086 |
|
|
5087 |
|
if (!pNameChunk && pFile->pVersion && pFile->pVersion->major == 3) { |
5088 |
|
// v3 has a fixed list of 128 strings, find a free one |
5089 |
|
for (RIFF::Chunk* ck = _3gnl->GetFirstSubChunk() ; ck ; ck = _3gnl->GetNextSubChunk()) { |
5090 |
|
if (strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) { |
5091 |
|
pNameChunk = ck; |
5092 |
|
break; |
5093 |
|
} |
5094 |
|
} |
5095 |
|
} |
5096 |
|
|
5097 |
// now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk |
// now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk |
5098 |
::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); |
::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); |
5099 |
} |
} |
5169 |
// *************** File *************** |
// *************** File *************** |
5170 |
// * |
// * |
5171 |
|
|
5172 |
|
/// Reflects Gigasampler file format version 2.0 (1998-06-28). |
5173 |
|
const DLS::version_t File::VERSION_2 = { |
5174 |
|
0, 2, 19980628 & 0xffff, 19980628 >> 16 |
5175 |
|
}; |
5176 |
|
|
5177 |
|
/// Reflects Gigasampler file format version 3.0 (2003-03-31). |
5178 |
|
const DLS::version_t File::VERSION_3 = { |
5179 |
|
0, 3, 20030331 & 0xffff, 20030331 >> 16 |
5180 |
|
}; |
5181 |
|
|
5182 |
|
static const DLS::Info::string_length_t _FileFixedStringLengths[] = { |
5183 |
|
{ CHUNK_ID_IARL, 256 }, |
5184 |
|
{ CHUNK_ID_IART, 128 }, |
5185 |
|
{ CHUNK_ID_ICMS, 128 }, |
5186 |
|
{ CHUNK_ID_ICMT, 1024 }, |
5187 |
|
{ CHUNK_ID_ICOP, 128 }, |
5188 |
|
{ CHUNK_ID_ICRD, 128 }, |
5189 |
|
{ CHUNK_ID_IENG, 128 }, |
5190 |
|
{ CHUNK_ID_IGNR, 128 }, |
5191 |
|
{ CHUNK_ID_IKEY, 128 }, |
5192 |
|
{ CHUNK_ID_IMED, 128 }, |
5193 |
|
{ CHUNK_ID_INAM, 128 }, |
5194 |
|
{ CHUNK_ID_IPRD, 128 }, |
5195 |
|
{ CHUNK_ID_ISBJ, 128 }, |
5196 |
|
{ CHUNK_ID_ISFT, 128 }, |
5197 |
|
{ CHUNK_ID_ISRC, 128 }, |
5198 |
|
{ CHUNK_ID_ISRF, 128 }, |
5199 |
|
{ CHUNK_ID_ITCH, 128 }, |
5200 |
|
{ 0, 0 } |
5201 |
|
}; |
5202 |
|
|
5203 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
5204 |
|
bAutoLoad = true; |
5205 |
|
*pVersion = VERSION_3; |
5206 |
pGroups = NULL; |
pGroups = NULL; |
5207 |
pInfo->UseFixedLengthStrings = true; |
pScriptGroups = NULL; |
5208 |
|
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
5209 |
|
pInfo->ArchivalLocation = String(256, ' '); |
5210 |
|
|
5211 |
|
// add some mandatory chunks to get the file chunks in right |
5212 |
|
// order (INFO chunk will be moved to first position later) |
5213 |
|
pRIFF->AddSubChunk(CHUNK_ID_VERS, 8); |
5214 |
|
pRIFF->AddSubChunk(CHUNK_ID_COLH, 4); |
5215 |
|
pRIFF->AddSubChunk(CHUNK_ID_DLID, 16); |
5216 |
|
|
5217 |
|
GenerateDLSID(); |
5218 |
} |
} |
5219 |
|
|
5220 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
5221 |
|
bAutoLoad = true; |
5222 |
pGroups = NULL; |
pGroups = NULL; |
5223 |
pInfo->UseFixedLengthStrings = true; |
pScriptGroups = NULL; |
5224 |
|
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
5225 |
} |
} |
5226 |
|
|
5227 |
File::~File() { |
File::~File() { |
5234 |
} |
} |
5235 |
delete pGroups; |
delete pGroups; |
5236 |
} |
} |
5237 |
|
if (pScriptGroups) { |
5238 |
|
std::list<ScriptGroup*>::iterator iter = pScriptGroups->begin(); |
5239 |
|
std::list<ScriptGroup*>::iterator end = pScriptGroups->end(); |
5240 |
|
while (iter != end) { |
5241 |
|
delete *iter; |
5242 |
|
++iter; |
5243 |
|
} |
5244 |
|
delete pScriptGroups; |
5245 |
|
} |
5246 |
} |
} |
5247 |
|
|
5248 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
5257 |
SamplesIterator++; |
SamplesIterator++; |
5258 |
return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); |
return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); |
5259 |
} |
} |
5260 |
|
|
5261 |
|
/** |
5262 |
|
* Returns Sample object of @a index. |
5263 |
|
* |
5264 |
|
* @returns sample object or NULL if index is out of bounds |
5265 |
|
*/ |
5266 |
|
Sample* File::GetSample(uint index) { |
5267 |
|
if (!pSamples) LoadSamples(); |
5268 |
|
if (!pSamples) return NULL; |
5269 |
|
DLS::File::SampleList::iterator it = pSamples->begin(); |
5270 |
|
for (int i = 0; i < index; ++i) { |
5271 |
|
++it; |
5272 |
|
if (it == pSamples->end()) return NULL; |
5273 |
|
} |
5274 |
|
if (it == pSamples->end()) return NULL; |
5275 |
|
return static_cast<gig::Sample*>( *it ); |
5276 |
|
} |
5277 |
|
|
5278 |
/** @brief Add a new sample. |
/** @brief Add a new sample. |
5279 |
* |
* |
5289 |
// create new Sample object and its respective 'wave' list chunk |
// create new Sample object and its respective 'wave' list chunk |
5290 |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
5291 |
Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/); |
Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/); |
5292 |
|
|
5293 |
|
// add mandatory chunks to get the chunks in right order |
5294 |
|
wave->AddSubChunk(CHUNK_ID_FMT, 16); |
5295 |
|
wave->AddSubList(LIST_TYPE_INFO); |
5296 |
|
|
5297 |
pSamples->push_back(pSample); |
pSamples->push_back(pSample); |
5298 |
return pSample; |
return pSample; |
5299 |
} |
} |
5300 |
|
|
5301 |
/** @brief Delete a sample. |
/** @brief Delete a sample. |
5302 |
* |
* |
5303 |
* This will delete the given Sample object from the gig file. You have |
* This will delete the given Sample object from the gig file. Any |
5304 |
* to call Save() to make this persistent to the file. |
* references to this sample from Regions and DimensionRegions will be |
5305 |
|
* removed. You have to call Save() to make this persistent to the file. |
5306 |
* |
* |
5307 |
* @param pSample - sample to delete |
* @param pSample - sample to delete |
5308 |
* @throws gig::Exception if given sample could not be found |
* @throws gig::Exception if given sample could not be found |
5311 |
if (!pSamples || !pSamples->size()) throw gig::Exception("Could not delete sample as there are no samples"); |
if (!pSamples || !pSamples->size()) throw gig::Exception("Could not delete sample as there are no samples"); |
5312 |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample); |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample); |
5313 |
if (iter == pSamples->end()) throw gig::Exception("Could not delete sample, could not find given sample"); |
if (iter == pSamples->end()) throw gig::Exception("Could not delete sample, could not find given sample"); |
5314 |
|
if (SamplesIterator != pSamples->end() && *SamplesIterator == pSample) ++SamplesIterator; // avoid iterator invalidation |
5315 |
pSamples->erase(iter); |
pSamples->erase(iter); |
5316 |
delete pSample; |
delete pSample; |
5317 |
|
|
5318 |
|
SampleList::iterator tmp = SamplesIterator; |
5319 |
|
// remove all references to the sample |
5320 |
|
for (Instrument* instrument = GetFirstInstrument() ; instrument ; |
5321 |
|
instrument = GetNextInstrument()) { |
5322 |
|
for (Region* region = instrument->GetFirstRegion() ; region ; |
5323 |
|
region = instrument->GetNextRegion()) { |
5324 |
|
|
5325 |
|
if (region->GetSample() == pSample) region->SetSample(NULL); |
5326 |
|
|
5327 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
5328 |
|
gig::DimensionRegion *d = region->pDimensionRegions[i]; |
5329 |
|
if (d->pSample == pSample) d->pSample = NULL; |
5330 |
|
} |
5331 |
|
} |
5332 |
|
} |
5333 |
|
SamplesIterator = tmp; // restore iterator |
5334 |
} |
} |
5335 |
|
|
5336 |
void File::LoadSamples() { |
void File::LoadSamples() { |
5340 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
5341 |
// Groups must be loaded before samples, because samples will try |
// Groups must be loaded before samples, because samples will try |
5342 |
// to resolve the group they belong to |
// to resolve the group they belong to |
5343 |
LoadGroups(); |
if (!pGroups) LoadGroups(); |
5344 |
|
|
5345 |
if (!pSamples) pSamples = new SampleList; |
if (!pSamples) pSamples = new SampleList; |
5346 |
|
|
5351 |
int iTotalSamples = WavePoolCount; |
int iTotalSamples = WavePoolCount; |
5352 |
|
|
5353 |
// check if samples should be loaded from extension files |
// check if samples should be loaded from extension files |
5354 |
|
// (only for old gig files < 2 GB) |
5355 |
int lastFileNo = 0; |
int lastFileNo = 0; |
5356 |
for (int i = 0 ; i < WavePoolCount ; i++) { |
if (!file->IsNew() && !(file->GetCurrentFileSize() >> 31)) { |
5357 |
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
for (int i = 0 ; i < WavePoolCount ; i++) { |
5358 |
|
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
5359 |
|
} |
5360 |
} |
} |
5361 |
String name(pRIFF->GetFileName()); |
String name(pRIFF->GetFileName()); |
5362 |
int nameLen = name.length(); |
int nameLen = name.length(); |
5366 |
for (int fileNo = 0 ; ; ) { |
for (int fileNo = 0 ; ; ) { |
5367 |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
5368 |
if (wvpl) { |
if (wvpl) { |
5369 |
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
file_offset_t wvplFileOffset = wvpl->GetFilePos(); |
5370 |
RIFF::List* wave = wvpl->GetFirstSubList(); |
RIFF::List* wave = wvpl->GetFirstSubList(); |
5371 |
while (wave) { |
while (wave) { |
5372 |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
5374 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
5375 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
5376 |
|
|
5377 |
unsigned long waveFileOffset = wave->GetFilePos(); |
file_offset_t waveFileOffset = wave->GetFilePos(); |
5378 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
5379 |
|
|
5380 |
iSampleIndex++; |
iSampleIndex++; |
5424 |
progress_t subprogress; |
progress_t subprogress; |
5425 |
__divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask |
__divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask |
5426 |
__notify_progress(&subprogress, 0.0f); |
__notify_progress(&subprogress, 0.0f); |
5427 |
GetFirstSample(&subprogress); // now force all samples to be loaded |
if (GetAutoLoad()) |
5428 |
|
GetFirstSample(&subprogress); // now force all samples to be loaded |
5429 |
__notify_progress(&subprogress, 1.0f); |
__notify_progress(&subprogress, 1.0f); |
5430 |
|
|
5431 |
// instrument loading subtask |
// instrument loading subtask |
5458 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
5459 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
5460 |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
5461 |
|
|
5462 |
|
// add mandatory chunks to get the chunks in right order |
5463 |
|
lstInstr->AddSubList(LIST_TYPE_INFO); |
5464 |
|
lstInstr->AddSubChunk(CHUNK_ID_DLID, 16); |
5465 |
|
|
5466 |
Instrument* pInstrument = new Instrument(this, lstInstr); |
Instrument* pInstrument = new Instrument(this, lstInstr); |
5467 |
|
pInstrument->GenerateDLSID(); |
5468 |
|
|
5469 |
|
lstInstr->AddSubChunk(CHUNK_ID_INSH, 12); |
5470 |
|
|
5471 |
|
// this string is needed for the gig to be loadable in GSt: |
5472 |
|
pInstrument->pInfo->Software = "Endless Wave"; |
5473 |
|
|
5474 |
pInstruments->push_back(pInstrument); |
pInstruments->push_back(pInstrument); |
5475 |
return pInstrument; |
return pInstrument; |
5476 |
} |
} |
5477 |
|
|
5478 |
|
/** @brief Add a duplicate of an existing instrument. |
5479 |
|
* |
5480 |
|
* Duplicates the instrument definition given by @a orig and adds it |
5481 |
|
* to this file. This allows in an instrument editor application to |
5482 |
|
* easily create variations of an instrument, which will be stored in |
5483 |
|
* the same .gig file, sharing i.e. the same samples. |
5484 |
|
* |
5485 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
5486 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
5487 |
|
* |
5488 |
|
* You have to call Save() to make this persistent to the file. |
5489 |
|
* |
5490 |
|
* @param orig - original instrument to be copied |
5491 |
|
* @returns duplicated copy of the given instrument |
5492 |
|
*/ |
5493 |
|
Instrument* File::AddDuplicateInstrument(const Instrument* orig) { |
5494 |
|
Instrument* instr = AddInstrument(); |
5495 |
|
instr->CopyAssign(orig); |
5496 |
|
return instr; |
5497 |
|
} |
5498 |
|
|
5499 |
|
/** @brief Add content of another existing file. |
5500 |
|
* |
5501 |
|
* Duplicates the samples, groups and instruments of the original file |
5502 |
|
* given by @a pFile and adds them to @c this File. In case @c this File is |
5503 |
|
* a new one that you haven't saved before, then you have to call |
5504 |
|
* SetFileName() before calling AddContentOf(), because this method will |
5505 |
|
* automatically save this file during operation, which is required for |
5506 |
|
* writing the sample waveform data by disk streaming. |
5507 |
|
* |
5508 |
|
* @param pFile - original file whose's content shall be copied from |
5509 |
|
*/ |
5510 |
|
void File::AddContentOf(File* pFile) { |
5511 |
|
static int iCallCount = -1; |
5512 |
|
iCallCount++; |
5513 |
|
std::map<Group*,Group*> mGroups; |
5514 |
|
std::map<Sample*,Sample*> mSamples; |
5515 |
|
|
5516 |
|
// clone sample groups |
5517 |
|
for (int i = 0; pFile->GetGroup(i); ++i) { |
5518 |
|
Group* g = AddGroup(); |
5519 |
|
g->Name = |
5520 |
|
"COPY" + ToString(iCallCount) + "_" + pFile->GetGroup(i)->Name; |
5521 |
|
mGroups[pFile->GetGroup(i)] = g; |
5522 |
|
} |
5523 |
|
|
5524 |
|
// clone samples (not waveform data here yet) |
5525 |
|
for (int i = 0; pFile->GetSample(i); ++i) { |
5526 |
|
Sample* s = AddSample(); |
5527 |
|
s->CopyAssignMeta(pFile->GetSample(i)); |
5528 |
|
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
5529 |
|
mSamples[pFile->GetSample(i)] = s; |
5530 |
|
} |
5531 |
|
|
5532 |
|
//BUG: For some reason this method only works with this additional |
5533 |
|
// Save() call in between here. |
5534 |
|
// |
5535 |
|
// Important: The correct one of the 2 Save() methods has to be called |
5536 |
|
// here, depending on whether the file is completely new or has been |
5537 |
|
// saved to disk already, otherwise it will result in data corruption. |
5538 |
|
if (pRIFF->IsNew()) |
5539 |
|
Save(GetFileName()); |
5540 |
|
else |
5541 |
|
Save(); |
5542 |
|
|
5543 |
|
// clone instruments |
5544 |
|
// (passing the crosslink table here for the cloned samples) |
5545 |
|
for (int i = 0; pFile->GetInstrument(i); ++i) { |
5546 |
|
Instrument* instr = AddInstrument(); |
5547 |
|
instr->CopyAssign(pFile->GetInstrument(i), &mSamples); |
5548 |
|
} |
5549 |
|
|
5550 |
|
// Mandatory: file needs to be saved to disk at this point, so this |
5551 |
|
// file has the correct size and data layout for writing the samples' |
5552 |
|
// waveform data to disk. |
5553 |
|
Save(); |
5554 |
|
|
5555 |
|
// clone samples' waveform data |
5556 |
|
// (using direct read & write disk streaming) |
5557 |
|
for (int i = 0; pFile->GetSample(i); ++i) { |
5558 |
|
mSamples[pFile->GetSample(i)]->CopyAssignWave(pFile->GetSample(i)); |
5559 |
|
} |
5560 |
|
} |
5561 |
|
|
5562 |
/** @brief Delete an instrument. |
/** @brief Delete an instrument. |
5563 |
* |
* |
5565 |
* have to call Save() to make this persistent to the file. |
* have to call Save() to make this persistent to the file. |
5566 |
* |
* |
5567 |
* @param pInstrument - instrument to delete |
* @param pInstrument - instrument to delete |
5568 |
* @throws gig::Excption if given instrument could not be found |
* @throws gig::Exception if given instrument could not be found |
5569 |
*/ |
*/ |
5570 |
void File::DeleteInstrument(Instrument* pInstrument) { |
void File::DeleteInstrument(Instrument* pInstrument) { |
5571 |
if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments"); |
if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments"); |
5605 |
} |
} |
5606 |
} |
} |
5607 |
|
|
5608 |
|
/// Updates the 3crc chunk with the checksum of a sample. The |
5609 |
|
/// update is done directly to disk, as this method is called |
5610 |
|
/// after File::Save() |
5611 |
|
void File::SetSampleChecksum(Sample* pSample, uint32_t crc) { |
5612 |
|
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
5613 |
|
if (!_3crc) return; |
5614 |
|
|
5615 |
|
// get the index of the sample |
5616 |
|
int iWaveIndex = -1; |
5617 |
|
File::SampleList::iterator iter = pSamples->begin(); |
5618 |
|
File::SampleList::iterator end = pSamples->end(); |
5619 |
|
for (int index = 0; iter != end; ++iter, ++index) { |
5620 |
|
if (*iter == pSample) { |
5621 |
|
iWaveIndex = index; |
5622 |
|
break; |
5623 |
|
} |
5624 |
|
} |
5625 |
|
if (iWaveIndex < 0) throw gig::Exception("Could not update crc, could not find sample"); |
5626 |
|
|
5627 |
|
// write the CRC-32 checksum to disk |
5628 |
|
_3crc->SetPos(iWaveIndex * 8); |
5629 |
|
uint32_t tmp = 1; |
5630 |
|
_3crc->WriteUint32(&tmp); // unknown, always 1? |
5631 |
|
_3crc->WriteUint32(&crc); |
5632 |
|
} |
5633 |
|
|
5634 |
Group* File::GetFirstGroup() { |
Group* File::GetFirstGroup() { |
5635 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
5636 |
// there must always be at least one group |
// there must always be at least one group |
5660 |
return NULL; |
return NULL; |
5661 |
} |
} |
5662 |
|
|
5663 |
|
/** |
5664 |
|
* Returns the group with the given group name. |
5665 |
|
* |
5666 |
|
* Note: group names don't have to be unique in the gig format! So there |
5667 |
|
* can be multiple groups with the same name. This method will simply |
5668 |
|
* return the first group found with the given name. |
5669 |
|
* |
5670 |
|
* @param name - name of the sought group |
5671 |
|
* @returns sought group or NULL if there's no group with that name |
5672 |
|
*/ |
5673 |
|
Group* File::GetGroup(String name) { |
5674 |
|
if (!pGroups) LoadGroups(); |
5675 |
|
GroupsIterator = pGroups->begin(); |
5676 |
|
for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i) |
5677 |
|
if ((*GroupsIterator)->Name == name) return *GroupsIterator; |
5678 |
|
return NULL; |
5679 |
|
} |
5680 |
|
|
5681 |
Group* File::AddGroup() { |
Group* File::AddGroup() { |
5682 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
5683 |
// there must always be at least one group |
// there must always be at least one group |
5687 |
return pGroup; |
return pGroup; |
5688 |
} |
} |
5689 |
|
|
5690 |
|
/** @brief Delete a group and its samples. |
5691 |
|
* |
5692 |
|
* This will delete the given Group object and all the samples that |
5693 |
|
* belong to this group from the gig file. You have to call Save() to |
5694 |
|
* make this persistent to the file. |
5695 |
|
* |
5696 |
|
* @param pGroup - group to delete |
5697 |
|
* @throws gig::Exception if given group could not be found |
5698 |
|
*/ |
5699 |
void File::DeleteGroup(Group* pGroup) { |
void File::DeleteGroup(Group* pGroup) { |
5700 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
5701 |
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
5702 |
if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); |
if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); |
5703 |
if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); |
if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); |
5704 |
|
// delete all members of this group |
5705 |
|
for (Sample* pSample = pGroup->GetFirstSample(); pSample; pSample = pGroup->GetNextSample()) { |
5706 |
|
DeleteSample(pSample); |
5707 |
|
} |
5708 |
|
// now delete this group object |
5709 |
|
pGroups->erase(iter); |
5710 |
|
delete pGroup; |
5711 |
|
} |
5712 |
|
|
5713 |
|
/** @brief Delete a group. |
5714 |
|
* |
5715 |
|
* This will delete the given Group object from the gig file. All the |
5716 |
|
* samples that belong to this group will not be deleted, but instead |
5717 |
|
* be moved to another group. You have to call Save() to make this |
5718 |
|
* persistent to the file. |
5719 |
|
* |
5720 |
|
* @param pGroup - group to delete |
5721 |
|
* @throws gig::Exception if given group could not be found |
5722 |
|
*/ |
5723 |
|
void File::DeleteGroupOnly(Group* pGroup) { |
5724 |
|
if (!pGroups) LoadGroups(); |
5725 |
|
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
5726 |
|
if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); |
5727 |
|
if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); |
5728 |
// move all members of this group to another group |
// move all members of this group to another group |
5729 |
pGroup->MoveAll(); |
pGroup->MoveAll(); |
5730 |
pGroups->erase(iter); |
pGroups->erase(iter); |
5741 |
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
5742 |
while (ck) { |
while (ck) { |
5743 |
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
5744 |
|
if (pVersion && pVersion->major == 3 && |
5745 |
|
strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) break; |
5746 |
|
|
5747 |
pGroups->push_back(new Group(this, ck)); |
pGroups->push_back(new Group(this, ck)); |
5748 |
} |
} |
5749 |
ck = lst3gnl->GetNextSubChunk(); |
ck = lst3gnl->GetNextSubChunk(); |
5758 |
} |
} |
5759 |
} |
} |
5760 |
|
|
5761 |
|
/** @brief Get instrument script group (by index). |
5762 |
|
* |
5763 |
|
* Returns the real-time instrument script group with the given index. |
5764 |
|
* |
5765 |
|
* @param index - number of the sought group (0..n) |
5766 |
|
* @returns sought script group or NULL if there's no such group |
5767 |
|
*/ |
5768 |
|
ScriptGroup* File::GetScriptGroup(uint index) { |
5769 |
|
if (!pScriptGroups) LoadScriptGroups(); |
5770 |
|
std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
5771 |
|
for (uint i = 0; it != pScriptGroups->end(); ++i, ++it) |
5772 |
|
if (i == index) return *it; |
5773 |
|
return NULL; |
5774 |
|
} |
5775 |
|
|
5776 |
|
/** @brief Get instrument script group (by name). |
5777 |
|
* |
5778 |
|
* Returns the first real-time instrument script group found with the given |
5779 |
|
* group name. Note that group names may not necessarily be unique. |
5780 |
|
* |
5781 |
|
* @param name - name of the sought script group |
5782 |
|
* @returns sought script group or NULL if there's no such group |
5783 |
|
*/ |
5784 |
|
ScriptGroup* File::GetScriptGroup(const String& name) { |
5785 |
|
if (!pScriptGroups) LoadScriptGroups(); |
5786 |
|
std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
5787 |
|
for (uint i = 0; it != pScriptGroups->end(); ++i, ++it) |
5788 |
|
if ((*it)->Name == name) return *it; |
5789 |
|
return NULL; |
5790 |
|
} |
5791 |
|
|
5792 |
|
/** @brief Add new instrument script group. |
5793 |
|
* |
5794 |
|
* Adds a new, empty real-time instrument script group to the file. |
5795 |
|
* |
5796 |
|
* You have to call Save() to make this persistent to the file. |
5797 |
|
* |
5798 |
|
* @return new empty script group |
5799 |
|
*/ |
5800 |
|
ScriptGroup* File::AddScriptGroup() { |
5801 |
|
if (!pScriptGroups) LoadScriptGroups(); |
5802 |
|
ScriptGroup* pScriptGroup = new ScriptGroup(this, NULL); |
5803 |
|
pScriptGroups->push_back(pScriptGroup); |
5804 |
|
return pScriptGroup; |
5805 |
|
} |
5806 |
|
|
5807 |
|
/** @brief Delete an instrument script group. |
5808 |
|
* |
5809 |
|
* This will delete the given real-time instrument script group and all its |
5810 |
|
* instrument scripts it contains. References inside instruments that are |
5811 |
|
* using the deleted scripts will be removed from the respective instruments |
5812 |
|
* accordingly. |
5813 |
|
* |
5814 |
|
* You have to call Save() to make this persistent to the file. |
5815 |
|
* |
5816 |
|
* @param pScriptGroup - script group to delete |
5817 |
|
* @throws gig::Exception if given script group could not be found |
5818 |
|
*/ |
5819 |
|
void File::DeleteScriptGroup(ScriptGroup* pScriptGroup) { |
5820 |
|
if (!pScriptGroups) LoadScriptGroups(); |
5821 |
|
std::list<ScriptGroup*>::iterator iter = |
5822 |
|
find(pScriptGroups->begin(), pScriptGroups->end(), pScriptGroup); |
5823 |
|
if (iter == pScriptGroups->end()) |
5824 |
|
throw gig::Exception("Could not delete script group, could not find given script group"); |
5825 |
|
pScriptGroups->erase(iter); |
5826 |
|
for (int i = 0; pScriptGroup->GetScript(i); ++i) |
5827 |
|
pScriptGroup->DeleteScript(pScriptGroup->GetScript(i)); |
5828 |
|
if (pScriptGroup->pList) |
5829 |
|
pScriptGroup->pList->GetParent()->DeleteSubChunk(pScriptGroup->pList); |
5830 |
|
delete pScriptGroup; |
5831 |
|
} |
5832 |
|
|
5833 |
|
void File::LoadScriptGroups() { |
5834 |
|
if (pScriptGroups) return; |
5835 |
|
pScriptGroups = new std::list<ScriptGroup*>; |
5836 |
|
RIFF::List* lstLS = pRIFF->GetSubList(LIST_TYPE_3LS); |
5837 |
|
if (lstLS) { |
5838 |
|
for (RIFF::List* lst = lstLS->GetFirstSubList(); lst; |
5839 |
|
lst = lstLS->GetNextSubList()) |
5840 |
|
{ |
5841 |
|
if (lst->GetListType() == LIST_TYPE_RTIS) { |
5842 |
|
pScriptGroups->push_back(new ScriptGroup(this, lst)); |
5843 |
|
} |
5844 |
|
} |
5845 |
|
} |
5846 |
|
} |
5847 |
|
|
5848 |
|
/** |
5849 |
|
* Apply all the gig file's current instruments, samples, groups and settings |
5850 |
|
* to the respective RIFF chunks. You have to call Save() to make changes |
5851 |
|
* persistent. |
5852 |
|
* |
5853 |
|
* Usually there is absolutely no need to call this method explicitly. |
5854 |
|
* It will be called automatically when File::Save() was called. |
5855 |
|
* |
5856 |
|
* @param pProgress - callback function for progress notification |
5857 |
|
* @throws Exception - on errors |
5858 |
|
*/ |
5859 |
|
void File::UpdateChunks(progress_t* pProgress) { |
5860 |
|
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
5861 |
|
|
5862 |
|
// update own gig format extension chunks |
5863 |
|
// (not part of the GigaStudio 4 format) |
5864 |
|
RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS); |
5865 |
|
if (!lst3LS) { |
5866 |
|
lst3LS = pRIFF->AddSubList(LIST_TYPE_3LS); |
5867 |
|
} |
5868 |
|
// Make sure <3LS > chunk is placed before <ptbl> chunk. The precise |
5869 |
|
// location of <3LS > is irrelevant, however it should be located |
5870 |
|
// before the actual wave data |
5871 |
|
RIFF::Chunk* ckPTBL = pRIFF->GetSubChunk(CHUNK_ID_PTBL); |
5872 |
|
pRIFF->MoveSubChunk(lst3LS, ckPTBL); |
5873 |
|
|
5874 |
|
// This must be performed before writing the chunks for instruments, |
5875 |
|
// because the instruments' script slots will write the file offsets |
5876 |
|
// of the respective instrument script chunk as reference. |
5877 |
|
if (pScriptGroups) { |
5878 |
|
// Update instrument script (group) chunks. |
5879 |
|
for (std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
5880 |
|
it != pScriptGroups->end(); ++it) |
5881 |
|
{ |
5882 |
|
(*it)->UpdateChunks(pProgress); |
5883 |
|
} |
5884 |
|
} |
5885 |
|
|
5886 |
|
// in case no libgig custom format data was added, then remove the |
5887 |
|
// custom "3LS " chunk again |
5888 |
|
if (!lst3LS->CountSubChunks()) { |
5889 |
|
pRIFF->DeleteSubChunk(lst3LS); |
5890 |
|
lst3LS = NULL; |
5891 |
|
} |
5892 |
|
|
5893 |
|
// first update base class's chunks |
5894 |
|
DLS::File::UpdateChunks(pProgress); |
5895 |
|
|
5896 |
|
if (newFile) { |
5897 |
|
// INFO was added by Resource::UpdateChunks - make sure it |
5898 |
|
// is placed first in file |
5899 |
|
RIFF::Chunk* info = pRIFF->GetSubList(LIST_TYPE_INFO); |
5900 |
|
RIFF::Chunk* first = pRIFF->GetFirstSubChunk(); |
5901 |
|
if (first != info) { |
5902 |
|
pRIFF->MoveSubChunk(info, first); |
5903 |
|
} |
5904 |
|
} |
5905 |
|
|
5906 |
|
// update group's chunks |
5907 |
|
if (pGroups) { |
5908 |
|
// make sure '3gri' and '3gnl' list chunks exist |
5909 |
|
// (before updating the Group chunks) |
5910 |
|
RIFF::List* _3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
5911 |
|
if (!_3gri) { |
5912 |
|
_3gri = pRIFF->AddSubList(LIST_TYPE_3GRI); |
5913 |
|
pRIFF->MoveSubChunk(_3gri, pRIFF->GetSubChunk(CHUNK_ID_PTBL)); |
5914 |
|
} |
5915 |
|
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
5916 |
|
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
5917 |
|
|
5918 |
|
// v3: make sure the file has 128 3gnm chunks |
5919 |
|
// (before updating the Group chunks) |
5920 |
|
if (pVersion && pVersion->major == 3) { |
5921 |
|
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
5922 |
|
for (int i = 0 ; i < 128 ; i++) { |
5923 |
|
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
5924 |
|
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
5925 |
|
} |
5926 |
|
} |
5927 |
|
|
5928 |
|
std::list<Group*>::iterator iter = pGroups->begin(); |
5929 |
|
std::list<Group*>::iterator end = pGroups->end(); |
5930 |
|
for (; iter != end; ++iter) { |
5931 |
|
(*iter)->UpdateChunks(pProgress); |
5932 |
|
} |
5933 |
|
} |
5934 |
|
|
5935 |
|
// update einf chunk |
5936 |
|
|
5937 |
|
// The einf chunk contains statistics about the gig file, such |
5938 |
|
// as the number of regions and samples used by each |
5939 |
|
// instrument. It is divided in equally sized parts, where the |
5940 |
|
// first part contains information about the whole gig file, |
5941 |
|
// and the rest of the parts map to each instrument in the |
5942 |
|
// file. |
5943 |
|
// |
5944 |
|
// At the end of each part there is a bit map of each sample |
5945 |
|
// in the file, where a set bit means that the sample is used |
5946 |
|
// by the file/instrument. |
5947 |
|
// |
5948 |
|
// Note that there are several fields with unknown use. These |
5949 |
|
// are set to zero. |
5950 |
|
|
5951 |
|
int sublen = pSamples->size() / 8 + 49; |
5952 |
|
int einfSize = (Instruments + 1) * sublen; |
5953 |
|
|
5954 |
|
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
5955 |
|
if (einf) { |
5956 |
|
if (einf->GetSize() != einfSize) { |
5957 |
|
einf->Resize(einfSize); |
5958 |
|
memset(einf->LoadChunkData(), 0, einfSize); |
5959 |
|
} |
5960 |
|
} else if (newFile) { |
5961 |
|
einf = pRIFF->AddSubChunk(CHUNK_ID_EINF, einfSize); |
5962 |
|
} |
5963 |
|
if (einf) { |
5964 |
|
uint8_t* pData = (uint8_t*) einf->LoadChunkData(); |
5965 |
|
|
5966 |
|
std::map<gig::Sample*,int> sampleMap; |
5967 |
|
int sampleIdx = 0; |
5968 |
|
for (Sample* pSample = GetFirstSample(); pSample; pSample = GetNextSample()) { |
5969 |
|
sampleMap[pSample] = sampleIdx++; |
5970 |
|
} |
5971 |
|
|
5972 |
|
int totnbusedsamples = 0; |
5973 |
|
int totnbusedchannels = 0; |
5974 |
|
int totnbregions = 0; |
5975 |
|
int totnbdimregions = 0; |
5976 |
|
int totnbloops = 0; |
5977 |
|
int instrumentIdx = 0; |
5978 |
|
|
5979 |
|
memset(&pData[48], 0, sublen - 48); |
5980 |
|
|
5981 |
|
for (Instrument* instrument = GetFirstInstrument() ; instrument ; |
5982 |
|
instrument = GetNextInstrument()) { |
5983 |
|
int nbusedsamples = 0; |
5984 |
|
int nbusedchannels = 0; |
5985 |
|
int nbdimregions = 0; |
5986 |
|
int nbloops = 0; |
5987 |
|
|
5988 |
|
memset(&pData[(instrumentIdx + 1) * sublen + 48], 0, sublen - 48); |
5989 |
|
|
5990 |
|
for (Region* region = instrument->GetFirstRegion() ; region ; |
5991 |
|
region = instrument->GetNextRegion()) { |
5992 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
5993 |
|
gig::DimensionRegion *d = region->pDimensionRegions[i]; |
5994 |
|
if (d->pSample) { |
5995 |
|
int sampleIdx = sampleMap[d->pSample]; |
5996 |
|
int byte = 48 + sampleIdx / 8; |
5997 |
|
int bit = 1 << (sampleIdx & 7); |
5998 |
|
if ((pData[(instrumentIdx + 1) * sublen + byte] & bit) == 0) { |
5999 |
|
pData[(instrumentIdx + 1) * sublen + byte] |= bit; |
6000 |
|
nbusedsamples++; |
6001 |
|
nbusedchannels += d->pSample->Channels; |
6002 |
|
|
6003 |
|
if ((pData[byte] & bit) == 0) { |
6004 |
|
pData[byte] |= bit; |
6005 |
|
totnbusedsamples++; |
6006 |
|
totnbusedchannels += d->pSample->Channels; |
6007 |
|
} |
6008 |
|
} |
6009 |
|
} |
6010 |
|
if (d->SampleLoops) nbloops++; |
6011 |
|
} |
6012 |
|
nbdimregions += region->DimensionRegions; |
6013 |
|
} |
6014 |
|
// first 4 bytes unknown - sometimes 0, sometimes length of einf part |
6015 |
|
// store32(&pData[(instrumentIdx + 1) * sublen], sublen); |
6016 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 4], nbusedchannels); |
6017 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 8], nbusedsamples); |
6018 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 12], 1); |
6019 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 16], instrument->Regions); |
6020 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 20], nbdimregions); |
6021 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
6022 |
|
// next 8 bytes unknown |
6023 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
6024 |
|
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
6025 |
|
// next 4 bytes unknown |
6026 |
|
|
6027 |
|
totnbregions += instrument->Regions; |
6028 |
|
totnbdimregions += nbdimregions; |
6029 |
|
totnbloops += nbloops; |
6030 |
|
instrumentIdx++; |
6031 |
|
} |
6032 |
|
// first 4 bytes unknown - sometimes 0, sometimes length of einf part |
6033 |
|
// store32(&pData[0], sublen); |
6034 |
|
store32(&pData[4], totnbusedchannels); |
6035 |
|
store32(&pData[8], totnbusedsamples); |
6036 |
|
store32(&pData[12], Instruments); |
6037 |
|
store32(&pData[16], totnbregions); |
6038 |
|
store32(&pData[20], totnbdimregions); |
6039 |
|
store32(&pData[24], totnbloops); |
6040 |
|
// next 8 bytes unknown |
6041 |
|
// next 4 bytes unknown, not always 0 |
6042 |
|
store32(&pData[40], pSamples->size()); |
6043 |
|
// next 4 bytes unknown |
6044 |
|
} |
6045 |
|
|
6046 |
|
// update 3crc chunk |
6047 |
|
|
6048 |
|
// The 3crc chunk contains CRC-32 checksums for the |
6049 |
|
// samples. The actual checksum values will be filled in |
6050 |
|
// later, by Sample::Write. |
6051 |
|
|
6052 |
|
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
6053 |
|
if (_3crc) { |
6054 |
|
_3crc->Resize(pSamples->size() * 8); |
6055 |
|
} else if (newFile) { |
6056 |
|
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
6057 |
|
_3crc->LoadChunkData(); |
6058 |
|
|
6059 |
|
// the order of einf and 3crc is not the same in v2 and v3 |
6060 |
|
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
6061 |
|
} |
6062 |
|
} |
6063 |
|
|
6064 |
|
void File::UpdateFileOffsets() { |
6065 |
|
DLS::File::UpdateFileOffsets(); |
6066 |
|
|
6067 |
|
for (Instrument* instrument = GetFirstInstrument(); instrument; |
6068 |
|
instrument = GetNextInstrument()) |
6069 |
|
{ |
6070 |
|
instrument->UpdateScriptFileOffsets(); |
6071 |
|
} |
6072 |
|
} |
6073 |
|
|
6074 |
|
/** |
6075 |
|
* Enable / disable automatic loading. By default this properyt is |
6076 |
|
* enabled and all informations are loaded automatically. However |
6077 |
|
* loading all Regions, DimensionRegions and especially samples might |
6078 |
|
* take a long time for large .gig files, and sometimes one might only |
6079 |
|
* be interested in retrieving very superficial informations like the |
6080 |
|
* amount of instruments and their names. In this case one might disable |
6081 |
|
* automatic loading to avoid very slow response times. |
6082 |
|
* |
6083 |
|
* @e CAUTION: by disabling this property many pointers (i.e. sample |
6084 |
|
* references) and informations will have invalid or even undefined |
6085 |
|
* data! This feature is currently only intended for retrieving very |
6086 |
|
* superficial informations in a very fast way. Don't use it to retrieve |
6087 |
|
* details like synthesis informations or even to modify .gig files! |
6088 |
|
*/ |
6089 |
|
void File::SetAutoLoad(bool b) { |
6090 |
|
bAutoLoad = b; |
6091 |
|
} |
6092 |
|
|
6093 |
|
/** |
6094 |
|
* Returns whether automatic loading is enabled. |
6095 |
|
* @see SetAutoLoad() |
6096 |
|
*/ |
6097 |
|
bool File::GetAutoLoad() { |
6098 |
|
return bAutoLoad; |
6099 |
|
} |
6100 |
|
|
6101 |
|
|
6102 |
|
|
6103 |
// *************** Exception *************** |
// *************** Exception *************** |