3652 |
UpdateVelocityTable(); |
UpdateVelocityTable(); |
3653 |
} |
} |
3654 |
|
|
3655 |
|
/** @brief Change type of an existing dimension. |
3656 |
|
* |
3657 |
|
* Alters the dimension type of a dimension already existing on this |
3658 |
|
* region. If there is currently no dimension on this Region with type |
3659 |
|
* @a oldType, then this call with throw an Exception. Likewise there are |
3660 |
|
* cases where the requested dimension type cannot be performed. For example |
3661 |
|
* if the new dimension type shall be gig::dimension_samplechannel, and the |
3662 |
|
* current dimension has more than 2 zones. In such cases an Exception is |
3663 |
|
* thrown as well. |
3664 |
|
* |
3665 |
|
* @param oldType - identifies the existing dimension to be changed |
3666 |
|
* @param newType - to which dimension type it should be changed to |
3667 |
|
* @throws gig::Exception if requested change cannot be performed |
3668 |
|
*/ |
3669 |
|
void Region::SetDimensionType(dimension_t oldType, dimension_t newType) { |
3670 |
|
if (oldType == newType) return; |
3671 |
|
dimension_def_t* def = GetDimensionDefinition(oldType); |
3672 |
|
if (!def) |
3673 |
|
throw gig::Exception("No dimension with provided old dimension type exists on this region"); |
3674 |
|
if (newType == dimension_samplechannel && def->zones != 2) |
3675 |
|
throw gig::Exception("Cannot change to dimension type 'sample channel', because existing dimension does not have 2 zones"); |
3676 |
|
if (GetDimensionDefinition(newType)) |
3677 |
|
throw gig::Exception("There is already a dimension with requested new dimension type on this region"); |
3678 |
|
def->dimension = newType; |
3679 |
|
def->split_type = __resolveSplitType(newType); |
3680 |
|
} |
3681 |
|
|
3682 |
DimensionRegion* Region::GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase) { |
DimensionRegion* Region::GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase) { |
3683 |
uint8_t bits[8] = {}; |
uint8_t bits[8] = {}; |
3684 |
for (std::map<dimension_t,int>::const_iterator it = DimCase.begin(); |
for (std::map<dimension_t,int>::const_iterator it = DimCase.begin(); |
3786 |
return dimreg; |
return dimreg; |
3787 |
} |
} |
3788 |
|
|
3789 |
|
int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) { |
3790 |
|
uint8_t bits; |
3791 |
|
int veldim = -1; |
3792 |
|
int velbitpos; |
3793 |
|
int bitpos = 0; |
3794 |
|
int dimregidx = 0; |
3795 |
|
for (uint i = 0; i < Dimensions; i++) { |
3796 |
|
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
3797 |
|
// the velocity dimension must be handled after the other dimensions |
3798 |
|
veldim = i; |
3799 |
|
velbitpos = bitpos; |
3800 |
|
} else { |
3801 |
|
switch (pDimensionDefinitions[i].split_type) { |
3802 |
|
case split_type_normal: |
3803 |
|
if (pDimensionRegions[0]->DimensionUpperLimits[i]) { |
3804 |
|
// gig3: all normal dimensions (not just the velocity dimension) have custom zone ranges |
3805 |
|
for (bits = 0 ; bits < pDimensionDefinitions[i].zones ; bits++) { |
3806 |
|
if (DimValues[i] <= pDimensionRegions[bits << bitpos]->DimensionUpperLimits[i]) break; |
3807 |
|
} |
3808 |
|
} else { |
3809 |
|
// gig2: evenly sized zones |
3810 |
|
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
3811 |
|
} |
3812 |
|
break; |
3813 |
|
case split_type_bit: // the value is already the sought dimension bit number |
3814 |
|
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
3815 |
|
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
3816 |
|
break; |
3817 |
|
} |
3818 |
|
dimregidx |= bits << bitpos; |
3819 |
|
} |
3820 |
|
bitpos += pDimensionDefinitions[i].bits; |
3821 |
|
} |
3822 |
|
dimregidx &= 255; |
3823 |
|
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
3824 |
|
if (!dimreg) return -1; |
3825 |
|
if (veldim != -1) { |
3826 |
|
// (dimreg is now the dimension region for the lowest velocity) |
3827 |
|
if (dimreg->VelocityTable) // custom defined zone ranges |
3828 |
|
bits = dimreg->VelocityTable[DimValues[veldim] & 127]; |
3829 |
|
else // normal split type |
3830 |
|
bits = uint8_t((DimValues[veldim] & 127) / pDimensionDefinitions[veldim].zone_size); |
3831 |
|
|
3832 |
|
const uint8_t limiter_mask = (1 << pDimensionDefinitions[veldim].bits) - 1; |
3833 |
|
dimregidx |= (bits & limiter_mask) << velbitpos; |
3834 |
|
dimregidx &= 255; |
3835 |
|
} |
3836 |
|
return dimregidx; |
3837 |
|
} |
3838 |
|
|
3839 |
/** |
/** |
3840 |
* Returns the appropriate DimensionRegion for the given dimension bit |
* Returns the appropriate DimensionRegion for the given dimension bit |
3841 |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
4121 |
for (int i = 0; i < nameSize; ++i) |
for (int i = 0; i < nameSize; ++i) |
4122 |
Name[i] = ckScri->ReadUint8(); |
Name[i] = ckScri->ReadUint8(); |
4123 |
// to handle potential future extensions of the header |
// to handle potential future extensions of the header |
4124 |
ckScri->SetPos(headerSize - 6*sizeof(int32_t) + nameSize, RIFF::stream_curpos); |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4125 |
// read actual script data |
// read actual script data |
4126 |
uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos(); |
uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos(); |
4127 |
data.resize(scriptSize); |
data.resize(scriptSize); |
4206 |
this->pGroup = pGroup; |
this->pGroup = pGroup; |
4207 |
} |
} |
4208 |
|
|
4209 |
|
/** |
4210 |
|
* Returns the script group this script currently belongs to. Each script |
4211 |
|
* is a member of exactly one ScriptGroup. |
4212 |
|
* |
4213 |
|
* @returns current script group |
4214 |
|
*/ |
4215 |
|
ScriptGroup* Script::GetGroup() const { |
4216 |
|
return pGroup; |
4217 |
|
} |
4218 |
|
|
4219 |
void Script::RemoveAllScriptReferences() { |
void Script::RemoveAllScriptReferences() { |
4220 |
File* pFile = pGroup->pFile; |
File* pFile = pGroup->pFile; |
4221 |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4425 |
if (lst3LS) { |
if (lst3LS) { |
4426 |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4427 |
if (ckSCSL) { |
if (ckSCSL) { |
4428 |
int slotCount = ckSCSL->ReadUint32(); |
int headerSize = ckSCSL->ReadUint32(); |
4429 |
int slotSize = ckSCSL->ReadUint32(); |
int slotCount = ckSCSL->ReadUint32(); |
4430 |
int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future extensions |
if (slotCount) { |
4431 |
for (int i = 0; i < slotCount; ++i) { |
int slotSize = ckSCSL->ReadUint32(); |
4432 |
_ScriptPooolEntry e; |
ckSCSL->SetPos(headerSize); // in case of future header extensions |
4433 |
e.fileOffset = ckSCSL->ReadUint32(); |
int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future slot extensions |
4434 |
e.bypass = ckSCSL->ReadUint32() & 1; |
for (int i = 0; i < slotCount; ++i) { |
4435 |
if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions |
_ScriptPooolEntry e; |
4436 |
scriptPoolFileOffsets.push_back(e); |
e.fileOffset = ckSCSL->ReadUint32(); |
4437 |
|
e.bypass = ckSCSL->ReadUint32() & 1; |
4438 |
|
if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions |
4439 |
|
scriptPoolFileOffsets.push_back(e); |
4440 |
|
} |
4441 |
} |
} |
4442 |
} |
} |
4443 |
} |
} |
4523 |
if (pScriptRefs) { |
if (pScriptRefs) { |
4524 |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4525 |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS); |
4526 |
const int totalSize = pScriptRefs->size() * 2*sizeof(uint32_t); |
const int slotCount = pScriptRefs->size(); |
4527 |
|
const int headerSize = 3 * sizeof(uint32_t); |
4528 |
|
const int slotSize = 2 * sizeof(uint32_t); |
4529 |
|
const int totalChunkSize = headerSize + slotCount * slotSize; |
4530 |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4531 |
if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalSize); |
if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalChunkSize); |
4532 |
else ckSCSL->Resize(totalSize); |
else ckSCSL->Resize(totalChunkSize); |
4533 |
uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData(); |
uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData(); |
4534 |
for (int i = 0, pos = 0; i < pScriptRefs->size(); ++i) { |
int pos = 0; |
4535 |
int fileOffset = |
store32(&pData[pos], headerSize); |
4536 |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
pos += sizeof(uint32_t); |
4537 |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
store32(&pData[pos], slotCount); |
4538 |
CHUNK_HEADER_SIZE; |
pos += sizeof(uint32_t); |
4539 |
store32(&pData[pos], fileOffset); |
store32(&pData[pos], slotSize); |
4540 |
|
pos += sizeof(uint32_t); |
4541 |
|
for (int i = 0; i < slotCount; ++i) { |
4542 |
|
// arbitrary value, the actual file offset will be updated in |
4543 |
|
// UpdateScriptFileOffsets() after the file has been resized |
4544 |
|
int bogusFileOffset = 0; |
4545 |
|
store32(&pData[pos], bogusFileOffset); |
4546 |
pos += sizeof(uint32_t); |
pos += sizeof(uint32_t); |
4547 |
store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0); |
store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0); |
4548 |
pos += sizeof(uint32_t); |
pos += sizeof(uint32_t); |
4550 |
} |
} |
4551 |
} |
} |
4552 |
|
|
4553 |
|
void Instrument::UpdateScriptFileOffsets() { |
4554 |
|
// own gig format extensions |
4555 |
|
if (pScriptRefs) { |
4556 |
|
RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS); |
4557 |
|
RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL); |
4558 |
|
const int slotCount = pScriptRefs->size(); |
4559 |
|
const int headerSize = 3 * sizeof(uint32_t); |
4560 |
|
ckSCSL->SetPos(headerSize); |
4561 |
|
for (int i = 0; i < slotCount; ++i) { |
4562 |
|
uint32_t fileOffset = |
4563 |
|
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4564 |
|
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4565 |
|
CHUNK_HEADER_SIZE; |
4566 |
|
ckSCSL->WriteUint32(&fileOffset); |
4567 |
|
// jump over flags entry (containing the bypass flag) |
4568 |
|
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
4569 |
|
} |
4570 |
|
} |
4571 |
|
} |
4572 |
|
|
4573 |
/** |
/** |
4574 |
* Returns the appropriate Region for a triggered note. |
* Returns the appropriate Region for a triggered note. |
4575 |
* |
* |
4705 |
if (scriptPoolFileOffsets.empty()) return; |
if (scriptPoolFileOffsets.empty()) return; |
4706 |
File* pFile = (File*) GetParent(); |
File* pFile = (File*) GetParent(); |
4707 |
for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) { |
for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) { |
4708 |
uint32_t offset = scriptPoolFileOffsets[k].fileOffset; |
uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset; |
4709 |
for (uint i = 0; pFile->GetScriptGroup(i); ++i) { |
for (uint i = 0; pFile->GetScriptGroup(i); ++i) { |
4710 |
ScriptGroup* group = pFile->GetScriptGroup(i); |
ScriptGroup* group = pFile->GetScriptGroup(i); |
4711 |
for (uint s = 0; group->GetScript(s); ++s) { |
for (uint s = 0; group->GetScript(s); ++s) { |
4712 |
Script* script = group->GetScript(s); |
Script* script = group->GetScript(s); |
4713 |
if (script->pChunk) { |
if (script->pChunk) { |
4714 |
script->pChunk->SetPos(0); |
uint32_t offset = script->pChunk->GetFilePos() - |
4715 |
if (script->pChunk->GetFilePos() - |
script->pChunk->GetPos() - |
4716 |
script->pChunk->GetPos() - |
CHUNK_HEADER_SIZE; |
4717 |
CHUNK_HEADER_SIZE == offset) |
if (offset == soughtOffset) |
4718 |
{ |
{ |
4719 |
_ScriptPooolRef ref; |
_ScriptPooolRef ref; |
4720 |
ref.script = script; |
ref.script = script; |
5973 |
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
5974 |
} |
} |
5975 |
} |
} |
5976 |
|
|
5977 |
|
void File::UpdateFileOffsets() { |
5978 |
|
DLS::File::UpdateFileOffsets(); |
5979 |
|
|
5980 |
|
for (Instrument* instrument = GetFirstInstrument(); instrument; |
5981 |
|
instrument = GetNextInstrument()) |
5982 |
|
{ |
5983 |
|
instrument->UpdateScriptFileOffsets(); |
5984 |
|
} |
5985 |
|
} |
5986 |
|
|
5987 |
/** |
/** |
5988 |
* Enable / disable automatic loading. By default this properyt is |
* Enable / disable automatic loading. By default this properyt is |