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 |
|
|
348 |
} |
} |
349 |
FrameOffset = 0; // just for streaming compressed samples |
FrameOffset = 0; // just for streaming compressed samples |
350 |
|
|
351 |
LoopSize = LoopEnd - LoopStart; |
LoopSize = LoopEnd - LoopStart + 1; |
352 |
} |
} |
353 |
|
|
354 |
/** |
/** |
722 |
* @param SampleCount number of sample points to read |
* @param SampleCount number of sample points to read |
723 |
* @param pPlaybackState will be used to store and reload the playback |
* @param pPlaybackState will be used to store and reload the playback |
724 |
* state for the next ReadAndLoop() call |
* state for the next ReadAndLoop() call |
725 |
|
* @param pDimRgn dimension region with looping information |
726 |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
727 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
728 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
729 |
*/ |
*/ |
730 |
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, |
731 |
|
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
732 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
733 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
734 |
|
|
735 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
736 |
|
|
737 |
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 |
738 |
|
|
739 |
switch (this->LoopType) { |
const DLS::sample_loop_t& loop = pDimRgn->pSampleLoops[0]; |
740 |
|
const uint32_t loopEnd = loop.LoopStart + loop.LoopLength; |
741 |
|
|
742 |
case loop_type_bidirectional: { //TODO: not tested yet! |
if (GetPos() <= loopEnd) { |
743 |
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 |
|
744 |
|
|
745 |
// as we can only read forward from disk, we have to |
case loop_type_bidirectional: { //TODO: not tested yet! |
746 |
// determine the end position within the loop first, |
do { |
747 |
// read forward from that 'end' and finally after |
// if not endless loop check if max. number of loop cycles have been passed |
748 |
// reading, swap all sample frames so it reflects |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
749 |
// backward playback |
|
750 |
|
if (!pPlaybackState->reverse) { // forward playback |
751 |
unsigned long swapareastart = totalreadsamples; |
do { |
752 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
samplestoloopend = loopEnd - GetPos(); |
753 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
754 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
samplestoread -= readsamples; |
755 |
|
totalreadsamples += readsamples; |
756 |
SetPos(reverseplaybackend); |
if (readsamples == samplestoloopend) { |
757 |
|
pPlaybackState->reverse = true; |
758 |
// read samples for backward playback |
break; |
759 |
do { |
} |
760 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
} while (samplestoread && readsamples); |
761 |
samplestoreadinloop -= readsamples; |
} |
762 |
samplestoread -= readsamples; |
else { // backward playback |
|
totalreadsamples += readsamples; |
|
|
} while (samplestoreadinloop && readsamples); |
|
763 |
|
|
764 |
SetPos(reverseplaybackend); // pretend we really read backwards |
// as we can only read forward from disk, we have to |
765 |
|
// determine the end position within the loop first, |
766 |
|
// read forward from that 'end' and finally after |
767 |
|
// reading, swap all sample frames so it reflects |
768 |
|
// backward playback |
769 |
|
|
770 |
|
unsigned long swapareastart = totalreadsamples; |
771 |
|
unsigned long loopoffset = GetPos() - loop.LoopStart; |
772 |
|
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
773 |
|
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
774 |
|
|
775 |
|
SetPos(reverseplaybackend); |
776 |
|
|
777 |
|
// read samples for backward playback |
778 |
|
do { |
779 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
780 |
|
samplestoreadinloop -= readsamples; |
781 |
|
samplestoread -= readsamples; |
782 |
|
totalreadsamples += readsamples; |
783 |
|
} while (samplestoreadinloop && readsamples); |
784 |
|
|
785 |
|
SetPos(reverseplaybackend); // pretend we really read backwards |
786 |
|
|
787 |
|
if (reverseplaybackend == loop.LoopStart) { |
788 |
|
pPlaybackState->loop_cycles_left--; |
789 |
|
pPlaybackState->reverse = false; |
790 |
|
} |
791 |
|
|
792 |
if (reverseplaybackend == this->LoopStart) { |
// reverse the sample frames for backward playback |
793 |
pPlaybackState->loop_cycles_left--; |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
|
pPlaybackState->reverse = false; |
|
794 |
} |
} |
795 |
|
} while (samplestoread && readsamples); |
796 |
|
break; |
797 |
|
} |
798 |
|
|
799 |
// reverse the sample frames for backward playback |
case loop_type_backward: { // TODO: not tested yet! |
800 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
// forward playback (not entered the loop yet) |
801 |
} |
if (!pPlaybackState->reverse) do { |
802 |
} while (samplestoread && readsamples); |
samplestoloopend = loopEnd - GetPos(); |
803 |
break; |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
804 |
} |
samplestoread -= readsamples; |
805 |
|
totalreadsamples += readsamples; |
806 |
case loop_type_backward: { // TODO: not tested yet! |
if (readsamples == samplestoloopend) { |
807 |
// forward playback (not entered the loop yet) |
pPlaybackState->reverse = true; |
808 |
if (!pPlaybackState->reverse) do { |
break; |
809 |
samplestoloopend = this->LoopEnd - GetPos(); |
} |
810 |
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); |
|
811 |
|
|
812 |
if (!samplestoread) break; |
if (!samplestoread) break; |
813 |
|
|
814 |
// as we can only read forward from disk, we have to |
// as we can only read forward from disk, we have to |
815 |
// determine the end position within the loop first, |
// determine the end position within the loop first, |
816 |
// read forward from that 'end' and finally after |
// read forward from that 'end' and finally after |
817 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
818 |
// backward playback |
// backward playback |
819 |
|
|
820 |
unsigned long swapareastart = totalreadsamples; |
unsigned long swapareastart = totalreadsamples; |
821 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
822 |
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) |
823 |
: samplestoread; |
: samplestoread; |
824 |
unsigned long reverseplaybackend = this->LoopStart + Abs((loopoffset - samplestoreadinloop) % this->LoopSize); |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
825 |
|
|
826 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
827 |
|
|
828 |
// read samples for backward playback |
// read samples for backward playback |
829 |
do { |
do { |
830 |
// 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 |
831 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
832 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
833 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
834 |
samplestoreadinloop -= readsamples; |
samplestoreadinloop -= readsamples; |
835 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
836 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
837 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
838 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
839 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
840 |
} |
} |
841 |
} while (samplestoreadinloop && readsamples); |
} while (samplestoreadinloop && readsamples); |
842 |
|
|
843 |
SetPos(reverseplaybackend); // pretend we really read backwards |
SetPos(reverseplaybackend); // pretend we really read backwards |
844 |
|
|
845 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
846 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
847 |
break; |
break; |
848 |
} |
} |
849 |
|
|
850 |
default: case loop_type_normal: { |
default: case loop_type_normal: { |
851 |
do { |
do { |
852 |
// 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 |
853 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
854 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
855 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
856 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
857 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
858 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
859 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
860 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
861 |
} |
} |
862 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
863 |
break; |
break; |
864 |
|
} |
865 |
} |
} |
866 |
} |
} |
867 |
} |
} |
1170 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1171 |
Instances++; |
Instances++; |
1172 |
|
|
1173 |
|
pSample = NULL; |
1174 |
|
|
1175 |
memcpy(&Crossfade, &SamplerOptions, 4); |
memcpy(&Crossfade, &SamplerOptions, 4); |
1176 |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
1177 |
|
|
1436 |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
1437 |
|
|
1438 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1439 |
|
VelocityTable = 0; |
1440 |
} |
} |
1441 |
|
|
1442 |
/** |
/** |
1956 |
delete pVelocityTables; |
delete pVelocityTables; |
1957 |
pVelocityTables = NULL; |
pVelocityTables = NULL; |
1958 |
} |
} |
1959 |
|
if (VelocityTable) delete[] VelocityTable; |
1960 |
} |
} |
1961 |
|
|
1962 |
/** |
/** |
2081 |
pDimensionDefinitions[i].bits = 0; |
pDimensionDefinitions[i].bits = 0; |
2082 |
pDimensionDefinitions[i].zones = 0; |
pDimensionDefinitions[i].zones = 0; |
2083 |
pDimensionDefinitions[i].split_type = split_type_bit; |
pDimensionDefinitions[i].split_type = split_type_bit; |
|
pDimensionDefinitions[i].ranges = NULL; |
|
2084 |
pDimensionDefinitions[i].zone_size = 0; |
pDimensionDefinitions[i].zone_size = 0; |
2085 |
} |
} |
2086 |
else { // active dimension |
else { // active dimension |
2090 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
2091 |
dimension == dimension_samplechannel || |
dimension == dimension_samplechannel || |
2092 |
dimension == dimension_releasetrigger || |
dimension == dimension_releasetrigger || |
2093 |
|
dimension == dimension_keyboard || |
2094 |
dimension == dimension_roundrobin || |
dimension == dimension_roundrobin || |
2095 |
dimension == dimension_random) ? split_type_bit |
dimension == dimension_random) ? split_type_bit |
2096 |
: 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 |
|
2097 |
pDimensionDefinitions[i].zone_size = |
pDimensionDefinitions[i].zone_size = |
2098 |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
2099 |
: 0; |
: 0; |
2104 |
} |
} |
2105 |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
2106 |
} |
} |
2107 |
|
for (int i = dimensionBits ; i < 8 ; i++) pDimensionDefinitions[i].bits = 0; |
2108 |
|
|
2109 |
// 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, |
2110 |
for (uint i = 0; i < Dimensions; i++) { |
// update the VelocityTables in the dimension regions |
2111 |
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); |
|
|
} |
|
|
} |
|
|
} |
|
2112 |
|
|
2113 |
// 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(); |
|
2114 |
if (file->pVersion && file->pVersion->major == 3) |
if (file->pVersion && file->pVersion->major == 3) |
2115 |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
2116 |
else |
else |
2122 |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2123 |
} |
} |
2124 |
} |
} |
2125 |
|
|
2126 |
|
// make sure there is at least one dimension region |
2127 |
|
if (!DimensionRegions) { |
2128 |
|
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
2129 |
|
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
2130 |
|
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
2131 |
|
pDimensionRegions[0] = new DimensionRegion(_3ewl); |
2132 |
|
DimensionRegions = 1; |
2133 |
|
} |
2134 |
} |
} |
2135 |
|
|
2136 |
/** |
/** |
2147 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(); |
2148 |
|
|
2149 |
// update dimension region's chunks |
// update dimension region's chunks |
2150 |
for (int i = 0; i < Dimensions; i++) |
for (int i = 0; i < DimensionRegions; i++) { |
2151 |
pDimensionRegions[i]->UpdateChunks(); |
pDimensionRegions[i]->UpdateChunks(); |
2152 |
|
} |
2153 |
|
|
2154 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
2155 |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
2177 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
2178 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
2179 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
2180 |
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"); |
2181 |
std::list<Sample*>::iterator iter = pFile->pSamples->begin(); |
File::SampleList::iterator iter = pFile->pSamples->begin(); |
2182 |
std::list<Sample*>::iterator end = pFile->pSamples->end(); |
File::SampleList::iterator end = pFile->pSamples->end(); |
2183 |
for (int index = 0; iter != end; ++iter, ++index) { |
for (int index = 0; iter != end; ++iter, ++index) { |
2184 |
if (*iter == pDimensionRegions[i]->pSample) iWaveIndex = index; |
if (*iter == pDimensionRegions[i]->pSample) { |
2185 |
break; |
iWaveIndex = index; |
2186 |
|
break; |
2187 |
|
} |
2188 |
} |
} |
2189 |
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"); |
2190 |
} |
} |
2208 |
} |
} |
2209 |
} |
} |
2210 |
|
|
2211 |
void Region::UpdateVelocityTable(dimension_def_t* pDimDef) { |
void Region::UpdateVelocityTable() { |
2212 |
// get dimension's index |
// get velocity dimension's index |
2213 |
int iDimensionNr = -1; |
int veldim = -1; |
2214 |
for (int i = 0; i < Dimensions; i++) { |
for (int i = 0 ; i < Dimensions ; i++) { |
2215 |
if (&pDimensionDefinitions[i] == pDimDef) { |
if (pDimensionDefinitions[i].dimension == gig::dimension_velocity) { |
2216 |
iDimensionNr = i; |
veldim = i; |
2217 |
break; |
break; |
2218 |
} |
} |
2219 |
} |
} |
2220 |
if (iDimensionNr < 0) throw gig::Exception("Invalid dimension_def_t pointer"); |
if (veldim == -1) return; |
2221 |
|
|
2222 |
|
int step = 1; |
2223 |
|
for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits; |
2224 |
|
int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step; |
2225 |
|
int end = step * pDimensionDefinitions[veldim].zones; |
2226 |
|
|
2227 |
|
// loop through all dimension regions for all dimensions except the velocity dimension |
2228 |
|
int dim[8] = { 0 }; |
2229 |
|
for (int i = 0 ; i < DimensionRegions ; i++) { |
2230 |
|
|
2231 |
|
if (pDimensionRegions[i]->VelocityUpperLimit) { |
2232 |
|
// create the velocity table |
2233 |
|
uint8_t* table = pDimensionRegions[i]->VelocityTable; |
2234 |
|
if (!table) { |
2235 |
|
table = new uint8_t[128]; |
2236 |
|
pDimensionRegions[i]->VelocityTable = table; |
2237 |
|
} |
2238 |
|
int tableidx = 0; |
2239 |
|
int velocityZone = 0; |
2240 |
|
for (int k = i ; k < end ; k += step) { |
2241 |
|
DimensionRegion *d = pDimensionRegions[k]; |
2242 |
|
for (; tableidx <= d->VelocityUpperLimit ; tableidx++) table[tableidx] = velocityZone; |
2243 |
|
velocityZone++; |
2244 |
|
} |
2245 |
|
} else { |
2246 |
|
if (pDimensionRegions[i]->VelocityTable) { |
2247 |
|
delete[] pDimensionRegions[i]->VelocityTable; |
2248 |
|
pDimensionRegions[i]->VelocityTable = 0; |
2249 |
|
} |
2250 |
|
} |
2251 |
|
|
2252 |
uint8_t bits[8] = { 0 }; |
int j; |
2253 |
int previousUpperLimit = -1; |
int shift = 0; |
2254 |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
for (j = 0 ; j < Dimensions ; j++) { |
2255 |
bits[iDimensionNr] = velocityZone; |
if (j == veldim) i += skipveldim; // skip velocity dimension |
2256 |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits); |
else { |
2257 |
|
dim[j]++; |
2258 |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
if (dim[j] < pDimensionDefinitions[j].zones) break; |
2259 |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
else { |
2260 |
previousUpperLimit = pDimDef->ranges[velocityZone].high; |
// skip unused dimension regions |
2261 |
// fill velocity table |
dim[j] = 0; |
2262 |
for (int i = pDimDef->ranges[velocityZone].low; i <= pDimDef->ranges[velocityZone].high; i++) { |
i += ((1 << pDimensionDefinitions[j].bits) - |
2263 |
VelocityTable[i] = velocityZone; |
pDimensionDefinitions[j].zones) << shift; |
2264 |
|
} |
2265 |
|
} |
2266 |
|
shift += pDimensionDefinitions[j].bits; |
2267 |
} |
} |
2268 |
|
if (j == Dimensions) break; |
2269 |
} |
} |
2270 |
} |
} |
2271 |
|
|
2320 |
// if this is a layer dimension, update 'Layers' attribute |
// if this is a layer dimension, update 'Layers' attribute |
2321 |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
2322 |
|
|
2323 |
// 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); |
|
|
} |
|
2324 |
} |
} |
2325 |
|
|
2326 |
/** @brief Delete an existing dimension. |
/** @brief Delete an existing dimension. |
2390 |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
2391 |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
2392 |
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; |
|
|
} |
|
2393 |
|
|
2394 |
Dimensions--; |
Dimensions--; |
2395 |
|
|
2398 |
} |
} |
2399 |
|
|
2400 |
Region::~Region() { |
Region::~Region() { |
|
for (uint i = 0; i < Dimensions; i++) { |
|
|
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
|
|
} |
|
2401 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2402 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
2403 |
} |
} |
2422 |
* @see Dimensions |
* @see Dimensions |
2423 |
*/ |
*/ |
2424 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
2425 |
uint8_t bits[8] = { 0 }; |
uint8_t bits; |
2426 |
|
int veldim = -1; |
2427 |
|
int velbitpos; |
2428 |
|
int bitpos = 0; |
2429 |
|
int dimregidx = 0; |
2430 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
2431 |
bits[i] = DimValues[i]; |
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
2432 |
switch (pDimensionDefinitions[i].split_type) { |
// the velocity dimension must be handled after the other dimensions |
2433 |
case split_type_normal: |
veldim = i; |
2434 |
bits[i] = uint8_t(bits[i] / pDimensionDefinitions[i].zone_size); |
velbitpos = bitpos; |
2435 |
break; |
} else { |
2436 |
case split_type_customvelocity: |
switch (pDimensionDefinitions[i].split_type) { |
2437 |
bits[i] = VelocityTable[bits[i]]; |
case split_type_normal: |
2438 |
break; |
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
2439 |
case split_type_bit: // the value is already the sought dimension bit number |
break; |
2440 |
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
case split_type_bit: // the value is already the sought dimension bit number |
2441 |
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; |
2442 |
break; |
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
2443 |
|
break; |
2444 |
|
} |
2445 |
|
dimregidx |= bits << bitpos; |
2446 |
} |
} |
2447 |
|
bitpos += pDimensionDefinitions[i].bits; |
2448 |
} |
} |
2449 |
return GetDimensionRegionByBit(bits); |
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
2450 |
|
if (veldim != -1) { |
2451 |
|
// (dimreg is now the dimension region for the lowest velocity) |
2452 |
|
if (dimreg->VelocityUpperLimit) // custom defined zone ranges |
2453 |
|
bits = dimreg->VelocityTable[DimValues[veldim]]; |
2454 |
|
else // normal split type |
2455 |
|
bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size); |
2456 |
|
|
2457 |
|
dimregidx |= bits << velbitpos; |
2458 |
|
dimreg = pDimensionRegions[dimregidx]; |
2459 |
|
} |
2460 |
|
return dimreg; |
2461 |
} |
} |
2462 |
|
|
2463 |
/** |
/** |
2516 |
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) { |
2517 |
// Initialization |
// Initialization |
2518 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
|
RegionIndex = -1; |
|
2519 |
|
|
2520 |
// Loading |
// Loading |
2521 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
2533 |
} |
} |
2534 |
} |
} |
2535 |
|
|
2536 |
pRegions = new Region*[Regions]; |
if (!pRegions) pRegions = new RegionList; |
2537 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
2538 |
if (lrgn) { |
if (lrgn) { |
|
for (uint i = 0; i < Regions; i++) pRegions[i] = NULL; |
|
2539 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
|
unsigned int iRegion = 0; |
|
2540 |
while (rgn) { |
while (rgn) { |
2541 |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
2542 |
__notify_progress(pProgress, (float) iRegion / (float) Regions); |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
2543 |
pRegions[iRegion] = new Region(this, rgn); |
pRegions->push_back(new Region(this, rgn)); |
|
iRegion++; |
|
2544 |
} |
} |
2545 |
rgn = lrgn->GetNextSubList(); |
rgn = lrgn->GetNextSubList(); |
2546 |
} |
} |
2552 |
} |
} |
2553 |
|
|
2554 |
void Instrument::UpdateRegionKeyTable() { |
void Instrument::UpdateRegionKeyTable() { |
2555 |
for (uint iReg = 0; iReg < Regions; iReg++) { |
RegionList::iterator iter = pRegions->begin(); |
2556 |
for (int iKey = pRegions[iReg]->KeyRange.low; iKey <= pRegions[iReg]->KeyRange.high; iKey++) { |
RegionList::iterator end = pRegions->end(); |
2557 |
RegionKeyTable[iKey] = pRegions[iReg]; |
for (; iter != end; ++iter) { |
2558 |
|
gig::Region* pRegion = static_cast<gig::Region*>(*iter); |
2559 |
|
for (int iKey = pRegion->KeyRange.low; iKey <= pRegion->KeyRange.high; iKey++) { |
2560 |
|
RegionKeyTable[iKey] = pRegion; |
2561 |
} |
} |
2562 |
} |
} |
2563 |
} |
} |
2564 |
|
|
2565 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
|
for (uint i = 0; i < Regions; i++) { |
|
|
if (pRegions) { |
|
|
if (pRegions[i]) delete (pRegions[i]); |
|
|
} |
|
|
} |
|
|
if (pRegions) delete[] pRegions; |
|
2566 |
} |
} |
2567 |
|
|
2568 |
/** |
/** |
2579 |
DLS::Instrument::UpdateChunks(); |
DLS::Instrument::UpdateChunks(); |
2580 |
|
|
2581 |
// update Regions' chunks |
// update Regions' chunks |
2582 |
for (int i = 0; i < Regions; i++) |
{ |
2583 |
pRegions[i]->UpdateChunks(); |
RegionList::iterator iter = pRegions->begin(); |
2584 |
|
RegionList::iterator end = pRegions->end(); |
2585 |
|
for (; iter != end; ++iter) |
2586 |
|
(*iter)->UpdateChunks(); |
2587 |
|
} |
2588 |
|
|
2589 |
// make sure 'lart' RIFF list chunk exists |
// make sure 'lart' RIFF list chunk exists |
2590 |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
2612 |
* there is no Region defined for the given \a Key |
* there is no Region defined for the given \a Key |
2613 |
*/ |
*/ |
2614 |
Region* Instrument::GetRegion(unsigned int Key) { |
Region* Instrument::GetRegion(unsigned int Key) { |
2615 |
if (!pRegions || Key > 127) return NULL; |
if (!pRegions || !pRegions->size() || Key > 127) return NULL; |
2616 |
return RegionKeyTable[Key]; |
return RegionKeyTable[Key]; |
2617 |
|
|
2618 |
/*for (int i = 0; i < Regions; i++) { |
/*for (int i = 0; i < Regions; i++) { |
2619 |
if (Key <= pRegions[i]->KeyRange.high && |
if (Key <= pRegions[i]->KeyRange.high && |
2620 |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
2630 |
* @see GetNextRegion() |
* @see GetNextRegion() |
2631 |
*/ |
*/ |
2632 |
Region* Instrument::GetFirstRegion() { |
Region* Instrument::GetFirstRegion() { |
2633 |
if (!Regions) return NULL; |
if (!pRegions) return NULL; |
2634 |
RegionIndex = 1; |
RegionsIterator = pRegions->begin(); |
2635 |
return pRegions[0]; |
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2636 |
} |
} |
2637 |
|
|
2638 |
/** |
/** |
2644 |
* @see GetFirstRegion() |
* @see GetFirstRegion() |
2645 |
*/ |
*/ |
2646 |
Region* Instrument::GetNextRegion() { |
Region* Instrument::GetNextRegion() { |
2647 |
if (RegionIndex < 0 || uint32_t(RegionIndex) >= Regions) return NULL; |
if (!pRegions) return NULL; |
2648 |
return pRegions[RegionIndex++]; |
RegionsIterator++; |
2649 |
|
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2650 |
} |
} |
2651 |
|
|
2652 |
Region* Instrument::AddRegion() { |
Region* Instrument::AddRegion() { |
2655 |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
2656 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
2657 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
2658 |
// resize 'pRegions' array (increase by one) |
pRegions->push_back(pNewRegion); |
2659 |
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++; |
|
2660 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2661 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2662 |
// done |
// done |
2665 |
|
|
2666 |
void Instrument::DeleteRegion(Region* pRegion) { |
void Instrument::DeleteRegion(Region* pRegion) { |
2667 |
if (!pRegions) return; |
if (!pRegions) return; |
2668 |
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--; |
|
2669 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2670 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2671 |
} |
} |
2676 |
// * |
// * |
2677 |
|
|
2678 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
|
pSamples = NULL; |
|
|
pInstruments = NULL; |
|
2679 |
} |
} |
2680 |
|
|
2681 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
|
pSamples = NULL; |
|
|
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; |
|
2682 |
} |
} |
2683 |
|
|
2684 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
2706 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
2707 |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
2708 |
// 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; |
|
2709 |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
2710 |
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*/); |
2711 |
pSamples->push_back(pSample); |
pSamples->push_back(pSample); |
2721 |
* @throws gig::Exception if given sample could not be found |
* @throws gig::Exception if given sample could not be found |
2722 |
*/ |
*/ |
2723 |
void File::DeleteSample(Sample* pSample) { |
void File::DeleteSample(Sample* pSample) { |
2724 |
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"); |
2725 |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample); |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample); |
2726 |
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"); |
2727 |
pSamples->erase(iter); |
pSamples->erase(iter); |
2728 |
delete pSample; |
delete pSample; |
2729 |
} |
} |
2730 |
|
|
2731 |
|
void File::LoadSamples() { |
2732 |
|
LoadSamples(NULL); |
2733 |
|
} |
2734 |
|
|
2735 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
2736 |
|
if (!pSamples) pSamples = new SampleList; |
2737 |
|
|
2738 |
RIFF::File* file = pRIFF; |
RIFF::File* file = pRIFF; |
2739 |
|
|
2740 |
// just for progress calculation |
// just for progress calculation |
2762 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
2763 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
2764 |
|
|
|
if (!pSamples) pSamples = new SampleList; |
|
2765 |
unsigned long waveFileOffset = wave->GetFilePos(); |
unsigned long waveFileOffset = wave->GetFilePos(); |
2766 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
2767 |
|
|
2778 |
name.replace(nameLen, 5, suffix); |
name.replace(nameLen, 5, suffix); |
2779 |
file = new RIFF::File(name); |
file = new RIFF::File(name); |
2780 |
ExtensionFiles.push_back(file); |
ExtensionFiles.push_back(file); |
2781 |
} |
} else break; |
|
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
|
2782 |
} |
} |
2783 |
|
|
2784 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2788 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2789 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2790 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2791 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2792 |
} |
} |
2793 |
|
|
2794 |
Instrument* File::GetNextInstrument() { |
Instrument* File::GetNextInstrument() { |
2795 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2796 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2797 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2798 |
} |
} |
2799 |
|
|
2800 |
/** |
/** |
2827 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2828 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2829 |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
2830 |
if (i == index) return *InstrumentsIterator; |
if (i == index) return static_cast<gig::Instrument*>( *InstrumentsIterator ); |
2831 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2832 |
} |
} |
2833 |
return NULL; |
return NULL; |
2843 |
Instrument* File::AddInstrument() { |
Instrument* File::AddInstrument() { |
2844 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2845 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
2846 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
2847 |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
2848 |
Instrument* pInstrument = new Instrument(this, lstInstr); |
Instrument* pInstrument = new Instrument(this, lstInstr); |
2860 |
*/ |
*/ |
2861 |
void File::DeleteInstrument(Instrument* pInstrument) { |
void File::DeleteInstrument(Instrument* pInstrument) { |
2862 |
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"); |
2863 |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument); |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); |
2864 |
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"); |
2865 |
pInstruments->erase(iter); |
pInstruments->erase(iter); |
2866 |
delete pInstrument; |
delete pInstrument; |
2867 |
} |
} |
2868 |
|
|
2869 |
|
void File::LoadInstruments() { |
2870 |
|
LoadInstruments(NULL); |
2871 |
|
} |
2872 |
|
|
2873 |
void File::LoadInstruments(progress_t* pProgress) { |
void File::LoadInstruments(progress_t* pProgress) { |
2874 |
|
if (!pInstruments) pInstruments = new InstrumentList; |
2875 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
2876 |
if (lstInstruments) { |
if (lstInstruments) { |
2877 |
int iInstrumentIndex = 0; |
int iInstrumentIndex = 0; |
2886 |
progress_t subprogress; |
progress_t subprogress; |
2887 |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
2888 |
|
|
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
2889 |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
2890 |
|
|
2891 |
iInstrumentIndex++; |
iInstrumentIndex++; |
2894 |
} |
} |
2895 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2896 |
} |
} |
|
else throw gig::Exception("Mandatory <lins> list chunk not found."); |
|
2897 |
} |
} |
2898 |
|
|
2899 |
|
|