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-2019 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 |
|
|
412 |
|
|
413 |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
414 |
if (pCk3gix) { |
if (pCk3gix) { |
415 |
|
pCk3gix->SetPos(0); |
416 |
|
|
417 |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
418 |
pGroup = pFile->GetGroup(iSampleGroup); |
pGroup = pFile->GetGroup(iSampleGroup); |
419 |
} else { // '3gix' chunk missing |
} else { // '3gix' chunk missing |
423 |
|
|
424 |
pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL); |
pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL); |
425 |
if (pCkSmpl) { |
if (pCkSmpl) { |
426 |
|
pCkSmpl->SetPos(0); |
427 |
|
|
428 |
Manufacturer = pCkSmpl->ReadInt32(); |
Manufacturer = pCkSmpl->ReadInt32(); |
429 |
Product = pCkSmpl->ReadInt32(); |
Product = pCkSmpl->ReadInt32(); |
430 |
SamplePeriod = pCkSmpl->ReadInt32(); |
SamplePeriod = pCkSmpl->ReadInt32(); |
471 |
Dithered = false; |
Dithered = false; |
472 |
TruncatedBits = 0; |
TruncatedBits = 0; |
473 |
if (Compressed) { |
if (Compressed) { |
474 |
|
ewav->SetPos(0); |
475 |
|
|
476 |
uint32_t version = ewav->ReadInt32(); |
uint32_t version = ewav->ReadInt32(); |
477 |
if (version == 3 && BitDepth == 24) { |
if (version > 2 && BitDepth == 24) { |
478 |
Dithered = ewav->ReadInt32(); |
Dithered = ewav->ReadInt32(); |
479 |
ewav->SetPos(Channels == 2 ? 84 : 64); |
ewav->SetPos(Channels == 2 ? 84 : 64); |
480 |
TruncatedBits = ewav->ReadInt32(); |
TruncatedBits = ewav->ReadInt32(); |
1347 |
// if this is the last write, update the checksum chunk in the |
// if this is the last write, update the checksum chunk in the |
1348 |
// file |
// file |
1349 |
if (pCkData->GetPos() == pCkData->GetSize()) { |
if (pCkData->GetPos() == pCkData->GetSize()) { |
1350 |
|
__finalizeCRC(crc); |
1351 |
File* pFile = static_cast<File*>(GetParent()); |
File* pFile = static_cast<File*>(GetParent()); |
1352 |
pFile->SetSampleChecksum(this, __encodeCRC(crc)); |
pFile->SetSampleChecksum(this, crc); |
1353 |
} |
} |
1354 |
return res; |
return res; |
1355 |
} |
} |
1450 |
* @see GetWaveDataCRC32Checksum() |
* @see GetWaveDataCRC32Checksum() |
1451 |
*/ |
*/ |
1452 |
bool Sample::VerifyWaveData(uint32_t* pActually) { |
bool Sample::VerifyWaveData(uint32_t* pActually) { |
1453 |
File* pFile = static_cast<File*>(GetParent()); |
//File* pFile = static_cast<File*>(GetParent()); |
1454 |
uint32_t crc = CalculateWaveDataChecksum(); |
uint32_t crc = CalculateWaveDataChecksum(); |
1455 |
if (pActually) *pActually = crc; |
if (pActually) *pActually = crc; |
1456 |
return crc == this->crc; |
return crc == this->crc; |
1470 |
if (nRead <= 0) break; |
if (nRead <= 0) break; |
1471 |
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
__calculateCRC(&buffer[0], nRead * FrameSize, crc); |
1472 |
} |
} |
1473 |
__encodeCRC(crc); |
__finalizeCRC(crc); |
1474 |
return crc; |
return crc; |
1475 |
} |
} |
1476 |
|
|
1506 |
|
|
1507 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
1508 |
if (_3ewa) { // if '3ewa' chunk exists |
if (_3ewa) { // if '3ewa' chunk exists |
1509 |
|
_3ewa->SetPos(0); |
1510 |
|
|
1511 |
_3ewa->ReadInt32(); // unknown, always == chunk size ? |
_3ewa->ReadInt32(); // unknown, always == chunk size ? |
1512 |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1513 |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1740 |
VCFType = vcf_type_lowpass; |
VCFType = vcf_type_lowpass; |
1741 |
memset(DimensionUpperLimits, 127, 8); |
memset(DimensionUpperLimits, 127, 8); |
1742 |
} |
} |
1743 |
|
// chunk for own format extensions, these will *NOT* work with Gigasampler/GigaStudio ! |
1744 |
|
RIFF::Chunk* lsde = _3ewl->GetSubChunk(CHUNK_ID_LSDE); |
1745 |
|
if (lsde) { // format extension for EG behavior options |
1746 |
|
lsde->SetPos(0); |
1747 |
|
|
1748 |
|
eg_opt_t* pEGOpts[2] = { &EG1Options, &EG2Options }; |
1749 |
|
for (int i = 0; i < 2; ++i) { // NOTE: we reserved a 3rd byte for a potential future EG3 option |
1750 |
|
unsigned char byte = lsde->ReadUint8(); |
1751 |
|
pEGOpts[i]->AttackCancel = byte & 1; |
1752 |
|
pEGOpts[i]->AttackHoldCancel = byte & (1 << 1); |
1753 |
|
pEGOpts[i]->Decay1Cancel = byte & (1 << 2); |
1754 |
|
pEGOpts[i]->Decay2Cancel = byte & (1 << 3); |
1755 |
|
pEGOpts[i]->ReleaseCancel = byte & (1 << 4); |
1756 |
|
} |
1757 |
|
} |
1758 |
|
// format extension for sustain pedal up effect on release trigger samples |
1759 |
|
if (lsde && lsde->GetSize() > 3) { // NOTE: we reserved the 3rd byte for a potential future EG3 option |
1760 |
|
lsde->SetPos(3); |
1761 |
|
uint8_t byte = lsde->ReadUint8(); |
1762 |
|
SustainReleaseTrigger = static_cast<sust_rel_trg_t>(byte & 0x03); |
1763 |
|
NoNoteOffReleaseTrigger = byte >> 7; |
1764 |
|
} else { |
1765 |
|
SustainReleaseTrigger = sust_rel_trg_none; |
1766 |
|
NoNoteOffReleaseTrigger = false; |
1767 |
|
} |
1768 |
|
|
1769 |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
1770 |
VelocityResponseDepth, |
VelocityResponseDepth, |
1870 |
} |
} |
1871 |
} |
} |
1872 |
|
|
1873 |
|
void DimensionRegion::serialize(Serialization::Archive* archive) { |
1874 |
|
// in case this class will become backward incompatible one day, |
1875 |
|
// then set a version and minimum version for this class like: |
1876 |
|
//archive->setVersion(*this, 2); |
1877 |
|
//archive->setMinVersion(*this, 1); |
1878 |
|
|
1879 |
|
SRLZ(VelocityUpperLimit); |
1880 |
|
SRLZ(EG1PreAttack); |
1881 |
|
SRLZ(EG1Attack); |
1882 |
|
SRLZ(EG1Decay1); |
1883 |
|
SRLZ(EG1Decay2); |
1884 |
|
SRLZ(EG1InfiniteSustain); |
1885 |
|
SRLZ(EG1Sustain); |
1886 |
|
SRLZ(EG1Release); |
1887 |
|
SRLZ(EG1Hold); |
1888 |
|
SRLZ(EG1Controller); |
1889 |
|
SRLZ(EG1ControllerInvert); |
1890 |
|
SRLZ(EG1ControllerAttackInfluence); |
1891 |
|
SRLZ(EG1ControllerDecayInfluence); |
1892 |
|
SRLZ(EG1ControllerReleaseInfluence); |
1893 |
|
SRLZ(LFO1Frequency); |
1894 |
|
SRLZ(LFO1InternalDepth); |
1895 |
|
SRLZ(LFO1ControlDepth); |
1896 |
|
SRLZ(LFO1Controller); |
1897 |
|
SRLZ(LFO1FlipPhase); |
1898 |
|
SRLZ(LFO1Sync); |
1899 |
|
SRLZ(EG2PreAttack); |
1900 |
|
SRLZ(EG2Attack); |
1901 |
|
SRLZ(EG2Decay1); |
1902 |
|
SRLZ(EG2Decay2); |
1903 |
|
SRLZ(EG2InfiniteSustain); |
1904 |
|
SRLZ(EG2Sustain); |
1905 |
|
SRLZ(EG2Release); |
1906 |
|
SRLZ(EG2Controller); |
1907 |
|
SRLZ(EG2ControllerInvert); |
1908 |
|
SRLZ(EG2ControllerAttackInfluence); |
1909 |
|
SRLZ(EG2ControllerDecayInfluence); |
1910 |
|
SRLZ(EG2ControllerReleaseInfluence); |
1911 |
|
SRLZ(LFO2Frequency); |
1912 |
|
SRLZ(LFO2InternalDepth); |
1913 |
|
SRLZ(LFO2ControlDepth); |
1914 |
|
SRLZ(LFO2Controller); |
1915 |
|
SRLZ(LFO2FlipPhase); |
1916 |
|
SRLZ(LFO2Sync); |
1917 |
|
SRLZ(EG3Attack); |
1918 |
|
SRLZ(EG3Depth); |
1919 |
|
SRLZ(LFO3Frequency); |
1920 |
|
SRLZ(LFO3InternalDepth); |
1921 |
|
SRLZ(LFO3ControlDepth); |
1922 |
|
SRLZ(LFO3Controller); |
1923 |
|
SRLZ(LFO3Sync); |
1924 |
|
SRLZ(VCFEnabled); |
1925 |
|
SRLZ(VCFType); |
1926 |
|
SRLZ(VCFCutoffController); |
1927 |
|
SRLZ(VCFCutoffControllerInvert); |
1928 |
|
SRLZ(VCFCutoff); |
1929 |
|
SRLZ(VCFVelocityCurve); |
1930 |
|
SRLZ(VCFVelocityScale); |
1931 |
|
SRLZ(VCFVelocityDynamicRange); |
1932 |
|
SRLZ(VCFResonance); |
1933 |
|
SRLZ(VCFResonanceDynamic); |
1934 |
|
SRLZ(VCFResonanceController); |
1935 |
|
SRLZ(VCFKeyboardTracking); |
1936 |
|
SRLZ(VCFKeyboardTrackingBreakpoint); |
1937 |
|
SRLZ(VelocityResponseCurve); |
1938 |
|
SRLZ(VelocityResponseDepth); |
1939 |
|
SRLZ(VelocityResponseCurveScaling); |
1940 |
|
SRLZ(ReleaseVelocityResponseCurve); |
1941 |
|
SRLZ(ReleaseVelocityResponseDepth); |
1942 |
|
SRLZ(ReleaseTriggerDecay); |
1943 |
|
SRLZ(Crossfade); |
1944 |
|
SRLZ(PitchTrack); |
1945 |
|
SRLZ(DimensionBypass); |
1946 |
|
SRLZ(Pan); |
1947 |
|
SRLZ(SelfMask); |
1948 |
|
SRLZ(AttenuationController); |
1949 |
|
SRLZ(InvertAttenuationController); |
1950 |
|
SRLZ(AttenuationControllerThreshold); |
1951 |
|
SRLZ(ChannelOffset); |
1952 |
|
SRLZ(SustainDefeat); |
1953 |
|
SRLZ(MSDecode); |
1954 |
|
//SRLZ(SampleStartOffset); |
1955 |
|
SRLZ(SampleAttenuation); |
1956 |
|
SRLZ(EG1Options); |
1957 |
|
SRLZ(EG2Options); |
1958 |
|
SRLZ(SustainReleaseTrigger); |
1959 |
|
SRLZ(NoNoteOffReleaseTrigger); |
1960 |
|
|
1961 |
|
// derived attributes from DLS::Sampler |
1962 |
|
SRLZ(FineTune); |
1963 |
|
SRLZ(Gain); |
1964 |
|
} |
1965 |
|
|
1966 |
/** |
/** |
1967 |
* Updates the respective member variable and updates @c SampleAttenuation |
* Updates the respective member variable and updates @c SampleAttenuation |
1968 |
* which depends on this value. |
* which depends on this value. |
1996 |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
1997 |
if (!_3ewa) { |
if (!_3ewa) { |
1998 |
File* pFile = (File*) GetParent()->GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent()->GetParent(); |
1999 |
bool version3 = pFile->pVersion && pFile->pVersion->major == 3; |
bool versiongt2 = pFile->pVersion && pFile->pVersion->major > 2; |
2000 |
_3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, version3 ? 148 : 140); |
_3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, versiongt2 ? 148 : 140); |
2001 |
} |
} |
2002 |
pData = (uint8_t*) _3ewa->LoadChunkData(); |
pData = (uint8_t*) _3ewa->LoadChunkData(); |
2003 |
|
|
2004 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
2005 |
|
|
2006 |
const uint32_t chunksize = _3ewa->GetNewSize(); |
const uint32_t chunksize = (uint32_t) _3ewa->GetNewSize(); |
2007 |
store32(&pData[0], chunksize); // unknown, always chunk size? |
store32(&pData[0], chunksize); // unknown, always chunk size? |
2008 |
|
|
2009 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
2263 |
if (chunksize >= 148) { |
if (chunksize >= 148) { |
2264 |
memcpy(&pData[140], DimensionUpperLimits, 8); |
memcpy(&pData[140], DimensionUpperLimits, 8); |
2265 |
} |
} |
2266 |
|
|
2267 |
|
// chunk for own format extensions, these will *NOT* work with |
2268 |
|
// Gigasampler/GigaStudio ! |
2269 |
|
RIFF::Chunk* lsde = pParentList->GetSubChunk(CHUNK_ID_LSDE); |
2270 |
|
const int lsdeSize = 4; // NOTE: we reserved the 3rd byte for a potential future EG3 option |
2271 |
|
if (!lsde) { |
2272 |
|
// only add this "LSDE" chunk if either EG options or release |
2273 |
|
// trigger options deviate from their default behaviour |
2274 |
|
eg_opt_t defaultOpt; |
2275 |
|
if (memcmp(&EG1Options, &defaultOpt, sizeof(eg_opt_t)) || |
2276 |
|
memcmp(&EG2Options, &defaultOpt, sizeof(eg_opt_t)) || |
2277 |
|
SustainReleaseTrigger || NoNoteOffReleaseTrigger) |
2278 |
|
{ |
2279 |
|
lsde = pParentList->AddSubChunk(CHUNK_ID_LSDE, lsdeSize); |
2280 |
|
// move LSDE chunk to the end of parent list |
2281 |
|
pParentList->MoveSubChunk(lsde, (RIFF::Chunk*)NULL); |
2282 |
|
} |
2283 |
|
} |
2284 |
|
if (lsde) { |
2285 |
|
if (lsde->GetNewSize() < lsdeSize) |
2286 |
|
lsde->Resize(lsdeSize); |
2287 |
|
// format extension for EG behavior options |
2288 |
|
unsigned char* pData = (unsigned char*) lsde->LoadChunkData(); |
2289 |
|
eg_opt_t* pEGOpts[2] = { &EG1Options, &EG2Options }; |
2290 |
|
for (int i = 0; i < 2; ++i) { // NOTE: we reserved the 3rd byte for a potential future EG3 option |
2291 |
|
pData[i] = |
2292 |
|
(pEGOpts[i]->AttackCancel ? 1 : 0) | |
2293 |
|
(pEGOpts[i]->AttackHoldCancel ? (1<<1) : 0) | |
2294 |
|
(pEGOpts[i]->Decay1Cancel ? (1<<2) : 0) | |
2295 |
|
(pEGOpts[i]->Decay2Cancel ? (1<<3) : 0) | |
2296 |
|
(pEGOpts[i]->ReleaseCancel ? (1<<4) : 0); |
2297 |
|
} |
2298 |
|
// format extension for release trigger options |
2299 |
|
pData[3] = static_cast<uint8_t>(SustainReleaseTrigger) | (NoNoteOffReleaseTrigger ? (1<<7) : 0); |
2300 |
|
} |
2301 |
} |
} |
2302 |
|
|
2303 |
double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { |
double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { |
2337 |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
2338 |
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
2339 |
{ |
{ |
2340 |
|
// sanity check input parameters |
2341 |
|
// (fallback to some default parameters on ill input) |
2342 |
|
switch (curveType) { |
2343 |
|
case curve_type_nonlinear: |
2344 |
|
case curve_type_linear: |
2345 |
|
if (depth > 4) { |
2346 |
|
printf("Warning: Invalid depth (0x%x) for velocity curve type (0x%x).\n", depth, curveType); |
2347 |
|
depth = 0; |
2348 |
|
scaling = 0; |
2349 |
|
} |
2350 |
|
break; |
2351 |
|
case curve_type_special: |
2352 |
|
if (depth > 5) { |
2353 |
|
printf("Warning: Invalid depth (0x%x) for velocity curve type 'special'.\n", depth); |
2354 |
|
depth = 0; |
2355 |
|
scaling = 0; |
2356 |
|
} |
2357 |
|
break; |
2358 |
|
case curve_type_unknown: |
2359 |
|
default: |
2360 |
|
printf("Warning: Unknown velocity curve type (0x%x).\n", curveType); |
2361 |
|
curveType = curve_type_linear; |
2362 |
|
depth = 0; |
2363 |
|
scaling = 0; |
2364 |
|
break; |
2365 |
|
} |
2366 |
|
|
2367 |
double* table; |
double* table; |
2368 |
uint32_t tableKey = (curveType<<16) | (depth<<8) | scaling; |
uint32_t tableKey = (curveType<<16) | (depth<<8) | scaling; |
2369 |
if (pVelocityTables->count(tableKey)) { // if key exists |
if (pVelocityTables->count(tableKey)) { // if key exists |
2739 |
|
|
2740 |
// unknown controller type |
// unknown controller type |
2741 |
default: |
default: |
2742 |
throw gig::Exception("Unknown leverage controller type."); |
decodedcontroller.type = leverage_ctrl_t::type_none; |
2743 |
|
decodedcontroller.controller_number = 0; |
2744 |
|
printf("Warning: Unknown leverage controller type (0x%x).\n", EncodedController); |
2745 |
|
break; |
2746 |
} |
} |
2747 |
return decodedcontroller; |
return decodedcontroller; |
2748 |
} |
} |
3236 |
} |
} |
3237 |
Layers = 1; |
Layers = 1; |
3238 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3239 |
int dimensionBits = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
int dimensionBits = (file->pVersion && file->pVersion->major > 2) ? 8 : 5; |
3240 |
|
|
3241 |
// Actual Loading |
// Actual Loading |
3242 |
|
|
3246 |
|
|
3247 |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
3248 |
if (_3lnk) { |
if (_3lnk) { |
3249 |
|
_3lnk->SetPos(0); |
3250 |
|
|
3251 |
DimensionRegions = _3lnk->ReadUint32(); |
DimensionRegions = _3lnk->ReadUint32(); |
3252 |
for (int i = 0; i < dimensionBits; i++) { |
for (int i = 0; i < dimensionBits; i++) { |
3253 |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
3282 |
UpdateVelocityTable(); |
UpdateVelocityTable(); |
3283 |
|
|
3284 |
// jump to start of the wave pool indices (if not already there) |
// jump to start of the wave pool indices (if not already there) |
3285 |
if (file->pVersion && file->pVersion->major == 3) |
if (file->pVersion && file->pVersion->major > 2) |
3286 |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
3287 |
else |
else |
3288 |
_3lnk->SetPos(44); |
_3lnk->SetPos(44); |
3291 |
if (file->GetAutoLoad()) { |
if (file->GetAutoLoad()) { |
3292 |
for (uint i = 0; i < DimensionRegions; i++) { |
for (uint i = 0; i < DimensionRegions; i++) { |
3293 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
3294 |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
if (file->pWavePoolTable && pDimensionRegions[i]) |
3295 |
|
pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
3296 |
} |
} |
3297 |
GetSample(); // load global region sample reference |
GetSample(); // load global region sample reference |
3298 |
} |
} |
3341 |
} |
} |
3342 |
|
|
3343 |
File* pFile = (File*) GetParent()->GetParent(); |
File* pFile = (File*) GetParent()->GetParent(); |
3344 |
bool version3 = pFile->pVersion && pFile->pVersion->major == 3; |
bool versiongt2 = pFile->pVersion && pFile->pVersion->major > 2; |
3345 |
const int iMaxDimensions = version3 ? 8 : 5; |
const int iMaxDimensions = versiongt2 ? 8 : 5; |
3346 |
const int iMaxDimensionRegions = version3 ? 256 : 32; |
const int iMaxDimensionRegions = versiongt2 ? 256 : 32; |
3347 |
|
|
3348 |
// make sure '3lnk' chunk exists |
// make sure '3lnk' chunk exists |
3349 |
RIFF::Chunk* _3lnk = pCkRegion->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = pCkRegion->GetSubChunk(CHUNK_ID_3LNK); |
3350 |
if (!_3lnk) { |
if (!_3lnk) { |
3351 |
const int _3lnkChunkSize = version3 ? 1092 : 172; |
const int _3lnkChunkSize = versiongt2 ? 1092 : 172; |
3352 |
_3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); |
_3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); |
3353 |
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
3354 |
|
|
3372 |
} |
} |
3373 |
|
|
3374 |
// update wave pool table in '3lnk' chunk |
// update wave pool table in '3lnk' chunk |
3375 |
const int iWavePoolOffset = version3 ? 68 : 44; |
const int iWavePoolOffset = versiongt2 ? 68 : 44; |
3376 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
3377 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
3378 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
3515 |
|
|
3516 |
// check if max. amount of dimensions reached |
// check if max. amount of dimensions reached |
3517 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3518 |
const int iMaxDimensions = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensions = (file->pVersion && file->pVersion->major > 2) ? 8 : 5; |
3519 |
if (Dimensions >= iMaxDimensions) |
if (Dimensions >= iMaxDimensions) |
3520 |
throw gig::Exception("Could not add new dimension, max. amount of " + ToString(iMaxDimensions) + " dimensions already reached"); |
throw gig::Exception("Could not add new dimension, max. amount of " + ToString(iMaxDimensions) + " dimensions already reached"); |
3521 |
// check if max. amount of dimension bits reached |
// check if max. amount of dimension bits reached |
3807 |
} |
} |
3808 |
|
|
3809 |
// delete temporary region |
// delete temporary region |
3810 |
|
tempRgn->DeleteChunks(); |
3811 |
delete tempRgn; |
delete tempRgn; |
3812 |
|
|
3813 |
UpdateVelocityTable(); |
UpdateVelocityTable(); |
3947 |
} |
} |
3948 |
|
|
3949 |
// delete temporary region |
// delete temporary region |
3950 |
|
tempRgn->DeleteChunks(); |
3951 |
delete tempRgn; |
delete tempRgn; |
3952 |
|
|
3953 |
UpdateVelocityTable(); |
UpdateVelocityTable(); |
4041 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
4042 |
uint8_t bits; |
uint8_t bits; |
4043 |
int veldim = -1; |
int veldim = -1; |
4044 |
int velbitpos; |
int velbitpos = 0; |
4045 |
int bitpos = 0; |
int bitpos = 0; |
4046 |
int dimregidx = 0; |
int dimregidx = 0; |
4047 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
4090 |
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
4091 |
uint8_t bits; |
uint8_t bits; |
4092 |
int veldim = -1; |
int veldim = -1; |
4093 |
int velbitpos; |
int velbitpos = 0; |
4094 |
int bitpos = 0; |
int bitpos = 0; |
4095 |
int dimregidx = 0; |
int dimregidx = 0; |
4096 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
4175 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
4176 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
4177 |
if (!file->pWavePoolTable) return NULL; |
if (!file->pWavePoolTable) return NULL; |
4178 |
|
if (WavePoolTableIndex + 1 > file->WavePoolCount) return NULL; |
4179 |
// for new files or files >= 2 GB use 64 bit wave pool offsets |
// for new files or files >= 2 GB use 64 bit wave pool offsets |
4180 |
if (file->pRIFF->IsNew() || (file->pRIFF->GetCurrentFileSize() >> 31)) { |
if (file->pRIFF->IsNew() || (file->pRIFF->GetCurrentFileSize() >> 31)) { |
4181 |
// use 64 bit wave pool offsets (treating this as large file) |
// use 64 bit wave pool offsets (treating this as large file) |
4426 |
pGroup = group; |
pGroup = group; |
4427 |
pChunk = ckScri; |
pChunk = ckScri; |
4428 |
if (ckScri) { // object is loaded from file ... |
if (ckScri) { // object is loaded from file ... |
4429 |
|
ckScri->SetPos(0); |
4430 |
|
|
4431 |
// read header |
// read header |
4432 |
uint32_t headerSize = ckScri->ReadUint32(); |
uint32_t headerSize = ckScri->ReadUint32(); |
4433 |
Compression = (Compression_t) ckScri->ReadUint32(); |
Compression = (Compression_t) ckScri->ReadUint32(); |
4442 |
// to handle potential future extensions of the header |
// to handle potential future extensions of the header |
4443 |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4444 |
// read actual script data |
// read actual script data |
4445 |
uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos(); |
uint32_t scriptSize = uint32_t(ckScri->GetSize() - ckScri->GetPos()); |
4446 |
data.resize(scriptSize); |
data.resize(scriptSize); |
4447 |
for (int i = 0; i < scriptSize; ++i) |
for (int i = 0; i < scriptSize; ++i) |
4448 |
data[i] = ckScri->ReadUint8(); |
data[i] = ckScri->ReadUint8(); |
4480 |
memcpy(&data[0], &text[0], text.size()); |
memcpy(&data[0], &text[0], text.size()); |
4481 |
} |
} |
4482 |
|
|
4483 |
|
/** @brief Remove all RIFF chunks associated with this Script object. |
4484 |
|
* |
4485 |
|
* At the moment Script::DeleteChunks() does nothing. It is |
4486 |
|
* recommended to call this method explicitly though from deriving classes's |
4487 |
|
* own overridden implementation of this method to avoid potential future |
4488 |
|
* compatiblity issues. |
4489 |
|
* |
4490 |
|
* See DLS::Storage::DeleteChunks() for details. |
4491 |
|
*/ |
4492 |
|
void Script::DeleteChunks() { |
4493 |
|
} |
4494 |
|
|
4495 |
/** |
/** |
4496 |
* Apply this script to the respective RIFF chunks. You have to call |
* Apply this script to the respective RIFF chunks. You have to call |
4497 |
* File::Save() to make changes persistent. |
* File::Save() to make changes persistent. |
4505 |
// recalculate CRC32 check sum |
// recalculate CRC32 check sum |
4506 |
__resetCRC(crc); |
__resetCRC(crc); |
4507 |
__calculateCRC(&data[0], data.size(), crc); |
__calculateCRC(&data[0], data.size(), crc); |
4508 |
__encodeCRC(crc); |
__finalizeCRC(crc); |
4509 |
// make sure chunk exists and has the required size |
// make sure chunk exists and has the required size |
4510 |
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(); |
4511 |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
4512 |
else pChunk->Resize(chunkSize); |
else pChunk->Resize(chunkSize); |
4513 |
// fill the chunk data to be written to disk |
// fill the chunk data to be written to disk |
4514 |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
4515 |
int pos = 0; |
int pos = 0; |
4516 |
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 |
4517 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4518 |
store32(&pData[pos], Compression); |
store32(&pData[pos], Compression); |
4519 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4525 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4526 |
store32(&pData[pos], crc); |
store32(&pData[pos], crc); |
4527 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4528 |
store32(&pData[pos], Name.size()); |
store32(&pData[pos], (uint32_t) Name.size()); |
4529 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4530 |
for (int i = 0; i < Name.size(); ++i, ++pos) |
for (int i = 0; i < Name.size(); ++i, ++pos) |
4531 |
pData[pos] = Name[i]; |
pData[pos] = Name[i]; |
4556 |
return pGroup; |
return pGroup; |
4557 |
} |
} |
4558 |
|
|
4559 |
|
/** |
4560 |
|
* Make a (semi) deep copy of the Script object given by @a orig |
4561 |
|
* and assign it to this object. Note: the ScriptGroup this Script |
4562 |
|
* object belongs to remains untouched by this call. |
4563 |
|
* |
4564 |
|
* @param orig - original Script object to be copied from |
4565 |
|
*/ |
4566 |
|
void Script::CopyAssign(const Script* orig) { |
4567 |
|
Name = orig->Name; |
4568 |
|
Compression = orig->Compression; |
4569 |
|
Encoding = orig->Encoding; |
4570 |
|
Language = orig->Language; |
4571 |
|
Bypass = orig->Bypass; |
4572 |
|
data = orig->data; |
4573 |
|
} |
4574 |
|
|
4575 |
void Script::RemoveAllScriptReferences() { |
void Script::RemoveAllScriptReferences() { |
4576 |
File* pFile = pGroup->pFile; |
File* pFile = pGroup->pFile; |
4577 |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4607 |
} |
} |
4608 |
} |
} |
4609 |
|
|
4610 |
|
/** @brief Remove all RIFF chunks associated with this ScriptGroup object. |
4611 |
|
* |
4612 |
|
* At the moment ScriptGroup::DeleteChunks() does nothing. It is |
4613 |
|
* recommended to call this method explicitly though from deriving classes's |
4614 |
|
* own overridden implementation of this method to avoid potential future |
4615 |
|
* compatiblity issues. |
4616 |
|
* |
4617 |
|
* See DLS::Storage::DeleteChunks() for details. |
4618 |
|
*/ |
4619 |
|
void ScriptGroup::DeleteChunks() { |
4620 |
|
} |
4621 |
|
|
4622 |
/** |
/** |
4623 |
* Apply this script group to the respective RIFF chunks. You have to call |
* Apply this script group to the respective RIFF chunks. You have to call |
4624 |
* File::Save() to make changes persistent. |
* File::Save() to make changes persistent. |
4730 |
EffectSend = 0; |
EffectSend = 0; |
4731 |
Attenuation = 0; |
Attenuation = 0; |
4732 |
FineTune = 0; |
FineTune = 0; |
4733 |
PitchbendRange = 0; |
PitchbendRange = 2; |
4734 |
PianoReleaseMode = false; |
PianoReleaseMode = false; |
4735 |
DimensionKeyRange.low = 0; |
DimensionKeyRange.low = 0; |
4736 |
DimensionKeyRange.high = 0; |
DimensionKeyRange.high = 0; |
4743 |
if (lart) { |
if (lart) { |
4744 |
RIFF::Chunk* _3ewg = lart->GetSubChunk(CHUNK_ID_3EWG); |
RIFF::Chunk* _3ewg = lart->GetSubChunk(CHUNK_ID_3EWG); |
4745 |
if (_3ewg) { |
if (_3ewg) { |
4746 |
|
_3ewg->SetPos(0); |
4747 |
|
|
4748 |
EffectSend = _3ewg->ReadUint16(); |
EffectSend = _3ewg->ReadUint16(); |
4749 |
Attenuation = _3ewg->ReadInt32(); |
Attenuation = _3ewg->ReadInt32(); |
4750 |
FineTune = _3ewg->ReadInt16(); |
FineTune = _3ewg->ReadInt16(); |
4804 |
if (lst3LS) { |
if (lst3LS) { |
4805 |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4806 |
if (ckSCSL) { |
if (ckSCSL) { |
4807 |
|
ckSCSL->SetPos(0); |
4808 |
|
|
4809 |
int headerSize = ckSCSL->ReadUint32(); |
int headerSize = ckSCSL->ReadUint32(); |
4810 |
int slotCount = ckSCSL->ReadUint32(); |
int slotCount = ckSCSL->ReadUint32(); |
4811 |
if (slotCount) { |
if (slotCount) { |
4832 |
RegionList::iterator end = pRegions->end(); |
RegionList::iterator end = pRegions->end(); |
4833 |
for (; iter != end; ++iter) { |
for (; iter != end; ++iter) { |
4834 |
gig::Region* pRegion = static_cast<gig::Region*>(*iter); |
gig::Region* pRegion = static_cast<gig::Region*>(*iter); |
4835 |
for (int iKey = pRegion->KeyRange.low; iKey <= pRegion->KeyRange.high; iKey++) { |
const int low = std::max(int(pRegion->KeyRange.low), 0); |
4836 |
|
const int high = std::min(int(pRegion->KeyRange.high), 127); |
4837 |
|
for (int iKey = low; iKey <= high; iKey++) { |
4838 |
RegionKeyTable[iKey] = pRegion; |
RegionKeyTable[iKey] = pRegion; |
4839 |
} |
} |
4840 |
} |
} |
4879 |
File* pFile = (File*) GetParent(); |
File* pFile = (File*) GetParent(); |
4880 |
|
|
4881 |
// 3ewg is bigger in gig3, as it includes the iMIDI rules |
// 3ewg is bigger in gig3, as it includes the iMIDI rules |
4882 |
int size = (pFile->pVersion && pFile->pVersion->major == 3) ? 16416 : 12; |
int size = (pFile->pVersion && pFile->pVersion->major > 2) ? 16416 : 12; |
4883 |
_3ewg = lart->AddSubChunk(CHUNK_ID_3EWG, size); |
_3ewg = lart->AddSubChunk(CHUNK_ID_3EWG, size); |
4884 |
memset(_3ewg->LoadChunkData(), 0, size); |
memset(_3ewg->LoadChunkData(), 0, size); |
4885 |
} |
} |
4911 |
|
|
4912 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4913 |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
4914 |
const int slotCount = pScriptRefs->size(); |
const int slotCount = (int) pScriptRefs->size(); |
4915 |
const int headerSize = 3 * sizeof(uint32_t); |
const int headerSize = 3 * sizeof(uint32_t); |
4916 |
const int slotSize = 2 * sizeof(uint32_t); |
const int slotSize = 2 * sizeof(uint32_t); |
4917 |
const int totalChunkSize = headerSize + slotCount * slotSize; |
const int totalChunkSize = headerSize + slotCount * slotSize; |
4947 |
if (pScriptRefs && pScriptRefs->size() > 0) { |
if (pScriptRefs && pScriptRefs->size() > 0) { |
4948 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4949 |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4950 |
const int slotCount = pScriptRefs->size(); |
const int slotCount = (int) pScriptRefs->size(); |
4951 |
const int headerSize = 3 * sizeof(uint32_t); |
const int headerSize = 3 * sizeof(uint32_t); |
4952 |
ckSCSL->SetPos(headerSize); |
ckSCSL->SetPos(headerSize); |
4953 |
for (int i = 0; i < slotCount; ++i) { |
for (int i = 0; i < slotCount; ++i) { |
4954 |
uint32_t fileOffset = |
uint32_t fileOffset = uint32_t( |
4955 |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4956 |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4957 |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()); |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()) |
4958 |
|
); |
4959 |
ckSCSL->WriteUint32(&fileOffset); |
ckSCSL->WriteUint32(&fileOffset); |
4960 |
// jump over flags entry (containing the bypass flag) |
// jump over flags entry (containing the bypass flag) |
4961 |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
5015 |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN); |
5016 |
Region* pNewRegion = new Region(this, rgn); |
Region* pNewRegion = new Region(this, rgn); |
5017 |
pRegions->push_back(pNewRegion); |
pRegions->push_back(pNewRegion); |
5018 |
Regions = pRegions->size(); |
Regions = (uint32_t) pRegions->size(); |
5019 |
// update Region key table for fast lookup |
// update Region key table for fast lookup |
5020 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
5021 |
// done |
// done |
5161 |
for (uint s = 0; group->GetScript(s); ++s) { |
for (uint s = 0; group->GetScript(s); ++s) { |
5162 |
Script* script = group->GetScript(s); |
Script* script = group->GetScript(s); |
5163 |
if (script->pChunk) { |
if (script->pChunk) { |
5164 |
uint32_t offset = script->pChunk->GetFilePos() - |
uint32_t offset = uint32_t( |
5165 |
script->pChunk->GetPos() - |
script->pChunk->GetFilePos() - |
5166 |
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()); |
script->pChunk->GetPos() - |
5167 |
|
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()) |
5168 |
|
); |
5169 |
if (offset == soughtOffset) |
if (offset == soughtOffset) |
5170 |
{ |
{ |
5171 |
_ScriptPooolRef ref; |
_ScriptPooolRef ref; |
5290 |
*/ |
*/ |
5291 |
void Instrument::RemoveScript(Script* pScript) { |
void Instrument::RemoveScript(Script* pScript) { |
5292 |
LoadScripts(); |
LoadScripts(); |
5293 |
for (int i = pScriptRefs->size() - 1; i >= 0; --i) { |
for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) { |
5294 |
if ((*pScriptRefs)[i].script == pScript) { |
if ((*pScriptRefs)[i].script == pScript) { |
5295 |
pScriptRefs->erase( pScriptRefs->begin() + i ); |
pScriptRefs->erase( pScriptRefs->begin() + i ); |
5296 |
} |
} |
5312 |
* gigedit. |
* gigedit. |
5313 |
*/ |
*/ |
5314 |
uint Instrument::ScriptSlotCount() const { |
uint Instrument::ScriptSlotCount() const { |
5315 |
return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size(); |
return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size()); |
5316 |
} |
} |
5317 |
|
|
5318 |
/** @brief Whether script execution shall be skipped. |
/** @brief Whether script execution shall be skipped. |
5436 |
::LoadString(pNameChunk, Name); |
::LoadString(pNameChunk, Name); |
5437 |
} |
} |
5438 |
|
|
5439 |
|
/** @brief Destructor. |
5440 |
|
* |
5441 |
|
* Currently this destructor implementation does nothing. |
5442 |
|
*/ |
5443 |
Group::~Group() { |
Group::~Group() { |
5444 |
// remove the chunk associated with this group (if any) |
} |
5445 |
if (pNameChunk) pNameChunk->GetParent()->DeleteSubChunk(pNameChunk); |
|
5446 |
|
/** @brief Remove all RIFF chunks associated with this Group object. |
5447 |
|
* |
5448 |
|
* See DLS::Storage::DeleteChunks() for details. |
5449 |
|
*/ |
5450 |
|
void Group::DeleteChunks() { |
5451 |
|
// handle own RIFF chunks |
5452 |
|
if (pNameChunk) { |
5453 |
|
pNameChunk->GetParent()->DeleteSubChunk(pNameChunk); |
5454 |
|
pNameChunk = NULL; |
5455 |
|
} |
5456 |
} |
} |
5457 |
|
|
5458 |
/** @brief Update chunks with current group settings. |
/** @brief Update chunks with current group settings. |
5475 |
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
5476 |
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
5477 |
|
|
5478 |
if (!pNameChunk && pFile->pVersion && pFile->pVersion->major == 3) { |
if (!pNameChunk && pFile->pVersion && pFile->pVersion->major > 2) { |
5479 |
// v3 has a fixed list of 128 strings, find a free one |
// v3 has a fixed list of 128 strings, find a free one |
5480 |
for (RIFF::Chunk* ck = _3gnl->GetFirstSubChunk() ; ck ; ck = _3gnl->GetNextSubChunk()) { |
for (RIFF::Chunk* ck = _3gnl->GetFirstSubChunk() ; ck ; ck = _3gnl->GetNextSubChunk()) { |
5481 |
if (strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) { |
if (strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) { |
5570 |
0, 3, 20030331 & 0xffff, 20030331 >> 16 |
0, 3, 20030331 & 0xffff, 20030331 >> 16 |
5571 |
}; |
}; |
5572 |
|
|
5573 |
|
/// Reflects Gigasampler file format version 4.0 (2007-10-12). |
5574 |
|
const DLS::version_t File::VERSION_4 = { |
5575 |
|
0, 4, 20071012 & 0xffff, 20071012 >> 16 |
5576 |
|
}; |
5577 |
|
|
5578 |
static const DLS::Info::string_length_t _FileFixedStringLengths[] = { |
static const DLS::Info::string_length_t _FileFixedStringLengths[] = { |
5579 |
{ CHUNK_ID_IARL, 256 }, |
{ CHUNK_ID_IARL, 256 }, |
5580 |
{ CHUNK_ID_IART, 128 }, |
{ CHUNK_ID_IART, 128 }, |
5671 |
return static_cast<gig::Sample*>( *it ); |
return static_cast<gig::Sample*>( *it ); |
5672 |
} |
} |
5673 |
|
|
5674 |
|
/** |
5675 |
|
* Returns the total amount of samples of this gig file. |
5676 |
|
* |
5677 |
|
* Note that this method might block for a long time in case it is required |
5678 |
|
* to load the sample info for the first time. |
5679 |
|
* |
5680 |
|
* @returns total amount of samples |
5681 |
|
*/ |
5682 |
|
size_t File::CountSamples() { |
5683 |
|
if (!pSamples) LoadSamples(); |
5684 |
|
if (!pSamples) return 0; |
5685 |
|
return pSamples->size(); |
5686 |
|
} |
5687 |
|
|
5688 |
/** @brief Add a new sample. |
/** @brief Add a new sample. |
5689 |
* |
* |
5690 |
* This will create a new Sample object for the gig file. You have to |
* This will create a new Sample object for the gig file. You have to |
5723 |
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"); |
5724 |
if (SamplesIterator != pSamples->end() && *SamplesIterator == pSample) ++SamplesIterator; // avoid iterator invalidation |
if (SamplesIterator != pSamples->end() && *SamplesIterator == pSample) ++SamplesIterator; // avoid iterator invalidation |
5725 |
pSamples->erase(iter); |
pSamples->erase(iter); |
5726 |
|
pSample->DeleteChunks(); |
5727 |
delete pSample; |
delete pSample; |
5728 |
|
|
5729 |
SampleList::iterator tmp = SamplesIterator; |
SampleList::iterator tmp = SamplesIterator; |
5761 |
int iSampleIndex = 0; |
int iSampleIndex = 0; |
5762 |
int iTotalSamples = WavePoolCount; |
int iTotalSamples = WavePoolCount; |
5763 |
|
|
5764 |
// check if samples should be loaded from extension files |
// just for assembling path of optional extension files to be read |
5765 |
// (only for old gig files < 2 GB) |
const std::string folder = parentPath(pRIFF->GetFileName()); |
5766 |
int lastFileNo = 0; |
const std::string baseName = pathWithoutExtension(pRIFF->GetFileName()); |
5767 |
if (!file->IsNew() && !(file->GetCurrentFileSize() >> 31)) { |
|
5768 |
for (int i = 0 ; i < WavePoolCount ; i++) { |
// the main gig file and the extension files (.gx01, ... , .gx98) may |
5769 |
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
// contain wave data (wave pool) |
5770 |
} |
std::vector<RIFF::File*> poolFiles; |
5771 |
} |
poolFiles.push_back(pRIFF); |
5772 |
String name(pRIFF->GetFileName()); |
|
5773 |
int nameLen = name.length(); |
// get info about all extension files |
5774 |
char suffix[6]; |
RIFF::Chunk* ckXfil = pRIFF->GetSubChunk(CHUNK_ID_XFIL); |
5775 |
if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4; |
if (ckXfil) { // there are extension files (.gx01, ... , .gx98) ... |
5776 |
|
const uint32_t n = ckXfil->ReadInt32(); |
5777 |
for (int fileNo = 0 ; ; ) { |
for (int i = 0; i < n; i++) { |
5778 |
|
// read the filename and load the extension file |
5779 |
|
std::string name; |
5780 |
|
ckXfil->ReadString(name, 128); |
5781 |
|
std::string path = concatPath(folder, name); |
5782 |
|
RIFF::File* pExtFile = new RIFF::File(path); |
5783 |
|
// check that the dlsids match |
5784 |
|
RIFF::Chunk* ckDLSID = pExtFile->GetSubChunk(CHUNK_ID_DLID); |
5785 |
|
if (ckDLSID) { |
5786 |
|
::DLS::dlsid_t idExpected; |
5787 |
|
idExpected.ulData1 = ckXfil->ReadInt32(); |
5788 |
|
idExpected.usData2 = ckXfil->ReadInt16(); |
5789 |
|
idExpected.usData3 = ckXfil->ReadInt16(); |
5790 |
|
ckXfil->Read(idExpected.abData, 8, 1); |
5791 |
|
::DLS::dlsid_t idFound; |
5792 |
|
ckDLSID->Read(&idFound.ulData1, 1, 4); |
5793 |
|
ckDLSID->Read(&idFound.usData2, 1, 2); |
5794 |
|
ckDLSID->Read(&idFound.usData3, 1, 2); |
5795 |
|
ckDLSID->Read(idFound.abData, 8, 1); |
5796 |
|
if (memcmp(&idExpected, &idFound, 16) != 0) |
5797 |
|
throw gig::Exception("dlsid mismatch for extension file: %s", path.c_str()); |
5798 |
|
} |
5799 |
|
poolFiles.push_back(pExtFile); |
5800 |
|
ExtensionFiles.push_back(pExtFile); |
5801 |
|
} |
5802 |
|
} |
5803 |
|
|
5804 |
|
// check if a .gx99 (GigaPulse) file exists |
5805 |
|
RIFF::Chunk* ckDoxf = pRIFF->GetSubChunk(CHUNK_ID_DOXF); |
5806 |
|
if (ckDoxf) { // there is a .gx99 (GigaPulse) file ... |
5807 |
|
std::string path = baseName + ".gx99"; |
5808 |
|
RIFF::File* pExtFile = new RIFF::File(path); |
5809 |
|
|
5810 |
|
// skip unused int and filename |
5811 |
|
ckDoxf->SetPos(132, RIFF::stream_curpos); |
5812 |
|
|
5813 |
|
// check that the dlsids match |
5814 |
|
RIFF::Chunk* ckDLSID = pExtFile->GetSubChunk(CHUNK_ID_DLID); |
5815 |
|
if (ckDLSID) { |
5816 |
|
::DLS::dlsid_t idExpected; |
5817 |
|
idExpected.ulData1 = ckDoxf->ReadInt32(); |
5818 |
|
idExpected.usData2 = ckDoxf->ReadInt16(); |
5819 |
|
idExpected.usData3 = ckDoxf->ReadInt16(); |
5820 |
|
ckDoxf->Read(idExpected.abData, 8, 1); |
5821 |
|
::DLS::dlsid_t idFound; |
5822 |
|
ckDLSID->Read(&idFound.ulData1, 1, 4); |
5823 |
|
ckDLSID->Read(&idFound.usData2, 1, 2); |
5824 |
|
ckDLSID->Read(&idFound.usData3, 1, 2); |
5825 |
|
ckDLSID->Read(idFound.abData, 8, 1); |
5826 |
|
if (memcmp(&idExpected, &idFound, 16) != 0) |
5827 |
|
throw gig::Exception("dlsid mismatch for GigaPulse file: %s", path.c_str()); |
5828 |
|
} |
5829 |
|
poolFiles.push_back(pExtFile); |
5830 |
|
ExtensionFiles.push_back(pExtFile); |
5831 |
|
} |
5832 |
|
|
5833 |
|
// load samples from extension files (if required) |
5834 |
|
for (int i = 0; i < poolFiles.size(); i++) { |
5835 |
|
RIFF::File* file = poolFiles[i]; |
5836 |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
5837 |
if (wvpl) { |
if (wvpl) { |
5838 |
file_offset_t wvplFileOffset = wvpl->GetFilePos(); |
file_offset_t wvplFileOffset = wvpl->GetFilePos() - |
5839 |
|
wvpl->GetPos(); // should be zero, but just to be sure |
5840 |
RIFF::List* wave = wvpl->GetFirstSubList(); |
RIFF::List* wave = wvpl->GetFirstSubList(); |
5841 |
while (wave) { |
while (wave) { |
5842 |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
5845 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
5846 |
|
|
5847 |
file_offset_t waveFileOffset = wave->GetFilePos(); |
file_offset_t waveFileOffset = wave->GetFilePos(); |
5848 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo, iSampleIndex)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, i, iSampleIndex)); |
5849 |
|
|
5850 |
iSampleIndex++; |
iSampleIndex++; |
5851 |
} |
} |
5852 |
wave = wvpl->GetNextSubList(); |
wave = wvpl->GetNextSubList(); |
5853 |
} |
} |
5854 |
|
} |
|
if (fileNo == lastFileNo) break; |
|
|
|
|
|
// open extension file (*.gx01, *.gx02, ...) |
|
|
fileNo++; |
|
|
sprintf(suffix, ".gx%02d", fileNo); |
|
|
name.replace(nameLen, 5, suffix); |
|
|
file = new RIFF::File(name); |
|
|
ExtensionFiles.push_back(file); |
|
|
} else break; |
|
5855 |
} |
} |
5856 |
|
|
5857 |
__notify_progress(pProgress, 1.0); // notify done |
__notify_progress(pProgress, 1.0); // notify done |
5871 |
} |
} |
5872 |
|
|
5873 |
/** |
/** |
5874 |
|
* Returns the total amount of instruments of this gig file. |
5875 |
|
* |
5876 |
|
* Note that this method might block for a long time in case it is required |
5877 |
|
* to load the instruments info for the first time. |
5878 |
|
* |
5879 |
|
* @returns total amount of instruments |
5880 |
|
*/ |
5881 |
|
size_t File::CountInstruments() { |
5882 |
|
if (!pInstruments) LoadInstruments(); |
5883 |
|
if (!pInstruments) return 0; |
5884 |
|
return pInstruments->size(); |
5885 |
|
} |
5886 |
|
|
5887 |
|
/** |
5888 |
* Returns the instrument with the given index. |
* Returns the instrument with the given index. |
5889 |
* |
* |
5890 |
* @param index - number of the sought instrument (0..n) |
* @param index - number of the sought instrument (0..n) |
6003 |
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
6004 |
mSamples[pFile->GetSample(i)] = s; |
mSamples[pFile->GetSample(i)] = s; |
6005 |
} |
} |
6006 |
|
|
6007 |
|
// clone script groups and their scripts |
6008 |
|
for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) { |
6009 |
|
ScriptGroup* sg = pFile->GetScriptGroup(iGroup); |
6010 |
|
ScriptGroup* dg = AddScriptGroup(); |
6011 |
|
dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name; |
6012 |
|
for (int iScript = 0; sg->GetScript(iScript); ++iScript) { |
6013 |
|
Script* ss = sg->GetScript(iScript); |
6014 |
|
Script* ds = dg->AddScript(); |
6015 |
|
ds->CopyAssign(ss); |
6016 |
|
} |
6017 |
|
} |
6018 |
|
|
6019 |
//BUG: For some reason this method only works with this additional |
//BUG: For some reason this method only works with this additional |
6020 |
// Save() call in between here. |
// Save() call in between here. |
6021 |
// |
// |
6059 |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); |
InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); |
6060 |
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"); |
6061 |
pInstruments->erase(iter); |
pInstruments->erase(iter); |
6062 |
|
pInstrument->DeleteChunks(); |
6063 |
delete pInstrument; |
delete pInstrument; |
6064 |
} |
} |
6065 |
|
|
6163 |
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned |
6164 |
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
if (_3crc->GetNewSize() != pSamples->size() * 8) return false; |
6165 |
|
|
6166 |
const int n = _3crc->GetNewSize() / 8; |
const file_offset_t n = _3crc->GetNewSize() / 8; |
6167 |
|
|
6168 |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
6169 |
if (!pData) return false; |
if (!pData) return false; |
6170 |
|
|
6171 |
for (int i = 0; i < n; ++i) { |
for (file_offset_t i = 0; i < n; ++i) { |
6172 |
uint32_t one = pData[i*2]; |
uint32_t one = pData[i*2]; |
6173 |
if (one != 1) return false; |
if (one != 1) return false; |
6174 |
} |
} |
6204 |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
6205 |
// the order of einf and 3crc is not the same in v2 and v3 |
// the order of einf and 3crc is not the same in v2 and v3 |
6206 |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
6207 |
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
if (einf && pVersion && pVersion->major > 2) pRIFF->MoveSubChunk(_3crc, einf); |
6208 |
bRequiresSave = true; |
bRequiresSave = true; |
6209 |
} else if (_3crc->GetNewSize() != pSamples->size() * 8) { |
} else if (_3crc->GetNewSize() != pSamples->size() * 8) { |
6210 |
_3crc->Resize(pSamples->size() * 8); |
_3crc->Resize(pSamples->size() * 8); |
6319 |
} |
} |
6320 |
// now delete this group object |
// now delete this group object |
6321 |
pGroups->erase(iter); |
pGroups->erase(iter); |
6322 |
|
pGroup->DeleteChunks(); |
6323 |
delete pGroup; |
delete pGroup; |
6324 |
} |
} |
6325 |
|
|
6341 |
// move all members of this group to another group |
// move all members of this group to another group |
6342 |
pGroup->MoveAll(); |
pGroup->MoveAll(); |
6343 |
pGroups->erase(iter); |
pGroups->erase(iter); |
6344 |
|
pGroup->DeleteChunks(); |
6345 |
delete pGroup; |
delete pGroup; |
6346 |
} |
} |
6347 |
|
|
6355 |
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
6356 |
while (ck) { |
while (ck) { |
6357 |
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
6358 |
if (pVersion && pVersion->major == 3 && |
if (pVersion && pVersion->major > 2 && |
6359 |
strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) break; |
strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) break; |
6360 |
|
|
6361 |
pGroups->push_back(new Group(this, ck)); |
pGroups->push_back(new Group(this, ck)); |
6441 |
pScriptGroup->DeleteScript(pScriptGroup->GetScript(i)); |
pScriptGroup->DeleteScript(pScriptGroup->GetScript(i)); |
6442 |
if (pScriptGroup->pList) |
if (pScriptGroup->pList) |
6443 |
pScriptGroup->pList->GetParent()->DeleteSubChunk(pScriptGroup->pList); |
pScriptGroup->pList->GetParent()->DeleteSubChunk(pScriptGroup->pList); |
6444 |
|
pScriptGroup->DeleteChunks(); |
6445 |
delete pScriptGroup; |
delete pScriptGroup; |
6446 |
} |
} |
6447 |
|
|
6532 |
|
|
6533 |
// v3: make sure the file has 128 3gnm chunks |
// v3: make sure the file has 128 3gnm chunks |
6534 |
// (before updating the Group chunks) |
// (before updating the Group chunks) |
6535 |
if (pVersion && pVersion->major == 3) { |
if (pVersion && pVersion->major > 2) { |
6536 |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
6537 |
for (int i = 0 ; i < 128 ; i++) { |
for (int i = 0 ; i < 128 ; i++) { |
6538 |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
6563 |
// Note that there are several fields with unknown use. These |
// Note that there are several fields with unknown use. These |
6564 |
// are set to zero. |
// are set to zero. |
6565 |
|
|
6566 |
int sublen = pSamples->size() / 8 + 49; |
int sublen = int(pSamples->size() / 8 + 49); |
6567 |
int einfSize = (Instruments + 1) * sublen; |
int einfSize = (Instruments + 1) * sublen; |
6568 |
|
|
6569 |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF); |
6636 |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
6637 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6638 |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
6639 |
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size()); |
6640 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6641 |
|
|
6642 |
totnbregions += instrument->Regions; |
totnbregions += instrument->Regions; |
6654 |
store32(&pData[24], totnbloops); |
store32(&pData[24], totnbloops); |
6655 |
// next 8 bytes unknown |
// next 8 bytes unknown |
6656 |
// next 4 bytes unknown, not always 0 |
// next 4 bytes unknown, not always 0 |
6657 |
store32(&pData[40], pSamples->size()); |
store32(&pData[40], (uint32_t) pSamples->size()); |
6658 |
// next 4 bytes unknown |
// next 4 bytes unknown |
6659 |
} |
} |
6660 |
|
|
6678 |
} else /*if (newFile)*/ { |
} else /*if (newFile)*/ { |
6679 |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
6680 |
// the order of einf and 3crc is not the same in v2 and v3 |
// the order of einf and 3crc is not the same in v2 and v3 |
6681 |
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
if (einf && pVersion && pVersion->major > 2) pRIFF->MoveSubChunk(_3crc, einf); |
6682 |
} |
} |
6683 |
{ // must be performed in RAM here ... |
{ // must be performed in RAM here ... |
6684 |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
uint32_t* pData = (uint32_t*) _3crc->LoadChunkData(); |
6705 |
} |
} |
6706 |
|
|
6707 |
/** |
/** |
6708 |
* Enable / disable automatic loading. By default this properyt is |
* Enable / disable automatic loading. By default this property is |
6709 |
* enabled and all informations are loaded automatically. However |
* enabled and every information is loaded automatically. However |
6710 |
* loading all Regions, DimensionRegions and especially samples might |
* loading all Regions, DimensionRegions and especially samples might |
6711 |
* take a long time for large .gig files, and sometimes one might only |
* take a long time for large .gig files, and sometimes one might only |
6712 |
* be interested in retrieving very superficial informations like the |
* be interested in retrieving very superficial informations like the |
6714 |
* automatic loading to avoid very slow response times. |
* automatic loading to avoid very slow response times. |
6715 |
* |
* |
6716 |
* @e CAUTION: by disabling this property many pointers (i.e. sample |
* @e CAUTION: by disabling this property many pointers (i.e. sample |
6717 |
* references) and informations will have invalid or even undefined |
* references) and attributes will have invalid or even undefined |
6718 |
* data! This feature is currently only intended for retrieving very |
* data! This feature is currently only intended for retrieving very |
6719 |
* superficial informations in a very fast way. Don't use it to retrieve |
* superficial information in a very fast way. Don't use it to retrieve |
6720 |
* details like synthesis informations or even to modify .gig files! |
* details like synthesis information or even to modify .gig files! |
6721 |
*/ |
*/ |
6722 |
void File::SetAutoLoad(bool b) { |
void File::SetAutoLoad(bool b) { |
6723 |
bAutoLoad = b; |
bAutoLoad = b; |
6736 |
// *************** Exception *************** |
// *************** Exception *************** |
6737 |
// * |
// * |
6738 |
|
|
6739 |
Exception::Exception(String Message) : DLS::Exception(Message) { |
Exception::Exception() : DLS::Exception() { |
6740 |
|
} |
6741 |
|
|
6742 |
|
Exception::Exception(String format, ...) : DLS::Exception() { |
6743 |
|
va_list arg; |
6744 |
|
va_start(arg, format); |
6745 |
|
Message = assemble(format, arg); |
6746 |
|
va_end(arg); |
6747 |
|
} |
6748 |
|
|
6749 |
|
Exception::Exception(String format, va_list arg) : DLS::Exception() { |
6750 |
|
Message = assemble(format, arg); |
6751 |
} |
} |
6752 |
|
|
6753 |
void Exception::PrintMessage() { |
void Exception::PrintMessage() { |