2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file access library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2016 by Christian Schoenebeck * |
* Copyright (C) 2003-2017 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 * |
24 |
#include "gig.h" |
#include "gig.h" |
25 |
|
|
26 |
#include "helper.h" |
#include "helper.h" |
27 |
|
#include "Serialization.h" |
28 |
|
|
29 |
#include <algorithm> |
#include <algorithm> |
30 |
#include <math.h> |
#include <math.h> |
56 |
#define GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(x) ((x & 0x03) << 3) |
#define GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(x) ((x & 0x03) << 3) |
57 |
#define GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(x) ((x & 0x03) << 5) |
#define GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(x) ((x & 0x03) << 5) |
58 |
|
|
59 |
|
#define SRLZ(member) \ |
60 |
|
archive->serializeMember(*this, member, #member); |
61 |
|
|
62 |
namespace gig { |
namespace gig { |
63 |
|
|
64 |
// *************** Internal functions for sample decompression *************** |
// *************** Internal functions for sample decompression *************** |
273 |
* steps. |
* steps. |
274 |
* |
* |
275 |
* Once the whole data was processed by __calculateCRC(), one should |
* Once the whole data was processed by __calculateCRC(), one should |
276 |
* call __encodeCRC() to get the final CRC result. |
* call __finalizeCRC() to get the final CRC result. |
277 |
* |
* |
278 |
* @param buf - pointer to data the CRC shall be calculated of |
* @param buf - pointer to data the CRC shall be calculated of |
279 |
* @param bufSize - size of the data to be processed |
* @param bufSize - size of the data to be processed |
280 |
* @param crc - variable the CRC sum shall be stored to |
* @param crc - variable the CRC sum shall be stored to |
281 |
*/ |
*/ |
282 |
static void __calculateCRC(unsigned char* buf, int bufSize, uint32_t& crc) { |
static void __calculateCRC(unsigned char* buf, size_t bufSize, uint32_t& crc) { |
283 |
for (int i = 0 ; i < bufSize ; i++) { |
for (size_t i = 0 ; i < bufSize ; i++) { |
284 |
crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); |
crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); |
285 |
} |
} |
286 |
} |
} |
290 |
* |
* |
291 |
* @param crc - variable previously passed to __calculateCRC() |
* @param crc - variable previously passed to __calculateCRC() |
292 |
*/ |
*/ |
293 |
inline static uint32_t __encodeCRC(const uint32_t& crc) { |
inline static void __finalizeCRC(uint32_t& crc) { |
294 |
return crc ^ 0xffffffff; |
crc ^= 0xffffffff; |
295 |
} |
} |
296 |
|
|
297 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
// *************** leverage_ctrl_t *************** |
323 |
|
// * |
324 |
|
|
325 |
|
void leverage_ctrl_t::serialize(Serialization::Archive* archive) { |
326 |
|
SRLZ(type); |
327 |
|
SRLZ(controller_number); |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
// *************** crossfade_t *************** |
333 |
|
// * |
334 |
|
|
335 |
|
void crossfade_t::serialize(Serialization::Archive* archive) { |
336 |
|
SRLZ(in_start); |
337 |
|
SRLZ(in_end); |
338 |
|
SRLZ(out_start); |
339 |
|
SRLZ(out_end); |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
// *************** Sample *************** |
// *************** Sample *************** |
345 |
// * |
// * |
346 |
|
|
1320 |
// if this is the last write, update the checksum chunk in the |
// if this is the last write, update the checksum chunk in the |
1321 |
// file |
// file |
1322 |
if (pCkData->GetPos() == pCkData->GetSize()) { |
if (pCkData->GetPos() == pCkData->GetSize()) { |
1323 |
|
__finalizeCRC(crc); |
1324 |
File* pFile = static_cast<File*>(GetParent()); |
File* pFile = static_cast<File*>(GetParent()); |
1325 |
pFile->SetSampleChecksum(this, __encodeCRC(crc)); |
pFile->SetSampleChecksum(this, crc); |
1326 |
} |
} |
1327 |
return res; |
return res; |
1328 |
} |
} |
1423 |
* @see GetWaveDataCRC32Checksum() |
* @see GetWaveDataCRC32Checksum() |
1424 |
*/ |
*/ |
1425 |
bool Sample::VerifyWaveData(uint32_t* pActually) { |
bool Sample::VerifyWaveData(uint32_t* pActually) { |
1426 |
File* pFile = static_cast<File*>(GetParent()); |
//File* pFile = static_cast<File*>(GetParent()); |
1427 |
uint32_t crc = CalculateWaveDataChecksum(); |
uint32_t crc = CalculateWaveDataChecksum(); |
1428 |
if (pActually) *pActually = crc; |
if (pActually) *pActually = crc; |
1429 |
return crc == this->crc; |
return crc == this->crc; |
1443 |
if (nRead <= 0) break; |
if (nRead <= 0) break; |
1444 |
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
1445 |
} |
} |
1446 |
__encodeCRC(crc); |
__finalizeCRC(crc); |
1447 |
return crc; |
return crc; |
1448 |
} |
} |
1449 |
|
|
1816 |
} |
} |
1817 |
} |
} |
1818 |
|
|
1819 |
|
void DimensionRegion::serialize(Serialization::Archive* archive) { |
1820 |
|
// in case this class will become backward incompatible one day, |
1821 |
|
// then set a version and minimum version for this class like: |
1822 |
|
//archive->setVersion(*this, 2); |
1823 |
|
//archive->setMinVersion(*this, 1); |
1824 |
|
|
1825 |
|
SRLZ(VelocityUpperLimit); |
1826 |
|
SRLZ(EG1PreAttack); |
1827 |
|
SRLZ(EG1Attack); |
1828 |
|
SRLZ(EG1Decay1); |
1829 |
|
SRLZ(EG1Decay2); |
1830 |
|
SRLZ(EG1InfiniteSustain); |
1831 |
|
SRLZ(EG1Sustain); |
1832 |
|
SRLZ(EG1Release); |
1833 |
|
SRLZ(EG1Hold); |
1834 |
|
SRLZ(EG1Controller); |
1835 |
|
SRLZ(EG1ControllerInvert); |
1836 |
|
SRLZ(EG1ControllerAttackInfluence); |
1837 |
|
SRLZ(EG1ControllerDecayInfluence); |
1838 |
|
SRLZ(EG1ControllerReleaseInfluence); |
1839 |
|
SRLZ(LFO1Frequency); |
1840 |
|
SRLZ(LFO1InternalDepth); |
1841 |
|
SRLZ(LFO1ControlDepth); |
1842 |
|
SRLZ(LFO1Controller); |
1843 |
|
SRLZ(LFO1FlipPhase); |
1844 |
|
SRLZ(LFO1Sync); |
1845 |
|
SRLZ(EG2PreAttack); |
1846 |
|
SRLZ(EG2Attack); |
1847 |
|
SRLZ(EG2Decay1); |
1848 |
|
SRLZ(EG2Decay2); |
1849 |
|
SRLZ(EG2InfiniteSustain); |
1850 |
|
SRLZ(EG2Sustain); |
1851 |
|
SRLZ(EG2Release); |
1852 |
|
SRLZ(EG2Controller); |
1853 |
|
SRLZ(EG2ControllerInvert); |
1854 |
|
SRLZ(EG2ControllerAttackInfluence); |
1855 |
|
SRLZ(EG2ControllerDecayInfluence); |
1856 |
|
SRLZ(EG2ControllerReleaseInfluence); |
1857 |
|
SRLZ(LFO2Frequency); |
1858 |
|
SRLZ(LFO2InternalDepth); |
1859 |
|
SRLZ(LFO2ControlDepth); |
1860 |
|
SRLZ(LFO2Controller); |
1861 |
|
SRLZ(LFO2FlipPhase); |
1862 |
|
SRLZ(LFO2Sync); |
1863 |
|
SRLZ(EG3Attack); |
1864 |
|
SRLZ(EG3Depth); |
1865 |
|
SRLZ(LFO3Frequency); |
1866 |
|
SRLZ(LFO3InternalDepth); |
1867 |
|
SRLZ(LFO3ControlDepth); |
1868 |
|
SRLZ(LFO3Controller); |
1869 |
|
SRLZ(LFO3Sync); |
1870 |
|
SRLZ(VCFEnabled); |
1871 |
|
SRLZ(VCFType); |
1872 |
|
SRLZ(VCFCutoffController); |
1873 |
|
SRLZ(VCFCutoffControllerInvert); |
1874 |
|
SRLZ(VCFCutoff); |
1875 |
|
SRLZ(VCFVelocityCurve); |
1876 |
|
SRLZ(VCFVelocityScale); |
1877 |
|
SRLZ(VCFVelocityDynamicRange); |
1878 |
|
SRLZ(VCFResonance); |
1879 |
|
SRLZ(VCFResonanceDynamic); |
1880 |
|
SRLZ(VCFResonanceController); |
1881 |
|
SRLZ(VCFKeyboardTracking); |
1882 |
|
SRLZ(VCFKeyboardTrackingBreakpoint); |
1883 |
|
SRLZ(VelocityResponseCurve); |
1884 |
|
SRLZ(VelocityResponseDepth); |
1885 |
|
SRLZ(VelocityResponseCurveScaling); |
1886 |
|
SRLZ(ReleaseVelocityResponseCurve); |
1887 |
|
SRLZ(ReleaseVelocityResponseDepth); |
1888 |
|
SRLZ(ReleaseTriggerDecay); |
1889 |
|
SRLZ(Crossfade); |
1890 |
|
SRLZ(PitchTrack); |
1891 |
|
SRLZ(DimensionBypass); |
1892 |
|
SRLZ(Pan); |
1893 |
|
SRLZ(SelfMask); |
1894 |
|
SRLZ(AttenuationController); |
1895 |
|
SRLZ(InvertAttenuationController); |
1896 |
|
SRLZ(AttenuationControllerThreshold); |
1897 |
|
SRLZ(ChannelOffset); |
1898 |
|
SRLZ(SustainDefeat); |
1899 |
|
SRLZ(MSDecode); |
1900 |
|
//SRLZ(SampleStartOffset); |
1901 |
|
SRLZ(SampleAttenuation); |
1902 |
|
|
1903 |
|
// derived attributes from DLS::Sampler |
1904 |
|
SRLZ(FineTune); |
1905 |
|
SRLZ(Gain); |
1906 |
|
} |
1907 |
|
|
1908 |
/** |
/** |
1909 |
* Updates the respective member variable and updates @c SampleAttenuation |
* Updates the respective member variable and updates @c SampleAttenuation |
1910 |
* which depends on this value. |
* which depends on this value. |
1945 |
|
|
1946 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1947 |
|
|
1948 |
const uint32_t chunksize = _3ewa->GetNewSize(); |
const uint32_t chunksize = (uint32_t) _3ewa->GetNewSize(); |
1949 |
store32(&pData[0], chunksize); // unknown, always chunk size? |
store32(&pData[0], chunksize); // unknown, always chunk size? |
1950 |
|
|
1951 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
2619 |
|
|
2620 |
// unknown controller type |
// unknown controller type |
2621 |
default: |
default: |
2622 |
throw gig::Exception("Unknown leverage controller type."); |
throw gig::Exception("Unknown leverage controller type (0x%x).", EncodedController); |
2623 |
} |
} |
2624 |
return decodedcontroller; |
return decodedcontroller; |
2625 |
} |
} |
3913 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
3914 |
uint8_t bits; |
uint8_t bits; |
3915 |
int veldim = -1; |
int veldim = -1; |
3916 |
int velbitpos; |
int velbitpos = 0; |
3917 |
int bitpos = 0; |
int bitpos = 0; |
3918 |
int dimregidx = 0; |
int dimregidx = 0; |
3919 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
3962 |
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
3963 |
uint8_t bits; |
uint8_t bits; |
3964 |
int veldim = -1; |
int veldim = -1; |
3965 |
int velbitpos; |
int velbitpos = 0; |
3966 |
int bitpos = 0; |
int bitpos = 0; |
3967 |
int dimregidx = 0; |
int dimregidx = 0; |
3968 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
4311 |
// to handle potential future extensions of the header |
// to handle potential future extensions of the header |
4312 |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4313 |
// read actual script data |
// read actual script data |
4314 |
uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos(); |
uint32_t scriptSize = uint32_t(ckScri->GetSize() - ckScri->GetPos()); |
4315 |
data.resize(scriptSize); |
data.resize(scriptSize); |
4316 |
for (int i = 0; i < scriptSize; ++i) |
for (int i = 0; i < scriptSize; ++i) |
4317 |
data[i] = ckScri->ReadUint8(); |
data[i] = ckScri->ReadUint8(); |
4362 |
// recalculate CRC32 check sum |
// recalculate CRC32 check sum |
4363 |
__resetCRC(crc); |
__resetCRC(crc); |
4364 |
__calculateCRC(&data[0], data.size(), crc); |
__calculateCRC(&data[0], data.size(), crc); |
4365 |
__encodeCRC(crc); |
__finalizeCRC(crc); |
4366 |
// make sure chunk exists and has the required size |
// make sure chunk exists and has the required size |
4367 |
const int chunkSize = 7*sizeof(int32_t) + Name.size() + data.size(); |
const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size(); |
4368 |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
4369 |
else pChunk->Resize(chunkSize); |
else pChunk->Resize(chunkSize); |
4370 |
// fill the chunk data to be written to disk |
// fill the chunk data to be written to disk |
4371 |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
4372 |
int pos = 0; |
int pos = 0; |
4373 |
store32(&pData[pos], 6*sizeof(int32_t) + Name.size()); // total header size |
store32(&pData[pos], uint32_t(6*sizeof(int32_t) + Name.size())); // total header size |
4374 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4375 |
store32(&pData[pos], Compression); |
store32(&pData[pos], Compression); |
4376 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4382 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4383 |
store32(&pData[pos], crc); |
store32(&pData[pos], crc); |
4384 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4385 |
store32(&pData[pos], Name.size()); |
store32(&pData[pos], (uint32_t) Name.size()); |
4386 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4387 |
for (int i = 0; i < Name.size(); ++i, ++pos) |
for (int i = 0; i < Name.size(); ++i, ++pos) |
4388 |
pData[pos] = Name[i]; |
pData[pos] = Name[i]; |
4413 |
return pGroup; |
return pGroup; |
4414 |
} |
} |
4415 |
|
|
4416 |
|
/** |
4417 |
|
* Make a (semi) deep copy of the Script object given by @a orig |
4418 |
|
* and assign it to this object. Note: the ScriptGroup this Script |
4419 |
|
* object belongs to remains untouched by this call. |
4420 |
|
* |
4421 |
|
* @param orig - original Script object to be copied from |
4422 |
|
*/ |
4423 |
|
void Script::CopyAssign(const Script* orig) { |
4424 |
|
Name = orig->Name; |
4425 |
|
Compression = orig->Compression; |
4426 |
|
Encoding = orig->Encoding; |
4427 |
|
Language = orig->Language; |
4428 |
|
Bypass = orig->Bypass; |
4429 |
|
data = orig->data; |
4430 |
|
} |
4431 |
|
|
4432 |
void Script::RemoveAllScriptReferences() { |
void Script::RemoveAllScriptReferences() { |
4433 |
File* pFile = pGroup->pFile; |
File* pFile = pGroup->pFile; |
4434 |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4575 |
EffectSend = 0; |
EffectSend = 0; |
4576 |
Attenuation = 0; |
Attenuation = 0; |
4577 |
FineTune = 0; |
FineTune = 0; |
4578 |
PitchbendRange = 0; |
PitchbendRange = 2; |
4579 |
PianoReleaseMode = false; |
PianoReleaseMode = false; |
4580 |
DimensionKeyRange.low = 0; |
DimensionKeyRange.low = 0; |
4581 |
DimensionKeyRange.high = 0; |
DimensionKeyRange.high = 0; |
4750 |
|
|
4751 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4752 |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
4753 |
const int slotCount = pScriptRefs->size(); |
const int slotCount = (int) pScriptRefs->size(); |
4754 |
const int headerSize = 3 * sizeof(uint32_t); |
const int headerSize = 3 * sizeof(uint32_t); |
4755 |
const int slotSize = 2 * sizeof(uint32_t); |
const int slotSize = 2 * sizeof(uint32_t); |
4756 |
const int totalChunkSize = headerSize + slotCount * slotSize; |
const int totalChunkSize = headerSize + slotCount * slotSize; |
4786 |
if (pScriptRefs && pScriptRefs->size() > 0) { |
if (pScriptRefs && pScriptRefs->size() > 0) { |
4787 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4788 |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4789 |
const int slotCount = pScriptRefs->size(); |
const int slotCount = (int) pScriptRefs->size(); |
4790 |
const int headerSize = 3 * sizeof(uint32_t); |
const int headerSize = 3 * sizeof(uint32_t); |
4791 |
ckSCSL->SetPos(headerSize); |
ckSCSL->SetPos(headerSize); |
4792 |
for (int i = 0; i < slotCount; ++i) { |
for (int i = 0; i < slotCount; ++i) { |
4793 |
uint32_t fileOffset = |
uint32_t fileOffset = uint32_t( |
4794 |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4795 |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4796 |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()); |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()) |
4797 |
|
); |
4798 |
ckSCSL->WriteUint32(&fileOffset); |
ckSCSL->WriteUint32(&fileOffset); |
4799 |
// jump over flags entry (containing the bypass flag) |
// jump over flags entry (containing the bypass flag) |
4800 |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
4854 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
4855 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
4856 |
pRegions->push_back(pNewRegion); |
pRegions->push_back(pNewRegion); |
4857 |
Regions = pRegions->size(); |
Regions = (uint32_t) pRegions->size(); |
4858 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
4859 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
4860 |
// done |
// done |
5000 |
for (uint s = 0; group->GetScript(s); ++s) { |
for (uint s = 0; group->GetScript(s); ++s) { |
5001 |
Script* script = group->GetScript(s); |
Script* script = group->GetScript(s); |
5002 |
if (script->pChunk) { |
if (script->pChunk) { |
5003 |
uint32_t offset = script->pChunk->GetFilePos() - |
uint32_t offset = uint32_t( |
5004 |
script->pChunk->GetPos() - |
script->pChunk->GetFilePos() - |
5005 |
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()); |
script->pChunk->GetPos() - |
5006 |
|
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()) |
5007 |
|
); |
5008 |
if (offset == soughtOffset) |
if (offset == soughtOffset) |
5009 |
{ |
{ |
5010 |
_ScriptPooolRef ref; |
_ScriptPooolRef ref; |
5129 |
*/ |
*/ |
5130 |
void Instrument::RemoveScript(Script* pScript) { |
void Instrument::RemoveScript(Script* pScript) { |
5131 |
LoadScripts(); |
LoadScripts(); |
5132 |
for (int i = pScriptRefs->size() - 1; i >= 0; --i) { |
for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) { |
5133 |
if ((*pScriptRefs)[i].script == pScript) { |
if ((*pScriptRefs)[i].script == pScript) { |
5134 |
pScriptRefs->erase( pScriptRefs->begin() + i ); |
pScriptRefs->erase( pScriptRefs->begin() + i ); |
5135 |
} |
} |
5151 |
* gigedit. |
* gigedit. |
5152 |
*/ |
*/ |
5153 |
uint Instrument::ScriptSlotCount() const { |
uint Instrument::ScriptSlotCount() const { |
5154 |
return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size(); |
return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size()); |
5155 |
} |
} |
5156 |
|
|
5157 |
/** @brief Whether script execution shall be skipped. |
/** @brief Whether script execution shall be skipped. |
5575 |
} |
} |
5576 |
} |
} |
5577 |
String name(pRIFF->GetFileName()); |
String name(pRIFF->GetFileName()); |
5578 |
int nameLen = name.length(); |
int nameLen = (int) name.length(); |
5579 |
char suffix[6]; |
char suffix[6]; |
5580 |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
5581 |
|
|
5744 |
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
5745 |
mSamples[pFile->GetSample(i)] = s; |
mSamples[pFile->GetSample(i)] = s; |
5746 |
} |
} |
5747 |
|
|
5748 |
|
// clone script groups and their scripts |
5749 |
|
for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) { |
5750 |
|
ScriptGroup* sg = pFile->GetScriptGroup(iGroup); |
5751 |
|
ScriptGroup* dg = AddScriptGroup(); |
5752 |
|
dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name; |
5753 |
|
for (int iScript = 0; sg->GetScript(iScript); ++iScript) { |
5754 |
|
Script* ss = sg->GetScript(iScript); |
5755 |
|
Script* ds = dg->AddScript(); |
5756 |
|
ds->CopyAssign(ss); |
5757 |
|
} |
5758 |
|
} |
5759 |
|
|
5760 |
//BUG: For some reason this method only works with this additional |
//BUG: For some reason this method only works with this additional |
5761 |
// Save() call in between here. |
// Save() call in between here. |
5762 |
// |
// |
5903 |
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
5904 |
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
5905 |
|
|
5906 |
const int n = _3crc->GetNewSize() / 8; |
const file_offset_t n = _3crc->GetNewSize() / 8; |
5907 |
|
|
5908 |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
5909 |
if (!pData) return false; |
if (!pData) return false; |
5910 |
|
|
5911 |
for (int i = 0; i < n; ++i) { |
for (file_offset_t i = 0; i < n; ++i) { |
5912 |
uint32_t one = pData[i*2]; |
uint32_t one = pData[i*2]; |
5913 |
if (one != 1) return false; |
if (one != 1) return false; |
5914 |
} |
} |
6300 |
// Note that there are several fields with unknown use. These |
// Note that there are several fields with unknown use. These |
6301 |
// are set to zero. |
// are set to zero. |
6302 |
|
|
6303 |
int sublen = pSamples->size() / 8 + 49; |
int sublen = int(pSamples->size() / 8 + 49); |
6304 |
int einfSize = (Instruments + 1) * sublen; |
int einfSize = (Instruments + 1) * sublen; |
6305 |
|
|
6306 |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
6373 |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
6374 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6375 |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
6376 |
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size()); |
6377 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6378 |
|
|
6379 |
totnbregions += instrument->Regions; |
totnbregions += instrument->Regions; |
6391 |
store32(&pData[24], totnbloops); |
store32(&pData[24], totnbloops); |
6392 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6393 |
// next 4 bytes unknown, not always 0 |
// next 4 bytes unknown, not always 0 |
6394 |
store32(&pData[40], pSamples->size()); |
store32(&pData[40], (uint32_t) pSamples->size()); |
6395 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6396 |
} |
} |
6397 |
|
|
6473 |
// *************** Exception *************** |
// *************** Exception *************** |
6474 |
// * |
// * |
6475 |
|
|
6476 |
Exception::Exception(String Message) : DLS::Exception(Message) { |
Exception::Exception() : DLS::Exception() { |
6477 |
|
} |
6478 |
|
|
6479 |
|
Exception::Exception(String format, ...) : DLS::Exception() { |
6480 |
|
va_list arg; |
6481 |
|
va_start(arg, format); |
6482 |
|
Message = assemble(format, arg); |
6483 |
|
va_end(arg); |
6484 |
|
} |
6485 |
|
|
6486 |
|
Exception::Exception(String format, va_list arg) : DLS::Exception() { |
6487 |
|
Message = assemble(format, arg); |
6488 |
} |
} |
6489 |
|
|
6490 |
void Exception::PrintMessage() { |
void Exception::PrintMessage() { |