243 |
unsigned int Sample::Instances = 0; |
unsigned int Sample::Instances = 0; |
244 |
buffer_t Sample::InternalDecompressionBuffer; |
buffer_t Sample::InternalDecompressionBuffer; |
245 |
|
|
246 |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
247 |
Instances++; |
Instances++; |
248 |
|
FileNo = fileNo; |
249 |
|
|
250 |
RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
251 |
if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found."); |
if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found."); |
1614 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
1615 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
1616 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
1617 |
|
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
1618 |
Sample* sample = file->GetFirstSample(pProgress); |
Sample* sample = file->GetFirstSample(pProgress); |
1619 |
while (sample) { |
while (sample) { |
1620 |
if (sample->ulWavePoolOffset == soughtoffset) return static_cast<gig::Sample*>(pSample = sample); |
if (sample->ulWavePoolOffset == soughtoffset && |
1621 |
|
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample); |
1622 |
sample = file->GetNextSample(); |
sample = file->GetNextSample(); |
1623 |
} |
} |
1624 |
return NULL; |
return NULL; |
1761 |
pInstruments->clear(); |
pInstruments->clear(); |
1762 |
delete pInstruments; |
delete pInstruments; |
1763 |
} |
} |
1764 |
|
// free extension files |
1765 |
|
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++) |
1766 |
|
delete *i; |
1767 |
} |
} |
1768 |
|
|
1769 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
1780 |
} |
} |
1781 |
|
|
1782 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
1783 |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
RIFF::File* file = pRIFF; |
|
if (wvpl) { |
|
|
// just for progress calculation |
|
|
int iSampleIndex = 0; |
|
|
int iTotalSamples = wvpl->CountSubLists(LIST_TYPE_WAVE); |
|
|
|
|
|
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
|
|
RIFF::List* wave = wvpl->GetFirstSubList(); |
|
|
while (wave) { |
|
|
if (wave->GetListType() == LIST_TYPE_WAVE) { |
|
|
// notify current progress |
|
|
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
|
|
__notify_progress(pProgress, subprogress); |
|
|
|
|
|
if (!pSamples) pSamples = new SampleList; |
|
|
unsigned long waveFileOffset = wave->GetFilePos(); |
|
|
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset)); |
|
1784 |
|
|
1785 |
iSampleIndex++; |
// just for progress calculation |
1786 |
|
int iSampleIndex = 0; |
1787 |
|
int iTotalSamples = WavePoolCount; |
1788 |
|
|
1789 |
|
// check if samples should be loaded from extension files |
1790 |
|
int lastFileNo = 0; |
1791 |
|
for (int i = 0 ; i < WavePoolCount ; i++) { |
1792 |
|
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
1793 |
|
} |
1794 |
|
String name(pRIFF->Filename); |
1795 |
|
int nameLen = pRIFF->Filename.length(); |
1796 |
|
char suffix[6]; |
1797 |
|
if (nameLen > 4 && pRIFF->Filename.substr(nameLen - 4) == ".gig") nameLen -= 4; |
1798 |
|
|
1799 |
|
for (int fileNo = 0 ; ; ) { |
1800 |
|
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
1801 |
|
if (wvpl) { |
1802 |
|
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
1803 |
|
RIFF::List* wave = wvpl->GetFirstSubList(); |
1804 |
|
while (wave) { |
1805 |
|
if (wave->GetListType() == LIST_TYPE_WAVE) { |
1806 |
|
// notify current progress |
1807 |
|
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
1808 |
|
__notify_progress(pProgress, subprogress); |
1809 |
|
|
1810 |
|
if (!pSamples) pSamples = new SampleList; |
1811 |
|
unsigned long waveFileOffset = wave->GetFilePos(); |
1812 |
|
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
1813 |
|
|
1814 |
|
iSampleIndex++; |
1815 |
|
} |
1816 |
|
wave = wvpl->GetNextSubList(); |
1817 |
} |
} |
1818 |
wave = wvpl->GetNextSubList(); |
|
1819 |
|
if (fileNo == lastFileNo) break; |
1820 |
|
|
1821 |
|
// open extension file (*.gx01, *.gx02, ...) |
1822 |
|
fileNo++; |
1823 |
|
sprintf(suffix, ".gx%02d", fileNo); |
1824 |
|
name.replace(nameLen, 5, suffix); |
1825 |
|
file = new RIFF::File(name); |
1826 |
|
ExtensionFiles.push_back(file); |
1827 |
} |
} |
1828 |
__notify_progress(pProgress, 1.0); // notify done |
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
1829 |
} |
} |
1830 |
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
|
1831 |
|
__notify_progress(pProgress, 1.0); // notify done |
1832 |
} |
} |
1833 |
|
|
1834 |
Instrument* File::GetFirstInstrument() { |
Instrument* File::GetFirstInstrument() { |