/[svn]/libgig/trunk/src/gig.cpp
ViewVC logotype

Diff of /libgig/trunk/src/gig.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2599 by schoenebeck, Sat Jun 7 00:00:10 2014 UTC revision 2639 by schoenebeck, Mon Jun 16 13:22:50 2014 UTC
# Line 3652  namespace { Line 3652  namespace {
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            def->split_type = __resolveSplitType(newType);
3677        }
3678    
3679      DimensionRegion* Region::GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase) {      DimensionRegion* Region::GetDimensionRegionByBit(const std::map<dimension_t,int>& DimCase) {
3680          uint8_t bits[8] = {};          uint8_t bits[8] = {};
3681          for (std::map<dimension_t,int>::const_iterator it = DimCase.begin();          for (std::map<dimension_t,int>::const_iterator it = DimCase.begin();
# Line 4094  namespace { Line 4118  namespace {
4118              for (int i = 0; i < nameSize; ++i)              for (int i = 0; i < nameSize; ++i)
4119                  Name[i] = ckScri->ReadUint8();                  Name[i] = ckScri->ReadUint8();
4120              // to handle potential future extensions of the header              // to handle potential future extensions of the header
4121              ckScri->SetPos(headerSize - 6*sizeof(int32_t) + nameSize, RIFF::stream_curpos);              ckScri->SetPos(sizeof(int32_t) + headerSize);
4122              // read actual script data              // read actual script data
4123              uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos();              uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos();
4124              data.resize(scriptSize);              data.resize(scriptSize);
# Line 4179  namespace { Line 4203  namespace {
4203          this->pGroup = pGroup;          this->pGroup = pGroup;
4204      }      }
4205    
4206        /**
4207         * Returns the script group this script currently belongs to. Each script
4208         * is a member of exactly one ScriptGroup.
4209         *
4210         * @returns current script group
4211         */
4212        ScriptGroup* Script::GetGroup() const {
4213            return pGroup;
4214        }
4215    
4216      void Script::RemoveAllScriptReferences() {      void Script::RemoveAllScriptReferences() {
4217          File* pFile = pGroup->pFile;          File* pFile = pGroup->pFile;
4218          for (int i = 0; pFile->GetInstrument(i); ++i) {          for (int i = 0; pFile->GetInstrument(i); ++i) {
# Line 4388  namespace { Line 4422  namespace {
4422          if (lst3LS) {          if (lst3LS) {
4423              RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);              RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4424              if (ckSCSL) {              if (ckSCSL) {
4425                  int slotCount = ckSCSL->ReadUint32();                  int headerSize = ckSCSL->ReadUint32();
4426                  int slotSize  = ckSCSL->ReadUint32();                  int slotCount  = ckSCSL->ReadUint32();
4427                  int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future extensions                  if (slotCount) {
4428                  for (int i = 0; i < slotCount; ++i) {                      int slotSize  = ckSCSL->ReadUint32();
4429                      _ScriptPooolEntry e;                      ckSCSL->SetPos(headerSize); // in case of future header extensions
4430                      e.fileOffset = ckSCSL->ReadUint32();                      int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future slot extensions
4431                      e.bypass     = ckSCSL->ReadUint32() & 1;                      for (int i = 0; i < slotCount; ++i) {
4432                      if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions                          _ScriptPooolEntry e;
4433                      scriptPoolFileOffsets.push_back(e);                          e.fileOffset = ckSCSL->ReadUint32();
4434                            e.bypass     = ckSCSL->ReadUint32() & 1;
4435                            if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions
4436                            scriptPoolFileOffsets.push_back(e);
4437                        }
4438                  }                  }
4439              }              }
4440          }          }
# Line 4482  namespace { Line 4520  namespace {
4520         if (pScriptRefs) {         if (pScriptRefs) {
4521             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4522             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);
4523             const int totalSize = pScriptRefs->size() * 2*sizeof(uint32_t);             const int slotCount = pScriptRefs->size();
4524               const int headerSize = 3 * sizeof(uint32_t);
4525               const int slotSize  = 2 * sizeof(uint32_t);
4526               const int totalChunkSize = headerSize + slotCount * slotSize;
4527             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4528             if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalSize);             if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalChunkSize);
4529             else ckSCSL->Resize(totalSize);             else ckSCSL->Resize(totalChunkSize);
4530             uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData();             uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData();
4531             for (int i = 0, pos = 0; i < pScriptRefs->size(); ++i) {             int pos = 0;
4532                 int fileOffset =             store32(&pData[pos], headerSize);
4533                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -             pos += sizeof(uint32_t);
4534                      (*pScriptRefs)[i].script->pChunk->GetPos() -             store32(&pData[pos], slotCount);
4535                      CHUNK_HEADER_SIZE;             pos += sizeof(uint32_t);
4536                 store32(&pData[pos], fileOffset);             store32(&pData[pos], slotSize);
4537               pos += sizeof(uint32_t);
4538               for (int i = 0; i < slotCount; ++i) {
4539                   // arbitrary value, the actual file offset will be updated in
4540                   // UpdateScriptFileOffsets() after the file has been resized
4541                   int bogusFileOffset = 0;
4542                   store32(&pData[pos], bogusFileOffset);
4543                 pos += sizeof(uint32_t);                 pos += sizeof(uint32_t);
4544                 store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0);                 store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0);
4545                 pos += sizeof(uint32_t);                 pos += sizeof(uint32_t);
# Line 4500  namespace { Line 4547  namespace {
4547         }         }
4548      }      }
4549    
4550        void Instrument::UpdateScriptFileOffsets() {
4551           // own gig format extensions
4552           if (pScriptRefs) {
4553               RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4554               RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4555               const int slotCount = pScriptRefs->size();
4556               const int headerSize = 3 * sizeof(uint32_t);
4557               ckSCSL->SetPos(headerSize);
4558               for (int i = 0; i < slotCount; ++i) {
4559                   uint32_t fileOffset =
4560                        (*pScriptRefs)[i].script->pChunk->GetFilePos() -
4561                        (*pScriptRefs)[i].script->pChunk->GetPos() -
4562                        CHUNK_HEADER_SIZE;
4563                   ckSCSL->WriteUint32(&fileOffset);
4564                   // jump over flags entry (containing the bypass flag)
4565                   ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);
4566               }
4567           }        
4568        }
4569    
4570      /**      /**
4571       * Returns the appropriate Region for a triggered note.       * Returns the appropriate Region for a triggered note.
4572       *       *
# Line 4635  namespace { Line 4702  namespace {
4702          if (scriptPoolFileOffsets.empty()) return;          if (scriptPoolFileOffsets.empty()) return;
4703          File* pFile = (File*) GetParent();          File* pFile = (File*) GetParent();
4704          for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) {          for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) {
4705              uint32_t offset = scriptPoolFileOffsets[k].fileOffset;              uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset;
4706              for (uint i = 0; pFile->GetScriptGroup(i); ++i) {              for (uint i = 0; pFile->GetScriptGroup(i); ++i) {
4707                  ScriptGroup* group = pFile->GetScriptGroup(i);                  ScriptGroup* group = pFile->GetScriptGroup(i);
4708                  for (uint s = 0; group->GetScript(s); ++s) {                  for (uint s = 0; group->GetScript(s); ++s) {
4709                      Script* script = group->GetScript(s);                      Script* script = group->GetScript(s);
4710                      if (script->pChunk) {                      if (script->pChunk) {
4711                          script->pChunk->SetPos(0);                          uint32_t offset = script->pChunk->GetFilePos() -
4712                          if (script->pChunk->GetFilePos() -                                            script->pChunk->GetPos() -
4713                              script->pChunk->GetPos() -                                            CHUNK_HEADER_SIZE;
4714                              CHUNK_HEADER_SIZE == offset)                          if (offset == soughtOffset)
4715                          {                          {
4716                              _ScriptPooolRef ref;                              _ScriptPooolRef ref;
4717                              ref.script = script;                              ref.script = script;
# Line 5903  namespace { Line 5970  namespace {
5970              if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);              if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);
5971          }          }
5972      }      }
5973        
5974        void File::UpdateFileOffsets() {
5975            DLS::File::UpdateFileOffsets();
5976    
5977            for (Instrument* instrument = GetFirstInstrument(); instrument;
5978                 instrument = GetNextInstrument())
5979            {
5980                instrument->UpdateScriptFileOffsets();
5981            }
5982        }
5983    
5984      /**      /**
5985       * Enable / disable automatic loading. By default this properyt is       * Enable / disable automatic loading. By default this properyt is

Legend:
Removed from v.2599  
changed lines
  Added in v.2639

  ViewVC Help
Powered by ViewVC