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-2009 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 * |
28 |
#include <algorithm> |
#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 |
|
|
269 |
* steps. |
* steps. |
270 |
* |
* |
271 |
* Once the whole data was processed by __calculateCRC(), one should |
* Once the whole data was processed by __calculateCRC(), one should |
272 |
* call __encodeCRC() to get the final CRC result. |
* call __finalizeCRC() to get the final CRC result. |
273 |
* |
* |
274 |
* @param buf - pointer to data the CRC shall be calculated of |
* @param buf - pointer to data the CRC shall be calculated of |
275 |
* @param bufSize - size of the data to be processed |
* @param bufSize - size of the data to be processed |
276 |
* @param crc - variable the CRC sum shall be stored to |
* @param crc - variable the CRC sum shall be stored to |
277 |
*/ |
*/ |
278 |
static void __calculateCRC(unsigned char* buf, int bufSize, uint32_t& crc) { |
static void __calculateCRC(unsigned char* buf, size_t bufSize, uint32_t& crc) { |
279 |
for (int i = 0 ; i < bufSize ; i++) { |
for (size_t i = 0 ; i < bufSize ; i++) { |
280 |
crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); |
crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); |
281 |
} |
} |
282 |
} |
} |
286 |
* |
* |
287 |
* @param crc - variable previously passed to __calculateCRC() |
* @param crc - variable previously passed to __calculateCRC() |
288 |
*/ |
*/ |
289 |
inline static uint32_t __encodeCRC(const uint32_t& crc) { |
inline static void __finalizeCRC(uint32_t& crc) { |
290 |
return crc ^ 0xffffffff; |
crc ^= 0xffffffff; |
291 |
} |
} |
292 |
|
|
293 |
|
|
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. |
338 |
* ('wvpl') list chunk |
* ('wvpl') list chunk |
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 |
|
* @param index - wave pool index of sample (may be -1 on new sample) |
342 |
*/ |
*/ |
343 |
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, int index) |
344 |
|
: DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) |
345 |
|
{ |
346 |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
347 |
{ CHUNK_ID_INAM, 64 }, |
{ CHUNK_ID_INAM, 64 }, |
348 |
{ 0, 0 } |
{ 0, 0 } |
352 |
FileNo = fileNo; |
FileNo = fileNo; |
353 |
|
|
354 |
__resetCRC(crc); |
__resetCRC(crc); |
355 |
|
// if this is not a new sample, try to get the sample's already existing |
356 |
|
// CRC32 checksum from disk, this checksum will reflect the sample's CRC32 |
357 |
|
// checksum of the time when the sample was consciously modified by the |
358 |
|
// user for the last time (by calling Sample::Write() that is). |
359 |
|
if (index >= 0) { // not a new file ... |
360 |
|
try { |
361 |
|
uint32_t crc = pFile->GetSampleChecksumByIndex(index); |
362 |
|
this->crc = crc; |
363 |
|
} catch (...) {} |
364 |
|
} |
365 |
|
|
366 |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
367 |
if (pCk3gix) { |
if (pCk3gix) { |
440 |
} |
} |
441 |
|
|
442 |
/** |
/** |
443 |
|
* Make a (semi) deep copy of the Sample object given by @a orig (without |
444 |
|
* the actual waveform data) and assign it to this object. |
445 |
|
* |
446 |
|
* Discussion: copying .gig samples is a bit tricky. It requires three |
447 |
|
* steps: |
448 |
|
* 1. Copy sample's meta informations (done by CopyAssignMeta()) including |
449 |
|
* its new sample waveform data size. |
450 |
|
* 2. Saving the file (done by File::Save()) so that it gains correct size |
451 |
|
* and layout for writing the actual wave form data directly to disc |
452 |
|
* in next step. |
453 |
|
* 3. Copy the waveform data with disk streaming (done by CopyAssignWave()). |
454 |
|
* |
455 |
|
* @param orig - original Sample object to be copied from |
456 |
|
*/ |
457 |
|
void Sample::CopyAssignMeta(const Sample* orig) { |
458 |
|
// handle base classes |
459 |
|
DLS::Sample::CopyAssignCore(orig); |
460 |
|
|
461 |
|
// handle actual own attributes of this class |
462 |
|
Manufacturer = orig->Manufacturer; |
463 |
|
Product = orig->Product; |
464 |
|
SamplePeriod = orig->SamplePeriod; |
465 |
|
MIDIUnityNote = orig->MIDIUnityNote; |
466 |
|
FineTune = orig->FineTune; |
467 |
|
SMPTEFormat = orig->SMPTEFormat; |
468 |
|
SMPTEOffset = orig->SMPTEOffset; |
469 |
|
Loops = orig->Loops; |
470 |
|
LoopID = orig->LoopID; |
471 |
|
LoopType = orig->LoopType; |
472 |
|
LoopStart = orig->LoopStart; |
473 |
|
LoopEnd = orig->LoopEnd; |
474 |
|
LoopSize = orig->LoopSize; |
475 |
|
LoopFraction = orig->LoopFraction; |
476 |
|
LoopPlayCount = orig->LoopPlayCount; |
477 |
|
|
478 |
|
// schedule resizing this sample to the given sample's size |
479 |
|
Resize(orig->GetSize()); |
480 |
|
} |
481 |
|
|
482 |
|
/** |
483 |
|
* Should be called after CopyAssignMeta() and File::Save() sequence. |
484 |
|
* Read more about it in the discussion of CopyAssignMeta(). This method |
485 |
|
* copies the actual waveform data by disk streaming. |
486 |
|
* |
487 |
|
* @e CAUTION: this method is currently not thread safe! During this |
488 |
|
* operation the sample must not be used for other purposes by other |
489 |
|
* threads! |
490 |
|
* |
491 |
|
* @param orig - original Sample object to be copied from |
492 |
|
*/ |
493 |
|
void Sample::CopyAssignWave(const Sample* orig) { |
494 |
|
const int iReadAtOnce = 32*1024; |
495 |
|
char* buf = new char[iReadAtOnce * orig->FrameSize]; |
496 |
|
Sample* pOrig = (Sample*) orig; //HACK: remove constness for now |
497 |
|
file_offset_t restorePos = pOrig->GetPos(); |
498 |
|
pOrig->SetPos(0); |
499 |
|
SetPos(0); |
500 |
|
for (file_offset_t n = pOrig->Read(buf, iReadAtOnce); n; |
501 |
|
n = pOrig->Read(buf, iReadAtOnce)) |
502 |
|
{ |
503 |
|
Write(buf, n); |
504 |
|
} |
505 |
|
pOrig->SetPos(restorePos); |
506 |
|
delete [] buf; |
507 |
|
} |
508 |
|
|
509 |
|
/** |
510 |
* Apply sample and its settings to the respective RIFF chunks. You have |
* Apply sample and its settings to the respective RIFF chunks. You have |
511 |
* to call File::Save() to make changes persistent. |
* to call File::Save() to make changes persistent. |
512 |
* |
* |
513 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
514 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
515 |
* |
* |
516 |
|
* @param pProgress - callback function for progress notification |
517 |
* @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 |
518 |
* was provided yet |
* was provided yet |
519 |
* @throws gig::Exception if there is any invalid sample setting |
* @throws gig::Exception if there is any invalid sample setting |
520 |
*/ |
*/ |
521 |
void Sample::UpdateChunks() { |
void Sample::UpdateChunks(progress_t* pProgress) { |
522 |
// first update base class's chunks |
// first update base class's chunks |
523 |
DLS::Sample::UpdateChunks(); |
DLS::Sample::UpdateChunks(pProgress); |
524 |
|
|
525 |
// make sure 'smpl' chunk exists |
// make sure 'smpl' chunk exists |
526 |
pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL); |
pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL); |
568 |
// update '3gix' chunk |
// update '3gix' chunk |
569 |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
570 |
store16(&pData[0], iSampleGroup); |
store16(&pData[0], iSampleGroup); |
571 |
|
|
572 |
|
// if the library user toggled the "Compressed" attribute from true to |
573 |
|
// false, then the EWAV chunk associated with compressed samples needs |
574 |
|
// to be deleted |
575 |
|
RIFF::Chunk* ewav = pWaveList->GetSubChunk(CHUNK_ID_EWAV); |
576 |
|
if (ewav && !Compressed) { |
577 |
|
pWaveList->DeleteSubChunk(ewav); |
578 |
|
} |
579 |
} |
} |
580 |
|
|
581 |
/// 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). |
582 |
void Sample::ScanCompressedSample() { |
void Sample::ScanCompressedSample() { |
583 |
//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) |
584 |
this->SamplesTotal = 0; |
this->SamplesTotal = 0; |
585 |
std::list<unsigned long> frameOffsets; |
std::list<file_offset_t> frameOffsets; |
586 |
|
|
587 |
SamplesPerFrame = BitDepth == 24 ? 256 : 2048; |
SamplesPerFrame = BitDepth == 24 ? 256 : 2048; |
588 |
WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag |
WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag |
598 |
const int mode_l = pCkData->ReadUint8(); |
const int mode_l = pCkData->ReadUint8(); |
599 |
const int mode_r = pCkData->ReadUint8(); |
const int mode_r = pCkData->ReadUint8(); |
600 |
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"); |
601 |
const unsigned long frameSize = bytesPerFrame[mode_l] + bytesPerFrame[mode_r]; |
const file_offset_t frameSize = bytesPerFrame[mode_l] + bytesPerFrame[mode_r]; |
602 |
|
|
603 |
if (pCkData->RemainingBytes() <= frameSize) { |
if (pCkData->RemainingBytes() <= frameSize) { |
604 |
SamplesInLastFrame = |
SamplesInLastFrame = |
617 |
|
|
618 |
const int mode = pCkData->ReadUint8(); |
const int mode = pCkData->ReadUint8(); |
619 |
if (mode > 5) throw gig::Exception("Unknown compression mode"); |
if (mode > 5) throw gig::Exception("Unknown compression mode"); |
620 |
const unsigned long frameSize = bytesPerFrame[mode]; |
const file_offset_t frameSize = bytesPerFrame[mode]; |
621 |
|
|
622 |
if (pCkData->RemainingBytes() <= frameSize) { |
if (pCkData->RemainingBytes() <= frameSize) { |
623 |
SamplesInLastFrame = |
SamplesInLastFrame = |
633 |
|
|
634 |
// 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) |
635 |
if (FrameTable) delete[] FrameTable; |
if (FrameTable) delete[] FrameTable; |
636 |
FrameTable = new unsigned long[frameOffsets.size()]; |
FrameTable = new file_offset_t[frameOffsets.size()]; |
637 |
std::list<unsigned long>::iterator end = frameOffsets.end(); |
std::list<file_offset_t>::iterator end = frameOffsets.end(); |
638 |
std::list<unsigned long>::iterator iter = frameOffsets.begin(); |
std::list<file_offset_t>::iterator iter = frameOffsets.begin(); |
639 |
for (int i = 0; iter != end; i++, iter++) { |
for (int i = 0; iter != end; i++, iter++) { |
640 |
FrameTable[i] = *iter; |
FrameTable[i] = *iter; |
641 |
} |
} |
676 |
* the cached sample data in bytes |
* the cached sample data in bytes |
677 |
* @see ReleaseSampleData(), Read(), SetPos() |
* @see ReleaseSampleData(), Read(), SetPos() |
678 |
*/ |
*/ |
679 |
buffer_t Sample::LoadSampleData(unsigned long SampleCount) { |
buffer_t Sample::LoadSampleData(file_offset_t SampleCount) { |
680 |
return LoadSampleDataWithNullSamplesExtension(SampleCount, 0); // 0 amount of NullSamples |
return LoadSampleDataWithNullSamplesExtension(SampleCount, 0); // 0 amount of NullSamples |
681 |
} |
} |
682 |
|
|
735 |
* size of the cached sample data in bytes |
* size of the cached sample data in bytes |
736 |
* @see ReleaseSampleData(), Read(), SetPos() |
* @see ReleaseSampleData(), Read(), SetPos() |
737 |
*/ |
*/ |
738 |
buffer_t Sample::LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount) { |
buffer_t Sample::LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount) { |
739 |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
740 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
741 |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
file_offset_t allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
742 |
SetPos(0); // reset read position to begin of sample |
SetPos(0); // reset read position to begin of sample |
743 |
RAMCache.pStart = new int8_t[allocationsize]; |
RAMCache.pStart = new int8_t[allocationsize]; |
744 |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
802 |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
803 |
* other formats will fail! |
* other formats will fail! |
804 |
* |
* |
805 |
* @param iNewSize - new sample wave data size in sample points (must be |
* @param NewSize - new sample wave data size in sample points (must be |
806 |
* greater than zero) |
* greater than zero) |
807 |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
808 |
* or if \a iNewSize is less than 1 |
* @throws DLS::Exception if \a NewSize is less than 1 or unrealistic large |
809 |
* @throws gig::Exception if existing sample is compressed |
* @throws gig::Exception if existing sample is compressed |
810 |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
811 |
* DLS::Sample::FormatTag, File::Save() |
* DLS::Sample::FormatTag, File::Save() |
812 |
*/ |
*/ |
813 |
void Sample::Resize(int iNewSize) { |
void Sample::Resize(file_offset_t NewSize) { |
814 |
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)"); |
815 |
DLS::Sample::Resize(iNewSize); |
DLS::Sample::Resize(NewSize); |
816 |
} |
} |
817 |
|
|
818 |
/** |
/** |
836 |
* @returns the new sample position |
* @returns the new sample position |
837 |
* @see Read() |
* @see Read() |
838 |
*/ |
*/ |
839 |
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) { |
840 |
if (Compressed) { |
if (Compressed) { |
841 |
switch (Whence) { |
switch (Whence) { |
842 |
case RIFF::stream_curpos: |
case RIFF::stream_curpos: |
854 |
} |
} |
855 |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
856 |
|
|
857 |
unsigned long frame = this->SamplePos / 2048; // to which frame to jump |
file_offset_t frame = this->SamplePos / 2048; // to which frame to jump |
858 |
this->FrameOffset = this->SamplePos % 2048; // offset (in sample points) within that frame |
this->FrameOffset = this->SamplePos % 2048; // offset (in sample points) within that frame |
859 |
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 |
860 |
return this->SamplePos; |
return this->SamplePos; |
861 |
} |
} |
862 |
else { // not compressed |
else { // not compressed |
863 |
unsigned long orderedBytes = SampleCount * this->FrameSize; |
file_offset_t orderedBytes = SampleCount * this->FrameSize; |
864 |
unsigned long result = pCkData->SetPos(orderedBytes, Whence); |
file_offset_t result = pCkData->SetPos(orderedBytes, Whence); |
865 |
return (result == orderedBytes) ? SampleCount |
return (result == orderedBytes) ? SampleCount |
866 |
: result / this->FrameSize; |
: result / this->FrameSize; |
867 |
} |
} |
870 |
/** |
/** |
871 |
* Returns the current position in the sample (in sample points). |
* Returns the current position in the sample (in sample points). |
872 |
*/ |
*/ |
873 |
unsigned long Sample::GetPos() { |
file_offset_t Sample::GetPos() const { |
874 |
if (Compressed) return SamplePos; |
if (Compressed) return SamplePos; |
875 |
else return pCkData->GetPos() / FrameSize; |
else return pCkData->GetPos() / FrameSize; |
876 |
} |
} |
909 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
910 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
911 |
*/ |
*/ |
912 |
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, |
913 |
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
914 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
file_offset_t samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
915 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
916 |
|
|
917 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
949 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
950 |
// backward playback |
// backward playback |
951 |
|
|
952 |
unsigned long swapareastart = totalreadsamples; |
file_offset_t swapareastart = totalreadsamples; |
953 |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
file_offset_t loopoffset = GetPos() - loop.LoopStart; |
954 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
file_offset_t samplestoreadinloop = Min(samplestoread, loopoffset); |
955 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
file_offset_t reverseplaybackend = GetPos() - samplestoreadinloop; |
956 |
|
|
957 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
958 |
|
|
972 |
} |
} |
973 |
|
|
974 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
975 |
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! |
976 |
|
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
977 |
} |
} |
978 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
979 |
break; |
break; |
1000 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
1001 |
// backward playback |
// backward playback |
1002 |
|
|
1003 |
unsigned long swapareastart = totalreadsamples; |
file_offset_t swapareastart = totalreadsamples; |
1004 |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
file_offset_t loopoffset = GetPos() - loop.LoopStart; |
1005 |
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) |
1006 |
: samplestoread; |
: samplestoread; |
1007 |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
file_offset_t reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
1008 |
|
|
1009 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
1010 |
|
|
1084 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
1085 |
* @see SetPos(), CreateDecompressionBuffer() |
* @see SetPos(), CreateDecompressionBuffer() |
1086 |
*/ |
*/ |
1087 |
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) { |
1088 |
if (SampleCount == 0) return 0; |
if (SampleCount == 0) return 0; |
1089 |
if (!Compressed) { |
if (!Compressed) { |
1090 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
1099 |
else { |
else { |
1100 |
if (this->SamplePos >= this->SamplesTotal) return 0; |
if (this->SamplePos >= this->SamplesTotal) return 0; |
1101 |
//TODO: efficiency: maybe we should test for an average compression rate |
//TODO: efficiency: maybe we should test for an average compression rate |
1102 |
unsigned long assumedsize = GuessSize(SampleCount), |
file_offset_t assumedsize = GuessSize(SampleCount), |
1103 |
remainingbytes = 0, // remaining bytes in the local buffer |
remainingbytes = 0, // remaining bytes in the local buffer |
1104 |
remainingsamples = SampleCount, |
remainingsamples = SampleCount, |
1105 |
copysamples, skipsamples, |
copysamples, skipsamples, |
1122 |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
1123 |
|
|
1124 |
while (remainingsamples && remainingbytes) { |
while (remainingsamples && remainingbytes) { |
1125 |
unsigned long framesamples = SamplesPerFrame; |
file_offset_t framesamples = SamplesPerFrame; |
1126 |
unsigned long framebytes, rightChannelOffset = 0, nextFrameOffset; |
file_offset_t framebytes, rightChannelOffset = 0, nextFrameOffset; |
1127 |
|
|
1128 |
int mode_l = *pSrc++, mode_r = 0; |
int mode_l = *pSrc++, mode_r = 0; |
1129 |
|
|
1273 |
* @throws gig::Exception if sample is compressed |
* @throws gig::Exception if sample is compressed |
1274 |
* @see DLS::LoadSampleData() |
* @see DLS::LoadSampleData() |
1275 |
*/ |
*/ |
1276 |
unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) { |
file_offset_t Sample::Write(void* pBuffer, file_offset_t SampleCount) { |
1277 |
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)"); |
1278 |
|
|
1279 |
// if this is the first write in this sample, reset the |
// if this is the first write in this sample, reset the |
1282 |
__resetCRC(crc); |
__resetCRC(crc); |
1283 |
} |
} |
1284 |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
1285 |
unsigned long res; |
file_offset_t res; |
1286 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
1287 |
res = pCkData->Write(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
res = pCkData->Write(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
1288 |
} else { // 16 bit |
} else { // 16 bit |
1294 |
// if this is the last write, update the checksum chunk in the |
// if this is the last write, update the checksum chunk in the |
1295 |
// file |
// file |
1296 |
if (pCkData->GetPos() == pCkData->GetSize()) { |
if (pCkData->GetPos() == pCkData->GetSize()) { |
1297 |
|
__finalizeCRC(crc); |
1298 |
File* pFile = static_cast<File*>(GetParent()); |
File* pFile = static_cast<File*>(GetParent()); |
1299 |
pFile->SetSampleChecksum(this, __encodeCRC(crc)); |
pFile->SetSampleChecksum(this, crc); |
1300 |
} |
} |
1301 |
return res; |
return res; |
1302 |
} |
} |
1317 |
* @returns allocated decompression buffer |
* @returns allocated decompression buffer |
1318 |
* @see DestroyDecompressionBuffer() |
* @see DestroyDecompressionBuffer() |
1319 |
*/ |
*/ |
1320 |
buffer_t Sample::CreateDecompressionBuffer(unsigned long MaxReadSize) { |
buffer_t Sample::CreateDecompressionBuffer(file_offset_t MaxReadSize) { |
1321 |
buffer_t result; |
buffer_t result; |
1322 |
const double worstCaseHeaderOverhead = |
const double worstCaseHeaderOverhead = |
1323 |
(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; |
1324 |
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); |
1325 |
result.pStart = new int8_t[result.Size]; |
result.pStart = new int8_t[result.Size]; |
1326 |
result.NullExtensionSize = 0; |
result.NullExtensionSize = 0; |
1327 |
return result; |
return result; |
1355 |
return pGroup; |
return pGroup; |
1356 |
} |
} |
1357 |
|
|
1358 |
|
/** |
1359 |
|
* Returns the CRC-32 checksum of the sample's raw wave form data at the |
1360 |
|
* time when this sample's wave form data was modified for the last time |
1361 |
|
* by calling Write(). This checksum only covers the raw wave form data, |
1362 |
|
* not any meta informations like i.e. bit depth or loop points. Since |
1363 |
|
* this method just returns the checksum stored for this sample i.e. when |
1364 |
|
* the gig file was loaded, this method returns immediately. So it does no |
1365 |
|
* recalcuation of the checksum with the currently available sample wave |
1366 |
|
* form data. |
1367 |
|
* |
1368 |
|
* @see VerifyWaveData() |
1369 |
|
*/ |
1370 |
|
uint32_t Sample::GetWaveDataCRC32Checksum() { |
1371 |
|
return crc; |
1372 |
|
} |
1373 |
|
|
1374 |
|
/** |
1375 |
|
* Checks the integrity of this sample's raw audio wave data. Whenever a |
1376 |
|
* Sample's raw wave data is intentionally modified (i.e. by calling |
1377 |
|
* Write() and supplying the new raw audio wave form data) a CRC32 checksum |
1378 |
|
* is calculated and stored/updated for this sample, along to the sample's |
1379 |
|
* meta informations. |
1380 |
|
* |
1381 |
|
* Now by calling this method the current raw audio wave data is checked |
1382 |
|
* against the already stored CRC32 check sum in order to check whether the |
1383 |
|
* sample data had been damaged unintentionally for some reason. Since by |
1384 |
|
* calling this method always the entire raw audio wave data has to be |
1385 |
|
* read, verifying all samples this way may take a long time accordingly. |
1386 |
|
* And that's also the reason why the sample integrity is not checked by |
1387 |
|
* default whenever a gig file is loaded. So this method must be called |
1388 |
|
* explicitly to fulfill this task. |
1389 |
|
* |
1390 |
|
* @param pActually - (optional) if provided, will be set to the actually |
1391 |
|
* calculated checksum of the current raw wave form data, |
1392 |
|
* you can get the expected checksum instead by calling |
1393 |
|
* GetWaveDataCRC32Checksum() |
1394 |
|
* @returns true if sample is OK or false if the sample is damaged |
1395 |
|
* @throws Exception if no checksum had been stored to disk for this |
1396 |
|
* sample yet, or on I/O issues |
1397 |
|
* @see GetWaveDataCRC32Checksum() |
1398 |
|
*/ |
1399 |
|
bool Sample::VerifyWaveData(uint32_t* pActually) { |
1400 |
|
//File* pFile = static_cast<File*>(GetParent()); |
1401 |
|
uint32_t crc = CalculateWaveDataChecksum(); |
1402 |
|
if (pActually) *pActually = crc; |
1403 |
|
return crc == this->crc; |
1404 |
|
} |
1405 |
|
|
1406 |
|
uint32_t Sample::CalculateWaveDataChecksum() { |
1407 |
|
const size_t sz = 20*1024; // 20kB buffer size |
1408 |
|
std::vector<uint8_t> buffer(sz); |
1409 |
|
buffer.resize(sz); |
1410 |
|
|
1411 |
|
const size_t n = sz / FrameSize; |
1412 |
|
SetPos(0); |
1413 |
|
uint32_t crc = 0; |
1414 |
|
__resetCRC(crc); |
1415 |
|
while (true) { |
1416 |
|
file_offset_t nRead = Read(&buffer[0], n); |
1417 |
|
if (nRead <= 0) break; |
1418 |
|
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
1419 |
|
} |
1420 |
|
__finalizeCRC(crc); |
1421 |
|
return crc; |
1422 |
|
} |
1423 |
|
|
1424 |
Sample::~Sample() { |
Sample::~Sample() { |
1425 |
Instances--; |
Instances--; |
1426 |
if (!Instances && InternalDecompressionBuffer.Size) { |
if (!Instances && InternalDecompressionBuffer.Size) { |
1437 |
// *************** DimensionRegion *************** |
// *************** DimensionRegion *************** |
1438 |
// * |
// * |
1439 |
|
|
1440 |
uint DimensionRegion::Instances = 0; |
size_t DimensionRegion::Instances = 0; |
1441 |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
1442 |
|
|
1443 |
DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1562 |
: vcf_res_ctrl_none; |
: vcf_res_ctrl_none; |
1563 |
uint16_t eg3depth = _3ewa->ReadUint16(); |
uint16_t eg3depth = _3ewa->ReadUint16(); |
1564 |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
1565 |
: (-1) * (int16_t) ((eg3depth ^ 0xffff) + 1); /* binary complementary for negatives */ |
: (-1) * (int16_t) ((eg3depth ^ 0xfff) + 1); /* binary complementary for negatives */ |
1566 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1567 |
ChannelOffset = _3ewa->ReadUint8() / 4; |
ChannelOffset = _3ewa->ReadUint8() / 4; |
1568 |
uint8_t regoptions = _3ewa->ReadUint8(); |
uint8_t regoptions = _3ewa->ReadUint8(); |
1631 |
EG2Attack = 0.0; |
EG2Attack = 0.0; |
1632 |
EG2Decay1 = 0.005; |
EG2Decay1 = 0.005; |
1633 |
EG2Sustain = 1000; |
EG2Sustain = 1000; |
1634 |
EG2Release = 0.3; |
EG2Release = 60; |
1635 |
LFO2ControlDepth = 0; |
LFO2ControlDepth = 0; |
1636 |
LFO2Frequency = 1.0; |
LFO2Frequency = 1.0; |
1637 |
LFO2InternalDepth = 0; |
LFO2InternalDepth = 0; |
1710 |
*/ |
*/ |
1711 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
1712 |
Instances++; |
Instances++; |
1713 |
|
//NOTE: I think we cannot call CopyAssign() here (in a constructor) as long as its a virtual method |
1714 |
*this = src; // default memberwise shallow copy of all parameters |
*this = src; // default memberwise shallow copy of all parameters |
1715 |
pParentList = _3ewl; // restore the chunk pointer |
pParentList = _3ewl; // restore the chunk pointer |
1716 |
|
|
1726 |
pSampleLoops[k] = src.pSampleLoops[k]; |
pSampleLoops[k] = src.pSampleLoops[k]; |
1727 |
} |
} |
1728 |
} |
} |
1729 |
|
|
1730 |
|
/** |
1731 |
|
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1732 |
|
* and assign it to this object. |
1733 |
|
* |
1734 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
1735 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
1736 |
|
* |
1737 |
|
* @param orig - original DimensionRegion object to be copied from |
1738 |
|
*/ |
1739 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig) { |
1740 |
|
CopyAssign(orig, NULL); |
1741 |
|
} |
1742 |
|
|
1743 |
|
/** |
1744 |
|
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1745 |
|
* and assign it to this object. |
1746 |
|
* |
1747 |
|
* @param orig - original DimensionRegion object to be copied from |
1748 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
1749 |
|
* this file's samples |
1750 |
|
*/ |
1751 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples) { |
1752 |
|
// delete all allocated data first |
1753 |
|
if (VelocityTable) delete [] VelocityTable; |
1754 |
|
if (pSampleLoops) delete [] pSampleLoops; |
1755 |
|
|
1756 |
|
// backup parent list pointer |
1757 |
|
RIFF::List* p = pParentList; |
1758 |
|
|
1759 |
|
gig::Sample* pOriginalSample = pSample; |
1760 |
|
gig::Region* pOriginalRegion = pRegion; |
1761 |
|
|
1762 |
|
//NOTE: copy code copied from assignment constructor above, see comment there as well |
1763 |
|
|
1764 |
|
*this = *orig; // default memberwise shallow copy of all parameters |
1765 |
|
|
1766 |
|
// restore members that shall not be altered |
1767 |
|
pParentList = p; // restore the chunk pointer |
1768 |
|
pRegion = pOriginalRegion; |
1769 |
|
|
1770 |
|
// only take the raw sample reference reference if the |
1771 |
|
// two DimensionRegion objects are part of the same file |
1772 |
|
if (pOriginalRegion->GetParent()->GetParent() != orig->pRegion->GetParent()->GetParent()) { |
1773 |
|
pSample = pOriginalSample; |
1774 |
|
} |
1775 |
|
|
1776 |
|
if (mSamples && mSamples->count(orig->pSample)) { |
1777 |
|
pSample = mSamples->find(orig->pSample)->second; |
1778 |
|
} |
1779 |
|
|
1780 |
|
// deep copy of owned structures |
1781 |
|
if (orig->VelocityTable) { |
1782 |
|
VelocityTable = new uint8_t[128]; |
1783 |
|
for (int k = 0 ; k < 128 ; k++) |
1784 |
|
VelocityTable[k] = orig->VelocityTable[k]; |
1785 |
|
} |
1786 |
|
if (orig->pSampleLoops) { |
1787 |
|
pSampleLoops = new DLS::sample_loop_t[orig->SampleLoops]; |
1788 |
|
for (int k = 0 ; k < orig->SampleLoops ; k++) |
1789 |
|
pSampleLoops[k] = orig->pSampleLoops[k]; |
1790 |
|
} |
1791 |
|
} |
1792 |
|
|
1793 |
/** |
/** |
1794 |
* Updates the respective member variable and updates @c SampleAttenuation |
* Updates the respective member variable and updates @c SampleAttenuation |
1805 |
* |
* |
1806 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
1807 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
1808 |
|
* |
1809 |
|
* @param pProgress - callback function for progress notification |
1810 |
*/ |
*/ |
1811 |
void DimensionRegion::UpdateChunks() { |
void DimensionRegion::UpdateChunks(progress_t* pProgress) { |
1812 |
// first update base class's chunk |
// first update base class's chunk |
1813 |
DLS::Sampler::UpdateChunks(); |
DLS::Sampler::UpdateChunks(pProgress); |
1814 |
|
|
1815 |
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP); |
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP); |
1816 |
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData(); |
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData(); |
1830 |
|
|
1831 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1832 |
|
|
1833 |
const uint32_t chunksize = _3ewa->GetNewSize(); |
const uint32_t chunksize = (uint32_t) _3ewa->GetNewSize(); |
1834 |
store32(&pData[0], chunksize); // unknown, always chunk size? |
store32(&pData[0], chunksize); // unknown, always chunk size? |
1835 |
|
|
1836 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
2032 |
} |
} |
2033 |
|
|
2034 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
2035 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xfff); /* binary complementary for negatives */ |
2036 |
store16(&pData[116], eg3depth); |
store16(&pData[116], eg3depth); |
2037 |
|
|
2038 |
// next 2 bytes unknown |
// next 2 bytes unknown |
2080 |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
2081 |
pData[137] = vcfbreakpoint; |
pData[137] = vcfbreakpoint; |
2082 |
|
|
2083 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 + |
2084 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
2085 |
pData[138] = vcfvelocity; |
pData[138] = vcfvelocity; |
2086 |
|
|
2145 |
return pRegion; |
return pRegion; |
2146 |
} |
} |
2147 |
|
|
2148 |
|
// show error if some _lev_ctrl_* enum entry is not listed in the following function |
2149 |
|
// (commented out for now, because "diagnostic push" not supported prior GCC 4.6) |
2150 |
|
// TODO: uncomment and add a GCC version check (see also commented "#pragma GCC diagnostic pop" below) |
2151 |
|
//#pragma GCC diagnostic push |
2152 |
|
//#pragma GCC diagnostic error "-Wswitch" |
2153 |
|
|
2154 |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
2155 |
leverage_ctrl_t decodedcontroller; |
leverage_ctrl_t decodedcontroller; |
2156 |
switch (EncodedController) { |
switch (EncodedController) { |
2262 |
decodedcontroller.controller_number = 95; |
decodedcontroller.controller_number = 95; |
2263 |
break; |
break; |
2264 |
|
|
2265 |
|
// format extension (these controllers are so far only supported by |
2266 |
|
// LinuxSampler & gigedit) they will *NOT* work with |
2267 |
|
// Gigasampler/GigaStudio ! |
2268 |
|
case _lev_ctrl_CC3_EXT: |
2269 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2270 |
|
decodedcontroller.controller_number = 3; |
2271 |
|
break; |
2272 |
|
case _lev_ctrl_CC6_EXT: |
2273 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2274 |
|
decodedcontroller.controller_number = 6; |
2275 |
|
break; |
2276 |
|
case _lev_ctrl_CC7_EXT: |
2277 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2278 |
|
decodedcontroller.controller_number = 7; |
2279 |
|
break; |
2280 |
|
case _lev_ctrl_CC8_EXT: |
2281 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2282 |
|
decodedcontroller.controller_number = 8; |
2283 |
|
break; |
2284 |
|
case _lev_ctrl_CC9_EXT: |
2285 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2286 |
|
decodedcontroller.controller_number = 9; |
2287 |
|
break; |
2288 |
|
case _lev_ctrl_CC10_EXT: |
2289 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2290 |
|
decodedcontroller.controller_number = 10; |
2291 |
|
break; |
2292 |
|
case _lev_ctrl_CC11_EXT: |
2293 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2294 |
|
decodedcontroller.controller_number = 11; |
2295 |
|
break; |
2296 |
|
case _lev_ctrl_CC14_EXT: |
2297 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2298 |
|
decodedcontroller.controller_number = 14; |
2299 |
|
break; |
2300 |
|
case _lev_ctrl_CC15_EXT: |
2301 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2302 |
|
decodedcontroller.controller_number = 15; |
2303 |
|
break; |
2304 |
|
case _lev_ctrl_CC20_EXT: |
2305 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2306 |
|
decodedcontroller.controller_number = 20; |
2307 |
|
break; |
2308 |
|
case _lev_ctrl_CC21_EXT: |
2309 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2310 |
|
decodedcontroller.controller_number = 21; |
2311 |
|
break; |
2312 |
|
case _lev_ctrl_CC22_EXT: |
2313 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2314 |
|
decodedcontroller.controller_number = 22; |
2315 |
|
break; |
2316 |
|
case _lev_ctrl_CC23_EXT: |
2317 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2318 |
|
decodedcontroller.controller_number = 23; |
2319 |
|
break; |
2320 |
|
case _lev_ctrl_CC24_EXT: |
2321 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2322 |
|
decodedcontroller.controller_number = 24; |
2323 |
|
break; |
2324 |
|
case _lev_ctrl_CC25_EXT: |
2325 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2326 |
|
decodedcontroller.controller_number = 25; |
2327 |
|
break; |
2328 |
|
case _lev_ctrl_CC26_EXT: |
2329 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2330 |
|
decodedcontroller.controller_number = 26; |
2331 |
|
break; |
2332 |
|
case _lev_ctrl_CC27_EXT: |
2333 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2334 |
|
decodedcontroller.controller_number = 27; |
2335 |
|
break; |
2336 |
|
case _lev_ctrl_CC28_EXT: |
2337 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2338 |
|
decodedcontroller.controller_number = 28; |
2339 |
|
break; |
2340 |
|
case _lev_ctrl_CC29_EXT: |
2341 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2342 |
|
decodedcontroller.controller_number = 29; |
2343 |
|
break; |
2344 |
|
case _lev_ctrl_CC30_EXT: |
2345 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2346 |
|
decodedcontroller.controller_number = 30; |
2347 |
|
break; |
2348 |
|
case _lev_ctrl_CC31_EXT: |
2349 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2350 |
|
decodedcontroller.controller_number = 31; |
2351 |
|
break; |
2352 |
|
case _lev_ctrl_CC68_EXT: |
2353 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2354 |
|
decodedcontroller.controller_number = 68; |
2355 |
|
break; |
2356 |
|
case _lev_ctrl_CC69_EXT: |
2357 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2358 |
|
decodedcontroller.controller_number = 69; |
2359 |
|
break; |
2360 |
|
case _lev_ctrl_CC70_EXT: |
2361 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2362 |
|
decodedcontroller.controller_number = 70; |
2363 |
|
break; |
2364 |
|
case _lev_ctrl_CC71_EXT: |
2365 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2366 |
|
decodedcontroller.controller_number = 71; |
2367 |
|
break; |
2368 |
|
case _lev_ctrl_CC72_EXT: |
2369 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2370 |
|
decodedcontroller.controller_number = 72; |
2371 |
|
break; |
2372 |
|
case _lev_ctrl_CC73_EXT: |
2373 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2374 |
|
decodedcontroller.controller_number = 73; |
2375 |
|
break; |
2376 |
|
case _lev_ctrl_CC74_EXT: |
2377 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2378 |
|
decodedcontroller.controller_number = 74; |
2379 |
|
break; |
2380 |
|
case _lev_ctrl_CC75_EXT: |
2381 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2382 |
|
decodedcontroller.controller_number = 75; |
2383 |
|
break; |
2384 |
|
case _lev_ctrl_CC76_EXT: |
2385 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2386 |
|
decodedcontroller.controller_number = 76; |
2387 |
|
break; |
2388 |
|
case _lev_ctrl_CC77_EXT: |
2389 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2390 |
|
decodedcontroller.controller_number = 77; |
2391 |
|
break; |
2392 |
|
case _lev_ctrl_CC78_EXT: |
2393 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2394 |
|
decodedcontroller.controller_number = 78; |
2395 |
|
break; |
2396 |
|
case _lev_ctrl_CC79_EXT: |
2397 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2398 |
|
decodedcontroller.controller_number = 79; |
2399 |
|
break; |
2400 |
|
case _lev_ctrl_CC84_EXT: |
2401 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2402 |
|
decodedcontroller.controller_number = 84; |
2403 |
|
break; |
2404 |
|
case _lev_ctrl_CC85_EXT: |
2405 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2406 |
|
decodedcontroller.controller_number = 85; |
2407 |
|
break; |
2408 |
|
case _lev_ctrl_CC86_EXT: |
2409 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2410 |
|
decodedcontroller.controller_number = 86; |
2411 |
|
break; |
2412 |
|
case _lev_ctrl_CC87_EXT: |
2413 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2414 |
|
decodedcontroller.controller_number = 87; |
2415 |
|
break; |
2416 |
|
case _lev_ctrl_CC89_EXT: |
2417 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2418 |
|
decodedcontroller.controller_number = 89; |
2419 |
|
break; |
2420 |
|
case _lev_ctrl_CC90_EXT: |
2421 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2422 |
|
decodedcontroller.controller_number = 90; |
2423 |
|
break; |
2424 |
|
case _lev_ctrl_CC96_EXT: |
2425 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2426 |
|
decodedcontroller.controller_number = 96; |
2427 |
|
break; |
2428 |
|
case _lev_ctrl_CC97_EXT: |
2429 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2430 |
|
decodedcontroller.controller_number = 97; |
2431 |
|
break; |
2432 |
|
case _lev_ctrl_CC102_EXT: |
2433 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2434 |
|
decodedcontroller.controller_number = 102; |
2435 |
|
break; |
2436 |
|
case _lev_ctrl_CC103_EXT: |
2437 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2438 |
|
decodedcontroller.controller_number = 103; |
2439 |
|
break; |
2440 |
|
case _lev_ctrl_CC104_EXT: |
2441 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2442 |
|
decodedcontroller.controller_number = 104; |
2443 |
|
break; |
2444 |
|
case _lev_ctrl_CC105_EXT: |
2445 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2446 |
|
decodedcontroller.controller_number = 105; |
2447 |
|
break; |
2448 |
|
case _lev_ctrl_CC106_EXT: |
2449 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2450 |
|
decodedcontroller.controller_number = 106; |
2451 |
|
break; |
2452 |
|
case _lev_ctrl_CC107_EXT: |
2453 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2454 |
|
decodedcontroller.controller_number = 107; |
2455 |
|
break; |
2456 |
|
case _lev_ctrl_CC108_EXT: |
2457 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2458 |
|
decodedcontroller.controller_number = 108; |
2459 |
|
break; |
2460 |
|
case _lev_ctrl_CC109_EXT: |
2461 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2462 |
|
decodedcontroller.controller_number = 109; |
2463 |
|
break; |
2464 |
|
case _lev_ctrl_CC110_EXT: |
2465 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2466 |
|
decodedcontroller.controller_number = 110; |
2467 |
|
break; |
2468 |
|
case _lev_ctrl_CC111_EXT: |
2469 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2470 |
|
decodedcontroller.controller_number = 111; |
2471 |
|
break; |
2472 |
|
case _lev_ctrl_CC112_EXT: |
2473 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2474 |
|
decodedcontroller.controller_number = 112; |
2475 |
|
break; |
2476 |
|
case _lev_ctrl_CC113_EXT: |
2477 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2478 |
|
decodedcontroller.controller_number = 113; |
2479 |
|
break; |
2480 |
|
case _lev_ctrl_CC114_EXT: |
2481 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2482 |
|
decodedcontroller.controller_number = 114; |
2483 |
|
break; |
2484 |
|
case _lev_ctrl_CC115_EXT: |
2485 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2486 |
|
decodedcontroller.controller_number = 115; |
2487 |
|
break; |
2488 |
|
case _lev_ctrl_CC116_EXT: |
2489 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2490 |
|
decodedcontroller.controller_number = 116; |
2491 |
|
break; |
2492 |
|
case _lev_ctrl_CC117_EXT: |
2493 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2494 |
|
decodedcontroller.controller_number = 117; |
2495 |
|
break; |
2496 |
|
case _lev_ctrl_CC118_EXT: |
2497 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2498 |
|
decodedcontroller.controller_number = 118; |
2499 |
|
break; |
2500 |
|
case _lev_ctrl_CC119_EXT: |
2501 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2502 |
|
decodedcontroller.controller_number = 119; |
2503 |
|
break; |
2504 |
|
|
2505 |
// unknown controller type |
// unknown controller type |
2506 |
default: |
default: |
2507 |
throw gig::Exception("Unknown leverage controller type."); |
throw gig::Exception("Unknown leverage controller type."); |
2508 |
} |
} |
2509 |
return decodedcontroller; |
return decodedcontroller; |
2510 |
} |
} |
2511 |
|
|
2512 |
|
// see above (diagnostic push not supported prior GCC 4.6) |
2513 |
|
//#pragma GCC diagnostic pop |
2514 |
|
|
2515 |
DimensionRegion::_lev_ctrl_t DimensionRegion::EncodeLeverageController(leverage_ctrl_t DecodedController) { |
DimensionRegion::_lev_ctrl_t DimensionRegion::EncodeLeverageController(leverage_ctrl_t DecodedController) { |
2516 |
_lev_ctrl_t encodedcontroller; |
_lev_ctrl_t encodedcontroller; |
2598 |
case 95: |
case 95: |
2599 |
encodedcontroller = _lev_ctrl_effect5depth; |
encodedcontroller = _lev_ctrl_effect5depth; |
2600 |
break; |
break; |
2601 |
|
|
2602 |
|
// format extension (these controllers are so far only |
2603 |
|
// supported by LinuxSampler & gigedit) they will *NOT* |
2604 |
|
// work with Gigasampler/GigaStudio ! |
2605 |
|
case 3: |
2606 |
|
encodedcontroller = _lev_ctrl_CC3_EXT; |
2607 |
|
break; |
2608 |
|
case 6: |
2609 |
|
encodedcontroller = _lev_ctrl_CC6_EXT; |
2610 |
|
break; |
2611 |
|
case 7: |
2612 |
|
encodedcontroller = _lev_ctrl_CC7_EXT; |
2613 |
|
break; |
2614 |
|
case 8: |
2615 |
|
encodedcontroller = _lev_ctrl_CC8_EXT; |
2616 |
|
break; |
2617 |
|
case 9: |
2618 |
|
encodedcontroller = _lev_ctrl_CC9_EXT; |
2619 |
|
break; |
2620 |
|
case 10: |
2621 |
|
encodedcontroller = _lev_ctrl_CC10_EXT; |
2622 |
|
break; |
2623 |
|
case 11: |
2624 |
|
encodedcontroller = _lev_ctrl_CC11_EXT; |
2625 |
|
break; |
2626 |
|
case 14: |
2627 |
|
encodedcontroller = _lev_ctrl_CC14_EXT; |
2628 |
|
break; |
2629 |
|
case 15: |
2630 |
|
encodedcontroller = _lev_ctrl_CC15_EXT; |
2631 |
|
break; |
2632 |
|
case 20: |
2633 |
|
encodedcontroller = _lev_ctrl_CC20_EXT; |
2634 |
|
break; |
2635 |
|
case 21: |
2636 |
|
encodedcontroller = _lev_ctrl_CC21_EXT; |
2637 |
|
break; |
2638 |
|
case 22: |
2639 |
|
encodedcontroller = _lev_ctrl_CC22_EXT; |
2640 |
|
break; |
2641 |
|
case 23: |
2642 |
|
encodedcontroller = _lev_ctrl_CC23_EXT; |
2643 |
|
break; |
2644 |
|
case 24: |
2645 |
|
encodedcontroller = _lev_ctrl_CC24_EXT; |
2646 |
|
break; |
2647 |
|
case 25: |
2648 |
|
encodedcontroller = _lev_ctrl_CC25_EXT; |
2649 |
|
break; |
2650 |
|
case 26: |
2651 |
|
encodedcontroller = _lev_ctrl_CC26_EXT; |
2652 |
|
break; |
2653 |
|
case 27: |
2654 |
|
encodedcontroller = _lev_ctrl_CC27_EXT; |
2655 |
|
break; |
2656 |
|
case 28: |
2657 |
|
encodedcontroller = _lev_ctrl_CC28_EXT; |
2658 |
|
break; |
2659 |
|
case 29: |
2660 |
|
encodedcontroller = _lev_ctrl_CC29_EXT; |
2661 |
|
break; |
2662 |
|
case 30: |
2663 |
|
encodedcontroller = _lev_ctrl_CC30_EXT; |
2664 |
|
break; |
2665 |
|
case 31: |
2666 |
|
encodedcontroller = _lev_ctrl_CC31_EXT; |
2667 |
|
break; |
2668 |
|
case 68: |
2669 |
|
encodedcontroller = _lev_ctrl_CC68_EXT; |
2670 |
|
break; |
2671 |
|
case 69: |
2672 |
|
encodedcontroller = _lev_ctrl_CC69_EXT; |
2673 |
|
break; |
2674 |
|
case 70: |
2675 |
|
encodedcontroller = _lev_ctrl_CC70_EXT; |
2676 |
|
break; |
2677 |
|
case 71: |
2678 |
|
encodedcontroller = _lev_ctrl_CC71_EXT; |
2679 |
|
break; |
2680 |
|
case 72: |
2681 |
|
encodedcontroller = _lev_ctrl_CC72_EXT; |
2682 |
|
break; |
2683 |
|
case 73: |
2684 |
|
encodedcontroller = _lev_ctrl_CC73_EXT; |
2685 |
|
break; |
2686 |
|
case 74: |
2687 |
|
encodedcontroller = _lev_ctrl_CC74_EXT; |
2688 |
|
break; |
2689 |
|
case 75: |
2690 |
|
encodedcontroller = _lev_ctrl_CC75_EXT; |
2691 |
|
break; |
2692 |
|
case 76: |
2693 |
|
encodedcontroller = _lev_ctrl_CC76_EXT; |
2694 |
|
break; |
2695 |
|
case 77: |
2696 |
|
encodedcontroller = _lev_ctrl_CC77_EXT; |
2697 |
|
break; |
2698 |
|
case 78: |
2699 |
|
encodedcontroller = _lev_ctrl_CC78_EXT; |
2700 |
|
break; |
2701 |
|
case 79: |
2702 |
|
encodedcontroller = _lev_ctrl_CC79_EXT; |
2703 |
|
break; |
2704 |
|
case 84: |
2705 |
|
encodedcontroller = _lev_ctrl_CC84_EXT; |
2706 |
|
break; |
2707 |
|
case 85: |
2708 |
|
encodedcontroller = _lev_ctrl_CC85_EXT; |
2709 |
|
break; |
2710 |
|
case 86: |
2711 |
|
encodedcontroller = _lev_ctrl_CC86_EXT; |
2712 |
|
break; |
2713 |
|
case 87: |
2714 |
|
encodedcontroller = _lev_ctrl_CC87_EXT; |
2715 |
|
break; |
2716 |
|
case 89: |
2717 |
|
encodedcontroller = _lev_ctrl_CC89_EXT; |
2718 |
|
break; |
2719 |
|
case 90: |
2720 |
|
encodedcontroller = _lev_ctrl_CC90_EXT; |
2721 |
|
break; |
2722 |
|
case 96: |
2723 |
|
encodedcontroller = _lev_ctrl_CC96_EXT; |
2724 |
|
break; |
2725 |
|
case 97: |
2726 |
|
encodedcontroller = _lev_ctrl_CC97_EXT; |
2727 |
|
break; |
2728 |
|
case 102: |
2729 |
|
encodedcontroller = _lev_ctrl_CC102_EXT; |
2730 |
|
break; |
2731 |
|
case 103: |
2732 |
|
encodedcontroller = _lev_ctrl_CC103_EXT; |
2733 |
|
break; |
2734 |
|
case 104: |
2735 |
|
encodedcontroller = _lev_ctrl_CC104_EXT; |
2736 |
|
break; |
2737 |
|
case 105: |
2738 |
|
encodedcontroller = _lev_ctrl_CC105_EXT; |
2739 |
|
break; |
2740 |
|
case 106: |
2741 |
|
encodedcontroller = _lev_ctrl_CC106_EXT; |
2742 |
|
break; |
2743 |
|
case 107: |
2744 |
|
encodedcontroller = _lev_ctrl_CC107_EXT; |
2745 |
|
break; |
2746 |
|
case 108: |
2747 |
|
encodedcontroller = _lev_ctrl_CC108_EXT; |
2748 |
|
break; |
2749 |
|
case 109: |
2750 |
|
encodedcontroller = _lev_ctrl_CC109_EXT; |
2751 |
|
break; |
2752 |
|
case 110: |
2753 |
|
encodedcontroller = _lev_ctrl_CC110_EXT; |
2754 |
|
break; |
2755 |
|
case 111: |
2756 |
|
encodedcontroller = _lev_ctrl_CC111_EXT; |
2757 |
|
break; |
2758 |
|
case 112: |
2759 |
|
encodedcontroller = _lev_ctrl_CC112_EXT; |
2760 |
|
break; |
2761 |
|
case 113: |
2762 |
|
encodedcontroller = _lev_ctrl_CC113_EXT; |
2763 |
|
break; |
2764 |
|
case 114: |
2765 |
|
encodedcontroller = _lev_ctrl_CC114_EXT; |
2766 |
|
break; |
2767 |
|
case 115: |
2768 |
|
encodedcontroller = _lev_ctrl_CC115_EXT; |
2769 |
|
break; |
2770 |
|
case 116: |
2771 |
|
encodedcontroller = _lev_ctrl_CC116_EXT; |
2772 |
|
break; |
2773 |
|
case 117: |
2774 |
|
encodedcontroller = _lev_ctrl_CC117_EXT; |
2775 |
|
break; |
2776 |
|
case 118: |
2777 |
|
encodedcontroller = _lev_ctrl_CC118_EXT; |
2778 |
|
break; |
2779 |
|
case 119: |
2780 |
|
encodedcontroller = _lev_ctrl_CC119_EXT; |
2781 |
|
break; |
2782 |
|
|
2783 |
default: |
default: |
2784 |
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"); |
2785 |
} |
} |
3081 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
3082 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
3083 |
* |
* |
3084 |
|
* @param pProgress - callback function for progress notification |
3085 |
* @throws gig::Exception if samples cannot be dereferenced |
* @throws gig::Exception if samples cannot be dereferenced |
3086 |
*/ |
*/ |
3087 |
void Region::UpdateChunks() { |
void Region::UpdateChunks(progress_t* pProgress) { |
3088 |
// in the gig format we don't care about the Region's sample reference |
// in the gig format we don't care about the Region's sample reference |
3089 |
// but we still have to provide some existing one to not corrupt the |
// but we still have to provide some existing one to not corrupt the |
3090 |
// file, so to avoid the latter we simply always assign the sample of |
// file, so to avoid the latter we simply always assign the sample of |
3092 |
pSample = pDimensionRegions[0]->pSample; |
pSample = pDimensionRegions[0]->pSample; |
3093 |
|
|
3094 |
// first update base class's chunks |
// first update base class's chunks |
3095 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(pProgress); |
3096 |
|
|
3097 |
// update dimension region's chunks |
// update dimension region's chunks |
3098 |
for (int i = 0; i < DimensionRegions; i++) { |
for (int i = 0; i < DimensionRegions; i++) { |
3099 |
pDimensionRegions[i]->UpdateChunks(); |
pDimensionRegions[i]->UpdateChunks(pProgress); |
3100 |
} |
} |
3101 |
|
|
3102 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
3112 |
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
3113 |
|
|
3114 |
// move 3prg to last position |
// move 3prg to last position |
3115 |
pCkRegion->MoveSubChunk(pCkRegion->GetSubList(LIST_TYPE_3PRG), 0); |
pCkRegion->MoveSubChunk(pCkRegion->GetSubList(LIST_TYPE_3PRG), (RIFF::Chunk*)NULL); |
3116 |
} |
} |
3117 |
|
|
3118 |
// update dimension definitions in '3lnk' chunk |
// update dimension definitions in '3lnk' chunk |
3186 |
int step = 1; |
int step = 1; |
3187 |
for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits; |
for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits; |
3188 |
int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step; |
int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step; |
|
int end = step * pDimensionDefinitions[veldim].zones; |
|
3189 |
|
|
3190 |
// loop through all dimension regions for all dimensions except the velocity dimension |
// loop through all dimension regions for all dimensions except the velocity dimension |
3191 |
int dim[8] = { 0 }; |
int dim[8] = { 0 }; |
3192 |
for (int i = 0 ; i < DimensionRegions ; i++) { |
for (int i = 0 ; i < DimensionRegions ; i++) { |
3193 |
|
const int end = i + step * pDimensionDefinitions[veldim].zones; |
3194 |
|
|
3195 |
|
// create a velocity table for all cases where the velocity zone is zero |
3196 |
if (pDimensionRegions[i]->DimensionUpperLimits[veldim] || |
if (pDimensionRegions[i]->DimensionUpperLimits[veldim] || |
3197 |
pDimensionRegions[i]->VelocityUpperLimit) { |
pDimensionRegions[i]->VelocityUpperLimit) { |
3198 |
// create the velocity table |
// create the velocity table |
3223 |
} |
} |
3224 |
} |
} |
3225 |
|
|
3226 |
|
// jump to the next case where the velocity zone is zero |
3227 |
int j; |
int j; |
3228 |
int shift = 0; |
int shift = 0; |
3229 |
for (j = 0 ; j < Dimensions ; j++) { |
for (j = 0 ; j < Dimensions ; j++) { |
3260 |
* dimension bits limit is violated |
* dimension bits limit is violated |
3261 |
*/ |
*/ |
3262 |
void Region::AddDimension(dimension_def_t* pDimDef) { |
void Region::AddDimension(dimension_def_t* pDimDef) { |
3263 |
|
// some initial sanity checks of the given dimension definition |
3264 |
|
if (pDimDef->zones < 2) |
3265 |
|
throw gig::Exception("Could not add new dimension, amount of requested zones must always be at least two"); |
3266 |
|
if (pDimDef->bits < 1) |
3267 |
|
throw gig::Exception("Could not add new dimension, amount of requested requested zone bits must always be at least one"); |
3268 |
|
if (pDimDef->dimension == dimension_samplechannel) { |
3269 |
|
if (pDimDef->zones != 2) |
3270 |
|
throw gig::Exception("Could not add new 'sample channel' dimensions, the requested amount of zones must always be 2 for this dimension type"); |
3271 |
|
if (pDimDef->bits != 1) |
3272 |
|
throw gig::Exception("Could not add new 'sample channel' dimensions, the requested amount of zone bits must always be 1 for this dimension type"); |
3273 |
|
} |
3274 |
|
|
3275 |
// check if max. amount of dimensions reached |
// check if max. amount of dimensions reached |
3276 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3277 |
const int iMaxDimensions = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
3447 |
if (pDimDef->dimension == dimension_layer) Layers = 1; |
if (pDimDef->dimension == dimension_layer) Layers = 1; |
3448 |
} |
} |
3449 |
|
|
3450 |
|
/** @brief Delete one split zone of a dimension (decrement zone amount). |
3451 |
|
* |
3452 |
|
* Instead of deleting an entire dimensions, this method will only delete |
3453 |
|
* one particular split zone given by @a zone of the Region's dimension |
3454 |
|
* given by @a type. So this method will simply decrement the amount of |
3455 |
|
* zones by one of the dimension in question. To be able to do that, the |
3456 |
|
* respective dimension must exist on this Region and it must have at least |
3457 |
|
* 3 zones. All DimensionRegion objects associated with the zone will be |
3458 |
|
* deleted. |
3459 |
|
* |
3460 |
|
* @param type - identifies the dimension where a zone shall be deleted |
3461 |
|
* @param zone - index of the dimension split zone that shall be deleted |
3462 |
|
* @throws gig::Exception if requested zone could not be deleted |
3463 |
|
*/ |
3464 |
|
void Region::DeleteDimensionZone(dimension_t type, int zone) { |
3465 |
|
dimension_def_t* oldDef = GetDimensionDefinition(type); |
3466 |
|
if (!oldDef) |
3467 |
|
throw gig::Exception("Could not delete dimension zone, no such dimension of given type"); |
3468 |
|
if (oldDef->zones <= 2) |
3469 |
|
throw gig::Exception("Could not delete dimension zone, because it would end up with only one zone."); |
3470 |
|
if (zone < 0 || zone >= oldDef->zones) |
3471 |
|
throw gig::Exception("Could not delete dimension zone, requested zone index out of bounds."); |
3472 |
|
|
3473 |
|
const int newZoneSize = oldDef->zones - 1; |
3474 |
|
|
3475 |
|
// create a temporary Region which just acts as a temporary copy |
3476 |
|
// container and will be deleted at the end of this function and will |
3477 |
|
// also not be visible through the API during this process |
3478 |
|
gig::Region* tempRgn = NULL; |
3479 |
|
{ |
3480 |
|
// adding these temporary chunks is probably not even necessary |
3481 |
|
Instrument* instr = static_cast<Instrument*>(GetParent()); |
3482 |
|
RIFF::List* pCkInstrument = instr->pCkInstrument; |
3483 |
|
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN); |
3484 |
|
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
3485 |
|
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
3486 |
|
tempRgn = new Region(instr, rgn); |
3487 |
|
} |
3488 |
|
|
3489 |
|
// copy this region's dimensions (with already the dimension split size |
3490 |
|
// requested by the arguments of this method call) to the temporary |
3491 |
|
// region, and don't use Region::CopyAssign() here for this task, since |
3492 |
|
// it would also alter fast lookup helper variables here and there |
3493 |
|
dimension_def_t newDef; |
3494 |
|
for (int i = 0; i < Dimensions; ++i) { |
3495 |
|
dimension_def_t def = pDimensionDefinitions[i]; // copy, don't reference |
3496 |
|
// is this the dimension requested by the method arguments? ... |
3497 |
|
if (def.dimension == type) { // ... if yes, decrement zone amount by one |
3498 |
|
def.zones = newZoneSize; |
3499 |
|
if ((1 << (def.bits - 1)) == def.zones) def.bits--; |
3500 |
|
newDef = def; |
3501 |
|
} |
3502 |
|
tempRgn->AddDimension(&def); |
3503 |
|
} |
3504 |
|
|
3505 |
|
// find the dimension index in the tempRegion which is the dimension |
3506 |
|
// type passed to this method (paranoidly expecting different order) |
3507 |
|
int tempReducedDimensionIndex = -1; |
3508 |
|
for (int d = 0; d < tempRgn->Dimensions; ++d) { |
3509 |
|
if (tempRgn->pDimensionDefinitions[d].dimension == type) { |
3510 |
|
tempReducedDimensionIndex = d; |
3511 |
|
break; |
3512 |
|
} |
3513 |
|
} |
3514 |
|
|
3515 |
|
// copy dimension regions from this region to the temporary region |
3516 |
|
for (int iDst = 0; iDst < 256; ++iDst) { |
3517 |
|
DimensionRegion* dstDimRgn = tempRgn->pDimensionRegions[iDst]; |
3518 |
|
if (!dstDimRgn) continue; |
3519 |
|
std::map<dimension_t,int> dimCase; |
3520 |
|
bool isValidZone = true; |
3521 |
|
for (int d = 0, baseBits = 0; d < tempRgn->Dimensions; ++d) { |
3522 |
|
const int dstBits = tempRgn->pDimensionDefinitions[d].bits; |
3523 |
|
dimCase[tempRgn->pDimensionDefinitions[d].dimension] = |
3524 |
|
(iDst >> baseBits) & ((1 << dstBits) - 1); |
3525 |
|
baseBits += dstBits; |
3526 |
|
// there are also DimensionRegion objects of unused zones, skip them |
3527 |
|
if (dimCase[tempRgn->pDimensionDefinitions[d].dimension] >= tempRgn->pDimensionDefinitions[d].zones) { |
3528 |
|
isValidZone = false; |
3529 |
|
break; |
3530 |
|
} |
3531 |
|
} |
3532 |
|
if (!isValidZone) continue; |
3533 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3534 |
|
// have different order in source and destination regions |
3535 |
|
const bool isLastZone = (dimCase[type] == newZoneSize - 1); |
3536 |
|
if (dimCase[type] >= zone) dimCase[type]++; |
3537 |
|
DimensionRegion* srcDimRgn = GetDimensionRegionByBit(dimCase); |
3538 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3539 |
|
// if this is the upper most zone of the dimension passed to this |
3540 |
|
// method, then correct (raise) its upper limit to 127 |
3541 |
|
if (newDef.split_type == split_type_normal && isLastZone) |
3542 |
|
dstDimRgn->DimensionUpperLimits[tempReducedDimensionIndex] = 127; |
3543 |
|
} |
3544 |
|
|
3545 |
|
// now tempRegion's dimensions and DimensionRegions basically reflect |
3546 |
|
// what we wanted to get for this actual Region here, so we now just |
3547 |
|
// delete and recreate the dimension in question with the new amount |
3548 |
|
// zones and then copy back from tempRegion |
3549 |
|
DeleteDimension(oldDef); |
3550 |
|
AddDimension(&newDef); |
3551 |
|
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3552 |
|
DimensionRegion* srcDimRgn = tempRgn->pDimensionRegions[iSrc]; |
3553 |
|
if (!srcDimRgn) continue; |
3554 |
|
std::map<dimension_t,int> dimCase; |
3555 |
|
for (int d = 0, baseBits = 0; d < tempRgn->Dimensions; ++d) { |
3556 |
|
const int srcBits = tempRgn->pDimensionDefinitions[d].bits; |
3557 |
|
dimCase[tempRgn->pDimensionDefinitions[d].dimension] = |
3558 |
|
(iSrc >> baseBits) & ((1 << srcBits) - 1); |
3559 |
|
baseBits += srcBits; |
3560 |
|
} |
3561 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3562 |
|
// have different order in source and destination regions |
3563 |
|
DimensionRegion* dstDimRgn = GetDimensionRegionByBit(dimCase); |
3564 |
|
if (!dstDimRgn) continue; |
3565 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3566 |
|
} |
3567 |
|
|
3568 |
|
// delete temporary region |
3569 |
|
delete tempRgn; |
3570 |
|
|
3571 |
|
UpdateVelocityTable(); |
3572 |
|
} |
3573 |
|
|
3574 |
|
/** @brief Divide split zone of a dimension in two (increment zone amount). |
3575 |
|
* |
3576 |
|
* This will increment the amount of zones for the dimension (given by |
3577 |
|
* @a type) by one. It will do so by dividing the zone (given by @a zone) |
3578 |
|
* in the middle of its zone range in two. So the two zones resulting from |
3579 |
|
* the zone being splitted, will be an equivalent copy regarding all their |
3580 |
|
* articulation informations and sample reference. The two zones will only |
3581 |
|
* differ in their zone's upper limit |
3582 |
|
* (DimensionRegion::DimensionUpperLimits). |
3583 |
|
* |
3584 |
|
* @param type - identifies the dimension where a zone shall be splitted |
3585 |
|
* @param zone - index of the dimension split zone that shall be splitted |
3586 |
|
* @throws gig::Exception if requested zone could not be splitted |
3587 |
|
*/ |
3588 |
|
void Region::SplitDimensionZone(dimension_t type, int zone) { |
3589 |
|
dimension_def_t* oldDef = GetDimensionDefinition(type); |
3590 |
|
if (!oldDef) |
3591 |
|
throw gig::Exception("Could not split dimension zone, no such dimension of given type"); |
3592 |
|
if (zone < 0 || zone >= oldDef->zones) |
3593 |
|
throw gig::Exception("Could not split dimension zone, requested zone index out of bounds."); |
3594 |
|
|
3595 |
|
const int newZoneSize = oldDef->zones + 1; |
3596 |
|
|
3597 |
|
// create a temporary Region which just acts as a temporary copy |
3598 |
|
// container and will be deleted at the end of this function and will |
3599 |
|
// also not be visible through the API during this process |
3600 |
|
gig::Region* tempRgn = NULL; |
3601 |
|
{ |
3602 |
|
// adding these temporary chunks is probably not even necessary |
3603 |
|
Instrument* instr = static_cast<Instrument*>(GetParent()); |
3604 |
|
RIFF::List* pCkInstrument = instr->pCkInstrument; |
3605 |
|
RIFF::List* lrgn = pCkInstrument->GetSubList(LIST_TYPE_LRGN); |
3606 |
|
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
3607 |
|
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
3608 |
|
tempRgn = new Region(instr, rgn); |
3609 |
|
} |
3610 |
|
|
3611 |
|
// copy this region's dimensions (with already the dimension split size |
3612 |
|
// requested by the arguments of this method call) to the temporary |
3613 |
|
// region, and don't use Region::CopyAssign() here for this task, since |
3614 |
|
// it would also alter fast lookup helper variables here and there |
3615 |
|
dimension_def_t newDef; |
3616 |
|
for (int i = 0; i < Dimensions; ++i) { |
3617 |
|
dimension_def_t def = pDimensionDefinitions[i]; // copy, don't reference |
3618 |
|
// is this the dimension requested by the method arguments? ... |
3619 |
|
if (def.dimension == type) { // ... if yes, increment zone amount by one |
3620 |
|
def.zones = newZoneSize; |
3621 |
|
if ((1 << oldDef->bits) < newZoneSize) def.bits++; |
3622 |
|
newDef = def; |
3623 |
|
} |
3624 |
|
tempRgn->AddDimension(&def); |
3625 |
|
} |
3626 |
|
|
3627 |
|
// find the dimension index in the tempRegion which is the dimension |
3628 |
|
// type passed to this method (paranoidly expecting different order) |
3629 |
|
int tempIncreasedDimensionIndex = -1; |
3630 |
|
for (int d = 0; d < tempRgn->Dimensions; ++d) { |
3631 |
|
if (tempRgn->pDimensionDefinitions[d].dimension == type) { |
3632 |
|
tempIncreasedDimensionIndex = d; |
3633 |
|
break; |
3634 |
|
} |
3635 |
|
} |
3636 |
|
|
3637 |
|
// copy dimension regions from this region to the temporary region |
3638 |
|
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3639 |
|
DimensionRegion* srcDimRgn = pDimensionRegions[iSrc]; |
3640 |
|
if (!srcDimRgn) continue; |
3641 |
|
std::map<dimension_t,int> dimCase; |
3642 |
|
bool isValidZone = true; |
3643 |
|
for (int d = 0, baseBits = 0; d < Dimensions; ++d) { |
3644 |
|
const int srcBits = pDimensionDefinitions[d].bits; |
3645 |
|
dimCase[pDimensionDefinitions[d].dimension] = |
3646 |
|
(iSrc >> baseBits) & ((1 << srcBits) - 1); |
3647 |
|
// there are also DimensionRegion objects for unused zones, skip them |
3648 |
|
if (dimCase[pDimensionDefinitions[d].dimension] >= pDimensionDefinitions[d].zones) { |
3649 |
|
isValidZone = false; |
3650 |
|
break; |
3651 |
|
} |
3652 |
|
baseBits += srcBits; |
3653 |
|
} |
3654 |
|
if (!isValidZone) continue; |
3655 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3656 |
|
// have different order in source and destination regions |
3657 |
|
if (dimCase[type] > zone) dimCase[type]++; |
3658 |
|
DimensionRegion* dstDimRgn = tempRgn->GetDimensionRegionByBit(dimCase); |
3659 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3660 |
|
// if this is the requested zone to be splitted, then also copy |
3661 |
|
// the source DimensionRegion to the newly created target zone |
3662 |
|
// and set the old zones upper limit lower |
3663 |
|
if (dimCase[type] == zone) { |
3664 |
|
// lower old zones upper limit |
3665 |
|
if (newDef.split_type == split_type_normal) { |
3666 |
|
const int high = |
3667 |
|
dstDimRgn->DimensionUpperLimits[tempIncreasedDimensionIndex]; |
3668 |
|
int low = 0; |
3669 |
|
if (zone > 0) { |
3670 |
|
std::map<dimension_t,int> lowerCase = dimCase; |
3671 |
|
lowerCase[type]--; |
3672 |
|
DimensionRegion* dstDimRgnLow = tempRgn->GetDimensionRegionByBit(lowerCase); |
3673 |
|
low = dstDimRgnLow->DimensionUpperLimits[tempIncreasedDimensionIndex]; |
3674 |
|
} |
3675 |
|
dstDimRgn->DimensionUpperLimits[tempIncreasedDimensionIndex] = low + (high - low) / 2; |
3676 |
|
} |
3677 |
|
// fill the newly created zone of the divided zone as well |
3678 |
|
dimCase[type]++; |
3679 |
|
dstDimRgn = tempRgn->GetDimensionRegionByBit(dimCase); |
3680 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3681 |
|
} |
3682 |
|
} |
3683 |
|
|
3684 |
|
// now tempRegion's dimensions and DimensionRegions basically reflect |
3685 |
|
// what we wanted to get for this actual Region here, so we now just |
3686 |
|
// delete and recreate the dimension in question with the new amount |
3687 |
|
// zones and then copy back from tempRegion |
3688 |
|
DeleteDimension(oldDef); |
3689 |
|
AddDimension(&newDef); |
3690 |
|
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3691 |
|
DimensionRegion* srcDimRgn = tempRgn->pDimensionRegions[iSrc]; |
3692 |
|
if (!srcDimRgn) continue; |
3693 |
|
std::map<dimension_t,int> dimCase; |
3694 |
|
for (int d = 0, baseBits = 0; d < tempRgn->Dimensions; ++d) { |
3695 |
|
const int srcBits = tempRgn->pDimensionDefinitions[d].bits; |
3696 |
|
dimCase[tempRgn->pDimensionDefinitions[d].dimension] = |
3697 |
|
(iSrc >> baseBits) & ((1 << srcBits) - 1); |
3698 |
|
baseBits += srcBits; |
3699 |
|
} |
3700 |
|
// a bit paranoid: cope with the chance that the dimensions would |
3701 |
|
// have different order in source and destination regions |
3702 |
|
DimensionRegion* dstDimRgn = GetDimensionRegionByBit(dimCase); |
3703 |
|
if (!dstDimRgn) continue; |
3704 |
|
dstDimRgn->CopyAssign(srcDimRgn); |
3705 |
|
} |
3706 |
|
|
3707 |
|
// delete temporary region |
3708 |
|
delete tempRgn; |
3709 |
|
|
3710 |
|
UpdateVelocityTable(); |
3711 |
|
} |
3712 |
|
|
3713 |
|
/** @brief Change type of an existing dimension. |
3714 |
|
* |
3715 |
|
* Alters the dimension type of a dimension already existing on this |
3716 |
|
* region. If there is currently no dimension on this Region with type |
3717 |
|
* @a oldType, then this call with throw an Exception. Likewise there are |
3718 |
|
* cases where the requested dimension type cannot be performed. For example |
3719 |
|
* if the new dimension type shall be gig::dimension_samplechannel, and the |
3720 |
|
* current dimension has more than 2 zones. In such cases an Exception is |
3721 |
|
* thrown as well. |
3722 |
|
* |
3723 |
|
* @param oldType - identifies the existing dimension to be changed |
3724 |
|
* @param newType - to which dimension type it should be changed to |
3725 |
|
* @throws gig::Exception if requested change cannot be performed |
3726 |
|
*/ |
3727 |
|
void Region::SetDimensionType(dimension_t oldType, dimension_t newType) { |
3728 |
|
if (oldType == newType) return; |
3729 |
|
dimension_def_t* def = GetDimensionDefinition(oldType); |
3730 |
|
if (!def) |
3731 |
|
throw gig::Exception("No dimension with provided old dimension type exists on this region"); |
3732 |
|
if (newType == dimension_samplechannel && def->zones != 2) |
3733 |
|
throw gig::Exception("Cannot change to dimension type 'sample channel', because existing dimension does not have 2 zones"); |
3734 |
|
if (GetDimensionDefinition(newType)) |
3735 |
|
throw gig::Exception("There is already a dimension with requested new dimension type on this region"); |
3736 |
|
def->dimension = newType; |
3737 |
|
def->split_type = __resolveSplitType(newType); |
3738 |
|
} |
3739 |
|
|
3740 |
|
DimensionRegion* Region::GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase) { |
3741 |
|
uint8_t bits[8] = {}; |
3742 |
|
for (std::map<dimension_t,int>::const_iterator it = DimCase.begin(); |
3743 |
|
it != DimCase.end(); ++it) |
3744 |
|
{ |
3745 |
|
for (int d = 0; d < Dimensions; ++d) { |
3746 |
|
if (pDimensionDefinitions[d].dimension == it->first) { |
3747 |
|
bits[d] = it->second; |
3748 |
|
goto nextDimCaseSlice; |
3749 |
|
} |
3750 |
|
} |
3751 |
|
assert(false); // do crash ... too harsh maybe ? ignore it instead ? |
3752 |
|
nextDimCaseSlice: |
3753 |
|
; // noop |
3754 |
|
} |
3755 |
|
return GetDimensionRegionByBit(bits); |
3756 |
|
} |
3757 |
|
|
3758 |
|
/** |
3759 |
|
* Searches in the current Region for a dimension of the given dimension |
3760 |
|
* type and returns the precise configuration of that dimension in this |
3761 |
|
* Region. |
3762 |
|
* |
3763 |
|
* @param type - dimension type of the sought dimension |
3764 |
|
* @returns dimension definition or NULL if there is no dimension with |
3765 |
|
* sought type in this Region. |
3766 |
|
*/ |
3767 |
|
dimension_def_t* Region::GetDimensionDefinition(dimension_t type) { |
3768 |
|
for (int i = 0; i < Dimensions; ++i) |
3769 |
|
if (pDimensionDefinitions[i].dimension == type) |
3770 |
|
return &pDimensionDefinitions[i]; |
3771 |
|
return NULL; |
3772 |
|
} |
3773 |
|
|
3774 |
Region::~Region() { |
Region::~Region() { |
3775 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
3776 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
3798 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
3799 |
uint8_t bits; |
uint8_t bits; |
3800 |
int veldim = -1; |
int veldim = -1; |
3801 |
int velbitpos; |
int velbitpos = 0; |
3802 |
int bitpos = 0; |
int bitpos = 0; |
3803 |
int dimregidx = 0; |
int dimregidx = 0; |
3804 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
3828 |
} |
} |
3829 |
bitpos += pDimensionDefinitions[i].bits; |
bitpos += pDimensionDefinitions[i].bits; |
3830 |
} |
} |
3831 |
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
DimensionRegion* dimreg = pDimensionRegions[dimregidx & 255]; |
3832 |
|
if (!dimreg) return NULL; |
3833 |
if (veldim != -1) { |
if (veldim != -1) { |
3834 |
// (dimreg is now the dimension region for the lowest velocity) |
// (dimreg is now the dimension region for the lowest velocity) |
3835 |
if (dimreg->VelocityTable) // custom defined zone ranges |
if (dimreg->VelocityTable) // custom defined zone ranges |
3836 |
bits = dimreg->VelocityTable[DimValues[veldim]]; |
bits = dimreg->VelocityTable[DimValues[veldim] & 127]; |
3837 |
else // normal split type |
else // normal split type |
3838 |
bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size); |
bits = uint8_t((DimValues[veldim] & 127) / pDimensionDefinitions[veldim].zone_size); |
3839 |
|
|
3840 |
dimregidx |= bits << velbitpos; |
const uint8_t limiter_mask = (1 << pDimensionDefinitions[veldim].bits) - 1; |
3841 |
dimreg = pDimensionRegions[dimregidx]; |
dimregidx |= (bits & limiter_mask) << velbitpos; |
3842 |
|
dimreg = pDimensionRegions[dimregidx & 255]; |
3843 |
} |
} |
3844 |
return dimreg; |
return dimreg; |
3845 |
} |
} |
3846 |
|
|
3847 |
|
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
3848 |
|
uint8_t bits; |
3849 |
|
int veldim = -1; |
3850 |
|
int velbitpos = 0; |
3851 |
|
int bitpos = 0; |
3852 |
|
int dimregidx = 0; |
3853 |
|
for (uint i = 0; i < Dimensions; i++) { |
3854 |
|
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
3855 |
|
// the velocity dimension must be handled after the other dimensions |
3856 |
|
veldim = i; |
3857 |
|
velbitpos = bitpos; |
3858 |
|
} else { |
3859 |
|
switch (pDimensionDefinitions[i].split_type) { |
3860 |
|
case split_type_normal: |
3861 |
|
if (pDimensionRegions[0]->DimensionUpperLimits[i]) { |
3862 |
|
// gig3: all normal dimensions (not just the velocity dimension) have custom zone ranges |
3863 |
|
for (bits = 0 ; bits < pDimensionDefinitions[i].zones ; bits++) { |
3864 |
|
if (DimValues[i] <= pDimensionRegions[bits << bitpos]->DimensionUpperLimits[i]) break; |
3865 |
|
} |
3866 |
|
} else { |
3867 |
|
// gig2: evenly sized zones |
3868 |
|
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
3869 |
|
} |
3870 |
|
break; |
3871 |
|
case split_type_bit: // the value is already the sought dimension bit number |
3872 |
|
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
3873 |
|
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
3874 |
|
break; |
3875 |
|
} |
3876 |
|
dimregidx |= bits << bitpos; |
3877 |
|
} |
3878 |
|
bitpos += pDimensionDefinitions[i].bits; |
3879 |
|
} |
3880 |
|
dimregidx &= 255; |
3881 |
|
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
3882 |
|
if (!dimreg) return -1; |
3883 |
|
if (veldim != -1) { |
3884 |
|
// (dimreg is now the dimension region for the lowest velocity) |
3885 |
|
if (dimreg->VelocityTable) // custom defined zone ranges |
3886 |
|
bits = dimreg->VelocityTable[DimValues[veldim] & 127]; |
3887 |
|
else // normal split type |
3888 |
|
bits = uint8_t((DimValues[veldim] & 127) / pDimensionDefinitions[veldim].zone_size); |
3889 |
|
|
3890 |
|
const uint8_t limiter_mask = (1 << pDimensionDefinitions[veldim].bits) - 1; |
3891 |
|
dimregidx |= (bits & limiter_mask) << velbitpos; |
3892 |
|
dimregidx &= 255; |
3893 |
|
} |
3894 |
|
return dimregidx; |
3895 |
|
} |
3896 |
|
|
3897 |
/** |
/** |
3898 |
* Returns the appropriate DimensionRegion for the given dimension bit |
* Returns the appropriate DimensionRegion for the given dimension bit |
3899 |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
3932 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
3933 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3934 |
if (!file->pWavePoolTable) return NULL; |
if (!file->pWavePoolTable) return NULL; |
3935 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
// for new files or files >= 2 GB use 64 bit wave pool offsets |
3936 |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
if (file->pRIFF->IsNew() || (file->pRIFF->GetCurrentFileSize() >> 31)) { |
3937 |
Sample* sample = file->GetFirstSample(pProgress); |
// use 64 bit wave pool offsets (treating this as large file) |
3938 |
while (sample) { |
uint64_t soughtoffset = |
3939 |
if (sample->ulWavePoolOffset == soughtoffset && |
uint64_t(file->pWavePoolTable[WavePoolTableIndex]) | |
3940 |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
uint64_t(file->pWavePoolTableHi[WavePoolTableIndex]) << 32; |
3941 |
sample = file->GetNextSample(); |
Sample* sample = file->GetFirstSample(pProgress); |
3942 |
|
while (sample) { |
3943 |
|
if (sample->ullWavePoolOffset == soughtoffset) |
3944 |
|
return static_cast<gig::Sample*>(sample); |
3945 |
|
sample = file->GetNextSample(); |
3946 |
|
} |
3947 |
|
} else { |
3948 |
|
// use extension files and 32 bit wave pool offsets |
3949 |
|
file_offset_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
3950 |
|
file_offset_t soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
3951 |
|
Sample* sample = file->GetFirstSample(pProgress); |
3952 |
|
while (sample) { |
3953 |
|
if (sample->ullWavePoolOffset == soughtoffset && |
3954 |
|
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
3955 |
|
sample = file->GetNextSample(); |
3956 |
|
} |
3957 |
} |
} |
3958 |
return NULL; |
return NULL; |
3959 |
} |
} |
3960 |
|
|
3961 |
|
/** |
3962 |
|
* Make a (semi) deep copy of the Region object given by @a orig |
3963 |
|
* and assign it to this object. |
3964 |
|
* |
3965 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
3966 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
3967 |
|
* |
3968 |
|
* @param orig - original Region object to be copied from |
3969 |
|
*/ |
3970 |
|
void Region::CopyAssign(const Region* orig) { |
3971 |
|
CopyAssign(orig, NULL); |
3972 |
|
} |
3973 |
|
|
3974 |
|
/** |
3975 |
|
* Make a (semi) deep copy of the Region object given by @a orig and |
3976 |
|
* assign it to this object |
3977 |
|
* |
3978 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
3979 |
|
* this file's samples |
3980 |
|
*/ |
3981 |
|
void Region::CopyAssign(const Region* orig, const std::map<Sample*,Sample*>* mSamples) { |
3982 |
|
// handle base classes |
3983 |
|
DLS::Region::CopyAssign(orig); |
3984 |
|
|
3985 |
|
if (mSamples && mSamples->count((gig::Sample*)orig->pSample)) { |
3986 |
|
pSample = mSamples->find((gig::Sample*)orig->pSample)->second; |
3987 |
|
} |
3988 |
|
|
3989 |
|
// handle own member variables |
3990 |
|
for (int i = Dimensions - 1; i >= 0; --i) { |
3991 |
|
DeleteDimension(&pDimensionDefinitions[i]); |
3992 |
|
} |
3993 |
|
Layers = 0; // just to be sure |
3994 |
|
for (int i = 0; i < orig->Dimensions; i++) { |
3995 |
|
// we need to copy the dim definition here, to avoid the compiler |
3996 |
|
// complaining about const-ness issue |
3997 |
|
dimension_def_t def = orig->pDimensionDefinitions[i]; |
3998 |
|
AddDimension(&def); |
3999 |
|
} |
4000 |
|
for (int i = 0; i < 256; i++) { |
4001 |
|
if (pDimensionRegions[i] && orig->pDimensionRegions[i]) { |
4002 |
|
pDimensionRegions[i]->CopyAssign( |
4003 |
|
orig->pDimensionRegions[i], |
4004 |
|
mSamples |
4005 |
|
); |
4006 |
|
} |
4007 |
|
} |
4008 |
|
Layers = orig->Layers; |
4009 |
|
} |
4010 |
|
|
4011 |
|
|
4012 |
// *************** MidiRule *************** |
// *************** MidiRule *************** |
4013 |
// * |
// * |
4014 |
|
|
4015 |
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) { |
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) { |
4016 |
_3ewg->SetPos(36); |
_3ewg->SetPos(36); |
4017 |
Triggers = _3ewg->ReadUint8(); |
Triggers = _3ewg->ReadUint8(); |
4018 |
_3ewg->SetPos(40); |
_3ewg->SetPos(40); |
4019 |
ControllerNumber = _3ewg->ReadUint8(); |
ControllerNumber = _3ewg->ReadUint8(); |
4020 |
_3ewg->SetPos(46); |
_3ewg->SetPos(46); |
4021 |
for (int i = 0 ; i < Triggers ; i++) { |
for (int i = 0 ; i < Triggers ; i++) { |
4022 |
pTriggers[i].TriggerPoint = _3ewg->ReadUint8(); |
pTriggers[i].TriggerPoint = _3ewg->ReadUint8(); |
4023 |
pTriggers[i].Descending = _3ewg->ReadUint8(); |
pTriggers[i].Descending = _3ewg->ReadUint8(); |
4024 |
pTriggers[i].VelSensitivity = _3ewg->ReadUint8(); |
pTriggers[i].VelSensitivity = _3ewg->ReadUint8(); |
4025 |
pTriggers[i].Key = _3ewg->ReadUint8(); |
pTriggers[i].Key = _3ewg->ReadUint8(); |
4026 |
pTriggers[i].NoteOff = _3ewg->ReadUint8(); |
pTriggers[i].NoteOff = _3ewg->ReadUint8(); |
4027 |
pTriggers[i].Velocity = _3ewg->ReadUint8(); |
pTriggers[i].Velocity = _3ewg->ReadUint8(); |
4028 |
pTriggers[i].OverridePedal = _3ewg->ReadUint8(); |
pTriggers[i].OverridePedal = _3ewg->ReadUint8(); |
4029 |
_3ewg->ReadUint8(); |
_3ewg->ReadUint8(); |
4030 |
|
} |
4031 |
|
} |
4032 |
|
|
4033 |
|
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger() : |
4034 |
|
ControllerNumber(0), |
4035 |
|
Triggers(0) { |
4036 |
|
} |
4037 |
|
|
4038 |
|
void MidiRuleCtrlTrigger::UpdateChunks(uint8_t* pData) const { |
4039 |
|
pData[32] = 4; |
4040 |
|
pData[33] = 16; |
4041 |
|
pData[36] = Triggers; |
4042 |
|
pData[40] = ControllerNumber; |
4043 |
|
for (int i = 0 ; i < Triggers ; i++) { |
4044 |
|
pData[46 + i * 8] = pTriggers[i].TriggerPoint; |
4045 |
|
pData[47 + i * 8] = pTriggers[i].Descending; |
4046 |
|
pData[48 + i * 8] = pTriggers[i].VelSensitivity; |
4047 |
|
pData[49 + i * 8] = pTriggers[i].Key; |
4048 |
|
pData[50 + i * 8] = pTriggers[i].NoteOff; |
4049 |
|
pData[51 + i * 8] = pTriggers[i].Velocity; |
4050 |
|
pData[52 + i * 8] = pTriggers[i].OverridePedal; |
4051 |
|
} |
4052 |
|
} |
4053 |
|
|
4054 |
|
MidiRuleLegato::MidiRuleLegato(RIFF::Chunk* _3ewg) { |
4055 |
|
_3ewg->SetPos(36); |
4056 |
|
LegatoSamples = _3ewg->ReadUint8(); // always 12 |
4057 |
|
_3ewg->SetPos(40); |
4058 |
|
BypassUseController = _3ewg->ReadUint8(); |
4059 |
|
BypassKey = _3ewg->ReadUint8(); |
4060 |
|
BypassController = _3ewg->ReadUint8(); |
4061 |
|
ThresholdTime = _3ewg->ReadUint16(); |
4062 |
|
_3ewg->ReadInt16(); |
4063 |
|
ReleaseTime = _3ewg->ReadUint16(); |
4064 |
|
_3ewg->ReadInt16(); |
4065 |
|
KeyRange.low = _3ewg->ReadUint8(); |
4066 |
|
KeyRange.high = _3ewg->ReadUint8(); |
4067 |
|
_3ewg->SetPos(64); |
4068 |
|
ReleaseTriggerKey = _3ewg->ReadUint8(); |
4069 |
|
AltSustain1Key = _3ewg->ReadUint8(); |
4070 |
|
AltSustain2Key = _3ewg->ReadUint8(); |
4071 |
|
} |
4072 |
|
|
4073 |
|
MidiRuleLegato::MidiRuleLegato() : |
4074 |
|
LegatoSamples(12), |
4075 |
|
BypassUseController(false), |
4076 |
|
BypassKey(0), |
4077 |
|
BypassController(1), |
4078 |
|
ThresholdTime(20), |
4079 |
|
ReleaseTime(20), |
4080 |
|
ReleaseTriggerKey(0), |
4081 |
|
AltSustain1Key(0), |
4082 |
|
AltSustain2Key(0) |
4083 |
|
{ |
4084 |
|
KeyRange.low = KeyRange.high = 0; |
4085 |
} |
} |
|
} |
|
4086 |
|
|
4087 |
|
void MidiRuleLegato::UpdateChunks(uint8_t* pData) const { |
4088 |
|
pData[32] = 0; |
4089 |
|
pData[33] = 16; |
4090 |
|
pData[36] = LegatoSamples; |
4091 |
|
pData[40] = BypassUseController; |
4092 |
|
pData[41] = BypassKey; |
4093 |
|
pData[42] = BypassController; |
4094 |
|
store16(&pData[43], ThresholdTime); |
4095 |
|
store16(&pData[47], ReleaseTime); |
4096 |
|
pData[51] = KeyRange.low; |
4097 |
|
pData[52] = KeyRange.high; |
4098 |
|
pData[64] = ReleaseTriggerKey; |
4099 |
|
pData[65] = AltSustain1Key; |
4100 |
|
pData[66] = AltSustain2Key; |
4101 |
|
} |
4102 |
|
|
4103 |
|
MidiRuleAlternator::MidiRuleAlternator(RIFF::Chunk* _3ewg) { |
4104 |
|
_3ewg->SetPos(36); |
4105 |
|
Articulations = _3ewg->ReadUint8(); |
4106 |
|
int flags = _3ewg->ReadUint8(); |
4107 |
|
Polyphonic = flags & 8; |
4108 |
|
Chained = flags & 4; |
4109 |
|
Selector = (flags & 2) ? selector_controller : |
4110 |
|
(flags & 1) ? selector_key_switch : selector_none; |
4111 |
|
Patterns = _3ewg->ReadUint8(); |
4112 |
|
_3ewg->ReadUint8(); // chosen row |
4113 |
|
_3ewg->ReadUint8(); // unknown |
4114 |
|
_3ewg->ReadUint8(); // unknown |
4115 |
|
_3ewg->ReadUint8(); // unknown |
4116 |
|
KeySwitchRange.low = _3ewg->ReadUint8(); |
4117 |
|
KeySwitchRange.high = _3ewg->ReadUint8(); |
4118 |
|
Controller = _3ewg->ReadUint8(); |
4119 |
|
PlayRange.low = _3ewg->ReadUint8(); |
4120 |
|
PlayRange.high = _3ewg->ReadUint8(); |
4121 |
|
|
4122 |
|
int n = std::min(int(Articulations), 32); |
4123 |
|
for (int i = 0 ; i < n ; i++) { |
4124 |
|
_3ewg->ReadString(pArticulations[i], 32); |
4125 |
|
} |
4126 |
|
_3ewg->SetPos(1072); |
4127 |
|
n = std::min(int(Patterns), 32); |
4128 |
|
for (int i = 0 ; i < n ; i++) { |
4129 |
|
_3ewg->ReadString(pPatterns[i].Name, 16); |
4130 |
|
pPatterns[i].Size = _3ewg->ReadUint8(); |
4131 |
|
_3ewg->Read(&pPatterns[i][0], 1, 32); |
4132 |
|
} |
4133 |
|
} |
4134 |
|
|
4135 |
|
MidiRuleAlternator::MidiRuleAlternator() : |
4136 |
|
Articulations(0), |
4137 |
|
Patterns(0), |
4138 |
|
Selector(selector_none), |
4139 |
|
Controller(0), |
4140 |
|
Polyphonic(false), |
4141 |
|
Chained(false) |
4142 |
|
{ |
4143 |
|
PlayRange.low = PlayRange.high = 0; |
4144 |
|
KeySwitchRange.low = KeySwitchRange.high = 0; |
4145 |
|
} |
4146 |
|
|
4147 |
|
void MidiRuleAlternator::UpdateChunks(uint8_t* pData) const { |
4148 |
|
pData[32] = 3; |
4149 |
|
pData[33] = 16; |
4150 |
|
pData[36] = Articulations; |
4151 |
|
pData[37] = (Polyphonic ? 8 : 0) | (Chained ? 4 : 0) | |
4152 |
|
(Selector == selector_controller ? 2 : |
4153 |
|
(Selector == selector_key_switch ? 1 : 0)); |
4154 |
|
pData[38] = Patterns; |
4155 |
|
|
4156 |
|
pData[43] = KeySwitchRange.low; |
4157 |
|
pData[44] = KeySwitchRange.high; |
4158 |
|
pData[45] = Controller; |
4159 |
|
pData[46] = PlayRange.low; |
4160 |
|
pData[47] = PlayRange.high; |
4161 |
|
|
4162 |
|
char* str = reinterpret_cast<char*>(pData); |
4163 |
|
int pos = 48; |
4164 |
|
int n = std::min(int(Articulations), 32); |
4165 |
|
for (int i = 0 ; i < n ; i++, pos += 32) { |
4166 |
|
strncpy(&str[pos], pArticulations[i].c_str(), 32); |
4167 |
|
} |
4168 |
|
|
4169 |
|
pos = 1072; |
4170 |
|
n = std::min(int(Patterns), 32); |
4171 |
|
for (int i = 0 ; i < n ; i++, pos += 49) { |
4172 |
|
strncpy(&str[pos], pPatterns[i].Name.c_str(), 16); |
4173 |
|
pData[pos + 16] = pPatterns[i].Size; |
4174 |
|
memcpy(&pData[pos + 16], &(pPatterns[i][0]), 32); |
4175 |
|
} |
4176 |
|
} |
4177 |
|
|
4178 |
|
// *************** Script *************** |
4179 |
|
// * |
4180 |
|
|
4181 |
|
Script::Script(ScriptGroup* group, RIFF::Chunk* ckScri) { |
4182 |
|
pGroup = group; |
4183 |
|
pChunk = ckScri; |
4184 |
|
if (ckScri) { // object is loaded from file ... |
4185 |
|
// read header |
4186 |
|
uint32_t headerSize = ckScri->ReadUint32(); |
4187 |
|
Compression = (Compression_t) ckScri->ReadUint32(); |
4188 |
|
Encoding = (Encoding_t) ckScri->ReadUint32(); |
4189 |
|
Language = (Language_t) ckScri->ReadUint32(); |
4190 |
|
Bypass = (Language_t) ckScri->ReadUint32() & 1; |
4191 |
|
crc = ckScri->ReadUint32(); |
4192 |
|
uint32_t nameSize = ckScri->ReadUint32(); |
4193 |
|
Name.resize(nameSize, ' '); |
4194 |
|
for (int i = 0; i < nameSize; ++i) |
4195 |
|
Name[i] = ckScri->ReadUint8(); |
4196 |
|
// to handle potential future extensions of the header |
4197 |
|
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4198 |
|
// read actual script data |
4199 |
|
uint32_t scriptSize = uint32_t(ckScri->GetSize() - ckScri->GetPos()); |
4200 |
|
data.resize(scriptSize); |
4201 |
|
for (int i = 0; i < scriptSize; ++i) |
4202 |
|
data[i] = ckScri->ReadUint8(); |
4203 |
|
} else { // this is a new script object, so just initialize it as such ... |
4204 |
|
Compression = COMPRESSION_NONE; |
4205 |
|
Encoding = ENCODING_ASCII; |
4206 |
|
Language = LANGUAGE_NKSP; |
4207 |
|
Bypass = false; |
4208 |
|
crc = 0; |
4209 |
|
Name = "Unnamed Script"; |
4210 |
|
} |
4211 |
|
} |
4212 |
|
|
4213 |
|
Script::~Script() { |
4214 |
|
} |
4215 |
|
|
4216 |
|
/** |
4217 |
|
* Returns the current script (i.e. as source code) in text format. |
4218 |
|
*/ |
4219 |
|
String Script::GetScriptAsText() { |
4220 |
|
String s; |
4221 |
|
s.resize(data.size(), ' '); |
4222 |
|
memcpy(&s[0], &data[0], data.size()); |
4223 |
|
return s; |
4224 |
|
} |
4225 |
|
|
4226 |
|
/** |
4227 |
|
* Replaces the current script with the new script source code text given |
4228 |
|
* by @a text. |
4229 |
|
* |
4230 |
|
* @param text - new script source code |
4231 |
|
*/ |
4232 |
|
void Script::SetScriptAsText(const String& text) { |
4233 |
|
data.resize(text.size()); |
4234 |
|
memcpy(&data[0], &text[0], text.size()); |
4235 |
|
} |
4236 |
|
|
4237 |
|
/** |
4238 |
|
* Apply this script to the respective RIFF chunks. You have to call |
4239 |
|
* File::Save() to make changes persistent. |
4240 |
|
* |
4241 |
|
* Usually there is absolutely no need to call this method explicitly. |
4242 |
|
* It will be called automatically when File::Save() was called. |
4243 |
|
* |
4244 |
|
* @param pProgress - callback function for progress notification |
4245 |
|
*/ |
4246 |
|
void Script::UpdateChunks(progress_t* pProgress) { |
4247 |
|
// recalculate CRC32 check sum |
4248 |
|
__resetCRC(crc); |
4249 |
|
__calculateCRC(&data[0], data.size(), crc); |
4250 |
|
__finalizeCRC(crc); |
4251 |
|
// make sure chunk exists and has the required size |
4252 |
|
const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size(); |
4253 |
|
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
4254 |
|
else pChunk->Resize(chunkSize); |
4255 |
|
// fill the chunk data to be written to disk |
4256 |
|
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
4257 |
|
int pos = 0; |
4258 |
|
store32(&pData[pos], uint32_t(6*sizeof(int32_t) + Name.size())); // total header size |
4259 |
|
pos += sizeof(int32_t); |
4260 |
|
store32(&pData[pos], Compression); |
4261 |
|
pos += sizeof(int32_t); |
4262 |
|
store32(&pData[pos], Encoding); |
4263 |
|
pos += sizeof(int32_t); |
4264 |
|
store32(&pData[pos], Language); |
4265 |
|
pos += sizeof(int32_t); |
4266 |
|
store32(&pData[pos], Bypass ? 1 : 0); |
4267 |
|
pos += sizeof(int32_t); |
4268 |
|
store32(&pData[pos], crc); |
4269 |
|
pos += sizeof(int32_t); |
4270 |
|
store32(&pData[pos], (uint32_t) Name.size()); |
4271 |
|
pos += sizeof(int32_t); |
4272 |
|
for (int i = 0; i < Name.size(); ++i, ++pos) |
4273 |
|
pData[pos] = Name[i]; |
4274 |
|
for (int i = 0; i < data.size(); ++i, ++pos) |
4275 |
|
pData[pos] = data[i]; |
4276 |
|
} |
4277 |
|
|
4278 |
|
/** |
4279 |
|
* Move this script from its current ScriptGroup to another ScriptGroup |
4280 |
|
* given by @a pGroup. |
4281 |
|
* |
4282 |
|
* @param pGroup - script's new group |
4283 |
|
*/ |
4284 |
|
void Script::SetGroup(ScriptGroup* pGroup) { |
4285 |
|
if (this->pGroup == pGroup) return; |
4286 |
|
if (pChunk) |
4287 |
|
pChunk->GetParent()->MoveSubChunk(pChunk, pGroup->pList); |
4288 |
|
this->pGroup = pGroup; |
4289 |
|
} |
4290 |
|
|
4291 |
|
/** |
4292 |
|
* Returns the script group this script currently belongs to. Each script |
4293 |
|
* is a member of exactly one ScriptGroup. |
4294 |
|
* |
4295 |
|
* @returns current script group |
4296 |
|
*/ |
4297 |
|
ScriptGroup* Script::GetGroup() const { |
4298 |
|
return pGroup; |
4299 |
|
} |
4300 |
|
|
4301 |
|
void Script::RemoveAllScriptReferences() { |
4302 |
|
File* pFile = pGroup->pFile; |
4303 |
|
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4304 |
|
Instrument* instr = pFile->GetInstrument(i); |
4305 |
|
instr->RemoveScript(this); |
4306 |
|
} |
4307 |
|
} |
4308 |
|
|
4309 |
|
// *************** ScriptGroup *************** |
4310 |
|
// * |
4311 |
|
|
4312 |
|
ScriptGroup::ScriptGroup(File* file, RIFF::List* lstRTIS) { |
4313 |
|
pFile = file; |
4314 |
|
pList = lstRTIS; |
4315 |
|
pScripts = NULL; |
4316 |
|
if (lstRTIS) { |
4317 |
|
RIFF::Chunk* ckName = lstRTIS->GetSubChunk(CHUNK_ID_LSNM); |
4318 |
|
::LoadString(ckName, Name); |
4319 |
|
} else { |
4320 |
|
Name = "Default Group"; |
4321 |
|
} |
4322 |
|
} |
4323 |
|
|
4324 |
|
ScriptGroup::~ScriptGroup() { |
4325 |
|
if (pScripts) { |
4326 |
|
std::list<Script*>::iterator iter = pScripts->begin(); |
4327 |
|
std::list<Script*>::iterator end = pScripts->end(); |
4328 |
|
while (iter != end) { |
4329 |
|
delete *iter; |
4330 |
|
++iter; |
4331 |
|
} |
4332 |
|
delete pScripts; |
4333 |
|
} |
4334 |
|
} |
4335 |
|
|
4336 |
|
/** |
4337 |
|
* Apply this script group to the respective RIFF chunks. You have to call |
4338 |
|
* File::Save() to make changes persistent. |
4339 |
|
* |
4340 |
|
* Usually there is absolutely no need to call this method explicitly. |
4341 |
|
* It will be called automatically when File::Save() was called. |
4342 |
|
* |
4343 |
|
* @param pProgress - callback function for progress notification |
4344 |
|
*/ |
4345 |
|
void ScriptGroup::UpdateChunks(progress_t* pProgress) { |
4346 |
|
if (pScripts) { |
4347 |
|
if (!pList) |
4348 |
|
pList = pFile->pRIFF->GetSubList(LIST_TYPE_3LS)->AddSubList(LIST_TYPE_RTIS); |
4349 |
|
|
4350 |
|
// now store the name of this group as <LSNM> chunk as subchunk of the <RTIS> list chunk |
4351 |
|
::SaveString(CHUNK_ID_LSNM, NULL, pList, Name, String("Unnamed Group"), true, 64); |
4352 |
|
|
4353 |
|
for (std::list<Script*>::iterator it = pScripts->begin(); |
4354 |
|
it != pScripts->end(); ++it) |
4355 |
|
{ |
4356 |
|
(*it)->UpdateChunks(pProgress); |
4357 |
|
} |
4358 |
|
} |
4359 |
|
} |
4360 |
|
|
4361 |
|
/** @brief Get instrument script. |
4362 |
|
* |
4363 |
|
* Returns the real-time instrument script with the given index. |
4364 |
|
* |
4365 |
|
* @param index - number of the sought script (0..n) |
4366 |
|
* @returns sought script or NULL if there's no such script |
4367 |
|
*/ |
4368 |
|
Script* ScriptGroup::GetScript(uint index) { |
4369 |
|
if (!pScripts) LoadScripts(); |
4370 |
|
std::list<Script*>::iterator it = pScripts->begin(); |
4371 |
|
for (uint i = 0; it != pScripts->end(); ++i, ++it) |
4372 |
|
if (i == index) return *it; |
4373 |
|
return NULL; |
4374 |
|
} |
4375 |
|
|
4376 |
|
/** @brief Add new instrument script. |
4377 |
|
* |
4378 |
|
* Adds a new real-time instrument script to the file. The script is not |
4379 |
|
* actually used / executed unless it is referenced by an instrument to be |
4380 |
|
* used. This is similar to samples, which you can add to a file, without |
4381 |
|
* an instrument necessarily actually using it. |
4382 |
|
* |
4383 |
|
* You have to call Save() to make this persistent to the file. |
4384 |
|
* |
4385 |
|
* @return new empty script object |
4386 |
|
*/ |
4387 |
|
Script* ScriptGroup::AddScript() { |
4388 |
|
if (!pScripts) LoadScripts(); |
4389 |
|
Script* pScript = new Script(this, NULL); |
4390 |
|
pScripts->push_back(pScript); |
4391 |
|
return pScript; |
4392 |
|
} |
4393 |
|
|
4394 |
|
/** @brief Delete an instrument script. |
4395 |
|
* |
4396 |
|
* This will delete the given real-time instrument script. References of |
4397 |
|
* instruments that are using that script will be removed accordingly. |
4398 |
|
* |
4399 |
|
* You have to call Save() to make this persistent to the file. |
4400 |
|
* |
4401 |
|
* @param pScript - script to delete |
4402 |
|
* @throws gig::Exception if given script could not be found |
4403 |
|
*/ |
4404 |
|
void ScriptGroup::DeleteScript(Script* pScript) { |
4405 |
|
if (!pScripts) LoadScripts(); |
4406 |
|
std::list<Script*>::iterator iter = |
4407 |
|
find(pScripts->begin(), pScripts->end(), pScript); |
4408 |
|
if (iter == pScripts->end()) |
4409 |
|
throw gig::Exception("Could not delete script, could not find given script"); |
4410 |
|
pScripts->erase(iter); |
4411 |
|
pScript->RemoveAllScriptReferences(); |
4412 |
|
if (pScript->pChunk) |
4413 |
|
pScript->pChunk->GetParent()->DeleteSubChunk(pScript->pChunk); |
4414 |
|
delete pScript; |
4415 |
|
} |
4416 |
|
|
4417 |
|
void ScriptGroup::LoadScripts() { |
4418 |
|
if (pScripts) return; |
4419 |
|
pScripts = new std::list<Script*>; |
4420 |
|
if (!pList) return; |
4421 |
|
|
4422 |
|
for (RIFF::Chunk* ck = pList->GetFirstSubChunk(); ck; |
4423 |
|
ck = pList->GetNextSubChunk()) |
4424 |
|
{ |
4425 |
|
if (ck->GetChunkID() == CHUNK_ID_SCRI) { |
4426 |
|
pScripts->push_back(new Script(this, ck)); |
4427 |
|
} |
4428 |
|
} |
4429 |
|
} |
4430 |
|
|
4431 |
// *************** Instrument *************** |
// *************** Instrument *************** |
4432 |
// * |
// * |
4444 |
EffectSend = 0; |
EffectSend = 0; |
4445 |
Attenuation = 0; |
Attenuation = 0; |
4446 |
FineTune = 0; |
FineTune = 0; |
4447 |
PitchbendRange = 0; |
PitchbendRange = 2; |
4448 |
PianoReleaseMode = false; |
PianoReleaseMode = false; |
4449 |
DimensionKeyRange.low = 0; |
DimensionKeyRange.low = 0; |
4450 |
DimensionKeyRange.high = 0; |
DimensionKeyRange.high = 0; |
4451 |
pMidiRules = new MidiRule*[3]; |
pMidiRules = new MidiRule*[3]; |
4452 |
pMidiRules[0] = NULL; |
pMidiRules[0] = NULL; |
4453 |
|
pScriptRefs = NULL; |
4454 |
|
|
4455 |
// Loading |
// Loading |
4456 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
4473 |
uint8_t id1 = _3ewg->ReadUint8(); |
uint8_t id1 = _3ewg->ReadUint8(); |
4474 |
uint8_t id2 = _3ewg->ReadUint8(); |
uint8_t id2 = _3ewg->ReadUint8(); |
4475 |
|
|
4476 |
if (id1 == 4 && id2 == 16) { |
if (id2 == 16) { |
4477 |
pMidiRules[i++] = new MidiRuleCtrlTrigger(_3ewg); |
if (id1 == 4) { |
4478 |
|
pMidiRules[i++] = new MidiRuleCtrlTrigger(_3ewg); |
4479 |
|
} else if (id1 == 0) { |
4480 |
|
pMidiRules[i++] = new MidiRuleLegato(_3ewg); |
4481 |
|
} else if (id1 == 3) { |
4482 |
|
pMidiRules[i++] = new MidiRuleAlternator(_3ewg); |
4483 |
|
} else { |
4484 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
4485 |
|
} |
4486 |
|
} |
4487 |
|
else if (id1 != 0 || id2 != 0) { |
4488 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
4489 |
} |
} |
4490 |
//TODO: all the other types of rules |
//TODO: all the other types of rules |
4491 |
|
|
4511 |
} |
} |
4512 |
} |
} |
4513 |
|
|
4514 |
|
// own gig format extensions |
4515 |
|
RIFF::List* lst3LS = insList->GetSubList(LIST_TYPE_3LS); |
4516 |
|
if (lst3LS) { |
4517 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4518 |
|
if (ckSCSL) { |
4519 |
|
int headerSize = ckSCSL->ReadUint32(); |
4520 |
|
int slotCount = ckSCSL->ReadUint32(); |
4521 |
|
if (slotCount) { |
4522 |
|
int slotSize = ckSCSL->ReadUint32(); |
4523 |
|
ckSCSL->SetPos(headerSize); // in case of future header extensions |
4524 |
|
int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future slot extensions |
4525 |
|
for (int i = 0; i < slotCount; ++i) { |
4526 |
|
_ScriptPooolEntry e; |
4527 |
|
e.fileOffset = ckSCSL->ReadUint32(); |
4528 |
|
e.bypass = ckSCSL->ReadUint32() & 1; |
4529 |
|
if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions |
4530 |
|
scriptPoolFileOffsets.push_back(e); |
4531 |
|
} |
4532 |
|
} |
4533 |
|
} |
4534 |
|
} |
4535 |
|
|
4536 |
__notify_progress(pProgress, 1.0f); // notify done |
__notify_progress(pProgress, 1.0f); // notify done |
4537 |
} |
} |
4538 |
|
|
4549 |
} |
} |
4550 |
|
|
4551 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
4552 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
4553 |
|
delete pMidiRules[i]; |
4554 |
|
} |
4555 |
delete[] pMidiRules; |
delete[] pMidiRules; |
4556 |
|
if (pScriptRefs) delete pScriptRefs; |
4557 |
} |
} |
4558 |
|
|
4559 |
/** |
/** |
4563 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
4564 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
4565 |
* |
* |
4566 |
|
* @param pProgress - callback function for progress notification |
4567 |
* @throws gig::Exception if samples cannot be dereferenced |
* @throws gig::Exception if samples cannot be dereferenced |
4568 |
*/ |
*/ |
4569 |
void Instrument::UpdateChunks() { |
void Instrument::UpdateChunks(progress_t* pProgress) { |
4570 |
// first update base classes' chunks |
// first update base classes' chunks |
4571 |
DLS::Instrument::UpdateChunks(); |
DLS::Instrument::UpdateChunks(pProgress); |
4572 |
|
|
4573 |
// update Regions' chunks |
// update Regions' chunks |
4574 |
{ |
{ |
4575 |
RegionList::iterator iter = pRegions->begin(); |
RegionList::iterator iter = pRegions->begin(); |
4576 |
RegionList::iterator end = pRegions->end(); |
RegionList::iterator end = pRegions->end(); |
4577 |
for (; iter != end; ++iter) |
for (; iter != end; ++iter) |
4578 |
(*iter)->UpdateChunks(); |
(*iter)->UpdateChunks(pProgress); |
4579 |
} |
} |
4580 |
|
|
4581 |
// make sure 'lart' RIFF list chunk exists |
// make sure 'lart' RIFF list chunk exists |
4601 |
DimensionKeyRange.low << 1; |
DimensionKeyRange.low << 1; |
4602 |
pData[10] = dimkeystart; |
pData[10] = dimkeystart; |
4603 |
pData[11] = DimensionKeyRange.high; |
pData[11] = DimensionKeyRange.high; |
4604 |
|
|
4605 |
|
if (pMidiRules[0] == 0 && _3ewg->GetSize() >= 34) { |
4606 |
|
pData[32] = 0; |
4607 |
|
pData[33] = 0; |
4608 |
|
} else { |
4609 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
4610 |
|
pMidiRules[i]->UpdateChunks(pData); |
4611 |
|
} |
4612 |
|
} |
4613 |
|
|
4614 |
|
// own gig format extensions |
4615 |
|
if (ScriptSlotCount()) { |
4616 |
|
// make sure we have converted the original loaded script file |
4617 |
|
// offsets into valid Script object pointers |
4618 |
|
LoadScripts(); |
4619 |
|
|
4620 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4621 |
|
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
4622 |
|
const int slotCount = (int) pScriptRefs->size(); |
4623 |
|
const int headerSize = 3 * sizeof(uint32_t); |
4624 |
|
const int slotSize = 2 * sizeof(uint32_t); |
4625 |
|
const int totalChunkSize = headerSize + slotCount * slotSize; |
4626 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4627 |
|
if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalChunkSize); |
4628 |
|
else ckSCSL->Resize(totalChunkSize); |
4629 |
|
uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData(); |
4630 |
|
int pos = 0; |
4631 |
|
store32(&pData[pos], headerSize); |
4632 |
|
pos += sizeof(uint32_t); |
4633 |
|
store32(&pData[pos], slotCount); |
4634 |
|
pos += sizeof(uint32_t); |
4635 |
|
store32(&pData[pos], slotSize); |
4636 |
|
pos += sizeof(uint32_t); |
4637 |
|
for (int i = 0; i < slotCount; ++i) { |
4638 |
|
// arbitrary value, the actual file offset will be updated in |
4639 |
|
// UpdateScriptFileOffsets() after the file has been resized |
4640 |
|
int bogusFileOffset = 0; |
4641 |
|
store32(&pData[pos], bogusFileOffset); |
4642 |
|
pos += sizeof(uint32_t); |
4643 |
|
store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0); |
4644 |
|
pos += sizeof(uint32_t); |
4645 |
|
} |
4646 |
|
} else { |
4647 |
|
// no script slots, so get rid of any LS custom RIFF chunks (if any) |
4648 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4649 |
|
if (lst3LS) pCkInstrument->DeleteSubChunk(lst3LS); |
4650 |
|
} |
4651 |
|
} |
4652 |
|
|
4653 |
|
void Instrument::UpdateScriptFileOffsets() { |
4654 |
|
// own gig format extensions |
4655 |
|
if (pScriptRefs && pScriptRefs->size() > 0) { |
4656 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4657 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4658 |
|
const int slotCount = (int) pScriptRefs->size(); |
4659 |
|
const int headerSize = 3 * sizeof(uint32_t); |
4660 |
|
ckSCSL->SetPos(headerSize); |
4661 |
|
for (int i = 0; i < slotCount; ++i) { |
4662 |
|
uint32_t fileOffset = uint32_t( |
4663 |
|
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4664 |
|
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4665 |
|
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()) |
4666 |
|
); |
4667 |
|
ckSCSL->WriteUint32(&fileOffset); |
4668 |
|
// jump over flags entry (containing the bypass flag) |
4669 |
|
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
4670 |
|
} |
4671 |
|
} |
4672 |
} |
} |
4673 |
|
|
4674 |
/** |
/** |
4723 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
4724 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
4725 |
pRegions->push_back(pNewRegion); |
pRegions->push_back(pNewRegion); |
4726 |
Regions = pRegions->size(); |
Regions = (uint32_t) pRegions->size(); |
4727 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
4728 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
4729 |
// done |
// done |
4738 |
} |
} |
4739 |
|
|
4740 |
/** |
/** |
4741 |
|
* Move this instrument at the position before @arg dst. |
4742 |
|
* |
4743 |
|
* This method can be used to reorder the sequence of instruments in a |
4744 |
|
* .gig file. This might be helpful especially on large .gig files which |
4745 |
|
* contain a large number of instruments within the same .gig file. So |
4746 |
|
* grouping such instruments to similar ones, can help to keep track of them |
4747 |
|
* when working with such complex .gig files. |
4748 |
|
* |
4749 |
|
* When calling this method, this instrument will be removed from in its |
4750 |
|
* current position in the instruments list and moved to the requested |
4751 |
|
* target position provided by @param dst. You may also pass NULL as |
4752 |
|
* argument to this method, in that case this intrument will be moved to the |
4753 |
|
* very end of the .gig file's instrument list. |
4754 |
|
* |
4755 |
|
* You have to call Save() to make the order change persistent to the .gig |
4756 |
|
* file. |
4757 |
|
* |
4758 |
|
* Currently this method is limited to moving the instrument within the same |
4759 |
|
* .gig file. Trying to move it to another .gig file by calling this method |
4760 |
|
* will throw an exception. |
4761 |
|
* |
4762 |
|
* @param dst - destination instrument at which this instrument will be |
4763 |
|
* moved to, or pass NULL for moving to end of list |
4764 |
|
* @throw gig::Exception if this instrument and target instrument are not |
4765 |
|
* part of the same file |
4766 |
|
*/ |
4767 |
|
void Instrument::MoveTo(Instrument* dst) { |
4768 |
|
if (dst && GetParent() != dst->GetParent()) |
4769 |
|
throw Exception( |
4770 |
|
"gig::Instrument::MoveTo() can only be used for moving within " |
4771 |
|
"the same gig file." |
4772 |
|
); |
4773 |
|
|
4774 |
|
File* pFile = (File*) GetParent(); |
4775 |
|
|
4776 |
|
// move this instrument within the instrument list |
4777 |
|
{ |
4778 |
|
File::InstrumentList& list = *pFile->pInstruments; |
4779 |
|
|
4780 |
|
File::InstrumentList::iterator itFrom = |
4781 |
|
std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(this)); |
4782 |
|
|
4783 |
|
File::InstrumentList::iterator itTo = |
4784 |
|
std::find(list.begin(), list.end(), static_cast<DLS::Instrument*>(dst)); |
4785 |
|
|
4786 |
|
list.splice(itTo, list, itFrom); |
4787 |
|
} |
4788 |
|
|
4789 |
|
// move the instrument's actual list RIFF chunk appropriately |
4790 |
|
RIFF::List* lstCkInstruments = pFile->pRIFF->GetSubList(LIST_TYPE_LINS); |
4791 |
|
lstCkInstruments->MoveSubChunk( |
4792 |
|
this->pCkInstrument, |
4793 |
|
(RIFF::Chunk*) ((dst) ? dst->pCkInstrument : NULL) |
4794 |
|
); |
4795 |
|
} |
4796 |
|
|
4797 |
|
/** |
4798 |
* Returns a MIDI rule of the instrument. |
* Returns a MIDI rule of the instrument. |
4799 |
* |
* |
4800 |
* The list of MIDI rules, at least in gig v3, always contains at |
* The list of MIDI rules, at least in gig v3, always contains at |
4808 |
return pMidiRules[i]; |
return pMidiRules[i]; |
4809 |
} |
} |
4810 |
|
|
4811 |
|
/** |
4812 |
|
* Adds the "controller trigger" MIDI rule to the instrument. |
4813 |
|
* |
4814 |
|
* @returns the new MIDI rule |
4815 |
|
*/ |
4816 |
|
MidiRuleCtrlTrigger* Instrument::AddMidiRuleCtrlTrigger() { |
4817 |
|
delete pMidiRules[0]; |
4818 |
|
MidiRuleCtrlTrigger* r = new MidiRuleCtrlTrigger; |
4819 |
|
pMidiRules[0] = r; |
4820 |
|
pMidiRules[1] = 0; |
4821 |
|
return r; |
4822 |
|
} |
4823 |
|
|
4824 |
|
/** |
4825 |
|
* Adds the legato MIDI rule to the instrument. |
4826 |
|
* |
4827 |
|
* @returns the new MIDI rule |
4828 |
|
*/ |
4829 |
|
MidiRuleLegato* Instrument::AddMidiRuleLegato() { |
4830 |
|
delete pMidiRules[0]; |
4831 |
|
MidiRuleLegato* r = new MidiRuleLegato; |
4832 |
|
pMidiRules[0] = r; |
4833 |
|
pMidiRules[1] = 0; |
4834 |
|
return r; |
4835 |
|
} |
4836 |
|
|
4837 |
|
/** |
4838 |
|
* Adds the alternator MIDI rule to the instrument. |
4839 |
|
* |
4840 |
|
* @returns the new MIDI rule |
4841 |
|
*/ |
4842 |
|
MidiRuleAlternator* Instrument::AddMidiRuleAlternator() { |
4843 |
|
delete pMidiRules[0]; |
4844 |
|
MidiRuleAlternator* r = new MidiRuleAlternator; |
4845 |
|
pMidiRules[0] = r; |
4846 |
|
pMidiRules[1] = 0; |
4847 |
|
return r; |
4848 |
|
} |
4849 |
|
|
4850 |
|
/** |
4851 |
|
* Deletes a MIDI rule from the instrument. |
4852 |
|
* |
4853 |
|
* @param i - MIDI rule number |
4854 |
|
*/ |
4855 |
|
void Instrument::DeleteMidiRule(int i) { |
4856 |
|
delete pMidiRules[i]; |
4857 |
|
pMidiRules[i] = 0; |
4858 |
|
} |
4859 |
|
|
4860 |
|
void Instrument::LoadScripts() { |
4861 |
|
if (pScriptRefs) return; |
4862 |
|
pScriptRefs = new std::vector<_ScriptPooolRef>; |
4863 |
|
if (scriptPoolFileOffsets.empty()) return; |
4864 |
|
File* pFile = (File*) GetParent(); |
4865 |
|
for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) { |
4866 |
|
uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset; |
4867 |
|
for (uint i = 0; pFile->GetScriptGroup(i); ++i) { |
4868 |
|
ScriptGroup* group = pFile->GetScriptGroup(i); |
4869 |
|
for (uint s = 0; group->GetScript(s); ++s) { |
4870 |
|
Script* script = group->GetScript(s); |
4871 |
|
if (script->pChunk) { |
4872 |
|
uint32_t offset = uint32_t( |
4873 |
|
script->pChunk->GetFilePos() - |
4874 |
|
script->pChunk->GetPos() - |
4875 |
|
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()) |
4876 |
|
); |
4877 |
|
if (offset == soughtOffset) |
4878 |
|
{ |
4879 |
|
_ScriptPooolRef ref; |
4880 |
|
ref.script = script; |
4881 |
|
ref.bypass = scriptPoolFileOffsets[k].bypass; |
4882 |
|
pScriptRefs->push_back(ref); |
4883 |
|
break; |
4884 |
|
} |
4885 |
|
} |
4886 |
|
} |
4887 |
|
} |
4888 |
|
} |
4889 |
|
// we don't need that anymore |
4890 |
|
scriptPoolFileOffsets.clear(); |
4891 |
|
} |
4892 |
|
|
4893 |
|
/** @brief Get instrument script (gig format extension). |
4894 |
|
* |
4895 |
|
* Returns the real-time instrument script of instrument script slot |
4896 |
|
* @a index. |
4897 |
|
* |
4898 |
|
* @note This is an own format extension which did not exist i.e. in the |
4899 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4900 |
|
* gigedit. |
4901 |
|
* |
4902 |
|
* @param index - instrument script slot index |
4903 |
|
* @returns script or NULL if index is out of bounds |
4904 |
|
*/ |
4905 |
|
Script* Instrument::GetScriptOfSlot(uint index) { |
4906 |
|
LoadScripts(); |
4907 |
|
if (index >= pScriptRefs->size()) return NULL; |
4908 |
|
return pScriptRefs->at(index).script; |
4909 |
|
} |
4910 |
|
|
4911 |
|
/** @brief Add new instrument script slot (gig format extension). |
4912 |
|
* |
4913 |
|
* Add the given real-time instrument script reference to this instrument, |
4914 |
|
* which shall be executed by the sampler for for this instrument. The |
4915 |
|
* script will be added to the end of the script list of this instrument. |
4916 |
|
* The positions of the scripts in the Instrument's Script list are |
4917 |
|
* relevant, because they define in which order they shall be executed by |
4918 |
|
* the sampler. For this reason it is also legal to add the same script |
4919 |
|
* twice to an instrument, for example you might have a script called |
4920 |
|
* "MyFilter" which performs an event filter task, and you might have |
4921 |
|
* another script called "MyNoteTrigger" which triggers new notes, then you |
4922 |
|
* might for example have the following list of scripts on the instrument: |
4923 |
|
* |
4924 |
|
* 1. Script "MyFilter" |
4925 |
|
* 2. Script "MyNoteTrigger" |
4926 |
|
* 3. Script "MyFilter" |
4927 |
|
* |
4928 |
|
* Which would make sense, because the 2nd script launched new events, which |
4929 |
|
* you might need to filter as well. |
4930 |
|
* |
4931 |
|
* There are two ways to disable / "bypass" scripts. You can either disable |
4932 |
|
* a script locally for the respective script slot on an instrument (i.e. by |
4933 |
|
* passing @c false to the 2nd argument of this method, or by calling |
4934 |
|
* SetScriptBypassed()). Or you can disable a script globally for all slots |
4935 |
|
* and all instruments by setting Script::Bypass. |
4936 |
|
* |
4937 |
|
* @note This is an own format extension which did not exist i.e. in the |
4938 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4939 |
|
* gigedit. |
4940 |
|
* |
4941 |
|
* @param pScript - script that shall be executed for this instrument |
4942 |
|
* @param bypass - if enabled, the sampler shall skip executing this |
4943 |
|
* script (in the respective list position) |
4944 |
|
* @see SetScriptBypassed() |
4945 |
|
*/ |
4946 |
|
void Instrument::AddScriptSlot(Script* pScript, bool bypass) { |
4947 |
|
LoadScripts(); |
4948 |
|
_ScriptPooolRef ref = { pScript, bypass }; |
4949 |
|
pScriptRefs->push_back(ref); |
4950 |
|
} |
4951 |
|
|
4952 |
|
/** @brief Flip two script slots with each other (gig format extension). |
4953 |
|
* |
4954 |
|
* Swaps the position of the two given scripts in the Instrument's Script |
4955 |
|
* list. The positions of the scripts in the Instrument's Script list are |
4956 |
|
* relevant, because they define in which order they shall be executed by |
4957 |
|
* the sampler. |
4958 |
|
* |
4959 |
|
* @note This is an own format extension which did not exist i.e. in the |
4960 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4961 |
|
* gigedit. |
4962 |
|
* |
4963 |
|
* @param index1 - index of the first script slot to swap |
4964 |
|
* @param index2 - index of the second script slot to swap |
4965 |
|
*/ |
4966 |
|
void Instrument::SwapScriptSlots(uint index1, uint index2) { |
4967 |
|
LoadScripts(); |
4968 |
|
if (index1 >= pScriptRefs->size() || index2 >= pScriptRefs->size()) |
4969 |
|
return; |
4970 |
|
_ScriptPooolRef tmp = (*pScriptRefs)[index1]; |
4971 |
|
(*pScriptRefs)[index1] = (*pScriptRefs)[index2]; |
4972 |
|
(*pScriptRefs)[index2] = tmp; |
4973 |
|
} |
4974 |
|
|
4975 |
|
/** @brief Remove script slot. |
4976 |
|
* |
4977 |
|
* Removes the script slot with the given slot index. |
4978 |
|
* |
4979 |
|
* @param index - index of script slot to remove |
4980 |
|
*/ |
4981 |
|
void Instrument::RemoveScriptSlot(uint index) { |
4982 |
|
LoadScripts(); |
4983 |
|
if (index >= pScriptRefs->size()) return; |
4984 |
|
pScriptRefs->erase( pScriptRefs->begin() + index ); |
4985 |
|
} |
4986 |
|
|
4987 |
|
/** @brief Remove reference to given Script (gig format extension). |
4988 |
|
* |
4989 |
|
* This will remove all script slots on the instrument which are referencing |
4990 |
|
* the given script. |
4991 |
|
* |
4992 |
|
* @note This is an own format extension which did not exist i.e. in the |
4993 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
4994 |
|
* gigedit. |
4995 |
|
* |
4996 |
|
* @param pScript - script reference to remove from this instrument |
4997 |
|
* @see RemoveScriptSlot() |
4998 |
|
*/ |
4999 |
|
void Instrument::RemoveScript(Script* pScript) { |
5000 |
|
LoadScripts(); |
5001 |
|
for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) { |
5002 |
|
if ((*pScriptRefs)[i].script == pScript) { |
5003 |
|
pScriptRefs->erase( pScriptRefs->begin() + i ); |
5004 |
|
} |
5005 |
|
} |
5006 |
|
} |
5007 |
|
|
5008 |
|
/** @brief Instrument's amount of script slots. |
5009 |
|
* |
5010 |
|
* This method returns the amount of script slots this instrument currently |
5011 |
|
* uses. |
5012 |
|
* |
5013 |
|
* A script slot is a reference of a real-time instrument script to be |
5014 |
|
* executed by the sampler. The scripts will be executed by the sampler in |
5015 |
|
* sequence of the slots. One (same) script may be referenced multiple |
5016 |
|
* times in different slots. |
5017 |
|
* |
5018 |
|
* @note This is an own format extension which did not exist i.e. in the |
5019 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
5020 |
|
* gigedit. |
5021 |
|
*/ |
5022 |
|
uint Instrument::ScriptSlotCount() const { |
5023 |
|
return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size()); |
5024 |
|
} |
5025 |
|
|
5026 |
|
/** @brief Whether script execution shall be skipped. |
5027 |
|
* |
5028 |
|
* Defines locally for the Script reference slot in the Instrument's Script |
5029 |
|
* list, whether the script shall be skipped by the sampler regarding |
5030 |
|
* execution. |
5031 |
|
* |
5032 |
|
* It is also possible to ignore exeuction of the script globally, for all |
5033 |
|
* slots and for all instruments by setting Script::Bypass. |
5034 |
|
* |
5035 |
|
* @note This is an own format extension which did not exist i.e. in the |
5036 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
5037 |
|
* gigedit. |
5038 |
|
* |
5039 |
|
* @param index - index of the script slot on this instrument |
5040 |
|
* @see Script::Bypass |
5041 |
|
*/ |
5042 |
|
bool Instrument::IsScriptSlotBypassed(uint index) { |
5043 |
|
if (index >= ScriptSlotCount()) return false; |
5044 |
|
return pScriptRefs ? pScriptRefs->at(index).bypass |
5045 |
|
: scriptPoolFileOffsets.at(index).bypass; |
5046 |
|
|
5047 |
|
} |
5048 |
|
|
5049 |
|
/** @brief Defines whether execution shall be skipped. |
5050 |
|
* |
5051 |
|
* You can call this method to define locally whether or whether not the |
5052 |
|
* given script slot shall be executed by the sampler. |
5053 |
|
* |
5054 |
|
* @note This is an own format extension which did not exist i.e. in the |
5055 |
|
* GigaStudio 4 software. It will currently only work with LinuxSampler and |
5056 |
|
* gigedit. |
5057 |
|
* |
5058 |
|
* @param index - script slot index on this instrument |
5059 |
|
* @param bBypass - if true, the script slot will be skipped by the sampler |
5060 |
|
* @see Script::Bypass |
5061 |
|
*/ |
5062 |
|
void Instrument::SetScriptSlotBypassed(uint index, bool bBypass) { |
5063 |
|
if (index >= ScriptSlotCount()) return; |
5064 |
|
if (pScriptRefs) |
5065 |
|
pScriptRefs->at(index).bypass = bBypass; |
5066 |
|
else |
5067 |
|
scriptPoolFileOffsets.at(index).bypass = bBypass; |
5068 |
|
} |
5069 |
|
|
5070 |
|
/** |
5071 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
5072 |
|
* and assign it to this object. |
5073 |
|
* |
5074 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
5075 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
5076 |
|
* |
5077 |
|
* @param orig - original Instrument object to be copied from |
5078 |
|
*/ |
5079 |
|
void Instrument::CopyAssign(const Instrument* orig) { |
5080 |
|
CopyAssign(orig, NULL); |
5081 |
|
} |
5082 |
|
|
5083 |
|
/** |
5084 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
5085 |
|
* and assign it to this object. |
5086 |
|
* |
5087 |
|
* @param orig - original Instrument object to be copied from |
5088 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
5089 |
|
* this file's samples |
5090 |
|
*/ |
5091 |
|
void Instrument::CopyAssign(const Instrument* orig, const std::map<Sample*,Sample*>* mSamples) { |
5092 |
|
// handle base class |
5093 |
|
// (without copying DLS region stuff) |
5094 |
|
DLS::Instrument::CopyAssignCore(orig); |
5095 |
|
|
5096 |
|
// handle own member variables |
5097 |
|
Attenuation = orig->Attenuation; |
5098 |
|
EffectSend = orig->EffectSend; |
5099 |
|
FineTune = orig->FineTune; |
5100 |
|
PitchbendRange = orig->PitchbendRange; |
5101 |
|
PianoReleaseMode = orig->PianoReleaseMode; |
5102 |
|
DimensionKeyRange = orig->DimensionKeyRange; |
5103 |
|
scriptPoolFileOffsets = orig->scriptPoolFileOffsets; |
5104 |
|
pScriptRefs = orig->pScriptRefs; |
5105 |
|
|
5106 |
|
// free old midi rules |
5107 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
5108 |
|
delete pMidiRules[i]; |
5109 |
|
} |
5110 |
|
//TODO: MIDI rule copying |
5111 |
|
pMidiRules[0] = NULL; |
5112 |
|
|
5113 |
|
// delete all old regions |
5114 |
|
while (Regions) DeleteRegion(GetFirstRegion()); |
5115 |
|
// create new regions and copy them from original |
5116 |
|
{ |
5117 |
|
RegionList::const_iterator it = orig->pRegions->begin(); |
5118 |
|
for (int i = 0; i < orig->Regions; ++i, ++it) { |
5119 |
|
Region* dstRgn = AddRegion(); |
5120 |
|
//NOTE: Region does semi-deep copy ! |
5121 |
|
dstRgn->CopyAssign( |
5122 |
|
static_cast<gig::Region*>(*it), |
5123 |
|
mSamples |
5124 |
|
); |
5125 |
|
} |
5126 |
|
} |
5127 |
|
|
5128 |
|
UpdateRegionKeyTable(); |
5129 |
|
} |
5130 |
|
|
5131 |
|
|
5132 |
// *************** Group *************** |
// *************** Group *************** |
5133 |
// * |
// * |
5156 |
* |
* |
5157 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
5158 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
5159 |
|
* |
5160 |
|
* @param pProgress - callback function for progress notification |
5161 |
*/ |
*/ |
5162 |
void Group::UpdateChunks() { |
void Group::UpdateChunks(progress_t* pProgress) { |
5163 |
// make sure <3gri> and <3gnl> list chunks exist |
// make sure <3gri> and <3gnl> list chunks exist |
5164 |
RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); |
RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); |
5165 |
if (!_3gri) { |
if (!_3gri) { |
5289 |
bAutoLoad = true; |
bAutoLoad = true; |
5290 |
*pVersion = VERSION_3; |
*pVersion = VERSION_3; |
5291 |
pGroups = NULL; |
pGroups = NULL; |
5292 |
|
pScriptGroups = NULL; |
5293 |
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
5294 |
pInfo->ArchivalLocation = String(256, ' '); |
pInfo->ArchivalLocation = String(256, ' '); |
5295 |
|
|
5305 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
5306 |
bAutoLoad = true; |
bAutoLoad = true; |
5307 |
pGroups = NULL; |
pGroups = NULL; |
5308 |
|
pScriptGroups = NULL; |
5309 |
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
5310 |
} |
} |
5311 |
|
|
5319 |
} |
} |
5320 |
delete pGroups; |
delete pGroups; |
5321 |
} |
} |
5322 |
|
if (pScriptGroups) { |
5323 |
|
std::list<ScriptGroup*>::iterator iter = pScriptGroups->begin(); |
5324 |
|
std::list<ScriptGroup*>::iterator end = pScriptGroups->end(); |
5325 |
|
while (iter != end) { |
5326 |
|
delete *iter; |
5327 |
|
++iter; |
5328 |
|
} |
5329 |
|
delete pScriptGroups; |
5330 |
|
} |
5331 |
} |
} |
5332 |
|
|
5333 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
5342 |
SamplesIterator++; |
SamplesIterator++; |
5343 |
return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); |
return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); |
5344 |
} |
} |
5345 |
|
|
5346 |
|
/** |
5347 |
|
* Returns Sample object of @a index. |
5348 |
|
* |
5349 |
|
* @returns sample object or NULL if index is out of bounds |
5350 |
|
*/ |
5351 |
|
Sample* File::GetSample(uint index) { |
5352 |
|
if (!pSamples) LoadSamples(); |
5353 |
|
if (!pSamples) return NULL; |
5354 |
|
DLS::File::SampleList::iterator it = pSamples->begin(); |
5355 |
|
for (int i = 0; i < index; ++i) { |
5356 |
|
++it; |
5357 |
|
if (it == pSamples->end()) return NULL; |
5358 |
|
} |
5359 |
|
if (it == pSamples->end()) return NULL; |
5360 |
|
return static_cast<gig::Sample*>( *it ); |
5361 |
|
} |
5362 |
|
|
5363 |
/** @brief Add a new sample. |
/** @brief Add a new sample. |
5364 |
* |
* |
5436 |
int iTotalSamples = WavePoolCount; |
int iTotalSamples = WavePoolCount; |
5437 |
|
|
5438 |
// check if samples should be loaded from extension files |
// check if samples should be loaded from extension files |
5439 |
|
// (only for old gig files < 2 GB) |
5440 |
int lastFileNo = 0; |
int lastFileNo = 0; |
5441 |
for (int i = 0 ; i < WavePoolCount ; i++) { |
if (!file->IsNew() && !(file->GetCurrentFileSize() >> 31)) { |
5442 |
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
for (int i = 0 ; i < WavePoolCount ; i++) { |
5443 |
|
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
5444 |
|
} |
5445 |
} |
} |
5446 |
String name(pRIFF->GetFileName()); |
String name(pRIFF->GetFileName()); |
5447 |
int nameLen = name.length(); |
int nameLen = (int) name.length(); |
5448 |
char suffix[6]; |
char suffix[6]; |
5449 |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
5450 |
|
|
5451 |
for (int fileNo = 0 ; ; ) { |
for (int fileNo = 0 ; ; ) { |
5452 |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
5453 |
if (wvpl) { |
if (wvpl) { |
5454 |
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
file_offset_t wvplFileOffset = wvpl->GetFilePos(); |
5455 |
RIFF::List* wave = wvpl->GetFirstSubList(); |
RIFF::List* wave = wvpl->GetFirstSubList(); |
5456 |
while (wave) { |
while (wave) { |
5457 |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
5459 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
5460 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
5461 |
|
|
5462 |
unsigned long waveFileOffset = wave->GetFilePos(); |
file_offset_t waveFileOffset = wave->GetFilePos(); |
5463 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo, iSampleIndex)); |
5464 |
|
|
5465 |
iSampleIndex++; |
iSampleIndex++; |
5466 |
} |
} |
5559 |
pInstruments->push_back(pInstrument); |
pInstruments->push_back(pInstrument); |
5560 |
return pInstrument; |
return pInstrument; |
5561 |
} |
} |
5562 |
|
|
5563 |
|
/** @brief Add a duplicate of an existing instrument. |
5564 |
|
* |
5565 |
|
* Duplicates the instrument definition given by @a orig and adds it |
5566 |
|
* to this file. This allows in an instrument editor application to |
5567 |
|
* easily create variations of an instrument, which will be stored in |
5568 |
|
* the same .gig file, sharing i.e. the same samples. |
5569 |
|
* |
5570 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
5571 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
5572 |
|
* |
5573 |
|
* You have to call Save() to make this persistent to the file. |
5574 |
|
* |
5575 |
|
* @param orig - original instrument to be copied |
5576 |
|
* @returns duplicated copy of the given instrument |
5577 |
|
*/ |
5578 |
|
Instrument* File::AddDuplicateInstrument(const Instrument* orig) { |
5579 |
|
Instrument* instr = AddInstrument(); |
5580 |
|
instr->CopyAssign(orig); |
5581 |
|
return instr; |
5582 |
|
} |
5583 |
|
|
5584 |
|
/** @brief Add content of another existing file. |
5585 |
|
* |
5586 |
|
* Duplicates the samples, groups and instruments of the original file |
5587 |
|
* given by @a pFile and adds them to @c this File. In case @c this File is |
5588 |
|
* a new one that you haven't saved before, then you have to call |
5589 |
|
* SetFileName() before calling AddContentOf(), because this method will |
5590 |
|
* automatically save this file during operation, which is required for |
5591 |
|
* writing the sample waveform data by disk streaming. |
5592 |
|
* |
5593 |
|
* @param pFile - original file whose's content shall be copied from |
5594 |
|
*/ |
5595 |
|
void File::AddContentOf(File* pFile) { |
5596 |
|
static int iCallCount = -1; |
5597 |
|
iCallCount++; |
5598 |
|
std::map<Group*,Group*> mGroups; |
5599 |
|
std::map<Sample*,Sample*> mSamples; |
5600 |
|
|
5601 |
|
// clone sample groups |
5602 |
|
for (int i = 0; pFile->GetGroup(i); ++i) { |
5603 |
|
Group* g = AddGroup(); |
5604 |
|
g->Name = |
5605 |
|
"COPY" + ToString(iCallCount) + "_" + pFile->GetGroup(i)->Name; |
5606 |
|
mGroups[pFile->GetGroup(i)] = g; |
5607 |
|
} |
5608 |
|
|
5609 |
|
// clone samples (not waveform data here yet) |
5610 |
|
for (int i = 0; pFile->GetSample(i); ++i) { |
5611 |
|
Sample* s = AddSample(); |
5612 |
|
s->CopyAssignMeta(pFile->GetSample(i)); |
5613 |
|
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
5614 |
|
mSamples[pFile->GetSample(i)] = s; |
5615 |
|
} |
5616 |
|
|
5617 |
|
//BUG: For some reason this method only works with this additional |
5618 |
|
// Save() call in between here. |
5619 |
|
// |
5620 |
|
// Important: The correct one of the 2 Save() methods has to be called |
5621 |
|
// here, depending on whether the file is completely new or has been |
5622 |
|
// saved to disk already, otherwise it will result in data corruption. |
5623 |
|
if (pRIFF->IsNew()) |
5624 |
|
Save(GetFileName()); |
5625 |
|
else |
5626 |
|
Save(); |
5627 |
|
|
5628 |
|
// clone instruments |
5629 |
|
// (passing the crosslink table here for the cloned samples) |
5630 |
|
for (int i = 0; pFile->GetInstrument(i); ++i) { |
5631 |
|
Instrument* instr = AddInstrument(); |
5632 |
|
instr->CopyAssign(pFile->GetInstrument(i), &mSamples); |
5633 |
|
} |
5634 |
|
|
5635 |
|
// Mandatory: file needs to be saved to disk at this point, so this |
5636 |
|
// file has the correct size and data layout for writing the samples' |
5637 |
|
// waveform data to disk. |
5638 |
|
Save(); |
5639 |
|
|
5640 |
|
// clone samples' waveform data |
5641 |
|
// (using direct read & write disk streaming) |
5642 |
|
for (int i = 0; pFile->GetSample(i); ++i) { |
5643 |
|
mSamples[pFile->GetSample(i)]->CopyAssignWave(pFile->GetSample(i)); |
5644 |
|
} |
5645 |
|
} |
5646 |
|
|
5647 |
/** @brief Delete an instrument. |
/** @brief Delete an instrument. |
5648 |
* |
* |
5698 |
if (!_3crc) return; |
if (!_3crc) return; |
5699 |
|
|
5700 |
// get the index of the sample |
// get the index of the sample |
5701 |
int iWaveIndex = -1; |
int iWaveIndex = GetWaveTableIndexOf(pSample); |
|
File::SampleList::iterator iter = pSamples->begin(); |
|
|
File::SampleList::iterator end = pSamples->end(); |
|
|
for (int index = 0; iter != end; ++iter, ++index) { |
|
|
if (*iter == pSample) { |
|
|
iWaveIndex = index; |
|
|
break; |
|
|
} |
|
|
} |
|
5702 |
if (iWaveIndex < 0) throw gig::Exception("Could not update crc, could not find sample"); |
if (iWaveIndex < 0) throw gig::Exception("Could not update crc, could not find sample"); |
5703 |
|
|
5704 |
// write the CRC-32 checksum to disk |
// write the CRC-32 checksum to disk |
5705 |
_3crc->SetPos(iWaveIndex * 8); |
_3crc->SetPos(iWaveIndex * 8); |
5706 |
uint32_t tmp = 1; |
uint32_t one = 1; |
5707 |
_3crc->WriteUint32(&tmp); // unknown, always 1? |
_3crc->WriteUint32(&one); // always 1 |
5708 |
_3crc->WriteUint32(&crc); |
_3crc->WriteUint32(&crc); |
5709 |
} |
} |
5710 |
|
|
5711 |
|
uint32_t File::GetSampleChecksum(Sample* pSample) { |
5712 |
|
// get the index of the sample |
5713 |
|
int iWaveIndex = GetWaveTableIndexOf(pSample); |
5714 |
|
if (iWaveIndex < 0) throw gig::Exception("Could not retrieve reference crc of sample, could not resolve sample's wave table index"); |
5715 |
|
|
5716 |
|
return GetSampleChecksumByIndex(iWaveIndex); |
5717 |
|
} |
5718 |
|
|
5719 |
|
uint32_t File::GetSampleChecksumByIndex(int index) { |
5720 |
|
if (index < 0) throw gig::Exception("Could not retrieve reference crc of sample, invalid wave pool index of sample"); |
5721 |
|
|
5722 |
|
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
5723 |
|
if (!_3crc) throw gig::Exception("Could not retrieve reference crc of sample, no checksums stored for this file yet"); |
5724 |
|
uint8_t* pData = (uint8_t*) _3crc->LoadChunkData(); |
5725 |
|
if (!pData) throw gig::Exception("Could not retrieve reference crc of sample, no checksums stored for this file yet"); |
5726 |
|
|
5727 |
|
// read the CRC-32 checksum directly from disk |
5728 |
|
size_t pos = index * 8; |
5729 |
|
if (pos + 8 > _3crc->GetNewSize()) |
5730 |
|
throw gig::Exception("Could not retrieve reference crc of sample, could not seek to required position in crc chunk"); |
5731 |
|
|
5732 |
|
uint32_t one = load32(&pData[pos]); // always 1 |
5733 |
|
if (one != 1) |
5734 |
|
throw gig::Exception("Could not retrieve reference crc of sample, because reference checksum table is damaged"); |
5735 |
|
|
5736 |
|
return load32(&pData[pos+4]); |
5737 |
|
} |
5738 |
|
|
5739 |
|
int File::GetWaveTableIndexOf(gig::Sample* pSample) { |
5740 |
|
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
5741 |
|
File::SampleList::iterator iter = pSamples->begin(); |
5742 |
|
File::SampleList::iterator end = pSamples->end(); |
5743 |
|
for (int index = 0; iter != end; ++iter, ++index) |
5744 |
|
if (*iter == pSample) |
5745 |
|
return index; |
5746 |
|
return -1; |
5747 |
|
} |
5748 |
|
|
5749 |
|
/** |
5750 |
|
* Checks whether the file's "3CRC" chunk was damaged. This chunk contains |
5751 |
|
* the CRC32 check sums of all samples' raw wave data. |
5752 |
|
* |
5753 |
|
* @return true if 3CRC chunk is OK, or false if 3CRC chunk is damaged |
5754 |
|
*/ |
5755 |
|
bool File::VerifySampleChecksumTable() { |
5756 |
|
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
5757 |
|
if (!_3crc) return false; |
5758 |
|
if (_3crc->GetNewSize() <= 0) return false; |
5759 |
|
if (_3crc->GetNewSize() % 8) return false; |
5760 |
|
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
5761 |
|
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
5762 |
|
|
5763 |
|
const file_offset_t n = _3crc->GetNewSize() / 8; |
5764 |
|
|
5765 |
|
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
5766 |
|
if (!pData) return false; |
5767 |
|
|
5768 |
|
for (file_offset_t i = 0; i < n; ++i) { |
5769 |
|
uint32_t one = pData[i*2]; |
5770 |
|
if (one != 1) return false; |
5771 |
|
} |
5772 |
|
|
5773 |
|
return true; |
5774 |
|
} |
5775 |
|
|
5776 |
|
/** |
5777 |
|
* Recalculates CRC32 checksums for all samples and rebuilds this gig |
5778 |
|
* file's checksum table with those new checksums. This might usually |
5779 |
|
* just be necessary if the checksum table was damaged. |
5780 |
|
* |
5781 |
|
* @e IMPORTANT: The current implementation of this method only works |
5782 |
|
* with files that have not been modified since it was loaded, because |
5783 |
|
* it expects that no externally caused file structure changes are |
5784 |
|
* required! |
5785 |
|
* |
5786 |
|
* Due to the expectation above, this method is currently protected |
5787 |
|
* and actually only used by the command line tool "gigdump" yet. |
5788 |
|
* |
5789 |
|
* @returns true if Save() is required to be called after this call, |
5790 |
|
* false if no further action is required |
5791 |
|
*/ |
5792 |
|
bool File::RebuildSampleChecksumTable() { |
5793 |
|
// make sure sample chunks were scanned |
5794 |
|
if (!pSamples) GetFirstSample(); |
5795 |
|
|
5796 |
|
bool bRequiresSave = false; |
5797 |
|
|
5798 |
|
// make sure "3CRC" chunk exists with required size |
5799 |
|
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
5800 |
|
if (!_3crc) { |
5801 |
|
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
5802 |
|
// the order of einf and 3crc is not the same in v2 and v3 |
5803 |
|
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
5804 |
|
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
5805 |
|
bRequiresSave = true; |
5806 |
|
} else if (_3crc->GetNewSize() != pSamples->size() * 8) { |
5807 |
|
_3crc->Resize(pSamples->size() * 8); |
5808 |
|
bRequiresSave = true; |
5809 |
|
} |
5810 |
|
|
5811 |
|
if (bRequiresSave) { // refill CRC table for all samples in RAM ... |
5812 |
|
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
5813 |
|
{ |
5814 |
|
File::SampleList::iterator iter = pSamples->begin(); |
5815 |
|
File::SampleList::iterator end = pSamples->end(); |
5816 |
|
for (; iter != end; ++iter) { |
5817 |
|
gig::Sample* pSample = (gig::Sample*) *iter; |
5818 |
|
int index = GetWaveTableIndexOf(pSample); |
5819 |
|
if (index < 0) throw gig::Exception("Could not rebuild crc table for samples, wave table index of a sample could not be resolved"); |
5820 |
|
pData[index*2] = 1; // always 1 |
5821 |
|
pData[index*2+1] = pSample->CalculateWaveDataChecksum(); |
5822 |
|
} |
5823 |
|
} |
5824 |
|
} else { // no file structure changes necessary, so directly write to disk and we are done ... |
5825 |
|
// make sure file is in write mode |
5826 |
|
pRIFF->SetMode(RIFF::stream_mode_read_write); |
5827 |
|
{ |
5828 |
|
File::SampleList::iterator iter = pSamples->begin(); |
5829 |
|
File::SampleList::iterator end = pSamples->end(); |
5830 |
|
for (; iter != end; ++iter) { |
5831 |
|
gig::Sample* pSample = (gig::Sample*) *iter; |
5832 |
|
int index = GetWaveTableIndexOf(pSample); |
5833 |
|
if (index < 0) throw gig::Exception("Could not rebuild crc table for samples, wave table index of a sample could not be resolved"); |
5834 |
|
pSample->crc = pSample->CalculateWaveDataChecksum(); |
5835 |
|
SetSampleChecksum(pSample, pSample->crc); |
5836 |
|
} |
5837 |
|
} |
5838 |
|
} |
5839 |
|
|
5840 |
|
return bRequiresSave; |
5841 |
|
} |
5842 |
|
|
5843 |
Group* File::GetFirstGroup() { |
Group* File::GetFirstGroup() { |
5844 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
5845 |
// there must always be at least one group |
// there must always be at least one group |
5869 |
return NULL; |
return NULL; |
5870 |
} |
} |
5871 |
|
|
5872 |
|
/** |
5873 |
|
* Returns the group with the given group name. |
5874 |
|
* |
5875 |
|
* Note: group names don't have to be unique in the gig format! So there |
5876 |
|
* can be multiple groups with the same name. This method will simply |
5877 |
|
* return the first group found with the given name. |
5878 |
|
* |
5879 |
|
* @param name - name of the sought group |
5880 |
|
* @returns sought group or NULL if there's no group with that name |
5881 |
|
*/ |
5882 |
|
Group* File::GetGroup(String name) { |
5883 |
|
if (!pGroups) LoadGroups(); |
5884 |
|
GroupsIterator = pGroups->begin(); |
5885 |
|
for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i) |
5886 |
|
if ((*GroupsIterator)->Name == name) return *GroupsIterator; |
5887 |
|
return NULL; |
5888 |
|
} |
5889 |
|
|
5890 |
Group* File::AddGroup() { |
Group* File::AddGroup() { |
5891 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
5892 |
// there must always be at least one group |
// there must always be at least one group |
5967 |
} |
} |
5968 |
} |
} |
5969 |
|
|
5970 |
|
/** @brief Get instrument script group (by index). |
5971 |
|
* |
5972 |
|
* Returns the real-time instrument script group with the given index. |
5973 |
|
* |
5974 |
|
* @param index - number of the sought group (0..n) |
5975 |
|
* @returns sought script group or NULL if there's no such group |
5976 |
|
*/ |
5977 |
|
ScriptGroup* File::GetScriptGroup(uint index) { |
5978 |
|
if (!pScriptGroups) LoadScriptGroups(); |
5979 |
|
std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
5980 |
|
for (uint i = 0; it != pScriptGroups->end(); ++i, ++it) |
5981 |
|
if (i == index) return *it; |
5982 |
|
return NULL; |
5983 |
|
} |
5984 |
|
|
5985 |
|
/** @brief Get instrument script group (by name). |
5986 |
|
* |
5987 |
|
* Returns the first real-time instrument script group found with the given |
5988 |
|
* group name. Note that group names may not necessarily be unique. |
5989 |
|
* |
5990 |
|
* @param name - name of the sought script group |
5991 |
|
* @returns sought script group or NULL if there's no such group |
5992 |
|
*/ |
5993 |
|
ScriptGroup* File::GetScriptGroup(const String& name) { |
5994 |
|
if (!pScriptGroups) LoadScriptGroups(); |
5995 |
|
std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
5996 |
|
for (uint i = 0; it != pScriptGroups->end(); ++i, ++it) |
5997 |
|
if ((*it)->Name == name) return *it; |
5998 |
|
return NULL; |
5999 |
|
} |
6000 |
|
|
6001 |
|
/** @brief Add new instrument script group. |
6002 |
|
* |
6003 |
|
* Adds a new, empty real-time instrument script group to the file. |
6004 |
|
* |
6005 |
|
* You have to call Save() to make this persistent to the file. |
6006 |
|
* |
6007 |
|
* @return new empty script group |
6008 |
|
*/ |
6009 |
|
ScriptGroup* File::AddScriptGroup() { |
6010 |
|
if (!pScriptGroups) LoadScriptGroups(); |
6011 |
|
ScriptGroup* pScriptGroup = new ScriptGroup(this, NULL); |
6012 |
|
pScriptGroups->push_back(pScriptGroup); |
6013 |
|
return pScriptGroup; |
6014 |
|
} |
6015 |
|
|
6016 |
|
/** @brief Delete an instrument script group. |
6017 |
|
* |
6018 |
|
* This will delete the given real-time instrument script group and all its |
6019 |
|
* instrument scripts it contains. References inside instruments that are |
6020 |
|
* using the deleted scripts will be removed from the respective instruments |
6021 |
|
* accordingly. |
6022 |
|
* |
6023 |
|
* You have to call Save() to make this persistent to the file. |
6024 |
|
* |
6025 |
|
* @param pScriptGroup - script group to delete |
6026 |
|
* @throws gig::Exception if given script group could not be found |
6027 |
|
*/ |
6028 |
|
void File::DeleteScriptGroup(ScriptGroup* pScriptGroup) { |
6029 |
|
if (!pScriptGroups) LoadScriptGroups(); |
6030 |
|
std::list<ScriptGroup*>::iterator iter = |
6031 |
|
find(pScriptGroups->begin(), pScriptGroups->end(), pScriptGroup); |
6032 |
|
if (iter == pScriptGroups->end()) |
6033 |
|
throw gig::Exception("Could not delete script group, could not find given script group"); |
6034 |
|
pScriptGroups->erase(iter); |
6035 |
|
for (int i = 0; pScriptGroup->GetScript(i); ++i) |
6036 |
|
pScriptGroup->DeleteScript(pScriptGroup->GetScript(i)); |
6037 |
|
if (pScriptGroup->pList) |
6038 |
|
pScriptGroup->pList->GetParent()->DeleteSubChunk(pScriptGroup->pList); |
6039 |
|
delete pScriptGroup; |
6040 |
|
} |
6041 |
|
|
6042 |
|
void File::LoadScriptGroups() { |
6043 |
|
if (pScriptGroups) return; |
6044 |
|
pScriptGroups = new std::list<ScriptGroup*>; |
6045 |
|
RIFF::List* lstLS = pRIFF->GetSubList(LIST_TYPE_3LS); |
6046 |
|
if (lstLS) { |
6047 |
|
for (RIFF::List* lst = lstLS->GetFirstSubList(); lst; |
6048 |
|
lst = lstLS->GetNextSubList()) |
6049 |
|
{ |
6050 |
|
if (lst->GetListType() == LIST_TYPE_RTIS) { |
6051 |
|
pScriptGroups->push_back(new ScriptGroup(this, lst)); |
6052 |
|
} |
6053 |
|
} |
6054 |
|
} |
6055 |
|
} |
6056 |
|
|
6057 |
/** |
/** |
6058 |
* Apply all the gig file's current instruments, samples, groups and settings |
* Apply all the gig file's current instruments, samples, groups and settings |
6059 |
* to the respective RIFF chunks. You have to call Save() to make changes |
* to the respective RIFF chunks. You have to call Save() to make changes |
6062 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
6063 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
6064 |
* |
* |
6065 |
|
* @param pProgress - callback function for progress notification |
6066 |
* @throws Exception - on errors |
* @throws Exception - on errors |
6067 |
*/ |
*/ |
6068 |
void File::UpdateChunks() { |
void File::UpdateChunks(progress_t* pProgress) { |
6069 |
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
6070 |
|
|
6071 |
b64BitWavePoolOffsets = pVersion && pVersion->major == 3; |
// update own gig format extension chunks |
6072 |
|
// (not part of the GigaStudio 4 format) |
6073 |
|
RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS); |
6074 |
|
if (!lst3LS) { |
6075 |
|
lst3LS = pRIFF->AddSubList(LIST_TYPE_3LS); |
6076 |
|
} |
6077 |
|
// Make sure <3LS > chunk is placed before <ptbl> chunk. The precise |
6078 |
|
// location of <3LS > is irrelevant, however it should be located |
6079 |
|
// before the actual wave data |
6080 |
|
RIFF::Chunk* ckPTBL = pRIFF->GetSubChunk(CHUNK_ID_PTBL); |
6081 |
|
pRIFF->MoveSubChunk(lst3LS, ckPTBL); |
6082 |
|
|
6083 |
|
// This must be performed before writing the chunks for instruments, |
6084 |
|
// because the instruments' script slots will write the file offsets |
6085 |
|
// of the respective instrument script chunk as reference. |
6086 |
|
if (pScriptGroups) { |
6087 |
|
// Update instrument script (group) chunks. |
6088 |
|
for (std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
6089 |
|
it != pScriptGroups->end(); ++it) |
6090 |
|
{ |
6091 |
|
(*it)->UpdateChunks(pProgress); |
6092 |
|
} |
6093 |
|
} |
6094 |
|
|
6095 |
|
// in case no libgig custom format data was added, then remove the |
6096 |
|
// custom "3LS " chunk again |
6097 |
|
if (!lst3LS->CountSubChunks()) { |
6098 |
|
pRIFF->DeleteSubChunk(lst3LS); |
6099 |
|
lst3LS = NULL; |
6100 |
|
} |
6101 |
|
|
6102 |
// first update base class's chunks |
// first update base class's chunks |
6103 |
DLS::File::UpdateChunks(); |
DLS::File::UpdateChunks(pProgress); |
6104 |
|
|
6105 |
if (newFile) { |
if (newFile) { |
6106 |
// INFO was added by Resource::UpdateChunks - make sure it |
// INFO was added by Resource::UpdateChunks - make sure it |
6114 |
|
|
6115 |
// update group's chunks |
// update group's chunks |
6116 |
if (pGroups) { |
if (pGroups) { |
6117 |
std::list<Group*>::iterator iter = pGroups->begin(); |
// make sure '3gri' and '3gnl' list chunks exist |
6118 |
std::list<Group*>::iterator end = pGroups->end(); |
// (before updating the Group chunks) |
6119 |
for (; iter != end; ++iter) { |
RIFF::List* _3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
6120 |
(*iter)->UpdateChunks(); |
if (!_3gri) { |
6121 |
|
_3gri = pRIFF->AddSubList(LIST_TYPE_3GRI); |
6122 |
|
pRIFF->MoveSubChunk(_3gri, pRIFF->GetSubChunk(CHUNK_ID_PTBL)); |
6123 |
} |
} |
6124 |
|
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
6125 |
|
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
6126 |
|
|
6127 |
// v3: make sure the file has 128 3gnm chunks |
// v3: make sure the file has 128 3gnm chunks |
6128 |
|
// (before updating the Group chunks) |
6129 |
if (pVersion && pVersion->major == 3) { |
if (pVersion && pVersion->major == 3) { |
|
RIFF::List* _3gnl = pRIFF->GetSubList(LIST_TYPE_3GRI)->GetSubList(LIST_TYPE_3GNL); |
|
6130 |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
6131 |
for (int i = 0 ; i < 128 ; i++) { |
for (int i = 0 ; i < 128 ; i++) { |
6132 |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
6133 |
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
6134 |
} |
} |
6135 |
} |
} |
6136 |
|
|
6137 |
|
std::list<Group*>::iterator iter = pGroups->begin(); |
6138 |
|
std::list<Group*>::iterator end = pGroups->end(); |
6139 |
|
for (; iter != end; ++iter) { |
6140 |
|
(*iter)->UpdateChunks(pProgress); |
6141 |
|
} |
6142 |
} |
} |
6143 |
|
|
6144 |
// update einf chunk |
// update einf chunk |
6157 |
// Note that there are several fields with unknown use. These |
// Note that there are several fields with unknown use. These |
6158 |
// are set to zero. |
// are set to zero. |
6159 |
|
|
6160 |
int sublen = pSamples->size() / 8 + 49; |
int sublen = int(pSamples->size() / 8 + 49); |
6161 |
int einfSize = (Instruments + 1) * sublen; |
int einfSize = (Instruments + 1) * sublen; |
6162 |
|
|
6163 |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
6230 |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
6231 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6232 |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
6233 |
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size()); |
6234 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6235 |
|
|
6236 |
totnbregions += instrument->Regions; |
totnbregions += instrument->Regions; |
6248 |
store32(&pData[24], totnbloops); |
store32(&pData[24], totnbloops); |
6249 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6250 |
// next 4 bytes unknown, not always 0 |
// next 4 bytes unknown, not always 0 |
6251 |
store32(&pData[40], pSamples->size()); |
store32(&pData[40], (uint32_t) pSamples->size()); |
6252 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6253 |
} |
} |
6254 |
|
|
6255 |
// update 3crc chunk |
// update 3crc chunk |
6256 |
|
|
6257 |
// The 3crc chunk contains CRC-32 checksums for the |
// The 3crc chunk contains CRC-32 checksums for the |
6258 |
// samples. The actual checksum values will be filled in |
// samples. When saving a gig file to disk, we first update the 3CRC |
6259 |
// later, by Sample::Write. |
// chunk here (in RAM) with the old crc values which we read from the |
6260 |
|
// 3CRC chunk when we opened the file (available with gig::Sample::crc |
6261 |
|
// member variable). This step is required, because samples might have |
6262 |
|
// been deleted by the user since the file was opened, which in turn |
6263 |
|
// changes the order of the (i.e. old) checksums within the 3crc chunk. |
6264 |
|
// If a sample was conciously modified by the user (that is if |
6265 |
|
// Sample::Write() was called later on) then Sample::Write() will just |
6266 |
|
// update the respective individual checksum(s) directly on disk and |
6267 |
|
// leaves all other sample checksums untouched. |
6268 |
|
|
6269 |
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
6270 |
if (_3crc) { |
if (_3crc) { |
6271 |
_3crc->Resize(pSamples->size() * 8); |
_3crc->Resize(pSamples->size() * 8); |
6272 |
} else if (newFile) { |
} else /*if (newFile)*/ { |
6273 |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
|
_3crc->LoadChunkData(); |
|
|
|
|
6274 |
// the order of einf and 3crc is not the same in v2 and v3 |
// the order of einf and 3crc is not the same in v2 and v3 |
6275 |
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
6276 |
} |
} |
6277 |
|
{ // must be performed in RAM here ... |
6278 |
|
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
6279 |
|
if (pData) { |
6280 |
|
File::SampleList::iterator iter = pSamples->begin(); |
6281 |
|
File::SampleList::iterator end = pSamples->end(); |
6282 |
|
for (int index = 0; iter != end; ++iter, ++index) { |
6283 |
|
gig::Sample* pSample = (gig::Sample*) *iter; |
6284 |
|
pData[index*2] = 1; // always 1 |
6285 |
|
pData[index*2+1] = pSample->crc; |
6286 |
|
} |
6287 |
|
} |
6288 |
|
} |
6289 |
|
} |
6290 |
|
|
6291 |
|
void File::UpdateFileOffsets() { |
6292 |
|
DLS::File::UpdateFileOffsets(); |
6293 |
|
|
6294 |
|
for (Instrument* instrument = GetFirstInstrument(); instrument; |
6295 |
|
instrument = GetNextInstrument()) |
6296 |
|
{ |
6297 |
|
instrument->UpdateScriptFileOffsets(); |
6298 |
|
} |
6299 |
} |
} |
6300 |
|
|
6301 |
/** |
/** |