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 |
|
|
353 |
} |
} |
354 |
FrameOffset = 0; // just for streaming compressed samples |
FrameOffset = 0; // just for streaming compressed samples |
355 |
|
|
356 |
LoopSize = LoopEnd - LoopStart; |
LoopSize = LoopEnd - LoopStart + 1; |
357 |
} |
} |
358 |
|
|
359 |
/** |
/** |
376 |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
377 |
// update 'smpl' chunk |
// update 'smpl' chunk |
378 |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
379 |
SamplePeriod = 1 / SamplesPerSecond; |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
380 |
memcpy(&pData[0], &Manufacturer, 4); |
memcpy(&pData[0], &Manufacturer, 4); |
381 |
memcpy(&pData[4], &Product, 4); |
memcpy(&pData[4], &Product, 4); |
382 |
memcpy(&pData[8], &SamplePeriod, 4); |
memcpy(&pData[8], &SamplePeriod, 4); |
727 |
* @param SampleCount number of sample points to read |
* @param SampleCount number of sample points to read |
728 |
* @param pPlaybackState will be used to store and reload the playback |
* @param pPlaybackState will be used to store and reload the playback |
729 |
* state for the next ReadAndLoop() call |
* state for the next ReadAndLoop() call |
730 |
|
* @param pDimRgn dimension region with looping information |
731 |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
732 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
733 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
734 |
*/ |
*/ |
735 |
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, |
736 |
|
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
737 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
738 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
739 |
|
|
740 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
741 |
|
|
742 |
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 |
743 |
|
|
744 |
switch (this->LoopType) { |
const DLS::sample_loop_t& loop = pDimRgn->pSampleLoops[0]; |
745 |
|
const uint32_t loopEnd = loop.LoopStart + loop.LoopLength; |
746 |
|
|
747 |
case loop_type_bidirectional: { //TODO: not tested yet! |
if (GetPos() <= loopEnd) { |
748 |
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 |
|
749 |
|
|
750 |
// as we can only read forward from disk, we have to |
case loop_type_bidirectional: { //TODO: not tested yet! |
751 |
// determine the end position within the loop first, |
do { |
752 |
// read forward from that 'end' and finally after |
// if not endless loop check if max. number of loop cycles have been passed |
753 |
// reading, swap all sample frames so it reflects |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
754 |
// backward playback |
|
755 |
|
if (!pPlaybackState->reverse) { // forward playback |
756 |
unsigned long swapareastart = totalreadsamples; |
do { |
757 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
samplestoloopend = loopEnd - GetPos(); |
758 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
759 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
samplestoread -= readsamples; |
760 |
|
totalreadsamples += readsamples; |
761 |
SetPos(reverseplaybackend); |
if (readsamples == samplestoloopend) { |
762 |
|
pPlaybackState->reverse = true; |
763 |
// read samples for backward playback |
break; |
764 |
do { |
} |
765 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
} while (samplestoread && readsamples); |
766 |
samplestoreadinloop -= readsamples; |
} |
767 |
samplestoread -= readsamples; |
else { // backward playback |
|
totalreadsamples += readsamples; |
|
|
} while (samplestoreadinloop && readsamples); |
|
768 |
|
|
769 |
SetPos(reverseplaybackend); // pretend we really read backwards |
// as we can only read forward from disk, we have to |
770 |
|
// determine the end position within the loop first, |
771 |
|
// read forward from that 'end' and finally after |
772 |
|
// reading, swap all sample frames so it reflects |
773 |
|
// backward playback |
774 |
|
|
775 |
|
unsigned long swapareastart = totalreadsamples; |
776 |
|
unsigned long loopoffset = GetPos() - loop.LoopStart; |
777 |
|
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
778 |
|
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
779 |
|
|
780 |
|
SetPos(reverseplaybackend); |
781 |
|
|
782 |
|
// read samples for backward playback |
783 |
|
do { |
784 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
785 |
|
samplestoreadinloop -= readsamples; |
786 |
|
samplestoread -= readsamples; |
787 |
|
totalreadsamples += readsamples; |
788 |
|
} while (samplestoreadinloop && readsamples); |
789 |
|
|
790 |
|
SetPos(reverseplaybackend); // pretend we really read backwards |
791 |
|
|
792 |
|
if (reverseplaybackend == loop.LoopStart) { |
793 |
|
pPlaybackState->loop_cycles_left--; |
794 |
|
pPlaybackState->reverse = false; |
795 |
|
} |
796 |
|
|
797 |
if (reverseplaybackend == this->LoopStart) { |
// reverse the sample frames for backward playback |
798 |
pPlaybackState->loop_cycles_left--; |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
|
pPlaybackState->reverse = false; |
|
799 |
} |
} |
800 |
|
} while (samplestoread && readsamples); |
801 |
|
break; |
802 |
|
} |
803 |
|
|
804 |
// reverse the sample frames for backward playback |
case loop_type_backward: { // TODO: not tested yet! |
805 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
// forward playback (not entered the loop yet) |
806 |
} |
if (!pPlaybackState->reverse) do { |
807 |
} while (samplestoread && readsamples); |
samplestoloopend = loopEnd - GetPos(); |
808 |
break; |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
809 |
} |
samplestoread -= readsamples; |
810 |
|
totalreadsamples += readsamples; |
811 |
case loop_type_backward: { // TODO: not tested yet! |
if (readsamples == samplestoloopend) { |
812 |
// forward playback (not entered the loop yet) |
pPlaybackState->reverse = true; |
813 |
if (!pPlaybackState->reverse) do { |
break; |
814 |
samplestoloopend = this->LoopEnd - GetPos(); |
} |
815 |
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); |
|
816 |
|
|
817 |
if (!samplestoread) break; |
if (!samplestoread) break; |
818 |
|
|
819 |
// as we can only read forward from disk, we have to |
// as we can only read forward from disk, we have to |
820 |
// determine the end position within the loop first, |
// determine the end position within the loop first, |
821 |
// read forward from that 'end' and finally after |
// read forward from that 'end' and finally after |
822 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
823 |
// backward playback |
// backward playback |
824 |
|
|
825 |
unsigned long swapareastart = totalreadsamples; |
unsigned long swapareastart = totalreadsamples; |
826 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
827 |
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) |
828 |
: samplestoread; |
: samplestoread; |
829 |
unsigned long reverseplaybackend = this->LoopStart + Abs((loopoffset - samplestoreadinloop) % this->LoopSize); |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
830 |
|
|
831 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
832 |
|
|
833 |
// read samples for backward playback |
// read samples for backward playback |
834 |
do { |
do { |
835 |
// 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 |
836 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
837 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
838 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
839 |
samplestoreadinloop -= readsamples; |
samplestoreadinloop -= readsamples; |
840 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
841 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
842 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
843 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
844 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
845 |
} |
} |
846 |
} while (samplestoreadinloop && readsamples); |
} while (samplestoreadinloop && readsamples); |
847 |
|
|
848 |
SetPos(reverseplaybackend); // pretend we really read backwards |
SetPos(reverseplaybackend); // pretend we really read backwards |
849 |
|
|
850 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
851 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
852 |
break; |
break; |
853 |
} |
} |
854 |
|
|
855 |
default: case loop_type_normal: { |
default: case loop_type_normal: { |
856 |
do { |
do { |
857 |
// 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 |
858 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
859 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
860 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
861 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
862 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
863 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
864 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
865 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
866 |
} |
} |
867 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
868 |
break; |
break; |
869 |
|
} |
870 |
} |
} |
871 |
} |
} |
872 |
} |
} |
896 |
* have to use an external decompression buffer for <b>EACH</b> |
* have to use an external decompression buffer for <b>EACH</b> |
897 |
* streaming thread to avoid race conditions and crashes! |
* streaming thread to avoid race conditions and crashes! |
898 |
* |
* |
899 |
|
* For 16 bit samples, the data in the buffer will be int16_t |
900 |
|
* (using native endianness). For 24 bit, the buffer will |
901 |
|
* contain three bytes per sample, little-endian. |
902 |
|
* |
903 |
* @param pBuffer destination buffer |
* @param pBuffer destination buffer |
904 |
* @param SampleCount number of sample points to read |
* @param SampleCount number of sample points to read |
905 |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
910 |
if (SampleCount == 0) return 0; |
if (SampleCount == 0) return 0; |
911 |
if (!Compressed) { |
if (!Compressed) { |
912 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
913 |
// 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); |
|
|
} |
|
914 |
} |
} |
915 |
else { // 16 bit |
else { // 16 bit |
916 |
// (pCkData->Read does endian correction) |
// (pCkData->Read does endian correction) |
940 |
|
|
941 |
unsigned char* pSrc = (unsigned char*) pDecompressionBuffer->pStart; |
unsigned char* pSrc = (unsigned char*) pDecompressionBuffer->pStart; |
942 |
int16_t* pDst = static_cast<int16_t*>(pBuffer); |
int16_t* pDst = static_cast<int16_t*>(pBuffer); |
943 |
|
uint8_t* pDst24 = static_cast<uint8_t*>(pBuffer); |
944 |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
945 |
|
|
946 |
while (remainingsamples && remainingbytes) { |
while (remainingsamples && remainingbytes) { |
1022 |
const unsigned char* const param_r = pSrc; |
const unsigned char* const param_r = pSrc; |
1023 |
if (mode_r != 2) pSrc += 12; |
if (mode_r != 2) pSrc += 12; |
1024 |
|
|
1025 |
Decompress24(mode_l, param_l, 2, pSrc, pDst, |
Decompress24(mode_l, param_l, 6, pSrc, pDst24, |
1026 |
skipsamples, copysamples, TruncatedBits); |
skipsamples, copysamples, TruncatedBits); |
1027 |
Decompress24(mode_r, param_r, 2, pSrc + rightChannelOffset, pDst + 1, |
Decompress24(mode_r, param_r, 6, pSrc + rightChannelOffset, pDst24 + 3, |
1028 |
skipsamples, copysamples, TruncatedBits); |
skipsamples, copysamples, TruncatedBits); |
1029 |
pDst += copysamples << 1; |
pDst24 += copysamples * 6; |
1030 |
} |
} |
1031 |
else { // Mono |
else { // Mono |
1032 |
Decompress24(mode_l, param_l, 1, pSrc, pDst, |
Decompress24(mode_l, param_l, 3, pSrc, pDst24, |
1033 |
skipsamples, copysamples, TruncatedBits); |
skipsamples, copysamples, TruncatedBits); |
1034 |
pDst += copysamples; |
pDst24 += copysamples * 3; |
1035 |
} |
} |
1036 |
} |
} |
1037 |
else { // 16 bit |
else { // 16 bit |
1160 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1161 |
Instances++; |
Instances++; |
1162 |
|
|
1163 |
|
pSample = NULL; |
1164 |
|
|
1165 |
memcpy(&Crossfade, &SamplerOptions, 4); |
memcpy(&Crossfade, &SamplerOptions, 4); |
1166 |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
1167 |
|
|
1168 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
1169 |
if (_3ewa) { // if '3ewa' chunk exists |
if (_3ewa) { // if '3ewa' chunk exists |
1170 |
_3ewa->ReadInt32(); // unknown, always 0x0000008C ? |
_3ewa->ReadInt32(); // unknown, always == chunk size ? |
1171 |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1172 |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1173 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1426 |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
1427 |
|
|
1428 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1429 |
|
VelocityTable = 0; |
1430 |
} |
} |
1431 |
|
|
1432 |
/** |
/** |
1447 |
|
|
1448 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1449 |
|
|
1450 |
const uint32_t unknown = 0x0000008C; // unknown, always 0x0000008C ? |
const uint32_t unknown = _3ewa->GetSize(); // unknown, always chunk size ? |
1451 |
memcpy(&pData[0], &unknown, 4); |
memcpy(&pData[0], &unknown, 4); |
1452 |
|
|
1453 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
1454 |
memcpy(&pData[4], &lfo3freq, 4); |
memcpy(&pData[4], &lfo3freq, 4); |
1455 |
|
|
1456 |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
1457 |
memcpy(&pData[4], &eg3attack, 4); |
memcpy(&pData[8], &eg3attack, 4); |
1458 |
|
|
1459 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1460 |
|
|
1461 |
memcpy(&pData[10], &LFO1InternalDepth, 2); |
memcpy(&pData[14], &LFO1InternalDepth, 2); |
1462 |
|
|
1463 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1464 |
|
|
1465 |
memcpy(&pData[14], &LFO3InternalDepth, 2); |
memcpy(&pData[18], &LFO3InternalDepth, 2); |
1466 |
|
|
1467 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1468 |
|
|
1469 |
memcpy(&pData[18], &LFO1ControlDepth, 2); |
memcpy(&pData[22], &LFO1ControlDepth, 2); |
1470 |
|
|
1471 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1472 |
|
|
1473 |
memcpy(&pData[22], &LFO3ControlDepth, 2); |
memcpy(&pData[26], &LFO3ControlDepth, 2); |
1474 |
|
|
1475 |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
1476 |
memcpy(&pData[24], &eg1attack, 4); |
memcpy(&pData[28], &eg1attack, 4); |
1477 |
|
|
1478 |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
1479 |
memcpy(&pData[28], &eg1decay1, 4); |
memcpy(&pData[32], &eg1decay1, 4); |
1480 |
|
|
1481 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1482 |
|
|
1483 |
memcpy(&pData[34], &EG1Sustain, 2); |
memcpy(&pData[38], &EG1Sustain, 2); |
1484 |
|
|
1485 |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
1486 |
memcpy(&pData[36], &eg1release, 4); |
memcpy(&pData[40], &eg1release, 4); |
1487 |
|
|
1488 |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
1489 |
memcpy(&pData[40], &eg1ctl, 1); |
memcpy(&pData[44], &eg1ctl, 1); |
1490 |
|
|
1491 |
const uint8_t eg1ctrloptions = |
const uint8_t eg1ctrloptions = |
1492 |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
1493 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
1494 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
1495 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
1496 |
memcpy(&pData[41], &eg1ctrloptions, 1); |
memcpy(&pData[45], &eg1ctrloptions, 1); |
1497 |
|
|
1498 |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
1499 |
memcpy(&pData[42], &eg2ctl, 1); |
memcpy(&pData[46], &eg2ctl, 1); |
1500 |
|
|
1501 |
const uint8_t eg2ctrloptions = |
const uint8_t eg2ctrloptions = |
1502 |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
1503 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
1504 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
1505 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
1506 |
memcpy(&pData[43], &eg2ctrloptions, 1); |
memcpy(&pData[47], &eg2ctrloptions, 1); |
1507 |
|
|
1508 |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
1509 |
memcpy(&pData[44], &lfo1freq, 4); |
memcpy(&pData[48], &lfo1freq, 4); |
1510 |
|
|
1511 |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
1512 |
memcpy(&pData[48], &eg2attack, 4); |
memcpy(&pData[52], &eg2attack, 4); |
1513 |
|
|
1514 |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
1515 |
memcpy(&pData[52], &eg2decay1, 4); |
memcpy(&pData[56], &eg2decay1, 4); |
1516 |
|
|
1517 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1518 |
|
|
1519 |
memcpy(&pData[58], &EG2Sustain, 2); |
memcpy(&pData[62], &EG2Sustain, 2); |
1520 |
|
|
1521 |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
1522 |
memcpy(&pData[60], &eg2release, 4); |
memcpy(&pData[64], &eg2release, 4); |
1523 |
|
|
1524 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1525 |
|
|
1526 |
memcpy(&pData[66], &LFO2ControlDepth, 2); |
memcpy(&pData[70], &LFO2ControlDepth, 2); |
1527 |
|
|
1528 |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
1529 |
memcpy(&pData[68], &lfo2freq, 4); |
memcpy(&pData[72], &lfo2freq, 4); |
1530 |
|
|
1531 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1532 |
|
|
1533 |
memcpy(&pData[72], &LFO2InternalDepth, 2); |
memcpy(&pData[78], &LFO2InternalDepth, 2); |
1534 |
|
|
1535 |
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); |
1536 |
memcpy(&pData[74], &eg1decay2, 4); |
memcpy(&pData[80], &eg1decay2, 4); |
1537 |
|
|
1538 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1539 |
|
|
1540 |
memcpy(&pData[80], &EG1PreAttack, 2); |
memcpy(&pData[86], &EG1PreAttack, 2); |
1541 |
|
|
1542 |
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); |
1543 |
memcpy(&pData[82], &eg2decay2, 4); |
memcpy(&pData[88], &eg2decay2, 4); |
1544 |
|
|
1545 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1546 |
|
|
1547 |
memcpy(&pData[88], &EG2PreAttack, 2); |
memcpy(&pData[94], &EG2PreAttack, 2); |
1548 |
|
|
1549 |
{ |
{ |
1550 |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
1562 |
default: |
default: |
1563 |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
1564 |
} |
} |
1565 |
memcpy(&pData[90], &velocityresponse, 1); |
memcpy(&pData[96], &velocityresponse, 1); |
1566 |
} |
} |
1567 |
|
|
1568 |
{ |
{ |
1581 |
default: |
default: |
1582 |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
1583 |
} |
} |
1584 |
memcpy(&pData[91], &releasevelocityresponse, 1); |
memcpy(&pData[97], &releasevelocityresponse, 1); |
1585 |
} |
} |
1586 |
|
|
1587 |
memcpy(&pData[92], &VelocityResponseCurveScaling, 1); |
memcpy(&pData[98], &VelocityResponseCurveScaling, 1); |
1588 |
|
|
1589 |
memcpy(&pData[93], &AttenuationControllerThreshold, 1); |
memcpy(&pData[99], &AttenuationControllerThreshold, 1); |
1590 |
|
|
1591 |
// next 4 bytes unknown |
// next 4 bytes unknown |
1592 |
|
|
1593 |
memcpy(&pData[98], &SampleStartOffset, 2); |
memcpy(&pData[104], &SampleStartOffset, 2); |
1594 |
|
|
1595 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1596 |
|
|
1609 |
default: |
default: |
1610 |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
1611 |
} |
} |
1612 |
memcpy(&pData[102], &pitchTrackDimensionBypass, 1); |
memcpy(&pData[108], &pitchTrackDimensionBypass, 1); |
1613 |
} |
} |
1614 |
|
|
1615 |
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 |
1616 |
memcpy(&pData[103], &pan, 1); |
memcpy(&pData[109], &pan, 1); |
1617 |
|
|
1618 |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
1619 |
memcpy(&pData[104], &selfmask, 1); |
memcpy(&pData[110], &selfmask, 1); |
1620 |
|
|
1621 |
// next byte unknown |
// next byte unknown |
1622 |
|
|
1625 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
1626 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
1627 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
1628 |
memcpy(&pData[106], &lfo3ctrl, 1); |
memcpy(&pData[112], &lfo3ctrl, 1); |
1629 |
} |
} |
1630 |
|
|
1631 |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
1632 |
memcpy(&pData[107], &attenctl, 1); |
memcpy(&pData[113], &attenctl, 1); |
1633 |
|
|
1634 |
{ |
{ |
1635 |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
1636 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
1637 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
1638 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
1639 |
memcpy(&pData[108], &lfo2ctrl, 1); |
memcpy(&pData[114], &lfo2ctrl, 1); |
1640 |
} |
} |
1641 |
|
|
1642 |
{ |
{ |
1645 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
1646 |
if (VCFResonanceController != vcf_res_ctrl_none) |
if (VCFResonanceController != vcf_res_ctrl_none) |
1647 |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
1648 |
memcpy(&pData[109], &lfo1ctrl, 1); |
memcpy(&pData[115], &lfo1ctrl, 1); |
1649 |
} |
} |
1650 |
|
|
1651 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
1652 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
1653 |
memcpy(&pData[110], &eg3depth, 1); |
memcpy(&pData[116], &eg3depth, 1); |
1654 |
|
|
1655 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1656 |
|
|
1657 |
const uint8_t channeloffset = ChannelOffset * 4; |
const uint8_t channeloffset = ChannelOffset * 4; |
1658 |
memcpy(&pData[113], &channeloffset, 1); |
memcpy(&pData[120], &channeloffset, 1); |
1659 |
|
|
1660 |
{ |
{ |
1661 |
uint8_t regoptions = 0; |
uint8_t regoptions = 0; |
1662 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
1663 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
1664 |
memcpy(&pData[114], ®options, 1); |
memcpy(&pData[121], ®options, 1); |
1665 |
} |
} |
1666 |
|
|
1667 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1668 |
|
|
1669 |
memcpy(&pData[117], &VelocityUpperLimit, 1); |
memcpy(&pData[124], &VelocityUpperLimit, 1); |
1670 |
|
|
1671 |
// next 3 bytes unknown |
// next 3 bytes unknown |
1672 |
|
|
1673 |
memcpy(&pData[121], &ReleaseTriggerDecay, 1); |
memcpy(&pData[128], &ReleaseTriggerDecay, 1); |
1674 |
|
|
1675 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1676 |
|
|
1677 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
1678 |
memcpy(&pData[124], &eg1hold, 1); |
memcpy(&pData[131], &eg1hold, 1); |
1679 |
|
|
1680 |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
1681 |
(VCFCutoff) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
1682 |
memcpy(&pData[125], &vcfcutoff, 1); |
memcpy(&pData[132], &vcfcutoff, 1); |
1683 |
|
|
1684 |
memcpy(&pData[126], &VCFCutoffController, 1); |
memcpy(&pData[133], &VCFCutoffController, 1); |
1685 |
|
|
1686 |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
1687 |
(VCFVelocityScale) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
1688 |
memcpy(&pData[127], &vcfvelscale, 1); |
memcpy(&pData[134], &vcfvelscale, 1); |
1689 |
|
|
1690 |
// next byte unknown |
// next byte unknown |
1691 |
|
|
1692 |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
1693 |
(VCFResonance) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFResonance & 0x7f); /* lower 7 bits */ |
1694 |
memcpy(&pData[129], &vcfresonance, 1); |
memcpy(&pData[136], &vcfresonance, 1); |
1695 |
|
|
1696 |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
1697 |
(VCFKeyboardTrackingBreakpoint) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
1698 |
memcpy(&pData[130], &vcfbreakpoint, 1); |
memcpy(&pData[137], &vcfbreakpoint, 1); |
1699 |
|
|
1700 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
1701 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
1702 |
memcpy(&pData[131], &vcfvelocity, 1); |
memcpy(&pData[138], &vcfvelocity, 1); |
1703 |
|
|
1704 |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
1705 |
memcpy(&pData[132], &vcftype, 1); |
memcpy(&pData[139], &vcftype, 1); |
1706 |
} |
} |
1707 |
|
|
1708 |
// 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 |
1946 |
delete pVelocityTables; |
delete pVelocityTables; |
1947 |
pVelocityTables = NULL; |
pVelocityTables = NULL; |
1948 |
} |
} |
1949 |
|
if (VelocityTable) delete[] VelocityTable; |
1950 |
} |
} |
1951 |
|
|
1952 |
/** |
/** |
2044 |
// * |
// * |
2045 |
|
|
2046 |
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) { |
2047 |
|
pInfo->UseFixedLengthStrings = true; |
2048 |
|
|
2049 |
// Initialization |
// Initialization |
2050 |
Dimensions = 0; |
Dimensions = 0; |
2051 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2073 |
pDimensionDefinitions[i].bits = 0; |
pDimensionDefinitions[i].bits = 0; |
2074 |
pDimensionDefinitions[i].zones = 0; |
pDimensionDefinitions[i].zones = 0; |
2075 |
pDimensionDefinitions[i].split_type = split_type_bit; |
pDimensionDefinitions[i].split_type = split_type_bit; |
|
pDimensionDefinitions[i].ranges = NULL; |
|
2076 |
pDimensionDefinitions[i].zone_size = 0; |
pDimensionDefinitions[i].zone_size = 0; |
2077 |
} |
} |
2078 |
else { // active dimension |
else { // active dimension |
2082 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
2083 |
dimension == dimension_samplechannel || |
dimension == dimension_samplechannel || |
2084 |
dimension == dimension_releasetrigger || |
dimension == dimension_releasetrigger || |
2085 |
|
dimension == dimension_keyboard || |
2086 |
dimension == dimension_roundrobin || |
dimension == dimension_roundrobin || |
2087 |
dimension == dimension_random) ? split_type_bit |
dimension == dimension_random) ? split_type_bit |
2088 |
: split_type_normal; |
: split_type_normal; |
|
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
|
2089 |
pDimensionDefinitions[i].zone_size = |
pDimensionDefinitions[i].zone_size = |
2090 |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
2091 |
: 0; |
: 0; |
2096 |
} |
} |
2097 |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
2098 |
} |
} |
2099 |
|
for (int i = dimensionBits ; i < 8 ; i++) pDimensionDefinitions[i].bits = 0; |
2100 |
|
|
2101 |
// 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, |
2102 |
for (uint i = 0; i < Dimensions; i++) { |
// update the VelocityTables in the dimension regions |
2103 |
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); |
|
|
} |
|
|
} |
|
|
} |
|
2104 |
|
|
2105 |
// 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(); |
|
2106 |
if (file->pVersion && file->pVersion->major == 3) |
if (file->pVersion && file->pVersion->major == 3) |
2107 |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
2108 |
else |
else |
2111 |
// load sample references |
// load sample references |
2112 |
for (uint i = 0; i < DimensionRegions; i++) { |
for (uint i = 0; i < DimensionRegions; i++) { |
2113 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
2114 |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2115 |
} |
} |
2116 |
|
GetSample(); // load global region sample reference |
2117 |
|
} |
2118 |
|
|
2119 |
|
// make sure there is at least one dimension region |
2120 |
|
if (!DimensionRegions) { |
2121 |
|
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
2122 |
|
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
2123 |
|
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
2124 |
|
pDimensionRegions[0] = new DimensionRegion(_3ewl); |
2125 |
|
DimensionRegions = 1; |
2126 |
} |
} |
2127 |
} |
} |
2128 |
|
|
2140 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(); |
2141 |
|
|
2142 |
// update dimension region's chunks |
// update dimension region's chunks |
2143 |
for (int i = 0; i < Dimensions; i++) |
for (int i = 0; i < DimensionRegions; i++) { |
2144 |
pDimensionRegions[i]->UpdateChunks(); |
pDimensionRegions[i]->UpdateChunks(); |
2145 |
|
} |
2146 |
|
|
2147 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
2148 |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
2157 |
|
|
2158 |
// update dimension definitions in '3lnk' chunk |
// update dimension definitions in '3lnk' chunk |
2159 |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
2160 |
|
memcpy(&pData[0], &DimensionRegions, 4); |
2161 |
for (int i = 0; i < iMaxDimensions; i++) { |
for (int i = 0; i < iMaxDimensions; i++) { |
2162 |
pData[i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
2163 |
pData[i * 8 + 1] = pDimensionDefinitions[i].bits; |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
2164 |
// next 2 bytes unknown |
// next 2 bytes unknown |
2165 |
pData[i * 8 + 4] = pDimensionDefinitions[i].zones; |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
2166 |
// next 3 bytes unknown |
// next 3 bytes unknown |
2167 |
} |
} |
2168 |
|
|
2171 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
2172 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
2173 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
2174 |
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"); |
2175 |
std::list<Sample*>::iterator iter = pFile->pSamples->begin(); |
File::SampleList::iterator iter = pFile->pSamples->begin(); |
2176 |
std::list<Sample*>::iterator end = pFile->pSamples->end(); |
File::SampleList::iterator end = pFile->pSamples->end(); |
2177 |
for (int index = 0; iter != end; ++iter, ++index) { |
for (int index = 0; iter != end; ++iter, ++index) { |
2178 |
if (*iter == pDimensionRegions[i]->pSample) iWaveIndex = index; |
if (*iter == pDimensionRegions[i]->pSample) { |
2179 |
break; |
iWaveIndex = index; |
2180 |
|
break; |
2181 |
|
} |
2182 |
} |
} |
2183 |
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"); |
2184 |
} |
} |
2202 |
} |
} |
2203 |
} |
} |
2204 |
|
|
2205 |
void Region::UpdateVelocityTable(dimension_def_t* pDimDef) { |
void Region::UpdateVelocityTable() { |
2206 |
// get dimension's index |
// get velocity dimension's index |
2207 |
int iDimensionNr = -1; |
int veldim = -1; |
2208 |
for (int i = 0; i < Dimensions; i++) { |
for (int i = 0 ; i < Dimensions ; i++) { |
2209 |
if (&pDimensionDefinitions[i] == pDimDef) { |
if (pDimensionDefinitions[i].dimension == gig::dimension_velocity) { |
2210 |
iDimensionNr = i; |
veldim = i; |
2211 |
break; |
break; |
2212 |
} |
} |
2213 |
} |
} |
2214 |
if (iDimensionNr < 0) throw gig::Exception("Invalid dimension_def_t pointer"); |
if (veldim == -1) return; |
2215 |
|
|
2216 |
|
int step = 1; |
2217 |
|
for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits; |
2218 |
|
int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step; |
2219 |
|
int end = step * pDimensionDefinitions[veldim].zones; |
2220 |
|
|
2221 |
|
// loop through all dimension regions for all dimensions except the velocity dimension |
2222 |
|
int dim[8] = { 0 }; |
2223 |
|
for (int i = 0 ; i < DimensionRegions ; i++) { |
2224 |
|
|
2225 |
|
if (pDimensionRegions[i]->VelocityUpperLimit) { |
2226 |
|
// create the velocity table |
2227 |
|
uint8_t* table = pDimensionRegions[i]->VelocityTable; |
2228 |
|
if (!table) { |
2229 |
|
table = new uint8_t[128]; |
2230 |
|
pDimensionRegions[i]->VelocityTable = table; |
2231 |
|
} |
2232 |
|
int tableidx = 0; |
2233 |
|
int velocityZone = 0; |
2234 |
|
for (int k = i ; k < end ; k += step) { |
2235 |
|
DimensionRegion *d = pDimensionRegions[k]; |
2236 |
|
for (; tableidx <= d->VelocityUpperLimit ; tableidx++) table[tableidx] = velocityZone; |
2237 |
|
velocityZone++; |
2238 |
|
} |
2239 |
|
} else { |
2240 |
|
if (pDimensionRegions[i]->VelocityTable) { |
2241 |
|
delete[] pDimensionRegions[i]->VelocityTable; |
2242 |
|
pDimensionRegions[i]->VelocityTable = 0; |
2243 |
|
} |
2244 |
|
} |
2245 |
|
|
2246 |
uint8_t bits[8] = { 0 }; |
int j; |
2247 |
int previousUpperLimit = -1; |
int shift = 0; |
2248 |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
for (j = 0 ; j < Dimensions ; j++) { |
2249 |
bits[iDimensionNr] = velocityZone; |
if (j == veldim) i += skipveldim; // skip velocity dimension |
2250 |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits); |
else { |
2251 |
|
dim[j]++; |
2252 |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
if (dim[j] < pDimensionDefinitions[j].zones) break; |
2253 |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
else { |
2254 |
previousUpperLimit = pDimDef->ranges[velocityZone].high; |
// skip unused dimension regions |
2255 |
// fill velocity table |
dim[j] = 0; |
2256 |
for (int i = pDimDef->ranges[velocityZone].low; i <= pDimDef->ranges[velocityZone].high; i++) { |
i += ((1 << pDimensionDefinitions[j].bits) - |
2257 |
VelocityTable[i] = velocityZone; |
pDimensionDefinitions[j].zones) << shift; |
2258 |
|
} |
2259 |
|
} |
2260 |
|
shift += pDimensionDefinitions[j].bits; |
2261 |
} |
} |
2262 |
|
if (j == Dimensions) break; |
2263 |
} |
} |
2264 |
} |
} |
2265 |
|
|
2314 |
// if this is a layer dimension, update 'Layers' attribute |
// if this is a layer dimension, update 'Layers' attribute |
2315 |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
2316 |
|
|
2317 |
// 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); |
|
|
} |
|
2318 |
} |
} |
2319 |
|
|
2320 |
/** @brief Delete an existing dimension. |
/** @brief Delete an existing dimension. |
2384 |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
2385 |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
2386 |
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; |
|
|
} |
|
2387 |
|
|
2388 |
Dimensions--; |
Dimensions--; |
2389 |
|
|
2392 |
} |
} |
2393 |
|
|
2394 |
Region::~Region() { |
Region::~Region() { |
|
for (uint i = 0; i < Dimensions; i++) { |
|
|
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
|
|
} |
|
2395 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2396 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
2397 |
} |
} |
2416 |
* @see Dimensions |
* @see Dimensions |
2417 |
*/ |
*/ |
2418 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
2419 |
uint8_t bits[8] = { 0 }; |
uint8_t bits; |
2420 |
|
int veldim = -1; |
2421 |
|
int velbitpos; |
2422 |
|
int bitpos = 0; |
2423 |
|
int dimregidx = 0; |
2424 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
2425 |
bits[i] = DimValues[i]; |
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
2426 |
switch (pDimensionDefinitions[i].split_type) { |
// the velocity dimension must be handled after the other dimensions |
2427 |
case split_type_normal: |
veldim = i; |
2428 |
bits[i] = uint8_t(bits[i] / pDimensionDefinitions[i].zone_size); |
velbitpos = bitpos; |
2429 |
break; |
} else { |
2430 |
case split_type_customvelocity: |
switch (pDimensionDefinitions[i].split_type) { |
2431 |
bits[i] = VelocityTable[bits[i]]; |
case split_type_normal: |
2432 |
break; |
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
2433 |
case split_type_bit: // the value is already the sought dimension bit number |
break; |
2434 |
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
case split_type_bit: // the value is already the sought dimension bit number |
2435 |
bits[i] = bits[i] & limiter_mask; // just make sure the value don't uses more bits than allowed |
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
2436 |
break; |
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
2437 |
|
break; |
2438 |
|
} |
2439 |
|
dimregidx |= bits << bitpos; |
2440 |
} |
} |
2441 |
|
bitpos += pDimensionDefinitions[i].bits; |
2442 |
|
} |
2443 |
|
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
2444 |
|
if (veldim != -1) { |
2445 |
|
// (dimreg is now the dimension region for the lowest velocity) |
2446 |
|
if (dimreg->VelocityUpperLimit) // custom defined zone ranges |
2447 |
|
bits = dimreg->VelocityTable[DimValues[veldim]]; |
2448 |
|
else // normal split type |
2449 |
|
bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size); |
2450 |
|
|
2451 |
|
dimregidx |= bits << velbitpos; |
2452 |
|
dimreg = pDimensionRegions[dimregidx]; |
2453 |
} |
} |
2454 |
return GetDimensionRegionByBit(bits); |
return dimreg; |
2455 |
} |
} |
2456 |
|
|
2457 |
/** |
/** |
2491 |
Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress) { |
Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress) { |
2492 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
2493 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
2494 |
|
if (!file->pWavePoolTable) return NULL; |
2495 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
2496 |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
2497 |
Sample* sample = file->GetFirstSample(pProgress); |
Sample* sample = file->GetFirstSample(pProgress); |
2498 |
while (sample) { |
while (sample) { |
2499 |
if (sample->ulWavePoolOffset == soughtoffset && |
if (sample->ulWavePoolOffset == soughtoffset && |
2500 |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample); |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
2501 |
sample = file->GetNextSample(); |
sample = file->GetNextSample(); |
2502 |
} |
} |
2503 |
return NULL; |
return NULL; |
2509 |
// * |
// * |
2510 |
|
|
2511 |
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) { |
2512 |
|
pInfo->UseFixedLengthStrings = true; |
2513 |
|
|
2514 |
// Initialization |
// Initialization |
2515 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
|
RegionIndex = -1; |
|
2516 |
|
|
2517 |
// Loading |
// Loading |
2518 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
2530 |
} |
} |
2531 |
} |
} |
2532 |
|
|
2533 |
pRegions = new Region*[Regions]; |
if (!pRegions) pRegions = new RegionList; |
2534 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
2535 |
if (lrgn) { |
if (lrgn) { |
|
for (uint i = 0; i < Regions; i++) pRegions[i] = NULL; |
|
2536 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
|
unsigned int iRegion = 0; |
|
2537 |
while (rgn) { |
while (rgn) { |
2538 |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
2539 |
__notify_progress(pProgress, (float) iRegion / (float) Regions); |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
2540 |
pRegions[iRegion] = new Region(this, rgn); |
pRegions->push_back(new Region(this, rgn)); |
|
iRegion++; |
|
2541 |
} |
} |
2542 |
rgn = lrgn->GetNextSubList(); |
rgn = lrgn->GetNextSubList(); |
2543 |
} |
} |
2549 |
} |
} |
2550 |
|
|
2551 |
void Instrument::UpdateRegionKeyTable() { |
void Instrument::UpdateRegionKeyTable() { |
2552 |
for (uint iReg = 0; iReg < Regions; iReg++) { |
RegionList::iterator iter = pRegions->begin(); |
2553 |
for (int iKey = pRegions[iReg]->KeyRange.low; iKey <= pRegions[iReg]->KeyRange.high; iKey++) { |
RegionList::iterator end = pRegions->end(); |
2554 |
RegionKeyTable[iKey] = pRegions[iReg]; |
for (; iter != end; ++iter) { |
2555 |
|
gig::Region* pRegion = static_cast<gig::Region*>(*iter); |
2556 |
|
for (int iKey = pRegion->KeyRange.low; iKey <= pRegion->KeyRange.high; iKey++) { |
2557 |
|
RegionKeyTable[iKey] = pRegion; |
2558 |
} |
} |
2559 |
} |
} |
2560 |
} |
} |
2561 |
|
|
2562 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
|
for (uint i = 0; i < Regions; i++) { |
|
|
if (pRegions) { |
|
|
if (pRegions[i]) delete (pRegions[i]); |
|
|
} |
|
|
} |
|
|
if (pRegions) delete[] pRegions; |
|
2563 |
} |
} |
2564 |
|
|
2565 |
/** |
/** |
2576 |
DLS::Instrument::UpdateChunks(); |
DLS::Instrument::UpdateChunks(); |
2577 |
|
|
2578 |
// update Regions' chunks |
// update Regions' chunks |
2579 |
for (int i = 0; i < Regions; i++) |
{ |
2580 |
pRegions[i]->UpdateChunks(); |
RegionList::iterator iter = pRegions->begin(); |
2581 |
|
RegionList::iterator end = pRegions->end(); |
2582 |
|
for (; iter != end; ++iter) |
2583 |
|
(*iter)->UpdateChunks(); |
2584 |
|
} |
2585 |
|
|
2586 |
// make sure 'lart' RIFF list chunk exists |
// make sure 'lart' RIFF list chunk exists |
2587 |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
2609 |
* there is no Region defined for the given \a Key |
* there is no Region defined for the given \a Key |
2610 |
*/ |
*/ |
2611 |
Region* Instrument::GetRegion(unsigned int Key) { |
Region* Instrument::GetRegion(unsigned int Key) { |
2612 |
if (!pRegions || Key > 127) return NULL; |
if (!pRegions || !pRegions->size() || Key > 127) return NULL; |
2613 |
return RegionKeyTable[Key]; |
return RegionKeyTable[Key]; |
2614 |
|
|
2615 |
/*for (int i = 0; i < Regions; i++) { |
/*for (int i = 0; i < Regions; i++) { |
2616 |
if (Key <= pRegions[i]->KeyRange.high && |
if (Key <= pRegions[i]->KeyRange.high && |
2617 |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
2627 |
* @see GetNextRegion() |
* @see GetNextRegion() |
2628 |
*/ |
*/ |
2629 |
Region* Instrument::GetFirstRegion() { |
Region* Instrument::GetFirstRegion() { |
2630 |
if (!Regions) return NULL; |
if (!pRegions) return NULL; |
2631 |
RegionIndex = 1; |
RegionsIterator = pRegions->begin(); |
2632 |
return pRegions[0]; |
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2633 |
} |
} |
2634 |
|
|
2635 |
/** |
/** |
2641 |
* @see GetFirstRegion() |
* @see GetFirstRegion() |
2642 |
*/ |
*/ |
2643 |
Region* Instrument::GetNextRegion() { |
Region* Instrument::GetNextRegion() { |
2644 |
if (RegionIndex < 0 || uint32_t(RegionIndex) >= Regions) return NULL; |
if (!pRegions) return NULL; |
2645 |
return pRegions[RegionIndex++]; |
RegionsIterator++; |
2646 |
|
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2647 |
} |
} |
2648 |
|
|
2649 |
Region* Instrument::AddRegion() { |
Region* Instrument::AddRegion() { |
2652 |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
2653 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
2654 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
2655 |
// resize 'pRegions' array (increase by one) |
pRegions->push_back(pNewRegion); |
2656 |
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++; |
|
2657 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2658 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2659 |
// done |
// done |
2662 |
|
|
2663 |
void Instrument::DeleteRegion(Region* pRegion) { |
void Instrument::DeleteRegion(Region* pRegion) { |
2664 |
if (!pRegions) return; |
if (!pRegions) return; |
2665 |
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--; |
|
2666 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2667 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2668 |
} |
} |
2673 |
// * |
// * |
2674 |
|
|
2675 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
2676 |
pSamples = NULL; |
pInfo->UseFixedLengthStrings = true; |
|
pInstruments = NULL; |
|
2677 |
} |
} |
2678 |
|
|
2679 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
2680 |
pSamples = NULL; |
pInfo->UseFixedLengthStrings = true; |
|
pInstruments = NULL; |
|
|
} |
|
|
|
|
|
File::~File() { |
|
|
// free samples |
|
|
if (pSamples) { |
|
|
SamplesIterator = pSamples->begin(); |
|
|
while (SamplesIterator != pSamples->end() ) { |
|
|
delete (*SamplesIterator); |
|
|
SamplesIterator++; |
|
|
} |
|
|
pSamples->clear(); |
|
|
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; |
|
2681 |
} |
} |
2682 |
|
|
2683 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
2705 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
2706 |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
2707 |
// 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; |
|
2708 |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
2709 |
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*/); |
2710 |
pSamples->push_back(pSample); |
pSamples->push_back(pSample); |
2720 |
* @throws gig::Exception if given sample could not be found |
* @throws gig::Exception if given sample could not be found |
2721 |
*/ |
*/ |
2722 |
void File::DeleteSample(Sample* pSample) { |
void File::DeleteSample(Sample* pSample) { |
2723 |
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"); |
2724 |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample); |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample); |
2725 |
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"); |
2726 |
pSamples->erase(iter); |
pSamples->erase(iter); |
2727 |
delete pSample; |
delete pSample; |
2728 |
} |
} |
2729 |
|
|
2730 |
|
void File::LoadSamples() { |
2731 |
|
LoadSamples(NULL); |
2732 |
|
} |
2733 |
|
|
2734 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
2735 |
|
if (!pSamples) pSamples = new SampleList; |
2736 |
|
|
2737 |
RIFF::File* file = pRIFF; |
RIFF::File* file = pRIFF; |
2738 |
|
|
2739 |
// just for progress calculation |
// just for progress calculation |
2761 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
2762 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
2763 |
|
|
|
if (!pSamples) pSamples = new SampleList; |
|
2764 |
unsigned long waveFileOffset = wave->GetFilePos(); |
unsigned long waveFileOffset = wave->GetFilePos(); |
2765 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
2766 |
|
|
2777 |
name.replace(nameLen, 5, suffix); |
name.replace(nameLen, 5, suffix); |
2778 |
file = new RIFF::File(name); |
file = new RIFF::File(name); |
2779 |
ExtensionFiles.push_back(file); |
ExtensionFiles.push_back(file); |
2780 |
} |
} else break; |
|
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
|
2781 |
} |
} |
2782 |
|
|
2783 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2787 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2788 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2789 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2790 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2791 |
} |
} |
2792 |
|
|
2793 |
Instrument* File::GetNextInstrument() { |
Instrument* File::GetNextInstrument() { |
2794 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2795 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2796 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2797 |
} |
} |
2798 |
|
|
2799 |
/** |
/** |
2826 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2827 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2828 |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
2829 |
if (i == index) return *InstrumentsIterator; |
if (i == index) return static_cast<gig::Instrument*>( *InstrumentsIterator ); |
2830 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2831 |
} |
} |
2832 |
return NULL; |
return NULL; |
2842 |
Instrument* File::AddInstrument() { |
Instrument* File::AddInstrument() { |
2843 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2844 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
2845 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
2846 |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
2847 |
Instrument* pInstrument = new Instrument(this, lstInstr); |
Instrument* pInstrument = new Instrument(this, lstInstr); |
2859 |
*/ |
*/ |
2860 |
void File::DeleteInstrument(Instrument* pInstrument) { |
void File::DeleteInstrument(Instrument* pInstrument) { |
2861 |
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"); |
2862 |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument); |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); |
2863 |
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"); |
2864 |
pInstruments->erase(iter); |
pInstruments->erase(iter); |
2865 |
delete pInstrument; |
delete pInstrument; |
2866 |
} |
} |
2867 |
|
|
2868 |
|
void File::LoadInstruments() { |
2869 |
|
LoadInstruments(NULL); |
2870 |
|
} |
2871 |
|
|
2872 |
void File::LoadInstruments(progress_t* pProgress) { |
void File::LoadInstruments(progress_t* pProgress) { |
2873 |
|
if (!pInstruments) pInstruments = new InstrumentList; |
2874 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
2875 |
if (lstInstruments) { |
if (lstInstruments) { |
2876 |
int iInstrumentIndex = 0; |
int iInstrumentIndex = 0; |
2885 |
progress_t subprogress; |
progress_t subprogress; |
2886 |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
2887 |
|
|
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
2888 |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
2889 |
|
|
2890 |
iInstrumentIndex++; |
iInstrumentIndex++; |
2893 |
} |
} |
2894 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2895 |
} |
} |
|
else throw gig::Exception("Mandatory <lins> list chunk not found."); |
|
2896 |
} |
} |
2897 |
|
|
2898 |
|
|