1183 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1184 |
Instances++; |
Instances++; |
1185 |
|
|
1186 |
|
pSample = NULL; |
1187 |
|
|
1188 |
memcpy(&Crossfade, &SamplerOptions, 4); |
memcpy(&Crossfade, &SamplerOptions, 4); |
1189 |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
1190 |
|
|
2147 |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2148 |
} |
} |
2149 |
} |
} |
2150 |
|
|
2151 |
|
// make sure there is at least one dimension region |
2152 |
|
if (!DimensionRegions) { |
2153 |
|
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
2154 |
|
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
2155 |
|
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
2156 |
|
pDimensionRegions[0] = new DimensionRegion(_3ewl); |
2157 |
|
DimensionRegions = 1; |
2158 |
|
} |
2159 |
} |
} |
2160 |
|
|
2161 |
/** |
/** |
2172 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(); |
2173 |
|
|
2174 |
// update dimension region's chunks |
// update dimension region's chunks |
2175 |
for (int i = 0; i < Dimensions; i++) |
for (int i = 0; i < DimensionRegions; i++) { |
2176 |
pDimensionRegions[i]->UpdateChunks(); |
pDimensionRegions[i]->UpdateChunks(); |
2177 |
|
} |
2178 |
|
|
2179 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
2180 |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
2202 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
2203 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
2204 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
2205 |
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"); |
2206 |
std::list<Sample*>::iterator iter = pFile->pSamples->begin(); |
File::SampleList::iterator iter = pFile->pSamples->begin(); |
2207 |
std::list<Sample*>::iterator end = pFile->pSamples->end(); |
File::SampleList::iterator end = pFile->pSamples->end(); |
2208 |
for (int index = 0; iter != end; ++iter, ++index) { |
for (int index = 0; iter != end; ++iter, ++index) { |
2209 |
if (*iter == pDimensionRegions[i]->pSample) iWaveIndex = index; |
if (*iter == pDimensionRegions[i]->pSample) { |
2210 |
break; |
iWaveIndex = index; |
2211 |
|
break; |
2212 |
|
} |
2213 |
} |
} |
2214 |
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"); |
2215 |
} |
} |
2499 |
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) { |
2500 |
// Initialization |
// Initialization |
2501 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
|
RegionIndex = -1; |
|
2502 |
|
|
2503 |
// Loading |
// Loading |
2504 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
2516 |
} |
} |
2517 |
} |
} |
2518 |
|
|
2519 |
pRegions = new Region*[Regions]; |
if (!pRegions) pRegions = new RegionList; |
2520 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
2521 |
if (lrgn) { |
if (lrgn) { |
|
for (uint i = 0; i < Regions; i++) pRegions[i] = NULL; |
|
2522 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
|
unsigned int iRegion = 0; |
|
2523 |
while (rgn) { |
while (rgn) { |
2524 |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
2525 |
__notify_progress(pProgress, (float) iRegion / (float) Regions); |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
2526 |
pRegions[iRegion] = new Region(this, rgn); |
pRegions->push_back(new Region(this, rgn)); |
|
iRegion++; |
|
2527 |
} |
} |
2528 |
rgn = lrgn->GetNextSubList(); |
rgn = lrgn->GetNextSubList(); |
2529 |
} |
} |
2535 |
} |
} |
2536 |
|
|
2537 |
void Instrument::UpdateRegionKeyTable() { |
void Instrument::UpdateRegionKeyTable() { |
2538 |
for (uint iReg = 0; iReg < Regions; iReg++) { |
RegionList::iterator iter = pRegions->begin(); |
2539 |
for (int iKey = pRegions[iReg]->KeyRange.low; iKey <= pRegions[iReg]->KeyRange.high; iKey++) { |
RegionList::iterator end = pRegions->end(); |
2540 |
RegionKeyTable[iKey] = pRegions[iReg]; |
for (; iter != end; ++iter) { |
2541 |
|
gig::Region* pRegion = static_cast<gig::Region*>(*iter); |
2542 |
|
for (int iKey = pRegion->KeyRange.low; iKey <= pRegion->KeyRange.high; iKey++) { |
2543 |
|
RegionKeyTable[iKey] = pRegion; |
2544 |
} |
} |
2545 |
} |
} |
2546 |
} |
} |
2547 |
|
|
2548 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
|
for (uint i = 0; i < Regions; i++) { |
|
|
if (pRegions) { |
|
|
if (pRegions[i]) delete (pRegions[i]); |
|
|
} |
|
|
} |
|
|
if (pRegions) delete[] pRegions; |
|
2549 |
} |
} |
2550 |
|
|
2551 |
/** |
/** |
2562 |
DLS::Instrument::UpdateChunks(); |
DLS::Instrument::UpdateChunks(); |
2563 |
|
|
2564 |
// update Regions' chunks |
// update Regions' chunks |
2565 |
for (int i = 0; i < Regions; i++) |
{ |
2566 |
pRegions[i]->UpdateChunks(); |
RegionList::iterator iter = pRegions->begin(); |
2567 |
|
RegionList::iterator end = pRegions->end(); |
2568 |
|
for (; iter != end; ++iter) |
2569 |
|
(*iter)->UpdateChunks(); |
2570 |
|
} |
2571 |
|
|
2572 |
// make sure 'lart' RIFF list chunk exists |
// make sure 'lart' RIFF list chunk exists |
2573 |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = pCkInstrument->GetSubList(LIST_TYPE_LART); |
2595 |
* there is no Region defined for the given \a Key |
* there is no Region defined for the given \a Key |
2596 |
*/ |
*/ |
2597 |
Region* Instrument::GetRegion(unsigned int Key) { |
Region* Instrument::GetRegion(unsigned int Key) { |
2598 |
if (!pRegions || Key > 127) return NULL; |
if (!pRegions || !pRegions->size() || Key > 127) return NULL; |
2599 |
return RegionKeyTable[Key]; |
return RegionKeyTable[Key]; |
2600 |
|
|
2601 |
/*for (int i = 0; i < Regions; i++) { |
/*for (int i = 0; i < Regions; i++) { |
2602 |
if (Key <= pRegions[i]->KeyRange.high && |
if (Key <= pRegions[i]->KeyRange.high && |
2603 |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
Key >= pRegions[i]->KeyRange.low) return pRegions[i]; |
2613 |
* @see GetNextRegion() |
* @see GetNextRegion() |
2614 |
*/ |
*/ |
2615 |
Region* Instrument::GetFirstRegion() { |
Region* Instrument::GetFirstRegion() { |
2616 |
if (!Regions) return NULL; |
if (!pRegions) return NULL; |
2617 |
RegionIndex = 1; |
RegionsIterator = pRegions->begin(); |
2618 |
return pRegions[0]; |
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2619 |
} |
} |
2620 |
|
|
2621 |
/** |
/** |
2627 |
* @see GetFirstRegion() |
* @see GetFirstRegion() |
2628 |
*/ |
*/ |
2629 |
Region* Instrument::GetNextRegion() { |
Region* Instrument::GetNextRegion() { |
2630 |
if (RegionIndex < 0 || uint32_t(RegionIndex) >= Regions) return NULL; |
if (!pRegions) return NULL; |
2631 |
return pRegions[RegionIndex++]; |
RegionsIterator++; |
2632 |
|
return static_cast<gig::Region*>( (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL ); |
2633 |
} |
} |
2634 |
|
|
2635 |
Region* Instrument::AddRegion() { |
Region* Instrument::AddRegion() { |
2638 |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
if (!lrgn) lrgn = pCkInstrument->AddSubList(LIST_TYPE_LRGN); |
2639 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
2640 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
2641 |
// resize 'pRegions' array (increase by one) |
pRegions->push_back(pNewRegion); |
2642 |
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++; |
|
2643 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2644 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2645 |
// done |
// done |
2648 |
|
|
2649 |
void Instrument::DeleteRegion(Region* pRegion) { |
void Instrument::DeleteRegion(Region* pRegion) { |
2650 |
if (!pRegions) return; |
if (!pRegions) return; |
2651 |
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--; |
|
2652 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
2653 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
2654 |
} |
} |
2659 |
// * |
// * |
2660 |
|
|
2661 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
|
pSamples = NULL; |
|
|
pInstruments = NULL; |
|
2662 |
} |
} |
2663 |
|
|
2664 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
|
pSamples = NULL; |
|
|
pInstruments = NULL; |
|
2665 |
} |
} |
2666 |
|
|
2667 |
File::~File() { |
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; |
|
|
} |
|
2668 |
// free extension files |
// free extension files |
2669 |
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++) |
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++) |
2670 |
delete *i; |
delete *i; |
2695 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
2696 |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
2697 |
// 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; |
|
2698 |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); |
2699 |
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*/); |
2700 |
pSamples->push_back(pSample); |
pSamples->push_back(pSample); |
2710 |
* @throws gig::Exception if given sample could not be found |
* @throws gig::Exception if given sample could not be found |
2711 |
*/ |
*/ |
2712 |
void File::DeleteSample(Sample* pSample) { |
void File::DeleteSample(Sample* pSample) { |
2713 |
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"); |
2714 |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), pSample); |
SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample); |
2715 |
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"); |
2716 |
pSamples->erase(iter); |
pSamples->erase(iter); |
2717 |
delete pSample; |
delete pSample; |
2718 |
} |
} |
2719 |
|
|
2720 |
|
void File::LoadSamples() { |
2721 |
|
LoadSamples(NULL); |
2722 |
|
} |
2723 |
|
|
2724 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
2725 |
|
if (!pSamples) pSamples = new SampleList; |
2726 |
|
|
2727 |
RIFF::File* file = pRIFF; |
RIFF::File* file = pRIFF; |
2728 |
|
|
2729 |
// just for progress calculation |
// just for progress calculation |
2751 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
2752 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
2753 |
|
|
|
if (!pSamples) pSamples = new SampleList; |
|
2754 |
unsigned long waveFileOffset = wave->GetFilePos(); |
unsigned long waveFileOffset = wave->GetFilePos(); |
2755 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
2756 |
|
|
2767 |
name.replace(nameLen, 5, suffix); |
name.replace(nameLen, 5, suffix); |
2768 |
file = new RIFF::File(name); |
file = new RIFF::File(name); |
2769 |
ExtensionFiles.push_back(file); |
ExtensionFiles.push_back(file); |
2770 |
} |
} else break; |
|
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
|
2771 |
} |
} |
2772 |
|
|
2773 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2777 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2778 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2779 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2780 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2781 |
} |
} |
2782 |
|
|
2783 |
Instrument* File::GetNextInstrument() { |
Instrument* File::GetNextInstrument() { |
2784 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2785 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2786 |
return (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL; |
return static_cast<gig::Instrument*>( (InstrumentsIterator != pInstruments->end()) ? *InstrumentsIterator : NULL ); |
2787 |
} |
} |
2788 |
|
|
2789 |
/** |
/** |
2816 |
if (!pInstruments) return NULL; |
if (!pInstruments) return NULL; |
2817 |
InstrumentsIterator = pInstruments->begin(); |
InstrumentsIterator = pInstruments->begin(); |
2818 |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) { |
2819 |
if (i == index) return *InstrumentsIterator; |
if (i == index) return static_cast<gig::Instrument*>( *InstrumentsIterator ); |
2820 |
InstrumentsIterator++; |
InstrumentsIterator++; |
2821 |
} |
} |
2822 |
return NULL; |
return NULL; |
2832 |
Instrument* File::AddInstrument() { |
Instrument* File::AddInstrument() { |
2833 |
if (!pInstruments) LoadInstruments(); |
if (!pInstruments) LoadInstruments(); |
2834 |
__ensureMandatoryChunksExist(); |
__ensureMandatoryChunksExist(); |
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
2835 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
2836 |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); |
2837 |
Instrument* pInstrument = new Instrument(this, lstInstr); |
Instrument* pInstrument = new Instrument(this, lstInstr); |
2849 |
*/ |
*/ |
2850 |
void File::DeleteInstrument(Instrument* pInstrument) { |
void File::DeleteInstrument(Instrument* pInstrument) { |
2851 |
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"); |
2852 |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), pInstrument); |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); |
2853 |
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"); |
2854 |
pInstruments->erase(iter); |
pInstruments->erase(iter); |
2855 |
delete pInstrument; |
delete pInstrument; |
2856 |
} |
} |
2857 |
|
|
2858 |
|
void File::LoadInstruments() { |
2859 |
|
LoadInstruments(NULL); |
2860 |
|
} |
2861 |
|
|
2862 |
void File::LoadInstruments(progress_t* pProgress) { |
void File::LoadInstruments(progress_t* pProgress) { |
2863 |
|
if (!pInstruments) pInstruments = new InstrumentList; |
2864 |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); |
2865 |
if (lstInstruments) { |
if (lstInstruments) { |
2866 |
int iInstrumentIndex = 0; |
int iInstrumentIndex = 0; |
2875 |
progress_t subprogress; |
progress_t subprogress; |
2876 |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
__divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex); |
2877 |
|
|
|
if (!pInstruments) pInstruments = new InstrumentList; |
|
2878 |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
pInstruments->push_back(new Instrument(this, lstInstr, &subprogress)); |
2879 |
|
|
2880 |
iInstrumentIndex++; |
iInstrumentIndex++; |
2883 |
} |
} |
2884 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
2885 |
} |
} |
|
else throw gig::Exception("Mandatory <lins> list chunk not found."); |
|
2886 |
} |
} |
2887 |
|
|
2888 |
|
|