/[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 2640 by schoenebeck, Mon Jun 16 14:54:06 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            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();
# Line 4094  namespace { Line 4121  namespace {
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);
# Line 4179  namespace { Line 4206  namespace {
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) {
# Line 4388  namespace { Line 4425  namespace {
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          }          }
# Line 4482  namespace { Line 4523  namespace {
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);
# Line 4500  namespace { Line 4550  namespace {
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       *       *
# Line 4635  namespace { Line 4705  namespace {
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;
# Line 5903  namespace { Line 5973  namespace {
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

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

  ViewVC Help
Powered by ViewVC