1542 |
VelocityTable = 0; |
VelocityTable = 0; |
1543 |
} |
} |
1544 |
|
|
1545 |
|
/* |
1546 |
|
* Constructs a DimensionRegion by copying all parameters from |
1547 |
|
* another DimensionRegion |
1548 |
|
*/ |
1549 |
|
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
1550 |
|
Instances++; |
1551 |
|
*this = src; // default memberwise shallow copy of all parameters |
1552 |
|
pParentList = _3ewl; // restore the chunk pointer |
1553 |
|
|
1554 |
|
// deep copy of owned structures |
1555 |
|
if (src.VelocityTable) { |
1556 |
|
VelocityTable = new uint8_t[128]; |
1557 |
|
for (int k = 0 ; k < 128 ; k++) |
1558 |
|
VelocityTable[k] = src.VelocityTable[k]; |
1559 |
|
} |
1560 |
|
if (src.pSampleLoops) { |
1561 |
|
pSampleLoops = new DLS::sample_loop_t[src.SampleLoops]; |
1562 |
|
for (int k = 0 ; k < src.SampleLoops ; k++) |
1563 |
|
pSampleLoops[k] = src.pSampleLoops[k]; |
1564 |
|
} |
1565 |
|
} |
1566 |
|
|
1567 |
/** |
/** |
1568 |
* Apply dimension region settings to the respective RIFF chunks. You |
* Apply dimension region settings to the respective RIFF chunks. You |
1569 |
* have to call File::Save() to make changes persistent. |
* have to call File::Save() to make changes persistent. |
2482 |
if (pDimensionDefinitions[i].dimension == pDimDef->dimension) |
if (pDimensionDefinitions[i].dimension == pDimDef->dimension) |
2483 |
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"); |
2484 |
|
|
2485 |
|
// pos is where the new dimension should be placed, normally |
2486 |
|
// last in list, except for the samplechannel dimension which |
2487 |
|
// has to be first in list |
2488 |
|
int pos = pDimDef->dimension == dimension_samplechannel ? 0 : Dimensions; |
2489 |
|
int bitpos = 0; |
2490 |
|
for (int i = 0 ; i < pos ; i++) |
2491 |
|
bitpos += pDimensionDefinitions[i].bits; |
2492 |
|
|
2493 |
|
// make room for the new dimension |
2494 |
|
for (int i = Dimensions ; i > pos ; i--) pDimensionDefinitions[i] = pDimensionDefinitions[i - 1]; |
2495 |
|
for (int i = 0 ; i < (1 << iCurrentBits) ; i++) { |
2496 |
|
for (int j = Dimensions ; j > pos ; j--) { |
2497 |
|
pDimensionRegions[i]->DimensionUpperLimits[j] = |
2498 |
|
pDimensionRegions[i]->DimensionUpperLimits[j - 1]; |
2499 |
|
} |
2500 |
|
} |
2501 |
|
|
2502 |
// assign definition of new dimension |
// assign definition of new dimension |
2503 |
pDimensionDefinitions[Dimensions] = *pDimDef; |
pDimensionDefinitions[pos] = *pDimDef; |
2504 |
|
|
2505 |
// auto correct certain dimension definition fields (where possible) |
// auto correct certain dimension definition fields (where possible) |
2506 |
pDimensionDefinitions[Dimensions].split_type = |
pDimensionDefinitions[pos].split_type = |
2507 |
__resolveSplitType(pDimensionDefinitions[Dimensions].dimension); |
__resolveSplitType(pDimensionDefinitions[pos].dimension); |
2508 |
pDimensionDefinitions[Dimensions].zone_size = |
pDimensionDefinitions[pos].zone_size = |
2509 |
__resolveZoneSize(pDimensionDefinitions[Dimensions]); |
__resolveZoneSize(pDimensionDefinitions[pos]); |
2510 |
|
|
2511 |
// create new dimension region(s) for this new dimension |
// create new dimension region(s) for this new dimension, and make |
2512 |
for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) { |
// sure that the dimension regions are placed correctly in both the |
2513 |
//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 |
2514 |
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
RIFF::Chunk* moveTo = NULL; |
2515 |
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
2516 |
pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk); |
for (int i = (1 << iCurrentBits) - (1 << bitpos) ; i >= 0 ; i -= (1 << bitpos)) { |
2517 |
|
for (int k = 0 ; k < (1 << bitpos) ; k++) { |
2518 |
// copy the upper limits for the other dimensions |
pDimensionRegions[(i << pDimDef->bits) + k] = pDimensionRegions[i + k]; |
2519 |
memcpy(pDimensionRegions[i]->DimensionUpperLimits, |
} |
2520 |
pDimensionRegions[i & ((1 << iCurrentBits) - 1)]->DimensionUpperLimits, 8); |
for (int j = 1 ; j < (1 << pDimDef->bits) ; j++) { |
2521 |
|
for (int k = 0 ; k < (1 << bitpos) ; k++) { |
2522 |
|
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
2523 |
|
if (moveTo) _3prg->MoveSubChunk(pNewDimRgnListChunk, moveTo); |
2524 |
|
// create a new dimension region and copy all parameter values from |
2525 |
|
// an existing dimension region |
2526 |
|
pDimensionRegions[(i << pDimDef->bits) + (j << bitpos) + k] = |
2527 |
|
new DimensionRegion(pNewDimRgnListChunk, *pDimensionRegions[i + k]); |
2528 |
|
|
2529 |
DimensionRegions++; |
DimensionRegions++; |
2530 |
|
} |
2531 |
|
} |
2532 |
|
moveTo = pDimensionRegions[i]->pParentList; |
2533 |
} |
} |
2534 |
|
|
2535 |
// initialize the upper limits for this dimension |
// initialize the upper limits for this dimension |
2536 |
for (int z = 0, j = 0 ; z < pDimDef->zones ; z++, j += 1 << iCurrentBits) { |
int mask = (1 << bitpos) - 1; |
2537 |
|
for (int z = 0 ; z < pDimDef->zones ; z++) { |
2538 |
uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1); |
uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1); |
2539 |
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
2540 |
pDimensionRegions[j + i]->DimensionUpperLimits[Dimensions] = upperLimit; |
pDimensionRegions[((i & ~mask) << pDimDef->bits) | |
2541 |
|
(z << bitpos) | |
2542 |
|
(i & mask)]->DimensionUpperLimits[pos] = upperLimit; |
2543 |
} |
} |
2544 |
} |
} |
2545 |
|
|