1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file loader library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2005 by Christian Schoenebeck * |
* Copyright (C) 2003-2007 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 * |
51 |
|
|
52 |
namespace gig { |
namespace gig { |
53 |
|
|
|
// *************** dimension_def_t *************** |
|
|
// * |
|
|
|
|
|
dimension_def_t& dimension_def_t::operator=(const dimension_def_t& arg) { |
|
|
dimension = arg.dimension; |
|
|
bits = arg.bits; |
|
|
zones = arg.zones; |
|
|
split_type = arg.split_type; |
|
|
ranges = arg.ranges; |
|
|
zone_size = arg.zone_size; |
|
|
if (ranges) { |
|
|
ranges = new range_t[zones]; |
|
|
for (int i = 0; i < zones; i++) |
|
|
ranges[i] = arg.ranges[i]; |
|
|
} |
|
|
return *this; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
54 |
// *************** progress_t *************** |
// *************** progress_t *************** |
55 |
// * |
// * |
56 |
|
|
111 |
return x & 0x800000 ? x - 0x1000000 : x; |
return x & 0x800000 ? x - 0x1000000 : x; |
112 |
} |
} |
113 |
|
|
114 |
|
inline void store24(unsigned char* pDst, int x) |
115 |
|
{ |
116 |
|
pDst[0] = x; |
117 |
|
pDst[1] = x >> 8; |
118 |
|
pDst[2] = x >> 16; |
119 |
|
} |
120 |
|
|
121 |
void Decompress16(int compressionmode, const unsigned char* params, |
void Decompress16(int compressionmode, const unsigned char* params, |
122 |
int srcStep, int dstStep, |
int srcStep, int dstStep, |
123 |
const unsigned char* pSrc, int16_t* pDst, |
const unsigned char* pSrc, int16_t* pDst, |
157 |
} |
} |
158 |
|
|
159 |
void Decompress24(int compressionmode, const unsigned char* params, |
void Decompress24(int compressionmode, const unsigned char* params, |
160 |
int dstStep, const unsigned char* pSrc, int16_t* pDst, |
int dstStep, const unsigned char* pSrc, uint8_t* pDst, |
161 |
unsigned long currentframeoffset, |
unsigned long currentframeoffset, |
162 |
unsigned long copysamples, int truncatedBits) |
unsigned long copysamples, int truncatedBits) |
163 |
{ |
{ |
|
// Note: The 24 bits are truncated to 16 bits for now. |
|
|
|
|
164 |
int y, dy, ddy, dddy; |
int y, dy, ddy, dddy; |
|
const int shift = 8 - truncatedBits; |
|
165 |
|
|
166 |
#define GET_PARAMS(params) \ |
#define GET_PARAMS(params) \ |
167 |
y = get24(params); \ |
y = get24(params); \ |
177 |
|
|
178 |
#define COPY_ONE(x) \ |
#define COPY_ONE(x) \ |
179 |
SKIP_ONE(x); \ |
SKIP_ONE(x); \ |
180 |
*pDst = y >> shift; \ |
store24(pDst, y << truncatedBits); \ |
181 |
pDst += dstStep |
pDst += dstStep |
182 |
|
|
183 |
switch (compressionmode) { |
switch (compressionmode) { |
184 |
case 2: // 24 bit uncompressed |
case 2: // 24 bit uncompressed |
185 |
pSrc += currentframeoffset * 3; |
pSrc += currentframeoffset * 3; |
186 |
while (copysamples) { |
while (copysamples) { |
187 |
*pDst = get24(pSrc) >> shift; |
store24(pDst, get24(pSrc) << truncatedBits); |
188 |
pDst += dstStep; |
pDst += dstStep; |
189 |
pSrc += 3; |
pSrc += 3; |
190 |
copysamples--; |
copysamples--; |
279 |
* is located, 0 otherwise |
* is located, 0 otherwise |
280 |
*/ |
*/ |
281 |
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, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
282 |
|
pInfo->UseFixedLengthStrings = true; |
283 |
Instances++; |
Instances++; |
284 |
FileNo = fileNo; |
FileNo = fileNo; |
285 |
|
|
286 |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
287 |
if (pCk3gix) { |
if (pCk3gix) { |
288 |
SampleGroup = pCk3gix->ReadInt16(); |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
289 |
|
pGroup = pFile->GetGroup(iSampleGroup); |
290 |
} else { // '3gix' chunk missing |
} else { // '3gix' chunk missing |
291 |
// use default value(s) |
// by default assigned to that mandatory "Default Group" |
292 |
SampleGroup = 0; |
pGroup = pFile->GetGroup(0); |
293 |
} |
} |
294 |
|
|
295 |
pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL); |
pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL); |
313 |
// use default values |
// use default values |
314 |
Manufacturer = 0; |
Manufacturer = 0; |
315 |
Product = 0; |
Product = 0; |
316 |
SamplePeriod = 1 / SamplesPerSecond; |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
317 |
MIDIUnityNote = 64; |
MIDIUnityNote = 64; |
318 |
FineTune = 0; |
FineTune = 0; |
319 |
SMPTEOffset = 0; |
SMPTEOffset = 0; |
354 |
} |
} |
355 |
FrameOffset = 0; // just for streaming compressed samples |
FrameOffset = 0; // just for streaming compressed samples |
356 |
|
|
357 |
LoopSize = LoopEnd - LoopStart; |
LoopSize = LoopEnd - LoopStart + 1; |
358 |
} |
} |
359 |
|
|
360 |
/** |
/** |
364 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
365 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
366 |
* |
* |
367 |
* @throws DLS::Exception if FormatTag != WAVE_FORMAT_PCM or no sample data |
* @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data |
368 |
* was provided yet |
* was provided yet |
369 |
* @throws gig::Exception if there is any invalid sample setting |
* @throws gig::Exception if there is any invalid sample setting |
370 |
*/ |
*/ |
377 |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
378 |
// update 'smpl' chunk |
// update 'smpl' chunk |
379 |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
380 |
SamplePeriod = 1 / SamplesPerSecond; |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
381 |
memcpy(&pData[0], &Manufacturer, 4); |
memcpy(&pData[0], &Manufacturer, 4); |
382 |
memcpy(&pData[4], &Product, 4); |
memcpy(&pData[4], &Product, 4); |
383 |
memcpy(&pData[8], &SamplePeriod, 4); |
memcpy(&pData[8], &SamplePeriod, 4); |
399 |
// make sure '3gix' chunk exists |
// make sure '3gix' chunk exists |
400 |
pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX); |
401 |
if (!pCk3gix) pCk3gix = pWaveList->AddSubChunk(CHUNK_ID_3GIX, 4); |
if (!pCk3gix) pCk3gix = pWaveList->AddSubChunk(CHUNK_ID_3GIX, 4); |
402 |
|
// determine appropriate sample group index (to be stored in chunk) |
403 |
|
uint16_t iSampleGroup = 0; // 0 refers to default sample group |
404 |
|
File* pFile = static_cast<File*>(pParent); |
405 |
|
if (pFile->pGroups) { |
406 |
|
std::list<Group*>::iterator iter = pFile->pGroups->begin(); |
407 |
|
std::list<Group*>::iterator end = pFile->pGroups->end(); |
408 |
|
for (int i = 0; iter != end; i++, iter++) { |
409 |
|
if (*iter == pGroup) { |
410 |
|
iSampleGroup = i; |
411 |
|
break; // found |
412 |
|
} |
413 |
|
} |
414 |
|
} |
415 |
// update '3gix' chunk |
// update '3gix' chunk |
416 |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
417 |
memcpy(&pData[0], &SampleGroup, 2); |
memcpy(&pData[0], &iSampleGroup, 2); |
418 |
} |
} |
419 |
|
|
420 |
/// 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). |
635 |
* enlarged samples before calling File::Save() as this might exceed the |
* enlarged samples before calling File::Save() as this might exceed the |
636 |
* current sample's boundary! |
* current sample's boundary! |
637 |
* |
* |
638 |
* Also note: only WAVE_FORMAT_PCM is currently supported, that is |
* Also note: only DLS_WAVE_FORMAT_PCM is currently supported, that is |
639 |
* FormatTag must be WAVE_FORMAT_PCM. Trying to resize samples with |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
640 |
* other formats will fail! |
* other formats will fail! |
641 |
* |
* |
642 |
* @param iNewSize - new sample wave data size in sample points (must be |
* @param iNewSize - new sample wave data size in sample points (must be |
643 |
* greater than zero) |
* greater than zero) |
644 |
* @throws DLS::Excecption if FormatTag != WAVE_FORMAT_PCM |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
645 |
* or if \a iNewSize is less than 1 |
* or if \a iNewSize is less than 1 |
646 |
* @throws gig::Exception if existing sample is compressed |
* @throws gig::Exception if existing sample is compressed |
647 |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
741 |
* @param SampleCount number of sample points to read |
* @param SampleCount number of sample points to read |
742 |
* @param pPlaybackState will be used to store and reload the playback |
* @param pPlaybackState will be used to store and reload the playback |
743 |
* state for the next ReadAndLoop() call |
* state for the next ReadAndLoop() call |
744 |
|
* @param pDimRgn dimension region with looping information |
745 |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
746 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
747 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
748 |
*/ |
*/ |
749 |
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, buffer_t* pExternalDecompressionBuffer) { |
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, |
750 |
|
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
751 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
752 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
753 |
|
|
754 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
755 |
|
|
756 |
if (this->Loops && GetPos() <= this->LoopEnd) { // honor looping if there are loop points defined |
if (pDimRgn->SampleLoops) { // honor looping if there are loop points defined |
757 |
|
|
758 |
switch (this->LoopType) { |
const DLS::sample_loop_t& loop = pDimRgn->pSampleLoops[0]; |
759 |
|
const uint32_t loopEnd = loop.LoopStart + loop.LoopLength; |
760 |
|
|
761 |
case loop_type_bidirectional: { //TODO: not tested yet! |
if (GetPos() <= loopEnd) { |
762 |
do { |
switch (loop.LoopType) { |
|
// if not endless loop check if max. number of loop cycles have been passed |
|
|
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
|
|
|
|
|
if (!pPlaybackState->reverse) { // forward playback |
|
|
do { |
|
|
samplestoloopend = this->LoopEnd - GetPos(); |
|
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
|
|
samplestoread -= readsamples; |
|
|
totalreadsamples += readsamples; |
|
|
if (readsamples == samplestoloopend) { |
|
|
pPlaybackState->reverse = true; |
|
|
break; |
|
|
} |
|
|
} while (samplestoread && readsamples); |
|
|
} |
|
|
else { // backward playback |
|
763 |
|
|
764 |
// as we can only read forward from disk, we have to |
case loop_type_bidirectional: { //TODO: not tested yet! |
765 |
// determine the end position within the loop first, |
do { |
766 |
// read forward from that 'end' and finally after |
// if not endless loop check if max. number of loop cycles have been passed |
767 |
// reading, swap all sample frames so it reflects |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
768 |
// backward playback |
|
769 |
|
if (!pPlaybackState->reverse) { // forward playback |
770 |
unsigned long swapareastart = totalreadsamples; |
do { |
771 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
samplestoloopend = loopEnd - GetPos(); |
772 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
773 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
samplestoread -= readsamples; |
774 |
|
totalreadsamples += readsamples; |
775 |
SetPos(reverseplaybackend); |
if (readsamples == samplestoloopend) { |
776 |
|
pPlaybackState->reverse = true; |
777 |
// read samples for backward playback |
break; |
778 |
do { |
} |
779 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
} while (samplestoread && readsamples); |
780 |
samplestoreadinloop -= readsamples; |
} |
781 |
samplestoread -= readsamples; |
else { // backward playback |
|
totalreadsamples += readsamples; |
|
|
} while (samplestoreadinloop && readsamples); |
|
782 |
|
|
783 |
SetPos(reverseplaybackend); // pretend we really read backwards |
// as we can only read forward from disk, we have to |
784 |
|
// determine the end position within the loop first, |
785 |
|
// read forward from that 'end' and finally after |
786 |
|
// reading, swap all sample frames so it reflects |
787 |
|
// backward playback |
788 |
|
|
789 |
|
unsigned long swapareastart = totalreadsamples; |
790 |
|
unsigned long loopoffset = GetPos() - loop.LoopStart; |
791 |
|
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
792 |
|
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
793 |
|
|
794 |
|
SetPos(reverseplaybackend); |
795 |
|
|
796 |
|
// read samples for backward playback |
797 |
|
do { |
798 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
799 |
|
samplestoreadinloop -= readsamples; |
800 |
|
samplestoread -= readsamples; |
801 |
|
totalreadsamples += readsamples; |
802 |
|
} while (samplestoreadinloop && readsamples); |
803 |
|
|
804 |
|
SetPos(reverseplaybackend); // pretend we really read backwards |
805 |
|
|
806 |
|
if (reverseplaybackend == loop.LoopStart) { |
807 |
|
pPlaybackState->loop_cycles_left--; |
808 |
|
pPlaybackState->reverse = false; |
809 |
|
} |
810 |
|
|
811 |
if (reverseplaybackend == this->LoopStart) { |
// reverse the sample frames for backward playback |
812 |
pPlaybackState->loop_cycles_left--; |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
|
pPlaybackState->reverse = false; |
|
813 |
} |
} |
814 |
|
} while (samplestoread && readsamples); |
815 |
|
break; |
816 |
|
} |
817 |
|
|
818 |
// reverse the sample frames for backward playback |
case loop_type_backward: { // TODO: not tested yet! |
819 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
// forward playback (not entered the loop yet) |
820 |
} |
if (!pPlaybackState->reverse) do { |
821 |
} while (samplestoread && readsamples); |
samplestoloopend = loopEnd - GetPos(); |
822 |
break; |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
823 |
} |
samplestoread -= readsamples; |
824 |
|
totalreadsamples += readsamples; |
825 |
case loop_type_backward: { // TODO: not tested yet! |
if (readsamples == samplestoloopend) { |
826 |
// forward playback (not entered the loop yet) |
pPlaybackState->reverse = true; |
827 |
if (!pPlaybackState->reverse) do { |
break; |
828 |
samplestoloopend = this->LoopEnd - GetPos(); |
} |
829 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
} while (samplestoread && readsamples); |
|
samplestoread -= readsamples; |
|
|
totalreadsamples += readsamples; |
|
|
if (readsamples == samplestoloopend) { |
|
|
pPlaybackState->reverse = true; |
|
|
break; |
|
|
} |
|
|
} while (samplestoread && readsamples); |
|
830 |
|
|
831 |
if (!samplestoread) break; |
if (!samplestoread) break; |
832 |
|
|
833 |
// as we can only read forward from disk, we have to |
// as we can only read forward from disk, we have to |
834 |
// determine the end position within the loop first, |
// determine the end position within the loop first, |
835 |
// read forward from that 'end' and finally after |
// read forward from that 'end' and finally after |
836 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
837 |
// backward playback |
// backward playback |
838 |
|
|
839 |
unsigned long swapareastart = totalreadsamples; |
unsigned long swapareastart = totalreadsamples; |
840 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
841 |
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * LoopSize - loopoffset) |
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * loop.LoopLength - loopoffset) |
842 |
: samplestoread; |
: samplestoread; |
843 |
unsigned long reverseplaybackend = this->LoopStart + Abs((loopoffset - samplestoreadinloop) % this->LoopSize); |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
844 |
|
|
845 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
846 |
|
|
847 |
// read samples for backward playback |
// read samples for backward playback |
848 |
do { |
do { |
849 |
// if not endless loop check if max. number of loop cycles have been passed |
// if not endless loop check if max. number of loop cycles have been passed |
850 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
851 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
852 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
853 |
samplestoreadinloop -= readsamples; |
samplestoreadinloop -= readsamples; |
854 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
855 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
856 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
857 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
858 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
859 |
} |
} |
860 |
} while (samplestoreadinloop && readsamples); |
} while (samplestoreadinloop && readsamples); |
861 |
|
|
862 |
SetPos(reverseplaybackend); // pretend we really read backwards |
SetPos(reverseplaybackend); // pretend we really read backwards |
863 |
|
|
864 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
865 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
866 |
break; |
break; |
867 |
} |
} |
868 |
|
|
869 |
default: case loop_type_normal: { |
default: case loop_type_normal: { |
870 |
do { |
do { |
871 |
// if not endless loop check if max. number of loop cycles have been passed |
// if not endless loop check if max. number of loop cycles have been passed |
872 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
873 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
874 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
875 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
876 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
877 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
878 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
879 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
880 |
} |
} |
881 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
882 |
break; |
break; |
883 |
|
} |
884 |
} |
} |
885 |
} |
} |
886 |
} |
} |
910 |
* have to use an external decompression buffer for <b>EACH</b> |
* have to use an external decompression buffer for <b>EACH</b> |
911 |
* streaming thread to avoid race conditions and crashes! |
* streaming thread to avoid race conditions and crashes! |
912 |
* |
* |
913 |
|
* For 16 bit samples, the data in the buffer will be int16_t |
914 |
|
* (using native endianness). For 24 bit, the buffer will |
915 |
|
* contain three bytes per sample, little-endian. |
916 |
|
* |
917 |
* @param pBuffer destination buffer |
* @param pBuffer destination buffer |
918 |
* @param SampleCount number of sample points to read |
* @param SampleCount number of sample points to read |
919 |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
924 |
if (SampleCount == 0) return 0; |
if (SampleCount == 0) return 0; |
925 |
if (!Compressed) { |
if (!Compressed) { |
926 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
927 |
// 24 bit sample. For now just truncate to 16 bit. |
return pCkData->Read(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
|
unsigned char* pSrc = (unsigned char*) ((pExternalDecompressionBuffer) ? pExternalDecompressionBuffer->pStart : this->InternalDecompressionBuffer.pStart); |
|
|
int16_t* pDst = static_cast<int16_t*>(pBuffer); |
|
|
if (Channels == 2) { // Stereo |
|
|
unsigned long readBytes = pCkData->Read(pSrc, SampleCount * 6, 1); |
|
|
pSrc++; |
|
|
for (unsigned long i = readBytes ; i > 0 ; i -= 3) { |
|
|
*pDst++ = get16(pSrc); |
|
|
pSrc += 3; |
|
|
} |
|
|
return (pDst - static_cast<int16_t*>(pBuffer)) >> 1; |
|
|
} |
|
|
else { // Mono |
|
|
unsigned long readBytes = pCkData->Read(pSrc, SampleCount * 3, 1); |
|
|
pSrc++; |
|
|
for (unsigned long i = readBytes ; i > 0 ; i -= 3) { |
|
|
*pDst++ = get16(pSrc); |
|
|
pSrc += 3; |
|
|
} |
|
|
return pDst - static_cast<int16_t*>(pBuffer); |
|
|
} |
|
928 |
} |
} |
929 |
else { // 16 bit |
else { // 16 bit |
930 |
// (pCkData->Read does endian correction) |
// (pCkData->Read does endian correction) |
954 |
|
|
955 |
unsigned char* pSrc = (unsigned char*) pDecompressionBuffer->pStart; |
unsigned char* pSrc = (unsigned char*) pDecompressionBuffer->pStart; |
956 |
int16_t* pDst = static_cast<int16_t*>(pBuffer); |
int16_t* pDst = static_cast<int16_t*>(pBuffer); |
957 |
|
uint8_t* pDst24 = static_cast<uint8_t*>(pBuffer); |
958 |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
959 |
|
|
960 |
while (remainingsamples && remainingbytes) { |
while (remainingsamples && remainingbytes) { |
1036 |
const unsigned char* const param_r = pSrc; |
const unsigned char* const param_r = pSrc; |
1037 |
if (mode_r != 2) pSrc += 12; |
if (mode_r != 2) pSrc += 12; |
1038 |
|
|
1039 |
Decompress24(mode_l, param_l, 2, pSrc, pDst, |
Decompress24(mode_l, param_l, 6, pSrc, pDst24, |
1040 |
skipsamples, copysamples, TruncatedBits); |
skipsamples, copysamples, TruncatedBits); |
1041 |
Decompress24(mode_r, param_r, 2, pSrc + rightChannelOffset, pDst + 1, |
Decompress24(mode_r, param_r, 6, pSrc + rightChannelOffset, pDst24 + 3, |
1042 |
skipsamples, copysamples, TruncatedBits); |
skipsamples, copysamples, TruncatedBits); |
1043 |
pDst += copysamples << 1; |
pDst24 += copysamples * 6; |
1044 |
} |
} |
1045 |
else { // Mono |
else { // Mono |
1046 |
Decompress24(mode_l, param_l, 1, pSrc, pDst, |
Decompress24(mode_l, param_l, 3, pSrc, pDst24, |
1047 |
skipsamples, copysamples, TruncatedBits); |
skipsamples, copysamples, TruncatedBits); |
1048 |
pDst += copysamples; |
pDst24 += copysamples * 3; |
1049 |
} |
} |
1050 |
} |
} |
1051 |
else { // 16 bit |
else { // 16 bit |
1152 |
} |
} |
1153 |
} |
} |
1154 |
|
|
1155 |
|
/** |
1156 |
|
* Returns pointer to the Group this Sample belongs to. In the .gig |
1157 |
|
* format a sample always belongs to one group. If it wasn't explicitly |
1158 |
|
* assigned to a certain group, it will be automatically assigned to a |
1159 |
|
* default group. |
1160 |
|
* |
1161 |
|
* @returns Sample's Group (never NULL) |
1162 |
|
*/ |
1163 |
|
Group* Sample::GetGroup() const { |
1164 |
|
return pGroup; |
1165 |
|
} |
1166 |
|
|
1167 |
Sample::~Sample() { |
Sample::~Sample() { |
1168 |
Instances--; |
Instances--; |
1169 |
if (!Instances && InternalDecompressionBuffer.Size) { |
if (!Instances && InternalDecompressionBuffer.Size) { |
1186 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1187 |
Instances++; |
Instances++; |
1188 |
|
|
1189 |
|
pSample = NULL; |
1190 |
|
|
1191 |
memcpy(&Crossfade, &SamplerOptions, 4); |
memcpy(&Crossfade, &SamplerOptions, 4); |
1192 |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
1193 |
|
|
1194 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
1195 |
if (_3ewa) { // if '3ewa' chunk exists |
if (_3ewa) { // if '3ewa' chunk exists |
1196 |
_3ewa->ReadInt32(); // unknown, always 0x0000008C ? |
_3ewa->ReadInt32(); // unknown, always == chunk size ? |
1197 |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1198 |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1199 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1338 |
if (lfo3ctrl & 0x40) // bit 6 |
if (lfo3ctrl & 0x40) // bit 6 |
1339 |
VCFType = vcf_type_lowpassturbo; |
VCFType = vcf_type_lowpassturbo; |
1340 |
} |
} |
1341 |
|
if (_3ewa->RemainingBytes() >= 8) { |
1342 |
|
_3ewa->Read(DimensionUpperLimits, 1, 8); |
1343 |
|
} else { |
1344 |
|
memset(DimensionUpperLimits, 0, 8); |
1345 |
|
} |
1346 |
} else { // '3ewa' chunk does not exist yet |
} else { // '3ewa' chunk does not exist yet |
1347 |
// use default values |
// use default values |
1348 |
LFO3Frequency = 1.0; |
LFO3Frequency = 1.0; |
1423 |
VCFVelocityDynamicRange = 0x04; |
VCFVelocityDynamicRange = 0x04; |
1424 |
VCFVelocityCurve = curve_type_linear; |
VCFVelocityCurve = curve_type_linear; |
1425 |
VCFType = vcf_type_lowpass; |
VCFType = vcf_type_lowpass; |
1426 |
|
memset(DimensionUpperLimits, 0, 8); |
1427 |
} |
} |
1428 |
|
|
1429 |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
1458 |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
1459 |
|
|
1460 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1461 |
|
VelocityTable = 0; |
1462 |
} |
} |
1463 |
|
|
1464 |
/** |
/** |
1479 |
|
|
1480 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1481 |
|
|
1482 |
const uint32_t unknown = 0x0000008C; // unknown, always 0x0000008C ? |
const uint32_t chunksize = _3ewa->GetSize(); |
1483 |
memcpy(&pData[0], &unknown, 4); |
memcpy(&pData[0], &chunksize, 4); // unknown, always chunk size? |
1484 |
|
|
1485 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
1486 |
memcpy(&pData[4], &lfo3freq, 4); |
memcpy(&pData[4], &lfo3freq, 4); |
1487 |
|
|
1488 |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
1489 |
memcpy(&pData[4], &eg3attack, 4); |
memcpy(&pData[8], &eg3attack, 4); |
1490 |
|
|
1491 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1492 |
|
|
1493 |
memcpy(&pData[10], &LFO1InternalDepth, 2); |
memcpy(&pData[14], &LFO1InternalDepth, 2); |
1494 |
|
|
1495 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1496 |
|
|
1497 |
memcpy(&pData[14], &LFO3InternalDepth, 2); |
memcpy(&pData[18], &LFO3InternalDepth, 2); |
1498 |
|
|
1499 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1500 |
|
|
1501 |
memcpy(&pData[18], &LFO1ControlDepth, 2); |
memcpy(&pData[22], &LFO1ControlDepth, 2); |
1502 |
|
|
1503 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1504 |
|
|
1505 |
memcpy(&pData[22], &LFO3ControlDepth, 2); |
memcpy(&pData[26], &LFO3ControlDepth, 2); |
1506 |
|
|
1507 |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
1508 |
memcpy(&pData[24], &eg1attack, 4); |
memcpy(&pData[28], &eg1attack, 4); |
1509 |
|
|
1510 |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
1511 |
memcpy(&pData[28], &eg1decay1, 4); |
memcpy(&pData[32], &eg1decay1, 4); |
1512 |
|
|
1513 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1514 |
|
|
1515 |
memcpy(&pData[34], &EG1Sustain, 2); |
memcpy(&pData[38], &EG1Sustain, 2); |
1516 |
|
|
1517 |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
1518 |
memcpy(&pData[36], &eg1release, 4); |
memcpy(&pData[40], &eg1release, 4); |
1519 |
|
|
1520 |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
1521 |
memcpy(&pData[40], &eg1ctl, 1); |
memcpy(&pData[44], &eg1ctl, 1); |
1522 |
|
|
1523 |
const uint8_t eg1ctrloptions = |
const uint8_t eg1ctrloptions = |
1524 |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
1525 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
1526 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
1527 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
1528 |
memcpy(&pData[41], &eg1ctrloptions, 1); |
memcpy(&pData[45], &eg1ctrloptions, 1); |
1529 |
|
|
1530 |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
1531 |
memcpy(&pData[42], &eg2ctl, 1); |
memcpy(&pData[46], &eg2ctl, 1); |
1532 |
|
|
1533 |
const uint8_t eg2ctrloptions = |
const uint8_t eg2ctrloptions = |
1534 |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
1535 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
1536 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
1537 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
1538 |
memcpy(&pData[43], &eg2ctrloptions, 1); |
memcpy(&pData[47], &eg2ctrloptions, 1); |
1539 |
|
|
1540 |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
1541 |
memcpy(&pData[44], &lfo1freq, 4); |
memcpy(&pData[48], &lfo1freq, 4); |
1542 |
|
|
1543 |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
1544 |
memcpy(&pData[48], &eg2attack, 4); |
memcpy(&pData[52], &eg2attack, 4); |
1545 |
|
|
1546 |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
1547 |
memcpy(&pData[52], &eg2decay1, 4); |
memcpy(&pData[56], &eg2decay1, 4); |
1548 |
|
|
1549 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1550 |
|
|
1551 |
memcpy(&pData[58], &EG2Sustain, 2); |
memcpy(&pData[62], &EG2Sustain, 2); |
1552 |
|
|
1553 |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
1554 |
memcpy(&pData[60], &eg2release, 4); |
memcpy(&pData[64], &eg2release, 4); |
1555 |
|
|
1556 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1557 |
|
|
1558 |
memcpy(&pData[66], &LFO2ControlDepth, 2); |
memcpy(&pData[70], &LFO2ControlDepth, 2); |
1559 |
|
|
1560 |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
1561 |
memcpy(&pData[68], &lfo2freq, 4); |
memcpy(&pData[72], &lfo2freq, 4); |
1562 |
|
|
1563 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1564 |
|
|
1565 |
memcpy(&pData[72], &LFO2InternalDepth, 2); |
memcpy(&pData[78], &LFO2InternalDepth, 2); |
1566 |
|
|
1567 |
const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2); |
const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2); |
1568 |
memcpy(&pData[74], &eg1decay2, 4); |
memcpy(&pData[80], &eg1decay2, 4); |
1569 |
|
|
1570 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1571 |
|
|
1572 |
memcpy(&pData[80], &EG1PreAttack, 2); |
memcpy(&pData[86], &EG1PreAttack, 2); |
1573 |
|
|
1574 |
const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2); |
const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2); |
1575 |
memcpy(&pData[82], &eg2decay2, 4); |
memcpy(&pData[88], &eg2decay2, 4); |
1576 |
|
|
1577 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1578 |
|
|
1579 |
memcpy(&pData[88], &EG2PreAttack, 2); |
memcpy(&pData[94], &EG2PreAttack, 2); |
1580 |
|
|
1581 |
{ |
{ |
1582 |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
1594 |
default: |
default: |
1595 |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
1596 |
} |
} |
1597 |
memcpy(&pData[90], &velocityresponse, 1); |
memcpy(&pData[96], &velocityresponse, 1); |
1598 |
} |
} |
1599 |
|
|
1600 |
{ |
{ |
1613 |
default: |
default: |
1614 |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
1615 |
} |
} |
1616 |
memcpy(&pData[91], &releasevelocityresponse, 1); |
memcpy(&pData[97], &releasevelocityresponse, 1); |
1617 |
} |
} |
1618 |
|
|
1619 |
memcpy(&pData[92], &VelocityResponseCurveScaling, 1); |
memcpy(&pData[98], &VelocityResponseCurveScaling, 1); |
1620 |
|
|
1621 |
memcpy(&pData[93], &AttenuationControllerThreshold, 1); |
memcpy(&pData[99], &AttenuationControllerThreshold, 1); |
1622 |
|
|
1623 |
// next 4 bytes unknown |
// next 4 bytes unknown |
1624 |
|
|
1625 |
memcpy(&pData[98], &SampleStartOffset, 2); |
memcpy(&pData[104], &SampleStartOffset, 2); |
1626 |
|
|
1627 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1628 |
|
|
1641 |
default: |
default: |
1642 |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
1643 |
} |
} |
1644 |
memcpy(&pData[102], &pitchTrackDimensionBypass, 1); |
memcpy(&pData[108], &pitchTrackDimensionBypass, 1); |
1645 |
} |
} |
1646 |
|
|
1647 |
const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit |
const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit |
1648 |
memcpy(&pData[103], &pan, 1); |
memcpy(&pData[109], &pan, 1); |
1649 |
|
|
1650 |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
1651 |
memcpy(&pData[104], &selfmask, 1); |
memcpy(&pData[110], &selfmask, 1); |
1652 |
|
|
1653 |
// next byte unknown |
// next byte unknown |
1654 |
|
|
1657 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
1658 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
1659 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
1660 |
memcpy(&pData[106], &lfo3ctrl, 1); |
memcpy(&pData[112], &lfo3ctrl, 1); |
1661 |
} |
} |
1662 |
|
|
1663 |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
1664 |
memcpy(&pData[107], &attenctl, 1); |
memcpy(&pData[113], &attenctl, 1); |
1665 |
|
|
1666 |
{ |
{ |
1667 |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
1668 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
1669 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
1670 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
1671 |
memcpy(&pData[108], &lfo2ctrl, 1); |
memcpy(&pData[114], &lfo2ctrl, 1); |
1672 |
} |
} |
1673 |
|
|
1674 |
{ |
{ |
1677 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
1678 |
if (VCFResonanceController != vcf_res_ctrl_none) |
if (VCFResonanceController != vcf_res_ctrl_none) |
1679 |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
1680 |
memcpy(&pData[109], &lfo1ctrl, 1); |
memcpy(&pData[115], &lfo1ctrl, 1); |
1681 |
} |
} |
1682 |
|
|
1683 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
1684 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
1685 |
memcpy(&pData[110], &eg3depth, 1); |
memcpy(&pData[116], &eg3depth, 1); |
1686 |
|
|
1687 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1688 |
|
|
1689 |
const uint8_t channeloffset = ChannelOffset * 4; |
const uint8_t channeloffset = ChannelOffset * 4; |
1690 |
memcpy(&pData[113], &channeloffset, 1); |
memcpy(&pData[120], &channeloffset, 1); |
1691 |
|
|
1692 |
{ |
{ |
1693 |
uint8_t regoptions = 0; |
uint8_t regoptions = 0; |
1694 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
1695 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
1696 |
memcpy(&pData[114], ®options, 1); |
memcpy(&pData[121], ®options, 1); |
1697 |
} |
} |
1698 |
|
|
1699 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1700 |
|
|
1701 |
memcpy(&pData[117], &VelocityUpperLimit, 1); |
memcpy(&pData[124], &VelocityUpperLimit, 1); |
1702 |
|
|
1703 |
// next 3 bytes unknown |
// next 3 bytes unknown |
1704 |
|
|
1705 |
memcpy(&pData[121], &ReleaseTriggerDecay, 1); |
memcpy(&pData[128], &ReleaseTriggerDecay, 1); |
1706 |
|
|
1707 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1708 |
|
|
1709 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
1710 |
memcpy(&pData[124], &eg1hold, 1); |
memcpy(&pData[131], &eg1hold, 1); |
1711 |
|
|
1712 |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
1713 |
(VCFCutoff) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
1714 |
memcpy(&pData[125], &vcfcutoff, 1); |
memcpy(&pData[132], &vcfcutoff, 1); |
1715 |
|
|
1716 |
memcpy(&pData[126], &VCFCutoffController, 1); |
memcpy(&pData[133], &VCFCutoffController, 1); |
1717 |
|
|
1718 |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
1719 |
(VCFVelocityScale) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
1720 |
memcpy(&pData[127], &vcfvelscale, 1); |
memcpy(&pData[134], &vcfvelscale, 1); |
1721 |
|
|
1722 |
// next byte unknown |
// next byte unknown |
1723 |
|
|
1724 |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
1725 |
(VCFResonance) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFResonance & 0x7f); /* lower 7 bits */ |
1726 |
memcpy(&pData[129], &vcfresonance, 1); |
memcpy(&pData[136], &vcfresonance, 1); |
1727 |
|
|
1728 |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
1729 |
(VCFKeyboardTrackingBreakpoint) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
1730 |
memcpy(&pData[130], &vcfbreakpoint, 1); |
memcpy(&pData[137], &vcfbreakpoint, 1); |
1731 |
|
|
1732 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
1733 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
1734 |
memcpy(&pData[131], &vcfvelocity, 1); |
memcpy(&pData[138], &vcfvelocity, 1); |
1735 |
|
|
1736 |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
1737 |
memcpy(&pData[132], &vcftype, 1); |
memcpy(&pData[139], &vcftype, 1); |
1738 |
|
|
1739 |
|
if (chunksize >= 148) { |
1740 |
|
memcpy(&pData[140], DimensionUpperLimits, 8); |
1741 |
|
} |
1742 |
} |
} |
1743 |
|
|
1744 |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
1982 |
delete pVelocityTables; |
delete pVelocityTables; |
1983 |
pVelocityTables = NULL; |
pVelocityTables = NULL; |
1984 |
} |
} |
1985 |
|
if (VelocityTable) delete[] VelocityTable; |
1986 |
} |
} |
1987 |
|
|
1988 |
/** |
/** |
2080 |
// * |
// * |
2081 |
|
|
2082 |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
2083 |
|
pInfo->UseFixedLengthStrings = true; |
2084 |
|
|
2085 |
// Initialization |
// Initialization |
2086 |
Dimensions = 0; |
Dimensions = 0; |
2087 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2109 |
pDimensionDefinitions[i].bits = 0; |
pDimensionDefinitions[i].bits = 0; |
2110 |
pDimensionDefinitions[i].zones = 0; |
pDimensionDefinitions[i].zones = 0; |
2111 |
pDimensionDefinitions[i].split_type = split_type_bit; |
pDimensionDefinitions[i].split_type = split_type_bit; |
|
pDimensionDefinitions[i].ranges = NULL; |
|
2112 |
pDimensionDefinitions[i].zone_size = 0; |
pDimensionDefinitions[i].zone_size = 0; |
2113 |
} |
} |
2114 |
else { // active dimension |
else { // active dimension |
2118 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
2119 |
dimension == dimension_samplechannel || |
dimension == dimension_samplechannel || |
2120 |
dimension == dimension_releasetrigger || |
dimension == dimension_releasetrigger || |
2121 |
|
dimension == dimension_keyboard || |
2122 |
dimension == dimension_roundrobin || |
dimension == dimension_roundrobin || |
2123 |
dimension == dimension_random) ? split_type_bit |
dimension == dimension_random || |
2124 |
: split_type_normal; |
dimension == dimension_smartmidi || |
2125 |
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
dimension == dimension_roundrobinkeyboard) ? split_type_bit |
2126 |
|
: split_type_normal; |
2127 |
pDimensionDefinitions[i].zone_size = |
pDimensionDefinitions[i].zone_size = |
2128 |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
2129 |
: 0; |
: 0; |
2134 |
} |
} |
2135 |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
2136 |
} |
} |
2137 |
|
for (int i = dimensionBits ; i < 8 ; i++) pDimensionDefinitions[i].bits = 0; |
2138 |
|
|
2139 |
// check velocity dimension (if there is one) for custom defined zone ranges |
// if there's a velocity dimension and custom velocity zone splits are used, |
2140 |
for (uint i = 0; i < Dimensions; i++) { |
// update the VelocityTables in the dimension regions |
2141 |
dimension_def_t* pDimDef = pDimensionDefinitions + i; |
UpdateVelocityTable(); |
|
if (pDimDef->dimension == dimension_velocity) { |
|
|
if (pDimensionRegions[0]->VelocityUpperLimit == 0) { |
|
|
// no custom defined ranges |
|
|
pDimDef->split_type = split_type_normal; |
|
|
pDimDef->ranges = NULL; |
|
|
} |
|
|
else { // custom defined ranges |
|
|
pDimDef->split_type = split_type_customvelocity; |
|
|
pDimDef->ranges = new range_t[pDimDef->zones]; |
|
|
UpdateVelocityTable(pDimDef); |
|
|
} |
|
|
} |
|
|
} |
|
2142 |
|
|
2143 |
// jump to start of the wave pool indices (if not already there) |
// jump to start of the wave pool indices (if not already there) |
|
File* file = (File*) GetParent()->GetParent(); |
|
2144 |
if (file->pVersion && file->pVersion->major == 3) |
if (file->pVersion && file->pVersion->major == 3) |
2145 |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
2146 |
else |
else |
2149 |
// load sample references |
// load sample references |
2150 |
for (uint i = 0; i < DimensionRegions; i++) { |
for (uint i = 0; i < DimensionRegions; i++) { |
2151 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
2152 |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2153 |
} |
} |
2154 |
|
GetSample(); // load global region sample reference |
2155 |
|
} |
2156 |
|
|
2157 |
|
// make sure there is at least one dimension region |
2158 |
|
if (!DimensionRegions) { |
2159 |
|
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
2160 |
|
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
2161 |
|
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
2162 |
|
pDimensionRegions[0] = new DimensionRegion(_3ewl); |
2163 |
|
DimensionRegions = 1; |
2164 |
} |
} |
2165 |
} |
} |
2166 |
|
|
2178 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(); |
2179 |
|
|
2180 |
// update dimension region's chunks |
// update dimension region's chunks |
2181 |
for (int i = 0; i < Dimensions; i++) |
for (int i = 0; i < DimensionRegions; i++) { |
2182 |
pDimensionRegions[i]->UpdateChunks(); |
pDimensionRegions[i]->UpdateChunks(); |
2183 |
|
} |
2184 |
|
|
2185 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
2186 |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
2195 |
|
|
2196 |
// update dimension definitions in '3lnk' chunk |
// update dimension definitions in '3lnk' chunk |
2197 |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
2198 |
|
memcpy(&pData[0], &DimensionRegions, 4); |
2199 |
for (int i = 0; i < iMaxDimensions; i++) { |
for (int i = 0; i < iMaxDimensions; i++) { |
2200 |
pData[i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
2201 |
pData[i * 8 + 1] = pDimensionDefinitions[i].bits; |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
2202 |
// next 2 bytes unknown |
// next 2 bytes unknown |
2203 |
pData[i * 8 + 4] = pDimensionDefinitions[i].zones; |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
2204 |
// next 3 bytes unknown |
// next 3 bytes unknown |
2205 |
} |
} |
2206 |
|
|
2209 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
2210 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
2211 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
2212 |
if (!pFile->pSamples) throw gig::Exception("Could not update gig::Region, there are no samples"); |
if (!pFile->pSamples || !pFile->pSamples->size()) throw gig::Exception("Could not update gig::Region, there are no samples"); |
2213 |
std::list<Sample*>::iterator iter = pFile->pSamples->begin(); |
File::SampleList::iterator iter = pFile->pSamples->begin(); |
2214 |
std::list<Sample*>::iterator end = pFile->pSamples->end(); |
File::SampleList::iterator end = pFile->pSamples->end(); |
2215 |
for (int index = 0; iter != end; ++iter, ++index) { |
for (int index = 0; iter != end; ++iter, ++index) { |
2216 |
if (*iter == pDimensionRegions[i]->pSample) iWaveIndex = index; |
if (*iter == pDimensionRegions[i]->pSample) { |
2217 |
break; |
iWaveIndex = index; |
2218 |
|
break; |
2219 |
|
} |
2220 |
} |
} |
2221 |
if (iWaveIndex < 0) throw gig::Exception("Could not update gig::Region, could not find DimensionRegion's sample"); |
if (iWaveIndex < 0) throw gig::Exception("Could not update gig::Region, could not find DimensionRegion's sample"); |
2222 |
} |
} |
2240 |
} |
} |
2241 |
} |
} |
2242 |
|
|
2243 |
void Region::UpdateVelocityTable(dimension_def_t* pDimDef) { |
void Region::UpdateVelocityTable() { |
2244 |
// get dimension's index |
// get velocity dimension's index |
2245 |
int iDimensionNr = -1; |
int veldim = -1; |
2246 |
for (int i = 0; i < Dimensions; i++) { |
for (int i = 0 ; i < Dimensions ; i++) { |
2247 |
if (&pDimensionDefinitions[i] == pDimDef) { |
if (pDimensionDefinitions[i].dimension == gig::dimension_velocity) { |
2248 |
iDimensionNr = i; |
veldim = i; |
2249 |
break; |
break; |
2250 |
} |
} |
2251 |
} |
} |
2252 |
if (iDimensionNr < 0) throw gig::Exception("Invalid dimension_def_t pointer"); |
if (veldim == -1) return; |
2253 |
|
|
2254 |
|
int step = 1; |
2255 |
|
for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits; |
2256 |
|
int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step; |
2257 |
|
int end = step * pDimensionDefinitions[veldim].zones; |
2258 |
|
|
2259 |
|
// loop through all dimension regions for all dimensions except the velocity dimension |
2260 |
|
int dim[8] = { 0 }; |
2261 |
|
for (int i = 0 ; i < DimensionRegions ; i++) { |
2262 |
|
|
2263 |
|
if (pDimensionRegions[i]->DimensionUpperLimits[veldim] || |
2264 |
|
pDimensionRegions[i]->VelocityUpperLimit) { |
2265 |
|
// create the velocity table |
2266 |
|
uint8_t* table = pDimensionRegions[i]->VelocityTable; |
2267 |
|
if (!table) { |
2268 |
|
table = new uint8_t[128]; |
2269 |
|
pDimensionRegions[i]->VelocityTable = table; |
2270 |
|
} |
2271 |
|
int tableidx = 0; |
2272 |
|
int velocityZone = 0; |
2273 |
|
if (pDimensionRegions[i]->DimensionUpperLimits[veldim]) { // gig3 |
2274 |
|
for (int k = i ; k < end ; k += step) { |
2275 |
|
DimensionRegion *d = pDimensionRegions[k]; |
2276 |
|
for (; tableidx <= d->DimensionUpperLimits[veldim] ; tableidx++) table[tableidx] = velocityZone; |
2277 |
|
velocityZone++; |
2278 |
|
} |
2279 |
|
} else { // gig2 |
2280 |
|
for (int k = i ; k < end ; k += step) { |
2281 |
|
DimensionRegion *d = pDimensionRegions[k]; |
2282 |
|
for (; tableidx <= d->VelocityUpperLimit ; tableidx++) table[tableidx] = velocityZone; |
2283 |
|
velocityZone++; |
2284 |
|
} |
2285 |
|
} |
2286 |
|
} else { |
2287 |
|
if (pDimensionRegions[i]->VelocityTable) { |
2288 |
|
delete[] pDimensionRegions[i]->VelocityTable; |
2289 |
|
pDimensionRegions[i]->VelocityTable = 0; |
2290 |
|
} |
2291 |
|
} |
2292 |
|
|
2293 |
uint8_t bits[8] = { 0 }; |
int j; |
2294 |
int previousUpperLimit = -1; |
int shift = 0; |
2295 |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
for (j = 0 ; j < Dimensions ; j++) { |
2296 |
bits[iDimensionNr] = velocityZone; |
if (j == veldim) i += skipveldim; // skip velocity dimension |
2297 |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits); |
else { |
2298 |
|
dim[j]++; |
2299 |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
if (dim[j] < pDimensionDefinitions[j].zones) break; |
2300 |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
else { |
2301 |
previousUpperLimit = pDimDef->ranges[velocityZone].high; |
// skip unused dimension regions |
2302 |
// fill velocity table |
dim[j] = 0; |
2303 |
for (int i = pDimDef->ranges[velocityZone].low; i <= pDimDef->ranges[velocityZone].high; i++) { |
i += ((1 << pDimensionDefinitions[j].bits) - |
2304 |
VelocityTable[i] = velocityZone; |
pDimensionDefinitions[j].zones) << shift; |
2305 |
|
} |
2306 |
|
} |
2307 |
|
shift += pDimensionDefinitions[j].bits; |
2308 |
} |
} |
2309 |
|
if (j == Dimensions) break; |
2310 |
} |
} |
2311 |
} |
} |
2312 |
|
|
2361 |
// if this is a layer dimension, update 'Layers' attribute |
// if this is a layer dimension, update 'Layers' attribute |
2362 |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
2363 |
|
|
2364 |
// if this is velocity dimension and got custom defined ranges, update velocity table |
UpdateVelocityTable(); |
|
if (pDimDef->dimension == dimension_velocity && |
|
|
pDimDef->split_type == split_type_customvelocity) { |
|
|
UpdateVelocityTable(pDimDef); |
|
|
} |
|
2365 |
} |
} |
2366 |
|
|
2367 |
/** @brief Delete an existing dimension. |
/** @brief Delete an existing dimension. |
2431 |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
2432 |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
2433 |
pDimensionDefinitions[Dimensions - 1].zones = 0; |
pDimensionDefinitions[Dimensions - 1].zones = 0; |
|
if (pDimensionDefinitions[Dimensions - 1].ranges) { |
|
|
delete[] pDimensionDefinitions[Dimensions - 1].ranges; |
|
|
pDimensionDefinitions[Dimensions - 1].ranges = NULL; |
|
|
} |
|
2434 |
|
|
2435 |
Dimensions--; |
Dimensions--; |
2436 |
|
|
2439 |
} |
} |
2440 |
|
|
2441 |
Region::~Region() { |
Region::~Region() { |
|
for (uint i = 0; i < Dimensions; i++) { |
|
|
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
|
|
} |
|
2442 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2443 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
2444 |
} |
} |
2463 |
* @see Dimensions |
* @see Dimensions |
2464 |
*/ |
*/ |
2465 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
2466 |
uint8_t bits[8] = { 0 }; |
uint8_t bits; |
2467 |
|
int veldim = -1; |
2468 |
|
int velbitpos; |
2469 |
|
int bitpos = 0; |
2470 |
|
int dimregidx = 0; |
2471 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
2472 |
bits[i] = DimValues[i]; |
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
2473 |
switch (pDimensionDefinitions[i].split_type) { |
// the velocity dimension must be handled after the other dimensions |
2474 |
case split_type_normal: |
veldim = i; |
2475 |
bits[i] = uint8_t(bits[i] / pDimensionDefinitions[i].zone_size); |
velbitpos = bitpos; |
2476 |
break; |
} else { |
2477 |
case split_type_customvelocity: |
switch (pDimensionDefinitions[i].split_type) { |
2478 |
bits[i] = VelocityTable[bits[i]]; |
case split_type_normal: |
2479 |
break; |
if (pDimensionRegions[0]->DimensionUpperLimits[i]) { |
2480 |
case split_type_bit: // the value is already the sought dimension bit number |
// gig3: all normal dimensions (not just the velocity dimension) have custom zone ranges |
2481 |
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
for (bits = 0 ; bits < pDimensionDefinitions[i].zones ; bits++) { |
2482 |
bits[i] = bits[i] & limiter_mask; // just make sure the value don't uses more bits than allowed |
if (DimValues[i] <= pDimensionRegions[bits << bitpos]->DimensionUpperLimits[i]) break; |
2483 |
break; |
} |
2484 |
|
} else { |
2485 |
|
// gig2: evenly sized zones |
2486 |
|
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
2487 |
|
} |
2488 |
|
break; |
2489 |
|
case split_type_bit: // the value is already the sought dimension bit number |
2490 |
|
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
2491 |
|
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
2492 |
|
break; |
2493 |
|
} |
2494 |
|
dimregidx |= bits << bitpos; |
2495 |
} |
} |
2496 |
|
bitpos += pDimensionDefinitions[i].bits; |
2497 |
} |
} |
2498 |
return GetDimensionRegionByBit(bits); |
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
2499 |
|
if (veldim != -1) { |
2500 |
|
// (dimreg is now the dimension region for the lowest velocity) |
2501 |
|
if (dimreg->VelocityTable) // custom defined zone ranges |
2502 |
|
bits = dimreg->VelocityTable[DimValues[veldim]]; |
2503 |
|
else // normal split type |
2504 |
|
bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size); |
2505 |
|
|
2506 |
|
dimregidx |= bits << velbitpos; |
2507 |
|
dimreg = pDimensionRegions[dimregidx]; |
2508 |
|
} |
2509 |
|
return dimreg; |
2510 |
} |
} |
2511 |
|
|
2512 |
/** |
/** |
2546 |
Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress) { |
Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress) { |
2547 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
2548 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
2549 |
|
if (!file->pWavePoolTable) return NULL; |
2550 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
2551 |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
2552 |
Sample* sample = file->GetFirstSample(pProgress); |
Sample* sample = file->GetFirstSample(pProgress); |
2553 |
while (sample) { |
while (sample) { |
2554 |
if (sample->ulWavePoolOffset == soughtoffset && |
if (sample->ulWavePoolOffset == soughtoffset && |
2555 |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample); |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
2556 |
sample = file->GetNextSample(); |
sample = file->GetNextSample(); |
2557 |
} |
} |
2558 |
return NULL; |
return NULL; |
2564 |
// * |
// * |
2565 |
|
|
2566 |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
2567 |
|
pInfo->UseFixedLengthStrings = true; |
2568 |
|
|
2569 |
// Initialization |
// Initialization |
2570 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
|
RegionIndex = -1; |
|
2571 |
|
|
2572 |
// Loading |
// Loading |
2573 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
2585 |
} |
} |
2586 |
} |
} |
2587 |
|
|
2588 |
pRegions = new Region*[Regions]; |
if (!pRegions) pRegions = new RegionList; |
2589 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
2590 |
if (lrgn) { |
if (lrgn) { |
|
for (uint i = 0; i < Regions; i++) pRegions[i] = NULL; |
|
2591 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
|
unsigned int iRegion = 0; |
|
2592 |
while (rgn) { |
while (rgn) { |
2593 |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
2594 |
__notify_progress(pProgress, (float) iRegion / (float) Regions); |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
2595 |
pRegions[iRegion] = new Region(this, rgn); |
pRegions->push_back(new Region(this, rgn)); |
|
iRegion++; |
|
2596 |
} |
} |
2597 |
rgn = lrgn->GetNextSubList(); |
rgn = lrgn->GetNextSubList(); |
2598 |
} |
} |
2604 |
} |
} |
2605 |
|
|
2606 |
void Instrument::UpdateRegionKeyTable() { |
void Instrument::UpdateRegionKeyTable() { |
2607 |
for (uint iReg = 0; iReg < Regions; iReg++) { |
RegionList::iterator iter = pRegions->begin(); |
2608 |
for (int iKey = pRegions[iReg]->KeyRange.low; iKey <= pRegions[iReg]->KeyRange.high; iKey++) { |
RegionList::iterator end = pRegions->end(); |
2609 |
RegionKeyTable[iKey] = pRegions[iReg]; |
for (; iter != end; ++iter) { |
2610 |
|
gig::Region* pRegion = static_cast<gig::Region*>(*iter); |
2611 |
|
for (int iKey = pRegion->KeyRange.low; iKey <= pRegion->KeyRange.high; iKey++) { |
2612 |
|
RegionKeyTable[iKey] = pRegion; |
2613 |
} |
} |
2614 |
} |
} |
2615 |
} |
} |
2616 |
|
|
2617 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
|
for (uint i = 0; i < Regions; i++) { |
|
|
if (pRegions) { |
|
|
if (pRegions[i]) delete (pRegions[i]); |
|
|
} |
|
|
} |
|
|
if (pRegions) delete[] pRegions; |
|
2618 |
} |
} |
2619 |
|
|
2620 |
/** |
/** |
2631 |
DLS::Instrument::UpdateChunks(); |
DLS::Instrument::UpdateChunks(); |
2632 |
|
|
2633 |
// update Regions' chunks |
// update Regions' chunks |
2634 |
for (int i = 0; i < Regions; i++) |
{ |
2635 |
pRegions[i]->UpdateChunks(); |
RegionList::iterator iter = pRegions->begin(); |
2636 |
|
RegionList::iterator end = pRegions->end(); |
2637 |
|
for (; iter != end; ++iter) |
2638 |
|
(*iter)->UpdateChunks(); |
2639 |
|
} |
2640 |
|
|
2641 |
// make sure 'lart' RIFF list chunk exists |
// make sure 'lart' RIFF list chunk exists |
2642 |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
2664 |
* there is no Region defined for the given \a Key |
* there is no Region defined for the given \a Key |
2665 |
*/ |
*/ |
2666 |
Region* Instrument::GetRegion(unsigned int Key) { |
Region* Instrument::GetRegion(unsigned int Key) { |
2667 |
if (!pRegions || Key > 127) return NULL; |
if (!pRegions || !pRegions->size() || Key > 127) return NULL; |
2668 |
return RegionKeyTable[Key]; |
return RegionKeyTable[Key]; |
2669 |
|
|
2670 |
/*for (int i = 0; i < Regions; i++) { |
/*for (int i = 0; i < Regions; i++) { |
2671 |
if (Key <= pRegions[i]->KeyRange.high && |
if (Key <= pRegions[i]->KeyRange.high && |
2672 |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
2682 |
* @see GetNextRegion() |
* @see GetNextRegion() |
2683 |
*/ |
*/ |
2684 |
Region* Instrument::GetFirstRegion() { |
Region* Instrument::GetFirstRegion() { |
2685 |
if (!Regions) return NULL; |
if (!pRegions) return NULL; |
2686 |
RegionIndex = 1; |
RegionsIterator = pRegions->begin(); |
2687 |
return pRegions[0]; |
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2688 |
} |
} |
2689 |
|
|
2690 |
/** |
/** |
2696 |
* @see GetFirstRegion() |
* @see GetFirstRegion() |
2697 |
*/ |
*/ |
2698 |
Region* Instrument::GetNextRegion() { |
Region* Instrument::GetNextRegion() { |
2699 |
if (RegionIndex < 0 || uint32_t(RegionIndex) >= Regions) return NULL; |
if (!pRegions) return NULL; |
2700 |
return pRegions[RegionIndex++]; |
RegionsIterator++; |
2701 |
|
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2702 |
} |
} |
2703 |
|
|
2704 |
Region* Instrument::AddRegion() { |
Region* Instrument::AddRegion() { |
2707 |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
2708 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
2709 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
2710 |
// resize 'pRegions' array (increase by one) |
pRegions->push_back(pNewRegion); |
2711 |
Region** pNewRegions = new Region*[Regions + 1]; |
Regions = pRegions->size(); |
|
memcpy(pNewRegions, pRegions, Regions * sizeof(Region*)); |
|
|
// add new Region object |
|
|
pNewRegions[Regions] = pNewRegion; |
|
|
// replace old 'pRegions' array by the new increased array |
|
|
if (pRegions) delete[] pRegions; |
|
|
pRegions = pNewRegions; |
|
|
Regions++; |
|
2712 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2713 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2714 |
// done |
// done |
2717 |
|
|
2718 |
void Instrument::DeleteRegion(Region* pRegion) { |
void Instrument::DeleteRegion(Region* pRegion) { |
2719 |
if (!pRegions) return; |
if (!pRegions) return; |
2720 |
int iOffset = 0; |
DLS::Instrument::DeleteRegion((DLS::Region*) pRegion); |
|
// resize 'pRegions' array (decrease by one) |
|
|
Region** pNewRegions = new Region*[Regions - 1]; |
|
|
for (int i = 0; i < Regions; i++) { |
|
|
if (pRegions[i] == pRegion) { // found Region to delete |
|
|
iOffset = 1; |
|
|
delete pRegion; |
|
|
} |
|
|
if (i < Regions - 1) pNewRegions[i] = pRegions[i + iOffset]; |
|
|
} |
|
|
if (!iOffset) throw gig::Exception("There is no such gig::Region to delete"); |
|
|
// replace old 'pRegions' array by the new decreased array |
|
|
if (pRegions) delete[] pRegions; |
|
|
pRegions = pNewRegions; |
|
|
Regions--; |
|
2721 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2722 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2723 |
} |
} |
2724 |
|
|
2725 |
|
|
2726 |
|
|
2727 |
|
// *************** Group *************** |
2728 |
|
// * |
2729 |
|
|
2730 |
|
/** @brief Constructor. |
2731 |
|
* |
2732 |
|
* @param file - pointer to the gig::File object |
2733 |
|
* @param ck3gnm - pointer to 3gnm chunk associated with this group or |
2734 |
|
* NULL if this is a new Group |
2735 |
|
*/ |
2736 |
|
Group::Group(File* file, RIFF::Chunk* ck3gnm) { |
2737 |
|
pFile = file; |
2738 |
|
pNameChunk = ck3gnm; |
2739 |
|
::LoadString(pNameChunk, Name); |
2740 |
|
} |
2741 |
|
|
2742 |
|
Group::~Group() { |
2743 |
|
} |
2744 |
|
|
2745 |
|
/** @brief Update chunks with current group settings. |
2746 |
|
* |
2747 |
|
* Apply current Group field values to the respective. You have to call |
2748 |
|
* File::Save() to make changes persistent. |
2749 |
|
*/ |
2750 |
|
void Group::UpdateChunks() { |
2751 |
|
// make sure <3gri> and <3gnl> list chunks exist |
2752 |
|
RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); |
2753 |
|
if (!_3gri) _3gri = pFile->pRIFF->AddSubList(LIST_TYPE_3GRI); |
2754 |
|
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
2755 |
|
if (!_3gnl) _3gnl = pFile->pRIFF->AddSubList(LIST_TYPE_3GNL); |
2756 |
|
// now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk |
2757 |
|
::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); |
2758 |
|
} |
2759 |
|
|
2760 |
|
/** |
2761 |
|
* Returns the first Sample of this Group. You have to call this method |
2762 |
|
* once before you use GetNextSample(). |
2763 |
|
* |
2764 |
|
* <b>Notice:</b> this method might block for a long time, in case the |
2765 |
|
* samples of this .gig file were not scanned yet |
2766 |
|
* |
2767 |
|
* @returns pointer address to first Sample or NULL if there is none |
2768 |
|
* applied to this Group |
2769 |
|
* @see GetNextSample() |
2770 |
|
*/ |
2771 |
|
Sample* Group::GetFirstSample() { |
2772 |
|
// FIXME: lazy und unsafe implementation, should be an autonomous iterator |
2773 |
|
for (Sample* pSample = pFile->GetFirstSample(); pSample; pSample = pFile->GetNextSample()) { |
2774 |
|
if (pSample->GetGroup() == this) return pSample; |
2775 |
|
} |
2776 |
|
return NULL; |
2777 |
|
} |
2778 |
|
|
2779 |
|
/** |
2780 |
|
* Returns the next Sample of the Group. You have to call |
2781 |
|
* GetFirstSample() once before you can use this method. By calling this |
2782 |
|
* method multiple times it iterates through the Samples assigned to |
2783 |
|
* this Group. |
2784 |
|
* |
2785 |
|
* @returns pointer address to the next Sample of this Group or NULL if |
2786 |
|
* end reached |
2787 |
|
* @see GetFirstSample() |
2788 |
|
*/ |
2789 |
|
Sample* Group::GetNextSample() { |
2790 |
|
// FIXME: lazy und unsafe implementation, should be an autonomous iterator |
2791 |
|
for (Sample* pSample = pFile->GetNextSample(); pSample; pSample = pFile->GetNextSample()) { |
2792 |
|
if (pSample->GetGroup() == this) return pSample; |
2793 |
|
} |
2794 |
|
return NULL; |
2795 |
|
} |
2796 |
|
|
2797 |
|
/** |
2798 |
|
* Move Sample given by \a pSample from another Group to this Group. |
2799 |
|
*/ |
2800 |
|
void Group::AddSample(Sample* pSample) { |
2801 |
|
pSample->pGroup = this; |
2802 |
|
} |
2803 |
|
|
2804 |
|
/** |
2805 |
|
* Move all members of this group to another group (preferably the 1st |
2806 |
|
* one except this). This method is called explicitly by |
2807 |
|
* File::DeleteGroup() thus when a Group was deleted. This code was |
2808 |
|
* intentionally not placed in the destructor! |
2809 |
|
*/ |
2810 |
|
void Group::MoveAll() { |
2811 |
|
// get "that" other group first |
2812 |
|
Group* pOtherGroup = NULL; |
2813 |
|
for (pOtherGroup = pFile->GetFirstGroup(); pOtherGroup; pOtherGroup = pFile->GetNextGroup()) { |
2814 |
|
if (pOtherGroup != this) break; |
2815 |
|
} |
2816 |
|
if (!pOtherGroup) throw Exception( |
2817 |
|
"Could not move samples to another group, since there is no " |
2818 |
|
"other Group. This is a bug, report it!" |
2819 |
|
); |
2820 |
|
// now move all samples of this group to the other group |
2821 |
|
for (Sample* pSample = GetFirstSample(); pSample; pSample = GetNextSample()) { |
2822 |
|
pOtherGroup->AddSample(pSample); |
2823 |
|
} |
2824 |
|
} |
2825 |
|
|
2826 |
|
|
2827 |
|
|
2828 |
// *************** File *************** |
// *************** File *************** |
2829 |
// * |
// * |
2830 |
|
|
2831 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
2832 |
pSamples = NULL; |
pGroups = NULL; |
2833 |
pInstruments = NULL; |
pInfo->UseFixedLengthStrings = true; |
2834 |
} |
} |
2835 |
|
|
2836 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
2837 |
pSamples = NULL; |
pGroups = NULL; |
2838 |
pInstruments = NULL; |
pInfo->UseFixedLengthStrings = true; |
2839 |
} |
} |
2840 |
|
|
2841 |
File::~File() { |
File::~File() { |
2842 |
// free samples |
if (pGroups) { |
2843 |
if (pSamples) { |
std::list<Group*>::iterator iter = pGroups->begin(); |
2844 |
SamplesIterator = pSamples->begin(); |
std::list<Group*>::iterator end = pGroups->end(); |
2845 |
while (SamplesIterator != pSamples->end() ) { |
while (iter != end) { |
2846 |
delete (*SamplesIterator); |
delete *iter; |
2847 |
SamplesIterator++; |
++iter; |
2848 |
} |
} |
2849 |
pSamples->clear(); |
delete pGroups; |
2850 |
delete pSamples; |
} |
|
|
|
|
} |
|
|
// free instruments |
|
|
if (pInstruments) { |
|
|
InstrumentsIterator = pInstruments->begin(); |
|
|
while (InstrumentsIterator != pInstruments->end() ) { |
|
|
delete (*InstrumentsIterator); |
|
|
InstrumentsIterator++; |
|
|
} |
|
|
pInstruments->clear(); |
|
|
delete pInstruments; |
|
|
} |
|
|
// free extension files |
|
|
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++) |
|
|
delete *i; |
|
2851 |
} |
} |
2852 |
|
|
2853 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
2875 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
2876 |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
2877 |
// create new Sample object and its respective 'wave' list chunk |
// create new Sample object and its respective 'wave' list chunk |
|
if (!pSamples) pSamples = new SampleList; |
|
2878 |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
2879 |
Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/); |
Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/); |
2880 |
pSamples->push_back(pSample); |
pSamples->push_back(pSample); |
2890 |
* @throws gig::Exception if given sample could not be found |
* @throws gig::Exception if given sample could not be found |
2891 |
*/ |
*/ |
2892 |
void File::DeleteSample(Sample* pSample) { |
void File::DeleteSample(Sample* pSample) { |
2893 |
if (!pSamples) throw gig::Exception("Could not delete sample as there are no samples"); |
if (!pSamples || !pSamples->size()) throw gig::Exception("Could not delete sample as there are no samples"); |
2894 |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample); |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample); |
2895 |
if (iter == pSamples->end()) throw gig::Exception("Could not delete sample, could not find given sample"); |
if (iter == pSamples->end()) throw gig::Exception("Could not delete sample, could not find given sample"); |
2896 |
pSamples->erase(iter); |
pSamples->erase(iter); |
2897 |
delete pSample; |
delete pSample; |
2898 |
} |
} |
2899 |
|
|
2900 |
|
void File::LoadSamples() { |
2901 |
|
LoadSamples(NULL); |
2902 |
|
} |
2903 |
|
|
2904 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
2905 |
|
// Groups must be loaded before samples, because samples will try |
2906 |
|
// to resolve the group they belong to |
2907 |
|
LoadGroups(); |
2908 |
|
|
2909 |
|
if (!pSamples) pSamples = new SampleList; |
2910 |
|
|
2911 |
RIFF::File* file = pRIFF; |
RIFF::File* file = pRIFF; |
2912 |
|
|
2913 |
// just for progress calculation |
// just for progress calculation |
2935 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
2936 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
2937 |
|
|
|
if (!pSamples) pSamples = new SampleList; |
|
2938 |
unsigned long waveFileOffset = wave->GetFilePos(); |
unsigned long waveFileOffset = wave->GetFilePos(); |
2939 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
2940 |
|
|
2951 |
name.replace(nameLen, 5, suffix); |
name.replace(nameLen, 5, suffix); |
2952 |
file = new RIFF::File(name); |
file = new RIFF::File(name); |
2953 |
ExtensionFiles.push_back(file); |
ExtensionFiles.push_back(file); |
2954 |
} |
} else break; |
|
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
|
2955 |
} |
} |
2956 |
|
|
2957 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2961 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2962 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2963 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2964 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2965 |
} |
} |
2966 |
|
|
2967 |
Instrument* File::GetNextInstrument() { |
Instrument* File::GetNextInstrument() { |
2968 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2969 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2970 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2971 |
} |
} |
2972 |
|
|
2973 |
/** |
/** |
3000 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
3001 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
3002 |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
3003 |
if (i == index) return *InstrumentsIterator; |
if (i == index) return static_cast<gig::Instrument*>( *InstrumentsIterator ); |
3004 |
InstrumentsIterator++; |
InstrumentsIterator++; |
3005 |
} |
} |
3006 |
return NULL; |
return NULL; |
3016 |
Instrument* File::AddInstrument() { |
Instrument* File::AddInstrument() { |
3017 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
3018 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
3019 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
3020 |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
3021 |
Instrument* pInstrument = new Instrument(this, lstInstr); |
Instrument* pInstrument = new Instrument(this, lstInstr); |
3033 |
*/ |
*/ |
3034 |
void File::DeleteInstrument(Instrument* pInstrument) { |
void File::DeleteInstrument(Instrument* pInstrument) { |
3035 |
if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments"); |
if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments"); |
3036 |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument); |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); |
3037 |
if (iter == pInstruments->end()) throw gig::Exception("Could not delete instrument, could not find given instrument"); |
if (iter == pInstruments->end()) throw gig::Exception("Could not delete instrument, could not find given instrument"); |
3038 |
pInstruments->erase(iter); |
pInstruments->erase(iter); |
3039 |
delete pInstrument; |
delete pInstrument; |
3040 |
} |
} |
3041 |
|
|
3042 |
|
void File::LoadInstruments() { |
3043 |
|
LoadInstruments(NULL); |
3044 |
|
} |
3045 |
|
|
3046 |
void File::LoadInstruments(progress_t* pProgress) { |
void File::LoadInstruments(progress_t* pProgress) { |
3047 |
|
if (!pInstruments) pInstruments = new InstrumentList; |
3048 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
3049 |
if (lstInstruments) { |
if (lstInstruments) { |
3050 |
int iInstrumentIndex = 0; |
int iInstrumentIndex = 0; |
3059 |
progress_t subprogress; |
progress_t subprogress; |
3060 |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
3061 |
|
|
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
3062 |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
3063 |
|
|
3064 |
iInstrumentIndex++; |
iInstrumentIndex++; |
3067 |
} |
} |
3068 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
3069 |
} |
} |
3070 |
else throw gig::Exception("Mandatory <lins> list chunk not found."); |
} |
3071 |
|
|
3072 |
|
Group* File::GetFirstGroup() { |
3073 |
|
if (!pGroups) LoadGroups(); |
3074 |
|
// there must always be at least one group |
3075 |
|
GroupsIterator = pGroups->begin(); |
3076 |
|
return *GroupsIterator; |
3077 |
|
} |
3078 |
|
|
3079 |
|
Group* File::GetNextGroup() { |
3080 |
|
if (!pGroups) return NULL; |
3081 |
|
++GroupsIterator; |
3082 |
|
return (GroupsIterator == pGroups->end()) ? NULL : *GroupsIterator; |
3083 |
|
} |
3084 |
|
|
3085 |
|
/** |
3086 |
|
* Returns the group with the given index. |
3087 |
|
* |
3088 |
|
* @param index - number of the sought group (0..n) |
3089 |
|
* @returns sought group or NULL if there's no such group |
3090 |
|
*/ |
3091 |
|
Group* File::GetGroup(uint index) { |
3092 |
|
if (!pGroups) LoadGroups(); |
3093 |
|
GroupsIterator = pGroups->begin(); |
3094 |
|
for (uint i = 0; GroupsIterator != pGroups->end(); i++) { |
3095 |
|
if (i == index) return *GroupsIterator; |
3096 |
|
++GroupsIterator; |
3097 |
|
} |
3098 |
|
return NULL; |
3099 |
|
} |
3100 |
|
|
3101 |
|
Group* File::AddGroup() { |
3102 |
|
if (!pGroups) LoadGroups(); |
3103 |
|
// there must always be at least one group |
3104 |
|
__ensureMandatoryChunksExist(); |
3105 |
|
Group* pGroup = new Group(this, NULL); |
3106 |
|
pGroups->push_back(pGroup); |
3107 |
|
return pGroup; |
3108 |
|
} |
3109 |
|
|
3110 |
|
void File::DeleteGroup(Group* pGroup) { |
3111 |
|
if (!pGroups) LoadGroups(); |
3112 |
|
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
3113 |
|
if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); |
3114 |
|
if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); |
3115 |
|
// move all members of this group to another group |
3116 |
|
pGroup->MoveAll(); |
3117 |
|
pGroups->erase(iter); |
3118 |
|
delete pGroup; |
3119 |
|
} |
3120 |
|
|
3121 |
|
void File::LoadGroups() { |
3122 |
|
if (!pGroups) pGroups = new std::list<Group*>; |
3123 |
|
// try to read defined groups from file |
3124 |
|
RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
3125 |
|
if (lst3gri) { |
3126 |
|
RIFF::List* lst3gnl = lst3gri->GetSubList(LIST_TYPE_3GNL); |
3127 |
|
if (lst3gnl) { |
3128 |
|
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
3129 |
|
while (ck) { |
3130 |
|
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
3131 |
|
pGroups->push_back(new Group(this, ck)); |
3132 |
|
} |
3133 |
|
ck = lst3gnl->GetNextSubChunk(); |
3134 |
|
} |
3135 |
|
} |
3136 |
|
} |
3137 |
|
// if there were no group(s), create at least the mandatory default group |
3138 |
|
if (!pGroups->size()) { |
3139 |
|
Group* pGroup = new Group(this, NULL); |
3140 |
|
pGroup->Name = "Default Group"; |
3141 |
|
pGroups->push_back(pGroup); |
3142 |
|
} |
3143 |
} |
} |
3144 |
|
|
3145 |
|
|