3890 |
// now tempRegion's dimensions and DimensionRegions basically reflect |
// now tempRegion's dimensions and DimensionRegions basically reflect |
3891 |
// what we wanted to get for this actual Region here, so we now just |
// what we wanted to get for this actual Region here, so we now just |
3892 |
// delete and recreate the dimension in question with the new amount |
// delete and recreate the dimension in question with the new amount |
3893 |
// zones and then copy back from tempRegion |
// zones and then copy back from tempRegion. we're actually deleting and |
3894 |
DeleteDimension(oldDef); |
// recreating all dimensions here, to avoid altering the precise order |
3895 |
AddDimension(&newDef); |
// of the dimensions (which would not be an error per se, but it would |
3896 |
|
// cause usability issues with instrument editors) |
3897 |
|
{ |
3898 |
|
std::vector<dimension_def_t> oldDefs; |
3899 |
|
for (int i = 0; i < Dimensions; ++i) |
3900 |
|
oldDefs.push_back(pDimensionDefinitions[i]); // copy, don't reference |
3901 |
|
for (int i = Dimensions - 1; i >= 0; --i) |
3902 |
|
DeleteDimension(&pDimensionDefinitions[i]); |
3903 |
|
for (int i = 0; i < oldDefs.size(); ++i) { |
3904 |
|
dimension_def_t& def = oldDefs[i]; |
3905 |
|
AddDimension( |
3906 |
|
(def.dimension == newDef.dimension) ? &newDef : &def |
3907 |
|
); |
3908 |
|
} |
3909 |
|
} |
3910 |
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
for (int iSrc = 0; iSrc < 256; ++iSrc) { |
3911 |
DimensionRegion* srcDimRgn = tempRgn->pDimensionRegions[iSrc]; |
DimensionRegion* srcDimRgn = tempRgn->pDimensionRegions[iSrc]; |
3912 |
if (!srcDimRgn) continue; |
if (!srcDimRgn) continue; |
4046 |
// delete and recreate the dimension in question with the new amount |
// delete and recreate the dimension in question with the new amount |
4047 |
// zones and then copy back from tempRegion. we're actually deleting and |
// zones and then copy back from tempRegion. we're actually deleting and |
4048 |
// recreating all dimensions here, to avoid altering the precise order |
// recreating all dimensions here, to avoid altering the precise order |
4049 |
// of the dimensions (which would not be an error per so, but it would |
// of the dimensions (which would not be an error per se, but it would |
4050 |
// cause usability issues with instrument editors) |
// cause usability issues with instrument editors) |
4051 |
{ |
{ |
4052 |
std::vector<dimension_def_t> oldDefs; |
std::vector<dimension_def_t> oldDefs; |
4588 |
Compression = (Compression_t) ckScri->ReadUint32(); |
Compression = (Compression_t) ckScri->ReadUint32(); |
4589 |
Encoding = (Encoding_t) ckScri->ReadUint32(); |
Encoding = (Encoding_t) ckScri->ReadUint32(); |
4590 |
Language = (Language_t) ckScri->ReadUint32(); |
Language = (Language_t) ckScri->ReadUint32(); |
4591 |
Bypass = (Language_t) ckScri->ReadUint32() & 1; |
Bypass = ckScri->ReadUint32() & 1; |
4592 |
crc = ckScri->ReadUint32(); |
crc = ckScri->ReadUint32(); |
4593 |
uint32_t nameSize = ckScri->ReadUint32(); |
uint32_t nameSize = ckScri->ReadUint32(); |
4594 |
Name.resize(nameSize, ' '); |
Name.resize(nameSize, ' '); |
4595 |
for (int i = 0; i < nameSize; ++i) |
for (int i = 0; i < nameSize; ++i) |
4596 |
Name[i] = ckScri->ReadUint8(); |
Name[i] = ckScri->ReadUint8(); |
4597 |
|
// check if an uuid was already stored along with this script |
4598 |
|
if (headerSize >= 6*sizeof(int32_t) + nameSize + 16) { // yes ... |
4599 |
|
for (uint i = 0; i < 16; ++i) { |
4600 |
|
Uuid[i] = ckScri->ReadUint8(); |
4601 |
|
} |
4602 |
|
} else { // no uuid yet, generate one now ... |
4603 |
|
GenerateUuid(); |
4604 |
|
} |
4605 |
// to handle potential future extensions of the header |
// to handle potential future extensions of the header |
4606 |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
ckScri->SetPos(sizeof(int32_t) + headerSize); |
4607 |
// read actual script data |
// read actual script data |
4616 |
Bypass = false; |
Bypass = false; |
4617 |
crc = 0; |
crc = 0; |
4618 |
Name = "Unnamed Script"; |
Name = "Unnamed Script"; |
4619 |
|
GenerateUuid(); |
4620 |
} |
} |
4621 |
} |
} |
4622 |
|
|
4671 |
__calculateCRC(&data[0], data.size(), crc); |
__calculateCRC(&data[0], data.size(), crc); |
4672 |
__finalizeCRC(crc); |
__finalizeCRC(crc); |
4673 |
// make sure chunk exists and has the required size |
// make sure chunk exists and has the required size |
4674 |
const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size(); |
const file_offset_t chunkSize = |
4675 |
|
(file_offset_t) 7*sizeof(int32_t) + Name.size() + 16 + data.size(); |
4676 |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize); |
4677 |
else pChunk->Resize(chunkSize); |
else pChunk->Resize(chunkSize); |
4678 |
// fill the chunk data to be written to disk |
// fill the chunk data to be written to disk |
4679 |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
uint8_t* pData = (uint8_t*) pChunk->LoadChunkData(); |
4680 |
int pos = 0; |
int pos = 0; |
4681 |
store32(&pData[pos], uint32_t(6*sizeof(int32_t) + Name.size())); // total header size |
store32(&pData[pos], uint32_t(6*sizeof(int32_t) + Name.size() + 16)); // total header size |
4682 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4683 |
store32(&pData[pos], Compression); |
store32(&pData[pos], Compression); |
4684 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4694 |
pos += sizeof(int32_t); |
pos += sizeof(int32_t); |
4695 |
for (int i = 0; i < Name.size(); ++i, ++pos) |
for (int i = 0; i < Name.size(); ++i, ++pos) |
4696 |
pData[pos] = Name[i]; |
pData[pos] = Name[i]; |
4697 |
|
for (int i = 0; i < 16; ++i, ++pos) |
4698 |
|
pData[pos] = Uuid[i]; |
4699 |
for (int i = 0; i < data.size(); ++i, ++pos) |
for (int i = 0; i < data.size(); ++i, ++pos) |
4700 |
pData[pos] = data[i]; |
pData[pos] = data[i]; |
4701 |
} |
} |
4702 |
|
|
4703 |
/** |
/** |
4704 |
|
* Generate a new Universally Unique Identifier (UUID) for this script. |
4705 |
|
*/ |
4706 |
|
void Script::GenerateUuid() { |
4707 |
|
DLS::dlsid_t dlsid; |
4708 |
|
DLS::Resource::GenerateDLSID(&dlsid); |
4709 |
|
Uuid[0] = dlsid.ulData1 & 0xff; |
4710 |
|
Uuid[1] = dlsid.ulData1 >> 8 & 0xff; |
4711 |
|
Uuid[2] = dlsid.ulData1 >> 16 & 0xff; |
4712 |
|
Uuid[3] = dlsid.ulData1 >> 24 & 0xff; |
4713 |
|
Uuid[4] = dlsid.usData2 & 0xff; |
4714 |
|
Uuid[5] = dlsid.usData2 >> 8 & 0xff; |
4715 |
|
Uuid[6] = dlsid.usData3 & 0xff; |
4716 |
|
Uuid[7] = dlsid.usData3 >> 8 & 0xff; |
4717 |
|
Uuid[8] = dlsid.abData[0]; |
4718 |
|
Uuid[9] = dlsid.abData[1]; |
4719 |
|
Uuid[10] = dlsid.abData[2]; |
4720 |
|
Uuid[11] = dlsid.abData[3]; |
4721 |
|
Uuid[12] = dlsid.abData[4]; |
4722 |
|
Uuid[13] = dlsid.abData[5]; |
4723 |
|
Uuid[14] = dlsid.abData[6]; |
4724 |
|
Uuid[15] = dlsid.abData[7]; |
4725 |
|
} |
4726 |
|
|
4727 |
|
/** |
4728 |
* Move this script from its current ScriptGroup to another ScriptGroup |
* Move this script from its current ScriptGroup to another ScriptGroup |
4729 |
* given by @a pGroup. |
* given by @a pGroup. |
4730 |
* |
* |