1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file loader library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2005 by Christian Schoenebeck * |
* Copyright (C) 2003-2007 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 * |
279 |
* is located, 0 otherwise |
* is located, 0 otherwise |
280 |
*/ |
*/ |
281 |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
282 |
|
pInfo->UseFixedLengthStrings = true; |
283 |
Instances++; |
Instances++; |
284 |
FileNo = fileNo; |
FileNo = fileNo; |
285 |
|
|
286 |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
287 |
if (pCk3gix) { |
if (pCk3gix) { |
288 |
SampleGroup = pCk3gix->ReadInt16(); |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
289 |
|
pGroup = pFile->GetGroup(iSampleGroup); |
290 |
} else { // '3gix' chunk missing |
} else { // '3gix' chunk missing |
291 |
// use default value(s) |
// by default assigned to that mandatory "Default Group" |
292 |
SampleGroup = 0; |
pGroup = pFile->GetGroup(0); |
293 |
} |
} |
294 |
|
|
295 |
pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL); |
pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL); |
313 |
// use default values |
// use default values |
314 |
Manufacturer = 0; |
Manufacturer = 0; |
315 |
Product = 0; |
Product = 0; |
316 |
SamplePeriod = 1 / SamplesPerSecond; |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
317 |
MIDIUnityNote = 64; |
MIDIUnityNote = 64; |
318 |
FineTune = 0; |
FineTune = 0; |
319 |
SMPTEOffset = 0; |
SMPTEOffset = 0; |
364 |
* Usually there is absolutely no need to call this method explicitly. |
* Usually there is absolutely no need to call this method explicitly. |
365 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
366 |
* |
* |
367 |
* @throws DLS::Exception if FormatTag != WAVE_FORMAT_PCM or no sample data |
* @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data |
368 |
* was provided yet |
* was provided yet |
369 |
* @throws gig::Exception if there is any invalid sample setting |
* @throws gig::Exception if there is any invalid sample setting |
370 |
*/ |
*/ |
377 |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); |
378 |
// update 'smpl' chunk |
// update 'smpl' chunk |
379 |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); |
380 |
SamplePeriod = 1 / SamplesPerSecond; |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
381 |
memcpy(&pData[0], &Manufacturer, 4); |
memcpy(&pData[0], &Manufacturer, 4); |
382 |
memcpy(&pData[4], &Product, 4); |
memcpy(&pData[4], &Product, 4); |
383 |
memcpy(&pData[8], &SamplePeriod, 4); |
memcpy(&pData[8], &SamplePeriod, 4); |
399 |
// make sure '3gix' chunk exists |
// make sure '3gix' chunk exists |
400 |
pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX); |
401 |
if (!pCk3gix) pCk3gix = pWaveList->AddSubChunk(CHUNK_ID_3GIX, 4); |
if (!pCk3gix) pCk3gix = pWaveList->AddSubChunk(CHUNK_ID_3GIX, 4); |
402 |
|
// determine appropriate sample group index (to be stored in chunk) |
403 |
|
uint16_t iSampleGroup = 0; // 0 refers to default sample group |
404 |
|
File* pFile = static_cast<File*>(pParent); |
405 |
|
if (pFile->pGroups) { |
406 |
|
std::list<Group*>::iterator iter = pFile->pGroups->begin(); |
407 |
|
std::list<Group*>::iterator end = pFile->pGroups->end(); |
408 |
|
for (int i = 0; iter != end; i++, iter++) { |
409 |
|
if (*iter == pGroup) { |
410 |
|
iSampleGroup = i; |
411 |
|
break; // found |
412 |
|
} |
413 |
|
} |
414 |
|
} |
415 |
// update '3gix' chunk |
// update '3gix' chunk |
416 |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
417 |
memcpy(&pData[0], &SampleGroup, 2); |
memcpy(&pData[0], &iSampleGroup, 2); |
418 |
} |
} |
419 |
|
|
420 |
/// Scans compressed samples for mandatory informations (e.g. actual number of total sample points). |
/// Scans compressed samples for mandatory informations (e.g. actual number of total sample points). |
635 |
* enlarged samples before calling File::Save() as this might exceed the |
* enlarged samples before calling File::Save() as this might exceed the |
636 |
* current sample's boundary! |
* current sample's boundary! |
637 |
* |
* |
638 |
* Also note: only WAVE_FORMAT_PCM is currently supported, that is |
* Also note: only DLS_WAVE_FORMAT_PCM is currently supported, that is |
639 |
* FormatTag must be WAVE_FORMAT_PCM. Trying to resize samples with |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
640 |
* other formats will fail! |
* other formats will fail! |
641 |
* |
* |
642 |
* @param iNewSize - new sample wave data size in sample points (must be |
* @param iNewSize - new sample wave data size in sample points (must be |
643 |
* greater than zero) |
* greater than zero) |
644 |
* @throws DLS::Excecption if FormatTag != WAVE_FORMAT_PCM |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
645 |
* or if \a iNewSize is less than 1 |
* or if \a iNewSize is less than 1 |
646 |
* @throws gig::Exception if existing sample is compressed |
* @throws gig::Exception if existing sample is compressed |
647 |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
1152 |
} |
} |
1153 |
} |
} |
1154 |
|
|
1155 |
|
/** |
1156 |
|
* Returns pointer to the Group this Sample belongs to. In the .gig |
1157 |
|
* format a sample always belongs to one group. If it wasn't explicitly |
1158 |
|
* assigned to a certain group, it will be automatically assigned to a |
1159 |
|
* default group. |
1160 |
|
* |
1161 |
|
* @returns Sample's Group (never NULL) |
1162 |
|
*/ |
1163 |
|
Group* Sample::GetGroup() const { |
1164 |
|
return pGroup; |
1165 |
|
} |
1166 |
|
|
1167 |
Sample::~Sample() { |
Sample::~Sample() { |
1168 |
Instances--; |
Instances--; |
1169 |
if (!Instances && InternalDecompressionBuffer.Size) { |
if (!Instances && InternalDecompressionBuffer.Size) { |
1193 |
|
|
1194 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
1195 |
if (_3ewa) { // if '3ewa' chunk exists |
if (_3ewa) { // if '3ewa' chunk exists |
1196 |
_3ewa->ReadInt32(); // unknown, always 0x0000008C ? |
_3ewa->ReadInt32(); // unknown, always == chunk size ? |
1197 |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1198 |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
EG3Attack = (double) GIG_EXP_DECODE(_3ewa->ReadInt32()); |
1199 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1473 |
|
|
1474 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1475 |
|
|
1476 |
const uint32_t unknown = 0x0000008C; // unknown, always 0x0000008C ? |
const uint32_t unknown = _3ewa->GetSize(); // unknown, always chunk size ? |
1477 |
memcpy(&pData[0], &unknown, 4); |
memcpy(&pData[0], &unknown, 4); |
1478 |
|
|
1479 |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); |
1480 |
memcpy(&pData[4], &lfo3freq, 4); |
memcpy(&pData[4], &lfo3freq, 4); |
1481 |
|
|
1482 |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack); |
1483 |
memcpy(&pData[4], &eg3attack, 4); |
memcpy(&pData[8], &eg3attack, 4); |
1484 |
|
|
1485 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1486 |
|
|
1487 |
memcpy(&pData[10], &LFO1InternalDepth, 2); |
memcpy(&pData[14], &LFO1InternalDepth, 2); |
1488 |
|
|
1489 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1490 |
|
|
1491 |
memcpy(&pData[14], &LFO3InternalDepth, 2); |
memcpy(&pData[18], &LFO3InternalDepth, 2); |
1492 |
|
|
1493 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1494 |
|
|
1495 |
memcpy(&pData[18], &LFO1ControlDepth, 2); |
memcpy(&pData[22], &LFO1ControlDepth, 2); |
1496 |
|
|
1497 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1498 |
|
|
1499 |
memcpy(&pData[22], &LFO3ControlDepth, 2); |
memcpy(&pData[26], &LFO3ControlDepth, 2); |
1500 |
|
|
1501 |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack); |
1502 |
memcpy(&pData[24], &eg1attack, 4); |
memcpy(&pData[28], &eg1attack, 4); |
1503 |
|
|
1504 |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1); |
1505 |
memcpy(&pData[28], &eg1decay1, 4); |
memcpy(&pData[32], &eg1decay1, 4); |
1506 |
|
|
1507 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1508 |
|
|
1509 |
memcpy(&pData[34], &EG1Sustain, 2); |
memcpy(&pData[38], &EG1Sustain, 2); |
1510 |
|
|
1511 |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release); |
1512 |
memcpy(&pData[36], &eg1release, 4); |
memcpy(&pData[40], &eg1release, 4); |
1513 |
|
|
1514 |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller); |
1515 |
memcpy(&pData[40], &eg1ctl, 1); |
memcpy(&pData[44], &eg1ctl, 1); |
1516 |
|
|
1517 |
const uint8_t eg1ctrloptions = |
const uint8_t eg1ctrloptions = |
1518 |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
1519 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
1520 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
1521 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
1522 |
memcpy(&pData[41], &eg1ctrloptions, 1); |
memcpy(&pData[45], &eg1ctrloptions, 1); |
1523 |
|
|
1524 |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller); |
1525 |
memcpy(&pData[42], &eg2ctl, 1); |
memcpy(&pData[46], &eg2ctl, 1); |
1526 |
|
|
1527 |
const uint8_t eg2ctrloptions = |
const uint8_t eg2ctrloptions = |
1528 |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
1529 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
1530 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
1531 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
1532 |
memcpy(&pData[43], &eg2ctrloptions, 1); |
memcpy(&pData[47], &eg2ctrloptions, 1); |
1533 |
|
|
1534 |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency); |
1535 |
memcpy(&pData[44], &lfo1freq, 4); |
memcpy(&pData[48], &lfo1freq, 4); |
1536 |
|
|
1537 |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack); |
1538 |
memcpy(&pData[48], &eg2attack, 4); |
memcpy(&pData[52], &eg2attack, 4); |
1539 |
|
|
1540 |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1); |
1541 |
memcpy(&pData[52], &eg2decay1, 4); |
memcpy(&pData[56], &eg2decay1, 4); |
1542 |
|
|
1543 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1544 |
|
|
1545 |
memcpy(&pData[58], &EG2Sustain, 2); |
memcpy(&pData[62], &EG2Sustain, 2); |
1546 |
|
|
1547 |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release); |
1548 |
memcpy(&pData[60], &eg2release, 4); |
memcpy(&pData[64], &eg2release, 4); |
1549 |
|
|
1550 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1551 |
|
|
1552 |
memcpy(&pData[66], &LFO2ControlDepth, 2); |
memcpy(&pData[70], &LFO2ControlDepth, 2); |
1553 |
|
|
1554 |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency); |
1555 |
memcpy(&pData[68], &lfo2freq, 4); |
memcpy(&pData[72], &lfo2freq, 4); |
1556 |
|
|
1557 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1558 |
|
|
1559 |
memcpy(&pData[72], &LFO2InternalDepth, 2); |
memcpy(&pData[78], &LFO2InternalDepth, 2); |
1560 |
|
|
1561 |
const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2); |
const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2); |
1562 |
memcpy(&pData[74], &eg1decay2, 4); |
memcpy(&pData[80], &eg1decay2, 4); |
1563 |
|
|
1564 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1565 |
|
|
1566 |
memcpy(&pData[80], &EG1PreAttack, 2); |
memcpy(&pData[86], &EG1PreAttack, 2); |
1567 |
|
|
1568 |
const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2); |
const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2); |
1569 |
memcpy(&pData[82], &eg2decay2, 4); |
memcpy(&pData[88], &eg2decay2, 4); |
1570 |
|
|
1571 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1572 |
|
|
1573 |
memcpy(&pData[88], &EG2PreAttack, 2); |
memcpy(&pData[94], &EG2PreAttack, 2); |
1574 |
|
|
1575 |
{ |
{ |
1576 |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4"); |
1588 |
default: |
default: |
1589 |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected"); |
1590 |
} |
} |
1591 |
memcpy(&pData[90], &velocityresponse, 1); |
memcpy(&pData[96], &velocityresponse, 1); |
1592 |
} |
} |
1593 |
|
|
1594 |
{ |
{ |
1607 |
default: |
default: |
1608 |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected"); |
1609 |
} |
} |
1610 |
memcpy(&pData[91], &releasevelocityresponse, 1); |
memcpy(&pData[97], &releasevelocityresponse, 1); |
1611 |
} |
} |
1612 |
|
|
1613 |
memcpy(&pData[92], &VelocityResponseCurveScaling, 1); |
memcpy(&pData[98], &VelocityResponseCurveScaling, 1); |
1614 |
|
|
1615 |
memcpy(&pData[93], &AttenuationControllerThreshold, 1); |
memcpy(&pData[99], &AttenuationControllerThreshold, 1); |
1616 |
|
|
1617 |
// next 4 bytes unknown |
// next 4 bytes unknown |
1618 |
|
|
1619 |
memcpy(&pData[98], &SampleStartOffset, 2); |
memcpy(&pData[104], &SampleStartOffset, 2); |
1620 |
|
|
1621 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1622 |
|
|
1635 |
default: |
default: |
1636 |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected"); |
1637 |
} |
} |
1638 |
memcpy(&pData[102], &pitchTrackDimensionBypass, 1); |
memcpy(&pData[108], &pitchTrackDimensionBypass, 1); |
1639 |
} |
} |
1640 |
|
|
1641 |
const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit |
const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit |
1642 |
memcpy(&pData[103], &pan, 1); |
memcpy(&pData[109], &pan, 1); |
1643 |
|
|
1644 |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00; |
1645 |
memcpy(&pData[104], &selfmask, 1); |
memcpy(&pData[110], &selfmask, 1); |
1646 |
|
|
1647 |
// next byte unknown |
// next byte unknown |
1648 |
|
|
1651 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5 |
1652 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7 |
1653 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6 |
1654 |
memcpy(&pData[106], &lfo3ctrl, 1); |
memcpy(&pData[112], &lfo3ctrl, 1); |
1655 |
} |
} |
1656 |
|
|
1657 |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
const uint8_t attenctl = EncodeLeverageController(AttenuationController); |
1658 |
memcpy(&pData[107], &attenctl, 1); |
memcpy(&pData[113], &attenctl, 1); |
1659 |
|
|
1660 |
{ |
{ |
1661 |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits |
1662 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7 |
1663 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
if (LFO2Sync) lfo2ctrl |= 0x20; // bit 5 |
1664 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6 |
1665 |
memcpy(&pData[108], &lfo2ctrl, 1); |
memcpy(&pData[114], &lfo2ctrl, 1); |
1666 |
} |
} |
1667 |
|
|
1668 |
{ |
{ |
1671 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
if (LFO1Sync) lfo1ctrl |= 0x40; // bit 6 |
1672 |
if (VCFResonanceController != vcf_res_ctrl_none) |
if (VCFResonanceController != vcf_res_ctrl_none) |
1673 |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController); |
1674 |
memcpy(&pData[109], &lfo1ctrl, 1); |
memcpy(&pData[115], &lfo1ctrl, 1); |
1675 |
} |
} |
1676 |
|
|
1677 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
1678 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
1679 |
memcpy(&pData[110], &eg3depth, 1); |
memcpy(&pData[116], &eg3depth, 1); |
1680 |
|
|
1681 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1682 |
|
|
1683 |
const uint8_t channeloffset = ChannelOffset * 4; |
const uint8_t channeloffset = ChannelOffset * 4; |
1684 |
memcpy(&pData[113], &channeloffset, 1); |
memcpy(&pData[120], &channeloffset, 1); |
1685 |
|
|
1686 |
{ |
{ |
1687 |
uint8_t regoptions = 0; |
uint8_t regoptions = 0; |
1688 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
if (MSDecode) regoptions |= 0x01; // bit 0 |
1689 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
if (SustainDefeat) regoptions |= 0x02; // bit 1 |
1690 |
memcpy(&pData[114], ®options, 1); |
memcpy(&pData[121], ®options, 1); |
1691 |
} |
} |
1692 |
|
|
1693 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1694 |
|
|
1695 |
memcpy(&pData[117], &VelocityUpperLimit, 1); |
memcpy(&pData[124], &VelocityUpperLimit, 1); |
1696 |
|
|
1697 |
// next 3 bytes unknown |
// next 3 bytes unknown |
1698 |
|
|
1699 |
memcpy(&pData[121], &ReleaseTriggerDecay, 1); |
memcpy(&pData[128], &ReleaseTriggerDecay, 1); |
1700 |
|
|
1701 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1702 |
|
|
1703 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
1704 |
memcpy(&pData[124], &eg1hold, 1); |
memcpy(&pData[131], &eg1hold, 1); |
1705 |
|
|
1706 |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
1707 |
(VCFCutoff) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
1708 |
memcpy(&pData[125], &vcfcutoff, 1); |
memcpy(&pData[132], &vcfcutoff, 1); |
1709 |
|
|
1710 |
memcpy(&pData[126], &VCFCutoffController, 1); |
memcpy(&pData[133], &VCFCutoffController, 1); |
1711 |
|
|
1712 |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
1713 |
(VCFVelocityScale) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
1714 |
memcpy(&pData[127], &vcfvelscale, 1); |
memcpy(&pData[134], &vcfvelscale, 1); |
1715 |
|
|
1716 |
// next byte unknown |
// next byte unknown |
1717 |
|
|
1718 |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
1719 |
(VCFResonance) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFResonance & 0x7f); /* lower 7 bits */ |
1720 |
memcpy(&pData[129], &vcfresonance, 1); |
memcpy(&pData[136], &vcfresonance, 1); |
1721 |
|
|
1722 |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
1723 |
(VCFKeyboardTrackingBreakpoint) ? 0x7f : 0x00; /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
1724 |
memcpy(&pData[130], &vcfbreakpoint, 1); |
memcpy(&pData[137], &vcfbreakpoint, 1); |
1725 |
|
|
1726 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
1727 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
1728 |
memcpy(&pData[131], &vcfvelocity, 1); |
memcpy(&pData[138], &vcfvelocity, 1); |
1729 |
|
|
1730 |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; |
1731 |
memcpy(&pData[132], &vcftype, 1); |
memcpy(&pData[139], &vcftype, 1); |
1732 |
} |
} |
1733 |
|
|
1734 |
// 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 |
2070 |
// * |
// * |
2071 |
|
|
2072 |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
2073 |
|
pInfo->UseFixedLengthStrings = true; |
2074 |
|
|
2075 |
// Initialization |
// Initialization |
2076 |
Dimensions = 0; |
Dimensions = 0; |
2077 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2139 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
2140 |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2141 |
} |
} |
2142 |
|
GetSample(); // load global region sample reference |
2143 |
} |
} |
2144 |
|
|
2145 |
// make sure there is at least one dimension region |
// make sure there is at least one dimension region |
2183 |
|
|
2184 |
// update dimension definitions in '3lnk' chunk |
// update dimension definitions in '3lnk' chunk |
2185 |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData(); |
2186 |
|
memcpy(&pData[0], &DimensionRegions, 4); |
2187 |
for (int i = 0; i < iMaxDimensions; i++) { |
for (int i = 0; i < iMaxDimensions; i++) { |
2188 |
pData[i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
2189 |
pData[i * 8 + 1] = pDimensionDefinitions[i].bits; |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
2190 |
// next 2 bytes unknown |
// next 2 bytes unknown |
2191 |
pData[i * 8 + 4] = pDimensionDefinitions[i].zones; |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
2192 |
// next 3 bytes unknown |
// next 3 bytes unknown |
2193 |
} |
} |
2194 |
|
|
2523 |
Sample* sample = file->GetFirstSample(pProgress); |
Sample* sample = file->GetFirstSample(pProgress); |
2524 |
while (sample) { |
while (sample) { |
2525 |
if (sample->ulWavePoolOffset == soughtoffset && |
if (sample->ulWavePoolOffset == soughtoffset && |
2526 |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample); |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
2527 |
sample = file->GetNextSample(); |
sample = file->GetNextSample(); |
2528 |
} |
} |
2529 |
return NULL; |
return NULL; |
2535 |
// * |
// * |
2536 |
|
|
2537 |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
2538 |
|
pInfo->UseFixedLengthStrings = true; |
2539 |
|
|
2540 |
// Initialization |
// Initialization |
2541 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
2542 |
|
|
2695 |
|
|
2696 |
|
|
2697 |
|
|
2698 |
|
// *************** Group *************** |
2699 |
|
// * |
2700 |
|
|
2701 |
|
/** @brief Constructor. |
2702 |
|
* |
2703 |
|
* @param file - pointer to the gig::File object |
2704 |
|
* @param ck3gnm - pointer to 3gnm chunk associated with this group or |
2705 |
|
* NULL if this is a new Group |
2706 |
|
*/ |
2707 |
|
Group::Group(File* file, RIFF::Chunk* ck3gnm) { |
2708 |
|
pFile = file; |
2709 |
|
pNameChunk = ck3gnm; |
2710 |
|
::LoadString(pNameChunk, Name); |
2711 |
|
} |
2712 |
|
|
2713 |
|
Group::~Group() { |
2714 |
|
} |
2715 |
|
|
2716 |
|
/** @brief Update chunks with current group settings. |
2717 |
|
* |
2718 |
|
* Apply current Group field values to the respective. You have to call |
2719 |
|
* File::Save() to make changes persistent. |
2720 |
|
*/ |
2721 |
|
void Group::UpdateChunks() { |
2722 |
|
// make sure <3gri> and <3gnl> list chunks exist |
2723 |
|
RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); |
2724 |
|
if (!_3gri) _3gri = pFile->pRIFF->AddSubList(LIST_TYPE_3GRI); |
2725 |
|
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
2726 |
|
if (!_3gnl) _3gnl = pFile->pRIFF->AddSubList(LIST_TYPE_3GNL); |
2727 |
|
// now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk |
2728 |
|
::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); |
2729 |
|
} |
2730 |
|
|
2731 |
|
/** |
2732 |
|
* Returns the first Sample of this Group. You have to call this method |
2733 |
|
* once before you use GetNextSample(). |
2734 |
|
* |
2735 |
|
* <b>Notice:</b> this method might block for a long time, in case the |
2736 |
|
* samples of this .gig file were not scanned yet |
2737 |
|
* |
2738 |
|
* @returns pointer address to first Sample or NULL if there is none |
2739 |
|
* applied to this Group |
2740 |
|
* @see GetNextSample() |
2741 |
|
*/ |
2742 |
|
Sample* Group::GetFirstSample() { |
2743 |
|
// FIXME: lazy und unsafe implementation, should be an autonomous iterator |
2744 |
|
for (Sample* pSample = pFile->GetFirstSample(); pSample; pSample = pFile->GetNextSample()) { |
2745 |
|
if (pSample->GetGroup() == this) return pSample; |
2746 |
|
} |
2747 |
|
return NULL; |
2748 |
|
} |
2749 |
|
|
2750 |
|
/** |
2751 |
|
* Returns the next Sample of the Group. You have to call |
2752 |
|
* GetFirstSample() once before you can use this method. By calling this |
2753 |
|
* method multiple times it iterates through the Samples assigned to |
2754 |
|
* this Group. |
2755 |
|
* |
2756 |
|
* @returns pointer address to the next Sample of this Group or NULL if |
2757 |
|
* end reached |
2758 |
|
* @see GetFirstSample() |
2759 |
|
*/ |
2760 |
|
Sample* Group::GetNextSample() { |
2761 |
|
// FIXME: lazy und unsafe implementation, should be an autonomous iterator |
2762 |
|
for (Sample* pSample = pFile->GetNextSample(); pSample; pSample = pFile->GetNextSample()) { |
2763 |
|
if (pSample->GetGroup() == this) return pSample; |
2764 |
|
} |
2765 |
|
return NULL; |
2766 |
|
} |
2767 |
|
|
2768 |
|
/** |
2769 |
|
* Move Sample given by \a pSample from another Group to this Group. |
2770 |
|
*/ |
2771 |
|
void Group::AddSample(Sample* pSample) { |
2772 |
|
pSample->pGroup = this; |
2773 |
|
} |
2774 |
|
|
2775 |
|
/** |
2776 |
|
* Move all members of this group to another group (preferably the 1st |
2777 |
|
* one except this). This method is called explicitly by |
2778 |
|
* File::DeleteGroup() thus when a Group was deleted. This code was |
2779 |
|
* intentionally not placed in the destructor! |
2780 |
|
*/ |
2781 |
|
void Group::MoveAll() { |
2782 |
|
// get "that" other group first |
2783 |
|
Group* pOtherGroup = NULL; |
2784 |
|
for (pOtherGroup = pFile->GetFirstGroup(); pOtherGroup; pOtherGroup = pFile->GetNextGroup()) { |
2785 |
|
if (pOtherGroup != this) break; |
2786 |
|
} |
2787 |
|
if (!pOtherGroup) throw Exception( |
2788 |
|
"Could not move samples to another group, since there is no " |
2789 |
|
"other Group. This is a bug, report it!" |
2790 |
|
); |
2791 |
|
// now move all samples of this group to the other group |
2792 |
|
for (Sample* pSample = GetFirstSample(); pSample; pSample = GetNextSample()) { |
2793 |
|
pOtherGroup->AddSample(pSample); |
2794 |
|
} |
2795 |
|
} |
2796 |
|
|
2797 |
|
|
2798 |
|
|
2799 |
// *************** File *************** |
// *************** File *************** |
2800 |
// * |
// * |
2801 |
|
|
2802 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
2803 |
|
pGroups = NULL; |
2804 |
|
pInfo->UseFixedLengthStrings = true; |
2805 |
} |
} |
2806 |
|
|
2807 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
2808 |
|
pGroups = NULL; |
2809 |
|
pInfo->UseFixedLengthStrings = true; |
2810 |
|
} |
2811 |
|
|
2812 |
|
File::~File() { |
2813 |
|
if (pGroups) { |
2814 |
|
std::list<Group*>::iterator iter = pGroups->begin(); |
2815 |
|
std::list<Group*>::iterator end = pGroups->end(); |
2816 |
|
while (iter != end) { |
2817 |
|
delete *iter; |
2818 |
|
++iter; |
2819 |
|
} |
2820 |
|
delete pGroups; |
2821 |
|
} |
2822 |
} |
} |
2823 |
|
|
2824 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
2873 |
} |
} |
2874 |
|
|
2875 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
2876 |
|
// Groups must be loaded before samples, because samples will try |
2877 |
|
// to resolve the group they belong to |
2878 |
|
LoadGroups(); |
2879 |
|
|
2880 |
if (!pSamples) pSamples = new SampleList; |
if (!pSamples) pSamples = new SampleList; |
2881 |
|
|
2882 |
RIFF::File* file = pRIFF; |
RIFF::File* file = pRIFF; |
3040 |
} |
} |
3041 |
} |
} |
3042 |
|
|
3043 |
|
Group* File::GetFirstGroup() { |
3044 |
|
if (!pGroups) LoadGroups(); |
3045 |
|
// there must always be at least one group |
3046 |
|
GroupsIterator = pGroups->begin(); |
3047 |
|
return *GroupsIterator; |
3048 |
|
} |
3049 |
|
|
3050 |
|
Group* File::GetNextGroup() { |
3051 |
|
if (!pGroups) return NULL; |
3052 |
|
++GroupsIterator; |
3053 |
|
return (GroupsIterator == pGroups->end()) ? NULL : *GroupsIterator; |
3054 |
|
} |
3055 |
|
|
3056 |
|
/** |
3057 |
|
* Returns the group with the given index. |
3058 |
|
* |
3059 |
|
* @param index - number of the sought group (0..n) |
3060 |
|
* @returns sought group or NULL if there's no such group |
3061 |
|
*/ |
3062 |
|
Group* File::GetGroup(uint index) { |
3063 |
|
if (!pGroups) LoadGroups(); |
3064 |
|
GroupsIterator = pGroups->begin(); |
3065 |
|
for (uint i = 0; GroupsIterator != pGroups->end(); i++) { |
3066 |
|
if (i == index) return *GroupsIterator; |
3067 |
|
++GroupsIterator; |
3068 |
|
} |
3069 |
|
return NULL; |
3070 |
|
} |
3071 |
|
|
3072 |
|
Group* File::AddGroup() { |
3073 |
|
if (!pGroups) LoadGroups(); |
3074 |
|
// there must always be at least one group |
3075 |
|
__ensureMandatoryChunksExist(); |
3076 |
|
Group* pGroup = new Group(this, NULL); |
3077 |
|
pGroups->push_back(pGroup); |
3078 |
|
return pGroup; |
3079 |
|
} |
3080 |
|
|
3081 |
|
void File::DeleteGroup(Group* pGroup) { |
3082 |
|
if (!pGroups) LoadGroups(); |
3083 |
|
std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup); |
3084 |
|
if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group"); |
3085 |
|
if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!"); |
3086 |
|
// move all members of this group to another group |
3087 |
|
pGroup->MoveAll(); |
3088 |
|
pGroups->erase(iter); |
3089 |
|
delete pGroup; |
3090 |
|
} |
3091 |
|
|
3092 |
|
void File::LoadGroups() { |
3093 |
|
if (!pGroups) pGroups = new std::list<Group*>; |
3094 |
|
// try to read defined groups from file |
3095 |
|
RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
3096 |
|
if (lst3gri) { |
3097 |
|
RIFF::List* lst3gnl = lst3gri->GetSubList(LIST_TYPE_3GNL); |
3098 |
|
if (lst3gnl) { |
3099 |
|
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
3100 |
|
while (ck) { |
3101 |
|
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
3102 |
|
pGroups->push_back(new Group(this, ck)); |
3103 |
|
} |
3104 |
|
ck = lst3gnl->GetNextSubChunk(); |
3105 |
|
} |
3106 |
|
} |
3107 |
|
} |
3108 |
|
// if there were no group(s), create at least the mandatory default group |
3109 |
|
if (!pGroups->size()) { |
3110 |
|
Group* pGroup = new Group(this, NULL); |
3111 |
|
pGroup->Name = "Default Group"; |
3112 |
|
pGroups->push_back(pGroup); |
3113 |
|
} |
3114 |
|
} |
3115 |
|
|
3116 |
|
|
3117 |
|
|
3118 |
// *************** Exception *************** |
// *************** Exception *************** |