/[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 2584 by schoenebeck, Sat May 31 20:54:39 2014 UTC revision 2609 by schoenebeck, Sun Jun 8 19:00:30 2014 UTC
# Line 3759  namespace { Line 3759  namespace {
3759          return dimreg;          return dimreg;
3760      }      }
3761    
3762        int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) {
3763            uint8_t bits;
3764            int veldim = -1;
3765            int velbitpos;
3766            int bitpos = 0;
3767            int dimregidx = 0;
3768            for (uint i = 0; i < Dimensions; i++) {
3769                if (pDimensionDefinitions[i].dimension == dimension_velocity) {
3770                    // the velocity dimension must be handled after the other dimensions
3771                    veldim = i;
3772                    velbitpos = bitpos;
3773                } else {
3774                    switch (pDimensionDefinitions[i].split_type) {
3775                        case split_type_normal:
3776                            if (pDimensionRegions[0]->DimensionUpperLimits[i]) {
3777                                // gig3: all normal dimensions (not just the velocity dimension) have custom zone ranges
3778                                for (bits = 0 ; bits < pDimensionDefinitions[i].zones ; bits++) {
3779                                    if (DimValues[i] <= pDimensionRegions[bits << bitpos]->DimensionUpperLimits[i]) break;
3780                                }
3781                            } else {
3782                                // gig2: evenly sized zones
3783                                bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size);
3784                            }
3785                            break;
3786                        case split_type_bit: // the value is already the sought dimension bit number
3787                            const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff;
3788                            bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed
3789                            break;
3790                    }
3791                    dimregidx |= bits << bitpos;
3792                }
3793                bitpos += pDimensionDefinitions[i].bits;
3794            }
3795            dimregidx &= 255;
3796            DimensionRegion* dimreg = pDimensionRegions[dimregidx];
3797            if (!dimreg) return -1;
3798            if (veldim != -1) {
3799                // (dimreg is now the dimension region for the lowest velocity)
3800                if (dimreg->VelocityTable) // custom defined zone ranges
3801                    bits = dimreg->VelocityTable[DimValues[veldim] & 127];
3802                else // normal split type
3803                    bits = uint8_t((DimValues[veldim] & 127) / pDimensionDefinitions[veldim].zone_size);
3804    
3805                const uint8_t limiter_mask = (1 << pDimensionDefinitions[veldim].bits) - 1;
3806                dimregidx |= (bits & limiter_mask) << velbitpos;
3807                dimregidx &= 255;
3808            }
3809            return dimregidx;
3810        }
3811    
3812      /**      /**
3813       * Returns the appropriate DimensionRegion for the given dimension bit       * Returns the appropriate DimensionRegion for the given dimension bit
3814       * numbers (zone index). You usually use <i>GetDimensionRegionByValue</i>       * numbers (zone index). You usually use <i>GetDimensionRegionByValue</i>
# Line 4044  namespace { Line 4094  namespace {
4094              for (int i = 0; i < nameSize; ++i)              for (int i = 0; i < nameSize; ++i)
4095                  Name[i] = ckScri->ReadUint8();                  Name[i] = ckScri->ReadUint8();
4096              // to handle potential future extensions of the header              // to handle potential future extensions of the header
4097              ckScri->SetPos(headerSize - 6*sizeof(int32_t) + nameSize, RIFF::stream_curpos);              ckScri->SetPos(sizeof(int32_t) + headerSize);
4098              // read actual script data              // read actual script data
4099              uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos();              uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos();
4100              data.resize(scriptSize);              data.resize(scriptSize);
# Line 4129  namespace { Line 4179  namespace {
4179          this->pGroup = pGroup;          this->pGroup = pGroup;
4180      }      }
4181    
4182        /**
4183         * Returns the script group this script currently belongs to. Each script
4184         * is a member of exactly one ScriptGroup.
4185         *
4186         * @returns current script group
4187         */
4188        ScriptGroup* Script::GetGroup() const {
4189            return pGroup;
4190        }
4191    
4192      void Script::RemoveAllScriptReferences() {      void Script::RemoveAllScriptReferences() {
4193          File* pFile = pGroup->pFile;          File* pFile = pGroup->pFile;
4194          for (int i = 0; pFile->GetInstrument(i); ++i) {          for (int i = 0; pFile->GetInstrument(i); ++i) {
# Line 4338  namespace { Line 4398  namespace {
4398          if (lst3LS) {          if (lst3LS) {
4399              RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);              RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4400              if (ckSCSL) {              if (ckSCSL) {
4401                  int slotCount = ckSCSL->ReadUint32();                  int headerSize = ckSCSL->ReadUint32();
4402                  int slotSize  = ckSCSL->ReadUint32();                  int slotCount  = ckSCSL->ReadUint32();
4403                  int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future extensions                  if (slotCount) {
4404                  for (int i = 0; i < slotCount; ++i) {                      int slotSize  = ckSCSL->ReadUint32();
4405                      _ScriptPooolEntry e;                      ckSCSL->SetPos(headerSize); // in case of future header extensions
4406                      e.fileOffset = ckSCSL->ReadUint32();                      int unknownSpace = slotSize - 2*sizeof(uint32_t); // in case of future slot extensions
4407                      e.bypass     = ckSCSL->ReadUint32() & 1;                      for (int i = 0; i < slotCount; ++i) {
4408                      if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions                          _ScriptPooolEntry e;
4409                      scriptPoolFileOffsets.push_back(e);                          e.fileOffset = ckSCSL->ReadUint32();
4410                            e.bypass     = ckSCSL->ReadUint32() & 1;
4411                            if (unknownSpace) ckSCSL->SetPos(unknownSpace, RIFF::stream_curpos); // in case of future extensions
4412                            scriptPoolFileOffsets.push_back(e);
4413                        }
4414                  }                  }
4415              }              }
4416          }          }
# Line 4432  namespace { Line 4496  namespace {
4496         if (pScriptRefs) {         if (pScriptRefs) {
4497             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4498             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);
4499             const int totalSize = pScriptRefs->size() * 2*sizeof(uint32_t);             const int slotCount = pScriptRefs->size();
4500               const int headerSize = 3 * sizeof(uint32_t);
4501               const int slotSize  = 2 * sizeof(uint32_t);
4502               const int totalChunkSize = headerSize + slotCount * slotSize;
4503             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4504             if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalSize);             if (!ckSCSL) ckSCSL = lst3LS->AddSubChunk(CHUNK_ID_SCSL, totalChunkSize);
4505             else ckSCSL->Resize(totalSize);             else ckSCSL->Resize(totalChunkSize);
4506             uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData();             uint8_t* pData = (uint8_t*) ckSCSL->LoadChunkData();
4507             for (int i = 0, pos = 0; i < pScriptRefs->size(); ++i) {             int pos = 0;
4508                 int fileOffset =             store32(&pData[pos], headerSize);
4509                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -             pos += sizeof(uint32_t);
4510                      (*pScriptRefs)[i].script->pChunk->GetPos() -             store32(&pData[pos], slotCount);
4511                      CHUNK_HEADER_SIZE;             pos += sizeof(uint32_t);
4512                 store32(&pData[pos], fileOffset);             store32(&pData[pos], slotSize);
4513               pos += sizeof(uint32_t);
4514               for (int i = 0; i < slotCount; ++i) {
4515                   // arbitrary value, the actual file offset will be updated in
4516                   // UpdateScriptFileOffsets() after the file has been resized
4517                   int bogusFileOffset = 0;
4518                   store32(&pData[pos], bogusFileOffset);
4519                 pos += sizeof(uint32_t);                 pos += sizeof(uint32_t);
4520                 store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0);                 store32(&pData[pos], (*pScriptRefs)[i].bypass ? 1 : 0);
4521                 pos += sizeof(uint32_t);                 pos += sizeof(uint32_t);
# Line 4450  namespace { Line 4523  namespace {
4523         }         }
4524      }      }
4525    
4526        void Instrument::UpdateScriptFileOffsets() {
4527           // own gig format extensions
4528           if (pScriptRefs) {
4529               RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4530               RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4531               const int slotCount = pScriptRefs->size();
4532               const int headerSize = 3 * sizeof(uint32_t);
4533               ckSCSL->SetPos(headerSize);
4534               for (int i = 0; i < slotCount; ++i) {
4535                   uint32_t fileOffset =
4536                        (*pScriptRefs)[i].script->pChunk->GetFilePos() -
4537                        (*pScriptRefs)[i].script->pChunk->GetPos() -
4538                        CHUNK_HEADER_SIZE;
4539                   ckSCSL->WriteUint32(&fileOffset);
4540                   // jump over flags entry (containing the bypass flag)
4541                   ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);
4542               }
4543           }        
4544        }
4545    
4546      /**      /**
4547       * Returns the appropriate Region for a triggered note.       * Returns the appropriate Region for a triggered note.
4548       *       *
# Line 4585  namespace { Line 4678  namespace {
4678          if (scriptPoolFileOffsets.empty()) return;          if (scriptPoolFileOffsets.empty()) return;
4679          File* pFile = (File*) GetParent();          File* pFile = (File*) GetParent();
4680          for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) {          for (uint k = 0; k < scriptPoolFileOffsets.size(); ++k) {
4681              uint32_t offset = scriptPoolFileOffsets[k].fileOffset;              uint32_t soughtOffset = scriptPoolFileOffsets[k].fileOffset;
4682              for (uint i = 0; pFile->GetScriptGroup(i); ++i) {              for (uint i = 0; pFile->GetScriptGroup(i); ++i) {
4683                  ScriptGroup* group = pFile->GetScriptGroup(i);                  ScriptGroup* group = pFile->GetScriptGroup(i);
4684                  for (uint s = 0; group->GetScript(s); ++s) {                  for (uint s = 0; group->GetScript(s); ++s) {
4685                      Script* script = group->GetScript(s);                      Script* script = group->GetScript(s);
4686                      if (script->pChunk) {                      if (script->pChunk) {
4687                          script->pChunk->SetPos(0);                          uint32_t offset = script->pChunk->GetFilePos() -
4688                          if (script->pChunk->GetFilePos() -                                            script->pChunk->GetPos() -
4689                              script->pChunk->GetPos() -                                            CHUNK_HEADER_SIZE;
4690                              CHUNK_HEADER_SIZE == offset)                          if (offset == soughtOffset)
4691                          {                          {
4692                              _ScriptPooolRef ref;                              _ScriptPooolRef ref;
4693                              ref.script = script;                              ref.script = script;
# Line 4610  namespace { Line 4703  namespace {
4703          scriptPoolFileOffsets.clear();          scriptPoolFileOffsets.clear();
4704      }      }
4705    
4706      /** @brief Add new instrument script slot (gig format extension)      /** @brief Get instrument script (gig format extension).
4707         *
4708         * Returns the real-time instrument script of instrument script slot
4709         * @a index.
4710         *
4711         * @note This is an own format extension which did not exist i.e. in the
4712         * GigaStudio 4 software. It will currently only work with LinuxSampler and
4713         * gigedit.
4714         *
4715         * @param index - instrument script slot index
4716         * @returns script or NULL if index is out of bounds
4717         */
4718        Script* Instrument::GetScriptOfSlot(uint index) {
4719            LoadScripts();
4720            if (index >= pScriptRefs->size()) return NULL;
4721            return pScriptRefs->at(index).script;
4722        }
4723    
4724        /** @brief Add new instrument script slot (gig format extension).
4725       *       *
4726       * Add the given real-time instrument script reference to this instrument,       * Add the given real-time instrument script reference to this instrument,
4727       * which shall be executed by the sampler for for this instrument. The       * which shall be executed by the sampler for for this instrument. The
# Line 5835  namespace { Line 5946  namespace {
5946              if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);              if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);
5947          }          }
5948      }      }
5949        
5950        void File::UpdateFileOffsets() {
5951            DLS::File::UpdateFileOffsets();
5952    
5953            for (Instrument* instrument = GetFirstInstrument(); instrument;
5954                 instrument = GetNextInstrument())
5955            {
5956                instrument->UpdateScriptFileOffsets();
5957            }
5958        }
5959    
5960      /**      /**
5961       * Enable / disable automatic loading. By default this properyt is       * Enable / disable automatic loading. By default this properyt is

Legend:
Removed from v.2584  
changed lines
  Added in v.2609

  ViewVC Help
Powered by ViewVC