1262 |
uint DimensionRegion::Instances = 0; |
uint DimensionRegion::Instances = 0; |
1263 |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
1264 |
|
|
1265 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
1266 |
Instances++; |
Instances++; |
1267 |
|
|
1268 |
pSample = NULL; |
pSample = NULL; |
1269 |
|
pRegion = pParent; |
1270 |
|
|
1271 |
if (_3ewl->GetSubChunk(CHUNK_ID_WSMP)) memcpy(&Crossfade, &SamplerOptions, 4); |
if (_3ewl->GetSubChunk(CHUNK_ID_WSMP)) memcpy(&Crossfade, &SamplerOptions, 4); |
1272 |
else memset(&Crossfade, 0, 4); |
else memset(&Crossfade, 0, 4); |
1543 |
VelocityTable = 0; |
VelocityTable = 0; |
1544 |
} |
} |
1545 |
|
|
1546 |
|
/* |
1547 |
|
* Constructs a DimensionRegion by copying all parameters from |
1548 |
|
* another DimensionRegion |
1549 |
|
*/ |
1550 |
|
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
1551 |
|
Instances++; |
1552 |
|
*this = src; // default memberwise shallow copy of all parameters |
1553 |
|
pParentList = _3ewl; // restore the chunk pointer |
1554 |
|
|
1555 |
|
// deep copy of owned structures |
1556 |
|
if (src.VelocityTable) { |
1557 |
|
VelocityTable = new uint8_t[128]; |
1558 |
|
for (int k = 0 ; k < 128 ; k++) |
1559 |
|
VelocityTable[k] = src.VelocityTable[k]; |
1560 |
|
} |
1561 |
|
if (src.pSampleLoops) { |
1562 |
|
pSampleLoops = new DLS::sample_loop_t[src.SampleLoops]; |
1563 |
|
for (int k = 0 ; k < src.SampleLoops ; k++) |
1564 |
|
pSampleLoops[k] = src.pSampleLoops[k]; |
1565 |
|
} |
1566 |
|
} |
1567 |
|
|
1568 |
/** |
/** |
1569 |
* Apply dimension region settings to the respective RIFF chunks. You |
* Apply dimension region settings to the respective RIFF chunks. You |
1570 |
* have to call File::Save() to make changes persistent. |
* have to call File::Save() to make changes persistent. |
1640 |
pData[44] = eg1ctl; |
pData[44] = eg1ctl; |
1641 |
|
|
1642 |
const uint8_t eg1ctrloptions = |
const uint8_t eg1ctrloptions = |
1643 |
(EG1ControllerInvert) ? 0x01 : 0x00 | |
(EG1ControllerInvert ? 0x01 : 0x00) | |
1644 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) | |
1645 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) | |
1646 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence); |
1650 |
pData[46] = eg2ctl; |
pData[46] = eg2ctl; |
1651 |
|
|
1652 |
const uint8_t eg2ctrloptions = |
const uint8_t eg2ctrloptions = |
1653 |
(EG2ControllerInvert) ? 0x01 : 0x00 | |
(EG2ControllerInvert ? 0x01 : 0x00) | |
1654 |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) | |
1655 |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) | |
1656 |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence); |
1828 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7 |
1829 |
pData[131] = eg1hold; |
pData[131] = eg1hold; |
1830 |
|
|
1831 |
const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfcutoff = (VCFEnabled ? 0x80 : 0x00) | /* bit 7 */ |
1832 |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
(VCFCutoff & 0x7f); /* lower 7 bits */ |
1833 |
pData[132] = vcfcutoff; |
pData[132] = vcfcutoff; |
1834 |
|
|
1835 |
pData[133] = VCFCutoffController; |
pData[133] = VCFCutoffController; |
1836 |
|
|
1837 |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfvelscale = (VCFCutoffControllerInvert ? 0x80 : 0x00) | /* bit 7 */ |
1838 |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
(VCFVelocityScale & 0x7f); /* lower 7 bits */ |
1839 |
pData[134] = vcfvelscale; |
pData[134] = vcfvelscale; |
1840 |
|
|
1841 |
// next byte unknown |
// next byte unknown |
1842 |
|
|
1843 |
const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */ |
const uint8_t vcfresonance = (VCFResonanceDynamic ? 0x00 : 0x80) | /* bit 7 */ |
1844 |
(VCFResonance & 0x7f); /* lower 7 bits */ |
(VCFResonance & 0x7f); /* lower 7 bits */ |
1845 |
pData[136] = vcfresonance; |
pData[136] = vcfresonance; |
1846 |
|
|
1847 |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */ |
const uint8_t vcfbreakpoint = (VCFKeyboardTracking ? 0x80 : 0x00) | /* bit 7 */ |
1848 |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
1849 |
pData[137] = vcfbreakpoint; |
pData[137] = vcfbreakpoint; |
1850 |
|
|
1875 |
return table; |
return table; |
1876 |
} |
} |
1877 |
|
|
1878 |
|
Region* DimensionRegion::GetParent() const { |
1879 |
|
return pRegion; |
1880 |
|
} |
1881 |
|
|
1882 |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
1883 |
leverage_ctrl_t decodedcontroller; |
leverage_ctrl_t decodedcontroller; |
1884 |
switch (EncodedController) { |
switch (EncodedController) { |
2278 |
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG); |
2279 |
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG); |
2280 |
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL); |
2281 |
pDimensionRegions[0] = new DimensionRegion(_3ewl); |
pDimensionRegions[0] = new DimensionRegion(this, _3ewl); |
2282 |
DimensionRegions = 1; |
DimensionRegions = 1; |
2283 |
} |
} |
2284 |
} |
} |
2339 |
for (int i = 0; i < iMaxDimensions; i++) { |
for (int i = 0; i < iMaxDimensions; i++) { |
2340 |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension; |
2341 |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
pData[5 + i * 8] = pDimensionDefinitions[i].bits; |
2342 |
pData[6 + i * 8] = shift; |
pData[6 + i * 8] = pDimensionDefinitions[i].dimension == dimension_none ? 0 : shift; |
2343 |
pData[7 + i * 8] = (1 << (shift + pDimensionDefinitions[i].bits)) - (1 << shift); |
pData[7 + i * 8] = (1 << (shift + pDimensionDefinitions[i].bits)) - (1 << shift); |
2344 |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
pData[8 + i * 8] = pDimensionDefinitions[i].zones; |
2345 |
// next 3 bytes unknown, always zero? |
// next 3 bytes unknown, always zero? |
2361 |
break; |
break; |
2362 |
} |
} |
2363 |
} |
} |
|
if (iWaveIndex < 0) throw gig::Exception("Could not update gig::Region, could not find DimensionRegion's sample"); |
|
2364 |
} |
} |
2365 |
store32(&pData[iWavePoolOffset + i * 4], iWaveIndex); |
store32(&pData[iWavePoolOffset + i * 4], iWaveIndex); |
2366 |
} |
} |
2373 |
RIFF::List* _3ewl = _3prg->GetFirstSubList(); |
RIFF::List* _3ewl = _3prg->GetFirstSubList(); |
2374 |
while (_3ewl) { |
while (_3ewl) { |
2375 |
if (_3ewl->GetListType() == LIST_TYPE_3EWL) { |
if (_3ewl->GetListType() == LIST_TYPE_3EWL) { |
2376 |
pDimensionRegions[dimensionRegionNr] = new DimensionRegion(_3ewl); |
pDimensionRegions[dimensionRegionNr] = new DimensionRegion(this, _3ewl); |
2377 |
dimensionRegionNr++; |
dimensionRegionNr++; |
2378 |
} |
} |
2379 |
_3ewl = _3prg->GetNextSubList(); |
_3ewl = _3prg->GetNextSubList(); |
2487 |
if (pDimensionDefinitions[i].dimension == pDimDef->dimension) |
if (pDimensionDefinitions[i].dimension == pDimDef->dimension) |
2488 |
throw gig::Exception("Could not add new dimension, there is already a dimension of the same type"); |
throw gig::Exception("Could not add new dimension, there is already a dimension of the same type"); |
2489 |
|
|
2490 |
|
// pos is where the new dimension should be placed, normally |
2491 |
|
// last in list, except for the samplechannel dimension which |
2492 |
|
// has to be first in list |
2493 |
|
int pos = pDimDef->dimension == dimension_samplechannel ? 0 : Dimensions; |
2494 |
|
int bitpos = 0; |
2495 |
|
for (int i = 0 ; i < pos ; i++) |
2496 |
|
bitpos += pDimensionDefinitions[i].bits; |
2497 |
|
|
2498 |
|
// make room for the new dimension |
2499 |
|
for (int i = Dimensions ; i > pos ; i--) pDimensionDefinitions[i] = pDimensionDefinitions[i - 1]; |
2500 |
|
for (int i = 0 ; i < (1 << iCurrentBits) ; i++) { |
2501 |
|
for (int j = Dimensions ; j > pos ; j--) { |
2502 |
|
pDimensionRegions[i]->DimensionUpperLimits[j] = |
2503 |
|
pDimensionRegions[i]->DimensionUpperLimits[j - 1]; |
2504 |
|
} |
2505 |
|
} |
2506 |
|
|
2507 |
// assign definition of new dimension |
// assign definition of new dimension |
2508 |
pDimensionDefinitions[Dimensions] = *pDimDef; |
pDimensionDefinitions[pos] = *pDimDef; |
2509 |
|
|
2510 |
// auto correct certain dimension definition fields (where possible) |
// auto correct certain dimension definition fields (where possible) |
2511 |
pDimensionDefinitions[Dimensions].split_type = |
pDimensionDefinitions[pos].split_type = |
2512 |
__resolveSplitType(pDimensionDefinitions[Dimensions].dimension); |
__resolveSplitType(pDimensionDefinitions[pos].dimension); |
2513 |
pDimensionDefinitions[Dimensions].zone_size = |
pDimensionDefinitions[pos].zone_size = |
2514 |
__resolveZoneSize(pDimensionDefinitions[Dimensions]); |
__resolveZoneSize(pDimensionDefinitions[pos]); |
2515 |
|
|
2516 |
// create new dimension region(s) for this new dimension |
// create new dimension region(s) for this new dimension, and make |
2517 |
for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) { |
// sure that the dimension regions are placed correctly in both the |
2518 |
//TODO: maybe we should copy existing dimension regions if possible instead of simply creating new ones with default values |
// RIFF list and the pDimensionRegions array |
2519 |
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
RIFF::Chunk* moveTo = NULL; |
2520 |
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
2521 |
pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk); |
for (int i = (1 << iCurrentBits) - (1 << bitpos) ; i >= 0 ; i -= (1 << bitpos)) { |
2522 |
|
for (int k = 0 ; k < (1 << bitpos) ; k++) { |
2523 |
// copy the upper limits for the other dimensions |
pDimensionRegions[(i << pDimDef->bits) + k] = pDimensionRegions[i + k]; |
2524 |
memcpy(pDimensionRegions[i]->DimensionUpperLimits, |
} |
2525 |
pDimensionRegions[i & ((1 << iCurrentBits) - 1)]->DimensionUpperLimits, 8); |
for (int j = 1 ; j < (1 << pDimDef->bits) ; j++) { |
2526 |
|
for (int k = 0 ; k < (1 << bitpos) ; k++) { |
2527 |
|
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
2528 |
|
if (moveTo) _3prg->MoveSubChunk(pNewDimRgnListChunk, moveTo); |
2529 |
|
// create a new dimension region and copy all parameter values from |
2530 |
|
// an existing dimension region |
2531 |
|
pDimensionRegions[(i << pDimDef->bits) + (j << bitpos) + k] = |
2532 |
|
new DimensionRegion(pNewDimRgnListChunk, *pDimensionRegions[i + k]); |
2533 |
|
|
2534 |
DimensionRegions++; |
DimensionRegions++; |
2535 |
|
} |
2536 |
|
} |
2537 |
|
moveTo = pDimensionRegions[i]->pParentList; |
2538 |
} |
} |
2539 |
|
|
2540 |
// initialize the upper limits for this dimension |
// initialize the upper limits for this dimension |
2541 |
for (int z = 0, j = 0 ; z < pDimDef->zones ; z++, j += 1 << iCurrentBits) { |
int mask = (1 << bitpos) - 1; |
2542 |
|
for (int z = 0 ; z < pDimDef->zones ; z++) { |
2543 |
uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1); |
uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1); |
2544 |
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
2545 |
pDimensionRegions[j + i]->DimensionUpperLimits[Dimensions] = upperLimit; |
pDimensionRegions[((i & ~mask) << pDimDef->bits) | |
2546 |
|
(z << bitpos) | |
2547 |
|
(i & mask)]->DimensionUpperLimits[pos] = upperLimit; |
2548 |
} |
} |
2549 |
} |
} |
2550 |
|
|
2874 |
store32(&pData[2], Attenuation); |
store32(&pData[2], Attenuation); |
2875 |
store16(&pData[6], FineTune); |
store16(&pData[6], FineTune); |
2876 |
store16(&pData[8], PitchbendRange); |
store16(&pData[8], PitchbendRange); |
2877 |
const uint8_t dimkeystart = (PianoReleaseMode) ? 0x01 : 0x00 | |
const uint8_t dimkeystart = (PianoReleaseMode ? 0x01 : 0x00) | |
2878 |
DimensionKeyRange.low << 1; |
DimensionKeyRange.low << 1; |
2879 |
pData[10] = dimkeystart; |
pData[10] = dimkeystart; |
2880 |
pData[11] = DimensionKeyRange.high; |
pData[11] = DimensionKeyRange.high; |
2985 |
} |
} |
2986 |
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
2987 |
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
2988 |
|
|
2989 |
|
if (!pNameChunk && pFile->pVersion && pFile->pVersion->major == 3) { |
2990 |
|
// v3 has a fixed list of 128 strings, find a free one |
2991 |
|
for (RIFF::Chunk* ck = _3gnl->GetFirstSubChunk() ; ck ; ck = _3gnl->GetNextSubChunk()) { |
2992 |
|
if (strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) { |
2993 |
|
pNameChunk = ck; |
2994 |
|
break; |
2995 |
|
} |
2996 |
|
} |
2997 |
|
} |
2998 |
|
|
2999 |
// now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk |
// now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk |
3000 |
::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); |
::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); |
3001 |
} |
} |
3172 |
|
|
3173 |
/** @brief Delete a sample. |
/** @brief Delete a sample. |
3174 |
* |
* |
3175 |
* This will delete the given Sample object from the gig file. You have |
* This will delete the given Sample object from the gig file. Any |
3176 |
* to call Save() to make this persistent to the file. |
* references to this sample from Regions and DimensionRegions will be |
3177 |
|
* removed. You have to call Save() to make this persistent to the file. |
3178 |
* |
* |
3179 |
* @param pSample - sample to delete |
* @param pSample - sample to delete |
3180 |
* @throws gig::Exception if given sample could not be found |
* @throws gig::Exception if given sample could not be found |
3186 |
if (SamplesIterator != pSamples->end() && *SamplesIterator == pSample) ++SamplesIterator; // avoid iterator invalidation |
if (SamplesIterator != pSamples->end() && *SamplesIterator == pSample) ++SamplesIterator; // avoid iterator invalidation |
3187 |
pSamples->erase(iter); |
pSamples->erase(iter); |
3188 |
delete pSample; |
delete pSample; |
3189 |
|
|
3190 |
|
// remove all references to the sample |
3191 |
|
for (Instrument* instrument = GetFirstInstrument() ; instrument ; |
3192 |
|
instrument = GetNextInstrument()) { |
3193 |
|
for (Region* region = instrument->GetFirstRegion() ; region ; |
3194 |
|
region = instrument->GetNextRegion()) { |
3195 |
|
|
3196 |
|
if (region->GetSample() == pSample) region->SetSample(NULL); |
3197 |
|
|
3198 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
3199 |
|
gig::DimensionRegion *d = region->pDimensionRegions[i]; |
3200 |
|
if (d->pSample == pSample) d->pSample = NULL; |
3201 |
|
} |
3202 |
|
} |
3203 |
|
} |
3204 |
} |
} |
3205 |
|
|
3206 |
void File::LoadSamples() { |
void File::LoadSamples() { |
3505 |
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk(); |
3506 |
while (ck) { |
while (ck) { |
3507 |
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
if (ck->GetChunkID() == CHUNK_ID_3GNM) { |
3508 |
|
if (pVersion && pVersion->major == 3 && |
3509 |
|
strcmp(static_cast<char*>(ck->LoadChunkData()), "") == 0) break; |
3510 |
|
|
3511 |
pGroups->push_back(new Group(this, ck)); |
pGroups->push_back(new Group(this, ck)); |
3512 |
} |
} |
3513 |
ck = lst3gnl->GetNextSubChunk(); |
ck = lst3gnl->GetNextSubChunk(); |
3557 |
for (; iter != end; ++iter) { |
for (; iter != end; ++iter) { |
3558 |
(*iter)->UpdateChunks(); |
(*iter)->UpdateChunks(); |
3559 |
} |
} |
3560 |
|
|
3561 |
|
// v3: make sure the file has 128 3gnm chunks |
3562 |
|
if (pVersion && pVersion->major == 3) { |
3563 |
|
RIFF::List* _3gnl = pRIFF->GetSubList(LIST_TYPE_3GRI)->GetSubList(LIST_TYPE_3GNL); |
3564 |
|
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
3565 |
|
for (int i = 0 ; i < 128 ; i++) { |
3566 |
|
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
3567 |
|
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
3568 |
|
} |
3569 |
|
} |
3570 |
} |
} |
3571 |
|
|
3572 |
// update einf chunk |
// update einf chunk |