2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file loader library * |
* libgig - C++ cross-platform Gigasampler format file loader library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003 by Christian Schoenebeck * |
* Copyright (C) 2003, 2004 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 * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
45 |
Product = smpl->ReadInt32(); |
Product = smpl->ReadInt32(); |
46 |
SamplePeriod = smpl->ReadInt32(); |
SamplePeriod = smpl->ReadInt32(); |
47 |
MIDIUnityNote = smpl->ReadInt32(); |
MIDIUnityNote = smpl->ReadInt32(); |
48 |
MIDIPitchFraction = smpl->ReadInt32(); |
FineTune = smpl->ReadInt32(); |
49 |
smpl->Read(&SMPTEFormat, 1, 4); |
smpl->Read(&SMPTEFormat, 1, 4); |
50 |
SMPTEOffset = smpl->ReadInt32(); |
SMPTEOffset = smpl->ReadInt32(); |
51 |
Loops = smpl->ReadInt32(); |
Loops = smpl->ReadInt32(); |
52 |
|
uint32_t manufByt = smpl->ReadInt32(); |
53 |
LoopID = smpl->ReadInt32(); |
LoopID = smpl->ReadInt32(); |
54 |
smpl->Read(&LoopType, 1, 4); |
smpl->Read(&LoopType, 1, 4); |
55 |
LoopStart = smpl->ReadInt32(); |
LoopStart = smpl->ReadInt32(); |
66 |
Compressed = (waveList->GetSubChunk(CHUNK_ID_EWAV)); |
Compressed = (waveList->GetSubChunk(CHUNK_ID_EWAV)); |
67 |
if (Compressed) { |
if (Compressed) { |
68 |
ScanCompressedSample(); |
ScanCompressedSample(); |
69 |
if (!pDecompressionBuffer) { |
} |
70 |
pDecompressionBuffer = new int8_t[INITIAL_SAMPLE_BUFFER_SIZE]; |
|
71 |
DecompressionBufferSize = INITIAL_SAMPLE_BUFFER_SIZE; |
if (BitDepth > 24) throw gig::Exception("Only samples up to 24 bit supported"); |
72 |
} |
if (Compressed && Channels == 1) throw gig::Exception("Mono compressed samples not yet supported"); |
73 |
|
if (Compressed && BitDepth == 24) throw gig::Exception("24 bit compressed samples not yet supported"); |
74 |
|
|
75 |
|
// we use a buffer for decompression and for truncating 24 bit samples to 16 bit |
76 |
|
if ((Compressed || BitDepth == 24) && !pDecompressionBuffer) { |
77 |
|
pDecompressionBuffer = new int8_t[INITIAL_SAMPLE_BUFFER_SIZE]; |
78 |
|
DecompressionBufferSize = INITIAL_SAMPLE_BUFFER_SIZE; |
79 |
} |
} |
80 |
FrameOffset = 0; // just for streaming compressed samples |
FrameOffset = 0; // just for streaming compressed samples |
81 |
|
|
82 |
|
LoopSize = LoopEnd - LoopStart; |
83 |
} |
} |
84 |
|
|
85 |
/// 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). |
319 |
} |
} |
320 |
|
|
321 |
/** |
/** |
322 |
|
* Reads \a SampleCount number of sample points from the position stored |
323 |
|
* in \a pPlaybackState into the buffer pointed by \a pBuffer and moves |
324 |
|
* the position within the sample respectively, this method honors the |
325 |
|
* looping informations of the sample (if any). The sample wave stream |
326 |
|
* will be decompressed on the fly if using a compressed sample. Use this |
327 |
|
* method if you don't want to load the sample into RAM, thus for disk |
328 |
|
* streaming. All this methods needs to know to proceed with streaming |
329 |
|
* for the next time you call this method is stored in \a pPlaybackState. |
330 |
|
* You have to allocate and initialize the playback_state_t structure by |
331 |
|
* yourself before you use it to stream a sample: |
332 |
|
* |
333 |
|
* <i> |
334 |
|
* gig::playback_state_t playbackstate; <br> |
335 |
|
* playbackstate.position = 0; <br> |
336 |
|
* playbackstate.reverse = false; <br> |
337 |
|
* playbackstate.loop_cycles_left = pSample->LoopPlayCount; <br> |
338 |
|
* </i> |
339 |
|
* |
340 |
|
* You don't have to take care of things like if there is actually a loop |
341 |
|
* defined or if the current read position is located within a loop area. |
342 |
|
* The method already handles such cases by itself. |
343 |
|
* |
344 |
|
* @param pBuffer destination buffer |
345 |
|
* @param SampleCount number of sample points to read |
346 |
|
* @param pPlaybackState will be used to store and reload the playback |
347 |
|
* state for the next ReadAndLoop() call |
348 |
|
* @returns number of successfully read sample points |
349 |
|
*/ |
350 |
|
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState) { |
351 |
|
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
352 |
|
uint8_t* pDst = (uint8_t*) pBuffer; |
353 |
|
|
354 |
|
SetPos(pPlaybackState->position); // recover position from the last time |
355 |
|
|
356 |
|
if (this->Loops && GetPos() <= this->LoopEnd) { // honor looping if there are loop points defined |
357 |
|
|
358 |
|
switch (this->LoopType) { |
359 |
|
|
360 |
|
case loop_type_bidirectional: { //TODO: not tested yet! |
361 |
|
do { |
362 |
|
// if not endless loop check if max. number of loop cycles have been passed |
363 |
|
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
364 |
|
|
365 |
|
if (!pPlaybackState->reverse) { // forward playback |
366 |
|
do { |
367 |
|
samplestoloopend = this->LoopEnd - GetPos(); |
368 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend)); |
369 |
|
samplestoread -= readsamples; |
370 |
|
totalreadsamples += readsamples; |
371 |
|
if (readsamples == samplestoloopend) { |
372 |
|
pPlaybackState->reverse = true; |
373 |
|
break; |
374 |
|
} |
375 |
|
} while (samplestoread && readsamples); |
376 |
|
} |
377 |
|
else { // backward playback |
378 |
|
|
379 |
|
// as we can only read forward from disk, we have to |
380 |
|
// determine the end position within the loop first, |
381 |
|
// read forward from that 'end' and finally after |
382 |
|
// reading, swap all sample frames so it reflects |
383 |
|
// backward playback |
384 |
|
|
385 |
|
unsigned long swapareastart = totalreadsamples; |
386 |
|
unsigned long loopoffset = GetPos() - this->LoopStart; |
387 |
|
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
388 |
|
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
389 |
|
|
390 |
|
SetPos(reverseplaybackend); |
391 |
|
|
392 |
|
// read samples for backward playback |
393 |
|
do { |
394 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop); |
395 |
|
samplestoreadinloop -= readsamples; |
396 |
|
samplestoread -= readsamples; |
397 |
|
totalreadsamples += readsamples; |
398 |
|
} while (samplestoreadinloop && readsamples); |
399 |
|
|
400 |
|
SetPos(reverseplaybackend); // pretend we really read backwards |
401 |
|
|
402 |
|
if (reverseplaybackend == this->LoopStart) { |
403 |
|
pPlaybackState->loop_cycles_left--; |
404 |
|
pPlaybackState->reverse = false; |
405 |
|
} |
406 |
|
|
407 |
|
// reverse the sample frames for backward playback |
408 |
|
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
409 |
|
} |
410 |
|
} while (samplestoread && readsamples); |
411 |
|
break; |
412 |
|
} |
413 |
|
|
414 |
|
case loop_type_backward: { // TODO: not tested yet! |
415 |
|
// forward playback (not entered the loop yet) |
416 |
|
if (!pPlaybackState->reverse) do { |
417 |
|
samplestoloopend = this->LoopEnd - GetPos(); |
418 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend)); |
419 |
|
samplestoread -= readsamples; |
420 |
|
totalreadsamples += readsamples; |
421 |
|
if (readsamples == samplestoloopend) { |
422 |
|
pPlaybackState->reverse = true; |
423 |
|
break; |
424 |
|
} |
425 |
|
} while (samplestoread && readsamples); |
426 |
|
|
427 |
|
if (!samplestoread) break; |
428 |
|
|
429 |
|
// as we can only read forward from disk, we have to |
430 |
|
// determine the end position within the loop first, |
431 |
|
// read forward from that 'end' and finally after |
432 |
|
// reading, swap all sample frames so it reflects |
433 |
|
// backward playback |
434 |
|
|
435 |
|
unsigned long swapareastart = totalreadsamples; |
436 |
|
unsigned long loopoffset = GetPos() - this->LoopStart; |
437 |
|
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * LoopSize - loopoffset) |
438 |
|
: samplestoread; |
439 |
|
unsigned long reverseplaybackend = this->LoopStart + Abs((loopoffset - samplestoreadinloop) % this->LoopSize); |
440 |
|
|
441 |
|
SetPos(reverseplaybackend); |
442 |
|
|
443 |
|
// read samples for backward playback |
444 |
|
do { |
445 |
|
// if not endless loop check if max. number of loop cycles have been passed |
446 |
|
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
447 |
|
samplestoloopend = this->LoopEnd - GetPos(); |
448 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend)); |
449 |
|
samplestoreadinloop -= readsamples; |
450 |
|
samplestoread -= readsamples; |
451 |
|
totalreadsamples += readsamples; |
452 |
|
if (readsamples == samplestoloopend) { |
453 |
|
pPlaybackState->loop_cycles_left--; |
454 |
|
SetPos(this->LoopStart); |
455 |
|
} |
456 |
|
} while (samplestoreadinloop && readsamples); |
457 |
|
|
458 |
|
SetPos(reverseplaybackend); // pretend we really read backwards |
459 |
|
|
460 |
|
// reverse the sample frames for backward playback |
461 |
|
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
462 |
|
break; |
463 |
|
} |
464 |
|
|
465 |
|
default: case loop_type_normal: { |
466 |
|
do { |
467 |
|
// if not endless loop check if max. number of loop cycles have been passed |
468 |
|
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
469 |
|
samplestoloopend = this->LoopEnd - GetPos(); |
470 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend)); |
471 |
|
samplestoread -= readsamples; |
472 |
|
totalreadsamples += readsamples; |
473 |
|
if (readsamples == samplestoloopend) { |
474 |
|
pPlaybackState->loop_cycles_left--; |
475 |
|
SetPos(this->LoopStart); |
476 |
|
} |
477 |
|
} while (samplestoread && readsamples); |
478 |
|
break; |
479 |
|
} |
480 |
|
} |
481 |
|
} |
482 |
|
|
483 |
|
// read on without looping |
484 |
|
if (samplestoread) do { |
485 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoread); |
486 |
|
samplestoread -= readsamples; |
487 |
|
totalreadsamples += readsamples; |
488 |
|
} while (readsamples && samplestoread); |
489 |
|
|
490 |
|
// store current position |
491 |
|
pPlaybackState->position = GetPos(); |
492 |
|
|
493 |
|
return totalreadsamples; |
494 |
|
} |
495 |
|
|
496 |
|
/** |
497 |
* Reads \a SampleCount number of sample points from the current |
* Reads \a SampleCount number of sample points from the current |
498 |
* position into the buffer pointed by \a pBuffer and increments the |
* position into the buffer pointed by \a pBuffer and increments the |
499 |
* position within the sample. The sample wave stream will be |
* position within the sample. The sample wave stream will be |
507 |
* @see SetPos() |
* @see SetPos() |
508 |
*/ |
*/ |
509 |
unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) { |
unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) { |
510 |
if (!Compressed) return pCkData->Read(pBuffer, SampleCount, FrameSize); |
if (SampleCount == 0) return 0; |
511 |
|
if (!Compressed) { |
512 |
|
if (BitDepth == 24) { |
513 |
|
// 24 bit sample. For now just truncate to 16 bit. |
514 |
|
int8_t* pSrc = (int8_t*)this->pDecompressionBuffer; |
515 |
|
int8_t* pDst = (int8_t*)pBuffer; |
516 |
|
unsigned long n = pCkData->Read(pSrc, SampleCount, FrameSize); |
517 |
|
for (int i = SampleCount * (FrameSize / 3) ; i > 0 ; i--) { |
518 |
|
pSrc++; |
519 |
|
*pDst++ = *pSrc++; |
520 |
|
*pDst++ = *pSrc++; |
521 |
|
} |
522 |
|
return SampleCount; |
523 |
|
} else { |
524 |
|
return pCkData->Read(pBuffer, SampleCount, FrameSize); //FIXME: channel inversion due to endian correction? |
525 |
|
} |
526 |
|
} |
527 |
else { //FIXME: no support for mono compressed samples yet, are there any? |
else { //FIXME: no support for mono compressed samples yet, are there any? |
528 |
|
if (this->SamplePos >= this->SamplesTotal) return 0; |
529 |
//TODO: efficiency: we simply assume here that all frames are compressed, maybe we should test for an average compression rate |
//TODO: efficiency: we simply assume here that all frames are compressed, maybe we should test for an average compression rate |
530 |
// best case needed buffer size (all frames compressed) |
// best case needed buffer size (all frames compressed) |
531 |
unsigned long assumedsize = (SampleCount << 1) + // *2 (16 Bit, stereo, but assume all frames compressed) |
unsigned long assumedsize = (SampleCount << 1) + // *2 (16 Bit, stereo, but assume all frames compressed) |
554 |
// reload from disk to local buffer if needed |
// reload from disk to local buffer if needed |
555 |
if (remainingbytes < 8194) { |
if (remainingbytes < 8194) { |
556 |
if (pCkData->GetState() != RIFF::stream_ready) { |
if (pCkData->GetState() != RIFF::stream_ready) { |
557 |
this->SamplePos += (SampleCount - remainingsamples); |
this->SamplePos = this->SamplesTotal; |
|
//if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
|
558 |
return (SampleCount - remainingsamples); |
return (SampleCount - remainingsamples); |
559 |
} |
} |
560 |
assumedsize = remainingsamples; |
assumedsize = remainingsamples; |
674 |
} |
} |
675 |
} |
} |
676 |
this->SamplePos += (SampleCount - remainingsamples); |
this->SamplePos += (SampleCount - remainingsamples); |
677 |
//if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
678 |
return (SampleCount - remainingsamples); |
return (SampleCount - remainingsamples); |
679 |
} |
} |
680 |
} |
} |
691 |
// *************** DimensionRegion *************** |
// *************** DimensionRegion *************** |
692 |
// * |
// * |
693 |
|
|
694 |
|
uint DimensionRegion::Instances = 0; |
695 |
|
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
696 |
|
|
697 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
698 |
|
Instances++; |
699 |
|
|
700 |
memcpy(&Crossfade, &SamplerOptions, 4); |
memcpy(&Crossfade, &SamplerOptions, 4); |
701 |
|
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
702 |
|
|
703 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
704 |
_3ewa->ReadInt32(); // unknown, allways 0x0000008C ? |
_3ewa->ReadInt32(); // unknown, always 0x0000008C ? |
705 |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
706 |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
707 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
717 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
718 |
EG1Sustain = _3ewa->ReadUint16(); |
EG1Sustain = _3ewa->ReadUint16(); |
719 |
EG1Release = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
EG1Release = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
720 |
EG1Controller = static_cast<eg1_ctrl_t>(_3ewa->ReadUint8()); |
EG1Controller = DecodeLeverageController(static_cast<_lev_ctrl_t>(_3ewa->ReadUint8())); |
721 |
uint8_t eg1ctrloptions = _3ewa->ReadUint8(); |
uint8_t eg1ctrloptions = _3ewa->ReadUint8(); |
722 |
EG1ControllerInvert = eg1ctrloptions & 0x01; |
EG1ControllerInvert = eg1ctrloptions & 0x01; |
723 |
EG1ControllerAttackInfluence = GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(eg1ctrloptions); |
EG1ControllerAttackInfluence = GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(eg1ctrloptions); |
724 |
EG1ControllerDecayInfluence = GIG_EG_CTR_DECAY_INFLUENCE_EXTRACT(eg1ctrloptions); |
EG1ControllerDecayInfluence = GIG_EG_CTR_DECAY_INFLUENCE_EXTRACT(eg1ctrloptions); |
725 |
EG1ControllerReleaseInfluence = GIG_EG_CTR_RELEASE_INFLUENCE_EXTRACT(eg1ctrloptions); |
EG1ControllerReleaseInfluence = GIG_EG_CTR_RELEASE_INFLUENCE_EXTRACT(eg1ctrloptions); |
726 |
EG2Controller = static_cast<eg2_ctrl_t>(_3ewa->ReadUint8()); |
EG2Controller = DecodeLeverageController(static_cast<_lev_ctrl_t>(_3ewa->ReadUint8())); |
727 |
uint8_t eg2ctrloptions = _3ewa->ReadUint8(); |
uint8_t eg2ctrloptions = _3ewa->ReadUint8(); |
728 |
EG2ControllerInvert = eg2ctrloptions & 0x01; |
EG2ControllerInvert = eg2ctrloptions & 0x01; |
729 |
EG2ControllerAttackInfluence = GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(eg2ctrloptions); |
EG2ControllerAttackInfluence = GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(eg2ctrloptions); |
785 |
ReleaseVelocityResponseDepth = 0; |
ReleaseVelocityResponseDepth = 0; |
786 |
} |
} |
787 |
VelocityResponseCurveScaling = _3ewa->ReadUint8(); |
VelocityResponseCurveScaling = _3ewa->ReadUint8(); |
788 |
AttenuationControlTreshold = _3ewa->ReadInt8(); |
AttenuationControllerThreshold = _3ewa->ReadInt8(); |
789 |
_3ewa->ReadInt32(); // unknown |
_3ewa->ReadInt32(); // unknown |
790 |
SampleStartOffset = (uint16_t) _3ewa->ReadInt16(); |
SampleStartOffset = (uint16_t) _3ewa->ReadInt16(); |
791 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
795 |
else if (pitchTrackDimensionBypass & 0x20) DimensionBypass = dim_bypass_ctrl_95; |
else if (pitchTrackDimensionBypass & 0x20) DimensionBypass = dim_bypass_ctrl_95; |
796 |
else DimensionBypass = dim_bypass_ctrl_none; |
else DimensionBypass = dim_bypass_ctrl_none; |
797 |
uint8_t pan = _3ewa->ReadUint8(); |
uint8_t pan = _3ewa->ReadUint8(); |
798 |
Pan = (pan < 64) ? pan : (-1) * (int8_t)pan - 63; |
Pan = (pan < 64) ? pan : -((int)pan - 63); // signed 7 bit -> signed 8 bit |
799 |
SelfMask = _3ewa->ReadInt8() & 0x01; |
SelfMask = _3ewa->ReadInt8() & 0x01; |
800 |
_3ewa->ReadInt8(); // unknown |
_3ewa->ReadInt8(); // unknown |
801 |
uint8_t lfo3ctrl = _3ewa->ReadUint8(); |
uint8_t lfo3ctrl = _3ewa->ReadUint8(); |
802 |
LFO3Controller = static_cast<lfo3_ctrl_t>(lfo3ctrl & 0x07); // lower 3 bits |
LFO3Controller = static_cast<lfo3_ctrl_t>(lfo3ctrl & 0x07); // lower 3 bits |
803 |
LFO3Sync = lfo3ctrl & 0x20; // bit 5 |
LFO3Sync = lfo3ctrl & 0x20; // bit 5 |
804 |
InvertAttenuationControl = lfo3ctrl & 0x80; // bit 7 |
InvertAttenuationController = lfo3ctrl & 0x80; // bit 7 |
805 |
if (VCFType == vcf_type_lowpass) { |
AttenuationController = DecodeLeverageController(static_cast<_lev_ctrl_t>(_3ewa->ReadUint8())); |
|
if (lfo3ctrl & 0x40) // bit 6 |
|
|
VCFType = vcf_type_lowpassturbo; |
|
|
} |
|
|
AttenuationControl = static_cast<attenuation_ctrl_t>(_3ewa->ReadUint8()); |
|
806 |
uint8_t lfo2ctrl = _3ewa->ReadUint8(); |
uint8_t lfo2ctrl = _3ewa->ReadUint8(); |
807 |
LFO2Controller = static_cast<lfo2_ctrl_t>(lfo2ctrl & 0x07); // lower 3 bits |
LFO2Controller = static_cast<lfo2_ctrl_t>(lfo2ctrl & 0x07); // lower 3 bits |
808 |
LFO2FlipPhase = lfo2ctrl & 0x80; // bit 7 |
LFO2FlipPhase = lfo2ctrl & 0x80; // bit 7 |
846 |
VCFVelocityDynamicRange = vcfvelocity % 5; |
VCFVelocityDynamicRange = vcfvelocity % 5; |
847 |
VCFVelocityCurve = static_cast<curve_type_t>(vcfvelocity / 5); |
VCFVelocityCurve = static_cast<curve_type_t>(vcfvelocity / 5); |
848 |
VCFType = static_cast<vcf_type_t>(_3ewa->ReadUint8()); |
VCFType = static_cast<vcf_type_t>(_3ewa->ReadUint8()); |
849 |
|
if (VCFType == vcf_type_lowpass) { |
850 |
|
if (lfo3ctrl & 0x40) // bit 6 |
851 |
|
VCFType = vcf_type_lowpassturbo; |
852 |
|
} |
853 |
|
|
854 |
|
// get the corresponding velocity->volume table from the table map or create & calculate that table if it doesn't exist yet |
855 |
|
uint32_t tableKey = (VelocityResponseCurve<<16) | (VelocityResponseDepth<<8) | VelocityResponseCurveScaling; |
856 |
|
if (pVelocityTables->count(tableKey)) { // if key exists |
857 |
|
pVelocityAttenuationTable = (*pVelocityTables)[tableKey]; |
858 |
|
} |
859 |
|
else { |
860 |
|
pVelocityAttenuationTable = |
861 |
|
CreateVelocityTable(VelocityResponseCurve, |
862 |
|
VelocityResponseDepth, |
863 |
|
VelocityResponseCurveScaling); |
864 |
|
(*pVelocityTables)[tableKey] = pVelocityAttenuationTable; // put the new table into the tables map |
865 |
|
} |
866 |
|
} |
867 |
|
|
868 |
|
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
869 |
|
leverage_ctrl_t decodedcontroller; |
870 |
|
switch (EncodedController) { |
871 |
|
// special controller |
872 |
|
case _lev_ctrl_none: |
873 |
|
decodedcontroller.type = leverage_ctrl_t::type_none; |
874 |
|
decodedcontroller.controller_number = 0; |
875 |
|
break; |
876 |
|
case _lev_ctrl_velocity: |
877 |
|
decodedcontroller.type = leverage_ctrl_t::type_velocity; |
878 |
|
decodedcontroller.controller_number = 0; |
879 |
|
break; |
880 |
|
case _lev_ctrl_channelaftertouch: |
881 |
|
decodedcontroller.type = leverage_ctrl_t::type_channelaftertouch; |
882 |
|
decodedcontroller.controller_number = 0; |
883 |
|
break; |
884 |
|
|
885 |
|
// ordinary MIDI control change controller |
886 |
|
case _lev_ctrl_modwheel: |
887 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
888 |
|
decodedcontroller.controller_number = 1; |
889 |
|
break; |
890 |
|
case _lev_ctrl_breath: |
891 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
892 |
|
decodedcontroller.controller_number = 2; |
893 |
|
break; |
894 |
|
case _lev_ctrl_foot: |
895 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
896 |
|
decodedcontroller.controller_number = 4; |
897 |
|
break; |
898 |
|
case _lev_ctrl_effect1: |
899 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
900 |
|
decodedcontroller.controller_number = 12; |
901 |
|
break; |
902 |
|
case _lev_ctrl_effect2: |
903 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
904 |
|
decodedcontroller.controller_number = 13; |
905 |
|
break; |
906 |
|
case _lev_ctrl_genpurpose1: |
907 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
908 |
|
decodedcontroller.controller_number = 16; |
909 |
|
break; |
910 |
|
case _lev_ctrl_genpurpose2: |
911 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
912 |
|
decodedcontroller.controller_number = 17; |
913 |
|
break; |
914 |
|
case _lev_ctrl_genpurpose3: |
915 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
916 |
|
decodedcontroller.controller_number = 18; |
917 |
|
break; |
918 |
|
case _lev_ctrl_genpurpose4: |
919 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
920 |
|
decodedcontroller.controller_number = 19; |
921 |
|
break; |
922 |
|
case _lev_ctrl_portamentotime: |
923 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
924 |
|
decodedcontroller.controller_number = 5; |
925 |
|
break; |
926 |
|
case _lev_ctrl_sustainpedal: |
927 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
928 |
|
decodedcontroller.controller_number = 64; |
929 |
|
break; |
930 |
|
case _lev_ctrl_portamento: |
931 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
932 |
|
decodedcontroller.controller_number = 65; |
933 |
|
break; |
934 |
|
case _lev_ctrl_sostenutopedal: |
935 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
936 |
|
decodedcontroller.controller_number = 66; |
937 |
|
break; |
938 |
|
case _lev_ctrl_softpedal: |
939 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
940 |
|
decodedcontroller.controller_number = 67; |
941 |
|
break; |
942 |
|
case _lev_ctrl_genpurpose5: |
943 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
944 |
|
decodedcontroller.controller_number = 80; |
945 |
|
break; |
946 |
|
case _lev_ctrl_genpurpose6: |
947 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
948 |
|
decodedcontroller.controller_number = 81; |
949 |
|
break; |
950 |
|
case _lev_ctrl_genpurpose7: |
951 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
952 |
|
decodedcontroller.controller_number = 82; |
953 |
|
break; |
954 |
|
case _lev_ctrl_genpurpose8: |
955 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
956 |
|
decodedcontroller.controller_number = 83; |
957 |
|
break; |
958 |
|
case _lev_ctrl_effect1depth: |
959 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
960 |
|
decodedcontroller.controller_number = 91; |
961 |
|
break; |
962 |
|
case _lev_ctrl_effect2depth: |
963 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
964 |
|
decodedcontroller.controller_number = 92; |
965 |
|
break; |
966 |
|
case _lev_ctrl_effect3depth: |
967 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
968 |
|
decodedcontroller.controller_number = 93; |
969 |
|
break; |
970 |
|
case _lev_ctrl_effect4depth: |
971 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
972 |
|
decodedcontroller.controller_number = 94; |
973 |
|
break; |
974 |
|
case _lev_ctrl_effect5depth: |
975 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
976 |
|
decodedcontroller.controller_number = 95; |
977 |
|
break; |
978 |
|
|
979 |
|
// unknown controller type |
980 |
|
default: |
981 |
|
throw gig::Exception("Unknown leverage controller type."); |
982 |
|
} |
983 |
|
return decodedcontroller; |
984 |
} |
} |
985 |
|
|
986 |
|
DimensionRegion::~DimensionRegion() { |
987 |
|
Instances--; |
988 |
|
if (!Instances) { |
989 |
|
// delete the velocity->volume tables |
990 |
|
VelocityTableMap::iterator iter; |
991 |
|
for (iter = pVelocityTables->begin(); iter != pVelocityTables->end(); iter++) { |
992 |
|
double* pTable = iter->second; |
993 |
|
if (pTable) delete[] pTable; |
994 |
|
} |
995 |
|
pVelocityTables->clear(); |
996 |
|
delete pVelocityTables; |
997 |
|
pVelocityTables = NULL; |
998 |
|
} |
999 |
|
} |
1000 |
|
|
1001 |
|
/** |
1002 |
|
* Returns the correct amplitude factor for the given \a MIDIKeyVelocity. |
1003 |
|
* All involved parameters (VelocityResponseCurve, VelocityResponseDepth |
1004 |
|
* and VelocityResponseCurveScaling) involved are taken into account to |
1005 |
|
* calculate the amplitude factor. Use this method when a key was |
1006 |
|
* triggered to get the volume with which the sample should be played |
1007 |
|
* back. |
1008 |
|
* |
1009 |
|
* @param MIDIKeyVelocity MIDI velocity value of the triggered key (between 0 and 127) |
1010 |
|
* @returns amplitude factor (between 0.0 and 1.0) |
1011 |
|
*/ |
1012 |
|
double DimensionRegion::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) { |
1013 |
|
return pVelocityAttenuationTable[MIDIKeyVelocity]; |
1014 |
|
} |
1015 |
|
|
1016 |
|
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
1017 |
|
|
1018 |
|
// line-segment approximations of the 15 velocity curves |
1019 |
|
|
1020 |
|
// linear |
1021 |
|
const int lin0[] = { 1, 1, 127, 127 }; |
1022 |
|
const int lin1[] = { 1, 21, 127, 127 }; |
1023 |
|
const int lin2[] = { 1, 45, 127, 127 }; |
1024 |
|
const int lin3[] = { 1, 74, 127, 127 }; |
1025 |
|
const int lin4[] = { 1, 127, 127, 127 }; |
1026 |
|
|
1027 |
|
// non-linear |
1028 |
|
const int non0[] = { 1, 4, 24, 5, 57, 17, 92, 57, 122, 127, 127, 127 }; |
1029 |
|
const int non1[] = { 1, 4, 46, 9, 93, 56, 118, 106, 123, 127, |
1030 |
|
127, 127 }; |
1031 |
|
const int non2[] = { 1, 4, 46, 9, 57, 20, 102, 107, 107, 127, |
1032 |
|
127, 127 }; |
1033 |
|
const int non3[] = { 1, 15, 10, 19, 67, 73, 80, 80, 90, 98, 98, 127, |
1034 |
|
127, 127 }; |
1035 |
|
const int non4[] = { 1, 25, 33, 57, 82, 81, 92, 127, 127, 127 }; |
1036 |
|
|
1037 |
|
// special |
1038 |
|
const int spe0[] = { 1, 2, 76, 10, 90, 15, 95, 20, 99, 28, 103, 44, |
1039 |
|
113, 127, 127, 127 }; |
1040 |
|
const int spe1[] = { 1, 2, 27, 5, 67, 18, 89, 29, 95, 35, 107, 67, |
1041 |
|
118, 127, 127, 127 }; |
1042 |
|
const int spe2[] = { 1, 1, 33, 1, 53, 5, 61, 13, 69, 32, 79, 74, |
1043 |
|
85, 90, 91, 127, 127, 127 }; |
1044 |
|
const int spe3[] = { 1, 32, 28, 35, 66, 48, 89, 59, 95, 65, 99, 73, |
1045 |
|
117, 127, 127, 127 }; |
1046 |
|
const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127, |
1047 |
|
127, 127 }; |
1048 |
|
|
1049 |
|
const int* const curves[] = { non0, non1, non2, non3, non4, |
1050 |
|
lin0, lin1, lin2, lin3, lin4, |
1051 |
|
spe0, spe1, spe2, spe3, spe4 }; |
1052 |
|
|
1053 |
|
double* const table = new double[128]; |
1054 |
|
|
1055 |
|
const int* curve = curves[curveType * 5 + depth]; |
1056 |
|
const int s = scaling == 0 ? 20 : scaling; // 0 or 20 means no scaling |
1057 |
|
|
1058 |
|
table[0] = 0; |
1059 |
|
for (int x = 1 ; x < 128 ; x++) { |
1060 |
|
|
1061 |
|
if (x > curve[2]) curve += 2; |
1062 |
|
double y = curve[1] + (x - curve[0]) * |
1063 |
|
(double(curve[3] - curve[1]) / (curve[2] - curve[0])); |
1064 |
|
y = y / 127; |
1065 |
|
|
1066 |
|
// Scale up for s > 20, down for s < 20. When |
1067 |
|
// down-scaling, the curve still ends at 1.0. |
1068 |
|
if (s < 20 && y >= 0.5) |
1069 |
|
y = y / ((2 - 40.0 / s) * y + 40.0 / s - 1); |
1070 |
|
else |
1071 |
|
y = y * (s / 20.0); |
1072 |
|
if (y > 1) y = 1; |
1073 |
|
|
1074 |
|
table[x] = y; |
1075 |
|
} |
1076 |
|
return table; |
1077 |
|
} |
1078 |
|
|
1079 |
|
|
1080 |
// *************** Region *************** |
// *************** Region *************** |
1083 |
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) { |
1084 |
// Initialization |
// Initialization |
1085 |
Dimensions = 0; |
Dimensions = 0; |
1086 |
for (int i = 0; i < 32; i++) { |
for (int i = 0; i < 256; i++) { |
1087 |
pDimensionRegions[i] = NULL; |
pDimensionRegions[i] = NULL; |
1088 |
} |
} |
1089 |
|
Layers = 1; |
1090 |
|
File* file = (File*) GetParent()->GetParent(); |
1091 |
|
int dimensionBits = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
1092 |
|
|
1093 |
// Actual Loading |
// Actual Loading |
1094 |
|
|
1097 |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
1098 |
if (_3lnk) { |
if (_3lnk) { |
1099 |
DimensionRegions = _3lnk->ReadUint32(); |
DimensionRegions = _3lnk->ReadUint32(); |
1100 |
for (int i = 0; i < 5; i++) { |
for (int i = 0; i < dimensionBits; i++) { |
1101 |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
1102 |
uint8_t bits = _3lnk->ReadUint8(); |
uint8_t bits = _3lnk->ReadUint8(); |
1103 |
if (dimension == dimension_none) { // inactive dimension |
if (dimension == dimension_none) { // inactive dimension |
1113 |
pDimensionDefinitions[i].bits = bits; |
pDimensionDefinitions[i].bits = bits; |
1114 |
pDimensionDefinitions[i].zones = 0x01 << bits; // = pow(2,bits) |
pDimensionDefinitions[i].zones = 0x01 << bits; // = pow(2,bits) |
1115 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
1116 |
dimension == dimension_samplechannel) ? split_type_bit |
dimension == dimension_samplechannel || |
1117 |
: split_type_normal; |
dimension == dimension_releasetrigger) ? split_type_bit |
1118 |
|
: split_type_normal; |
1119 |
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
1120 |
pDimensionDefinitions[i].zone_size = |
pDimensionDefinitions[i].zone_size = |
1121 |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones |
1122 |
: 0; |
: 0; |
1123 |
Dimensions++; |
Dimensions++; |
1124 |
|
|
1125 |
|
// if this is a layer dimension, remember the amount of layers |
1126 |
|
if (dimension == dimension_layer) Layers = pDimensionDefinitions[i].zones; |
1127 |
} |
} |
1128 |
_3lnk->SetPos(6, RIFF::stream_curpos); // jump forward to next dimension definition |
_3lnk->SetPos(6, RIFF::stream_curpos); // jump forward to next dimension definition |
1129 |
} |
} |
1140 |
else { // custom defined ranges |
else { // custom defined ranges |
1141 |
pDimDef->split_type = split_type_customvelocity; |
pDimDef->split_type = split_type_customvelocity; |
1142 |
pDimDef->ranges = new range_t[pDimDef->zones]; |
pDimDef->ranges = new range_t[pDimDef->zones]; |
1143 |
unsigned int bits[5] = {0,0,0,0,0}; |
uint8_t bits[8] = { 0 }; |
1144 |
int previousUpperLimit = -1; |
int previousUpperLimit = -1; |
1145 |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
1146 |
bits[i] = velocityZone; |
bits[i] = velocityZone; |
1147 |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits[4],bits[3],bits[2],bits[1],bits[0]); |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits); |
1148 |
|
|
1149 |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
1150 |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
1158 |
} |
} |
1159 |
} |
} |
1160 |
|
|
1161 |
|
// jump to start of the wave pool indices (if not already there) |
1162 |
|
File* file = (File*) GetParent()->GetParent(); |
1163 |
|
if (file->pVersion && file->pVersion->major == 3) |
1164 |
|
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
1165 |
|
else |
1166 |
|
_3lnk->SetPos(44); |
1167 |
|
|
1168 |
// load sample references |
// load sample references |
|
_3lnk->SetPos(44); // jump to start of the wave pool indices (if not already there) |
|
1169 |
for (uint i = 0; i < DimensionRegions; i++) { |
for (uint i = 0; i < DimensionRegions; i++) { |
1170 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
1171 |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
1194 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
1195 |
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
1196 |
} |
} |
1197 |
for (int i = 0; i < 32; i++) { |
for (int i = 0; i < 256; i++) { |
1198 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
1199 |
} |
} |
1200 |
} |
} |
1212 |
* left channel, 1 for right channel or 0 for layer 0, 1 for layer 1, |
* left channel, 1 for right channel or 0 for layer 0, 1 for layer 1, |
1213 |
* etc.). |
* etc.). |
1214 |
* |
* |
1215 |
* @param Dim4Val MIDI controller value (0-127) for dimension 4 |
* @param DimValues MIDI controller values (0-127) for dimension 0 to 7 |
|
* @param Dim3Val MIDI controller value (0-127) for dimension 3 |
|
|
* @param Dim2Val MIDI controller value (0-127) for dimension 2 |
|
|
* @param Dim1Val MIDI controller value (0-127) for dimension 1 |
|
|
* @param Dim0Val MIDI controller value (0-127) for dimension 0 |
|
1216 |
* @returns adress to the DimensionRegion for the given situation |
* @returns adress to the DimensionRegion for the given situation |
1217 |
* @see pDimensionDefinitions |
* @see pDimensionDefinitions |
1218 |
* @see Dimensions |
* @see Dimensions |
1219 |
*/ |
*/ |
1220 |
DimensionRegion* Region::GetDimensionRegionByValue(uint Dim4Val, uint Dim3Val, uint Dim2Val, uint Dim1Val, uint Dim0Val) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
1221 |
unsigned int bits[5] = {Dim0Val,Dim1Val,Dim2Val,Dim3Val,Dim4Val}; |
uint8_t bits[8] = { 0 }; |
1222 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
1223 |
|
bits[i] = DimValues[i]; |
1224 |
switch (pDimensionDefinitions[i].split_type) { |
switch (pDimensionDefinitions[i].split_type) { |
1225 |
case split_type_normal: |
case split_type_normal: |
1226 |
bits[i] /= pDimensionDefinitions[i].zone_size; |
bits[i] /= pDimensionDefinitions[i].zone_size; |
1228 |
case split_type_customvelocity: |
case split_type_customvelocity: |
1229 |
bits[i] = VelocityTable[bits[i]]; |
bits[i] = VelocityTable[bits[i]]; |
1230 |
break; |
break; |
1231 |
// else the value is already the sought dimension bit number |
case split_type_bit: // the value is already the sought dimension bit number |
1232 |
|
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
1233 |
|
bits[i] = bits[i] & limiter_mask; // just make sure the value don't uses more bits than allowed |
1234 |
|
break; |
1235 |
} |
} |
1236 |
} |
} |
1237 |
return GetDimensionRegionByBit(bits[4],bits[3],bits[2],bits[1],bits[0]); |
return GetDimensionRegionByBit(bits); |
1238 |
} |
} |
1239 |
|
|
1240 |
/** |
/** |
1242 |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
1243 |
* instead of calling this method directly! |
* instead of calling this method directly! |
1244 |
* |
* |
1245 |
* @param Dim4Bit Bit number for dimension 4 |
* @param DimBits Bit numbers for dimension 0 to 7 |
|
* @param Dim3Bit Bit number for dimension 3 |
|
|
* @param Dim2Bit Bit number for dimension 2 |
|
|
* @param Dim1Bit Bit number for dimension 1 |
|
|
* @param Dim0Bit Bit number for dimension 0 |
|
1246 |
* @returns adress to the DimensionRegion for the given dimension |
* @returns adress to the DimensionRegion for the given dimension |
1247 |
* bit numbers |
* bit numbers |
1248 |
* @see GetDimensionRegionByValue() |
* @see GetDimensionRegionByValue() |
1249 |
*/ |
*/ |
1250 |
DimensionRegion* Region::GetDimensionRegionByBit(uint8_t Dim4Bit, uint8_t Dim3Bit, uint8_t Dim2Bit, uint8_t Dim1Bit, uint8_t Dim0Bit) { |
DimensionRegion* Region::GetDimensionRegionByBit(const uint8_t DimBits[8]) { |
1251 |
return *(pDimensionRegions + ((((((((Dim4Bit << pDimensionDefinitions[3].bits) | Dim3Bit) |
return pDimensionRegions[((((((DimBits[7] << pDimensionDefinitions[6].bits | DimBits[6]) |
1252 |
<< pDimensionDefinitions[2].bits) | Dim2Bit) |
<< pDimensionDefinitions[5].bits | DimBits[5]) |
1253 |
<< pDimensionDefinitions[1].bits) | Dim1Bit) |
<< pDimensionDefinitions[4].bits | DimBits[4]) |
1254 |
<< pDimensionDefinitions[0].bits) | Dim0Bit) ); |
<< pDimensionDefinitions[3].bits | DimBits[3]) |
1255 |
|
<< pDimensionDefinitions[2].bits | DimBits[2]) |
1256 |
|
<< pDimensionDefinitions[1].bits | DimBits[1]) |
1257 |
|
<< pDimensionDefinitions[0].bits | DimBits[0]]; |
1258 |
} |
} |
1259 |
|
|
1260 |
/** |
/** |
1313 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
1314 |
if (!lrgn) throw gig::Exception("Mandatory chunks in <ins > chunk not found."); |
if (!lrgn) throw gig::Exception("Mandatory chunks in <ins > chunk not found."); |
1315 |
pRegions = new Region*[Regions]; |
pRegions = new Region*[Regions]; |
1316 |
|
for (uint i = 0; i < Regions; i++) pRegions[i] = NULL; |
1317 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
1318 |
unsigned int iRegion = 0; |
unsigned int iRegion = 0; |
1319 |
while (rgn) { |
while (rgn) { |
1337 |
if (pRegions) { |
if (pRegions) { |
1338 |
if (pRegions[i]) delete (pRegions[i]); |
if (pRegions[i]) delete (pRegions[i]); |
1339 |
} |
} |
|
delete[] pRegions; |
|
1340 |
} |
} |
1341 |
|
if (pRegions) delete[] pRegions; |
1342 |
} |
} |
1343 |
|
|
1344 |
/** |
/** |
1394 |
pInstruments = NULL; |
pInstruments = NULL; |
1395 |
} |
} |
1396 |
|
|
1397 |
|
File::~File() { |
1398 |
|
// free samples |
1399 |
|
if (pSamples) { |
1400 |
|
SamplesIterator = pSamples->begin(); |
1401 |
|
while (SamplesIterator != pSamples->end() ) { |
1402 |
|
delete (*SamplesIterator); |
1403 |
|
SamplesIterator++; |
1404 |
|
} |
1405 |
|
pSamples->clear(); |
1406 |
|
|
1407 |
|
} |
1408 |
|
// free instruments |
1409 |
|
if (pInstruments) { |
1410 |
|
InstrumentsIterator = pInstruments->begin(); |
1411 |
|
while (InstrumentsIterator != pInstruments->end() ) { |
1412 |
|
delete (*InstrumentsIterator); |
1413 |
|
InstrumentsIterator++; |
1414 |
|
} |
1415 |
|
pInstruments->clear(); |
1416 |
|
} |
1417 |
|
} |
1418 |
|
|
1419 |
Sample* File::GetFirstSample() { |
Sample* File::GetFirstSample() { |
1420 |
if (!pSamples) LoadSamples(); |
if (!pSamples) LoadSamples(); |
1421 |
if (!pSamples) return NULL; |
if (!pSamples) return NULL; |
1459 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
1460 |
} |
} |
1461 |
|
|
1462 |
|
/** |
1463 |
|
* Returns the instrument with the given index. |
1464 |
|
* |
1465 |
|
* @returns sought instrument or NULL if there's no such instrument |
1466 |
|
*/ |
1467 |
|
Instrument* File::GetInstrument(uint index) { |
1468 |
|
if (!pInstruments) LoadInstruments(); |
1469 |
|
if (!pInstruments) return NULL; |
1470 |
|
InstrumentsIterator = pInstruments->begin(); |
1471 |
|
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
1472 |
|
if (i == index) return *InstrumentsIterator; |
1473 |
|
InstrumentsIterator++; |
1474 |
|
} |
1475 |
|
return NULL; |
1476 |
|
} |
1477 |
|
|
1478 |
void File::LoadInstruments() { |
void File::LoadInstruments() { |
1479 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
1480 |
if (lstInstruments) { |
if (lstInstruments) { |