/[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 2989 by schoenebeck, Sat Sep 24 14:00:46 2016 UTC revision 3323 by schoenebeck, Thu Jul 20 22:09:54 2017 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2016 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2017 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 24  Line 24 
24  #include "gig.h"  #include "gig.h"
25    
26  #include "helper.h"  #include "helper.h"
27    #include "Serialization.h"
28    
29  #include <algorithm>  #include <algorithm>
30  #include <math.h>  #include <math.h>
# Line 55  Line 56 
56  #define GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(x)    ((x & 0x03) << 3)  #define GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(x)    ((x & 0x03) << 3)
57  #define GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(x)  ((x & 0x03) << 5)  #define GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(x)  ((x & 0x03) << 5)
58    
59    #define SRLZ(member) \
60        archive->serializeMember(*this, member, #member);
61    
62  namespace gig {  namespace gig {
63    
64  // *************** Internal functions for sample decompression ***************  // *************** Internal functions for sample decompression ***************
# Line 269  namespace { Line 273  namespace {
273       * steps.       * steps.
274       *       *
275       * Once the whole data was processed by __calculateCRC(), one should       * Once the whole data was processed by __calculateCRC(), one should
276       * call __encodeCRC() to get the final CRC result.       * call __finalizeCRC() to get the final CRC result.
277       *       *
278       * @param buf     - pointer to data the CRC shall be calculated of       * @param buf     - pointer to data the CRC shall be calculated of
279       * @param bufSize - size of the data to be processed       * @param bufSize - size of the data to be processed
280       * @param crc     - variable the CRC sum shall be stored to       * @param crc     - variable the CRC sum shall be stored to
281       */       */
282      static void __calculateCRC(unsigned char* buf, int bufSize, uint32_t& crc) {      static void __calculateCRC(unsigned char* buf, size_t bufSize, uint32_t& crc) {
283          for (int i = 0 ; i < bufSize ; i++) {          for (size_t i = 0 ; i < bufSize ; i++) {
284              crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);              crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);
285          }          }
286      }      }
# Line 286  namespace { Line 290  namespace {
290       *       *
291       * @param crc - variable previously passed to __calculateCRC()       * @param crc - variable previously passed to __calculateCRC()
292       */       */
293      inline static uint32_t __encodeCRC(const uint32_t& crc) {      inline static void __finalizeCRC(uint32_t& crc) {
294          return crc ^ 0xffffffff;          crc ^= 0xffffffff;
295      }      }
296    
297    
# Line 315  namespace { Line 319  namespace {
319    
320    
321    
322    // *************** leverage_ctrl_t ***************
323    // *
324    
325        void leverage_ctrl_t::serialize(Serialization::Archive* archive) {
326            SRLZ(type);
327            SRLZ(controller_number);
328        }
329    
330    
331    
332    // *************** crossfade_t ***************
333    // *
334    
335        void crossfade_t::serialize(Serialization::Archive* archive) {
336            SRLZ(in_start);
337            SRLZ(in_end);
338            SRLZ(out_start);
339            SRLZ(out_end);
340        }
341    
342    
343    
344    // *************** eg_opt_t ***************
345    // *
346    
347        eg_opt_t::eg_opt_t() {
348            AttackCancel     = true;
349            AttackHoldCancel = true;
350            DecayCancel      = true;
351            ReleaseCancel    = true;
352        }
353    
354        void eg_opt_t::serialize(Serialization::Archive* archive) {
355            SRLZ(AttackCancel);
356            SRLZ(AttackHoldCancel);
357            SRLZ(DecayCancel);
358            SRLZ(ReleaseCancel);
359        }
360    
361    
362    
363  // *************** Sample ***************  // *************** Sample ***************
364  // *  // *
365    
# Line 1294  namespace { Line 1339  namespace {
1339          // if this is the last write, update the checksum chunk in the          // if this is the last write, update the checksum chunk in the
1340          // file          // file
1341          if (pCkData->GetPos() == pCkData->GetSize()) {          if (pCkData->GetPos() == pCkData->GetSize()) {
1342                __finalizeCRC(crc);
1343              File* pFile = static_cast<File*>(GetParent());              File* pFile = static_cast<File*>(GetParent());
1344              pFile->SetSampleChecksum(this, __encodeCRC(crc));              pFile->SetSampleChecksum(this, crc);
1345          }          }
1346          return res;          return res;
1347      }      }
# Line 1396  namespace { Line 1442  namespace {
1442       * @see GetWaveDataCRC32Checksum()       * @see GetWaveDataCRC32Checksum()
1443       */       */
1444      bool Sample::VerifyWaveData(uint32_t* pActually) {      bool Sample::VerifyWaveData(uint32_t* pActually) {
1445          File* pFile = static_cast<File*>(GetParent());          //File* pFile = static_cast<File*>(GetParent());
1446          uint32_t crc = CalculateWaveDataChecksum();          uint32_t crc = CalculateWaveDataChecksum();
1447          if (pActually) *pActually = crc;          if (pActually) *pActually = crc;
1448          return crc == this->crc;          return crc == this->crc;
# Line 1416  namespace { Line 1462  namespace {
1462              if (nRead <= 0) break;              if (nRead <= 0) break;
1463              __calculateCRC(&buffer[0], nRead * FrameSize, crc);              __calculateCRC(&buffer[0], nRead * FrameSize, crc);
1464          }          }
1465          __encodeCRC(crc);          __finalizeCRC(crc);
1466          return crc;          return crc;
1467      }      }
1468    
# Line 1630  namespace { Line 1676  namespace {
1676              EG2Attack                       = 0.0;              EG2Attack                       = 0.0;
1677              EG2Decay1                       = 0.005;              EG2Decay1                       = 0.005;
1678              EG2Sustain                      = 1000;              EG2Sustain                      = 1000;
1679              EG2Release                      = 0.3;              EG2Release                      = 60;
1680              LFO2ControlDepth                = 0;              LFO2ControlDepth                = 0;
1681              LFO2Frequency                   = 1.0;              LFO2Frequency                   = 1.0;
1682              LFO2InternalDepth               = 0;              LFO2InternalDepth               = 0;
# Line 1684  namespace { Line 1730  namespace {
1730              VCFType                         = vcf_type_lowpass;              VCFType                         = vcf_type_lowpass;
1731              memset(DimensionUpperLimits, 127, 8);              memset(DimensionUpperLimits, 127, 8);
1732          }          }
1733            // format extension for EG behavior options, these will *NOT* work with
1734            // Gigasampler/GigaStudio !
1735            RIFF::Chunk* lsde = _3ewl->GetSubChunk(CHUNK_ID_LSDE);
1736            if (lsde) {
1737                unsigned char byte = lsde->ReadUint8();
1738                EGOptions.AttackCancel     = byte & 1;
1739                EGOptions.AttackHoldCancel = byte & (1 << 1);
1740                EGOptions.DecayCancel      = byte & (1 << 2);
1741                EGOptions.ReleaseCancel    = byte & (1 << 3);
1742            }
1743    
1744          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,
1745                                                       VelocityResponseDepth,                                                       VelocityResponseDepth,
# Line 1789  namespace { Line 1845  namespace {
1845          }          }
1846      }      }
1847    
1848        void DimensionRegion::serialize(Serialization::Archive* archive) {
1849            // in case this class will become backward incompatible one day,
1850            // then set a version and minimum version for this class like:
1851            //archive->setVersion(*this, 2);
1852            //archive->setMinVersion(*this, 1);
1853    
1854            SRLZ(VelocityUpperLimit);
1855            SRLZ(EG1PreAttack);
1856            SRLZ(EG1Attack);
1857            SRLZ(EG1Decay1);
1858            SRLZ(EG1Decay2);
1859            SRLZ(EG1InfiniteSustain);
1860            SRLZ(EG1Sustain);
1861            SRLZ(EG1Release);
1862            SRLZ(EG1Hold);
1863            SRLZ(EG1Controller);
1864            SRLZ(EG1ControllerInvert);
1865            SRLZ(EG1ControllerAttackInfluence);
1866            SRLZ(EG1ControllerDecayInfluence);
1867            SRLZ(EG1ControllerReleaseInfluence);
1868            SRLZ(LFO1Frequency);
1869            SRLZ(LFO1InternalDepth);
1870            SRLZ(LFO1ControlDepth);
1871            SRLZ(LFO1Controller);
1872            SRLZ(LFO1FlipPhase);
1873            SRLZ(LFO1Sync);
1874            SRLZ(EG2PreAttack);
1875            SRLZ(EG2Attack);
1876            SRLZ(EG2Decay1);
1877            SRLZ(EG2Decay2);
1878            SRLZ(EG2InfiniteSustain);
1879            SRLZ(EG2Sustain);
1880            SRLZ(EG2Release);
1881            SRLZ(EG2Controller);
1882            SRLZ(EG2ControllerInvert);
1883            SRLZ(EG2ControllerAttackInfluence);
1884            SRLZ(EG2ControllerDecayInfluence);
1885            SRLZ(EG2ControllerReleaseInfluence);
1886            SRLZ(LFO2Frequency);
1887            SRLZ(LFO2InternalDepth);
1888            SRLZ(LFO2ControlDepth);
1889            SRLZ(LFO2Controller);
1890            SRLZ(LFO2FlipPhase);
1891            SRLZ(LFO2Sync);
1892            SRLZ(EG3Attack);
1893            SRLZ(EG3Depth);
1894            SRLZ(LFO3Frequency);
1895            SRLZ(LFO3InternalDepth);
1896            SRLZ(LFO3ControlDepth);
1897            SRLZ(LFO3Controller);
1898            SRLZ(LFO3Sync);
1899            SRLZ(VCFEnabled);
1900            SRLZ(VCFType);
1901            SRLZ(VCFCutoffController);
1902            SRLZ(VCFCutoffControllerInvert);
1903            SRLZ(VCFCutoff);
1904            SRLZ(VCFVelocityCurve);
1905            SRLZ(VCFVelocityScale);
1906            SRLZ(VCFVelocityDynamicRange);
1907            SRLZ(VCFResonance);
1908            SRLZ(VCFResonanceDynamic);
1909            SRLZ(VCFResonanceController);
1910            SRLZ(VCFKeyboardTracking);
1911            SRLZ(VCFKeyboardTrackingBreakpoint);
1912            SRLZ(VelocityResponseCurve);
1913            SRLZ(VelocityResponseDepth);
1914            SRLZ(VelocityResponseCurveScaling);
1915            SRLZ(ReleaseVelocityResponseCurve);
1916            SRLZ(ReleaseVelocityResponseDepth);
1917            SRLZ(ReleaseTriggerDecay);
1918            SRLZ(Crossfade);
1919            SRLZ(PitchTrack);
1920            SRLZ(DimensionBypass);
1921            SRLZ(Pan);
1922            SRLZ(SelfMask);
1923            SRLZ(AttenuationController);
1924            SRLZ(InvertAttenuationController);
1925            SRLZ(AttenuationControllerThreshold);
1926            SRLZ(ChannelOffset);
1927            SRLZ(SustainDefeat);
1928            SRLZ(MSDecode);
1929            //SRLZ(SampleStartOffset);
1930            SRLZ(SampleAttenuation);
1931            SRLZ(EGOptions);
1932    
1933            // derived attributes from DLS::Sampler
1934            SRLZ(FineTune);
1935            SRLZ(Gain);
1936        }
1937    
1938      /**      /**
1939       * Updates the respective member variable and updates @c SampleAttenuation       * Updates the respective member variable and updates @c SampleAttenuation
1940       * which depends on this value.       * which depends on this value.
# Line 1829  namespace { Line 1975  namespace {
1975    
1976          // update '3ewa' chunk with DimensionRegion's current settings          // update '3ewa' chunk with DimensionRegion's current settings
1977    
1978          const uint32_t chunksize = _3ewa->GetNewSize();          const uint32_t chunksize = (uint32_t) _3ewa->GetNewSize();
1979          store32(&pData[0], chunksize); // unknown, always chunk size?          store32(&pData[0], chunksize); // unknown, always chunk size?
1980    
1981          const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency);          const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency);
# Line 2089  namespace { Line 2235  namespace {
2235          if (chunksize >= 148) {          if (chunksize >= 148) {
2236              memcpy(&pData[140], DimensionUpperLimits, 8);              memcpy(&pData[140], DimensionUpperLimits, 8);
2237          }          }
2238    
2239            // format extension for EG behavior options, these will *NOT* work with
2240            // Gigasampler/GigaStudio !
2241            RIFF::Chunk* lsde = pParentList->GetSubChunk(CHUNK_ID_LSDE);
2242            if (!lsde) {
2243                // only add this "LSDE" chunk if the EG options do not match the
2244                // default EG behavior
2245                eg_opt_t defaultOpt;
2246                if (memcmp(&EGOptions, &defaultOpt, sizeof(eg_opt_t))) {
2247                    lsde = pParentList->AddSubChunk(CHUNK_ID_LSDE, 1);
2248                    // move LSDE chunk to the end of parent list
2249                    pParentList->MoveSubChunk(lsde, (RIFF::Chunk*)NULL);
2250                }
2251            }
2252            if (lsde) {
2253                unsigned char* pByte = (unsigned char*) lsde->LoadChunkData();
2254                *pByte =
2255                    (EGOptions.AttackCancel     ? 1 : 0) |
2256                    (EGOptions.AttackHoldCancel ? (1<<1) : 0) |
2257                    (EGOptions.DecayCancel      ? (1<<2) : 0) |
2258                    (EGOptions.ReleaseCancel    ? (1<<3) : 0);
2259            }
2260      }      }
2261    
2262      double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) {      double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) {
# Line 2503  namespace { Line 2671  namespace {
2671    
2672              // unknown controller type              // unknown controller type
2673              default:              default:
2674                  throw gig::Exception("Unknown leverage controller type.");                  decodedcontroller.type = leverage_ctrl_t::type_none;
2675                    decodedcontroller.controller_number = 0;
2676                    printf("Warning: Unknown leverage controller type (0x%x).\n", EncodedController);
2677                    break;
2678          }          }
2679          return decodedcontroller;          return decodedcontroller;
2680      }      }
# Line 3797  namespace { Line 3968  namespace {
3968      DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) {      DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) {
3969          uint8_t bits;          uint8_t bits;
3970          int veldim = -1;          int veldim = -1;
3971          int velbitpos;          int velbitpos = 0;
3972          int bitpos = 0;          int bitpos = 0;
3973          int dimregidx = 0;          int dimregidx = 0;
3974          for (uint i = 0; i < Dimensions; i++) {          for (uint i = 0; i < Dimensions; i++) {
# Line 3846  namespace { Line 4017  namespace {
4017      int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) {      int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) {
4018          uint8_t bits;          uint8_t bits;
4019          int veldim = -1;          int veldim = -1;
4020          int velbitpos;          int velbitpos = 0;
4021          int bitpos = 0;          int bitpos = 0;
4022          int dimregidx = 0;          int dimregidx = 0;
4023          for (uint i = 0; i < Dimensions; i++) {          for (uint i = 0; i < Dimensions; i++) {
# Line 4195  namespace { Line 4366  namespace {
4366              // to handle potential future extensions of the header              // to handle potential future extensions of the header
4367              ckScri->SetPos(sizeof(int32_t) + headerSize);              ckScri->SetPos(sizeof(int32_t) + headerSize);
4368              // read actual script data              // read actual script data
4369              uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos();              uint32_t scriptSize = uint32_t(ckScri->GetSize() - ckScri->GetPos());
4370              data.resize(scriptSize);              data.resize(scriptSize);
4371              for (int i = 0; i < scriptSize; ++i)              for (int i = 0; i < scriptSize; ++i)
4372                  data[i] = ckScri->ReadUint8();                  data[i] = ckScri->ReadUint8();
# Line 4246  namespace { Line 4417  namespace {
4417          // recalculate CRC32 check sum          // recalculate CRC32 check sum
4418          __resetCRC(crc);          __resetCRC(crc);
4419          __calculateCRC(&data[0], data.size(), crc);          __calculateCRC(&data[0], data.size(), crc);
4420          __encodeCRC(crc);          __finalizeCRC(crc);
4421          // make sure chunk exists and has the required size          // make sure chunk exists and has the required size
4422          const int chunkSize = 7*sizeof(int32_t) + Name.size() + data.size();          const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size();
4423          if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize);          if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize);
4424          else pChunk->Resize(chunkSize);          else pChunk->Resize(chunkSize);
4425          // fill the chunk data to be written to disk          // fill the chunk data to be written to disk
4426          uint8_t* pData = (uint8_t*) pChunk->LoadChunkData();          uint8_t* pData = (uint8_t*) pChunk->LoadChunkData();
4427          int pos = 0;          int pos = 0;
4428          store32(&pData[pos], 6*sizeof(int32_t) + Name.size()); // total header size          store32(&pData[pos], uint32_t(6*sizeof(int32_t) + Name.size())); // total header size
4429          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4430          store32(&pData[pos], Compression);          store32(&pData[pos], Compression);
4431          pos += sizeof(int32_t);          pos += sizeof(int32_t);
# Line 4266  namespace { Line 4437  namespace {
4437          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4438          store32(&pData[pos], crc);          store32(&pData[pos], crc);
4439          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4440          store32(&pData[pos], Name.size());          store32(&pData[pos], (uint32_t) Name.size());
4441          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4442          for (int i = 0; i < Name.size(); ++i, ++pos)          for (int i = 0; i < Name.size(); ++i, ++pos)
4443              pData[pos] = Name[i];              pData[pos] = Name[i];
# Line 4297  namespace { Line 4468  namespace {
4468          return pGroup;          return pGroup;
4469      }      }
4470    
4471        /**
4472         * Make a (semi) deep copy of the Script object given by @a orig
4473         * and assign it to this object. Note: the ScriptGroup this Script
4474         * object belongs to remains untouched by this call.
4475         *
4476         * @param orig - original Script object to be copied from
4477         */
4478        void Script::CopyAssign(const Script* orig) {
4479            Name        = orig->Name;
4480            Compression = orig->Compression;
4481            Encoding    = orig->Encoding;
4482            Language    = orig->Language;
4483            Bypass      = orig->Bypass;
4484            data        = orig->data;
4485        }
4486    
4487      void Script::RemoveAllScriptReferences() {      void Script::RemoveAllScriptReferences() {
4488          File* pFile = pGroup->pFile;          File* pFile = pGroup->pFile;
4489          for (int i = 0; pFile->GetInstrument(i); ++i) {          for (int i = 0; pFile->GetInstrument(i); ++i) {
# Line 4443  namespace { Line 4630  namespace {
4630          EffectSend = 0;          EffectSend = 0;
4631          Attenuation = 0;          Attenuation = 0;
4632          FineTune = 0;          FineTune = 0;
4633          PitchbendRange = 0;          PitchbendRange = 2;
4634          PianoReleaseMode = false;          PianoReleaseMode = false;
4635          DimensionKeyRange.low = 0;          DimensionKeyRange.low = 0;
4636          DimensionKeyRange.high = 0;          DimensionKeyRange.high = 0;
# Line 4618  namespace { Line 4805  namespace {
4805    
4806             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4807             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);
4808             const int slotCount = pScriptRefs->size();             const int slotCount = (int) pScriptRefs->size();
4809             const int headerSize = 3 * sizeof(uint32_t);             const int headerSize = 3 * sizeof(uint32_t);
4810             const int slotSize  = 2 * sizeof(uint32_t);             const int slotSize  = 2 * sizeof(uint32_t);
4811             const int totalChunkSize = headerSize + slotCount * slotSize;             const int totalChunkSize = headerSize + slotCount * slotSize;
# Line 4654  namespace { Line 4841  namespace {
4841         if (pScriptRefs && pScriptRefs->size() > 0) {         if (pScriptRefs && pScriptRefs->size() > 0) {
4842             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4843             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4844             const int slotCount = pScriptRefs->size();             const int slotCount = (int) pScriptRefs->size();
4845             const int headerSize = 3 * sizeof(uint32_t);             const int headerSize = 3 * sizeof(uint32_t);
4846             ckSCSL->SetPos(headerSize);             ckSCSL->SetPos(headerSize);
4847             for (int i = 0; i < slotCount; ++i) {             for (int i = 0; i < slotCount; ++i) {
4848                 uint32_t fileOffset =                 uint32_t fileOffset = uint32_t(
4849                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -
4850                      (*pScriptRefs)[i].script->pChunk->GetPos() -                      (*pScriptRefs)[i].script->pChunk->GetPos() -
4851                      CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize());                      CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize())
4852                   );
4853                 ckSCSL->WriteUint32(&fileOffset);                 ckSCSL->WriteUint32(&fileOffset);
4854                 // jump over flags entry (containing the bypass flag)                 // jump over flags entry (containing the bypass flag)
4855                 ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);                 ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);
# Line 4721  namespace { Line 4909  namespace {
4909          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
4910          Region* pNewRegion = new Region(this, rgn);          Region* pNewRegion = new Region(this, rgn);
4911          pRegions->push_back(pNewRegion);          pRegions->push_back(pNewRegion);
4912          Regions = pRegions->size();          Regions = (uint32_t) pRegions->size();
4913          // update Region key table for fast lookup          // update Region key table for fast lookup
4914          UpdateRegionKeyTable();          UpdateRegionKeyTable();
4915          // done          // done
# Line 4867  namespace { Line 5055  namespace {
5055                  for (uint s = 0; group->GetScript(s); ++s) {                  for (uint s = 0; group->GetScript(s); ++s) {
5056                      Script* script = group->GetScript(s);                      Script* script = group->GetScript(s);
5057                      if (script->pChunk) {                      if (script->pChunk) {
5058                          uint32_t offset = script->pChunk->GetFilePos() -                          uint32_t offset = uint32_t(
5059                                            script->pChunk->GetPos() -                              script->pChunk->GetFilePos() -
5060                                            CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize());                              script->pChunk->GetPos() -
5061                                CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize())
5062                            );
5063                          if (offset == soughtOffset)                          if (offset == soughtOffset)
5064                          {                          {
5065                              _ScriptPooolRef ref;                              _ScriptPooolRef ref;
# Line 4994  namespace { Line 5184  namespace {
5184       */       */
5185      void Instrument::RemoveScript(Script* pScript) {      void Instrument::RemoveScript(Script* pScript) {
5186          LoadScripts();          LoadScripts();
5187          for (int i = pScriptRefs->size() - 1; i >= 0; --i) {          for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) {
5188              if ((*pScriptRefs)[i].script == pScript) {              if ((*pScriptRefs)[i].script == pScript) {
5189                  pScriptRefs->erase( pScriptRefs->begin() + i );                  pScriptRefs->erase( pScriptRefs->begin() + i );
5190              }              }
# Line 5016  namespace { Line 5206  namespace {
5206       * gigedit.       * gigedit.
5207       */       */
5208      uint Instrument::ScriptSlotCount() const {      uint Instrument::ScriptSlotCount() const {
5209          return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size();          return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size());
5210      }      }
5211    
5212      /** @brief Whether script execution shall be skipped.      /** @brief Whether script execution shall be skipped.
# Line 5440  namespace { Line 5630  namespace {
5630              }              }
5631          }          }
5632          String name(pRIFF->GetFileName());          String name(pRIFF->GetFileName());
5633          int nameLen = name.length();          int nameLen = (int) name.length();
5634          char suffix[6];          char suffix[6];
5635          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;
5636    
# Line 5609  namespace { Line 5799  namespace {
5799              mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s);              mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s);
5800              mSamples[pFile->GetSample(i)] = s;              mSamples[pFile->GetSample(i)] = s;
5801          }          }
5802            
5803            // clone script groups and their scripts
5804            for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) {
5805                ScriptGroup* sg = pFile->GetScriptGroup(iGroup);
5806                ScriptGroup* dg = AddScriptGroup();
5807                dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name;
5808                for (int iScript = 0; sg->GetScript(iScript); ++iScript) {
5809                    Script* ss = sg->GetScript(iScript);
5810                    Script* ds = dg->AddScript();
5811                    ds->CopyAssign(ss);
5812                }
5813            }
5814    
5815          //BUG: For some reason this method only works with this additional          //BUG: For some reason this method only works with this additional
5816          //     Save() call in between here.          //     Save() call in between here.
5817          //          //
# Line 5756  namespace { Line 5958  namespace {
5958          if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned          if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned
5959          if (_3crc->GetNewSize() != pSamples->size() * 8) return false;          if (_3crc->GetNewSize() != pSamples->size() * 8) return false;
5960    
5961          const int n = _3crc->GetNewSize() / 8;          const file_offset_t n = _3crc->GetNewSize() / 8;
5962    
5963          uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();          uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();
5964          if (!pData) return false;          if (!pData) return false;
5965    
5966          for (int i = 0; i < n; ++i) {          for (file_offset_t i = 0; i < n; ++i) {
5967              uint32_t one = pData[i*2];              uint32_t one = pData[i*2];
5968              if (one != 1) return false;              if (one != 1) return false;
5969          }          }
# Line 6153  namespace { Line 6355  namespace {
6355          // Note that there are several fields with unknown use. These          // Note that there are several fields with unknown use. These
6356          // are set to zero.          // are set to zero.
6357    
6358          int sublen = pSamples->size() / 8 + 49;          int sublen = int(pSamples->size() / 8 + 49);
6359          int einfSize = (Instruments + 1) * sublen;          int einfSize = (Instruments + 1) * sublen;
6360    
6361          RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);          RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);
# Line 6226  namespace { Line 6428  namespace {
6428                  store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops);                  store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops);
6429                  // next 8 bytes unknown                  // next 8 bytes unknown
6430                  store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx);                  store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx);
6431                  store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size());                  store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size());
6432                  // next 4 bytes unknown                  // next 4 bytes unknown
6433    
6434                  totnbregions += instrument->Regions;                  totnbregions += instrument->Regions;
# Line 6244  namespace { Line 6446  namespace {
6446              store32(&pData[24], totnbloops);              store32(&pData[24], totnbloops);
6447              // next 8 bytes unknown              // next 8 bytes unknown
6448              // next 4 bytes unknown, not always 0              // next 4 bytes unknown, not always 0
6449              store32(&pData[40], pSamples->size());              store32(&pData[40], (uint32_t) pSamples->size());
6450              // next 4 bytes unknown              // next 4 bytes unknown
6451          }          }
6452    
# Line 6326  namespace { Line 6528  namespace {
6528  // *************** Exception ***************  // *************** Exception ***************
6529  // *  // *
6530    
6531      Exception::Exception(String Message) : DLS::Exception(Message) {      Exception::Exception() : DLS::Exception() {
6532        }
6533    
6534        Exception::Exception(String format, ...) : DLS::Exception() {
6535            va_list arg;
6536            va_start(arg, format);
6537            Message = assemble(format, arg);
6538            va_end(arg);
6539        }
6540    
6541        Exception::Exception(String format, va_list arg) : DLS::Exception() {
6542            Message = assemble(format, arg);
6543      }      }
6544    
6545      void Exception::PrintMessage() {      void Exception::PrintMessage() {

Legend:
Removed from v.2989  
changed lines
  Added in v.3323

  ViewVC Help
Powered by ViewVC