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 |
|
// *************** eg_opt_t *************** |
345 |
|
// * |
346 |
|
|
347 |
|
eg_opt_t::eg_opt_t() { |
348 |
|
AttackCancel = true; |
349 |
|
AttackHoldCancel = true; |
350 |
|
Decay1Cancel = true; |
351 |
|
Decay2Cancel = true; |
352 |
|
ReleaseCancel = true; |
353 |
|
} |
354 |
|
|
355 |
|
void eg_opt_t::serialize(Serialization::Archive* archive) { |
356 |
|
SRLZ(AttackCancel); |
357 |
|
SRLZ(AttackHoldCancel); |
358 |
|
SRLZ(Decay1Cancel); |
359 |
|
SRLZ(Decay2Cancel); |
360 |
|
SRLZ(ReleaseCancel); |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
|
|
365 |
// *************** Sample *************** |
// *************** Sample *************** |
366 |
// * |
// * |
367 |
|
|
1341 |
// if this is the last write, update the checksum chunk in the |
// if this is the last write, update the checksum chunk in the |
1342 |
// file |
// file |
1343 |
if (pCkData->GetPos() == pCkData->GetSize()) { |
if (pCkData->GetPos() == pCkData->GetSize()) { |
1344 |
|
__finalizeCRC(crc); |
1345 |
File* pFile = static_cast<File*>(GetParent()); |
File* pFile = static_cast<File*>(GetParent()); |
1346 |
pFile->SetSampleChecksum(this, __encodeCRC(crc)); |
pFile->SetSampleChecksum(this, crc); |
1347 |
} |
} |
1348 |
return res; |
return res; |
1349 |
} |
} |
1444 |
* @see GetWaveDataCRC32Checksum() |
* @see GetWaveDataCRC32Checksum() |
1445 |
*/ |
*/ |
1446 |
bool Sample::VerifyWaveData(uint32_t* pActually) { |
bool Sample::VerifyWaveData(uint32_t* pActually) { |
1447 |
File* pFile = static_cast<File*>(GetParent()); |
//File* pFile = static_cast<File*>(GetParent()); |
1448 |
uint32_t crc = CalculateWaveDataChecksum(); |
uint32_t crc = CalculateWaveDataChecksum(); |
1449 |
if (pActually) *pActually = crc; |
if (pActually) *pActually = crc; |
1450 |
return crc == this->crc; |
return crc == this->crc; |
1464 |
if (nRead <= 0) break; |
if (nRead <= 0) break; |
1465 |
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
1466 |
} |
} |
1467 |
__encodeCRC(crc); |
__finalizeCRC(crc); |
1468 |
return crc; |
return crc; |
1469 |
} |
} |
1470 |
|
|
1732 |
VCFType = vcf_type_lowpass; |
VCFType = vcf_type_lowpass; |
1733 |
memset(DimensionUpperLimits, 127, 8); |
memset(DimensionUpperLimits, 127, 8); |
1734 |
} |
} |
1735 |
|
// format extension for EG behavior options, these will *NOT* work with |
1736 |
|
// Gigasampler/GigaStudio ! |
1737 |
|
RIFF::Chunk* lsde = _3ewl->GetSubChunk(CHUNK_ID_LSDE); |
1738 |
|
if (lsde) { |
1739 |
|
unsigned char byte = lsde->ReadUint8(); |
1740 |
|
EGOptions.AttackCancel = byte & 1; |
1741 |
|
EGOptions.AttackHoldCancel = byte & (1 << 1); |
1742 |
|
EGOptions.Decay1Cancel = byte & (1 << 2); |
1743 |
|
EGOptions.Decay2Cancel = byte & (1 << 3); |
1744 |
|
EGOptions.ReleaseCancel = byte & (1 << 4); |
1745 |
|
} |
1746 |
|
|
1747 |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
1748 |
VelocityResponseDepth, |
VelocityResponseDepth, |
1848 |
} |
} |
1849 |
} |
} |
1850 |
|
|
1851 |
|
void DimensionRegion::serialize(Serialization::Archive* archive) { |
1852 |
|
// in case this class will become backward incompatible one day, |
1853 |
|
// then set a version and minimum version for this class like: |
1854 |
|
//archive->setVersion(*this, 2); |
1855 |
|
//archive->setMinVersion(*this, 1); |
1856 |
|
|
1857 |
|
SRLZ(VelocityUpperLimit); |
1858 |
|
SRLZ(EG1PreAttack); |
1859 |
|
SRLZ(EG1Attack); |
1860 |
|
SRLZ(EG1Decay1); |
1861 |
|
SRLZ(EG1Decay2); |
1862 |
|
SRLZ(EG1InfiniteSustain); |
1863 |
|
SRLZ(EG1Sustain); |
1864 |
|
SRLZ(EG1Release); |
1865 |
|
SRLZ(EG1Hold); |
1866 |
|
SRLZ(EG1Controller); |
1867 |
|
SRLZ(EG1ControllerInvert); |
1868 |
|
SRLZ(EG1ControllerAttackInfluence); |
1869 |
|
SRLZ(EG1ControllerDecayInfluence); |
1870 |
|
SRLZ(EG1ControllerReleaseInfluence); |
1871 |
|
SRLZ(LFO1Frequency); |
1872 |
|
SRLZ(LFO1InternalDepth); |
1873 |
|
SRLZ(LFO1ControlDepth); |
1874 |
|
SRLZ(LFO1Controller); |
1875 |
|
SRLZ(LFO1FlipPhase); |
1876 |
|
SRLZ(LFO1Sync); |
1877 |
|
SRLZ(EG2PreAttack); |
1878 |
|
SRLZ(EG2Attack); |
1879 |
|
SRLZ(EG2Decay1); |
1880 |
|
SRLZ(EG2Decay2); |
1881 |
|
SRLZ(EG2InfiniteSustain); |
1882 |
|
SRLZ(EG2Sustain); |
1883 |
|
SRLZ(EG2Release); |
1884 |
|
SRLZ(EG2Controller); |
1885 |
|
SRLZ(EG2ControllerInvert); |
1886 |
|
SRLZ(EG2ControllerAttackInfluence); |
1887 |
|
SRLZ(EG2ControllerDecayInfluence); |
1888 |
|
SRLZ(EG2ControllerReleaseInfluence); |
1889 |
|
SRLZ(LFO2Frequency); |
1890 |
|
SRLZ(LFO2InternalDepth); |
1891 |
|
SRLZ(LFO2ControlDepth); |
1892 |
|
SRLZ(LFO2Controller); |
1893 |
|
SRLZ(LFO2FlipPhase); |
1894 |
|
SRLZ(LFO2Sync); |
1895 |
|
SRLZ(EG3Attack); |
1896 |
|
SRLZ(EG3Depth); |
1897 |
|
SRLZ(LFO3Frequency); |
1898 |
|
SRLZ(LFO3InternalDepth); |
1899 |
|
SRLZ(LFO3ControlDepth); |
1900 |
|
SRLZ(LFO3Controller); |
1901 |
|
SRLZ(LFO3Sync); |
1902 |
|
SRLZ(VCFEnabled); |
1903 |
|
SRLZ(VCFType); |
1904 |
|
SRLZ(VCFCutoffController); |
1905 |
|
SRLZ(VCFCutoffControllerInvert); |
1906 |
|
SRLZ(VCFCutoff); |
1907 |
|
SRLZ(VCFVelocityCurve); |
1908 |
|
SRLZ(VCFVelocityScale); |
1909 |
|
SRLZ(VCFVelocityDynamicRange); |
1910 |
|
SRLZ(VCFResonance); |
1911 |
|
SRLZ(VCFResonanceDynamic); |
1912 |
|
SRLZ(VCFResonanceController); |
1913 |
|
SRLZ(VCFKeyboardTracking); |
1914 |
|
SRLZ(VCFKeyboardTrackingBreakpoint); |
1915 |
|
SRLZ(VelocityResponseCurve); |
1916 |
|
SRLZ(VelocityResponseDepth); |
1917 |
|
SRLZ(VelocityResponseCurveScaling); |
1918 |
|
SRLZ(ReleaseVelocityResponseCurve); |
1919 |
|
SRLZ(ReleaseVelocityResponseDepth); |
1920 |
|
SRLZ(ReleaseTriggerDecay); |
1921 |
|
SRLZ(Crossfade); |
1922 |
|
SRLZ(PitchTrack); |
1923 |
|
SRLZ(DimensionBypass); |
1924 |
|
SRLZ(Pan); |
1925 |
|
SRLZ(SelfMask); |
1926 |
|
SRLZ(AttenuationController); |
1927 |
|
SRLZ(InvertAttenuationController); |
1928 |
|
SRLZ(AttenuationControllerThreshold); |
1929 |
|
SRLZ(ChannelOffset); |
1930 |
|
SRLZ(SustainDefeat); |
1931 |
|
SRLZ(MSDecode); |
1932 |
|
//SRLZ(SampleStartOffset); |
1933 |
|
SRLZ(SampleAttenuation); |
1934 |
|
SRLZ(EGOptions); |
1935 |
|
|
1936 |
|
// derived attributes from DLS::Sampler |
1937 |
|
SRLZ(FineTune); |
1938 |
|
SRLZ(Gain); |
1939 |
|
} |
1940 |
|
|
1941 |
/** |
/** |
1942 |
* Updates the respective member variable and updates @c SampleAttenuation |
* Updates the respective member variable and updates @c SampleAttenuation |
1943 |
* which depends on this value. |
* which depends on this value. |
1978 |
|
|
1979 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1980 |
|
|
1981 |
const uint32_t chunksize = _3ewa->GetNewSize(); |
const uint32_t chunksize = (uint32_t) _3ewa->GetNewSize(); |
1982 |
store32(&pData[0], chunksize); // unknown, always chunk size? |
store32(&pData[0], chunksize); // unknown, always chunk size? |
1983 |
|
|
1984 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
2238 |
if (chunksize >= 148) { |
if (chunksize >= 148) { |
2239 |
memcpy(&pData[140], DimensionUpperLimits, 8); |
memcpy(&pData[140], DimensionUpperLimits, 8); |
2240 |
} |
} |
2241 |
|
|
2242 |
|
// format extension for EG behavior options, these will *NOT* work with |
2243 |
|
// Gigasampler/GigaStudio ! |
2244 |
|
RIFF::Chunk* lsde = pParentList->GetSubChunk(CHUNK_ID_LSDE); |
2245 |
|
if (!lsde) { |
2246 |
|
// only add this "LSDE" chunk if the EG options do not match the |
2247 |
|
// default EG behavior |
2248 |
|
eg_opt_t defaultOpt; |
2249 |
|
if (memcmp(&EGOptions, &defaultOpt, sizeof(eg_opt_t))) { |
2250 |
|
lsde = pParentList->AddSubChunk(CHUNK_ID_LSDE, 1); |
2251 |
|
// move LSDE chunk to the end of parent list |
2252 |
|
pParentList->MoveSubChunk(lsde, (RIFF::Chunk*)NULL); |
2253 |
|
} |
2254 |
|
} |
2255 |
|
if (lsde) { |
2256 |
|
unsigned char* pByte = (unsigned char*) lsde->LoadChunkData(); |
2257 |
|
*pByte = |
2258 |
|
(EGOptions.AttackCancel ? 1 : 0) | |
2259 |
|
(EGOptions.AttackHoldCancel ? (1<<1) : 0) | |
2260 |
|
(EGOptions.Decay1Cancel ? (1<<2) : 0) | |
2261 |
|
(EGOptions.Decay2Cancel ? (1<<3) : 0) | |
2262 |
|
(EGOptions.ReleaseCancel ? (1<<4) : 0); |
2263 |
|
} |
2264 |
} |
} |
2265 |
|
|
2266 |
double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { |
double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { |
2675 |
|
|
2676 |
// unknown controller type |
// unknown controller type |
2677 |
default: |
default: |
2678 |
throw gig::Exception("Unknown leverage controller type."); |
decodedcontroller.type = leverage_ctrl_t::type_none; |
2679 |
|
decodedcontroller.controller_number = 0; |
2680 |
|
printf("Warning: Unknown leverage controller type (0x%x).\n", EncodedController); |
2681 |
|
break; |
2682 |
} |
} |
2683 |
return decodedcontroller; |
return decodedcontroller; |
2684 |
} |
} |
3972 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
3973 |
uint8_t bits; |
uint8_t bits; |
3974 |
int veldim = -1; |
int veldim = -1; |
3975 |
int velbitpos; |
int velbitpos = 0; |
3976 |
int bitpos = 0; |
int bitpos = 0; |
3977 |
int dimregidx = 0; |
int dimregidx = 0; |
3978 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
4021 |
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
4022 |
uint8_t bits; |
uint8_t bits; |
4023 |
int veldim = -1; |
int veldim = -1; |
4024 |
int velbitpos; |
int velbitpos = 0; |
4025 |
int bitpos = 0; |
int bitpos = 0; |
4026 |
int dimregidx = 0; |
int dimregidx = 0; |
4027 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
4370 |
// to handle potential future extensions of the header |
// to handle potential future extensions of the header |
4371 |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4372 |
// read actual script data |
// read actual script data |
4373 |
uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos(); |
uint32_t scriptSize = uint32_t(ckScri->GetSize() - ckScri->GetPos()); |
4374 |
data.resize(scriptSize); |
data.resize(scriptSize); |
4375 |
for (int i = 0; i < scriptSize; ++i) |
for (int i = 0; i < scriptSize; ++i) |
4376 |
data[i] = ckScri->ReadUint8(); |
data[i] = ckScri->ReadUint8(); |
4421 |
// recalculate CRC32 check sum |
// recalculate CRC32 check sum |
4422 |
__resetCRC(crc); |
__resetCRC(crc); |
4423 |
__calculateCRC(&data[0], data.size(), crc); |
__calculateCRC(&data[0], data.size(), crc); |
4424 |
__encodeCRC(crc); |
__finalizeCRC(crc); |
4425 |
// make sure chunk exists and has the required size |
// make sure chunk exists and has the required size |
4426 |
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(); |
4427 |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
4428 |
else pChunk->Resize(chunkSize); |
else pChunk->Resize(chunkSize); |
4429 |
// fill the chunk data to be written to disk |
// fill the chunk data to be written to disk |
4430 |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
4431 |
int pos = 0; |
int pos = 0; |
4432 |
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 |
4433 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4434 |
store32(&pData[pos], Compression); |
store32(&pData[pos], Compression); |
4435 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4441 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4442 |
store32(&pData[pos], crc); |
store32(&pData[pos], crc); |
4443 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4444 |
store32(&pData[pos], Name.size()); |
store32(&pData[pos], (uint32_t) Name.size()); |
4445 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4446 |
for (int i = 0; i < Name.size(); ++i, ++pos) |
for (int i = 0; i < Name.size(); ++i, ++pos) |
4447 |
pData[pos] = Name[i]; |
pData[pos] = Name[i]; |
4472 |
return pGroup; |
return pGroup; |
4473 |
} |
} |
4474 |
|
|
4475 |
|
/** |
4476 |
|
* Make a (semi) deep copy of the Script object given by @a orig |
4477 |
|
* and assign it to this object. Note: the ScriptGroup this Script |
4478 |
|
* object belongs to remains untouched by this call. |
4479 |
|
* |
4480 |
|
* @param orig - original Script object to be copied from |
4481 |
|
*/ |
4482 |
|
void Script::CopyAssign(const Script* orig) { |
4483 |
|
Name = orig->Name; |
4484 |
|
Compression = orig->Compression; |
4485 |
|
Encoding = orig->Encoding; |
4486 |
|
Language = orig->Language; |
4487 |
|
Bypass = orig->Bypass; |
4488 |
|
data = orig->data; |
4489 |
|
} |
4490 |
|
|
4491 |
void Script::RemoveAllScriptReferences() { |
void Script::RemoveAllScriptReferences() { |
4492 |
File* pFile = pGroup->pFile; |
File* pFile = pGroup->pFile; |
4493 |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4634 |
EffectSend = 0; |
EffectSend = 0; |
4635 |
Attenuation = 0; |
Attenuation = 0; |
4636 |
FineTune = 0; |
FineTune = 0; |
4637 |
PitchbendRange = 0; |
PitchbendRange = 2; |
4638 |
PianoReleaseMode = false; |
PianoReleaseMode = false; |
4639 |
DimensionKeyRange.low = 0; |
DimensionKeyRange.low = 0; |
4640 |
DimensionKeyRange.high = 0; |
DimensionKeyRange.high = 0; |
4809 |
|
|
4810 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4811 |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
4812 |
const int slotCount = pScriptRefs->size(); |
const int slotCount = (int) pScriptRefs->size(); |
4813 |
const int headerSize = 3 * sizeof(uint32_t); |
const int headerSize = 3 * sizeof(uint32_t); |
4814 |
const int slotSize = 2 * sizeof(uint32_t); |
const int slotSize = 2 * sizeof(uint32_t); |
4815 |
const int totalChunkSize = headerSize + slotCount * slotSize; |
const int totalChunkSize = headerSize + slotCount * slotSize; |
4845 |
if (pScriptRefs && pScriptRefs->size() > 0) { |
if (pScriptRefs && pScriptRefs->size() > 0) { |
4846 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4847 |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4848 |
const int slotCount = pScriptRefs->size(); |
const int slotCount = (int) pScriptRefs->size(); |
4849 |
const int headerSize = 3 * sizeof(uint32_t); |
const int headerSize = 3 * sizeof(uint32_t); |
4850 |
ckSCSL->SetPos(headerSize); |
ckSCSL->SetPos(headerSize); |
4851 |
for (int i = 0; i < slotCount; ++i) { |
for (int i = 0; i < slotCount; ++i) { |
4852 |
uint32_t fileOffset = |
uint32_t fileOffset = uint32_t( |
4853 |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4854 |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4855 |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()); |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()) |
4856 |
|
); |
4857 |
ckSCSL->WriteUint32(&fileOffset); |
ckSCSL->WriteUint32(&fileOffset); |
4858 |
// jump over flags entry (containing the bypass flag) |
// jump over flags entry (containing the bypass flag) |
4859 |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
4913 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
4914 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
4915 |
pRegions->push_back(pNewRegion); |
pRegions->push_back(pNewRegion); |
4916 |
Regions = pRegions->size(); |
Regions = (uint32_t) pRegions->size(); |
4917 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
4918 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
4919 |
// done |
// done |
5059 |
for (uint s = 0; group->GetScript(s); ++s) { |
for (uint s = 0; group->GetScript(s); ++s) { |
5060 |
Script* script = group->GetScript(s); |
Script* script = group->GetScript(s); |
5061 |
if (script->pChunk) { |
if (script->pChunk) { |
5062 |
uint32_t offset = script->pChunk->GetFilePos() - |
uint32_t offset = uint32_t( |
5063 |
script->pChunk->GetPos() - |
script->pChunk->GetFilePos() - |
5064 |
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()); |
script->pChunk->GetPos() - |
5065 |
|
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()) |
5066 |
|
); |
5067 |
if (offset == soughtOffset) |
if (offset == soughtOffset) |
5068 |
{ |
{ |
5069 |
_ScriptPooolRef ref; |
_ScriptPooolRef ref; |
5188 |
*/ |
*/ |
5189 |
void Instrument::RemoveScript(Script* pScript) { |
void Instrument::RemoveScript(Script* pScript) { |
5190 |
LoadScripts(); |
LoadScripts(); |
5191 |
for (int i = pScriptRefs->size() - 1; i >= 0; --i) { |
for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) { |
5192 |
if ((*pScriptRefs)[i].script == pScript) { |
if ((*pScriptRefs)[i].script == pScript) { |
5193 |
pScriptRefs->erase( pScriptRefs->begin() + i ); |
pScriptRefs->erase( pScriptRefs->begin() + i ); |
5194 |
} |
} |
5210 |
* gigedit. |
* gigedit. |
5211 |
*/ |
*/ |
5212 |
uint Instrument::ScriptSlotCount() const { |
uint Instrument::ScriptSlotCount() const { |
5213 |
return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size(); |
return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size()); |
5214 |
} |
} |
5215 |
|
|
5216 |
/** @brief Whether script execution shall be skipped. |
/** @brief Whether script execution shall be skipped. |
5634 |
} |
} |
5635 |
} |
} |
5636 |
String name(pRIFF->GetFileName()); |
String name(pRIFF->GetFileName()); |
5637 |
int nameLen = name.length(); |
int nameLen = (int) name.length(); |
5638 |
char suffix[6]; |
char suffix[6]; |
5639 |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
5640 |
|
|
5803 |
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
5804 |
mSamples[pFile->GetSample(i)] = s; |
mSamples[pFile->GetSample(i)] = s; |
5805 |
} |
} |
5806 |
|
|
5807 |
|
// clone script groups and their scripts |
5808 |
|
for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) { |
5809 |
|
ScriptGroup* sg = pFile->GetScriptGroup(iGroup); |
5810 |
|
ScriptGroup* dg = AddScriptGroup(); |
5811 |
|
dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name; |
5812 |
|
for (int iScript = 0; sg->GetScript(iScript); ++iScript) { |
5813 |
|
Script* ss = sg->GetScript(iScript); |
5814 |
|
Script* ds = dg->AddScript(); |
5815 |
|
ds->CopyAssign(ss); |
5816 |
|
} |
5817 |
|
} |
5818 |
|
|
5819 |
//BUG: For some reason this method only works with this additional |
//BUG: For some reason this method only works with this additional |
5820 |
// Save() call in between here. |
// Save() call in between here. |
5821 |
// |
// |
5962 |
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
5963 |
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
5964 |
|
|
5965 |
const int n = _3crc->GetNewSize() / 8; |
const file_offset_t n = _3crc->GetNewSize() / 8; |
5966 |
|
|
5967 |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
5968 |
if (!pData) return false; |
if (!pData) return false; |
5969 |
|
|
5970 |
for (int i = 0; i < n; ++i) { |
for (file_offset_t i = 0; i < n; ++i) { |
5971 |
uint32_t one = pData[i*2]; |
uint32_t one = pData[i*2]; |
5972 |
if (one != 1) return false; |
if (one != 1) return false; |
5973 |
} |
} |
6359 |
// Note that there are several fields with unknown use. These |
// Note that there are several fields with unknown use. These |
6360 |
// are set to zero. |
// are set to zero. |
6361 |
|
|
6362 |
int sublen = pSamples->size() / 8 + 49; |
int sublen = int(pSamples->size() / 8 + 49); |
6363 |
int einfSize = (Instruments + 1) * sublen; |
int einfSize = (Instruments + 1) * sublen; |
6364 |
|
|
6365 |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
6432 |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
6433 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6434 |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
6435 |
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size()); |
6436 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6437 |
|
|
6438 |
totnbregions += instrument->Regions; |
totnbregions += instrument->Regions; |
6450 |
store32(&pData[24], totnbloops); |
store32(&pData[24], totnbloops); |
6451 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6452 |
// next 4 bytes unknown, not always 0 |
// next 4 bytes unknown, not always 0 |
6453 |
store32(&pData[40], pSamples->size()); |
store32(&pData[40], (uint32_t) pSamples->size()); |
6454 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6455 |
} |
} |
6456 |
|
|
6532 |
// *************** Exception *************** |
// *************** Exception *************** |
6533 |
// * |
// * |
6534 |
|
|
6535 |
Exception::Exception(String Message) : DLS::Exception(Message) { |
Exception::Exception() : DLS::Exception() { |
6536 |
|
} |
6537 |
|
|
6538 |
|
Exception::Exception(String format, ...) : DLS::Exception() { |
6539 |
|
va_list arg; |
6540 |
|
va_start(arg, format); |
6541 |
|
Message = assemble(format, arg); |
6542 |
|
va_end(arg); |
6543 |
|
} |
6544 |
|
|
6545 |
|
Exception::Exception(String format, va_list arg) : DLS::Exception() { |
6546 |
|
Message = assemble(format, arg); |
6547 |
} |
} |
6548 |
|
|
6549 |
void Exception::PrintMessage() { |
void Exception::PrintMessage() { |